001: /*
002: * The contents of this file are subject to the terms of the Common Development
003: * and Distribution License (the License). You may not use this file except in
004: * compliance with the License.
005: *
006: * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
007: * or http://www.netbeans.org/cddl.txt.
008: *
009: * When distributing Covered Code, include this CDDL Header Notice in each file
010: * and include the License file at http://www.netbeans.org/cddl.txt.
011: * If applicable, add the following below the CDDL Header, with the fields
012: * enclosed by brackets [] replaced by your own identifying information:
013: * "Portions Copyrighted [year] [name of copyright owner]"
014: *
015: * The Original Software is NetBeans. The Initial Developer of the Original
016: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
017: * Microsystems, Inc. All Rights Reserved.
018: */
019:
020: package org.netbeans.modules.xslt.tmap.nodes;
021:
022: import java.awt.datatransfer.DataFlavor;
023: import java.awt.datatransfer.Transferable;
024: import java.awt.datatransfer.UnsupportedFlavorException;
025: import java.io.IOException;
026: import java.util.ArrayList;
027: import java.util.List;
028: import org.netbeans.modules.xml.xam.ui.ComponentPasteType;
029: import org.netbeans.modules.xslt.tmap.model.api.Operation;
030: import org.netbeans.modules.xslt.tmap.model.api.Service;
031: import org.netbeans.modules.xslt.tmap.model.api.TMapComponent;
032: import org.netbeans.modules.xslt.tmap.model.api.TMapModel;
033: import org.netbeans.modules.xslt.tmap.nodes.properties.PropertyType;
034: import org.netbeans.modules.xslt.tmap.nodes.properties.PropertyUtils;
035: import org.openide.nodes.Children;
036: import org.openide.nodes.Node;
037: import org.openide.nodes.Sheet;
038: import org.openide.util.Exceptions;
039: import org.openide.util.Lookup;
040: import org.openide.util.NbBundle;
041: import org.openide.util.datatransfer.NewType;
042: import org.openide.util.datatransfer.PasteType;
043:
044: /**
045: *
046: * @author Vitaly Bychkov
047: * @version 1.0
048: */
049: public class ServiceNode extends TMapComponentNode<DecoratedService> {
050:
051: public ServiceNode(Service ref, Lookup lookup) {
052: this (ref, Children.LEAF, lookup);
053: }
054:
055: public ServiceNode(Service ref, Children children, Lookup lookup) {
056: super (new DecoratedService(ref), children, lookup);
057: }
058:
059: // @Override
060: // protected void createPasteTypes(Transferable t, List<PasteType> s) {
061: //// super.createPasteTypes(t, s);
062: // System.out.println("getted transferable: "+t);
063: // DataFlavor[] dataFlavors = t.getTransferDataFlavors();
064: // int i =0;
065: // for (DataFlavor dataFlavor : dataFlavors) {
066: // try {
067: // i++;
068: // System.out.println(i + ") currentDataFlavor: "
069: // + dataFlavor + "; transferedData: "
070: // + t.getTransferData(dataFlavor));
071: // } catch (UnsupportedFlavorException ex) {
072: // System.out.println("unsupproted dataFlavor");
073: // } catch (IOException ex) {
074: // System.out.println("ioexception when try to get transfered data");
075: // }
076: // }
077: //
078: //
079: //
080: //
081: // }
082:
083: protected Sheet createSheet() {
084: Sheet sheet = super .createSheet();
085: if (getReference() == null) {
086: // The related object has been removed!
087: return sheet;
088: }
089: //
090: Sheet.Set mainPropertySet = getPropertySet(sheet);
091: //
092: Node.Property prop;
093: prop = PropertyUtils.registerProperty(this , mainPropertySet,
094: PropertyType.PARTNER_LINK_TYPE, "getPartnerLinkType",
095: "setPartnerLinkType"); // NOI18N
096: prop.setValue("canEditAsText", Boolean.FALSE); // NOI18N
097: //
098: prop = PropertyUtils.registerProperty(this , mainPropertySet,
099: PropertyType.ROLE, "getRole", "setRole"); // NOI18N
100: prop.setValue("canEditAsText", Boolean.FALSE); // NOI18N
101: //
102: //
103: return sheet;
104: }
105:
106: //
107: // @Override
108: // protected void createPasteTypes(Transferable transferable, List<PasteType> list) {
109: // System.out.println("getted transferable: "+transferable);
110: // DataFlavor[] dataFlavors = transferable.getTransferDataFlavors();
111: // int i =0;
112: // for (DataFlavor dataFlavor : dataFlavors) {
113: // try {
114: // i++;
115: // System.out.println(i + ") currentDataFlavor: "
116: // + dataFlavor + "; transferedData: "
117: // + transferable.getTransferData(dataFlavor));
118: // } catch (UnsupportedFlavorException ex) {
119: // System.out.println("unsupproted dataFlavor");
120: // } catch (IOException ex) {
121: // System.out.println("ioexception when try to get transfered data");
122: // }
123: // }
124: //
125: // // Make sure this node is still valid.
126: // TMapComponent component = getComponentRef();
127: //
128: // if (component != null && component.getModel() != null && isEditable()) {
129: // PasteType type = ComponentPasteType.getPasteType(
130: // component, transferable, null);
131: // System.out.println("pasteType::: "+type);
132: // if (type != null) {
133: // list.add(type);
134: // }
135: // }
136: // }
137: //
138: // @Override
139: // public PasteType getDropType(Transferable transferable, int action, int index) {
140: // // Make sure this node is still valid.
141: // TMapComponent component = getComponentRef();
142: //
143: // if (component != null && component.getModel() != null && isEditable()) {
144: // PasteType type = ComponentPasteType.getDropType(
145: // component, transferable, null, action, index);
146: // System.out.println("drop type: "+type);
147: // if (type != null) {
148: // return type;
149: // }
150: // }
151: // return null;
152: // }
153: //
154: //
155: //
156: // private class OperationPasteType extends PasteType {
157: //
158: // @Override
159: // public Transferable paste() throws IOException {
160: // System.out.println("try to perform paste operation");
161: //
162: // return null;
163: // }
164: // }
165:
166: @Override
167: public NewType[] getNewTypes() {
168: if (isEditable()) {
169: return getNewTypes(getComponentRef());
170: }
171: return new NewType[] {};
172: }
173:
174: public NewType[] getNewTypes(TMapComponent newComponent) {
175:
176: List<NewType> list = new ArrayList<NewType>();
177:
178: if (newComponent instanceof Service) {
179: list.add(new OperationNewType((Service) newComponent));
180: }
181:
182: return list.toArray(new NewType[] {});
183: }
184:
185: public static class OperationNewType extends NewType {
186:
187: private Service myService;
188:
189: OperationNewType(Service service) {
190: myService = service;
191: }
192:
193: @Override
194: public String getName() {
195: return NbBundle.getMessage(TMapComponentNode.class,
196: "LBL_NewOperationAction"); // NOI18N
197: }
198:
199: @Override
200: public void create() throws IOException {
201: TMapModel model = myService.getModel();
202: model.startTransaction();
203: // String operationOutputName = NameGenerator.getInstance().generateUniqueOperationOutputName(mOperation);
204: Operation operation = model.getFactory().createOperation();
205: // output.setName(operationOutputName);
206: // mOperation.setOutput(output);
207: myService.addOperation(operation);
208: model.endTransaction();
209: // ActionHelper.selectNode(operation);
210: }
211: }
212:
213: }
|