]> git.argeo.org Git - gpl/argeo-slc.git/blob - eclipse/plugins/org.argeo.slc.client.ui/src/org/argeo/slc/client/ui/views/ProcessParametersView.java
4fabec13581bd3425b54f877039ecb271a4e8307
[gpl/argeo-slc.git] / eclipse / plugins / org.argeo.slc.client.ui / src / 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.argeo.slc.client.ui.ClientUiPlugin;
8 import org.argeo.slc.client.ui.providers.ProcessParametersEditingSupport;
9 import org.argeo.slc.core.execution.PrimitiveAccessor;
10 import org.argeo.slc.execution.ExecutionSpecAttribute;
11 import org.argeo.slc.process.RealizedFlow;
12 import org.eclipse.jface.viewers.IStructuredContentProvider;
13 import org.eclipse.jface.viewers.ITableLabelProvider;
14 import org.eclipse.jface.viewers.LabelProvider;
15 import org.eclipse.jface.viewers.TableViewer;
16 import org.eclipse.jface.viewers.TableViewerColumn;
17 import org.eclipse.jface.viewers.Viewer;
18 import org.eclipse.swt.SWT;
19 import org.eclipse.swt.graphics.Image;
20 import org.eclipse.swt.widgets.Composite;
21 import org.eclipse.swt.widgets.Table;
22 import org.eclipse.ui.part.ViewPart;
23
24 /**
25 *
26 * @author bsinou
27 *
28 * This view, directly linked with the <code> ProcessBuilderView </code>
29 * enables the display and editing the parameters of a given process.
30 *
31 * Note that for now we use <code>ExecutionFlowDescriptor.values</code>
32 * attribute to recall (and update ??) the various parameters.
33 */
34 public class ProcessParametersView extends ViewPart {
35 public static final String ID = "org.argeo.slc.client.ui.processParametersView";
36
37 // class attribute
38 private Map<String, ExecutionSpecAttribute> parameters;
39 private RealizedFlow curRealizedFlow;
40
41 // we should be using executionspecAttribute but for now we uses values.
42 private Map<String, Object> values;
43
44 // We must keep a reference to the current EditingSupport so that we can
45 // update the index of the process being updated
46 ProcessParametersEditingSupport ppEditingSupport;
47
48 // view attributes
49 private TableViewer viewer;
50
51 public void createPartControl(Composite parent) {
52 viewer = new TableViewer(parent, SWT.MULTI | SWT.H_SCROLL
53 | SWT.V_SCROLL | SWT.FULL_SELECTION);
54 createColumns(viewer);
55
56 // WARNING
57 // for the moment being, we support only one process builder at a time
58 // we set the corresponding view in the editor here.
59 ProcessBuilderView pbView = (ProcessBuilderView) ClientUiPlugin
60 .getDefault().getWorkbench().getActiveWorkbenchWindow()
61 .getActivePage().findView(ProcessBuilderView.ID);
62 ppEditingSupport.setCurrentProcessBuilderView(pbView);
63
64 viewer.setLabelProvider(new ViewLabelProvider());
65 viewer.setContentProvider(new ViewContentProvider());
66 viewer.setInput(getViewSite());
67
68
69 }
70
71 // This will create the columns for the table
72 private void createColumns(TableViewer viewer) {
73
74 String[] titles = { "Attribute name", "value" };
75 int[] bounds = { 200, 200 };
76
77 for (int i = 0; i < titles.length; i++) {
78 TableViewerColumn column = new TableViewerColumn(viewer, SWT.NONE);
79 column.getColumn().setText(titles[i]);
80 column.getColumn().setWidth(bounds[i]);
81 column.getColumn().setResizable(true);
82 column.getColumn().setMoveable(true);
83 if (i == 1) {
84 // we create the used EditingSupport and enable editing support
85 // for value Column
86 ppEditingSupport = new ProcessParametersEditingSupport(viewer,
87 i);
88 column.setEditingSupport(ppEditingSupport);
89 }
90 }
91 Table table = viewer.getTable();
92 table.setHeaderVisible(true);
93 table.setLinesVisible(true);
94
95 }
96
97 public void setFocus() {
98 viewer.getControl().setFocus();
99 }
100
101 // save and update a field when it looses the focus
102 // TODO implement this method.
103
104 // set class attributes, refresh the lists of process paramaters to edit.
105 public void setRealizedFlow(int index, RealizedFlow rf) {
106
107 // this.processIndex = index;
108 ppEditingSupport.setCurrentProcessIndex(index);
109 curRealizedFlow = rf;
110
111 // TODO :
112 // We should handle ExecutionSpec here. need to be improved.
113 // ExecutionSpec es = rf.getExecutionSpec();
114 // if (es != null && es.getAttributes() != null)
115 // parameters = es.getAttributes();
116 // if (parameters != null)
117 // viewer.setInput(parameters);
118
119 values = rf.getFlowDescriptor().getValues();
120 if (values != null)
121 viewer.setInput(values);
122 else
123 // No parameters to edit, we reset the view.
124 viewer.setInput(null);
125
126 }
127
128 // Inner Classes we should use ExecutionSpecAttribute instead of values
129 // see below
130 protected class ViewContentProvider implements IStructuredContentProvider {
131 public void inputChanged(Viewer arg0, Object arg1, Object arg2) {
132 }
133
134 public void dispose() {
135 }
136
137 @SuppressWarnings("unchecked")
138 // we cast the Map<String, Object> to List<Object>
139 public Object[] getElements(Object obj) {
140
141 if (obj instanceof Map && ((Map) obj).size() != 0) {
142 List<ObjectWithName> list = new ArrayList<ObjectWithName>();
143 Map<String, Object> map = (Map<String, Object>) obj;
144 for (String key : map.keySet()) {
145 list.add(new ObjectWithName(key, map.get(key)));
146 }
147 return list.toArray();
148 } else {
149 return new Object[0];
150 }
151 }
152 }
153
154 protected class ViewLabelProvider extends LabelProvider implements
155 ITableLabelProvider {
156
157 public String getColumnText(Object obj, int index) {
158 // NOTE : the passed object is a line of the table !!!
159
160 if (obj instanceof ObjectWithName) {
161 ObjectWithName own = (ObjectWithName) obj;
162 switch (index) {
163 case 0:
164 return own.name;
165 case 1:
166 if (own.obj instanceof PrimitiveAccessor) {
167 PrimitiveAccessor pa = (PrimitiveAccessor) own.obj;
168 if ("string".equals(pa.getType()))
169 return (String) pa.getValue();
170 else
171 return "Type " + pa.getType()
172 + " not yet supported";
173 } else
174 return own.obj.toString();
175 default:
176 return getText(obj);
177 }
178 } else
179 return getText(obj);
180 }
181
182 public Image getColumnImage(Object obj, int index) {
183 return null;
184 }
185
186 }
187
188 // We add an inner class to enrich the ExecutionSpecAttribute with a name
189 // so that we can display it.
190 public class ObjectWithName {
191 public Object obj;
192 public String name;
193
194 public ObjectWithName(String name, Object obj) {
195 this.name = name;
196 this.obj = obj;
197 }
198
199 }
200
201 // protected class ViewContentProvider implements IStructuredContentProvider
202 // {
203 // public void inputChanged(Viewer arg0, Object arg1, Object arg2) {
204 // }
205 //
206 // public void dispose() {
207 // }
208 //
209 // // we cast the Map<String, ExecutionSpecAttribute> to List<Object>
210 // public Object[] getElements(Object obj) {
211 // if (obj instanceof Map && ((Map) obj).size() != 0) {
212 // List<ExecutionSpecAttributeWithName> list = new
213 // ArrayList<ExecutionSpecAttributeWithName>();
214 // Map<String, ExecutionSpecAttribute> map = (Map<String,
215 // ExecutionSpecAttribute>) obj;
216 // for (String key : map.keySet()) {
217 // list.add(new ExecutionSpecAttributeWithName(key, map
218 // .get(key)));
219 // }
220 // return list.toArray();
221 // } else {
222 // return new Object[0];
223 // }
224 // }
225 // }
226 //
227 // protected class ViewLabelProvider extends LabelProvider implements
228 // ITableLabelProvider {
229 //
230 // public String getColumnText(Object obj, int index) {
231 // // NOTE : the passed object is a line of the table !!!
232 //
233 // if (obj instanceof ExecutionSpecAttributeWithName) {
234 // ExecutionSpecAttributeWithName esaw = (ExecutionSpecAttributeWithName)
235 // obj;
236 // switch (index) {
237 // case 0:
238 // return esaw.name;
239 // case 1:
240 // return esaw.esa.getValue().toString();
241 // default:
242 // return getText(obj);
243 // }
244 // } else
245 // return getText(obj);
246 // }
247 //
248 // public Image getColumnImage(Object obj, int index) {
249 // return null;
250 // }
251 //
252 // }
253 //
254 // // We add an inner class to enrich the ExecutionSpecAttribute with a name
255 // // so that we can display it.
256 // private class ExecutionSpecAttributeWithName {
257 // public ExecutionSpecAttribute esa;
258 // public String name;
259 //
260 // public ExecutionSpecAttributeWithName(String name,
261 // ExecutionSpecAttribute esa) {
262 // this.name = name;
263 // this.esa = esa;
264 // }
265
266 // }
267 }