KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > xml > schema > ui > basic > editors > 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.ui.basic.editors;
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.schema.model.SchemaComponent;
41 import org.netbeans.modules.xml.schema.model.SchemaModelFactory;
42 import org.openide.DialogDescriptor;
43 import org.openide.DialogDisplayer;
44 import org.openide.ErrorManager;
45 import org.openide.util.NbBundle;
46
47 /**
48  *
49  * @author Ajit Bhate
50  */

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

64     public NamespaceEditor(SchemaComponent component, String JavaDoc typeDisplayName, String JavaDoc property) {
65         this.typeDisplayName = typeDisplayName;
66         this.property = property;
67         this.options = new ArrayList JavaDoc<Option>();
68         if(component instanceof Schema) {
69             Schema schema = (Schema)component;
70             this.initialUri = schema.getTargetNamespace();
71             this.uris = schema.getPrefixes().values();
72             options.add(Option.None);
73             options.add(Option.Declared);
74             options.add(Option.Other);
75         } else if(component instanceof Notation) {
76             Notation notation = (Notation)component;
77             this.initialUri = notation.getSystemIdentifier();
78             this.uris = notation.getModel().getSchema().getPrefixes().values();
79             options.add(Option.Declared);
80             options.add(Option.Other);
81         }
82         uris.remove(SchemaModelFactory.getDefault().getPrimitiveTypesModel().
83                 getSchema().getTargetNamespace());
84         if(initialUri!=null) uris.remove(initialUri);
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         dlg.setPreferredSize(new Dimension JavaDoc(400,300));
122         return dlg;
123     }
124     
125     
126     public boolean supportsCustomEditor() {
127         return true;
128     }
129 }
130
Popular Tags