1 19 20 package org.netbeans.modules.j2ee.ddloaders.multiview; 21 22 import java.awt.Image ; 23 import org.netbeans.modules.j2ee.dd.api.ejb.EjbJar; 24 import org.netbeans.modules.xml.multiview.XmlMultiViewDataObject; 25 import org.openide.loaders.DataNode; 26 import org.openide.loaders.DataObject; 27 import org.openide.nodes.Children; 28 import org.openide.nodes.Node; 29 import org.openide.nodes.PropertySupport; 30 import org.openide.nodes.Sheet; 31 import org.openide.util.HelpCtx; 32 import org.openide.util.NbBundle; 33 import org.openide.util.Utilities; 34 import org.xml.sax.SAXException ; 35 36 import java.beans.PropertyChangeEvent ; 37 import java.beans.PropertyChangeListener ; 38 import org.openide.util.NbBundle; 39 40 45 public class EjbJarMultiViewDataNode extends DataNode { 46 47 private static final String DEPLOYMENT = "deployment"; 49 private EjbJarMultiViewDataObject dataObject; 50 51 54 public static final String PROPERTY_DOCUMENT_TYPE = "documentType"; 56 59 private PropertyChangeListener ddListener; 60 61 public EjbJarMultiViewDataNode(EjbJarMultiViewDataObject obj) { 62 this(obj, Children.LEAF); 63 } 64 65 public EjbJarMultiViewDataNode(EjbJarMultiViewDataObject obj, Children ch) { 66 super(obj, ch); 67 dataObject = obj; 68 initListeners(); 69 setIconBase(dataObject.getSaxError() == null); 70 } 71 72 76 private void initListeners() { 77 ddListener = new PropertyChangeListener () { 78 79 public void propertyChange(PropertyChangeEvent evt) { 80 String propertyName = evt.getPropertyName(); 81 Object oldValue = evt.getOldValue(); 82 Object newValue = evt.getNewValue(); 83 if (EjbJarMultiViewDataObject.PROP_DOCUMENT_DTD.equals(propertyName)) { 84 firePropertyChange(PROPERTY_DOCUMENT_TYPE, oldValue, newValue); 85 } else if (DataObject.PROP_VALID.equals(propertyName) && Boolean.TRUE.equals(newValue)) { 86 removePropertyChangeListener(EjbJarMultiViewDataNode.this.ddListener); 87 } else if (XmlMultiViewDataObject.PROP_DOCUMENT_VALID.equals(propertyName)) { 88 setIconBase(Boolean.TRUE.equals(newValue)); 89 } else if (Node.PROP_PROPERTY_SETS.equals(propertyName)) { 90 firePropertySetsChange(null, null); 91 } else if (XmlMultiViewDataObject.PROP_SAX_ERROR.equals(propertyName)) { 92 fireShortDescriptionChange((String ) oldValue, (String ) newValue); 93 } 94 } 95 96 }; 97 getDataObject().addPropertyChangeListener(ddListener); 98 } 99 100 private void setIconBase(final boolean valid) { 101 if (valid) { 102 setIconBaseWithExtension(dataObject.getIconBaseForValidDocument()); 103 } else { 104 setIconBaseWithExtension(dataObject.getIconBaseForInvalidDocument()); 105 } 106 fireIconChange(); 107 } 108 109 protected Sheet createSheet() { 110 Sheet s = new Sheet(); 111 Sheet.Set ss = new Sheet.Set(); 112 ss.setName(DEPLOYMENT); 113 ss.setDisplayName(NbBundle.getMessage(EjbJarMultiViewDataNode.class, "PROP_deploymentSet")); 114 ss.setShortDescription(NbBundle.getMessage(EjbJarMultiViewDataNode.class, "HINT_deploymentSet")); 115 ss.setValue("helpID", "TBD---Ludo ejbjar node"); 117 Property p = new PropertySupport.ReadWrite(PROPERTY_DOCUMENT_TYPE, 118 String .class, 119 NbBundle.getBundle(EjbJarMultiViewDataNode.class).getString("PROP_documentDTD"), 120 NbBundle.getBundle(EjbJarMultiViewDataNode.class).getString("HINT_documentDTD")) { 121 public Object getValue() { 122 java.math.BigDecimal version = dataObject.getEjbJar().getVersion(); 123 return (version == null ? "" : version.toString()); 124 } 125 126 public void setValue(Object value) { 127 String val = (String ) value; 128 if (EjbJar.VERSION_2_1.equals(val) && !val.equals(dataObject.getEjbJar().getVersion().toString())) { 129 dataObject.getEjbJar().setVersion(new java.math.BigDecimal (val)); 130 dataObject.modelUpdatedFromUI(); 131 } 132 } 133 }; 134 ss.put(p); 135 s.put(ss); 136 137 return s; 138 } 139 140 public HelpCtx getHelpCtx() { 141 return HelpCtx.DEFAULT_HELP; 142 } 143 144 public java.awt.Image getIcon(int type) { 145 Image ejbJarXmlIcon = Utilities.loadImage("org/netbeans/modules/j2ee/ddloaders/web/resources/DDDataIcon.gif"); 147 if (dataObject.getSaxError() == null){ 148 return ejbJarXmlIcon; 149 } 150 151 Image errorBadgeIcon = Utilities.loadImage("org/netbeans/modules/j2ee/ddloaders/web/resources/error-badge.gif"); return Utilities.mergeImages(ejbJarXmlIcon, errorBadgeIcon, 6, 6); 153 } 154 155 void descriptionChanged(String oldDesc, String newDesc) { 156 setShortDescription(newDesc == null ? "Enterprise Bean deployment descriptor" : newDesc); } 158 159 public String getShortDescription() { 160 SAXException saxError = dataObject.getSaxError(); 161 if (saxError==null) { 162 return Utils.getBundleMessage("HINT_ejb_dd"); 163 } else { 164 return saxError.getMessage(); 165 } 166 } 167 } 168 | Popular Tags |