1 package org
.argeo
.slc
.client
.ui
.views
;
3 import java
.util
.ArrayList
;
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
;
28 * This view, directly linked with the <code> ProcessBuilderView </code>
29 * enables the display and editing the parameters of a given process.
31 * Note that for now we use <code>ExecutionFlowDescriptor.values</code>
32 * attribute to recall (and update ??) the various parameters.
34 public class ProcessParametersView
extends ViewPart
{
35 public static final String ID
= "org.argeo.slc.client.ui.processParametersView";
38 private Map
<String
, ExecutionSpecAttribute
> parameters
;
39 private RealizedFlow curRealizedFlow
;
41 // we should be using executionspecAttribute but for now we uses values.
42 private Map
<String
, Object
> values
;
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
;
49 private TableViewer viewer
;
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
);
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
);
64 viewer
.setLabelProvider(new ViewLabelProvider());
65 viewer
.setContentProvider(new ViewContentProvider());
66 viewer
.setInput(getViewSite());
71 // This will create the columns for the table
72 private void createColumns(TableViewer viewer
) {
74 String
[] titles
= { "Attribute name", "value" };
75 int[] bounds
= { 200, 200 };
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);
84 // we create the used EditingSupport and enable editing support
86 ppEditingSupport
= new ProcessParametersEditingSupport(viewer
,
88 column
.setEditingSupport(ppEditingSupport
);
91 Table table
= viewer
.getTable();
92 table
.setHeaderVisible(true);
93 table
.setLinesVisible(true);
97 public void setFocus() {
98 viewer
.getControl().setFocus();
101 // save and update a field when it looses the focus
102 // TODO implement this method.
104 // set class attributes, refresh the lists of process paramaters to edit.
105 public void setRealizedFlow(int index
, RealizedFlow rf
) {
107 // this.processIndex = index;
108 ppEditingSupport
.setCurrentProcessIndex(index
);
109 curRealizedFlow
= rf
;
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);
119 values
= rf
.getFlowDescriptor().getValues();
121 viewer
.setInput(values
);
123 // No parameters to edit, we reset the view.
124 viewer
.setInput(null);
128 // Inner Classes we should use ExecutionSpecAttribute instead of values
130 protected class ViewContentProvider
implements IStructuredContentProvider
{
131 public void inputChanged(Viewer arg0
, Object arg1
, Object arg2
) {
134 public void dispose() {
137 @SuppressWarnings("unchecked")
138 // we cast the Map<String, Object> to List<Object>
139 public Object
[] getElements(Object obj
) {
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
)));
147 return list
.toArray();
149 return new Object
[0];
154 protected class ViewLabelProvider
extends LabelProvider
implements
155 ITableLabelProvider
{
157 public String
getColumnText(Object obj
, int index
) {
158 // NOTE : the passed object is a line of the table !!!
160 if (obj
instanceof ObjectWithName
) {
161 ObjectWithName own
= (ObjectWithName
) obj
;
166 if (own
.obj
instanceof PrimitiveAccessor
) {
167 PrimitiveAccessor pa
= (PrimitiveAccessor
) own
.obj
;
168 if ("string".equals(pa
.getType()))
169 return (String
) pa
.getValue();
171 return "Type " + pa
.getType()
172 + " not yet supported";
174 return own
.obj
.toString();
182 public Image
getColumnImage(Object obj
, int index
) {
188 // We add an inner class to enrich the ExecutionSpecAttribute with a name
189 // so that we can display it.
190 public class ObjectWithName
{
194 public ObjectWithName(String name
, Object obj
) {
201 // protected class ViewContentProvider implements IStructuredContentProvider
203 // public void inputChanged(Viewer arg0, Object arg1, Object arg2) {
206 // public void dispose() {
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
220 // return list.toArray();
222 // return new Object[0];
227 // protected class ViewLabelProvider extends LabelProvider implements
228 // ITableLabelProvider {
230 // public String getColumnText(Object obj, int index) {
231 // // NOTE : the passed object is a line of the table !!!
233 // if (obj instanceof ExecutionSpecAttributeWithName) {
234 // ExecutionSpecAttributeWithName esaw = (ExecutionSpecAttributeWithName)
240 // return esaw.esa.getValue().toString();
242 // return getText(obj);
245 // return getText(obj);
248 // public Image getColumnImage(Object obj, int index) {
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;
260 // public ExecutionSpecAttributeWithName(String name,
261 // ExecutionSpecAttribute esa) {