1 19 20 25 26 package org.netbeans.modules.j2ee.sun.share.config.ui; 27 28 import java.util.*; 29 import java.beans.*; 30 import java.awt.Image ; 31 import java.awt.Component ; 32 33 import javax.enterprise.deploy.spi.DConfigBean ; 34 import javax.swing.SwingUtilities ; 35 36 import org.openide.ErrorManager; 37 import org.openide.cookies.SaveCookie; 38 import org.openide.loaders.DataObject; 39 import org.openide.nodes.*; 40 import org.openide.util.HelpCtx; 41 import org.openide.util.WeakListeners; 42 43 import org.netbeans.modules.j2ee.sun.share.config.ConfigurationStorage; 44 import org.netbeans.modules.j2ee.sun.share.config.ConfigBeanStorage; 45 import org.netbeans.modules.j2ee.sun.share.configbean.Base; 46 import org.netbeans.modules.j2ee.sun.share.configbean.DConfigBeanProperties; 47 48 49 55 public class ConfigBeanNode extends AbstractNode implements PropertyChangeListener { 56 57 final ConfigBeanStorage bean; 58 final BeanInfo info; 59 final DConfigBeanProperties extraProps; 60 61 public ConfigBeanNode(ConfigBeanStorage bean) { 62 super(new ConfigChildren(bean)); 63 this.bean = bean; 64 info = ConfigUtils.createBeanInfo(bean.getConfigBean()); 65 66 DConfigBean dcb = bean.getConfigBean(); 68 if(dcb instanceof Base) { 69 extraProps = ((Base) dcb).getUICustomization(dcb); 70 } else { 71 extraProps = null; 72 } 73 74 ConfigurationStorage storage = bean.getStorage(); 75 storage.addPropertyChangeListener(WeakListeners.propertyChange(this, storage)); 76 } 77 78 public String getDisplayName() { 79 if(extraProps != null) return extraProps.getDisplayName(); 80 if(info == null) return bean.getClass().toString(); 81 return info.getBeanDescriptor().getDisplayName(); 82 } 83 84 public Node.Cookie getCookie(Class type) { 85 if (SaveCookie.class.isAssignableFrom(type)) { 86 return bean.getStorage().getPrimaryDataObject().getCookie(type); 87 } 88 return super.getCookie(type); 89 } 90 91 private static final javax.swing.Action [] EMPTY_ACTIONS = new javax.swing.Action [0]; 92 public javax.swing.Action [] getActions(boolean context) { 93 return EMPTY_ACTIONS; 94 } 95 96 public HelpCtx getHelpCtx() { 97 if(extraProps != null) { 98 String helpId = extraProps.getHelpId(); 99 if(helpId != null) return new HelpCtx(helpId); 100 } 101 return HelpCtx.DEFAULT_HELP; 102 } 103 104 public Image getIcon(int type) { 105 if(info != null) { 106 Image icon = info.getIcon(type); 107 if(icon != null) return icon; 108 } 109 return super.getIcon(type); 110 } 111 112 public Image getOpenedIcon(int type) { 113 if(info != null) { 114 Image icon = info.getIcon(type); 115 if(icon != null) return icon; 116 } 117 return super.getOpenedIcon(type); 118 } 119 120 public Sheet createSheet() { 121 Sheet ret = new Sheet(); 122 Sheet.Set set = ConfigUtils.createSheet(bean); 123 set.setName(getDisplayName()); 124 ret.put(set); 125 return ret; 126 } 127 128 public DConfigBean getBean() { 129 return bean.getConfigBean(); 130 } 131 132 136 public Component getCustomizer() { 137 Component comp = null; 138 if (!hasCustomizer()) { 139 return null; 140 } 141 try { 142 return (java.awt.Component ) info.getBeanDescriptor().getCustomizerClass().newInstance(); 144 }catch (Exception e) { 145 ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, e); 146 } 147 return comp; 148 } 149 150 154 public boolean hasCustomizer() { 155 return info.getBeanDescriptor().getCustomizerClass() != null; 156 } 157 158 public void propertyChange(PropertyChangeEvent evt) { 159 if(DataObject.PROP_COOKIE.equals(evt.getPropertyName())) { 160 fireCookieChange(); 161 } 162 } 163 164 public static class ConfigChildren extends Children.Keys implements ConfigBeanStorage.ChildrenChangeListener { 165 ConfigBeanStorage bean; 166 ConfigChildren(ConfigBeanStorage bean) { 167 this.bean = bean; 168 } 169 170 protected void addNotify() { 171 updateKeys(); 172 bean.addChildrenChangeListener(this); 173 } 174 175 protected void removeNotify() { 176 setKeys(Collections.EMPTY_SET); 177 bean.removeChildrenChangeListener(this); 178 } 179 180 void updateKeys() { 181 setKeys(bean.getChildMap().keySet()); 182 } 183 184 void updateKey(Object key) { 185 refreshKey(key); 186 } 187 188 protected Node[] createNodes(Object key) { 189 Collection nodeSet = (Collection) bean.getChildMap().get(key); 190 ArrayList ret = new ArrayList(); 191 Iterator i = nodeSet.iterator(); 192 for(int c = 0; i.hasNext(); c++) { 193 ConfigBeanStorage cbs = (ConfigBeanStorage) i.next(); 194 Node node = cbs.getNode(); 195 if (node != null) { 196 ret.add(node); 197 } 198 } 199 return (Node[]) ret.toArray(new Node[ret.size()]); 200 } 201 202 public void childBeanAdded(final ConfigBeanStorage childStorage) { 203 SwingUtilities.invokeLater(new Runnable () { 204 public void run() { 205 updateKeys(); 206 refreshKey(childStorage.getConfigBean().getDDBean().getXpath()); 207 } 208 }); 209 } 210 211 public void childBeanRemoved(final ConfigBeanStorage childStorage) { 212 SwingUtilities.invokeLater(new Runnable () { 213 public void run() { 214 updateKey(childStorage.getConfigBean().getDDBean().getXpath()); 215 } 216 }); 217 } 218 } 219 } 220 | Popular Tags |