001: /*
002: * The contents of this file are subject to the terms of the Common
003: * Development
004: The contents of this file are subject to the terms of either the GNU
005: General Public License Version 2 only ("GPL") or the Common
006: Development and Distribution License("CDDL") (collectively, the
007: "License"). You may not use this file except in compliance with the
008: License. You can obtain a copy of the License at
009: http://www.netbeans.org/cddl-gplv2.html
010: or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
011: specific language governing permissions and limitations under the
012: License. When distributing the software, include this License Header
013: Notice in each file and include the License file at
014: nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
015: particular file as subject to the "Classpath" exception as provided
016: by Sun in the GPL Version 2 section of the License file that
017: accompanied this code. If applicable, add the following below the
018: License Header, with the fields enclosed by brackets [] replaced by
019: your own identifying information:
020: "Portions Copyrighted [year] [name of copyright owner]"
021: Contributor(s):
022: *
023: * Copyright 2006 Sun Microsystems, Inc. All Rights Reserved
024: If you wish your version of this file to be governed by only the CDDL
025: or only the GPL Version 2, indicate your decision by adding
026: "[Contributor] elects to include this software in this distribution
027: under the [CDDL or GPL Version 2] license." If you do not indicate a
028: single choice of license, a recipient has the option to distribute
029: your version of this file under either the CDDL, the GPL Version 2 or
030: to extend the choice of license to its licensees as provided above.
031: However, if you add GPL Version 2 code and therefore, elected the GPL
032: Version 2 license, then the option applies only if the new code is
033: made subject to such option by the copyright holder.
034: *
035: */
036: package org.netbeans.modules.etl.ui.palette;
037:
038: import java.awt.Point;
039: import java.awt.datatransfer.DataFlavor;
040: import java.awt.datatransfer.UnsupportedFlavorException;
041: import java.awt.event.ActionEvent;
042: import java.beans.PropertyChangeEvent;
043: import java.beans.PropertyChangeListener;
044: import java.io.IOException;
045: import javax.swing.Action;
046: import org.netbeans.modules.etl.ui.view.ETLCollaborationTopPanel;
047: import org.netbeans.modules.sql.framework.ui.graph.IGraphView;
048: import org.netbeans.modules.sql.framework.ui.graph.IOperatorXmlInfo;
049: import org.netbeans.modules.sql.framework.ui.graph.impl.OperatorXmlInfoModel;
050: import org.netbeans.spi.palette.DragAndDropHandler;
051: import org.netbeans.spi.palette.PaletteActions;
052: import org.netbeans.spi.palette.PaletteController;
053: import org.netbeans.spi.palette.PaletteFactory;
054: import org.openide.nodes.Node;
055: import org.openide.util.Lookup;
056: import org.openide.util.datatransfer.ExTransferable;
057:
058: /**
059: *
060: * @author nithya
061: */
062: public class PaletteSupport {
063:
064: public static final String MASHUP_DATA_FLAVOR = DataFlavor.javaJVMLocalObjectMimeType;
065: private static PaletteController controller;
066: private static IGraphView graphView;
067:
068: public PaletteSupport() {
069: }
070:
071: /**
072: *
073: * @return
074: */
075: public static PaletteController createPalette(
076: final ETLCollaborationTopPanel etlPanel) throws IOException {
077: controller = PaletteFactory.createPalette("ETLOperators",
078: new ETLAction(), null, new ETLDnDHandler());
079: controller
080: .addPropertyChangeListener(new PropertyChangeListener() {
081:
082: // FIXME: There should be a better way to do this.
083: ETLCollaborationTopPanel topPanel = etlPanel;
084:
085: public void propertyChange(PropertyChangeEvent evt) {
086: if (PaletteController.PROP_SELECTED_ITEM
087: .equals(evt.getPropertyName())) {
088: Lookup selItem = controller
089: .getSelectedItem();
090:
091: graphView = topPanel.getGraphView();
092: if (null != selItem) {
093: Node selNode = selItem
094: .lookup(Node.class);
095: if (null != selNode) {
096: IOperatorXmlInfo opXmlInfo = OperatorXmlInfoModel
097: .getInstance("ETLOperators")
098: .findOperatorXmlInfo(
099: selNode.getName());
100: graphView.setXMLInfo(opXmlInfo);
101: }
102: }
103: }
104: }
105: });
106: return controller;
107: }
108:
109: public static class ETLAction extends PaletteActions {
110:
111: /**
112: *
113: * @return
114: */
115: public Action[] getImportActions() {
116: return new Action[0];
117: }
118:
119: /**
120: *
121: * @return
122: */
123: public Action[] getCustomPaletteActions() {
124: return new Action[0];
125: }
126:
127: /**
128: *
129: * @param lookup
130: * @return
131: */
132: public Action[] getCustomCategoryActions(Lookup lookup) {
133: return new Action[0];
134: }
135:
136: /**
137: *
138: * @param lookup
139: * @return
140: */
141: public Action[] getCustomItemActions(Lookup lookup) {
142: return new Action[0];
143: }
144:
145: /**
146: *
147: * @param lookup
148: * @return
149: */
150: public Action getPreferredAction(Lookup lookup) {
151: return new PreferredAction(lookup);
152: }
153: }
154:
155: public static class PreferredAction implements Action {
156:
157: private IOperatorXmlInfo opXmlInfo = null;
158:
159: // FIXME: There should be a better way to do this.
160: public PreferredAction(Lookup lookup) {
161: Node node = lookup.lookup(Node.class);
162: if (null != node) {
163: opXmlInfo = OperatorXmlInfoModel.getInstance(
164: "ETLOperators").findOperatorXmlInfo(
165: node.getName());
166: graphView.setXMLInfo(opXmlInfo);
167: }
168: }
169:
170: public static String getSHORT_DESCRIPTION() {
171: return SHORT_DESCRIPTION;
172: }
173:
174: public Object getValue(String key) {
175: throw new UnsupportedOperationException(
176: "Not supported yet.");
177: }
178:
179: public void putValue(String key, Object value) {
180: throw new UnsupportedOperationException(
181: "Not supported yet.");
182: }
183:
184: public void setEnabled(boolean b) {
185: throw new UnsupportedOperationException(
186: "Not supported yet.");
187: }
188:
189: public boolean isEnabled() {
190: return true;
191: }
192:
193: public void addPropertyChangeListener(
194: PropertyChangeListener listener) {
195: throw new UnsupportedOperationException(
196: "Not supported yet.");
197: }
198:
199: public void removePropertyChangeListener(
200: PropertyChangeListener listener) {
201: throw new UnsupportedOperationException(
202: "Not supported yet.");
203: }
204:
205: public void actionPerformed(ActionEvent e) {
206: Point viewCoord = new Point();
207: if (graphView.getGraphController() != null) {
208: graphView.getGraphController().handleNodeAdded(
209: opXmlInfo, viewCoord);
210: }
211: }
212: }
213:
214: private static class ETLDnDHandler extends DragAndDropHandler {
215:
216: public void customize(ExTransferable exTransferable,
217: Lookup lookupobj) {
218: final Node node = lookupobj.lookup(Node.class);
219: DataFlavor flv = null;
220: try {
221: flv = new DataFlavor(
222: DataFlavor.javaJVMLocalObjectMimeType);
223: } catch (ClassNotFoundException ex) {
224: ex.printStackTrace();
225: }
226: exTransferable.put(new ExTransferable.Single(flv) {
227:
228: protected Object getData() throws IOException,
229: UnsupportedFlavorException {
230: return node;
231: }
232: });
233: }
234: }
235: }
|