]> git.argeo.org Git - gpl/argeo-slc.git/blob - eclipse/plugins/org.argeo.slc.client.ui/src/main/java/org/argeo/slc/client/ui/views/ProcessParametersView.java
JCR UI can run processes
[gpl/argeo-slc.git] / eclipse / plugins / org.argeo.slc.client.ui / src / main / java / org / argeo / slc / client / ui / views / ProcessParametersView.java
1 package org.argeo.slc.client.ui.views;
2
3 import java.util.ArrayList;
4 import java.util.List;
5 import java.util.Map;
6
7 import org.apache.commons.logging.Log;
8 import org.apache.commons.logging.LogFactory;
9 import org.argeo.slc.client.ui.ClientUiPlugin;
10 import org.argeo.slc.client.ui.providers.ProcessParametersEditingSupport;
11 import org.argeo.slc.core.execution.PrimitiveAccessor;
12 import org.argeo.slc.core.execution.RefValue;
13 import org.argeo.slc.process.RealizedFlow;
14 import org.eclipse.jface.viewers.IStructuredContentProvider;
15 import org.eclipse.jface.viewers.ITableLabelProvider;
16 import org.eclipse.jface.viewers.LabelProvider;
17 import org.eclipse.jface.viewers.TableViewer;
18 import org.eclipse.jface.viewers.TableViewerColumn;
19 import org.eclipse.jface.viewers.Viewer;
20 import org.eclipse.swt.SWT;
21 import org.eclipse.swt.graphics.Image;
22 import org.eclipse.swt.widgets.Composite;
23 import org.eclipse.swt.widgets.Table;
24 import org.eclipse.ui.part.ViewPart;
25
26 /**
27 * This view, directly linked with the <code> ProcessBuilderView </code> enables
28 * the display and editing the parameters of a given process.
29 *
30 *
31 * Note that for a given RealizedFlow :
32 *
33 * + parameters value are set using
34 * <code>RealizedFlow.ExecutionFlowDescriptor.values</code>, that might have
35 * default values
36 *
37 * + possible "values" for a given parameters are stored in
38 * <code>RealizedFlow.ExecutionSpec.</code>
39 *
40 */
41 public class ProcessParametersView extends ViewPart {
42 private static final Log log = LogFactory
43 .getLog(ProcessParametersView.class);
44
45 public static final String ID = "org.argeo.slc.client.ui.processParametersView";
46
47 // This map stores actual values :
48 // * default values (if defined) at instantiation time
49 // * values filled-in or modified by the end-user
50 private Map<String, Object> values;
51
52 // This map stores the spec of the attributes used to offer the end user
53 // some choices.
54 // private Map<String, ExecutionSpecAttribute> specAttributes;
55
56 // We must keep a reference to the current EditingSupport so that we can
57 // update the index of the process being updated
58 ProcessParametersEditingSupport ppEditingSupport;
59
60 // view attributes
61 private TableViewer viewer;
62
63 public void createPartControl(Composite parent) {
64 viewer = new TableViewer(parent, SWT.MULTI | SWT.H_SCROLL
65 | SWT.V_SCROLL | SWT.FULL_SELECTION);
66 createColumns(viewer);
67
68 // WARNING
69 // for the moment being, we support only one process builder at a time
70 // we set the corresponding view in the editor here.
71 ProcessBuilderView pbView = (ProcessBuilderView) ClientUiPlugin
72 .getDefault().getWorkbench().getActiveWorkbenchWindow()
73 .getActivePage().findView(ProcessBuilderView.ID);
74 ppEditingSupport.setCurrentProcessBuilderView(pbView);
75
76 viewer.setLabelProvider(new ViewLabelProvider());
77 viewer.setContentProvider(new ViewContentProvider());
78 viewer.setInput(getViewSite());
79
80 }
81
82 // This will create the columns for the table
83 private void createColumns(TableViewer viewer) {
84
85 String[] titles = { "Attribute name", "value" };
86 int[] bounds = { 200, 200 };
87
88 for (int i = 0; i < titles.length; i++) {
89 TableViewerColumn column = new TableViewerColumn(viewer, SWT.NONE);
90 column.getColumn().setText(titles[i]);
91 column.getColumn().setWidth(bounds[i]);
92 column.getColumn().setResizable(true);
93 column.getColumn().setMoveable(true);
94 if (i == 1) {
95 // we create the used EditingSupport and enable editing support
96 // for value Column
97 ppEditingSupport = new ProcessParametersEditingSupport(viewer,
98 i);
99 column.setEditingSupport(ppEditingSupport);
100 }
101 }
102 Table table = viewer.getTable();
103 table.setHeaderVisible(true);
104 table.setLinesVisible(true);
105
106 }
107
108 public void setFocus() {
109 viewer.getControl().setFocus();
110 }
111
112 // set class attributes, refresh the lists of process paramaters to edit.
113 public void setRealizedFlow(int index, RealizedFlow rf) {
114 // force the cleaning of the view
115 if (index == -1) {
116 viewer.setInput(null);
117 return;
118 }
119 // we store the index of the edited Process in the editor so that it can
120 // save entries modified by the end user.
121 ppEditingSupport.setCurrentProcessIndex(index);
122
123 // We also store corresponding ExecutionSpec to be able to retrieve
124 // possible values for dropdown lists
125 ppEditingSupport.setCurrentExecutionSpec(rf.getExecutionSpec());
126 // ExecutionSpec es = rf.getExecutionSpec();
127 // if (es != null && es.getAttributes() != null)
128 // parameters = es.getAttributes();
129 // if (parameters != null)
130 // viewer.setInput(parameters);
131
132 values = rf.getFlowDescriptor().getValues();
133 // specAttributes = rf.getFlowDescriptor().getExecutionSpec()
134 // .getAttributes();
135
136 if (values != null)
137 viewer.setInput(values);
138 else
139 // No parameters to edit, we reset the view.
140 viewer.setInput(null);
141
142 }
143
144 // Inner Classes we should use ExecutionSpecAttribute instead of values
145 // see below
146 protected class ViewContentProvider implements IStructuredContentProvider {
147 public void inputChanged(Viewer arg0, Object arg1, Object arg2) {
148 }
149
150 public void dispose() {
151 }
152
153 @SuppressWarnings({ "unchecked", "rawtypes" })
154 // we cast the Map<String, Object> to List<Object>
155 public Object[] getElements(Object obj) {
156
157 if (obj instanceof Map && ((Map) obj).size() != 0) {
158 List<ObjectWithName> list = new ArrayList<ObjectWithName>();
159 Map<String, Object> map = (Map<String, Object>) obj;
160 for (String key : map.keySet()) {
161 list.add(new ObjectWithName(key, map.get(key)));
162 }
163 return list.toArray();
164 } else {
165 return new Object[0];
166 }
167 }
168 }
169
170 protected class ViewLabelProvider extends LabelProvider implements
171 ITableLabelProvider {
172
173 public String getColumnText(Object obj, int index) {
174 // NOTE : the passed object is a line of the table !!!
175
176 if (obj instanceof ObjectWithName) {
177 ObjectWithName own = (ObjectWithName) obj;
178 switch (index) {
179 case 0:
180 return own.name;
181 case 1:
182 if (own.obj instanceof PrimitiveAccessor) {
183 PrimitiveAccessor pa = (PrimitiveAccessor) own.obj;
184 return pa.getValue().toString();
185 } else if (own.obj instanceof RefValue) {
186 RefValue refValue = (RefValue) own.obj;
187 return refValue.getRef();
188 } else {
189 if (log.isTraceEnabled()) {
190 log.warn("Not a Primitive accessor neither a ref Value : "
191 + own.obj.toString()
192 + " and class : "
193 + own.obj.getClass().toString());
194 }
195 return own.obj.toString();
196 }
197 default:
198 return getText(obj);
199 }
200 } else {
201 return getText(obj);
202 }
203 }
204
205 public Image getColumnImage(Object obj, int index) {
206 return null;
207 }
208
209 }
210
211 // We add an inner class to enrich the ExecutionSpecAttribute with a name
212 // so that we can display it.
213 public class ObjectWithName {
214 public Object obj;
215 public String name;
216
217 public ObjectWithName(String name, Object obj) {
218 this.name = name;
219 this.obj = obj;
220 }
221 }
222 }