X-Git-Url: http://git.argeo.org/?a=blobdiff_plain;f=plugins%2Forg.argeo.slc.client.ui%2Fsrc%2Fmain%2Fjava%2Forg%2Fargeo%2Fslc%2Fclient%2Fui%2Feditors%2FProcessBuilderPage.java;h=07817cc2a623e7e5e1fb3019c86ad4dc43c724c7;hb=48b6f7647f12f4b96d1914bcafc95efd7f43cc43;hp=c3e07153c371d29f9dc197874f71996c045eb1c0;hpb=58e0e18d64a2080680a9f8397b0dfa2894519910;p=gpl%2Fargeo-slc.git diff --git a/plugins/org.argeo.slc.client.ui/src/main/java/org/argeo/slc/client/ui/editors/ProcessBuilderPage.java b/plugins/org.argeo.slc.client.ui/src/main/java/org/argeo/slc/client/ui/editors/ProcessBuilderPage.java index c3e07153c..07817cc2a 100644 --- a/plugins/org.argeo.slc.client.ui/src/main/java/org/argeo/slc/client/ui/editors/ProcessBuilderPage.java +++ b/plugins/org.argeo.slc.client.ui/src/main/java/org/argeo/slc/client/ui/editors/ProcessBuilderPage.java @@ -33,15 +33,12 @@ import javax.jcr.query.Query; import javax.jcr.query.QueryManager; import org.argeo.ArgeoException; -import org.argeo.eclipse.ui.ErrorFeedback; import org.argeo.eclipse.ui.jcr.AsyncUiEventListener; import org.argeo.jcr.JcrUtils; import org.argeo.slc.SlcException; -import org.argeo.slc.client.ui.ClientUiPlugin; import org.argeo.slc.client.ui.SlcImages; import org.argeo.slc.core.execution.PrimitiveAccessor; import org.argeo.slc.core.execution.PrimitiveUtils; -import org.argeo.slc.execution.ExecutionModulesManager; import org.argeo.slc.execution.ExecutionProcess; import org.argeo.slc.jcr.SlcJcrUtils; import org.argeo.slc.jcr.SlcNames; @@ -80,6 +77,8 @@ import org.eclipse.swt.layout.RowLayout; import org.eclipse.swt.widgets.Button; import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Label; +import org.eclipse.swt.widgets.Menu; +import org.eclipse.swt.widgets.MenuItem; import org.eclipse.swt.widgets.Table; import org.eclipse.ui.forms.AbstractFormPart; import org.eclipse.ui.forms.IManagedForm; @@ -89,13 +88,15 @@ import org.eclipse.ui.forms.widgets.ScrolledForm; /** Definition of the process. */ public class ProcessBuilderPage extends FormPage implements SlcNames { + // private final static Log log = + // LogFactory.getLog(ProcessBuilderPage.class); + public final static String ID = "processBuilderPage"; /** To be displayed in empty lists */ final static String NONE = ""; private Node processNode; - private final ExecutionModulesManager modulesManager; private TreeViewer flowsViewer; private TableViewer valuesViewer; @@ -107,11 +108,9 @@ public class ProcessBuilderPage extends FormPage implements SlcNames { private AbstractFormPart formPart; private EventListener statusObserver; - public ProcessBuilderPage(ProcessEditor editor, Node processNode, - ExecutionModulesManager modulesManager) { + public ProcessBuilderPage(ProcessEditor editor, Node processNode) { super(editor, ID, "Definition"); this.processNode = processNode; - this.modulesManager = modulesManager; } @Override @@ -241,6 +240,9 @@ public class ProcessBuilderPage extends FormPage implements SlcNames { flowsViewer.addDropSupport(operations, tt, new FlowsDropListener( flowsViewer)); + // Context menu + addContextMenu(); + flowsViewer.setInput(getEditorSite()); flowsViewer.setInput(processNode); @@ -251,6 +253,8 @@ public class ProcessBuilderPage extends FormPage implements SlcNames { GridData valuedGd = new GridData(SWT.FILL, SWT.FILL, true, true); // valuedGd.widthHint = 200; valuesViewer.getTable().setLayoutData(valuedGd); + valuesViewer.getTable().setHeaderVisible(true); + valuesViewer.setContentProvider(new ValuesContentProvider()); initializeValuesViewer(valuesViewer); sashForm.setWeights(getWeights()); @@ -343,6 +347,8 @@ public class ProcessBuilderPage extends FormPage implements SlcNames { Node flowNode = processNode.getSession().getNode(path); Node realizedFlowNode = processNode.getNode(SLC_FLOW).addNode( SLC_FLOW); + realizedFlowNode.setProperty(SLC_NAME, + flowNode.getProperty(SLC_NAME).getString()); realizedFlowNode.addMixin(SlcTypes.SLC_REALIZED_FLOW); Node address = realizedFlowNode.addNode(SLC_ADDRESS, NodeType.NT_ADDRESS); @@ -381,10 +387,21 @@ public class ProcessBuilderPage extends FormPage implements SlcNames { } } + // Part title + StringBuilder editorTitle = new StringBuilder(); + NodeIterator it = realizedFlowNode.getParent().getNodes(SLC_FLOW); + while (it.hasNext()) { + Node rFlowNode = it.nextNode(); + String name = rFlowNode.getProperty(SLC_NAME).getString(); + editorTitle.append(name).append(' '); + } + ((ProcessEditor) getEditor()) + .setEditorTitle(editorTitle.toString()); + flowsViewer.refresh(); formPart.markDirty(); } catch (RepositoryException e) { - throw new SlcException("Cannot drop " + path, e); + throw new SlcException("Cannot add flow " + path, e); } } @@ -610,6 +627,39 @@ public class ProcessBuilderPage extends FormPage implements SlcNames { } } + /** + * Add a context menu that call private methods. It only relies on selected + * item(s) not on parameter that are passed in the menuAboutToShow method + **/ + private void addContextMenu() { + Menu menu = new Menu(flowsViewer.getControl()); + + MenuItem removeItems = new MenuItem(menu, SWT.PUSH); + removeItems.addSelectionListener(new SelectionListener() { + + public void widgetSelected(SelectionEvent e) { + removeSelectedFlows(); + } + + public void widgetDefaultSelected(SelectionEvent e) { + } + }); + removeItems.setText("Remove selected flow(s)"); + + MenuItem removeAllItems = new MenuItem(menu, SWT.PUSH); + removeAllItems.addSelectionListener(new SelectionListener() { + + public void widgetSelected(SelectionEvent e) { + removeAllFlows(); + } + + public void widgetDefaultSelected(SelectionEvent e) { + } + }); + removeAllItems.setText("Remove all flows"); + flowsViewer.getTree().setMenu(menu); + } + /** Manages drop event. */ class FlowsDropListener extends ViewerDropAdapter { @@ -619,32 +669,40 @@ public class ProcessBuilderPage extends FormPage implements SlcNames { @Override public boolean performDrop(Object data) { - String path = data.toString(); - try { - // either a node or a whole directory was dragged - QueryManager qm = processNode.getSession().getWorkspace() - .getQueryManager(); - String statement = "SELECT * FROM [" - + SlcTypes.SLC_EXECUTION_FLOW - + "] WHERE ISDESCENDANTNODE(['" + path - + "']) OR ISSAMENODE(['" + path + "'])"; - // log.debug(statement); - Query query = qm.createQuery(statement, Query.JCR_SQL2); - - // order paths - SortedSet paths = new TreeSet(); - for (NodeIterator nit = query.execute().getNodes(); nit - .hasNext();) { - paths.add(nit.nextNode().getPath()); - } - for (String p : paths) { - addFlow(p); + // Parse the received String, paths are separated with a carriage + // return + String[] paths = data.toString().split(new String("\n")); + SortedSet resultPaths = new TreeSet(); + for (String path : paths) { + try { + // either a node or a whole directory can have been dragged + QueryManager qm = processNode.getSession().getWorkspace() + .getQueryManager(); + String statement = "SELECT * FROM [" + + SlcTypes.SLC_EXECUTION_FLOW + + "] WHERE ISDESCENDANTNODE(['" + path + + "']) OR ISSAMENODE(['" + path + "'])"; + Query query = qm.createQuery(statement, Query.JCR_SQL2); + + // order paths + for (NodeIterator nit = query.execute().getNodes(); nit + .hasNext();) { + String currPath = nit.nextNode().getPath(); + // do not add twice a same flow + if (!resultPaths.contains(currPath)) + resultPaths.add(currPath); + } + } catch (RepositoryException e) { + throw new SlcException("Cannot query flows under " + path, + e); } - return true; - } catch (RepositoryException e) { - throw new SlcException("Cannot query flows under " + path, e); } + for (String p : resultPaths) { + addFlow(p); + } + return true; + } @Override @@ -672,6 +730,12 @@ public class ProcessBuilderPage extends FormPage implements SlcNames { if (!specAttrNode .isNodeType(SlcTypes.SLC_EXECUTION_SPEC_ATTRIBUTE)) continue specAttrs; + // workaround to enable hiding of necessary but unusable + // flow parameters + else if (specAttrNode.hasProperty(SlcNames.SLC_IS_HIDDEN) + && specAttrNode.getProperty(SlcNames.SLC_IS_HIDDEN) + .getBoolean()) + continue specAttrs; specAttributes.add(specAttrNode); } return specAttributes.toArray(); @@ -724,7 +788,7 @@ public class ProcessBuilderPage extends FormPage implements SlcNames { } return null; } catch (RepositoryException e) { - throw new SlcException("Cannot get celle editor", e); + throw new SlcException("Cannot get cell editor", e); } } @@ -732,10 +796,11 @@ public class ProcessBuilderPage extends FormPage implements SlcNames { protected boolean canEdit(Object element) { try { Node specAttrNode = (Node) element; - return !(specAttrNode.getProperty(SLC_IS_IMMUTABLE) - .getBoolean() || specAttrNode.getProperty( - SLC_IS_CONSTANT).getBoolean()) - && isSupportedAttributeType(specAttrNode); + Boolean cannotEdit = specAttrNode.getProperty(SLC_IS_IMMUTABLE) + .getBoolean() + || specAttrNode.getProperty(SLC_IS_CONSTANT) + .getBoolean(); + return !cannotEdit && isSupportedAttributeType(specAttrNode); } catch (RepositoryException e) { throw new SlcException("Cannot check whether " + element + " is editable", e); @@ -807,4 +872,4 @@ public class ProcessBuilderPage extends FormPage implements SlcNames { } } -} +} \ No newline at end of file