import org.eclipse.jface.viewers.CellEditor;
import org.eclipse.jface.viewers.ColumnLabelProvider;
import org.eclipse.jface.viewers.ColumnViewer;
+import org.eclipse.jface.viewers.ComboBoxCellEditor;
import org.eclipse.jface.viewers.EditingSupport;
import org.eclipse.jface.viewers.ISelectionChangedListener;
import org.eclipse.jface.viewers.IStructuredContentProvider;
// private final static Log log =
// LogFactory.getLog(ProcessBuilderPage.class);
+ /** To be displayed in empty lists */
+ final static String NONE = "<none>";
+
private Node processNode;
private TreeViewer flowsViewer;
} else if (i == 1) {
column.setLabelProvider(new ColumnLabelProvider() {
public String getText(Object element) {
- Object obj = getAttributeSpecValue((Node) element);
- return obj != null ? obj.toString() : "";
+ return getAttributeSpecText((Node) element);
}
});
column.setEditingSupport(new ValuesEditingSupport(viewer));
/*
* UTILITIES
*/
- protected static Object getAttributeSpecValue(Node specAttrNode) {
+ // protected static Object getAttributeSpecValue(Node specAttrNode) {
+ // try {
+ // if (specAttrNode.isNodeType(SlcTypes.SLC_PRIMITIVE_SPEC_ATTRIBUTE)) {
+ // if (!specAttrNode.hasProperty(SLC_VALUE))
+ // return null;
+ // String type = specAttrNode.getProperty(SLC_TYPE).getString();
+ // // TODO optimize based on data type?
+ // Object value = PrimitiveUtils.convert(type, specAttrNode
+ // .getProperty(SLC_VALUE).getString());
+ // // log.debug(specAttrNode + ", type=" + type + ", value=" +
+ // // value);
+ // return value;
+ // } else if (specAttrNode.isNodeType(SlcTypes.SLC_REF_SPEC_ATTRIBUTE)) {
+ // if (specAttrNode.hasNode(SLC_VALUE)) {
+ // // return the index of the sub node
+ // // in the future we may manage reference as well
+ // return specAttrNode.getProperty(SLC_VALUE).getLong();
+ // } else
+ // return null;
+ // }
+ // return null;
+ // } catch (RepositoryException e) {
+ // throw new SlcException("Cannot get value", e);
+ // }
+ //
+ // }
+
+ protected static String getAttributeSpecText(Node specAttrNode) {
try {
if (specAttrNode.isNodeType(SlcTypes.SLC_PRIMITIVE_SPEC_ATTRIBUTE)) {
if (!specAttrNode.hasProperty(SLC_VALUE))
- return null;
+ return "";
String type = specAttrNode.getProperty(SLC_TYPE).getString();
- // TODO optimize based on data type?
Object value = PrimitiveUtils.convert(type, specAttrNode
.getProperty(SLC_VALUE).getString());
- // log.debug(specAttrNode + ", type=" + type + ", value=" +
- // value);
- return value;
+ return value.toString();
+ } else if (specAttrNode.isNodeType(SlcTypes.SLC_REF_SPEC_ATTRIBUTE)) {
+ if (specAttrNode.hasProperty(SLC_VALUE)) {
+ int value = (int) specAttrNode.getProperty(SLC_VALUE)
+ .getLong();
+ NodeIterator children = specAttrNode.getNodes();
+ int index = 0;
+ while (children.hasNext()) {
+ Node child = children.nextNode();
+ if (index == value)
+ return child.getProperty(Property.JCR_TITLE)
+ .getString();
+ index++;
+ }
+ throw new SlcException("No child node with index " + value
+ + " for spec attribute " + specAttrNode);
+ } else
+ return "";
}
- return null;
+ throw new SlcException("Unsupported type for spec attribute "
+ + specAttrNode);
} catch (RepositoryException e) {
throw new SlcException("Cannot get value", e);
}
-
}
/*
try {
Node specAttrNode = (Node) element;
if (specAttrNode
- .isNodeType(SlcTypes.SLC_PRIMITIVE_SPEC_ATTRIBUTE))
+ .isNodeType(SlcTypes.SLC_PRIMITIVE_SPEC_ATTRIBUTE)) {
return new TextCellEditor(tableViewer.getTable());
+ } else if (specAttrNode
+ .isNodeType(SlcTypes.SLC_REF_SPEC_ATTRIBUTE)) {
+ NodeIterator children = specAttrNode.getNodes();
+ ArrayList<String> items = new ArrayList<String>();
+ while (children.hasNext()) {
+ Node child = children.nextNode();
+ if (child.isNodeType(NodeType.MIX_TITLE))
+ items.add(child.getProperty(Property.JCR_TITLE)
+ .getString());
+ }
+ return new ComboBoxCellEditor(tableViewer.getTable(),
+ items.toArray(new String[items.size()]));
+ }
return null;
} catch (RepositoryException e) {
throw new SlcException("Cannot get celle editor", e);
return !(specAttrNode.getProperty(SLC_IS_IMMUTABLE)
.getBoolean() || specAttrNode.getProperty(
SLC_IS_CONSTANT).getBoolean())
- && specAttrNode
- .isNodeType(SlcTypes.SLC_PRIMITIVE_SPEC_ATTRIBUTE);
+ && isSupportedAttributeType(specAttrNode);
} catch (RepositoryException e) {
- throw new SlcException("Cannot check canEdit", e);
+ throw new SlcException("Cannot check whether " + element
+ + " is editable", e);
}
}
+ /**
+ * Supports {@link SlcTypes#SLC_PRIMITIVE_SPEC_ATTRIBUTE} and
+ * {@link SlcTypes#SLC_REF_SPEC_ATTRIBUTE}
+ */
+ protected boolean isSupportedAttributeType(Node specAttrNode)
+ throws RepositoryException {
+ return specAttrNode
+ .isNodeType(SlcTypes.SLC_PRIMITIVE_SPEC_ATTRIBUTE)
+ || specAttrNode.isNodeType(SlcTypes.SLC_REF_SPEC_ATTRIBUTE);
+ }
+
@Override
protected Object getValue(Object element) {
Node specAttrNode = (Node) element;
try {
- Object value = getAttributeSpecValue(specAttrNode);
- if (value == null)
- throw new SlcException("Unsupported attribute " + element);
+ // Object value = getAttributeSpecValue(specAttrNode);
+ // if (value == null)
+ // throw new SlcException("Unsupported attribute " + element);
if (specAttrNode
- .isNodeType(SlcTypes.SLC_PRIMITIVE_SPEC_ATTRIBUTE))
+ .isNodeType(SlcTypes.SLC_PRIMITIVE_SPEC_ATTRIBUTE)) {
+ if (!specAttrNode.hasProperty(SLC_VALUE))
+ return NONE;
+ String type = specAttrNode.getProperty(SLC_TYPE)
+ .getString();
+ // TODO optimize based on data type?
+ Object value = PrimitiveUtils.convert(type, specAttrNode
+ .getProperty(SLC_VALUE).getString());
return value.toString();
- return value;
+ } else if (specAttrNode
+ .isNodeType(SlcTypes.SLC_REF_SPEC_ATTRIBUTE)) {
+ if (!specAttrNode.hasProperty(SLC_VALUE))
+ return 0;
+ // return the index of the sub node as set by setValue()
+ // in the future we may manage references as well
+ return (int) specAttrNode.getProperty(SLC_VALUE).getLong();
+ }
+ throw new SlcException("Unsupported type for spec attribute "
+ + specAttrNode);
} catch (RepositoryException e) {
throw new SlcException("Cannot get value for " + element, e);
}
type, value);
valuesViewer.refresh();
formPart.markDirty();
+ } else if (specAttrNode
+ .isNodeType(SlcTypes.SLC_REF_SPEC_ATTRIBUTE)) {
+ specAttrNode.setProperty(SLC_VALUE,
+ ((Integer) value).longValue());
+ valuesViewer.refresh();
+ formPart.markDirty();
}
} catch (RepositoryException e) {
throw new SlcException("Cannot get celle editor", e);
import org.argeo.slc.core.execution.PrimitiveSpecAttribute;
import org.argeo.slc.core.execution.PrimitiveUtils;
import org.argeo.slc.core.execution.ProcessThread;
+import org.argeo.slc.core.execution.RefSpecAttribute;
import org.argeo.slc.execution.ExecutionFlowDescriptor;
import org.argeo.slc.execution.ExecutionModulesManager;
import org.argeo.slc.execution.ExecutionProcess;
realizedFlow.setModuleVersion(executionModuleVersion);
// retrieve execution spec
- DefaultExecutionSpec executionSpec = null;
+ DefaultExecutionSpec executionSpec = new DefaultExecutionSpec();
+ Map<String, ExecutionSpecAttribute> attrs = readExecutionSpecAttributes(realizedFlowNode);
+ executionSpec.setAttributes(attrs);
+
+ // set execution spec name
if (flowNode.hasProperty(SlcNames.SLC_SPEC)) {
Node executionSpecNode = flowNode.getProperty(SLC_SPEC)
.getNode();
- executionSpec = new DefaultExecutionSpec();
executionSpec.setBeanName(executionSpecNode.getProperty(
SLC_NAME).getString());
- executionSpec
- .setAttributes(readExecutionSpecAttributes(executionSpecNode));
}
- // TODO: will with original attr
- Map<String, ExecutionSpecAttribute> attrs = readExecutionSpecAttributes(realizedFlowNode);
+
+ // explicitly retrieve values
Map<String, Object> values = new HashMap<String, Object>();
for (String attrName : attrs.keySet()) {
-// if (flowNode.hasNode(attrName)) {
-// // we assume this is a primitive
-// // since ref are not yet implemented
-// Node valueNode = flowNode.getNode(attrName);
-// String type = valueNode.getProperty(SLC_TYPE).getString();
-// String valueStr = valueNode.getProperty(SLC_VALUE)
-// .getString();
-// Object value = PrimitiveUtils.convert(type, valueStr);
-// values.put(attrName, value);
-// } else {
- ExecutionSpecAttribute attr = attrs.get(attrName);
- Object value = attr.getValue();
- values.put(attrName, value);
-// }
+ ExecutionSpecAttribute attr = attrs.get(attrName);
+ Object value = attr.getValue();
+ values.put(attrName, value);
}
- // if(executionSpec!=null)
- // executionSpec.setAttributes(attrs);
ExecutionFlowDescriptor efd = new ExecutionFlowDescriptor(flowName,
values, executionSpec);
realizedFlow.setFlowDescriptor(efd);
PrimitiveSpecAttribute specAttr = new PrimitiveSpecAttribute(
type, value);
attrs.put(specAttrNode.getName(), specAttr);
+ } else if (specAttrNode
+ .isNodeType(SlcTypes.SLC_REF_SPEC_ATTRIBUTE)) {
+ if (!specAttrNode.hasProperty(SLC_VALUE)) {
+ continue;
+ }
+ Integer value = (int) specAttrNode.getProperty(SLC_VALUE)
+ .getLong();
+ RefSpecAttribute specAttr = new RefSpecAttribute();
+ NodeIterator children = specAttrNode.getNodes();
+ int index = 0;
+ String id = null;
+ while (children.hasNext()) {
+ Node child = children.nextNode();
+ if (index == value)
+ id = child.getName();
+ index++;
+ }
+ specAttr.setValue(id);
+ attrs.put(specAttrNode.getName(), specAttr);
}
-
+ // throw new SlcException("Unsupported spec attribute "
+ // + specAttrNode);
}
return attrs;
} catch (RepositoryException e) {