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
.core
.execution
.RefValue
;
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.
34 * Note that for a given RealizedFlow :
36 * + paramaters value are set using
37 * <code>RealizedFlow.ExecutionFlowDescriptor.values</code>, that might
40 * + possible "values" for a given parameters are stored in
41 * <code>RealizedFlow.ExecutionSpec.</code>
44 public class ProcessParametersView
extends ViewPart
{
45 private static final Log log
= LogFactory
46 .getLog(ProcessParametersView
.class);
48 public static final String ID
= "org.argeo.slc.client.ui.processParametersView";
50 // This map stores actual values :
51 // * default values (if defined) at instantiation time
52 // * values filled-in or modified by the end-user
53 private Map
<String
, Object
> values
;
55 // This map stores the spec of the attributes used to offer the end user
57 // private Map<String, ExecutionSpecAttribute> specAttributes;
59 // We must keep a reference to the current EditingSupport so that we can
60 // update the index of the process being updated
61 ProcessParametersEditingSupport ppEditingSupport
;
64 private TableViewer viewer
;
66 public void createPartControl(Composite parent
) {
67 viewer
= new TableViewer(parent
, SWT
.MULTI
| SWT
.H_SCROLL
68 | SWT
.V_SCROLL
| SWT
.FULL_SELECTION
);
69 createColumns(viewer
);
72 // for the moment being, we support only one process builder at a time
73 // we set the corresponding view in the editor here.
74 ProcessBuilderView pbView
= (ProcessBuilderView
) ClientUiPlugin
75 .getDefault().getWorkbench().getActiveWorkbenchWindow()
76 .getActivePage().findView(ProcessBuilderView
.ID
);
77 ppEditingSupport
.setCurrentProcessBuilderView(pbView
);
79 viewer
.setLabelProvider(new ViewLabelProvider());
80 viewer
.setContentProvider(new ViewContentProvider());
81 viewer
.setInput(getViewSite());
85 // This will create the columns for the table
86 private void createColumns(TableViewer viewer
) {
88 String
[] titles
= { "Attribute name", "value" };
89 int[] bounds
= { 200, 200 };
91 for (int i
= 0; i
< titles
.length
; i
++) {
92 TableViewerColumn column
= new TableViewerColumn(viewer
, SWT
.NONE
);
93 column
.getColumn().setText(titles
[i
]);
94 column
.getColumn().setWidth(bounds
[i
]);
95 column
.getColumn().setResizable(true);
96 column
.getColumn().setMoveable(true);
98 // we create the used EditingSupport and enable editing support
100 ppEditingSupport
= new ProcessParametersEditingSupport(viewer
,
102 column
.setEditingSupport(ppEditingSupport
);
105 Table table
= viewer
.getTable();
106 table
.setHeaderVisible(true);
107 table
.setLinesVisible(true);
111 public void setFocus() {
112 viewer
.getControl().setFocus();
115 // set class attributes, refresh the lists of process paramaters to edit.
116 public void setRealizedFlow(int index
, RealizedFlow rf
) {
117 // force the cleaning of the view
119 viewer
.setInput(null);
122 // we store the index of the edited Process in the editor so that it can
123 // save entries modified by the end user.
124 ppEditingSupport
.setCurrentProcessIndex(index
);
126 // We also store corresponding ExecutionSpec to be able to retrieve
127 // possible values for dropdown lists
128 ppEditingSupport
.setCurrentExecutionSpec(rf
.getExecutionSpec());
129 // ExecutionSpec es = rf.getExecutionSpec();
130 // if (es != null && es.getAttributes() != null)
131 // parameters = es.getAttributes();
132 // if (parameters != null)
133 // viewer.setInput(parameters);
135 values
= rf
.getFlowDescriptor().getValues();
136 // specAttributes = rf.getFlowDescriptor().getExecutionSpec()
140 viewer
.setInput(values
);
142 // No parameters to edit, we reset the view.
143 viewer
.setInput(null);
147 // Inner Classes we should use ExecutionSpecAttribute instead of values
149 protected class ViewContentProvider
implements IStructuredContentProvider
{
150 public void inputChanged(Viewer arg0
, Object arg1
, Object arg2
) {
153 public void dispose() {
156 @SuppressWarnings({ "unchecked", "rawtypes" })
157 // we cast the Map<String, Object> to List<Object>
158 public Object
[] getElements(Object obj
) {
160 if (obj
instanceof Map
&& ((Map
) obj
).size() != 0) {
161 List
<ObjectWithName
> list
= new ArrayList
<ObjectWithName
>();
162 Map
<String
, Object
> map
= (Map
<String
, Object
>) obj
;
163 for (String key
: map
.keySet()) {
164 list
.add(new ObjectWithName(key
, map
.get(key
)));
166 return list
.toArray();
168 return new Object
[0];
173 protected class ViewLabelProvider
extends LabelProvider
implements
174 ITableLabelProvider
{
176 public String
getColumnText(Object obj
, int index
) {
177 // NOTE : the passed object is a line of the table !!!
179 if (obj
instanceof ObjectWithName
) {
180 ObjectWithName own
= (ObjectWithName
) obj
;
185 if (own
.obj
instanceof PrimitiveAccessor
) {
186 PrimitiveAccessor pa
= (PrimitiveAccessor
) own
.obj
;
187 return pa
.getValue().toString();
188 } else if (own
.obj
instanceof RefValue
) {
189 RefValue refValue
= (RefValue
) own
.obj
;
190 return refValue
.getRef();
192 if (log
.isTraceEnabled()) {
193 log
.warn("Not a Primitive accessor neither a ref Value : "
196 + own
.obj
.getClass().toString());
198 return own
.obj
.toString();
208 public Image
getColumnImage(Object obj
, int index
) {
214 // We add an inner class to enrich the ExecutionSpecAttribute with a name
215 // so that we can display it.
216 public class ObjectWithName
{
220 public ObjectWithName(String name
, Object obj
) {