1 19 20 25 26 package org.netbeans.modules.xml.schema.ui.basic.editors; 27 28 import java.awt.Component ; 29 import java.awt.Dialog ; 30 import java.awt.Dimension ; 31 import java.awt.event.ActionEvent ; 32 import java.awt.event.ActionListener ; 33 import java.beans.PropertyChangeEvent ; 34 import java.beans.PropertyChangeListener ; 35 import java.beans.PropertyEditorSupport ; 36 import java.util.ArrayList ; 37 import java.util.Collection ; 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 51 public class NamespaceEditor extends StringEditor { 52 53 private String typeDisplayName; 54 private String property; 55 private String initialUri; 56 private Collection <String > uris; 57 private Collection <Option> options; 58 59 public enum Option { None, Declared, Other, TargetNamespace, Local}; 60 61 64 public NamespaceEditor(SchemaComponent component, String typeDisplayName, String property) { 65 this.typeDisplayName = typeDisplayName; 66 this.property = property; 67 this.options = new ArrayList <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 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 () { 96 public void actionPerformed(ActionEvent evt) { 97 if (evt.getSource().equals(DialogDescriptor.OK_OPTION)) { 98 try { 99 setValue(panel.getCurrentSelection()); 100 } catch (IllegalArgumentException iae) { 101 ErrorManager.getDefault().annotate(iae, ErrorManager.USER, 102 iae.getMessage(), iae.getLocalizedMessage(), 103 null, new java.util.Date ()); 104 throw iae; 105 } 106 } 107 } 108 } 109 ); 110 panel.addPropertyChangeListener( new PropertyChangeListener () { 112 public void propertyChange(PropertyChangeEvent evt) { 113 if (evt.getPropertyName().equals( 114 NamespacePanel.PROP_VALID_SELECTION)) { 115 descriptor.setValid(((Boolean )evt.getNewValue()).booleanValue()); 116 } 117 } 118 }); 119 panel.checkValidity(); 120 Dialog dlg = DialogDisplayer.getDefault().createDialog(descriptor); 121 dlg.setPreferredSize(new Dimension (400,300)); 122 return dlg; 123 } 124 125 126 public boolean supportsCustomEditor() { 127 return true; 128 } 129 } 130 | Popular Tags |