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.Arrays;
016:
017: import org.eclipse.core.runtime.IPath;
018: import org.eclipse.core.runtime.Path;
019: import org.eclipse.jface.dialogs.MessageDialog;
020: import org.eclipse.swt.SWT;
021: import org.eclipse.swt.custom.StackLayout;
022: import org.eclipse.swt.events.SelectionEvent;
023: import org.eclipse.swt.events.SelectionListener;
024: import org.eclipse.swt.layout.GridData;
025: import org.eclipse.swt.layout.GridLayout;
026: import org.eclipse.swt.widgets.Button;
027: import org.eclipse.swt.widgets.Composite;
028: import org.eclipse.swt.widgets.FileDialog;
029: import org.eclipse.swt.widgets.Text;
030: import org.pentaho.actionsequence.dom.AbstractIOElement;
031: import org.pentaho.actionsequence.dom.ActionInput;
032: import org.pentaho.actionsequence.dom.ActionInputConstant;
033: import org.pentaho.actionsequence.dom.ActionOutput;
034: import org.pentaho.actionsequence.dom.ActionSequenceDocument;
035: import org.pentaho.actionsequence.dom.ActionSequenceInput;
036: import org.pentaho.actionsequence.dom.IActionSequenceElement;
037: import org.pentaho.actionsequence.dom.actions.SubActionAction;
038: import org.pentaho.designstudio.controls.ActionInputsList;
039: import org.pentaho.designstudio.controls.ActionInputsListToolbar;
040: import org.pentaho.designstudio.controls.ActionOutputsTable;
041: import org.pentaho.designstudio.controls.NewActionInputCombo;
042: import org.pentaho.designstudio.controls.NewActionInputText;
043: import org.pentaho.designstudio.controls.WidgetFactory;
044: import org.pentaho.designstudio.editors.actionsequence.pages.actions.IActionIOFilter;
045: import org.pentaho.designstudio.messages.Messages;
046: import org.pentaho.designstudio.util.SolutionHelper;
047:
048: /**
049: * The template describing the audit action definition.
050: *
051: */
052: public class SubActionDetailsPage extends ActionDetailsPage implements
053: IActionIOFilter, SelectionListener {
054:
055: public static final String SOLUTION_FILE_PREFIX = "solution:"; //$NON-NLS-1$
056: public static final String DISPLAY_NAME = Messages
057: .getString("SubActionDetailsPage.UI_COMPONENT_NAME_SUB_ACTION"); //$NON-NLS-1$
058:
059: class XActionFileText extends NewActionInputText {
060: public XActionFileText(Composite parent, Object layoutData) {
061: super (parent, layoutData);
062: }
063:
064: public void refresh() {
065: inputText.removeModifyListener(this );
066: inputText.setText(""); //$NON-NLS-1$
067: String solName = ((SubActionAction) actionDefinition)
068: .getSolution().getStringValue();
069: if ((solName != null) && solName.equals(solutionName)) {
070: String actionName = ((SubActionAction) actionDefinition)
071: .getAction().getStringValue();
072: if ((actionName != null)
073: && (actionName.trim().length() > 0)) {
074: String pathName = ((SubActionAction) actionDefinition)
075: .getPath().getStringValue();
076: if ((pathName != null)
077: && (pathName.trim().length() > 0)) {
078: inputText.setText(SOLUTION_FILE_PREFIX
079: + "/" + pathName + "/" + actionName); //$NON-NLS-1$ //$NON-NLS-2$
080: } else {
081: inputText.setText(SOLUTION_FILE_PREFIX
082: + "/" + actionName); //$NON-NLS-1$
083: }
084: }
085: }
086: inputText.addModifyListener(this );
087: }
088:
089: public void updateActionSequence() {
090: String resourceFileName = inputText.getText().trim();
091: IPath filePath = new Path(resourceFileName);
092: IPath relativeSolutionPath = null;
093: String solutionRoot = SolutionHelper
094: .getSolutionRoot(basePath.toString());
095: Path solutionPath = new Path(solutionRoot);
096: if ((resourceFileName.length() == 0)
097: || resourceFileName.equals(SOLUTION_FILE_PREFIX)) {
098: ((SubActionAction) actionDefinition).setSolution(null);
099: ((SubActionAction) actionDefinition).setPath(null);
100: ((SubActionAction) actionDefinition).setAction(null);
101: } else if (SOLUTION_FILE_PREFIX
102: .equals(filePath.getDevice())
103: || (filePath.getDevice() == null)) {
104: relativeSolutionPath = filePath.setDevice(null)
105: .makeRelative();
106: } else if ((filePath.getDevice() == null)
107: && !filePath.isAbsolute()) {
108: filePath = basePath.append(filePath.toString());
109: relativeSolutionPath = filePath.setDevice(null)
110: .removeFirstSegments(
111: solutionPath.segmentCount());
112: } else {
113: String fileSolution = SolutionHelper
114: .getSolutionName(resourceFileName);
115: if (solutionName.equals(fileSolution)) {
116: if (filePath.matchingFirstSegments(solutionPath) == solutionPath
117: .segmentCount()) {
118: relativeSolutionPath = filePath.setDevice(null)
119: .removeFirstSegments(
120: solutionPath.segmentCount());
121: }
122: }
123: }
124:
125: if (relativeSolutionPath != null) {
126: ((SubActionAction) actionDefinition)
127: .setSolution(new ActionInputConstant(
128: solutionName));
129: if (relativeSolutionPath.segmentCount() > 1) {
130: ((SubActionAction) actionDefinition)
131: .setPath(new ActionInputConstant(
132: relativeSolutionPath
133: .removeLastSegments(1)
134: .toString()));
135: ((SubActionAction) actionDefinition)
136: .setAction(new ActionInputConstant(
137: relativeSolutionPath
138: .removeFirstSegments(
139: relativeSolutionPath
140: .segmentCount() - 1)
141: .toString()));
142: } else {
143: ((SubActionAction) actionDefinition)
144: .setPath(new ActionInputConstant("")); //$NON-NLS-1$
145: ((SubActionAction) actionDefinition)
146: .setAction(new ActionInputConstant(
147: relativeSolutionPath.toString()));
148: }
149: }
150: }
151:
152: }
153:
154: NewActionInputCombo solution;
155: NewActionInputCombo path;
156: NewActionInputCombo xaction;
157: NewActionInputCombo proxySession;
158: ActionInputsList jobInputsList;
159: ActionInputsListToolbar jobInputsToolbar;
160: protected ActionOutputsTable actionOutputsTable;
161: Composite basicSubActionComposite;
162: Composite advancedSubActionComposite;
163: Button browseBtn;
164:
165: IPath basePath;
166: String solutionName;
167:
168: Composite stackedComposite;
169: StackLayout stackLayout;
170: XActionFileText xActionFile;
171:
172: /**
173: * Create an audit template.
174: */
175: public SubActionDetailsPage(IPath basePath) {
176: super ();
177: this .basePath = basePath;
178: solutionName = SolutionHelper.getSolutionName(basePath
179: .toString());
180: }
181:
182: /* (non-Javadoc)
183: * @see org.pentaho.designstudio.editors.actionsequence.pages.actions.templates.ActionDefinitionTemplate#getComponentClassName()
184: */
185: public String getComponentName() {
186: return SubActionAction.COMPONENT_NAME;
187: }
188:
189: /* (non-Javadoc)
190: * @see org.pentaho.designstudio.editors.actionsequence.pages.actions.templates.ActionDefinitionTemplate#getDisplayName()
191: */
192: public String getName() {
193: return DISPLAY_NAME;
194: }
195:
196: public void createDetailsComposite(Composite parent) {
197: Composite actionConfigComposite = parent;
198: GridLayout gridLayout = new GridLayout(2, true);
199: gridLayout.horizontalSpacing = 10;
200: actionConfigComposite.setLayout(gridLayout);
201:
202: stackedComposite = WidgetFactory
203: .createComposite(actionConfigComposite);
204: stackLayout = new StackLayout();
205: stackedComposite.setLayout(stackLayout);
206: GridData gridData = new GridData(GridData.FILL_HORIZONTAL);
207: gridData.verticalSpan = 2;
208: stackedComposite.setLayoutData(gridData);
209:
210: basicSubActionComposite = WidgetFactory
211: .createComposite(stackedComposite);
212: gridLayout = new GridLayout();
213: gridLayout.marginWidth = 1;
214: gridLayout.marginHeight = 1;
215: basicSubActionComposite.setLayout(gridLayout);
216:
217: advancedSubActionComposite = WidgetFactory
218: .createComposite(stackedComposite);
219: gridLayout = new GridLayout();
220: gridLayout.marginWidth = 1;
221: gridLayout.marginHeight = 1;
222: advancedSubActionComposite.setLayout(gridLayout);
223:
224: WidgetFactory.createLabel(basicSubActionComposite, Messages
225: .getString("SubActionDetailsPage.XACTION_FILE_LABEL")); //$NON-NLS-1$
226: xActionFile = new XActionFileText(basicSubActionComposite,
227: new GridData(GridData.FILL_HORIZONTAL));
228: browseBtn = WidgetFactory
229: .createButton(
230: basicSubActionComposite,
231: Messages
232: .getString("JFreeReportDetailsPage.UI_BROWSE_LABEL"), SWT.FLAT); //$NON-NLS-1$
233: browseBtn.addSelectionListener(this );
234: gridData = new GridData(GridData.FILL_HORIZONTAL);
235: gridData.horizontalAlignment = GridData.END;
236: browseBtn.setLayoutData(gridData);
237:
238: WidgetFactory.createLabel(advancedSubActionComposite, Messages
239: .getString("SubActionDetailsPage.UI_SOLUTION_LABEL")); //$NON-NLS-1$
240: solution = new NewActionInputCombo(advancedSubActionComposite,
241: new GridData(GridData.FILL_HORIZONTAL));
242: WidgetFactory.createLabel(advancedSubActionComposite, Messages
243: .getString("SubActionDetailsPage.UI_PATH_LABEL")); //$NON-NLS-1$
244: path = new NewActionInputCombo(advancedSubActionComposite,
245: new GridData(GridData.FILL_HORIZONTAL));
246: WidgetFactory
247: .createLabel(
248: advancedSubActionComposite,
249: Messages
250: .getString("SubActionDetailsPage.UI_XACTION_NAME_LABEL")); //$NON-NLS-1$
251: xaction = new NewActionInputCombo(advancedSubActionComposite,
252: new GridData(GridData.FILL_HORIZONTAL));
253: WidgetFactory
254: .createLabel(
255: advancedSubActionComposite,
256: Messages
257: .getString("SubActionDetailsPage.UI_PROXY_SESSION_NAME_LABEL")); //$NON-NLS-1$
258: proxySession = new NewActionInputCombo(
259: advancedSubActionComposite, new GridData(
260: GridData.FILL_HORIZONTAL));
261:
262: Composite composite = WidgetFactory
263: .createComposite(actionConfigComposite);
264: gridLayout = new GridLayout(2, false);
265: gridLayout.marginWidth = 0;
266: gridLayout.marginHeight = 0;
267: composite.setLayout(gridLayout);
268: composite.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
269: WidgetFactory
270: .createLabel(
271: composite,
272: Messages
273: .getString("SubActionDetailsPage.EXTERNAL_ACTION_PARAMETERS")); //$NON-NLS-1$
274:
275: jobInputsList = new ActionInputsList(actionConfigComposite);
276: gridData = new GridData(GridData.FILL_HORIZONTAL);
277: gridData.verticalAlignment = SWT.FILL;
278: jobInputsList.getControl().setLayoutData(gridData);
279: jobInputsList.setFilter(this );
280:
281: jobInputsToolbar = new ActionInputsListToolbar(composite,
282: jobInputsList);
283: gridData = new GridData(GridData.FILL_HORIZONTAL);
284: gridData.horizontalAlignment = GridData.END;
285: jobInputsToolbar.getControl().setLayoutData(gridData);
286:
287: gridData = new GridData();
288: gridData.horizontalSpan = 2;
289: WidgetFactory
290: .createLabel(actionConfigComposite, "").setLayoutData(gridData); //$NON-NLS-1$
291: gridData = new GridData();
292: gridData.horizontalSpan = 2;
293: WidgetFactory
294: .createLabel(
295: actionConfigComposite,
296: Messages
297: .getString("SubActionDetailsPage.ACTION_OUTPUTS")).setLayoutData(gridData); //$NON-NLS-1$
298: actionOutputsTable = new ActionOutputsTable(
299: actionConfigComposite);
300: gridData = new GridData(GridData.FILL_HORIZONTAL);
301: gridData.heightHint = 150;
302: gridData.widthHint = 10;
303: actionOutputsTable.getTable().setLayoutData(gridData);
304: }
305:
306: public void refresh() {
307: super .refresh();
308: solution.setTargetInput(actionDefinition,
309: SubActionAction.SOLUTION_ELEMENT,
310: ActionSequenceDocument.STRING_TYPE);
311: path.setTargetInput(actionDefinition,
312: SubActionAction.PATH_ELEMENT,
313: ActionSequenceDocument.STRING_TYPE);
314: xaction.setTargetInput(actionDefinition,
315: SubActionAction.ACTION_ELEMENT,
316: ActionSequenceDocument.STRING_TYPE);
317: proxySession.setTargetInput(actionDefinition,
318: SubActionAction.PROXY_ELEMENT,
319: ActionSequenceDocument.STRING_TYPE);
320: jobInputsList.setInput(actionDefinition);
321: jobInputsToolbar.refresh();
322: actionOutputsTable.setInput(actionDefinition);
323: xActionFile.setTargetInput(actionDefinition, null);
324: if ((solutionName != null)
325: && (solutionName.trim().length() > 0)) {
326: stackLayout.topControl = basicSubActionComposite;
327: } else {
328: stackLayout.topControl = advancedSubActionComposite;
329: }
330: stackedComposite.layout();
331: }
332:
333: public boolean accept(AbstractIOElement ioElement) {
334: String name = null;
335: if ((ioElement instanceof ActionSequenceInput)
336: || (ioElement instanceof ActionInput)) {
337: name = ioElement.getName();
338: } else if (ioElement instanceof ActionOutput) {
339: name = ((ActionOutput) ioElement).getPublicName();
340: }
341: return (name != null)
342: && !Arrays.asList(
343: ((SubActionAction) actionDefinition)
344: .getReservedInputNames())
345: .contains(name);
346: }
347:
348: public boolean accepts(IActionSequenceElement actionDef) {
349: return actionDef instanceof SubActionAction;
350: }
351:
352: public void widgetDefaultSelected(SelectionEvent e) {
353: }
354:
355: public void widgetSelected(SelectionEvent e) {
356: FileDialog fileChooser = new FileDialog(browseBtn.getShell(),
357: SWT.OPEN);
358: fileChooser.setText(Messages
359: .getString("SubActionDetailsPage.FILE_CHOOSER_TITLE")); //$NON-NLS-1$
360: fileChooser.setFilterExtensions(new String[] {
361: "*.xaction", "*.*" }); //$NON-NLS-1$ //$NON-NLS-2$
362: fileChooser
363: .setFilterNames(new String[] {
364: "Action Sequence", Messages.getString("JFreeReportDetailsPage.ALL_FILES") }); //$NON-NLS-1$ //$NON-NLS-2$
365: fileChooser.setFilterPath(basePath.toString());
366: String filename = fileChooser.open();
367: if (filename != null) {
368: String fileSolution = SolutionHelper
369: .getSolutionName(filename);
370: String solutionRoot = SolutionHelper
371: .getSolutionRoot(basePath.toString());
372: Path solutionPath = new Path(solutionRoot);
373: Path filePath = new Path(filename);
374: if (solutionName.equals(fileSolution)) {
375: if (filePath.matchingFirstSegments(solutionPath) == solutionPath
376: .segmentCount()) {
377: ((Text) xActionFile.getControl())
378: .setText(filePath
379: .setDevice("solution:").removeFirstSegments(solutionPath.segmentCount()).makeAbsolute().toString()); //$NON-NLS-1$
380: }
381: } else {
382: MessageDialog.openError(browseBtn.getShell(),
383: DISPLAY_NAME, "File must be within solution."); //$NON-NLS-1$
384: }
385: }
386: }
387: }
|