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.conditionbuilder;
042:
043: import java.util.ArrayList;
044: import java.util.List;
045:
046: import javax.swing.undo.UndoManager;
047:
048: import org.netbeans.modules.sql.framework.ui.graph.IGraphController;
049: import org.netbeans.modules.sql.framework.ui.graph.IGraphView;
050: import org.netbeans.modules.sql.framework.ui.graph.IOperatorXmlInfoModel;
051: import org.netbeans.modules.sql.framework.ui.graph.IToolBar;
052: import org.netbeans.modules.sql.framework.ui.graph.actions.AutoLayoutAction;
053: import org.netbeans.modules.sql.framework.ui.graph.actions.CollapseAllAction;
054: import org.netbeans.modules.sql.framework.ui.graph.actions.ExpandAllAction;
055: import org.netbeans.modules.sql.framework.ui.graph.actions.GraphAction;
056: import org.netbeans.modules.sql.framework.ui.graph.impl.OperatorXmlInfoModel;
057: import org.netbeans.modules.sql.framework.ui.graph.view.impl.SQLToolBar;
058: import org.netbeans.modules.sql.framework.ui.model.SQLUIModel;
059: import org.netbeans.modules.sql.framework.ui.undo.SQLUndoManager;
060: import org.netbeans.modules.sql.framework.ui.view.IGraphViewContainer;
061: import org.netbeans.modules.sql.framework.ui.view.conditionbuilder.actions.ShowSQLAction;
062: import org.netbeans.modules.sql.framework.ui.view.conditionbuilder.actions.ShowTableTreeAction;
063: import org.netbeans.modules.sql.framework.ui.view.conditionbuilder.actions.ValidateGraphAction;
064: import org.netbeans.modules.sql.framework.ui.view.graph.AbstractSQLViewFactory;
065: import org.netbeans.modules.sql.framework.ui.view.graph.BasicGraphFactory;
066:
067: /**
068: * @author Ritesh Adval
069: * @version $Revision$
070: */
071: public class ConditionBuilderViewFactory extends AbstractSQLViewFactory {
072: private IGraphView gView;
073: private IGraphViewContainer gViewContainer;
074: private OperatorXmlInfoModel operatorModel;
075:
076: private SQLUIModel sqlModel;
077: private IToolBar toolBar;
078:
079: public ConditionBuilderViewFactory(SQLUIModel model,
080: IGraphViewContainer gContainer) {
081: this (model, gContainer, IOperatorXmlInfoModel.CATEGORY_FILTER);
082: }
083:
084: public ConditionBuilderViewFactory(SQLUIModel model,
085: IGraphViewContainer gContainer, int toolBarType) {
086: this .sqlModel = model;
087: this .gViewContainer = gContainer;
088:
089: // Operator Model has to be created only once
090: this .operatorModel = OperatorXmlInfoModel
091: .getInstance(this .gViewContainer.getOperatorFolder());
092: this .toolbarType = toolBarType;
093:
094: super .setSQLToolBar();
095: }
096:
097: /**
098: * create a graph controller
099: *
100: * @return
101: */
102: public IGraphController createGraphController() {
103: IGraphController graphController = new ConditionGraphController();
104: return graphController;
105: }
106:
107: /**
108: * create a graph view
109: *
110: * @return graph view
111: */
112: public IGraphView createGraphView() {
113: ConditionGraphView graphView = new ConditionGraphView();
114: this .gView = graphView;
115: BasicGraphFactory graphFactory = new BasicGraphFactory(
116: gViewContainer.getOperatorFolder());
117: graphView.setGraphFactory(graphFactory);
118: sqlModel.addSQLDataListener(graphView);
119: UndoManager undoManager = sqlModel.getUndoManager();
120: if (undoManager instanceof SQLUndoManager) {
121: ((SQLUndoManager) undoManager)
122: .addUndoableEditListener(graphView);
123: }
124:
125: return graphView;
126: }
127:
128: /**
129: * create a tool bar
130: *
131: * @return tool bar
132: */
133: public IToolBar createToolBar() {
134: toolBar = new SQLToolBar(this );
135: return toolBar;
136: }
137:
138: /**
139: * get graph view pop up actions
140: *
141: * @return actions
142: */
143: public List getGraphActions() {
144: return null;
145: }
146:
147: /**
148: * Gets the current graph controller
149: *
150: * @return graph controller
151: */
152: public IGraphController getGraphController() {
153: return null;
154: }
155:
156: /**
157: * Gets graph view currently associated with this manager.
158: *
159: * @return current instance of IGraphView
160: */
161: public IGraphView getGraphView() {
162: return this .gView;
163: }
164:
165: /**
166: * get graph view container
167: *
168: * @return graph view container
169: */
170: public Object getGraphViewContainer() {
171: return this .gViewContainer;
172: }
173:
174: /**
175: * Gets operator view (toolbar) currently associated with this manager.
176: *
177: * @return current instance of IToolBar
178: */
179: public IToolBar getOperatorView() {
180: return toolBar;
181: }
182:
183: /**
184: * get operator xml info model which is defined in netbeans layer.xml file
185: *
186: * @return operator xml info model
187: */
188: public IOperatorXmlInfoModel getOperatorXmlInfoModel() {
189: return operatorModel;
190: }
191:
192: /**
193: * get sql model
194: *
195: * @return sql model
196: */
197: public SQLUIModel getSQLModel() {
198: return this .sqlModel;
199: }
200:
201: /**
202: * return toolbar actions
203: *
204: * @return toolbar actions
205: */
206: public List getToolBarActions() {
207: ArrayList actions = new ArrayList();
208: // Do not use same instance of ShowTableTreeAction, ExpandAllActions,
209: // CollapseAllAction and autoLayout as they are service more than one
210: // tool bar and types.
211: actions.add(new ShowTableTreeAction());
212: actions.add(GraphAction.getAction(ValidateGraphAction.class));
213: actions.add(GraphAction.getAction(ShowSQLAction.class));
214: actions.add(null);
215:
216: actions.add(new ExpandAllAction());
217: actions.add(new CollapseAllAction());
218: actions.add(new AutoLayoutAction());
219:
220: return actions;
221: }
222:
223: }
|