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.actions.details;
014:
015: import java.util.ArrayList;
016: import java.util.Arrays;
017: import java.util.List;
018:
019: import org.eclipse.jface.viewers.IStructuredSelection;
020: import org.eclipse.jface.viewers.StructuredSelection;
021: import org.eclipse.swt.layout.GridData;
022: import org.eclipse.swt.layout.GridLayout;
023: import org.eclipse.swt.widgets.Composite;
024: import org.pentaho.actionsequence.dom.AbstractIOElement;
025: import org.pentaho.actionsequence.dom.ActionInput;
026: import org.pentaho.actionsequence.dom.ActionOutput;
027: import org.pentaho.actionsequence.dom.ActionSequenceDocument;
028: import org.pentaho.actionsequence.dom.ActionSequenceInput;
029: import org.pentaho.actionsequence.dom.IActionInputValueProvider;
030: import org.pentaho.actionsequence.dom.IActionSequenceElement;
031: import org.pentaho.actionsequence.dom.actions.PrintParamAction;
032: import org.pentaho.designstudio.controls.ActionInputText;
033: import org.pentaho.designstudio.controls.ActionInputsList;
034: import org.pentaho.designstudio.controls.ActionInputsListToolbar;
035: import org.pentaho.designstudio.controls.NewActionInputText;
036: import org.pentaho.designstudio.controls.WidgetFactory;
037: import org.pentaho.designstudio.editors.actionsequence.pages.actions.IActionIOFilter;
038: import org.pentaho.designstudio.messages.Messages;
039:
040: public class PrintParamsDetailsPage extends ActionDetailsPage implements
041: IActionIOFilter {
042:
043: class PrintParamsToolbar extends ActionInputsListToolbar {
044: public PrintParamsToolbar(Composite parent,
045: PrintParamsTable inputsList) {
046: super (parent, inputsList);
047: }
048:
049: protected void moveSelectedItemDown() {
050: IStructuredSelection structuredSelection = (IStructuredSelection) actionInputsList
051: .getSelection();
052: if (structuredSelection.size() == 1) {
053: ArrayList msgInputs = new ArrayList();
054: for (int i = 0; i < actionInputsList.getList()
055: .getItemCount(); i++) {
056: msgInputs.add((ActionInput) actionInputsList
057: .getElementAt(i));
058: }
059: ActionInput selectedActionInput = (ActionInput) structuredSelection
060: .getFirstElement();
061: int currentListIndex = msgInputs
062: .indexOf(selectedActionInput);
063: if (currentListIndex < msgInputs.size() - 1) {
064: msgInputs.remove(currentListIndex);
065: currentListIndex++;
066: if (currentListIndex >= msgInputs.size()) {
067: msgInputs.add(selectedActionInput);
068: } else {
069: msgInputs.add(currentListIndex,
070: selectedActionInput);
071: }
072: PrintParamAction printParamAction = (PrintParamAction) actionDefinition;
073: printParamAction
074: .setInputsToPrint((IActionInputValueProvider[]) msgInputs
075: .toArray(new IActionInputValueProvider[0]));
076: actionInputsList.refresh();
077: structuredSelection = new StructuredSelection(
078: (ActionInput) actionInputsList
079: .getElementAt(currentListIndex));
080: actionInputsList.setSelection(structuredSelection);
081: }
082: }
083: }
084:
085: protected void moveSelectedItemUp() {
086: IStructuredSelection structuredSelection = (IStructuredSelection) actionInputsList
087: .getSelection();
088: if (structuredSelection.size() == 1) {
089: ArrayList msgInputs = new ArrayList();
090: for (int i = 0; i < actionInputsList.getList()
091: .getItemCount(); i++) {
092: msgInputs.add((ActionInput) actionInputsList
093: .getElementAt(i));
094: }
095: ActionInput selectedActionInput = (ActionInput) structuredSelection
096: .getFirstElement();
097: int currentListIndex = msgInputs
098: .indexOf(selectedActionInput);
099: if (currentListIndex > 0) {
100: msgInputs.remove(currentListIndex);
101: currentListIndex--;
102: msgInputs
103: .add(currentListIndex, selectedActionInput);
104: PrintParamAction formatMsgAction = (PrintParamAction) actionDefinition;
105: formatMsgAction
106: .setInputsToPrint((IActionInputValueProvider[]) msgInputs
107: .toArray(new IActionInputValueProvider[0]));
108: actionInputsList.refresh();
109: structuredSelection = new StructuredSelection(
110: (ActionInput) actionInputsList
111: .getElementAt(currentListIndex));
112: actionInputsList.setSelection(structuredSelection);
113: }
114: }
115: }
116: }
117:
118: class PrintParamsTable extends ActionInputsList {
119: public PrintParamsTable(Composite parent) {
120: super (parent);
121: }
122:
123: protected void removeSelectedIOElement() {
124: IStructuredSelection selection = (IStructuredSelection) getSelection();
125: remove(selection.toArray());
126: List selections = selection.toList();
127: PrintParamAction printParamAction = (PrintParamAction) actionDefinition;
128: ArrayList inputsList = new ArrayList(Arrays
129: .asList(printParamAction.getInputsToPrint()));
130: inputsList.removeAll(selections);
131: printParamAction
132: .setInputsToPrint((IActionInputValueProvider[]) inputsList
133: .toArray(new IActionInputValueProvider[0]));
134: refresh();
135: }
136:
137: protected ActionInput addInput(AbstractIOElement input) {
138: PrintParamAction printParamAction = (PrintParamAction) actionDefinition;
139: List valueProviders = new ArrayList(Arrays
140: .asList(printParamAction.getInputsToPrint()));
141: valueProviders.add(input);
142: printParamAction
143: .setInputsToPrint((IActionInputValueProvider[]) valueProviders
144: .toArray(new IActionInputValueProvider[0]));
145: valueProviders = Arrays.asList(printParamAction
146: .getInputsToPrint());
147: refresh();
148: return (ActionInput) valueProviders.get(valueProviders
149: .size() - 1);
150: }
151: }
152:
153: NewActionInputText delimiterText;
154: PrintParamsTable paramList;
155: PrintParamsToolbar paramListToolbar;
156:
157: public String getComponentName() {
158: return PrintParamAction.COMPONENT_NAME;
159: }
160:
161: public String getName() {
162: return Messages
163: .getString("PrintParamsDetailsPage.ID_PRINT_PARAMS"); //$NON-NLS-1$
164: }
165:
166: public void createDetailsComposite(Composite parent) {
167: Composite actionConfigComposite = parent;
168:
169: GridLayout gridLayout = new GridLayout(2, true);
170: gridLayout.horizontalSpacing = 20;
171: actionConfigComposite.setLayout(gridLayout);
172:
173: Composite composite = WidgetFactory
174: .createComposite(actionConfigComposite);
175: gridLayout = new GridLayout(2, false);
176: gridLayout.marginWidth = 0;
177: gridLayout.marginHeight = 0;
178: composite.setLayout(gridLayout);
179: composite.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
180: WidgetFactory
181: .createLabel(
182: composite,
183: Messages
184: .getString("PrintParamsDetailsPage.UI_PARAMETERS_LABEL")); //$NON-NLS-1$
185:
186: WidgetFactory
187: .createLabel(
188: actionConfigComposite,
189: Messages
190: .getString("PrintParamsDetailsPage.UI_DELIMITER_LABEL")); //$NON-NLS-1$
191:
192: paramList = new PrintParamsTable(actionConfigComposite);
193: paramList.setFilter(this );
194: GridData gridData = new GridData(GridData.FILL_HORIZONTAL);
195: gridData.heightHint = 150;
196: paramList.getList().setLayoutData(gridData);
197:
198: paramListToolbar = new PrintParamsToolbar(composite, paramList);
199: gridData = new GridData(GridData.FILL_HORIZONTAL);
200: gridData.horizontalAlignment = GridData.END;
201: paramListToolbar.getControl().setLayoutData(gridData);
202:
203: gridData = new GridData(GridData.FILL_HORIZONTAL);
204: gridData.verticalAlignment = GridData.BEGINNING;
205: delimiterText = new NewActionInputText(actionConfigComposite,
206: gridData);
207: }
208:
209: public boolean accepts(IActionSequenceElement actionDef) {
210: return actionDef instanceof PrintParamAction;
211: }
212:
213: public void refresh() {
214: super .refresh();
215: delimiterText.setTargetInput(actionDefinition,
216: PrintParamAction.DELIMITER_ELEMENT);
217: paramList.setInput(actionDefinition);
218: paramListToolbar.refresh();
219: }
220:
221: public boolean accept(AbstractIOElement ioElement) {
222: boolean result = false;
223: if (ioElement.getType().equals(
224: ActionSequenceDocument.STRING_TYPE)) {
225: if ((ioElement instanceof ActionSequenceInput)
226: || (ioElement instanceof ActionInput)) {
227: result = !ioElement.getName().equals(
228: PrintParamAction.DELIMITER_ELEMENT);
229: } else if (ioElement instanceof ActionOutput) {
230: result = !((ActionOutput) ioElement).getPublicName()
231: .equals(PrintParamAction.DELIMITER_ELEMENT);
232: }
233: }
234: return result;
235: }
236:
237: }
|