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: package org.netbeans.modules.compapp.casaeditor.nodes;
043:
044: import java.awt.Image;
045: import java.awt.Point;
046: import java.awt.Rectangle;
047: import java.awt.event.ActionEvent;
048: import java.io.IOException;
049: import java.lang.ref.WeakReference;
050: import java.util.List;
051: import javax.swing.AbstractAction;
052: import javax.swing.Action;
053: import org.netbeans.api.project.Project;
054: import org.netbeans.api.visual.widget.Widget;
055: import org.netbeans.modules.compapp.casaeditor.design.CasaModelGraphScene;
056: import org.netbeans.modules.compapp.casaeditor.model.casa.CasaComponent;
057: import org.netbeans.modules.compapp.casaeditor.model.casa.CasaWrapperModel;
058: import org.netbeans.modules.compapp.casaeditor.nodes.actions.AddWSDLPortsAction;
059: import org.netbeans.modules.compapp.casaeditor.nodes.actions.AutoLayoutAction;
060: import org.netbeans.modules.compapp.casaeditor.nodes.actions.AddExternalServiceUnitAction;
061: import org.netbeans.modules.compapp.casaeditor.nodes.actions.LoadWSDLPortsAction;
062: import org.netbeans.modules.compapp.casaeditor.nodes.actions.AddJBIModuleAction;
063: import org.netbeans.modules.compapp.casaeditor.properties.LookAndFeelProperty;
064: import org.netbeans.modules.compapp.casaeditor.properties.PropertyUtils;
065: import org.netbeans.modules.compapp.projects.jbi.ui.actions.AddProjectAction;
066: import org.openide.ErrorManager;
067: import org.openide.loaders.DataObject;
068: import org.openide.nodes.Node;
069: import org.openide.nodes.Sheet;
070: import org.openide.util.NbBundle;
071: import org.openide.util.Utilities;
072: import org.openide.util.actions.SystemAction;
073:
074: /**
075: *
076: * @author Josh Sandusky
077: */
078: public class CasaRootNode extends CasaNode {
079:
080: private static final Image ICON = Utilities
081: .loadImage("org/netbeans/modules/compapp/casaeditor/nodes/resources/CasaRootNode.png"); // NOI18N
082:
083: private static final String CHILD_ID_WSDL_ENDPOINTS = "WSDLEndpoints"; // NOI18N
084: private static final String CHILD_ID_SERVICE_ENGINES = "ServiceEngines"; // NOI18N
085: private static final String CHILD_ID_CONNECTIONS = "Connections"; // NOI18N
086:
087: private static final String[] CHILD_TYPES = {
088: CHILD_ID_WSDL_ENDPOINTS, CHILD_ID_SERVICE_ENGINES,
089: CHILD_ID_CONNECTIONS };
090:
091: public CasaRootNode(Object data, CasaNodeFactory factory) {
092: super (data, new MyChildren(data, factory), factory);
093: }
094:
095: public String getName() {
096: DataObject dataObject = getDataObject();
097: if (dataObject != null) {
098: return dataObject.getName();
099: }
100: return NbBundle.getMessage(getClass(), "LBL_CasaModel"); // NOI18N
101: }
102:
103: protected void setupPropertySheet(Sheet sheet) {
104: final CasaWrapperModel model = (CasaWrapperModel) getData();
105: if (model == null) {
106: return;
107: }
108:
109: Sheet.Set mainPropertySet = getPropertySet(sheet,
110: PropertyUtils.PropertiesGroups.MAIN_SET);
111:
112: String propertyName = NbBundle.getMessage(
113: LookAndFeelProperty.class, "LBL_LookAndFeel"); // NOI18N
114: try {
115: Node.Property property = new LookAndFeelProperty(this );
116: mainPropertySet.put(property);
117: } catch (Exception e) {
118: mainPropertySet.put(PropertyUtils
119: .createErrorProperty(propertyName));
120: ErrorManager.getDefault().notify(e);
121: }
122: }
123:
124: public Image getIcon(int type) {
125: return ICON;
126: }
127:
128: public Image getOpenedIcon(int type) {
129: return ICON;
130: }
131:
132: public boolean isValidSceneActionForLocation(Action action,
133: Widget widget, Point sceneLocation) {
134: if (action instanceof AddJBIModuleAction) {
135: CasaModelGraphScene scene = (CasaModelGraphScene) widget
136: .getScene();
137: Widget engineRegion = scene.getEngineRegion();
138: Rectangle engineRegionRect = engineRegion
139: .convertLocalToScene(new Rectangle(engineRegion
140: .getBounds().width, engineRegion
141: .getBounds().height));
142: if (engineRegionRect.contains(sceneLocation)) {
143: return true;
144: }
145: return false;
146: }
147:
148: else if ((action instanceof AddWSDLPortsAction)
149: || (action instanceof LoadWSDLPortsAction)) {
150: CasaModelGraphScene scene = (CasaModelGraphScene) widget
151: .getScene();
152: Widget bindingRegion = scene.getBindingRegion();
153: Rectangle bindingRegionRect = bindingRegion
154: .convertLocalToScene(new Rectangle(bindingRegion
155: .getBounds().width, bindingRegion
156: .getBounds().height));
157: if (bindingRegionRect.contains(sceneLocation)) {
158: return true;
159: }
160: return false;
161: }
162:
163: else if (action instanceof AddExternalServiceUnitAction) {
164: CasaModelGraphScene scene = (CasaModelGraphScene) widget
165: .getScene();
166: Widget externalRegion = scene.getExternalRegion();
167: Rectangle externalRegionRect = externalRegion
168: .convertLocalToScene(new Rectangle(externalRegion
169: .getBounds().width, externalRegion
170: .getBounds().height));
171: if (externalRegionRect.contains(sceneLocation)) {
172: return true;
173: }
174: return false;
175: }
176:
177: return true;
178: }
179:
180: protected void addCustomActions(List<Action> actions) {
181: final Project jbiProject = getModel().getJBIProject();
182: actions.add(new AddJBIModuleAction(jbiProject));
183: actions.add(SystemAction.get(LoadWSDLPortsAction.class));
184: actions.add(SystemAction.get(AddWSDLPortsAction.class));
185: actions.add(SystemAction
186: .get(AddExternalServiceUnitAction.class));
187: actions.add(null);
188: actions.add(new AutoLayoutAction(getDataObject()));
189: }
190:
191: private static class MyChildren extends CasaNodeChildren<String> {
192: private WeakReference mReference;
193:
194: public MyChildren(Object data, CasaNodeFactory factory) {
195: super (data, factory);
196: mReference = new WeakReference<Object>(data);
197: }
198:
199: protected Node[] createNodes(String keyName) {
200: if (mReference.get() != null) {
201: try {
202: CasaWrapperModel model = (CasaWrapperModel) mReference
203: .get();
204: if (keyName.equals(CHILD_ID_WSDL_ENDPOINTS)) {
205: return new Node[] { mNodeFactory
206: .createNode_portList(model
207: .getCasaPorts()) };
208: } else if (keyName.equals(CHILD_ID_SERVICE_ENGINES)) {
209: return new Node[] { mNodeFactory
210: .createNode_suList(model
211: .getServiceEngineServiceUnits()) };
212: } else if (keyName.equals(CHILD_ID_CONNECTIONS)) {
213: return new Node[] { mNodeFactory
214: .createNode_connectionList(model
215: .getCasaConnectionList(false)) };
216: }
217: } catch (Exception e) {
218: ErrorManager.getDefault().notify(e);
219: }
220: }
221: return null;
222: }
223:
224: public Object getChildKeys(Object data) {
225: return CHILD_TYPES;
226: }
227: }
228: }
|