01: /*
02: * Copyright 2006 Pentaho Corporation. All rights reserved.
03: * This software was developed by Pentaho Corporation and is provided under the terms
04: * of the Mozilla Public License, Version 1.1, or any later version. You may not use
05: * this file except in compliance with the license. If you need a copy of the license,
06: * please go to http://www.mozilla.org/MPL/MPL-1.1.txt. The Original Code is the Pentaho
07: * BI Platform. The Initial Developer is Pentaho Corporation.
08: *
09: * Software distributed under the Mozilla Public License is distributed on an "AS IS"
10: * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. Please refer to
11: * the license for the specific language governing your rights and limitations.
12: */
13: package org.pentaho.designstudio.controls;
14:
15: import java.util.ArrayList;
16: import java.util.Arrays;
17:
18: import org.eclipse.jface.viewers.IStructuredContentProvider;
19: import org.eclipse.jface.viewers.Viewer;
20: import org.pentaho.actionsequence.dom.AbstractActionIOElement;
21: import org.pentaho.actionsequence.dom.actions.ActionDefinition;
22: import org.pentaho.designstudio.editors.actionsequence.pages.actions.IActionIOFilter;
23:
24: /**
25: * Content provider used by ActionIOViewer.
26: *
27: * @author Angelo Rodriguez
28: */
29: public class ActionIOContentProvider implements
30: IStructuredContentProvider {
31:
32: ActionDefinition actionDefinition;
33: boolean provideInputs = true;
34: IActionIOFilter actionIOFilter;
35:
36: /**
37: * Placeholder used to indicate that a new row may be added to the viewer.
38: */
39:
40: /**
41: * Creates a content provider
42: * @param ioInfo a description of the inputs or outputs being displayed by the viewer.
43: * @param provideInputs indicates whether this provider should be providing
44: * the inputs or outputs of an action definition.
45: */
46: public ActionIOContentProvider(boolean provideInputs) {
47: super ();
48: this .provideInputs = provideInputs;
49: }
50:
51: /* (non-Javadoc)
52: * @see org.eclipse.jface.viewers.IStructuredContentProvider#getElements(java.lang.Object)
53: */
54: public Object[] getElements(Object ioElement) {
55: ArrayList elements = new ArrayList();
56: if (actionDefinition != null) {
57: AbstractActionIOElement[] io = null;
58: if (provideInputs) {
59: io = actionDefinition.getAllInputParams();
60: } else {
61: io = actionDefinition.getAllOutputParams();
62: }
63: if (actionIOFilter == null) {
64: elements.addAll(Arrays.asList(io));
65: } else {
66: for (int i = 0; i < io.length; i++) {
67: if (actionIOFilter.accept(io[i])) {
68: elements.add(io[i]);
69: }
70: }
71: }
72: }
73: elements.add(ActionUtil.NEW_IO_PLACEHOLDER);
74: return elements.toArray();
75: }
76:
77: /* (non-Javadoc)
78: * @see org.eclipse.jface.viewers.IContentProvider#dispose()
79: */
80: public void dispose() {
81: }
82:
83: /* (non-Javadoc)
84: * @see org.eclipse.jface.viewers.IContentProvider#inputChanged(org.eclipse.jface.viewers.Viewer, java.lang.Object, java.lang.Object)
85: */
86: public void inputChanged(Viewer viewer, Object oldInput,
87: Object newInput) {
88: actionDefinition = (ActionDefinition) newInput;
89: }
90:
91: public void setFilter(IActionIOFilter filter) {
92: actionIOFilter = filter;
93: }
94: }
|