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
;
27 * This view, directly linked with the <code> ProcessBuilderView </code> enables
28 * the display and editing the parameters of a given process.
31 * Note that for a given RealizedFlow :
33 * + parameters value are set using
34 * <code>RealizedFlow.ExecutionFlowDescriptor.values</code>, that might have
37 * + possible "values" for a given parameters are stored in
38 * <code>RealizedFlow.ExecutionSpec.</code>
41 public class ProcessParametersView
extends ViewPart
{
42 private static final Log log
= LogFactory
43 .getLog(ProcessParametersView
.class);
45 public static final String ID
= "org.argeo.slc.client.ui.processParametersView";
47 // This map stores actual values :
48 // * default values (if defined) at instantiation time
49 // * values filled-in or modified by the end-user
50 private Map
<String
, Object
> values
;
52 // This map stores the spec of the attributes used to offer the end user
54 // private Map<String, ExecutionSpecAttribute> specAttributes;
56 // We must keep a reference to the current EditingSupport so that we can
57 // update the index of the process being updated
58 ProcessParametersEditingSupport ppEditingSupport
;
61 private TableViewer viewer
;
63 public void createPartControl(Composite parent
) {
64 viewer
= new TableViewer(parent
, SWT
.MULTI
| SWT
.H_SCROLL
65 | SWT
.V_SCROLL
| SWT
.FULL_SELECTION
);
66 createColumns(viewer
);
69 // for the moment being, we support only one process builder at a time
70 // we set the corresponding view in the editor here.
71 ProcessBuilderView pbView
= (ProcessBuilderView
) ClientUiPlugin
72 .getDefault().getWorkbench().getActiveWorkbenchWindow()
73 .getActivePage().findView(ProcessBuilderView
.ID
);
74 ppEditingSupport
.setCurrentProcessBuilderView(pbView
);
76 viewer
.setLabelProvider(new ViewLabelProvider());
77 viewer
.setContentProvider(new ViewContentProvider());
78 viewer
.setInput(getViewSite());
82 // This will create the columns for the table
83 private void createColumns(TableViewer viewer
) {
85 String
[] titles
= { "Attribute name", "value" };
86 int[] bounds
= { 200, 200 };
88 for (int i
= 0; i
< titles
.length
; i
++) {
89 TableViewerColumn column
= new TableViewerColumn(viewer
, SWT
.NONE
);
90 column
.getColumn().setText(titles
[i
]);
91 column
.getColumn().setWidth(bounds
[i
]);
92 column
.getColumn().setResizable(true);
93 column
.getColumn().setMoveable(true);
95 // we create the used EditingSupport and enable editing support
97 ppEditingSupport
= new ProcessParametersEditingSupport(viewer
,
99 column
.setEditingSupport(ppEditingSupport
);
102 Table table
= viewer
.getTable();
103 table
.setHeaderVisible(true);
104 table
.setLinesVisible(true);
108 public void setFocus() {
109 viewer
.getControl().setFocus();
112 // set class attributes, refresh the lists of process paramaters to edit.
113 public void setRealizedFlow(int index
, RealizedFlow rf
) {
114 // force the cleaning of the view
116 viewer
.setInput(null);
119 // we store the index of the edited Process in the editor so that it can
120 // save entries modified by the end user.
121 ppEditingSupport
.setCurrentProcessIndex(index
);
123 // We also store corresponding ExecutionSpec to be able to retrieve
124 // possible values for dropdown lists
125 ppEditingSupport
.setCurrentExecutionSpec(rf
.getExecutionSpec());
126 // ExecutionSpec es = rf.getExecutionSpec();
127 // if (es != null && es.getAttributes() != null)
128 // parameters = es.getAttributes();
129 // if (parameters != null)
130 // viewer.setInput(parameters);
132 values
= rf
.getFlowDescriptor().getValues();
133 // specAttributes = rf.getFlowDescriptor().getExecutionSpec()
137 viewer
.setInput(values
);
139 // No parameters to edit, we reset the view.
140 viewer
.setInput(null);
144 // Inner Classes we should use ExecutionSpecAttribute instead of values
146 protected class ViewContentProvider
implements IStructuredContentProvider
{
147 public void inputChanged(Viewer arg0
, Object arg1
, Object arg2
) {
150 public void dispose() {
153 @SuppressWarnings({ "unchecked", "rawtypes" })
154 // we cast the Map<String, Object> to List<Object>
155 public Object
[] getElements(Object obj
) {
157 if (obj
instanceof Map
&& ((Map
) obj
).size() != 0) {
158 List
<ObjectWithName
> list
= new ArrayList
<ObjectWithName
>();
159 Map
<String
, Object
> map
= (Map
<String
, Object
>) obj
;
160 for (String key
: map
.keySet()) {
161 list
.add(new ObjectWithName(key
, map
.get(key
)));
163 return list
.toArray();
165 return new Object
[0];
170 protected class ViewLabelProvider
extends LabelProvider
implements
171 ITableLabelProvider
{
173 public String
getColumnText(Object obj
, int index
) {
174 // NOTE : the passed object is a line of the table !!!
176 if (obj
instanceof ObjectWithName
) {
177 ObjectWithName own
= (ObjectWithName
) obj
;
182 if (own
.obj
instanceof PrimitiveAccessor
) {
183 PrimitiveAccessor pa
= (PrimitiveAccessor
) own
.obj
;
184 return pa
.getValue().toString();
185 } else if (own
.obj
instanceof RefValue
) {
186 RefValue refValue
= (RefValue
) own
.obj
;
187 return refValue
.getRef();
189 if (log
.isTraceEnabled()) {
190 log
.warn("Not a Primitive accessor neither a ref Value : "
193 + own
.obj
.getClass().toString());
195 return own
.obj
.toString();
205 public Image
getColumnImage(Object obj
, int index
) {
211 // We add an inner class to enrich the ExecutionSpecAttribute with a name
212 // so that we can display it.
213 public class ObjectWithName
{
217 public ObjectWithName(String name
, Object obj
) {