001: package org.netbeans.modules.sql.framework.ui.view.graph;
002:
003: import java.util.ArrayList;
004: import java.util.List;
005:
006: import javax.swing.undo.UndoManager;
007:
008: import org.netbeans.modules.sql.framework.ui.graph.IGraphController;
009: import org.netbeans.modules.sql.framework.ui.graph.IGraphView;
010: import org.netbeans.modules.sql.framework.ui.graph.IOperatorXmlInfoModel;
011: import org.netbeans.modules.sql.framework.ui.graph.IToolBar;
012: import org.netbeans.modules.sql.framework.ui.graph.actions.AutoLayoutAction;
013: import org.netbeans.modules.sql.framework.ui.graph.actions.CollapseAllAction;
014: import org.netbeans.modules.sql.framework.ui.graph.actions.ExpandAllAction;
015: import org.netbeans.modules.sql.framework.ui.graph.actions.GraphAction;
016: import org.netbeans.modules.sql.framework.ui.graph.actions.ZoomAction;
017: import org.netbeans.modules.sql.framework.ui.graph.impl.OperatorXmlInfoModel;
018: import org.netbeans.modules.sql.framework.ui.graph.view.impl.SQLToolBar;
019: import org.netbeans.modules.sql.framework.ui.model.SQLUIModel;
020: import org.netbeans.modules.sql.framework.ui.undo.SQLUndoManager;
021: import org.netbeans.modules.sql.framework.ui.view.IGraphViewContainer;
022:
023: public final class BasicSQLViewFactory extends AbstractSQLViewFactory {
024: private IOperatorXmlInfoModel operatorModel;
025: private SQLUIModel sqlModel;
026: private IGraphViewContainer gViewContainer;
027: private IGraphView gView;
028: private IToolBar toolBar;
029: private List graphActions;
030: private List toolBarActions;
031:
032: public BasicSQLViewFactory(SQLUIModel model,
033: IGraphViewContainer gContainer, List gActions, List tActions) {
034: this .sqlModel = model;
035: this .gViewContainer = gContainer;
036: this .graphActions = gActions;
037: this .toolBarActions = tActions;
038:
039: // This has to be created only once
040: operatorModel = OperatorXmlInfoModel
041: .getInstance(this .gViewContainer.getOperatorFolder());
042: this .toolbarType = IOperatorXmlInfoModel.CATEGORY_TRANSFORM;
043: super .setUp();
044: }
045:
046: /**
047: * create a graph view
048: *
049: * @return graph view
050: */
051: public IGraphView createGraphView() {
052: SQLGraphView gv = new SQLGraphView();
053: this .gView = gv;
054: BasicGraphFactory graphFactory = new BasicGraphFactory(
055: this .gViewContainer.getOperatorFolder());
056: gv.setGraphFactory(graphFactory);
057: //set up model
058: sqlModel.addSQLDataListener(gv);
059:
060: UndoManager undoManager = sqlModel.getUndoManager();
061: if (undoManager instanceof SQLUndoManager) {
062: ((SQLUndoManager) undoManager).addUndoableEditListener(gv);
063: }
064:
065: return gv;
066: }
067:
068: /**
069: * create a tool bar
070: *
071: * @return tool bar
072: */
073: // XXX: Already created in Editor Multiview Element
074: public IToolBar createToolBar() {
075: if (toolBar == null) {
076: toolBar = new SQLToolBar(this );
077: }
078: return toolBar;
079: }
080:
081: /**
082: * create a graph controller
083: *
084: * @return
085: */
086: public IGraphController createGraphController() {
087: IGraphController graphController = new BasicSQLGraphController();
088: return graphController;
089: }
090:
091: /**
092: * get sql model
093: *
094: * @return sql model
095: */
096: public SQLUIModel getSQLModel() {
097: return this .sqlModel;
098: }
099:
100: /**
101: * get graph view container
102: *
103: * @return graph view container
104: */
105: public Object getGraphViewContainer() {
106: return this .gViewContainer;
107: }
108:
109: /**
110: * get graph view pop up actions
111: *
112: * @return actions
113: */
114: public List getGraphActions() {
115: if (graphActions != null) {
116: return graphActions;
117: }
118: ArrayList actions = new ArrayList();
119: //While right clicking
120: /*actions.add(SystemAction.get(UndoAction.class));
121: actions.add(SystemAction.get(RedoAction.class));*/
122: //actions.add(GraphAction.getAction(PrintAction.class));
123: return actions;
124: }
125:
126: /**
127: * return toolbar actions
128: *
129: * @return toolbar actions
130: */
131: public List getToolBarActions() {
132: if (toolBarActions != null) {
133: return toolBarActions;
134: }
135:
136: ArrayList actions = new ArrayList();
137:
138: //Commented the snippet for undo,redo fix
139:
140: //undo action are not static (because they are used in condition builder also)
141: // so we create it using constructor
142: /* UndoAction undoAction = new UndoAction();
143: RedoAction redoAction = new RedoAction();
144:
145: //undo redo action should not about each other so they can enable/disable each
146: // other
147: undoAction.setRedoAction(redoAction);
148: redoAction.setUndoAction(undoAction);
149: actions.add(undoAction);
150: actions.add(redoAction);
151: actions.add(null);*/
152: actions.add(GraphAction.getAction(ExpandAllAction.class));
153: actions.add(GraphAction.getAction(CollapseAllAction.class));
154: actions.add(GraphAction.getAction(AutoLayoutAction.class));
155: //actions.add(GraphAction.getAction(PrintAction.class));
156: actions.add(GraphAction.getAction(ZoomAction.class));
157:
158: return actions;
159: }
160:
161: /**
162: * get operator xml info model which is defined in netbeans layer.xml file
163: *
164: * @return operator xml info model
165: */
166: public IOperatorXmlInfoModel getOperatorXmlInfoModel() {
167: return operatorModel;
168: }
169:
170: /**
171: * Gets operator view (toolbar) currently associated with this manager.
172: *
173: * @return current instance of IToolBar
174: */
175: public IToolBar getOperatorView() {
176: return toolBar;
177: }
178:
179: /**
180: * Gets graph view currently associated with this manager.
181: *
182: * @return current instance of IGraphView
183: */
184: public IGraphView getGraphView() {
185: return gView;
186: }
187: }
|