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