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.parameters;
023:
024: import java.util.ArrayList;
025: import java.util.Arrays;
026: import java.util.HashMap;
027:
028: import javax.swing.table.DefaultTableModel;
029:
030: import org.eclipse.jface.viewers.ISelection;
031: import org.eclipse.jface.viewers.IStructuredSelection;
032: import org.eclipse.jface.window.Window;
033: import org.eclipse.swt.SWT;
034: import org.eclipse.swt.custom.StackLayout;
035: import org.eclipse.swt.events.FocusEvent;
036: import org.eclipse.swt.events.FocusListener;
037: import org.eclipse.swt.events.KeyEvent;
038: import org.eclipse.swt.events.KeyListener;
039: import org.eclipse.swt.events.ModifyEvent;
040: import org.eclipse.swt.events.ModifyListener;
041: import org.eclipse.swt.events.SelectionEvent;
042: import org.eclipse.swt.events.SelectionListener;
043: import org.eclipse.swt.layout.FillLayout;
044: import org.eclipse.swt.layout.GridData;
045: import org.eclipse.swt.layout.GridLayout;
046: import org.eclipse.swt.widgets.Button;
047: import org.eclipse.swt.widgets.Combo;
048: import org.eclipse.swt.widgets.Composite;
049: import org.eclipse.swt.widgets.Control;
050: import org.eclipse.swt.widgets.Label;
051: import org.eclipse.swt.widgets.Text;
052: import org.eclipse.ui.forms.IFormPart;
053: import org.eclipse.ui.forms.IManagedForm;
054: import org.eclipse.ui.forms.widgets.Section;
055: import org.eclipse.ui.forms.widgets.TableWrapLayout;
056: import org.pentaho.actionsequence.dom.AbstractIOElement;
057: import org.pentaho.actionsequence.dom.ActionControlStatement;
058: import org.pentaho.actionsequence.dom.ActionSequenceDocument;
059: import org.pentaho.actionsequence.dom.ActionSequenceInput;
060: import org.pentaho.actionsequence.dom.ActionSequenceInputSource;
061: import org.pentaho.actionsequence.dom.ActionSequenceOutput;
062: import org.pentaho.actionsequence.dom.IActionSequenceDocumentListener;
063: import org.pentaho.actionsequence.dom.IActionSequenceElement;
064: import org.pentaho.actionsequence.dom.actions.ActionDefinition;
065: import org.pentaho.designstudio.controls.IActionSequenceControl;
066: import org.pentaho.designstudio.controls.WidgetFactory;
067: import org.pentaho.designstudio.controls.XMLAwareComposite;
068: import org.pentaho.designstudio.editors.actionsequence.pages.IActionSequenceDetailsPage;
069: import org.pentaho.designstudio.messages.Messages;
070:
071: /**
072: * Page used to view and modify the details of a specific action sequence input
073: * parameter.
074: *
075: * @author Angelo Rodriguez
076: *
077: */
078: public class InputDetailsPage implements IActionSequenceDetailsPage,
079: ModifyListener, IActionSequenceDocumentListener {
080:
081: public class InputTypeCombo implements IActionSequenceControl,
082: ModifyListener {
083: protected Combo combo;
084:
085: /**
086: * @param toolkit the toolkit being used to create UI components
087: * @param parent the parent control
088: * @param layoutData the check box layout data. Can be null.
089: */
090: public InputTypeCombo(Composite parent, Object layoutData) {
091: combo = WidgetFactory.createCombo(parent, SWT.NONE);
092: if (layoutData != null) {
093: combo.setLayoutData(layoutData);
094: }
095: combo.setItems(ActionSequenceDocument.IO_TYPES);
096: combo.addModifyListener(this );
097: }
098:
099: public void modifyText(ModifyEvent e) {
100: if (Arrays.asList(ActionSequenceDocument.IO_TYPES)
101: .contains(combo.getText().trim())) {
102: updateActionSequence();
103: refreshInputType();
104: }
105: }
106:
107: public void refresh() {
108: combo.removeModifyListener(this );
109: combo.setText(actionSequenceInput.getType());
110: combo.addModifyListener(this );
111: }
112:
113: public void updateActionSequence() {
114: String txtString = combo.getText().trim();
115: if (Arrays.asList(ActionSequenceDocument.IO_TYPES)
116: .contains(txtString)) {
117: actionSequenceInput.setType(txtString);
118: }
119: }
120:
121: public String getText() {
122: return combo.getText();
123: }
124:
125: public void setText(String text) {
126: combo.setText(text);
127: }
128:
129: public Control getControl() {
130: return combo;
131: }
132:
133: }
134:
135: public class DefaultValueCheckBox implements SelectionListener {
136:
137: protected Button button;
138: protected String inputName;
139:
140: public DefaultValueCheckBox(String label, Composite parent,
141: Object layoutData) {
142: button = WidgetFactory.createButton(parent, label,
143: SWT.CHECK);
144:
145: if (layoutData != null) {
146: button.setLayoutData(layoutData);
147: }
148:
149: button.addSelectionListener(this );
150: }
151:
152: public void widgetDefaultSelected(SelectionEvent e) {
153: }
154:
155: public void widgetSelected(SelectionEvent e) {
156: String elementType = actionSequenceInput.getType();
157: if (elementType.equals(ActionSequenceDocument.STRING_TYPE)) {
158: defaultStringText
159: .removeModifyListener(InputDetailsPage.this );
160: defaultStringText.setText(""); //$NON-NLS-1$
161: actionSequenceInput.setDefaultValue(button
162: .getSelection() ? "" : null); //$NON-NLS-1$
163: defaultStringText
164: .addModifyListener(InputDetailsPage.this );
165: } else if (elementType
166: .equals(ActionSequenceDocument.LONG_TYPE)
167: || elementType
168: .equals(ActionSequenceDocument.INTEGER_TYPE)
169: || elementType
170: .equals(ActionSequenceDocument.BIGDECIMAL_TYPE)) {
171: defaultNumberText
172: .removeModifyListener(InputDetailsPage.this );
173: defaultNumberText.setText(""); //$NON-NLS-1$
174: actionSequenceInput.setDefaultValue(button
175: .getSelection() ? "" : null); //$NON-NLS-1$
176: defaultNumberText
177: .addModifyListener(InputDetailsPage.this );
178: } else if (elementType
179: .equals(ActionSequenceDocument.STRING_LIST_TYPE)) {
180: actionSequenceInput.setDefaultValue(button
181: .getSelection() ? new String[0] : null);
182: stringListViewer.refresh();
183: } else if (elementType
184: .equals(ActionSequenceDocument.PROPERTY_MAP_TYPE)) {
185: actionSequenceInput.setDefaultValue(button
186: .getSelection() ? new HashMap() : null);
187: propertyMapViewer.refresh();
188: } else if (elementType
189: .equals(ActionSequenceDocument.PROPERTY_MAP_LIST_TYPE)) {
190: actionSequenceInput.setDefaultValue(button
191: .getSelection() ? new DefaultTableModel()
192: : null, true);
193: propertyMapListViewer.refresh();
194: } else if (elementType
195: .equals(ActionSequenceDocument.RESULTSET_TYPE)) {
196: actionSequenceInput.setDefaultValue(button
197: .getSelection() ? new DefaultTableModel()
198: : null);
199: resultSetViewer.refresh();
200: }
201: }
202:
203: public void refresh() {
204: button.removeSelectionListener(this );
205: button.setSelection((actionSequenceInput != null)
206: && (actionSequenceInput.getDefaultValue() != null));
207: button.addSelectionListener(this );
208: }
209: }
210:
211: /** The form on which this details page appears. */
212: ActionSequenceInput actionSequenceInput;
213:
214: protected IManagedForm mform;
215: private boolean dirty = false;
216:
217: Text paramNameEditor;
218: String originalParamName;
219:
220: InputTypeCombo paramTypeEditor;
221:
222: DefaultValueCheckBox hasDefaultCheckBox;
223:
224: Text defaultStringText;
225:
226: Text defaultNumberText;
227:
228: Composite stackedComposite;
229:
230: Composite defaultStringComposite;
231:
232: Composite defaultLongComposite;
233:
234: Composite propertyMapComposite;
235:
236: Composite propertyMapListComposite;
237:
238: Composite stringListComposite;
239:
240: Composite resultSetComposite;
241:
242: StringListViewer stringListViewer;
243:
244: InputMapViewer propertyMapViewer;
245:
246: InputTableViewer propertyMapListViewer;
247:
248: InputTableViewer resultSetViewer;
249:
250: StackLayout stackLayout;
251:
252: InputSrcViewer inputSourceViewer;
253:
254: boolean syncInputNameWithSourceName = false;
255:
256: ArrayList parameterReferences = new ArrayList();
257:
258: /**
259: * Creates and input details page.
260: */
261: public InputDetailsPage() {
262: super ();
263: }
264:
265: public void grabFocus() {
266: paramNameEditor.forceFocus();
267: paramNameEditor.selectAll();
268: }
269:
270: /*
271: * (non-Javadoc)
272: *
273: * @see org.eclipse.ui.forms.IDetailsPage#createContents(org.eclipse.swt.widgets.Composite)
274: */
275: public void createContents(Composite parent) {
276: TableWrapLayout layout = new TableWrapLayout();
277: layout.topMargin = 5;
278: layout.leftMargin = 5;
279: layout.rightMargin = 2;
280: layout.bottomMargin = 5;
281: parent.setLayout(new GridLayout());
282:
283: createGeneralSection(parent);
284: createDefaultValuesSection(parent);
285: }
286:
287: private void createStringListComposite(Composite parent) {
288: stringListComposite = WidgetFactory.createComposite(parent);
289: GridLayout layout = new GridLayout();
290: stringListComposite.setLayout(layout);
291:
292: stringListViewer = new StringListViewer(WidgetFactory
293: .createTable(stringListComposite, SWT.FULL_SELECTION
294: | SWT.BORDER));
295: GridData layoutData = new GridData(GridData.FILL_HORIZONTAL);
296: layoutData.heightHint = 200;
297: layoutData.widthHint = 10;
298: stringListViewer.getTable().setLayoutData(layoutData);
299: }
300:
301: private void createPropertyMapComposite(Composite parent) {
302: propertyMapComposite = WidgetFactory.createComposite(parent);
303: GridLayout layout = new GridLayout();
304: propertyMapComposite.setLayout(layout);
305:
306: Composite composite = WidgetFactory
307: .createComposite(propertyMapComposite);
308: layout = new GridLayout();
309: layout.marginWidth = 0;
310: layout.marginHeight = 0;
311: composite.setLayout(layout);
312: composite.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
313:
314: propertyMapViewer = new InputMapViewer(propertyMapComposite,
315: SWT.FULL_SELECTION);
316: GridData layoutData = new GridData(GridData.FILL_BOTH);
317: layoutData.heightHint = 50;
318: layoutData.widthHint = 10;
319: propertyMapViewer.setLayoutData(layoutData);
320:
321: InputMapToolbar toolBar = new InputMapToolbar(composite,
322: propertyMapViewer);
323: layoutData = new GridData();
324: layoutData.grabExcessHorizontalSpace = true;
325: layoutData.horizontalAlignment = SWT.END;
326: toolBar.getControl().setLayoutData(layoutData);
327: }
328:
329: private void createPropertyMapListComposite(Composite parent) {
330: propertyMapListComposite = WidgetFactory
331: .createComposite(parent);
332: GridLayout layout = new GridLayout();
333: propertyMapListComposite.setLayout(layout);
334:
335: Composite composite = WidgetFactory
336: .createComposite(propertyMapListComposite);
337: layout = new GridLayout();
338: layout.marginWidth = 0;
339: layout.marginHeight = 0;
340: composite.setLayout(layout);
341: composite.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
342:
343: propertyMapListViewer = new InputTableViewer(
344: propertyMapListComposite, SWT.NONE, true);
345: GridData layoutData = new GridData(GridData.FILL_HORIZONTAL);
346: layoutData.heightHint = 200;
347: layoutData.widthHint = 10;
348: propertyMapListViewer.setLayoutData(layoutData);
349:
350: InputTableToolbar toolBar = new InputTableToolbar(composite,
351: propertyMapListViewer);
352: layoutData = new GridData();
353: layoutData.grabExcessHorizontalSpace = true;
354: layoutData.horizontalAlignment = SWT.END;
355: toolBar.getControl().setLayoutData(layoutData);
356: }
357:
358: private void createResultSetComposite(Composite parent) {
359: resultSetComposite = WidgetFactory.createComposite(parent);
360: GridLayout layout = new GridLayout();
361: resultSetComposite.setLayout(layout);
362:
363: Composite composite = WidgetFactory
364: .createComposite(resultSetComposite);
365: layout = new GridLayout();
366: layout.marginWidth = 0;
367: layout.marginHeight = 0;
368: composite.setLayout(layout);
369: composite.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
370:
371: resultSetViewer = new InputTableViewer(resultSetComposite,
372: SWT.NONE, false);
373: GridData layoutData = new GridData(GridData.FILL_HORIZONTAL);
374: layoutData.heightHint = 200;
375: resultSetViewer.setLayoutData(layoutData);
376:
377: InputTableToolbar toolBar = new InputTableToolbar(composite,
378: resultSetViewer);
379: layoutData = new GridData();
380: layoutData.grabExcessHorizontalSpace = true;
381: layoutData.horizontalAlignment = SWT.END;
382: toolBar.getControl().setLayoutData(layoutData);
383: }
384:
385: private void createDefaultLongComposite(Composite parent) {
386: defaultLongComposite = WidgetFactory.createComposite(parent);
387: defaultLongComposite.setLayout(new GridLayout(2, true));
388: GridData gridData = new GridData();
389: gridData.horizontalSpan = 2;
390: Label label = WidgetFactory
391: .createLabel(
392: defaultLongComposite,
393: Messages
394: .getString("InputDetailsPage.UI_DEFAULT_VALUE_LABEL")); //$NON-NLS-1$
395: label.setLayoutData(gridData);
396:
397: gridData = new GridData(GridData.FILL_HORIZONTAL);
398: gridData.widthHint = 10;
399: gridData.horizontalSpan = 1;
400: defaultNumberText = WidgetFactory.createText(
401: defaultLongComposite, ""); //$NON-NLS-1$
402: defaultNumberText.setLayoutData(gridData);
403: defaultNumberText.addModifyListener(this );
404: }
405:
406: private void createDefaultTextComposite(Composite parent) {
407: defaultStringComposite = WidgetFactory.createComposite(parent);
408: GridLayout layout = new GridLayout(3, true);
409: defaultStringComposite.setLayout(layout);
410:
411: GridData gridData = new GridData();
412: gridData.horizontalSpan = 3;
413: Label label = WidgetFactory
414: .createLabel(
415: defaultStringComposite,
416: Messages
417: .getString("InputDetailsPage.UI_DEFAULT_VALUE_LABEL")); //$NON-NLS-1$
418: label.setLayoutData(gridData);
419:
420: GridData layoutData = new GridData(GridData.FILL_HORIZONTAL);
421: layoutData.heightHint = 100;
422: layoutData.widthHint = 10;
423: layoutData.horizontalSpan = 2;
424: defaultStringText = WidgetFactory.createText(
425: defaultStringComposite, ""); //$NON-NLS-1$
426: defaultStringText.setLayoutData(layoutData);
427: defaultStringText.addModifyListener(this );
428: }
429:
430: private void createDefaultValuesSection(Composite parent) {
431: Section section = createSection(
432: parent,
433: Messages
434: .getString("InputDetailsPage.UI_DEFAULT_VALUE_SECTION_LABEL")); //$NON-NLS-1$
435: Composite composite = (Composite) section.getClient();
436: composite.setLayout(new GridLayout());
437:
438: hasDefaultCheckBox = new DefaultValueCheckBox(
439: Messages
440: .getString("InputDetailsPage.UI_HAS_DEFAULT_VALUE_CK_BOX"), composite, null); //$NON-NLS-1$
441:
442: stackLayout = new StackLayout();
443: stackedComposite = WidgetFactory.createComposite(composite);
444: stackedComposite.setLayout(stackLayout);
445: stackedComposite.setLayoutData(new GridData(
446: GridData.FILL_HORIZONTAL));
447:
448: createDefaultTextComposite(stackedComposite);
449: createDefaultLongComposite(stackedComposite);
450: createPropertyMapComposite(stackedComposite);
451: createPropertyMapListComposite(stackedComposite);
452: createResultSetComposite(stackedComposite);
453: createStringListComposite(stackedComposite);
454: }
455:
456: private void refreshInputType() {
457: defaultStringText.removeModifyListener(this );
458: defaultNumberText.removeModifyListener(this );
459: String inputType = actionSequenceInput.getType();
460: stackLayout.topControl = null;
461: stackedComposite.layout();
462: if (inputType.equals(ActionSequenceDocument.STRING_TYPE)
463: && (stackLayout.topControl != defaultStringComposite)) {
464: Object defVal = actionSequenceInput.getDefaultValue();
465: if (defVal instanceof String) {
466: defaultStringText.setText((String) defVal);
467: } else {
468: defaultStringText.setText(""); //$NON-NLS-1$
469: }
470: stackLayout.topControl = defaultStringComposite;
471: stackedComposite.layout();
472: } else if ((inputType.equals(ActionSequenceDocument.LONG_TYPE)
473: || inputType
474: .equals(ActionSequenceDocument.INTEGER_TYPE) || inputType
475: .equals(ActionSequenceDocument.BIGDECIMAL_TYPE))
476: && (stackLayout.topControl != defaultLongComposite)) {
477: Object defVal = actionSequenceInput.getDefaultValue();
478: if (defVal instanceof String) {
479: defaultNumberText.setText((String) defVal);
480: } else {
481: defaultNumberText.setText(""); //$NON-NLS-1$
482: }
483: stackLayout.topControl = defaultLongComposite;
484: stackedComposite.layout();
485: } else if (inputType
486: .equals(ActionSequenceDocument.PROPERTY_MAP_TYPE)
487: && (stackLayout.topControl != propertyMapComposite)) {
488: propertyMapViewer.refresh();
489: stackLayout.topControl = propertyMapComposite;
490: stackedComposite.layout();
491: } else if (inputType
492: .equals(ActionSequenceDocument.PROPERTY_MAP_LIST_TYPE)
493: && (stackLayout.topControl != propertyMapListComposite)) {
494: propertyMapListViewer.refresh();
495: stackLayout.topControl = propertyMapListComposite;
496: stackedComposite.layout();
497: } else if (inputType
498: .equals(ActionSequenceDocument.RESULTSET_TYPE)
499: && (stackLayout.topControl != resultSetComposite)) {
500: resultSetViewer.refresh();
501: stackLayout.topControl = resultSetComposite;
502: stackedComposite.layout();
503: } else if (inputType
504: .equals(ActionSequenceDocument.STRING_LIST_TYPE)) {
505: stringListViewer.refresh();
506: stackLayout.topControl = stringListComposite;
507: stackedComposite.layout();
508: }
509: hasDefaultCheckBox.refresh();
510: hasDefaultCheckBox.button
511: .setEnabled(stackLayout.topControl != null);
512: defaultStringText.addModifyListener(this );
513: defaultNumberText.addModifyListener(this );
514:
515: }
516:
517: /*
518: * (non-Javadoc)
519: *
520: * @see org.eclipse.swt.events.ModifyListener#modifyText(org.eclipse.swt.events.ModifyEvent)
521: */
522: public void modifyText(ModifyEvent e) {
523: if (e.widget == paramNameEditor) {
524: String inputName = paramNameEditor.getText().trim();
525: if (inputName.length() != 0) {
526: actionSequenceInput.setName(inputName);
527: }
528: } else if (e.widget == defaultNumberText) {
529: actionSequenceInput.setDefaultValue(defaultNumberText
530: .getText());
531: } else if (e.widget == defaultStringText) {
532: actionSequenceInput.setDefaultValue(defaultStringText
533: .getText());
534: }
535: }
536:
537: protected Section createSection(Composite parent, String sectionName) {
538: Section section = WidgetFactory.createSection(parent,
539: Section.TWISTIE | Section.EXPANDED);
540: section.setText(sectionName);
541:
542: section.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
543:
544: WidgetFactory.createSeparator(section);
545: XMLAwareComposite composite = new XMLAwareComposite(section,
546: SWT.NULL);
547: composite.setLayout(new FillLayout());
548: composite.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
549: section.setClient(composite);
550:
551: return section;
552: }
553:
554: private void createGeneralSection(Composite parent) {
555: Section section = createSection(parent, Messages
556: .getString("InputDetailsPage.UI_INPUT_SECTION")); //$NON-NLS-1$
557: Composite detailsComposite = (Composite) section.getClient();
558: GridLayout layout = new GridLayout(2, true);
559: layout.horizontalSpacing = 20;
560: detailsComposite.setLayout(layout);
561:
562: Label label = WidgetFactory.createLabel(detailsComposite,
563: Messages.getString("InputDetailsPage.UI_NAME_LABEL")); //$NON-NLS-1$
564:
565: Composite composite = WidgetFactory
566: .createComposite(detailsComposite);
567: composite.setLayout(new GridLayout(2, false));
568: composite.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
569: label = WidgetFactory.createLabel(composite, Messages
570: .getString("InputDetailsPage.UI_INPUT_SOURCE_LABEL")); //$NON-NLS-1$
571:
572: paramNameEditor = WidgetFactory
573: .createText(detailsComposite, ""); //$NON-NLS-1$
574: paramNameEditor.setLayoutData(new GridData(
575: GridData.FILL_HORIZONTAL));
576: paramNameEditor.addKeyListener(new KeyListener() {
577:
578: public void keyPressed(KeyEvent e) {
579: e.doit = !Character.isWhitespace(e.character)
580: && (e.character != '-');
581: }
582:
583: public void keyReleased(KeyEvent e) {
584: }
585:
586: });
587: paramNameEditor.addFocusListener(new FocusListener() {
588:
589: public void focusGained(FocusEvent e) {
590: originalParamName = actionSequenceInput.getName();
591: parameterReferences.clear();
592: parameterReferences.addAll(Arrays
593: .asList(actionSequenceInput.getDocument()
594: .getReferencesTo(actionSequenceInput)));
595: ActionSequenceOutput actionSequenceOutput = actionSequenceInput
596: .getDocument().getOutput(
597: actionSequenceInput.getName());
598: if (actionSequenceOutput != null) {
599: parameterReferences.add(actionSequenceOutput);
600: }
601: }
602:
603: public void focusLost(FocusEvent e) {
604: String currentParamName = actionSequenceInput.getName();
605: if (!currentParamName.equals(originalParamName)
606: && (parameterReferences.size()) > 0) {
607: UpdateParamReferencesDialog renameOutputDialog = new UpdateParamReferencesDialog(
608: paramNameEditor.getShell(),
609: actionSequenceInput, parameterReferences);
610: if (renameOutputDialog.open() == Window.CANCEL) {
611: paramNameEditor.setText(originalParamName);
612: }
613: }
614: }
615:
616: });
617: paramNameEditor.addModifyListener(this );
618:
619: inputSourceViewer = new InputSrcViewer(detailsComposite,
620: SWT.NONE);
621: GridData layoutData = new GridData(GridData.FILL_BOTH);
622: layoutData.verticalSpan = 4;
623: layoutData.widthHint = 10;
624: layoutData.heightHint = 100;
625: inputSourceViewer.setLayoutData(layoutData);
626:
627: InputSrcToolbar coolBar = new InputSrcToolbar(composite,
628: inputSourceViewer);
629: layoutData = new GridData();
630: layoutData.grabExcessHorizontalSpace = true;
631: layoutData.horizontalAlignment = SWT.END;
632: coolBar.getControl().setLayoutData(layoutData);
633:
634: label = WidgetFactory.createLabel(detailsComposite, ""); //$NON-NLS-1$
635:
636: label = WidgetFactory.createLabel(detailsComposite, Messages
637: .getString("InputDetailsPage.INPUT_TYPE_TITLE")); //$NON-NLS-1$
638: layoutData = new GridData(GridData.FILL_HORIZONTAL);
639: layoutData.verticalAlignment = SWT.BEGINNING;
640: paramTypeEditor = new InputTypeCombo(detailsComposite,
641: layoutData);
642: label = WidgetFactory.createLabel(detailsComposite, ""); //$NON-NLS-1$
643: }
644:
645: /*
646: * (non-Javadoc)
647: *
648: * @see org.eclipse.ui.forms.IFormPart#refresh()
649: */
650: public void refresh() {
651: paramNameEditor.removeModifyListener(this );
652: defaultStringText.removeModifyListener(this );
653: defaultNumberText.removeModifyListener(this );
654: try {
655: defaultStringText.setText(""); //$NON-NLS-1$
656: defaultNumberText.setText(""); //$NON-NLS-1$
657: String inputType = actionSequenceInput.getType();
658: if (inputType.equals(ActionSequenceDocument.STRING_TYPE)) {
659: Object defVal = actionSequenceInput.getDefaultValue();
660: if (defVal instanceof String) {
661: defaultStringText.setText(defVal.toString());
662: }
663: } else if (inputType
664: .equals(ActionSequenceDocument.LONG_TYPE)
665: || inputType
666: .equals(ActionSequenceDocument.INTEGER_TYPE)
667: || inputType
668: .equals(ActionSequenceDocument.BIGDECIMAL_TYPE)) {
669: Object defVal = actionSequenceInput.getDefaultValue();
670: if (defVal instanceof String) {
671: defaultNumberText.setText(defVal.toString());
672: }
673: }
674: paramNameEditor.setText(actionSequenceInput.getName());
675: propertyMapViewer.setInput(actionSequenceInput);
676: propertyMapListViewer.setInput(actionSequenceInput);
677: resultSetViewer.setInput(actionSequenceInput);
678: stringListViewer.setInput(actionSequenceInput);
679: inputSourceViewer.setInput(actionSequenceInput);
680: paramTypeEditor.refresh();
681:
682: String elementType = actionSequenceInput.getType();
683: stackLayout.topControl = null;
684: stackedComposite.layout();
685: if (elementType.equals(ActionSequenceDocument.STRING_TYPE)
686: && (stackLayout.topControl != defaultStringComposite)) {
687: stackLayout.topControl = defaultStringComposite;
688: stackedComposite.layout();
689: } else if ((elementType
690: .equals(ActionSequenceDocument.LONG_TYPE)
691: || elementType
692: .equals(ActionSequenceDocument.INTEGER_TYPE) || elementType
693: .equals(ActionSequenceDocument.BIGDECIMAL_TYPE))
694: && (stackLayout.topControl != defaultLongComposite)) {
695: stackLayout.topControl = defaultLongComposite;
696: stackedComposite.layout();
697: } else if (elementType
698: .equals(ActionSequenceDocument.STRING_LIST_TYPE)
699: && (stackLayout.topControl != stringListComposite)) {
700: stackLayout.topControl = stringListComposite;
701: stackedComposite.layout();
702: } else if (elementType
703: .equals(ActionSequenceDocument.PROPERTY_MAP_TYPE)
704: && (stackLayout.topControl != propertyMapComposite)) {
705: stackLayout.topControl = propertyMapComposite;
706: stackedComposite.layout();
707: } else if (elementType
708: .equals(ActionSequenceDocument.PROPERTY_MAP_LIST_TYPE)
709: && (stackLayout.topControl != propertyMapListComposite)) {
710: stackLayout.topControl = propertyMapListComposite;
711: stackedComposite.layout();
712: } else if (elementType
713: .equals(ActionSequenceDocument.RESULTSET_TYPE)
714: && (stackLayout.topControl != resultSetComposite)) {
715: stackLayout.topControl = resultSetComposite;
716: stackedComposite.layout();
717: }
718: hasDefaultCheckBox.refresh();
719: } finally {
720: paramNameEditor.addModifyListener(this );
721: defaultStringText.addModifyListener(this );
722: defaultNumberText.addModifyListener(this );
723: }
724: }
725:
726: /*
727: * (non-Javadoc)
728: *
729: * @see org.pentaho.designstudio.editors.actionsequence.pages.ActionSequenceDetailsPage#accepts(org.dom4j.Element)
730: */
731: public boolean accepts(IActionSequenceElement detailElement) {
732: return detailElement instanceof ActionSequenceInput;
733: }
734:
735: public String getName() {
736: return Messages.getString("InputDetailsPage.UI_INPUTS_MENU"); //$NON-NLS-1$
737: }
738:
739: public void dispose() {
740: // TODO Auto-generated method stub
741:
742: }
743:
744: public void selectionChanged(IFormPart part, ISelection selection) {
745: IStructuredSelection ssel = (IStructuredSelection) selection;
746: if ((ssel.size() == 1)
747: && (ssel.getFirstElement() instanceof ActionSequenceInput)) {
748: setActionSequenceElement((ActionSequenceInput) ssel
749: .getFirstElement());
750: } else {
751: setActionSequenceElement(null);
752: }
753: }
754:
755: /* (non-Javadoc)
756: * @see org.eclipse.ui.forms.IFormPart#initialize(org.eclipse.ui.forms.IManagedForm)
757: */
758: public void initialize(IManagedForm form) {
759: this .mform = form;
760: }
761:
762: /* (non-Javadoc)
763: * @see org.eclipse.ui.forms.IFormPart#isDirty()
764: */
765: public boolean isDirty() {
766: return dirty;
767: }
768:
769: /* (non-Javadoc)
770: * @see org.eclipse.ui.forms.IFormPart#commit(boolean)
771: */
772: public void commit(boolean onSave) {
773: }
774:
775: /* (non-Javadoc)
776: * @see org.eclipse.ui.forms.IFormPart#setFormInput(java.lang.Object)
777: */
778: public boolean setFormInput(Object input) {
779: return false;
780: }
781:
782: /* (non-Javadoc)
783: * @see org.eclipse.ui.forms.IFormPart#setFocus()
784: */
785: public void setFocus() {
786: }
787:
788: /* (non-Javadoc)
789: * @see org.eclipse.ui.forms.IFormPart#isStale()
790: */
791: public boolean isStale() {
792: return false;
793: }
794:
795: public void setInput(IActionSequenceElement input) {
796: actionSequenceInput = (ActionSequenceInput) input;
797: if (actionSequenceInput != null) {
798: actionSequenceInput.getDocument().addListener(this );
799: }
800: refresh();
801: }
802:
803: public IActionSequenceElement getActionSequenceElement() {
804: return actionSequenceInput;
805: }
806:
807: public void setActionSequenceElement(IActionSequenceElement element) {
808: actionSequenceInput = (ActionSequenceInput) element;
809: if (actionSequenceInput != null) {
810: actionSequenceInput.getDocument().addListener(this );
811: }
812: refresh();
813: String inputName = actionSequenceInput.getName();
814: ActionSequenceInputSource[] inputSources = actionSequenceInput
815: .getSources();
816: syncInputNameWithSourceName = ((inputSources.length == 1) && inputName
817: .equals(inputSources[0].getName()));
818: }
819:
820: public void actionAdded(ActionDefinition action) {
821: // TODO Auto-generated method stub
822:
823: }
824:
825: public void actionChanged(ActionDefinition action) {
826: // TODO Auto-generated method stub
827:
828: }
829:
830: public void actionRemoved(Object parent, ActionDefinition action) {
831: // TODO Auto-generated method stub
832:
833: }
834:
835: public void actionRenamed(ActionDefinition action) {
836: // TODO Auto-generated method stub
837:
838: }
839:
840: public void headerChanged(
841: ActionSequenceDocument actionSequenceDocument) {
842: // TODO Auto-generated method stub
843:
844: }
845:
846: public void ioAdded(AbstractIOElement io) {
847: // TODO Auto-generated method stub
848:
849: }
850:
851: public void ioChanged(AbstractIOElement io) {
852: if (io.equals(actionSequenceInput)) {
853: hasDefaultCheckBox.refresh();
854: ActionSequenceInputSource[] inputSources = actionSequenceInput
855: .getSources();
856: syncInputNameWithSourceName = ((inputSources.length == 1) && actionSequenceInput
857: .getName().equals(inputSources[0].getName()));
858: }
859: }
860:
861: public void ioRemoved(Object parent, AbstractIOElement io) {
862: // TODO Auto-generated method stub
863:
864: }
865:
866: public void ioRenamed(AbstractIOElement io) {
867: if (io.equals(actionSequenceInput)
868: && syncInputNameWithSourceName) {
869: ActionSequenceInputSource[] inputSources = actionSequenceInput
870: .getSources();
871: if (inputSources.length == 1) {
872: inputSources[0].setName(actionSequenceInput.getName());
873: inputSourceViewer.refresh();
874: }
875: }
876: }
877:
878: public void controlStatementAdded(
879: ActionControlStatement controlStatement) {
880: // TODO Auto-generated method stub
881:
882: }
883:
884: public void controlStatementChanged(
885: ActionControlStatement controlStatement) {
886: // TODO Auto-generated method stub
887:
888: }
889:
890: public void controlStatementRemoved(Object parent,
891: ActionControlStatement controlStatement) {
892: // TODO Auto-generated method stub
893:
894: }
895:
896: public void resourceAdded(Object resource) {
897: // TODO Auto-generated method stub
898:
899: }
900:
901: public void resourceChanged(Object resource) {
902: // TODO Auto-generated method stub
903:
904: }
905:
906: public void resourceRemoved(Object parent, Object resource) {
907: // TODO Auto-generated method stub
908:
909: }
910:
911: public void resourceRenamed(Object resource) {
912: // TODO Auto-generated method stub
913:
914: }
915:
916: }
|