KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > xml > schema > abe > nodes > properties > GlobalReferenceEditor


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-2007 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.modules.xml.schema.abe.nodes.properties;
21
22 import java.awt.Component JavaDoc;
23 import java.awt.Dialog JavaDoc;
24 import java.awt.event.ActionEvent JavaDoc;
25 import java.awt.event.ActionListener JavaDoc;
26 import java.beans.FeatureDescriptor JavaDoc;
27 import java.beans.PropertyEditorSupport JavaDoc;
28 import java.util.ArrayList JavaDoc;
29 import java.util.Collection JavaDoc;
30 import java.util.List JavaDoc;
31 import org.netbeans.modules.xml.axi.AXIComponent;
32 import org.netbeans.modules.xml.axi.AXIType;
33 import org.netbeans.modules.xml.axi.ContentModel;
34 import org.openide.DialogDescriptor;
35 import org.openide.DialogDisplayer;
36 import org.openide.ErrorManager;
37 import org.openide.explorer.propertysheet.ExPropertyEditor;
38 import org.openide.explorer.propertysheet.PropertyEnv;
39 import org.openide.util.NbBundle;
40
41 /**
42  *
43  * @author Ayub Khan
44  */

45 public class GlobalReferenceEditor
46         extends PropertyEditorSupport JavaDoc
47         implements ExPropertyEditor {
48     
49     private DialogDescriptor descriptor;
50     private AXIComponent component;
51     private List JavaDoc<Class JavaDoc> filterTypes;
52     private String JavaDoc referenceTypeDisplayName;
53     private String JavaDoc typeDisplayName;
54     private String JavaDoc propertyDisplayName;
55     private AXIComponentSelectionPanel panel;
56     
57     
58     /**
59      * Creates a new instance of GlobalReferenceEditor
60      */

61     public GlobalReferenceEditor(AXIComponent component,
62             String JavaDoc typeDisplayName,
63             String JavaDoc propertyDisplayName,
64             String JavaDoc referenceTypeDisplayName,
65             List JavaDoc<Class JavaDoc> filterTypes) {
66         this.typeDisplayName = typeDisplayName;
67         this.propertyDisplayName = propertyDisplayName;
68         this.filterTypes = filterTypes;
69         this.component = component;
70         this.referenceTypeDisplayName = referenceTypeDisplayName;
71     }
72     
73     public String JavaDoc getAsText() {
74         Object JavaDoc val = getValue();
75         if (val instanceof AXIType && component.getModel() != null)
76             return ((AXIType)val).getName();
77         else
78             return null;
79     }
80     
81     @SuppressWarnings JavaDoc("unchecked")
82     public Component JavaDoc getCustomEditor() {
83         Object JavaDoc currentGlobalReference = getValue();
84         Collection JavaDoc<AXIComponent> exclude = null;
85         for(Class JavaDoc filterType: filterTypes) {
86             if(filterType.isInstance(component)) {
87                 exclude = new ArrayList JavaDoc<AXIComponent>();
88                 exclude.add(component);
89             } else {
90                 AXIComponent parent = component.getParent();
91                 while (parent!=null) {
92                     if(filterType.isInstance(parent)) {
93                         exclude = new ArrayList JavaDoc<AXIComponent>();
94                         exclude.add(parent);
95                         break;
96                     }
97                     parent = parent.getParent();
98                 }
99             }
100         }
101         panel = new AXIComponentSelectionPanel(component.getModel(),
102                 referenceTypeDisplayName, filterTypes,
103                 currentGlobalReference, exclude);
104         descriptor = new AXIComponentSelDialogDesc(panel,
105                 NbBundle.getMessage(GlobalReferenceEditor.class,
106                 "LBL_Custom_Property_Editor_Title",
107                 new Object JavaDoc[] {typeDisplayName, propertyDisplayName}),
108                 true,
109                 new ActionListener JavaDoc() {
110             public void actionPerformed(ActionEvent JavaDoc evt) {
111                 if (evt.getSource().equals(DialogDescriptor.OK_OPTION)) {
112                     try {
113                         setValue(panel.getCurrentSelection());
114                     } catch (IllegalArgumentException JavaDoc iae) {
115                         ErrorManager.getDefault().annotate(iae, ErrorManager.USER,
116                                 iae.getMessage(), iae.getLocalizedMessage(),
117                                 null, new java.util.Date JavaDoc());
118                         throw iae;
119                     }
120                 }
121             }
122         });
123         
124         Dialog JavaDoc dlg = DialogDisplayer.getDefault().createDialog(descriptor);
125         return dlg;
126     }
127     
128     
129     public boolean supportsCustomEditor() {
130         return true;
131     }
132     
133     public void attachEnv(PropertyEnv env ) {
134         FeatureDescriptor JavaDoc desc = env.getFeatureDescriptor();
135         // make this is not editable
136
desc.setValue("canEditAsText", Boolean.FALSE); // NOI18N
137
}
138 }
139
Popular Tags