1 19 20 package org.netbeans.modules.j2ee.ddloaders.multiview; 21 22 import org.netbeans.modules.j2ee.dd.api.ejb.EntityAndSession; 23 import org.netbeans.modules.j2ee.ddloaders.multiview.ui.EjbImplementationAndInterfacesForm; 24 import org.netbeans.modules.xml.multiview.ItemCheckBoxHelper; 25 import org.netbeans.modules.xml.multiview.XmlMultiViewDataSynchronizer; 26 import org.netbeans.modules.xml.multiview.ui.LinkButton; 27 import org.netbeans.modules.xml.multiview.ui.SectionNodeView; 28 import org.openide.DialogDisplayer; 29 import org.openide.NotifyDescriptor; 30 31 import javax.swing.*; 32 import java.awt.*; 33 import java.awt.event.ActionEvent ; 34 import java.awt.event.ActionListener ; 35 import java.awt.event.FocusAdapter ; 36 import java.awt.event.FocusEvent ; 37 import java.awt.event.FocusListener ; 38 39 42 public class EjbImplementationAndInterfacesPanel extends EjbImplementationAndInterfacesForm { 43 44 private EntityAndSessionHelper helper; 45 private NonEditableDocument beanClassDocument = new NonEditableDocument() { 46 protected String retrieveText() { 47 return helper == null ? null : helper.getEjbClass(); 48 } 49 }; 50 private NonEditableDocument localComponentDocument = new NonEditableDocument() { 51 protected String retrieveText() { 52 return helper == null ? null : helper.getLocal(); 53 } 54 }; 55 private NonEditableDocument localHomeDocument = new NonEditableDocument() { 56 protected String retrieveText() { 57 return helper == null ? null : helper.getLocalHome(); 58 } 59 }; 60 private NonEditableDocument remoteComponentDocument = new NonEditableDocument() { 61 protected String retrieveText() { 62 return helper == null ? null : helper.getRemote(); 63 } 64 }; 65 private NonEditableDocument remoteHomeDocument = new NonEditableDocument() { 66 protected String retrieveText() { 67 return helper == null ? null : helper.getHome(); 68 } 69 }; 70 71 private String className = null; 72 private static final String LINK_BEAN = "linkBean"; 73 private static final String LINK_LOCAL = "linkLocal"; 74 private static final String LINK_LOCAL_HOME = "linkLocalHome"; 75 private static final String LINK_REMOTE = "linkRemote"; 76 private static final String LINK_REMOTE_HOME = "linkRemoteHome"; 77 78 81 public EjbImplementationAndInterfacesPanel(final SectionNodeView sectionNodeView, 82 final EntityAndSessionHelper helper) { 83 super(sectionNodeView); 84 this.helper = helper; 85 getBeanClassTextField().setDocument(beanClassDocument); 86 getLocalComponentTextField().setDocument(localComponentDocument); 87 getLocalHomeTextField().setDocument(localHomeDocument); 88 getRemoteComponentTextField().setDocument(remoteComponentDocument); 89 getRemoteHomeTextField().setDocument(remoteHomeDocument); 90 final JButton moveClassButton = getMoveClassButton(); 91 final JButton renameClassButton = getRenameClassButton(); 92 93 scheduleRefreshView(); 94 95 FocusListener focusListener = new FocusAdapter () { 96 public void focusGained(FocusEvent e) { 97 Component component = e.getComponent(); 98 if (component instanceof JTextField) { 99 className = ((JTextField) component).getText().trim(); 100 boolean enabled = className.length() > 0; 101 moveClassButton.setEnabled(enabled); 102 renameClassButton.setEnabled(enabled); 103 } else { 104 boolean isRefactorButton = component == moveClassButton || component == renameClassButton; 105 if (moveClassButton.isEnabled()) { 106 moveClassButton.setEnabled(isRefactorButton); 107 } 108 if (renameClassButton.isEnabled()) { 109 renameClassButton.setEnabled(isRefactorButton); 110 } 111 } 112 } 113 }; 114 addFocusListener(focusListener); 115 116 moveClassButton.addActionListener(new ActionListener () { 117 public void actionPerformed(ActionEvent e) { 118 moveClassButton.setEnabled(false); 120 renameClassButton.setEnabled(false); 121 } 122 }); 123 renameClassButton.addActionListener(new ActionListener () { 124 public void actionPerformed(ActionEvent e) { 125 moveClassButton.setEnabled(false); 127 renameClassButton.setEnabled(false); 128 } 129 }); 130 131 XmlMultiViewDataSynchronizer synchronizer = 132 ((EjbJarMultiViewDataObject) sectionNodeView.getDataObject()).getModelSynchronizer(); 133 addRefreshable(new ItemCheckBoxHelper(synchronizer, getLocalInterfaceCheckBox()) { 134 public boolean getItemValue() { 135 boolean value = helper.getLocal() != null; 136 getLocalComponentLinkButton().setVisible(value); 137 getLocalHomeLinkButton().setVisible(value); 138 return value; 139 } 140 141 public void setItemValue(boolean value) { 142 if (value != getItemValue()) { 143 if (value) { 144 addInterfaces(true); 145 } else { 146 removeInterfaces(true); 147 } 148 refresh(); 149 } 150 } 151 }); 152 153 addRefreshable(new ItemCheckBoxHelper(synchronizer, getRemoteInterfaceCheckBox()) { 154 public boolean getItemValue() { 155 boolean value = helper.getRemote() != null; 156 getRemoteComponentLinkButton().setVisible(value); 157 getRemoteHomeLinkButton().setVisible(value); 158 return value; 159 } 160 161 public void setItemValue(boolean value) { 162 if (value != getItemValue()) { 163 if (value) { 164 addInterfaces(false); 165 } else { 166 removeInterfaces(false); 167 } 168 refresh(); 169 } 170 } 171 }); 172 173 initLinkButton(getBeanClassLinkButton(), LINK_BEAN); 174 initLinkButton(getLocalComponentLinkButton(), LINK_LOCAL); 175 initLinkButton(getLocalHomeLinkButton(), LINK_LOCAL_HOME); 176 initLinkButton(getRemoteComponentLinkButton(), LINK_REMOTE); 177 initLinkButton(getRemoteHomeLinkButton(), LINK_REMOTE_HOME); 178 } 179 180 private void initLinkButton(AbstractButton button, String key) { 181 LinkButton.initLinkButton(button, this, null, key); 182 } 183 184 private void addInterfaces(boolean local) { 185 String interfaceType = Utils.getBundleMessage(local ? "TXT_Local" : "TXT_Remote"); 186 String msg = Utils.getBundleMessage("MSG_AddInterfaces", interfaceType); 187 String title = Utils.getBundleMessage("LBL_AddInterfaces"); 188 NotifyDescriptor descriptor = new NotifyDescriptor(msg, title, NotifyDescriptor.YES_NO_OPTION, 189 NotifyDescriptor.QUESTION_MESSAGE, null, null); 190 DialogDisplayer.getDefault().notify(descriptor); 191 if (NotifyDescriptor.YES_OPTION == descriptor.getValue()) { 192 try { 193 helper.addInterfaces(local); 194 } finally { 195 scheduleRefreshView(); 196 } 197 } 198 } 199 200 private void removeInterfaces(boolean local) { 201 String componentInterface = local ? helper.getLocal() : helper.getRemote(); 202 String homeInterface = local ? helper.getLocalHome() : helper.getHome(); 203 String interfaceType = Utils.getBundleMessage(local ? "TXT_Local" : "TXT_Remote"); 212 String title = Utils.getBundleMessage("LBL_RemoveInterfaces", interfaceType); 213 } 224 225 public void refreshView() { 226 beanClassDocument.init(); 227 localComponentDocument.init(); 228 localHomeDocument.init(); 229 remoteComponentDocument.init(); 230 remoteHomeDocument.init(); 231 232 String localComponent = helper.getLocal(); 233 boolean isLocal = localComponent != null; 234 getLocalInterfaceCheckBox().setSelected(isLocal); 235 String remoteComponent = helper.getRemote(); 236 boolean isRemote = remoteComponent != null; 237 getRemoteInterfaceCheckBox().setSelected(isRemote); 238 } 239 240 public void dataModelPropertyChange(Object source, String propertyName, Object oldValue, Object newValue) { 241 if (source instanceof EntityAndSession) { 242 scheduleRefreshView(); 243 } 244 } 245 246 public void linkButtonPressed(Object ddBean, String ddProperty) { 247 } 265 266 } 267 | Popular Tags |