001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common
008: * Development and Distribution License("CDDL") (collectively, the
009: * "License"). You may not use this file except in compliance with the
010: * License. You can obtain a copy of the License at
011: * http://www.netbeans.org/cddl-gplv2.html
012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013: * specific language governing permissions and limitations under the
014: * License. When distributing the software, include this License Header
015: * Notice in each file and include the License file at
016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
017: * particular file as subject to the "Classpath" exception as provided
018: * by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the
020: * License Header, with the fields enclosed by brackets [] replaced by
021: * your own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * Contributor(s):
025: *
026: * The Original Software is NetBeans. The Initial Developer of the Original
027: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
028: * Microsystems, Inc. All Rights Reserved.
029: *
030: * If you wish your version of this file to be governed by only the CDDL
031: * or only the GPL Version 2, indicate your decision by adding
032: * "[Contributor] elects to include this software in this distribution
033: * under the [CDDL or GPL Version 2] license." If you do not indicate a
034: * single choice of license, a recipient has the option to distribute
035: * your version of this file under either the CDDL, the GPL Version 2 or
036: * to extend the choice of license to its licensees as provided above.
037: * However, if you add GPL Version 2 code and therefore, elected the GPL
038: * Version 2 license, then the option applies only if the new code is
039: * made subject to such option by the copyright holder.
040: */
041: /*
042: * EjbGroupNode.java
043: *
044: * Created on May 3, 2004, 10:54 PM
045: */
046:
047: package org.netbeans.modules.visualweb.ejb.nodes;
048:
049: import org.netbeans.modules.visualweb.ejb.actions.ConfigureMethodsAction;
050: import org.netbeans.modules.visualweb.ejb.actions.DeleteEjbGroupAction;
051: import org.netbeans.modules.visualweb.ejb.actions.ExportEjbDataSourceAction;
052: import org.netbeans.modules.visualweb.ejb.actions.ModifyEjbGroupAction;
053: import org.netbeans.modules.visualweb.ejb.actions.RefreshEjbGroupAction;
054: import org.netbeans.modules.visualweb.ejb.datamodel.EjbDataModel;
055: import org.netbeans.modules.visualweb.ejb.datamodel.EjbGroup;
056: import java.awt.Image;
057: import java.beans.PropertyChangeEvent;
058: import java.beans.PropertyChangeListener;
059: import java.io.IOException;
060: import java.util.*;
061: import javax.swing.Action;
062: import org.openide.DialogDisplayer;
063: import org.openide.NotifyDescriptor;
064: import org.openide.nodes.AbstractNode;
065: import org.openide.nodes.Node;
066: import org.openide.nodes.Sheet.Set;
067: import org.openide.nodes.Sheet;
068: import org.openide.nodes.PropertySupport;
069: import org.openide.util.HelpCtx;
070: import org.openide.util.NbBundle;
071: import org.openide.util.Utilities;
072: import org.openide.util.actions.SystemAction;
073:
074: /**
075: * This node represents one EJB Group
076: *
077: * @author cao
078: */
079: public class EjbGroupNode extends AbstractNode implements
080: PropertyChangeListener, Node.Cookie {
081: private EjbGroup ejbGroup;
082:
083: /** Creates a new instance of EjbGroupNode */
084: public EjbGroupNode(EjbGroup ejbGroup) {
085: super (new EjbGroupNodeChildren(ejbGroup));
086: this .ejbGroup = ejbGroup;
087:
088: setName(ejbGroup.getName());
089: setDisplayName(ejbGroup.getName());
090: setShortDescription(ejbGroup.getName());
091: }
092:
093: // Create the popup menu for the EJB group node
094: public Action[] getActions(boolean context) {
095: return new Action[] {
096: SystemAction.get(RefreshEjbGroupAction.class),
097: SystemAction.get(ModifyEjbGroupAction.class),
098: SystemAction.get(DeleteEjbGroupAction.class),
099: SystemAction.get(ConfigureMethodsAction.class), null,
100: SystemAction.get(ExportEjbDataSourceAction.class), };
101: }
102:
103: public HelpCtx getHelpCtx() {
104: return new HelpCtx("projrave_ui_elements_server_nav_ejb_node");
105: }
106:
107: public Image getIcon(int type) {
108: Image image1 = Utilities
109: .loadImage("org/netbeans/modules/visualweb/ejb/resources/ejbSetFolder.png");
110: Image image2 = Utilities
111: .loadImage("org/netbeans/modules/visualweb/ejb/resources/archive_container_8x8.png");
112: int x = image1.getWidth(null) - image2.getWidth(null);
113: int y = image1.getHeight(null) - image2.getHeight(null);
114: return Utilities.mergeImages(image1, image2, x, y);
115: }
116:
117: public Image getOpenedIcon(int type) {
118: Image image1 = Utilities
119: .loadImage("org/netbeans/modules/visualweb/ejb/resources/ejbSetOpenFolder.png");
120: Image image2 = Utilities
121: .loadImage("org/netbeans/modules/visualweb/ejb/resources/archive_container_8x8.png");
122: int x = image1.getWidth(null) - image2.getWidth(null);
123: int y = image1.getHeight(null) - image2.getHeight(null);
124: return Utilities.mergeImages(image1, image2, x, y);
125: }
126:
127: protected EjbGroupNodeChildren getEjbGroupNodeChildren() {
128: return (EjbGroupNodeChildren) getChildren();
129: }
130:
131: public EjbGroup getEjbGroup() {
132: return this .ejbGroup;
133: }
134:
135: protected Sheet createSheet() {
136: Sheet sheet = super .createSheet();
137: Set ss = sheet.get("ejbGroup"); // NOI18N
138:
139: if (ss == null) {
140: ss = new Set();
141: ss.setName("ejbGroup"); // NOI18N
142: ss.setDisplayName(NbBundle.getMessage(EjbGroupNode.class,
143: "EJB_GROUP_INFORMATION"));
144: ss.setShortDescription(NbBundle.getMessage(
145: EjbGroupNode.class, "EJB_GROUP_INFORMATION"));
146: sheet.put(ss);
147: }
148:
149: // Name is read-writable.
150: // Need to make sure name is not empty
151: ss.put(new PropertySupport.ReadWrite("name", // NOI18N
152: String.class, NbBundle.getMessage(EjbGroupNode.class,
153: "EJB_GROUP_NAME"), NbBundle.getMessage(
154: EjbGroupNode.class, "EJB_GROUP_NAME")) {
155: public Object getValue() {
156: return ejbGroup.getName();
157: }
158:
159: public void setValue(Object val) {
160:
161: StringBuffer msg = new StringBuffer();
162: boolean valid = true;
163: if (((String) val) == null
164: || ((String) val).length() == 0) {
165: msg.append(NbBundle.getMessage(EjbGroupNode.class,
166: "EMPTY_GROUP_NAME"));
167: valid = false;
168: } else {
169: // Check uniqueness
170: if (EjbDataModel.getInstance().getEjbGroup(
171: (String) val) != null) {
172: msg.append(NbBundle.getMessage(
173: EjbGroupNode.class, "NAME_NOT_UNIQUE",
174: "\'" + (String) val + "\'"));
175: valid = false;
176: }
177: }
178:
179: if (!valid) {
180: NotifyDescriptor d = new NotifyDescriptor.Message(
181: msg.toString(),
182: NotifyDescriptor.ERROR_MESSAGE);
183: DialogDisplayer.getDefault().notify(d);
184: } else {
185: if (!ejbGroup.getName().equals((String) val)) {
186: ejbGroup.setName((String) val);
187: EjbDataModel.getInstance().touchModifiedFlag();
188: }
189: }
190: }
191:
192: });
193:
194: // App Server type is read only
195: ss.put(new PropertySupport.ReadOnly("containerType", // NOI18N
196: String.class, NbBundle.getMessage(EjbGroupNode.class,
197: "APP_SERVER_TYPE"), NbBundle.getMessage(
198: EjbGroupNode.class, "APP_SERVER_TYPE")) {
199: public Object getValue() {
200: return ejbGroup.getAppServerVendor();
201: }
202: });
203:
204: // server host is read-writable
205: // Need to make sure the server host is not empty and do not contain any spaces
206: ss.put(new PropertySupport.ReadWrite("serverHost", // NOI18N
207: String.class, NbBundle.getMessage(EjbGroupNode.class,
208: "APP_SERVER_HOST"), NbBundle.getMessage(
209: EjbGroupNode.class, "APP_SERVER_HOST")) {
210: public Object getValue() {
211: return ejbGroup.getServerHost();
212: }
213:
214: public void setValue(Object val) {
215:
216: // Make sure the server host is valid
217: StringBuffer msg = new StringBuffer();
218: boolean valid = true;
219: if (val == null || ((String) val).length() == 0) {
220: valid = false;
221: msg.append(NbBundle.getMessage(EjbGroupNode.class,
222: "EMPTY_SERVER_HOST"));
223: } else if (((String) val).trim().indexOf(" ") != -1) {
224: valid = false;
225: msg.append(NbBundle.getMessage(EjbGroupNode.class,
226: "SPACES_IN_SERVER_HOST", "\'"
227: + (String) val + "\'"));
228:
229: }
230:
231: if (!valid) {
232: NotifyDescriptor d = new NotifyDescriptor.Message(
233: msg.toString(),
234: NotifyDescriptor.ERROR_MESSAGE);
235: DialogDisplayer.getDefault().notify(d);
236: } else {
237:
238: // One more check, in case of the same client jar file is added in more than
239: // one ejb group, warn the user to modify the other groups too
240: EjbGroup cloneGrp = (EjbGroup) ejbGroup.clone();
241: cloneGrp.setServerHost((String) val);
242:
243: if (checkClientJarInfo(cloneGrp, true)) {
244: if (!ejbGroup.getServerHost().equals(
245: (String) val)) {
246: ejbGroup.setServerHost((String) val);
247: EjbDataModel.getInstance()
248: .touchModifiedFlag();
249: }
250: }
251: }
252: }
253: });
254:
255: // IIOP Port is read-writable.
256: // Need to make sure the iiop is not empty and it is a number
257: ss.put(new PropertySupport.ReadWrite("iiopPort", // NOI18N
258: String.class, NbBundle.getMessage(EjbGroupNode.class,
259: "IIOP_PORT"), NbBundle.getMessage(
260: EjbGroupNode.class, "IIOP_PORT")) {
261: public Object getValue() {
262: return Integer.toString(ejbGroup.getIIOPPort());
263: }
264:
265: public void setValue(Object val) {
266:
267: // Make sure the server host is valid
268: StringBuffer msg = new StringBuffer();
269: boolean valid = true;
270: if (val == null || ((String) val).length() == 0) {
271: valid = false;
272: msg.append(NbBundle.getMessage(EjbGroupNode.class,
273: "EMPTY_IIOP_PORT"));
274: } else { // Make it is a number
275: try {
276: int portNum = Integer.parseInt((String) val);
277: } catch (NumberFormatException ex) {
278: valid = false;
279: msg.append(NbBundle.getMessage(
280: EjbGroupNode.class,
281: "IIOP_PORT_NOT_NUMBER"));
282: }
283: }
284:
285: if (!valid) {
286: NotifyDescriptor d = new NotifyDescriptor.Message(
287: msg.toString(),
288: NotifyDescriptor.ERROR_MESSAGE);
289: DialogDisplayer.getDefault().notify(d);
290: } else {
291:
292: // One more check, in case of the same client jar file is added in more than
293: // one ejb group, warn the user to modify the other groups too
294: EjbGroup cloneGrp = (EjbGroup) ejbGroup.clone();
295: cloneGrp
296: .setIIOPPort(Integer.parseInt((String) val));
297:
298: if (checkClientJarInfo(cloneGrp, false)) {
299: if (ejbGroup.getIIOPPort() != Integer
300: .parseInt((String) val)) {
301: ejbGroup.setIIOPPort(Integer
302: .parseInt((String) val));
303: EjbDataModel.getInstance()
304: .touchModifiedFlag();
305: }
306: }
307: }
308: }
309: });
310:
311: // Client jars are read only
312: ss.put(new PropertySupport.ReadOnly("clientJarFileNames", // NOI18N
313: String.class, NbBundle.getMessage(EjbGroupNode.class,
314: "CLIENT_JARS"), NbBundle.getMessage(
315: EjbGroupNode.class, "CLIENT_JARS")) {
316: public Object getValue() {
317: return ejbGroup.getClientJarFilesAsOneStr();
318: }
319: });
320:
321: // The additional ear/jar for DDs. Read only
322: ss.put(new PropertySupport.ReadOnly("ddLocationFileName", // NOI18N
323: String.class, NbBundle.getMessage(EjbGroupNode.class,
324: "DD_JAR_FILE"), NbBundle.getMessage(
325: EjbGroupNode.class, "DD_JAR_FILE")) {
326: public Object getValue() {
327:
328: if (ejbGroup.getDDLocationFile() == null)
329: return NbBundle.getMessage(EjbGroupNode.class,
330: "NONE");
331: else
332: return ejbGroup.getDDLocationFile();
333: }
334: });
335:
336: // Need to listen on the properties change
337: // When the name gets changed, we need to change the node name to the new name
338: ejbGroup
339: .addPropertyChangeListener((PropertyChangeListener) this );
340:
341: return sheet;
342: }
343:
344: private boolean checkClientJarInfo(EjbGroup grp,
345: boolean isServerHost) {
346: ArrayList grpNames = new ArrayList();
347:
348: for (Iterator iter = grp.getClientJarFileNames().iterator(); iter
349: .hasNext();) {
350: String jar = (String) iter.next();
351:
352: Collection grps = EjbDataModel.getInstance()
353: .findEjbGroupsForJar(jar);
354:
355: for (Iterator grpIter = grps.iterator(); grpIter.hasNext();) {
356: EjbGroup existingGrpWithJar = (EjbGroup) grpIter.next();
357:
358: if (existingGrpWithJar != null
359: && (!existingGrpWithJar.getServerHost().equals(
360: grp.getServerHost()) || existingGrpWithJar
361: .getIIOPPort() != grp.getIIOPPort())) {
362: if (!grpNames
363: .contains(existingGrpWithJar.getName())
364: && !existingGrpWithJar.getName().equals(
365: grp.getName())) //Not itself
366: grpNames.add(existingGrpWithJar.getName());
367: }
368: }
369: }
370:
371: if (grpNames.size() != 0) {
372: // The server host and/or RMI-IIOP port modification will cause EJB Set {0} to
373: // contain incorrect information. Would like to preceed?
374: StringBuffer nameStr = new StringBuffer();
375: boolean first = true;
376: for (Iterator iter = grpNames.iterator(); iter.hasNext();) {
377: if (first)
378: first = false;
379: else
380: nameStr.append(", ");
381:
382: nameStr.append((String) iter.next());
383:
384: }
385: String msg = null;
386:
387: if (isServerHost)
388: msg = NbBundle.getMessage(EjbGroupNode.class,
389: "MISMATH_HOST_INFO_JAR_Q", nameStr.toString());
390: else
391: msg = NbBundle.getMessage(EjbGroupNode.class,
392: "MISMATH_PORT_INFO_JAR_Q", nameStr.toString());
393:
394: NotifyDescriptor confDialog = new NotifyDescriptor.Confirmation(
395: msg, NotifyDescriptor.OK_CANCEL_OPTION);
396: if (!(DialogDisplayer.getDefault().notify(confDialog) == NotifyDescriptor.OK_OPTION))
397: return false;
398: else
399: return true;
400: } else
401: return true;
402: }
403:
404: public boolean canDestroy() {
405: return true;
406: }
407:
408: public void destroy() throws IOException {
409:
410: EjbDataModel.getInstance().removeEjbGroup(ejbGroup);
411: super .destroy();
412: }
413:
414: public void propertyChange(PropertyChangeEvent evt) {
415: // Set the name to the new name the user just change to
416: setName((String) evt.getNewValue());
417: }
418: }
|