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
.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
;
27 * This view, directly linked with the <code> ProcessBuilderView </code>
28 * enables the display and editing the parameters of a given process.
30 * Note that for now we use <code>ExecutionFlowDescriptor.values</code>
31 * attribute to recall (and update ??) the various parameters.
33 public class ProcessParametersView
extends ViewPart
{
34 // private static final Log log = LogFactory
35 // .getLog(ProcessParametersView.class);
37 public static final String ID
= "org.argeo.slc.client.ui.processParametersView";
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
44 //private Map<String, ExecutionSpecAttribute> specAttributes;
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
;
51 private TableViewer viewer
;
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
);
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
);
66 viewer
.setLabelProvider(new ViewLabelProvider());
67 viewer
.setContentProvider(new ViewContentProvider());
68 viewer
.setInput(getViewSite());
72 // This will create the columns for the table
73 private void createColumns(TableViewer viewer
) {
75 String
[] titles
= { "Attribute name", "value" };
76 int[] bounds
= { 200, 200 };
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);
85 // we create the used EditingSupport and enable editing support
87 ppEditingSupport
= new ProcessParametersEditingSupport(viewer
,
89 column
.setEditingSupport(ppEditingSupport
);
92 Table table
= viewer
.getTable();
93 table
.setHeaderVisible(true);
94 table
.setLinesVisible(true);
98 public void setFocus() {
99 viewer
.getControl().setFocus();
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
106 viewer
.setInput(null);
109 // we store the index of the edited Process in the editor so that it can
110 // save computed values.
111 ppEditingSupport
.setCurrentProcessIndex(index
);
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);
121 values
= rf
.getFlowDescriptor().getValues();
122 // specAttributes = rf.getFlowDescriptor().getExecutionSpec()
126 viewer
.setInput(values
);
128 // No parameters to edit, we reset the view.
129 viewer
.setInput(null);
133 // Inner Classes we should use ExecutionSpecAttribute instead of values
135 protected class ViewContentProvider
implements IStructuredContentProvider
{
136 public void inputChanged(Viewer arg0
, Object arg1
, Object arg2
) {
139 public void dispose() {
142 @SuppressWarnings({ "unchecked", "rawtypes" })
143 // we cast the Map<String, Object> to List<Object>
144 public Object
[] getElements(Object obj
) {
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
)));
152 return list
.toArray();
154 return new Object
[0];
159 protected class ViewLabelProvider
extends LabelProvider
implements
160 ITableLabelProvider
{
162 public String
getColumnText(Object obj
, int index
) {
163 // NOTE : the passed object is a line of the table !!!
165 if (obj
instanceof ObjectWithName
) {
166 ObjectWithName own
= (ObjectWithName
) obj
;
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();
178 return "Type " + pa
.getType()
179 + " not yet supported";
181 return own
.obj
.toString();
189 public Image
getColumnImage(Object obj
, int index
) {
195 // We add an inner class to enrich the ExecutionSpecAttribute with a name
196 // so that we can display it.
197 public class ObjectWithName
{
201 public ObjectWithName(String name
, Object obj
) {