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: package org.netbeans.modules.sql.framework.ui.view.graph;
042:
043: import java.awt.Frame;
044: import java.util.List;
045: import org.netbeans.modules.sql.framework.ui.graph.IGraphController;
046: import org.netbeans.modules.sql.framework.ui.graph.IGraphView;
047: import org.netbeans.modules.sql.framework.ui.graph.IOperatorManager;
048: import org.netbeans.modules.sql.framework.ui.graph.IToolBar;
049: import org.netbeans.modules.sql.framework.ui.graph.view.impl.SQLToolBar;
050: import org.netbeans.modules.sql.framework.ui.graph.view.impl.OperatorPaletteDialog;
051: import org.netbeans.modules.sql.framework.ui.graph.view.impl.OperatorSelectionPanel;
052: import org.netbeans.modules.sql.framework.ui.model.SQLUIModel;
053: import org.openide.nodes.Node;
054: import org.openide.windows.WindowManager;
055:
056: /**
057: * Abstract factory for creating SQL graph view objects.
058: *
059: * @author Ritesh Adval
060: * @author Jonathan Giron
061: * @version $Revision$
062: */
063: public abstract class AbstractSQLViewFactory implements
064: IOperatorManager {
065:
066: private OperatorSelectionPanel panel;
067: protected int toolbarType;
068:
069: /**
070: * create a graph view
071: *
072: * @return graph view
073: */
074: public abstract IGraphView createGraphView();
075:
076: /**
077: * create a tool bar
078: *
079: * @return tool bar
080: */
081: public abstract IToolBar createToolBar();
082:
083: /**
084: * create a graph controller
085: *
086: * @return
087: */
088: public abstract IGraphController createGraphController();
089:
090: /**
091: * get SQL model
092: *
093: * @return SQL model
094: */
095: public abstract SQLUIModel getSQLModel();
096:
097: /**
098: * get graph view container
099: *
100: * @return graph view container
101: */
102: public abstract Object getGraphViewContainer();
103:
104: /**
105: * get graph view pop up actions
106: *
107: * @return actions
108: */
109: public abstract List getGraphActions();
110:
111: /**
112: * return toolbar actions
113: *
114: * @return toolbar actions
115: */
116: public abstract List getToolBarActions();
117:
118: /**
119: * call this to setup relation between graph view, graph view container, toolbar,
120: * controller and model
121: */
122:
123: IGraphView graphView = null;
124:
125: public void setUp() {
126: IGraphController controller = createGraphController();
127: SQLUIModel model = getSQLModel();
128:
129: //set up graph view
130: graphView = createGraphView();
131: if (graphView != null) {
132: graphView.setGraphController(controller);
133: graphView.setGraphModel(getSQLModel());
134:
135: graphView.setGraphViewContainer(getGraphViewContainer());
136: graphView.setGraphActions(getGraphActions());
137: }
138: //set up controller
139: if (controller != null) {
140: controller.setDataModel(model);
141: controller.setView(graphView);
142: }
143: }
144:
145: public void setToolBar() {
146: setUp();
147: //set up toolbar
148: IToolBar toolBar = createToolBar();
149: if (toolBar != null) {
150: toolBar.setGraphView(graphView);
151: toolBar.setActions(getToolBarActions());
152: toolBar.initializeToolBar();
153: //set toolbar on graph
154: if (graphView != null) {
155: graphView.setToolBar(toolBar);
156: }
157: }
158: }
159:
160: public void setSQLToolBar() {
161: setUp();
162: //set up toolbar
163: IToolBar toolBar = createToolBar();
164: if (toolBar != null) {
165: toolBar.setGraphView(graphView);
166: toolBar.setActions(getToolBarActions());
167: toolBar.initializeToolBar();
168: SQLToolBar sqlToolBar = (SQLToolBar) toolBar;
169: sqlToolBar.initializeSQLToolBar();
170: //set toolbar on graph
171: if (graphView != null) {
172: graphView.setToolBar(toolBar);
173: graphView.setToolBar(sqlToolBar);
174: }
175: }
176: }
177:
178: /**
179: * Show the operator palette dialog, initially displaying the category panel
180: * associated with the given node.
181: *
182: * @param node operator node whose category panel will be initially displayed in the
183: * selection dialog.
184: */
185: public void show(Node node) {
186: if (panel == null) {
187: panel = new OperatorSelectionPanel(this .getGraphView(),
188: getOperatorXmlInfoModel(), toolbarType);
189: }
190:
191: panel.selectCategory(node.getDisplayName());
192:
193: Frame f = WindowManager.getDefault().getMainWindow();
194:
195: OperatorPaletteDialog dlg = new OperatorPaletteDialog(f, panel);
196: dlg.pack();
197:
198: dlg.showDialog(f);
199: }
200:
201: /**
202: * Returns toolbar type.
203: *
204: * @return toolbar type
205: */
206: public int getToolbarType() {
207: return this.toolbarType;
208: }
209: }
|