KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > websvc > registry > ui > ResultCellEditor


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.modules.websvc.registry.ui;
21
22 /**
23  *
24  * @author David Botterill
25  */

26
27 import javax.swing.DefaultCellEditor JavaDoc;
28 import javax.swing.table.TableCellEditor JavaDoc;
29 import javax.swing.tree.DefaultMutableTreeNode JavaDoc;
30 import javax.swing.JTextField JavaDoc;
31
32 import org.netbeans.swing.outline.NodeRowModel;
33 import org.netbeans.swing.outline.OutlineModel;
34
35 import org.openide.DialogDescriptor;
36 import org.openide.NotifyDescriptor;
37 import org.openide.DialogDisplayer;
38
39 import java.awt.Dialog JavaDoc;
40 import java.util.EventObject JavaDoc;
41
42 import com.sun.xml.rpc.processor.model.java.JavaType;
43 import com.sun.xml.rpc.processor.model.java.JavaSimpleType;
44 import com.sun.xml.rpc.processor.model.java.JavaEnumerationType;
45
46
47 /**
48  *
49  * @author david
50  */

51 public class ResultCellEditor extends DefaultCellEditor JavaDoc implements TableCellEditor JavaDoc {
52     
53     private Dialog JavaDoc dialog;
54     private DialogDescriptor dlg;
55     private ResultViewerDialog viewerDialog;
56     private Object JavaDoc saveValue;
57     
58     /** Creates a new instance of TypeCellRenderer */
59     public ResultCellEditor() {
60         super(new JTextField JavaDoc());
61         this.setClickCountToStart(1);
62     }
63     /**
64      * return the value of the last component.
65      */

66     public Object JavaDoc getCellEditorValue() {
67         return saveValue;
68     }
69     
70     public java.awt.Component JavaDoc getTableCellEditorComponent(javax.swing.JTable JavaDoc table, Object JavaDoc value, boolean isSelected, int row, int column) {
71         saveValue = value;
72         NodeRowModel rowModel = ((OutlineModel)table.getModel()).getRowNodeModel();
73         DefaultMutableTreeNode JavaDoc node = (DefaultMutableTreeNode JavaDoc)rowModel.getNodeForRow(row);
74         /**
75          * Now depending on the type, create a component to edit/display the type.
76          */

77         viewerDialog = new ResultViewerDialog();
78         if(null == node.getUserObject()) {
79             viewerDialog.setText((String JavaDoc)value);
80             
81         } else {
82             ResultNodeData data = (ResultNodeData)node.getUserObject();
83             JavaType type = data.getResultType();
84             
85             if(type instanceof JavaSimpleType) {
86                 
87                 viewerDialog.setText(value != null ? value.toString() : "");
88             } else if(type instanceof JavaEnumerationType) {
89                 viewerDialog.setText(value != null ? value.toString() : "");
90             } else {
91                 return null;
92             }
93             
94             dlg = new DialogDescriptor(viewerDialog, data.getResultType().getRealName(),
95             true, NotifyDescriptor.OK_CANCEL_OPTION, NotifyDescriptor.OK_OPTION,
96             DialogDescriptor.DEFAULT_ALIGN, viewerDialog.getHelpCtx(), null);
97             dlg.setOptions(new Object JavaDoc[] { viewerDialog.getOkButton() });
98             
99             dialog = DialogDisplayer.getDefault().createDialog(dlg);
100             dialog.setSize(300,300);
101             dialog.show();
102         }
103         
104         
105         return null;
106     }
107     
108 }
109
Popular Tags