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:
018: import org.eclipse.swt.graphics.Point;
019: import org.pentaho.actionsequence.dom.ActionSequenceOutput;
020: import org.pentaho.designstudio.editors.actionsequence.ActionSequenceEditorPlugin;
021: import org.pentaho.designstudio.editors.actionsequence.preferences.InputSourcesEditor;
022: import org.pentaho.designstudio.editors.actionsequence.preferences.PreferenceConstants;
023: import org.pentaho.designstudio.messages.Messages;
024:
025: import de.kupzog.ktable.KTableCellEditor;
026: import de.kupzog.ktable.KTableCellRenderer;
027: import de.kupzog.ktable.KTableDefaultModel;
028: import de.kupzog.ktable.editors.KTableCellEditorCombo;
029: import de.kupzog.ktable.editors.KTableCellEditorText;
030: import de.kupzog.ktable.renderers.FixedCellRenderer;
031: import de.kupzog.ktable.renderers.TextCellRenderer;
032:
033: public class OutputDestModel extends KTableDefaultModel {
034:
035: static final String NEW_ROW_FILLER = new String(""); //$NON-NLS-1$
036: private static final String DESTINATION_HEADER = Messages
037: .getString("OutputDestModel.DESTINATION_HDR"); //$NON-NLS-1$
038: private static final String NAME_HEADER = Messages
039: .getString("OutputDestModel.NAME_HDR"); //$NON-NLS-1$
040:
041: ActionSequenceOutput actionSequenceOutput = null;
042:
043: final FixedCellRenderer headerRenderer = new FixedCellRenderer(
044: FixedCellRenderer.STYLE_FLAT
045: | FixedCellRenderer.INDICATION_CLICKED
046: | FixedCellRenderer.INDICATION_FOCUS);
047:
048: final TextCellRenderer cellRenderer = new TextCellRenderer(
049: TextCellRenderer.INDICATION_FOCUS);
050:
051: final KTableCellEditorText cellEditor = new KTableCellEditorText();
052:
053: public OutputDestModel() {
054: initialize();
055: }
056:
057: public Object doGetContentAt(int col, int row) {
058: Object value = ""; //$NON-NLS-1$
059: if ((row >= 0) && (row < getRowCount())) {
060: if (col == 0) {
061: if (row < getFixedHeaderRowCount()) {
062: value = DESTINATION_HEADER;
063: } else {
064: value = actionSequenceOutput.getDestinations()[row
065: - getFixedHeaderRowCount()]
066: .getDestination();
067: }
068: } else if (col == 1) {
069: if (row < getFixedHeaderRowCount()) {
070: value = NAME_HEADER;
071: } else {
072: value = actionSequenceOutput.getDestinations()[row
073: - getFixedHeaderRowCount()].getName();
074: }
075: }
076: }
077: return value == null ? "" : value.toString(); //$NON-NLS-1$
078: }
079:
080: public KTableCellEditor doGetCellEditor(int col, int row) {
081: KTableCellEditor editor = null;
082: if (col == 1) {
083: editor = cellEditor;
084: } else if (col == 0) {
085: editor = new KTableCellEditorCombo();
086: ArrayList destinations = new ArrayList();
087: destinations
088: .addAll(Arrays
089: .asList(InputSourcesEditor
090: .parsePrefsString(ActionSequenceEditorPlugin
091: .getDefault()
092: .getPluginPreferences()
093: .getString(
094: PreferenceConstants.OUTPUT_DEST))));
095: ((KTableCellEditorCombo) editor)
096: .setItems((String[]) destinations
097: .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: actionSequenceOutput.getDestinations()[row
106: - getFixedHeaderRowCount()].setName(value
107: .toString());
108: } else if (col == 0) {
109: actionSequenceOutput.getDestinations()[row
110: - getFixedHeaderRowCount()]
111: .setDestination(value.toString());
112: }
113: }
114: }
115:
116: public int doGetRowCount() {
117: return getFixedRowCount()
118: + actionSequenceOutput.getDestinations().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(ActionSequenceOutput actionSequenceOutput) {
173: this .actionSequenceOutput = actionSequenceOutput;
174: refresh();
175: }
176:
177: void refresh() {
178: }
179:
180: public void addDestination(String destination) {
181: actionSequenceOutput.addDestination(destination,
182: actionSequenceOutput.getName());
183: }
184:
185: public void deleteRow(int row) {
186: if (row >= getRowCount()) {
187: throw new IndexOutOfBoundsException();
188: }
189: actionSequenceOutput.getDestinations()[row
190: - getFixedHeaderRowCount()].delete();
191: }
192: }
|