1 package org
.argeo
.slc
.client
.ui
.views
;
3 import java
.util
.ArrayList
;
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
.execution
.ExecutionSpecAttribute
;
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
;
30 * This view, directly linked with the <code> ProcessBuilderView </code>
31 * enables the display and editing the parameters of a given process.
33 * Note that for now we use <code>ExecutionFlowDescriptor.values</code>
34 * attribute to recall (and update ??) the various parameters.
36 public class ProcessParametersView
extends ViewPart
{
37 private static final Log log
= LogFactory
38 .getLog(ProcessParametersView
.class);
40 public static final String ID
= "org.argeo.slc.client.ui.processParametersView";
42 // This map stores actual values set to default if existing at the begining
43 // and then the ones computed by the end user
44 private Map
<String
, Object
> values
;
45 // This map stores the spec of the attributes used to offer the end user
47 private Map
<String
, ExecutionSpecAttribute
> specAttributes
;
49 // We must keep a reference to the current EditingSupport so that we can
50 // update the index of the process being updated
51 ProcessParametersEditingSupport ppEditingSupport
;
54 private TableViewer viewer
;
56 public void createPartControl(Composite parent
) {
57 viewer
= new TableViewer(parent
, SWT
.MULTI
| SWT
.H_SCROLL
58 | SWT
.V_SCROLL
| SWT
.FULL_SELECTION
);
59 createColumns(viewer
);
62 // for the moment being, we support only one process builder at a time
63 // we set the corresponding view in the editor here.
64 ProcessBuilderView pbView
= (ProcessBuilderView
) ClientUiPlugin
65 .getDefault().getWorkbench().getActiveWorkbenchWindow()
66 .getActivePage().findView(ProcessBuilderView
.ID
);
67 ppEditingSupport
.setCurrentProcessBuilderView(pbView
);
69 viewer
.setLabelProvider(new ViewLabelProvider());
70 viewer
.setContentProvider(new ViewContentProvider());
71 viewer
.setInput(getViewSite());
75 // This will create the columns for the table
76 private void createColumns(TableViewer viewer
) {
78 String
[] titles
= { "Attribute name", "value" };
79 int[] bounds
= { 200, 200 };
81 for (int i
= 0; i
< titles
.length
; i
++) {
82 TableViewerColumn column
= new TableViewerColumn(viewer
, SWT
.NONE
);
83 column
.getColumn().setText(titles
[i
]);
84 column
.getColumn().setWidth(bounds
[i
]);
85 column
.getColumn().setResizable(true);
86 column
.getColumn().setMoveable(true);
88 // we create the used EditingSupport and enable editing support
90 ppEditingSupport
= new ProcessParametersEditingSupport(viewer
,
92 column
.setEditingSupport(ppEditingSupport
);
95 Table table
= viewer
.getTable();
96 table
.setHeaderVisible(true);
97 table
.setLinesVisible(true);
101 public void setFocus() {
102 viewer
.getControl().setFocus();
105 // set class attributes, refresh the lists of process paramaters to edit.
106 public void setRealizedFlow(int index
, RealizedFlow rf
) {
107 // force the cleaning of the view
109 viewer
.setInput(null);
112 // we store the index of the edited Process in the editor so that it can
113 // save computed values.
114 ppEditingSupport
.setCurrentProcessIndex(index
);
117 // We should handle ExecutionSpec here. need to be improved.
118 // ExecutionSpec es = rf.getExecutionSpec();
119 // if (es != null && es.getAttributes() != null)
120 // parameters = es.getAttributes();
121 // if (parameters != null)
122 // viewer.setInput(parameters);
124 values
= rf
.getFlowDescriptor().getValues();
125 specAttributes
= rf
.getFlowDescriptor().getExecutionSpec()
129 viewer
.setInput(values
);
131 // No parameters to edit, we reset the view.
132 viewer
.setInput(null);
136 // Inner Classes we should use ExecutionSpecAttribute instead of values
138 protected class ViewContentProvider
implements IStructuredContentProvider
{
139 public void inputChanged(Viewer arg0
, Object arg1
, Object arg2
) {
142 public void dispose() {
145 @SuppressWarnings("unchecked")
146 // we cast the Map<String, Object> to List<Object>
147 public Object
[] getElements(Object obj
) {
149 if (obj
instanceof Map
&& ((Map
) obj
).size() != 0) {
150 List
<ObjectWithName
> list
= new ArrayList
<ObjectWithName
>();
151 Map
<String
, Object
> map
= (Map
<String
, Object
>) obj
;
152 for (String key
: map
.keySet()) {
153 list
.add(new ObjectWithName(key
, map
.get(key
)));
155 return list
.toArray();
157 return new Object
[0];
162 protected class ViewLabelProvider
extends LabelProvider
implements
163 ITableLabelProvider
{
165 public String
getColumnText(Object obj
, int index
) {
166 // NOTE : the passed object is a line of the table !!!
168 if (obj
instanceof ObjectWithName
) {
169 ObjectWithName own
= (ObjectWithName
) obj
;
174 if (own
.obj
instanceof PrimitiveAccessor
) {
175 PrimitiveAccessor pa
= (PrimitiveAccessor
) own
.obj
;
176 if ("string".equals(pa
.getType()))
177 return (String
) pa
.getValue();
178 else if ("integer".equals(pa
.getType()))
179 return ((Integer
) pa
.getValue()).toString();
181 return "Type " + pa
.getType()
182 + " not yet supported";
184 return own
.obj
.toString();
192 public Image
getColumnImage(Object obj
, int index
) {
198 // We add an inner class to enrich the ExecutionSpecAttribute with a name
199 // so that we can display it.
200 public class ObjectWithName
{
204 public ObjectWithName(String name
, Object obj
) {