KickJava   Java API By Example, From Geeks To Geeks.

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


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 /*
21  * MemberTypesEditor.java
22  *
23  * Created on December 22, 2005, 12:58 PM
24  */

25
26 package org.netbeans.modules.xml.schema.abe.nodes.properties;
27
28 import java.awt.Component JavaDoc;
29 import java.awt.Dialog JavaDoc;
30 import java.awt.Dimension JavaDoc;
31 import java.awt.event.ActionEvent JavaDoc;
32 import java.awt.event.ActionListener JavaDoc;
33 import java.beans.PropertyChangeEvent JavaDoc;
34 import java.beans.PropertyChangeListener JavaDoc;
35 import java.beans.PropertyEditorSupport JavaDoc;
36 import java.util.ArrayList JavaDoc;
37 import java.util.Collection JavaDoc;
38 import org.netbeans.modules.xml.schema.model.Notation;
39 import org.netbeans.modules.xml.schema.model.Schema;
40 import org.netbeans.modules.xml.axi.AXIComponent;
41 import org.openide.DialogDescriptor;
42 import org.openide.DialogDisplayer;
43 import org.openide.ErrorManager;
44 import org.openide.util.NbBundle;
45
46 /**
47  *
48  * @author Ajit Bhate
49  */

50 public class NamespaceEditor extends StringEditor {
51     
52     private String JavaDoc typeDisplayName;
53     private String JavaDoc property;
54     private String JavaDoc initialUri;
55     private Collection JavaDoc<String JavaDoc> uris;
56     private Collection JavaDoc<Option> options;
57     
58     public enum Option { None, Declared, Other, TargetNamespace, Local};
59     
60     /**
61      * Creates a new instance of MemberTypesEditor
62      */

63     public NamespaceEditor(AXIComponent component, String JavaDoc typeDisplayName, String JavaDoc property) {
64         this.typeDisplayName = typeDisplayName;
65         this.property = property;
66         this.options = new ArrayList JavaDoc<Option>();
67         if(component.getPeer() instanceof Schema) {
68             Schema schema = (Schema)component.getPeer();
69             this.initialUri = schema.getTargetNamespace();
70             this.uris = new ArrayList JavaDoc<String JavaDoc>();
71             for(String JavaDoc uri: schema.getPrefixes().values()) {
72                 if(!uris.contains(uri))
73                     uris.add(uri);
74             }
75             options.add(Option.None);
76             options.add(Option.Declared);
77             options.add(Option.Other);
78         }/* else if(component instanceof Notation) {
79             Notation notation = (Notation)component;
80             this.initialUri = notation.getSystemIdentifier();
81             this.uris = notation.getModel().getSchema().getPrefixes().values();
82             options.add(Option.Declared);
83             options.add(Option.Other);
84         }*/

85     }
86     
87     public Component JavaDoc getCustomEditor() {
88         final NamespacePanel panel = new NamespacePanel(initialUri,
89                 uris, options);
90         final DialogDescriptor descriptor = new DialogDescriptor(panel,
91                 NbBundle.getMessage(
92                 NamespaceEditor.class,"LBL_Custom_Property_Editor_Title",
93                 typeDisplayName,property),
94                 true,
95                 new ActionListener JavaDoc() {
96             public void actionPerformed(ActionEvent JavaDoc evt) {
97                 if (evt.getSource().equals(DialogDescriptor.OK_OPTION)) {
98                     try {
99                         setValue(panel.getCurrentSelection());
100                     } catch (IllegalArgumentException JavaDoc iae) {
101                         ErrorManager.getDefault().annotate(iae, ErrorManager.USER,
102                                 iae.getMessage(), iae.getLocalizedMessage(),
103                                 null, new java.util.Date JavaDoc());
104                         throw iae;
105                     }
106                 }
107             }
108         }
109         );
110         // enable/disable the dlg ok button depending selection
111
panel.addPropertyChangeListener( new PropertyChangeListener JavaDoc() {
112             public void propertyChange(PropertyChangeEvent JavaDoc evt) {
113                 if (evt.getPropertyName().equals(
114                         NamespacePanel.PROP_VALID_SELECTION)) {
115                     descriptor.setValid(((Boolean JavaDoc)evt.getNewValue()).booleanValue());
116                 }
117             }
118         });
119         panel.checkValidity();
120         Dialog JavaDoc dlg = DialogDisplayer.getDefault().createDialog(descriptor);
121         return dlg;
122     }
123     
124     
125     public boolean supportsCustomEditor() {
126         return true;
127     }
128 }
129
Popular Tags