1 19 20 25 26 package org.netbeans.modules.xml.schema.abe.nodes.properties; 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.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 50 public class NamespaceEditor extends StringEditor { 51 52 private String typeDisplayName; 53 private String property; 54 private String initialUri; 55 private Collection <String > uris; 56 private Collection <Option> options; 57 58 public enum Option { None, Declared, Other, TargetNamespace, Local}; 59 60 63 public NamespaceEditor(AXIComponent component, String typeDisplayName, String property) { 64 this.typeDisplayName = typeDisplayName; 65 this.property = property; 66 this.options = new ArrayList <Option>(); 67 if(component.getPeer() instanceof Schema) { 68 Schema schema = (Schema)component.getPeer(); 69 this.initialUri = schema.getTargetNamespace(); 70 this.uris = new ArrayList <String >(); 71 for(String 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 } 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 return dlg; 122 } 123 124 125 public boolean supportsCustomEditor() { 126 return true; 127 } 128 } 129 | Popular Tags |