1 19 20 package org.netbeans.modules.xml.schema.abe.nodes.properties; 21 22 import java.awt.Component ; 23 import java.awt.Dialog ; 24 import java.awt.event.ActionEvent ; 25 import java.awt.event.ActionListener ; 26 import java.beans.FeatureDescriptor ; 27 import java.beans.PropertyEditorSupport ; 28 import java.util.ArrayList ; 29 import java.util.Collection ; 30 import java.util.List ; 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 45 public class GlobalReferenceEditor 46 extends PropertyEditorSupport  47 implements ExPropertyEditor { 48 49 private DialogDescriptor descriptor; 50 private AXIComponent component; 51 private List <Class > filterTypes; 52 private String referenceTypeDisplayName; 53 private String typeDisplayName; 54 private String propertyDisplayName; 55 private AXIComponentSelectionPanel panel; 56 57 58 61 public GlobalReferenceEditor(AXIComponent component, 62 String typeDisplayName, 63 String propertyDisplayName, 64 String referenceTypeDisplayName, 65 List <Class > 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 getAsText() { 74 Object val = getValue(); 75 if (val instanceof AXIType && component.getModel() != null) 76 return ((AXIType)val).getName(); 77 else 78 return null; 79 } 80 81 @SuppressWarnings ("unchecked") 82 public Component getCustomEditor() { 83 Object currentGlobalReference = getValue(); 84 Collection <AXIComponent> exclude = null; 85 for(Class filterType: filterTypes) { 86 if(filterType.isInstance(component)) { 87 exclude = new ArrayList <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 <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 [] {typeDisplayName, propertyDisplayName}), 108 true, 109 new ActionListener () { 110 public void actionPerformed(ActionEvent evt) { 111 if (evt.getSource().equals(DialogDescriptor.OK_OPTION)) { 112 try { 113 setValue(panel.getCurrentSelection()); 114 } catch (IllegalArgumentException iae) { 115 ErrorManager.getDefault().annotate(iae, ErrorManager.USER, 116 iae.getMessage(), iae.getLocalizedMessage(), 117 null, new java.util.Date ()); 118 throw iae; 119 } 120 } 121 } 122 }); 123 124 Dialog 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 desc = env.getFeatureDescriptor(); 135 desc.setValue("canEditAsText", Boolean.FALSE); } 138 } 139 | Popular Tags |