1 package org
.argeo
.slc
.client
.ui
.providers
;
3 import java
.util
.ArrayList
;
4 import java
.util
.HashMap
;
5 import java
.util
.Iterator
;
9 import org
.apache
.commons
.logging
.Log
;
10 import org
.apache
.commons
.logging
.LogFactory
;
11 import org
.argeo
.slc
.client
.ui
.views
.ProcessBuilderView
;
12 import org
.argeo
.slc
.client
.ui
.views
.ProcessParametersView
;
13 import org
.argeo
.slc
.core
.execution
.PrimitiveAccessor
;
14 import org
.argeo
.slc
.core
.execution
.PrimitiveUtils
;
15 import org
.argeo
.slc
.core
.execution
.RefSpecAttribute
;
16 import org
.argeo
.slc
.core
.execution
.RefValue
;
17 import org
.argeo
.slc
.core
.execution
.RefValueChoice
;
18 import org
.argeo
.slc
.execution
.ExecutionSpec
;
19 import org
.argeo
.slc
.execution
.ExecutionSpecAttribute
;
20 import org
.eclipse
.jface
.viewers
.CellEditor
;
21 import org
.eclipse
.jface
.viewers
.ColumnViewer
;
22 import org
.eclipse
.jface
.viewers
.ComboBoxCellEditor
;
23 import org
.eclipse
.jface
.viewers
.EditingSupport
;
24 import org
.eclipse
.jface
.viewers
.TableViewer
;
25 import org
.eclipse
.jface
.viewers
.TextCellEditor
;
30 * Implements the ability to edit and save various type of parameter of a given
31 * process. Parameter values are directly saved as soon as the focus on a given
35 * Note that EditingSupport is tightly coupled with both ProcessParametersView
36 * and ProcessBuilderView; it cannot serve as a generic EditingSupport as is.
37 * Note also that it assumes that processes in the ProcessBuilderView are stored
44 public class ProcessParametersEditingSupport
extends EditingSupport
{
46 private final static Log log
= LogFactory
47 .getLog(ProcessParametersEditingSupport
.class);
49 private CellEditor strEditor
;
50 // private ComboBoxCellEditor comboEditor;
51 // private int column;
53 // So that we can update corresponding process
54 private int curProcessIndex
;
55 private ProcessBuilderView pbView
;
57 // To populate drop down lists
58 private ExecutionSpec executionSpec
;
60 // To persist combo box elements indexes
61 Map
<String
, List
<String
>> comboBoxes
= new HashMap
<String
, List
<String
>>();
63 public ProcessParametersEditingSupport(ColumnViewer viewer
, int column
) {
65 strEditor
= new TextCellEditor(((TableViewer
) viewer
).getTable());
66 // TODO : add cell validators.
70 protected CellEditor
getCellEditor(Object element
) {
72 // TODO : check if all parameter always have a linked attribute.
73 if (element
instanceof ProcessParametersView
.ObjectWithName
) {
74 ProcessParametersView
.ObjectWithName own
= (ProcessParametersView
.ObjectWithName
) element
;
75 ExecutionSpecAttribute esa
= executionSpec
.getAttributes().get(
78 // Paramater is a primitive with no list of choices linked by
80 if (own
.obj
instanceof PrimitiveAccessor
81 && !(esa
instanceof RefSpecAttribute
))
83 else if (esa
instanceof RefSpecAttribute
) {
84 RefSpecAttribute rsa
= (RefSpecAttribute
) esa
;
86 Iterator
<RefValueChoice
> choices
= rsa
.getChoices()
88 List
<String
> items
= new ArrayList
<String
>();
89 while (choices
.hasNext()) {
90 items
.add(choices
.next().getName());
93 // persists order of the elements in the current combo box
94 comboBoxes
.put(own
.name
, items
);
96 String
[] itemsStr
= new String
[items
.size()];
97 ComboBoxCellEditor comboEditor
= new ComboBoxCellEditor(
98 ((TableViewer
) getViewer()).getTable(),
99 items
.toArray(itemsStr
));
104 if (log
.isTraceEnabled()) {
105 log
.warn(" No cell Editor fits for element : " + element
.toString()
106 + " of class : " + element
.getClass().getName());
112 protected boolean canEdit(Object element
) {
113 if (element
instanceof ProcessParametersView
.ObjectWithName
) {
114 ProcessParametersView
.ObjectWithName own
= (ProcessParametersView
.ObjectWithName
) element
;
115 ExecutionSpecAttribute esa
= executionSpec
.getAttributes().get(
117 if (esa
!= null && !esa
.getIsFrozen())
124 protected Object
getValue(Object element
) {
125 ProcessParametersView
.ObjectWithName own
= (ProcessParametersView
.ObjectWithName
) element
;
127 if (own
.obj
instanceof PrimitiveAccessor
) {
128 PrimitiveAccessor pv
= (PrimitiveAccessor
) own
.obj
;
129 return pv
.getValue().toString();
130 } else if (own
.obj
instanceof RefValue
) {
131 RefValue rv
= (RefValue
) own
.obj
;
132 List
<String
> values
= comboBoxes
.get(own
.name
);
133 log
.debug("Get Value : " + rv
.getRef() + " & index : "
134 + values
.indexOf(rv
.getRef()));
135 return values
.indexOf(rv
.getRef());
137 return "unsupported param type";
141 protected void setValue(Object element
, Object value
) {
142 ProcessParametersView
.ObjectWithName own
= (ProcessParametersView
.ObjectWithName
) element
;
143 if (own
.obj
instanceof PrimitiveAccessor
) {
144 PrimitiveAccessor pv
= (PrimitiveAccessor
) own
.obj
;
145 if (PrimitiveUtils
.typeAsClass(pv
.getType()) != null)
147 pbView
.updateParameter(curProcessIndex
, own
.name
, own
.obj
);
148 getViewer().update(element
, null);
149 } else if (own
.obj
instanceof RefValue
) {
150 RefValue rv
= (RefValue
) own
.obj
;
151 List
<String
> values
= comboBoxes
.get(own
.name
);
152 rv
.setRef(values
.get(((Integer
) value
).intValue()));
153 getViewer().update(element
, null);
158 // Store the index of the process which parameters are being edited
159 public void setCurrentProcessIndex(int index
) {
160 this.curProcessIndex
= index
;
163 public void setCurrentExecutionSpec(ExecutionSpec executionSpec
) {
164 this.executionSpec
= executionSpec
;
167 public void setCurrentProcessBuilderView(
168 ProcessBuilderView processbuilderView
) {
169 this.pbView
= processbuilderView
;