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.editors.actionsequence.pages.parameters;
014:
015: import java.util.ArrayList;
016: import java.util.Arrays;
017: import java.util.Iterator;
018:
019: import org.eclipse.swt.graphics.Point;
020: import org.pentaho.actionsequence.dom.ActionSequenceInput;
021: import org.pentaho.actionsequence.dom.ActionSequenceInputSource;
022: import org.pentaho.designstudio.editors.actionsequence.ActionSequenceEditorPlugin;
023: import org.pentaho.designstudio.editors.actionsequence.preferences.InputSourcesEditor;
024: import org.pentaho.designstudio.editors.actionsequence.preferences.PreferenceConstants;
025: import org.pentaho.designstudio.messages.Messages;
026:
027: import de.kupzog.ktable.KTableCellEditor;
028: import de.kupzog.ktable.KTableCellRenderer;
029: import de.kupzog.ktable.KTableDefaultModel;
030: import de.kupzog.ktable.editors.KTableCellEditorCombo;
031: import de.kupzog.ktable.editors.KTableCellEditorText;
032: import de.kupzog.ktable.renderers.FixedCellRenderer;
033: import de.kupzog.ktable.renderers.TextCellRenderer;
034:
035: public class InputSrcModel extends KTableDefaultModel {
036:
037: static final String NEW_ROW_FILLER = new String(""); //$NON-NLS-1$
038: private static final String ORIGIN_HEADER = Messages
039: .getString("InputSrcModel.ORIGIN_COLUMN_HEADER"); //$NON-NLS-1$
040: private static final String NAME_HEADER = Messages
041: .getString("InputSrcModel.NAME_COLUMN_HEADER"); //$NON-NLS-1$
042:
043: ActionSequenceInput actionSequenceInput = null;
044:
045: final FixedCellRenderer headerRenderer = new FixedCellRenderer(
046: FixedCellRenderer.STYLE_FLAT
047: | FixedCellRenderer.INDICATION_CLICKED
048: | FixedCellRenderer.INDICATION_FOCUS);
049:
050: final TextCellRenderer cellRenderer = new TextCellRenderer(
051: TextCellRenderer.INDICATION_FOCUS);
052:
053: final KTableCellEditorText nameCellEditor = new KTableCellEditorText();
054:
055: public InputSrcModel() {
056: initialize();
057: }
058:
059: public Object doGetContentAt(int col, int row) {
060: Object value = ""; //$NON-NLS-1$
061: if ((row >= 0) && (row < getRowCount())) {
062: if (col == 0) {
063: if (row < getFixedHeaderRowCount()) {
064: value = ORIGIN_HEADER;
065: } else {
066: value = actionSequenceInput.getSources()[row
067: - getFixedHeaderRowCount()].getOrigin();
068: }
069: } else if (col == 1) {
070: if (row < getFixedHeaderRowCount()) {
071: value = NAME_HEADER;
072: } else {
073: value = actionSequenceInput.getSources()[row
074: - getFixedHeaderRowCount()].getName();
075: }
076: }
077: }
078: return value == null ? "" : value.toString(); //$NON-NLS-1$
079: }
080:
081: public KTableCellEditor doGetCellEditor(int col, int row) {
082: KTableCellEditor editor = null;
083: if (col == 1) {
084: editor = nameCellEditor;
085: } else if (col == 0) {
086: editor = new KTableCellEditorCombo();
087: ArrayList sources = new ArrayList();
088: sources
089: .addAll(Arrays
090: .asList(InputSourcesEditor
091: .parsePrefsString(ActionSequenceEditorPlugin
092: .getDefault()
093: .getPluginPreferences()
094: .getString(
095: PreferenceConstants.INPUT_SOURCES))));
096: ((KTableCellEditorCombo) editor)
097: .setItems((String[]) sources.toArray(new String[0]));
098: }
099: return editor;
100: }
101:
102: public void doSetContentAt(int col, int row, Object value) {
103: if ((row >= getFixedHeaderRowCount()) && (row < getRowCount())) {
104: if (col == 1) {
105: actionSequenceInput.getSources()[row
106: - getFixedHeaderRowCount()].setName(value
107: .toString());
108: } else if (col == 0) {
109: actionSequenceInput.getSources()[row
110: - getFixedHeaderRowCount()].setOrigin(value
111: .toString());
112: }
113: }
114: }
115:
116: public int doGetRowCount() {
117: return getFixedRowCount()
118: + actionSequenceInput.getSources().length;
119: }
120:
121: public int getFixedHeaderRowCount() {
122: return 1;
123: }
124:
125: public int doGetColumnCount() {
126: return 2 + getFixedHeaderColumnCount();
127: }
128:
129: public int getFixedHeaderColumnCount() {
130: return 0;
131: }
132:
133: public int getFixedSelectableRowCount() {
134: return 0;
135: }
136:
137: public int getFixedSelectableColumnCount() {
138: return 0;
139: }
140:
141: public boolean isColumnResizable(int col) {
142: return true;
143: }
144:
145: public boolean isRowResizable(int row) {
146: return false;
147: }
148:
149: public int getRowHeightMinimum() {
150: return 22;
151: }
152:
153: public KTableCellRenderer doGetCellRenderer(int col, int row) {
154: if (isFixedCell(col, row))
155: return headerRenderer;
156:
157: return cellRenderer;
158: }
159:
160: public Point doBelongsToCell(int col, int row) {
161: return null;
162: }
163:
164: public int getInitialColumnWidth(int column) {
165: return 100;
166: }
167:
168: public int getInitialRowHeight(int row) {
169: return 22;
170: }
171:
172: void setInput(ActionSequenceInput actionSequenceInput) {
173: this .actionSequenceInput = actionSequenceInput;
174: refresh();
175: }
176:
177: void refresh() {
178: }
179:
180: public void addSource(String source) {
181: actionSequenceInput.addSource(source, actionSequenceInput
182: .getName());
183: }
184:
185: public void deleteRow(int row) {
186: if (row >= getRowCount()) {
187: throw new IndexOutOfBoundsException();
188: }
189: actionSequenceInput.getSources()[row - getFixedHeaderRowCount()]
190: .delete();
191: }
192:
193: public void moveRow(int from, int to) {
194: if (from != to) {
195: if ((from < getFixedHeaderRowCount())
196: || (to < getFixedHeaderRowCount())
197: || (from >= getRowCount()) || (to >= getRowCount())) {
198: throw new IndexOutOfBoundsException();
199: }
200: ActionSequenceInputSource[] sources = actionSequenceInput
201: .getSources();
202: for (int i = 0; i < sources.length; i++) {
203: sources[i].delete();
204: }
205: ArrayList sourceList = new ArrayList(Arrays.asList(sources));
206: sourceList.add(to - getFixedHeaderRowCount(), sourceList
207: .remove(from - getFixedHeaderRowCount()));
208: for (Iterator iter = sourceList.iterator(); iter.hasNext();) {
209: ActionSequenceInputSource source = (ActionSequenceInputSource) iter
210: .next();
211: actionSequenceInput.addSource(source.getOrigin(),
212: source.getName());
213: }
214: }
215: }
216:
217: public void initialize() {
218: super .initialize();
219: // originCellEditor.setItems(ActionSequenceDocument.INPUT_SOURCES);
220: }
221: }
|