X-Git-Url: http://git.argeo.org/?a=blobdiff_plain;f=eclipse%2Fplugins%2Forg.argeo.slc.client.ui%2Fsrc%2Fmain%2Fjava%2Forg%2Fargeo%2Fslc%2Fclient%2Fui%2Feditors%2FProcessBuilderPage.java;h=b46b2f1b095e4d418dd62964be031e9a9b97b6de;hb=8908d07cc1fd6ac0a274c460bbd40652816ca054;hp=28c2f69c611a6bd485256a70f055f1759a5cc287;hpb=24d560ee846fda5d7954d44f83cb22ab449dbe61;p=gpl%2Fargeo-slc.git diff --git a/eclipse/plugins/org.argeo.slc.client.ui/src/main/java/org/argeo/slc/client/ui/editors/ProcessBuilderPage.java b/eclipse/plugins/org.argeo.slc.client.ui/src/main/java/org/argeo/slc/client/ui/editors/ProcessBuilderPage.java index 28c2f69c6..b46b2f1b0 100644 --- a/eclipse/plugins/org.argeo.slc.client.ui/src/main/java/org/argeo/slc/client/ui/editors/ProcessBuilderPage.java +++ b/eclipse/plugins/org.argeo.slc.client.ui/src/main/java/org/argeo/slc/client/ui/editors/ProcessBuilderPage.java @@ -1,3 +1,18 @@ +/* + * Copyright (C) 2007-2012 Mathieu Baudier + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package org.argeo.slc.client.ui.editors; import java.util.ArrayList; @@ -30,6 +45,7 @@ import org.argeo.slc.jcr.SlcTypes; 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; @@ -73,6 +89,9 @@ public class ProcessBuilderPage extends FormPage implements SlcNames { // private final static Log log = // LogFactory.getLog(ProcessBuilderPage.class); + /** To be displayed in empty lists */ + final static String NONE = ""; + private Node processNode; private TreeViewer flowsViewer; @@ -258,8 +277,7 @@ public class ProcessBuilderPage extends FormPage implements SlcNames { } 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)); @@ -348,7 +366,7 @@ public class ProcessBuilderPage extends FormPage implements SlcNames { .getName()); JcrUtils.copy(specAttrNode, realizedAttrNode); - // ovveride with flow value + // override with flow value if (flowNode.hasNode(attrName)) { // assuming this is a primitive realizedAttrNode.setProperty(SLC_VALUE, @@ -442,24 +460,65 @@ public class ProcessBuilderPage extends FormPage implements SlcNames { /* * 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); } - } /* @@ -653,8 +712,21 @@ public class ProcessBuilderPage extends FormPage implements SlcNames { 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 items = new ArrayList(); + 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); @@ -668,24 +740,51 @@ public class ProcessBuilderPage extends FormPage implements SlcNames { 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); } @@ -703,6 +802,12 @@ public class ProcessBuilderPage extends FormPage implements SlcNames { 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);