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: /*******************************************************************************
014: * Copyright (c) 2000, 2004 IBM Corporation and others.
015: * All rights reserved. This program and the accompanying materials
016: * are made available under the terms of the Common Public License v1.0
017: * which accompanies this distribution, and is available at
018: * http://www.eclipse.org/legal/cpl-v10.html
019: *
020: * Contributors:
021: * IBM Corporation - initial API and implementation
022: *******************************************************************************/package org.pentaho.designstudio.editors.actionsequence.pages.actions.details;
023:
024: import java.util.ArrayList;
025: import java.util.Arrays;
026: import java.util.List;
027:
028: import org.eclipse.jface.viewers.ISelection;
029: import org.eclipse.jface.viewers.IStructuredContentProvider;
030: import org.eclipse.jface.viewers.IStructuredSelection;
031: import org.eclipse.jface.viewers.LabelProvider;
032: import org.eclipse.jface.viewers.ListViewer;
033: import org.eclipse.jface.viewers.Viewer;
034: import org.eclipse.swt.SWT;
035: import org.eclipse.swt.events.ModifyEvent;
036: import org.eclipse.swt.events.ModifyListener;
037: import org.eclipse.swt.layout.FillLayout;
038: import org.eclipse.swt.layout.GridData;
039: import org.eclipse.swt.layout.GridLayout;
040: import org.eclipse.swt.widgets.Composite;
041: import org.eclipse.swt.widgets.Label;
042: import org.eclipse.swt.widgets.Text;
043: import org.eclipse.ui.forms.IFormPart;
044: import org.eclipse.ui.forms.IManagedForm;
045: import org.eclipse.ui.forms.widgets.Section;
046: import org.eclipse.ui.forms.widgets.TableWrapData;
047: import org.eclipse.ui.forms.widgets.TableWrapLayout;
048: import org.pentaho.actionsequence.dom.ActionIfStatement;
049: import org.pentaho.actionsequence.dom.ActionOutput;
050: import org.pentaho.actionsequence.dom.ActionSequenceInput;
051: import org.pentaho.actionsequence.dom.IActionSequenceElement;
052: import org.pentaho.designstudio.controls.WidgetFactory;
053: import org.pentaho.designstudio.editors.actionsequence.pages.IActionSequenceDetailsPage;
054: import org.pentaho.designstudio.messages.Messages;
055:
056: /**
057: * Page for viewing the details of an "actions" element in an action sequence.
058: * @author Angelo Rodriguez
059: */
060: public class ActionIfDetailsPage implements IActionSequenceDetailsPage,
061: ModifyListener {
062:
063: public class MyContentProvider implements
064: IStructuredContentProvider {
065:
066: public Object[] getElements(Object ioElement) {
067: List availInputs = new ArrayList();
068: if (actionIf != null) {
069: availInputs.addAll(Arrays.asList(actionIf
070: .getAvailInputVariables()));
071: }
072: return availInputs.toArray();
073: }
074:
075: public void dispose() {
076: // TODO Auto-generated method stub
077:
078: }
079:
080: public void inputChanged(Viewer viewer, Object oldInput,
081: Object newInput) {
082: // TODO Auto-generated method stub
083:
084: }
085: }
086:
087: ActionIfStatement actionIf;
088: protected IManagedForm mform;
089: private boolean dirty = false;
090: Text conditionText;
091: ListViewer availInputsList;
092:
093: /**
094: * Creates a detail page.
095: */
096: public ActionIfDetailsPage() {
097: }
098:
099: public void createDetailsComposite(Composite parent) {
100: }
101:
102: /* (non-Javadoc)
103: * @see org.eclipse.ui.forms.IDetailsPage#createContents(org.eclipse.swt.widgets.Composite)
104: */
105: public void createContents(Composite parent) {
106: TableWrapLayout layout = new TableWrapLayout();
107: layout.topMargin = 5;
108: layout.leftMargin = 5;
109: layout.rightMargin = 2;
110: layout.bottomMargin = 5;
111: parent.setLayout(layout);
112: createGeneralSection(parent);
113: }
114:
115: /**
116: * Synchronizes this page with the contents of the actions element being displayed.
117: */
118: public void refresh() {
119: conditionText.removeModifyListener(this );
120: conditionText.setText(actionIf.getCondition());
121: conditionText.addModifyListener(this );
122: availInputsList.setInput(actionIf);
123: }
124:
125: private void createGeneralSection(Composite parent) {
126: Section section = createSection(parent, Messages
127: .getString("ActionIfDetailsPage.ACTION_TYPE_LABEL")); //$NON-NLS-1$
128: Composite composite = (Composite) section.getClient();
129: composite.setLayout(new GridLayout());
130:
131: Composite topComposite = WidgetFactory
132: .createComposite(composite);
133: GridLayout gridLayout = new GridLayout();
134: topComposite.setLayout(gridLayout);
135: GridData gridData = new GridData(GridData.FILL_HORIZONTAL);
136: gridData.heightHint = 150;
137: topComposite.setLayoutData(gridData);
138:
139: Label label = WidgetFactory
140: .createLabel(
141: topComposite,
142: Messages
143: .getString("ActionIfDetailsPage.VALID_PARAMS_MSG"), SWT.WRAP); //$NON-NLS-1$
144: gridData = new GridData(GridData.FILL_HORIZONTAL);
145: gridData.widthHint = 10;
146: label.setLayoutData(gridData);
147: availInputsList = new ListViewer(topComposite, SWT.V_SCROLL
148: | SWT.H_SCROLL | SWT.BORDER);
149: availInputsList.setContentProvider(new MyContentProvider());
150: availInputsList.setLabelProvider(new LabelProvider() {
151: public String getText(Object element) {
152: String text = ""; //$NON-NLS-1$
153: if (element instanceof ActionSequenceInput) {
154: ActionSequenceInput ioElement = (ActionSequenceInput) element;
155: text = ioElement.getName();
156: } else if (element instanceof ActionOutput) {
157: ActionOutput ioElement = (ActionOutput) element;
158: text = ioElement.getPublicName();
159: }
160: return text;
161: }
162: });
163: gridData = new GridData(GridData.FILL_BOTH);
164: availInputsList.getList().setLayoutData(gridData);
165:
166: WidgetFactory.createLabel(composite, ""); //$NON-NLS-1$
167: WidgetFactory.createLabel(composite, ""); //$NON-NLS-1$
168:
169: WidgetFactory.createLabel(composite, Messages
170: .getString("ActionIfDetailsPage.CONDITION_LABEL")); //$NON-NLS-1$
171:
172: gridData = new GridData(GridData.FILL_HORIZONTAL);
173: gridData.heightHint = 50;
174: if (System.getProperty("os.name").startsWith("Mac")) {
175: composite = WidgetFactory.createComposite(composite,
176: SWT.BORDER);
177: composite.setLayoutData(gridData);
178: composite.setLayout(new FillLayout());
179: conditionText = WidgetFactory
180: .createText(
181: composite,
182: "", SWT.MULTI | SWT.WRAP | SWT.V_SCROLL | SWT.BORDER); //$NON-NLS-1$
183: } else {
184: conditionText = WidgetFactory
185: .createText(
186: composite,
187: "", SWT.MULTI | SWT.WRAP | SWT.V_SCROLL | SWT.BORDER); //$NON-NLS-1$
188: conditionText.setLayoutData(gridData);
189: }
190: conditionText.addModifyListener(this );
191: }
192:
193: public boolean accepts(IActionSequenceElement detailElement) {
194: return detailElement instanceof ActionIfStatement;
195: }
196:
197: public String getName() {
198: return Messages
199: .getString("ActionIfDetailsPage.IF_STATEMENT_NAME"); //$NON-NLS-1$
200: }
201:
202: public void setActionSequenceElement(IActionSequenceElement element) {
203: actionIf = (ActionIfStatement) element;
204: refresh();
205: }
206:
207: /* (non-Javadoc)
208: * @see org.eclipse.ui.forms.IFormPart#initialize(org.eclipse.ui.forms.IManagedForm)
209: */
210: public void initialize(IManagedForm form) {
211: this .mform = form;
212: }
213:
214: /* (non-Javadoc)
215: * @see org.eclipse.ui.forms.IFormPart#isDirty()
216: */
217: public boolean isDirty() {
218: return dirty;
219: }
220:
221: /* (non-Javadoc)
222: * @see org.eclipse.ui.forms.IFormPart#commit(boolean)
223: */
224: public void commit(boolean onSave) {
225: }
226:
227: /* (non-Javadoc)
228: * @see org.eclipse.ui.forms.IFormPart#setFormInput(java.lang.Object)
229: */
230: public boolean setFormInput(Object input) {
231: return false;
232: }
233:
234: /* (non-Javadoc)
235: * @see org.eclipse.ui.forms.IFormPart#setFocus()
236: */
237: public void setFocus() {
238: }
239:
240: /* (non-Javadoc)
241: * @see org.eclipse.ui.forms.IFormPart#isStale()
242: */
243: public boolean isStale() {
244: return false;
245: }
246:
247: /**
248: * Returns the form on which this details page appears.
249: * */
250: protected IManagedForm getManagedForm() {
251: return mform;
252: }
253:
254: /* (non-Javadoc)
255: * @see org.eclipse.ui.forms.IFormPart#dispose()
256: */
257: public void dispose() {
258: }
259:
260: public void selectionChanged(IFormPart part, ISelection selection) {
261: IStructuredSelection ssel = (IStructuredSelection) selection;
262: if (ssel.size() == 1) {
263: setActionSequenceElement((IActionSequenceElement) ssel
264: .getFirstElement());
265: } else {
266: setActionSequenceElement(null);
267: }
268: }
269:
270: public IActionSequenceElement getActionSequenceElement() {
271: return actionIf;
272: }
273:
274: protected Section createSection(Composite parent,
275: String sectionName, int style) {
276: Section section = WidgetFactory.createSection(parent, style);
277: section.setText(sectionName);
278:
279: section.setLayoutData(new TableWrapData(
280: TableWrapData.FILL_GRAB, TableWrapData.TOP));
281:
282: WidgetFactory.createSeparator(section);
283: Composite composite = WidgetFactory.createComposite(section);
284: composite.setLayout(new FillLayout());
285: composite.setLayoutData(new TableWrapData(
286: TableWrapData.FILL_GRAB));
287: section.setClient(composite);
288:
289: return section;
290: }
291:
292: protected Section createSection(Composite parent, String sectionName) {
293: return createSection(parent, sectionName, Section.EXPANDED);
294: }
295:
296: public void modifyText(ModifyEvent e) {
297: actionIf.setCondition(conditionText.getText());
298: }
299:
300: public void grabFocus() {
301: conditionText.forceFocus();
302: }
303: }
|