KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > j2ee > ddloaders > multiview > EjbImplementationAndInterfacesPanel


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

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 JavaDoc;
34 import java.awt.event.ActionListener JavaDoc;
35 import java.awt.event.FocusAdapter JavaDoc;
36 import java.awt.event.FocusEvent JavaDoc;
37 import java.awt.event.FocusListener JavaDoc;
38
39 /**
40  * @author pfiala
41  */

42 public class EjbImplementationAndInterfacesPanel extends EjbImplementationAndInterfacesForm {
43
44     private EntityAndSessionHelper helper;
45     private NonEditableDocument beanClassDocument = new NonEditableDocument() {
46         protected String JavaDoc retrieveText() {
47             return helper == null ? null : helper.getEjbClass();
48         }
49     };
50     private NonEditableDocument localComponentDocument = new NonEditableDocument() {
51         protected String JavaDoc retrieveText() {
52             return helper == null ? null : helper.getLocal();
53         }
54     };
55     private NonEditableDocument localHomeDocument = new NonEditableDocument() {
56         protected String JavaDoc retrieveText() {
57             return helper == null ? null : helper.getLocalHome();
58         }
59     };
60     private NonEditableDocument remoteComponentDocument = new NonEditableDocument() {
61         protected String JavaDoc retrieveText() {
62             return helper == null ? null : helper.getRemote();
63         }
64     };
65     private NonEditableDocument remoteHomeDocument = new NonEditableDocument() {
66         protected String JavaDoc retrieveText() {
67             return helper == null ? null : helper.getHome();
68         }
69     };
70
71     private String JavaDoc className = null;
72     private static final String JavaDoc LINK_BEAN = "linkBean";
73     private static final String JavaDoc LINK_LOCAL = "linkLocal";
74     private static final String JavaDoc LINK_LOCAL_HOME = "linkLocalHome";
75     private static final String JavaDoc LINK_REMOTE = "linkRemote";
76     private static final String JavaDoc LINK_REMOTE_HOME = "linkRemoteHome";
77
78     /**
79      * Creates new form BeanForm
80      */

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 JavaDoc focusListener = new FocusAdapter JavaDoc() {
96             public void focusGained(FocusEvent JavaDoc 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 JavaDoc() {
117             public void actionPerformed(ActionEvent JavaDoc e) {
118 // Utils.activateMoveClassUI(className);
119
moveClassButton.setEnabled(false);
120                 renameClassButton.setEnabled(false);
121             }
122         });
123         renameClassButton.addActionListener(new ActionListener JavaDoc() {
124             public void actionPerformed(ActionEvent JavaDoc e) {
125 // Utils.activateRenameClassUI(className);
126
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 JavaDoc key) {
181         LinkButton.initLinkButton(button, this, null, key);
182     }
183
184     private void addInterfaces(boolean local) {
185         String JavaDoc interfaceType = Utils.getBundleMessage(local ? "TXT_Local" : "TXT_Remote");
186         String JavaDoc msg = Utils.getBundleMessage("MSG_AddInterfaces", interfaceType);
187         String JavaDoc 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 JavaDoc componentInterface = local ? helper.getLocal() : helper.getRemote();
202         String JavaDoc homeInterface = local ? helper.getLocalHome() : helper.getHome();
203 // String businessInterfaceName = helper.getBusinessInterfaceName(local);
204
// String msg;
205
// if (businessInterfaceName == null) {
206
// msg = Utils.getBundleMessage("MSG_RemoveInterfaces", homeInterface, componentInterface);
207
// } else {
208
// msg = Utils.getBundleMessage("MSG_RemoveInterfaces2", homeInterface, componentInterface,
209
// businessInterfaceName);
210
// }
211
String JavaDoc interfaceType = Utils.getBundleMessage(local ? "TXT_Local" : "TXT_Remote");
212         String JavaDoc title = Utils.getBundleMessage("LBL_RemoveInterfaces", interfaceType);
213 // NotifyDescriptor descriptor = new NotifyDescriptor(msg, title, NotifyDescriptor.YES_NO_OPTION,
214
// NotifyDescriptor.WARNING_MESSAGE, null, null);
215
// DialogDisplayer.getDefault().notify(descriptor);
216
// if (NotifyDescriptor.YES_OPTION == descriptor.getValue()) {
217
// try {
218
// helper.removeInterfaces(local);
219
// } finally {
220
// scheduleRefreshView();
221
// }
222
// }
223
}
224
225     public void refreshView() {
226         beanClassDocument.init();
227         localComponentDocument.init();
228         localHomeDocument.init();
229         remoteComponentDocument.init();
230         remoteHomeDocument.init();
231
232         String JavaDoc localComponent = helper.getLocal();
233         boolean isLocal = localComponent != null;
234         getLocalInterfaceCheckBox().setSelected(isLocal);
235         String JavaDoc remoteComponent = helper.getRemote();
236         boolean isRemote = remoteComponent != null;
237         getRemoteInterfaceCheckBox().setSelected(isRemote);
238     }
239
240     public void dataModelPropertyChange(Object JavaDoc source, String JavaDoc propertyName, Object JavaDoc oldValue, Object JavaDoc newValue) {
241         if (source instanceof EntityAndSession) {
242             scheduleRefreshView();
243         }
244     }
245
246     public void linkButtonPressed(Object JavaDoc ddBean, String JavaDoc ddProperty) {
247 // JavaClass javaClass;
248
// if(ddProperty == LINK_BEAN) {
249
// javaClass = helper.getBeanClass();
250
// } else if(ddProperty == LINK_LOCAL) {
251
// javaClass = helper.getLocalBusinessInterfaceClass();
252
// } else if(ddProperty == LINK_LOCAL_HOME) {
253
// javaClass = helper.getLocalHomeInterfaceClass();
254
// } else if(ddProperty == LINK_REMOTE) {
255
// javaClass = helper.getRemoteBusinessInterfaceClass();
256
// } else if (ddProperty == LINK_REMOTE_HOME) {
257
// javaClass = helper.getHomeInterfaceClass();
258
// } else {
259
// javaClass = null;
260
// }
261
// if (javaClass != null) {
262
// Utils.openEditorFor(helper.ejbJarFile, javaClass);
263
// }
264
}
265
266 }
267
Popular Tags