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;
014:
015: import java.util.ArrayList;
016: import java.util.List;
017:
018: import org.eclipse.jface.dialogs.Dialog;
019: import org.eclipse.jface.dialogs.IDialogConstants;
020: import org.eclipse.jface.viewers.ILabelProviderListener;
021: import org.eclipse.jface.viewers.IStructuredContentProvider;
022: import org.eclipse.jface.viewers.ITableLabelProvider;
023: import org.eclipse.jface.viewers.TableViewer;
024: import org.eclipse.jface.viewers.Viewer;
025: import org.eclipse.swt.SWT;
026: import org.eclipse.swt.graphics.Image;
027: import org.eclipse.swt.layout.GridData;
028: import org.eclipse.swt.widgets.Composite;
029: import org.eclipse.swt.widgets.Control;
030: import org.eclipse.swt.widgets.Shell;
031: import org.eclipse.swt.widgets.TableColumn;
032: import org.pentaho.actionsequence.dom.ActionInput;
033: import org.pentaho.actionsequence.dom.ActionLoop;
034: import org.pentaho.actionsequence.dom.ActionResource;
035: import org.pentaho.actionsequence.dom.IActionSequenceElement;
036: import org.pentaho.designstudio.controls.WidgetFactory;
037: import org.pentaho.designstudio.editors.actionsequence.pages.ActionSequenceLabelProvider;
038: import org.pentaho.designstudio.messages.Messages;
039:
040: public class BrokenParamDialog extends Dialog implements
041: IStructuredContentProvider {
042:
043: TableViewer tableViewer;
044: IActionSequenceElement[] brokenParams;
045: public static final int ACTION_COLUMN_IDX = 0;
046: public static final int PARAM_COLUMN_IDX = 1;
047:
048: public static final String ACTION_COLUMN_PROP = "Action Name"; //$NON-NLS-1$
049: public static final String PARAM_COLUMN_PROP = "Input Name"; //$NON-NLS-1$
050:
051: public class LabelProvider implements ITableLabelProvider {
052:
053: List listeners = new ArrayList();
054:
055: /**
056: * Creates a label provider
057: */
058: public LabelProvider() {
059: super ();
060: }
061:
062: /* (non-Javadoc)
063: * @see org.eclipse.jface.viewers.ITableLabelProvider#getColumnText(java.lang.Object, int)
064: */
065: public String getColumnText(Object element, int columnIndex) {
066: String columnText = ""; //$NON-NLS-1$
067: if (element instanceof ActionInput) {
068: ActionInput actionInput = (ActionInput) element;
069: if (columnIndex == ACTION_COLUMN_IDX) {
070: columnText = ActionSequenceLabelProvider
071: .getText(actionInput.getActionDefinition());
072: } else {
073: columnText = actionInput.getName();
074: }
075: } else if (element instanceof ActionLoop) {
076: ActionLoop actionLoop = (ActionLoop) element;
077: if (columnIndex == ACTION_COLUMN_IDX) {
078: columnText = ActionSequenceLabelProvider
079: .getText(actionLoop);
080: } else {
081: columnText = actionLoop.getLoopOn();
082: }
083: } else if (element instanceof ActionResource) {
084: ActionResource actionResource = (ActionResource) element;
085: if (columnIndex == ACTION_COLUMN_IDX) {
086: columnText = ActionSequenceLabelProvider
087: .getText(actionResource
088: .getActionDefinition());
089: } else {
090: columnText = actionResource.getName();
091: }
092: }
093: return columnText;
094: }
095:
096: /* (non-Javadoc)
097: * @see org.eclipse.jface.viewers.IBaseLabelProvider#addListener(org.eclipse.jface.viewers.ILabelProviderListener)
098: */
099: public void addListener(ILabelProviderListener listener) {
100: listeners.add(listener);
101: }
102:
103: /* (non-Javadoc)
104: * @see org.eclipse.jface.viewers.IBaseLabelProvider#dispose()
105: */
106: public void dispose() {
107: }
108:
109: /* (non-Javadoc)
110: * @see org.eclipse.jface.viewers.IBaseLabelProvider#isLabelProperty(java.lang.Object, java.lang.String)
111: */
112: public boolean isLabelProperty(Object element, String property) {
113: return true;
114: }
115:
116: /* (non-Javadoc)
117: * @see org.eclipse.jface.viewers.IBaseLabelProvider#removeListener(org.eclipse.jface.viewers.ILabelProviderListener)
118: */
119: public void removeListener(ILabelProviderListener listener) {
120: listeners.add(listener);
121: }
122:
123: /* (non-Javadoc)
124: * @see org.eclipse.jface.viewers.ITableLabelProvider#getColumnImage(java.lang.Object, int)
125: */
126: public Image getColumnImage(Object element, int columnIndex) {
127: return null;
128: }
129:
130: }
131:
132: public BrokenParamDialog(Shell parentShell,
133: IActionSequenceElement[] brokenParams) {
134: super (parentShell);
135: this .brokenParams = brokenParams;
136: }
137:
138: protected void configureShell(Shell shell) {
139: super .configureShell(shell);
140: shell
141: .setText(Messages
142: .getString("RenameActionSequenceInputDialog.RENAME_INPUT")); //$NON-NLS-1$
143: }
144:
145: protected void createButtonsForButtonBar(Composite parent) {
146: createButton(parent, IDialogConstants.OK_ID,
147: IDialogConstants.OK_LABEL, true);
148: createButton(parent, IDialogConstants.CANCEL_ID,
149: IDialogConstants.CANCEL_LABEL, true);
150: }
151:
152: protected Control createDialogArea(Composite parent) {
153: Composite composite = (Composite) super
154: .createDialogArea(parent);
155: WidgetFactory.createLabel(composite, ""); //$NON-NLS-1$
156: GridData gridData = new GridData(GridData.FILL_HORIZONTAL);
157: WidgetFactory
158: .createLabel(
159: composite,
160: Messages
161: .getString("BrokenParamDialog.BROKEN_PARAMS_MSG"), SWT.NONE).setLayoutData(gridData); //$NON-NLS-1$
162: tableViewer = new TableViewer(composite, SWT.NONE);
163: TableColumn tableColumn = new TableColumn(tableViewer
164: .getTable(), SWT.LEFT);
165: tableColumn.setText(Messages
166: .getString("BrokenParamDialog.ACTION_NAME")); //$NON-NLS-1$
167: tableColumn.setWidth(150);
168: tableColumn = new TableColumn(tableViewer.getTable(), SWT.LEFT);
169: tableColumn.setText(Messages
170: .getString("BrokenParamDialog.INPUT_NAME")); //$NON-NLS-1$
171: tableColumn.setWidth(150);
172: tableViewer.getTable().setHeaderVisible(true);
173: tableViewer.getTable().setLinesVisible(true);
174: tableViewer.setContentProvider(this );
175: tableViewer.setLabelProvider(new LabelProvider());
176: tableViewer.setColumnProperties(new String[] {
177: ACTION_COLUMN_PROP, PARAM_COLUMN_PROP });
178: tableViewer.setInput(brokenParams);
179: gridData = new GridData(GridData.FILL_HORIZONTAL);
180: gridData.heightHint = 100;
181: tableViewer.getControl().setLayoutData(gridData);
182: return composite;
183: }
184:
185: public Object[] getElements(Object inputElement) {
186: return brokenParams;
187: }
188:
189: public void dispose() {
190: }
191:
192: public void inputChanged(Viewer viewer, Object oldInput,
193: Object newInput) {
194: }
195:
196: }
|