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: package org.pentaho.designstudio.widgets.flowtable;
014:
015: import java.util.ArrayList;
016: import java.util.List;
017:
018: import org.eclipse.swt.SWT;
019: import org.eclipse.swt.events.MouseEvent;
020: import org.eclipse.swt.graphics.Point;
021: import org.eclipse.swt.widgets.Composite;
022: import org.pentaho.actionsequence.dom.AbstractIOElement;
023: import org.pentaho.actionsequence.dom.ActionControlStatement;
024: import org.pentaho.actionsequence.dom.ActionSequenceDocument;
025: import org.pentaho.actionsequence.dom.IActionSequenceDocumentListener;
026: import org.pentaho.actionsequence.dom.actions.ActionDefinition;
027:
028: import de.kupzog.ktable.KTable;
029: import de.kupzog.ktable.SWTX;
030:
031: public class FlowTable extends KTable implements
032: IActionSequenceDocumentListener {
033: ActionsModel actionsModel = new ActionsModel();
034: AbstractIOElement subSelection = null;
035:
036: public FlowTable(Composite parent) {
037: super (parent, SWT.FULL_SELECTION | SWTX.AUTO_SCROLL
038: | SWTX.FILL_WITH_LASTCOL);
039: this .setModel(actionsModel);
040: }
041:
042: public int getColumnCount() {
043: return (getModel().getColumnCount());
044: }
045:
046: public List getSelections() {
047: List al = new ArrayList();
048: if (subSelection == null) {
049: int items[] = getRowSelection();
050: for (int i = 0; i < items.length; ++i) {
051: FlowContent flowContent = (FlowContent) actionsModel
052: .getContentAt(0, items[i]);
053: al.add(flowContent.getData());
054: }
055: } else {
056: al.add(subSelection);
057: }
058: return (al);
059: }
060:
061: protected void onMouseDown(MouseEvent e) {
062: int btn = e.button;
063: e.button = 1; // Allow right click to select
064: super .onMouseDown(e);
065:
066: //Get the sub selection (parameter)
067:
068: subSelection = (btn == 1) ? actionsModel.getSubContentAt(0,
069: m_FocusRow, new Point(e.x, e.y)) : null;
070: }
071:
072: protected void onMouseUp(MouseEvent e) {
073: subSelection = null;
074: super .onMouseUp(e);
075: }
076:
077: protected void fireCellSelection(int col, int row, int statemask) {
078: super .fireCellSelection(col, row, statemask);
079: }
080:
081: public void setSelection(List selection) {
082: if ((selection != null) && (selection.size() > 0)) {
083: Point selectCell = actionsModel
084: .getCellWithContent(selection.get(0));
085: if (selectCell != null) {
086: setSelection(selectCell.x, selectCell.y, true);
087: subSelection = null;
088: }
089: }
090: }
091:
092: public void setActionSequence(ActionSequenceDocument document) {
093: actionsModel.setActionSequence(document);
094: if (actionsModel.actionSequence != null) {
095: actionsModel.actionSequence.removeListener(this );
096: }
097: actionsModel.setActionSequence(document);
098: if (document != null) {
099: actionsModel.actionSequence.addListener(this );
100: }
101: redraw();
102: }
103:
104: public void refresh() {
105: actionsModel.refresh();
106: redraw();
107: }
108:
109: public void actionAdded(ActionDefinition action) {
110: refresh();
111: }
112:
113: public void actionChanged(ActionDefinition action) {
114: refresh();
115: }
116:
117: public void actionRemoved(Object parent, ActionDefinition action) {
118: refresh();
119:
120: }
121:
122: public void actionRenamed(ActionDefinition action) {
123: refresh();
124: }
125:
126: public void ioAdded(AbstractIOElement io) {
127: refresh();
128: }
129:
130: public void ioChanged(AbstractIOElement io) {
131: refresh();
132: }
133:
134: public void ioRemoved(Object parent, AbstractIOElement io) {
135: refresh();
136: }
137:
138: public void ioRenamed(AbstractIOElement io) {
139: refresh();
140: }
141:
142: public void controlStatementAdded(
143: ActionControlStatement controlStatement) {
144: refresh();
145: }
146:
147: public void controlStatementChanged(
148: ActionControlStatement controlStatement) {
149: refresh();
150: }
151:
152: public void controlStatementRemoved(Object parent,
153: ActionControlStatement controlStatement) {
154: refresh();
155: }
156:
157: public void resourceAdded(Object resource) {
158: refresh();
159: }
160:
161: public void resourceChanged(Object resource) {
162: refresh();
163: }
164:
165: public void resourceRemoved(Object parent, Object resource) {
166: refresh();
167: }
168:
169: public void resourceRenamed(Object resource) {
170: refresh();
171: }
172:
173: public void headerChanged(
174: ActionSequenceDocument actionSequenceDocument) {
175: }
176:
177: }
|