001: /*
002: * Copyright 2006 Pentaho Corporation. All rights reserved.
003: * This software was developed by Pentaho Corporation and is provided under the terms
004: * of the Mozilla Public License, Version 1.1, or any later version. You may not use
005: * this file except in compliance with the license. If you need a copy of the license,
006: * please go to http://www.mozilla.org/MPL/MPL-1.1.txt. The Original Code is the Pentaho
007: * BI Platform. The Initial Developer is Pentaho Corporation.
008: *
009: * Software distributed under the Mozilla Public License is distributed on an "AS IS"
010: * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. Please refer to
011: * the license for the specific language governing your rights and limitations.
012: */
013: /*
014: * Copyright (C) 2004 by Friederich Kupzog Elektronik & Software
015: * All rights reserved. This program and the accompanying materials
016: * are made available under the terms of the Eclipse Public License v1.0
017: * which accompanies this distribution, and is available at
018: * http://www.eclipse.org/legal/epl-v10.html
019: *
020: Author: Friederich Kupzog
021: fkmk@kupzog.de
022: www.kupzog.de/fkmk
023: */
024: package org.pentaho.designstudio.widgets.flowtable;
025:
026: import java.util.ArrayList;
027: import java.util.List;
028:
029: import org.eclipse.swt.graphics.Image;
030: import org.eclipse.swt.graphics.Point;
031: import org.pentaho.actionsequence.dom.AbstractIOElement;
032: import org.pentaho.actionsequence.dom.ActionControlStatement;
033: import org.pentaho.actionsequence.dom.ActionIfStatement;
034: import org.pentaho.actionsequence.dom.ActionLoop;
035: import org.pentaho.actionsequence.dom.ActionSequenceDocument;
036: import org.pentaho.actionsequence.dom.actions.ActionDefinition;
037: import org.pentaho.designstudio.editors.actionsequence.ActionSequenceEditorPlugin;
038: import org.pentaho.designstudio.messages.Messages;
039:
040: import de.kupzog.ktable.KTableCellEditor;
041: import de.kupzog.ktable.KTableCellRenderer;
042: import de.kupzog.ktable.KTableModel;
043:
044: /**
045: * @author Friederich Kupzog
046: */
047: public class ActionsModel implements KTableModel {
048:
049: private int[] colWidths;
050: // private ActionsContent[] content;
051: static ActionsRenderer renderer = new ActionsRenderer();
052: List nodeList = new ArrayList();
053:
054: ActionSequenceDocument actionSequence;
055:
056: FlowContent unknownAction = new FlowContent() {
057:
058: public String getDescription() {
059: return ""; //$NON-NLS-1$
060: }
061:
062: public Image getImage() {
063: return ActionSequenceEditorPlugin
064: .getImageDescriptor(
065: FLOW_ICON_DIR
066: + Messages
067: .getString("ActionsModel.ICON_FLOW_DEFAULT")).createImage(); //$NON-NLS-1$
068: }
069:
070: public String getName() {
071: return Messages
072: .getString("ActionsModel.UI_UNKNOWN_ACTION_LABEL"); //$NON-NLS-1$
073: }
074:
075: public AbstractIOElement[] getParameters() {
076: return new AbstractIOElement[0];
077: }
078:
079: public Object getData() {
080: return null;
081: }
082:
083: };
084:
085: public ActionsModel() {
086: colWidths = new int[getColumnCount()];
087: colWidths[0] = 120;
088: }
089:
090: public void setActionSequence(ActionSequenceDocument actionSequence) {
091: this .actionSequence = actionSequence;
092: refresh();
093: }
094:
095: /*
096: * overridden from superclass
097: */
098: public Object getContentAt(int col, int row) {
099: if ((row > nodeList.size()) || (row < 0))
100: return (unknownAction);
101: return (nodeList.get(row));
102: }
103:
104: public AbstractIOElement getSubContentAt(int col, int row, Point p) {
105: FlowContent ac = (FlowContent) getContentAt(col, row);
106: AbstractIOElement o = ac.getSelectedParameter(p);
107: return (o);
108: }
109:
110: /*
111: * overridden from superclass
112: */
113: public KTableCellEditor getCellEditor(int col, int row) {
114: return null;
115: }
116:
117: /*
118: * overridden from superclass
119: */
120: public void setContentAt(int col, int row, Object value) {
121: }
122:
123: /*
124: * returns the cell that has the passed in content as a point cols == x, rows == y
125: * or null if not found
126: */
127:
128: public Point getCellWithContent(Object obj) {
129: for (int i = 0; i < nodeList.size(); ++i) {
130: FlowContent ac = (FlowContent) nodeList.get(i);
131: if (obj.equals(ac.getData())) {
132: return (new Point(0, i));
133: }
134: }
135: return (null);
136: }
137:
138: /*
139: * overridden from superclass
140: */
141: public int getRowCount() {
142: return (nodeList.size());
143: }
144:
145: /*
146: * overridden from superclass
147: */
148: public int getFixedHeaderRowCount() {
149: return 0;
150: }
151:
152: /*
153: * overridden from superclass
154: */
155: public int getColumnCount() {
156: return 1;
157: }
158:
159: /*
160: * overridden from superclass
161: */
162: public int getFixedHeaderColumnCount() {
163: return 0;
164: }
165:
166: /*
167: * overridden from superclass
168: */
169: public int getColumnWidth(int col) {
170: return colWidths[col];
171: }
172:
173: /*
174: * overridden from superclass
175: */
176: public boolean isColumnResizable(int col) {
177: return (false);
178: }
179:
180: /*
181: * overridden from superclass
182: */
183: public void setColumnWidth(int col, int value) {
184: if (value > 120)
185: colWidths[col] = value;
186: }
187:
188: /*
189: * overridden from superclass
190: */
191: public int getRowHeight(int row) {
192: //System.out.println( "ROW: " + row + " " + renderer.getRowHeight( content[row].imageHeight, content[row].pos ) );
193: if ((row > nodeList.size()) || (row < 0))
194: return (0);
195: FlowContent ac = (FlowContent) nodeList.get(row);
196: Image image = ac.getImage();
197: return (renderer.getRowHeight(
198: image != null ? image.getBounds().height : 0, ac));
199: }
200:
201: /*
202: * overridden from superclass
203: */
204: public boolean isRowResizable(int row) {
205: return false;
206: }
207:
208: /*
209: * overridden from superclass
210: */
211: public int getRowHeightMinimum() {
212: return 20;
213: }
214:
215: /*
216: * overridden from superclass
217: */
218: public void setRowHeight(int row, int value) {
219: }
220:
221: /*
222: * overridden from superclass
223: */
224: public KTableCellRenderer getCellRenderer(int col, int row) {
225: return renderer;
226: }
227:
228: /* (non-Javadoc)
229: * @see de.kupzog.ktable.KTableModel#belongsToCell(int, int)
230: */
231: public Point belongsToCell(int col, int row) {
232: return null;
233: }
234:
235: /* (non-Javadoc)
236: * @see de.kupzog.ktable.KTableModel#getTooltipAt(int, int)
237: */
238: public String getTooltipAt(int col, int row) {
239: // no tooltip
240: return null;
241: }
242:
243: /* (non-Javadoc)
244: * @see de.kupzog.ktable.KTableModel#getFixedSelectableRowCount()
245: */
246: public int getFixedSelectableRowCount() {
247: // all fixed rows are non-selectable.
248: return 0;
249: }
250:
251: /* (non-Javadoc)
252: * @see de.kupzog.ktable.KTableModel#getFixedSelectableColumnCount()
253: */
254: public int getFixedSelectableColumnCount() {
255: // all fixed columns are non-selctable.
256: return 0;
257: }
258:
259: public void refresh() {
260: nodeList = new ArrayList();
261: if (actionSequence != null) {
262: nodeList.add(new InputContent(actionSequence));
263: nodeList.add(new ResourceContent(actionSequence));
264: addExecutables(null, nodeList, 0);
265: nodeList.add(new OutputContent(actionSequence));
266: }
267: }
268:
269: void addExecutables(ActionControlStatement parent, List l, int level) {
270: Object obj[] = (parent == null) ? actionSequence
271: .getExecutableChildren() : parent.getChildren();
272: for (int i = 0; i < obj.length; ++i) {
273: boolean hasChildren = (obj[i] instanceof ActionControlStatement)
274: && (((ActionControlStatement) obj[i]).getChildren().length > 0);
275:
276: if (obj[i] instanceof ActionLoop) {
277: nodeList
278: .add(new LoopContent((ActionLoop) obj[i], level));
279: if (hasChildren) {
280: addExecutables((ActionLoop) obj[i], l, level + 1);
281: }
282: nodeList.add(new TerminatorContent((ActionLoop) obj[i],
283: level));
284: } else if (obj[i] instanceof ActionIfStatement) {
285: nodeList.add(new IfContent((ActionIfStatement) obj[i],
286: level));
287: if (hasChildren) {
288: addExecutables((ActionIfStatement) obj[i], l,
289: level + 1);
290: }
291: nodeList.add(new TerminatorContent(
292: (ActionIfStatement) obj[i], level));
293: } else {
294: ActionDefinition actionDefinition = (ActionDefinition) obj[i];
295: nodeList
296: .add(new ActionContent(actionDefinition, level));
297: }
298: }
299: }
300: }
|