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%2Fviews%2FJcrExecutionModulesView.java;h=71f291e8ac56b48e2757b7529fbb175870a62f1f;hb=48b6f7647f12f4b96d1914bcafc95efd7f43cc43;hp=f8cfab4c905fc3ed2b8edc08f8561ef156773c47;hpb=52311a31c8559c80c3189e2416b1e4a3d9cab3d2;p=gpl%2Fargeo-slc.git diff --git a/plugins/org.argeo.slc.client.ui/src/main/java/org/argeo/slc/client/ui/views/JcrExecutionModulesView.java b/plugins/org.argeo.slc.client.ui/src/main/java/org/argeo/slc/client/ui/views/JcrExecutionModulesView.java index f8cfab4c9..71f291e8a 100644 --- a/plugins/org.argeo.slc.client.ui/src/main/java/org/argeo/slc/client/ui/views/JcrExecutionModulesView.java +++ b/plugins/org.argeo.slc.client.ui/src/main/java/org/argeo/slc/client/ui/views/JcrExecutionModulesView.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2007-2012 Mathieu Baudier + * Copyright (C) 2007-2012 Argeo GmbH * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -26,6 +26,7 @@ import java.util.TreeSet; import javax.jcr.Node; import javax.jcr.NodeIterator; import javax.jcr.Property; +import javax.jcr.Repository; import javax.jcr.RepositoryException; import javax.jcr.Session; import javax.jcr.nodetype.NodeType; @@ -41,9 +42,9 @@ import org.argeo.eclipse.ui.jcr.DefaultNodeLabelProvider; import org.argeo.eclipse.ui.jcr.NodeElementComparer; import org.argeo.eclipse.ui.jcr.SimpleNodeContentProvider; import org.argeo.eclipse.ui.specific.EclipseUiSpecificUtils; -import org.argeo.slc.BasicNameVersion; -import org.argeo.slc.NameVersion; +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.client.ui.editors.ProcessEditor; import org.argeo.slc.client.ui.editors.ProcessEditorInput; @@ -51,10 +52,6 @@ import org.argeo.slc.execution.ExecutionModulesManager; import org.argeo.slc.jcr.SlcJcrConstants; import org.argeo.slc.jcr.SlcNames; import org.argeo.slc.jcr.SlcTypes; -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.core.runtime.IStatus; -import org.eclipse.core.runtime.Status; -import org.eclipse.core.runtime.jobs.Job; import org.eclipse.jface.viewers.DoubleClickEvent; import org.eclipse.jface.viewers.IDoubleClickListener; import org.eclipse.jface.viewers.IStructuredSelection; @@ -79,18 +76,18 @@ public class JcrExecutionModulesView extends ViewPart implements SlcTypes, private final static Log log = LogFactory .getLog(JcrExecutionModulesView.class); - public static final String ID = "org.argeo.slc.client.ui.jcrExecutionModulesView"; + public static final String ID = ClientUiPlugin.ID + + ".jcrExecutionModulesView"; private TreeViewer viewer; + /* DEPENDENCY INJECTION */ private Session session; - private ExecutionModulesManager modulesManager; public void createPartControl(Composite parent) { viewer = new TreeViewer(parent, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL); EclipseUiSpecificUtils.enableToolTipSupport(viewer); - ViewContentProvider contentProvider = new ViewContentProvider(session); viewer.setContentProvider(contentProvider); viewer.setComparer(new NodeElementComparer()); @@ -98,6 +95,9 @@ public class JcrExecutionModulesView extends ViewPart implements SlcTypes, viewer.setLabelProvider(viewLabelProvider); viewer.setInput(getViewSite()); viewer.addDoubleClickListener(new ViewDoubleClickListener()); + // context menu + // addContextMenu(viewer); + getViewSite().setSelectionProvider(viewer); Transfer[] tt = new Transfer[] { TextTransfer.getInstance() }; @@ -133,6 +133,7 @@ public class JcrExecutionModulesView extends ViewPart implements SlcTypes, viewer.setInput(getViewSite()); } + // Controllers class ViewContentProvider extends SimpleNodeContentProvider { public ViewContentProvider(Session session) { @@ -140,20 +141,6 @@ public class JcrExecutionModulesView extends ViewPart implements SlcTypes, new String[] { SlcJcrConstants.VM_AGENT_FACTORY_PATH }); } - // @Override - // protected Object[] getChildren(Node node) throws RepositoryException - // { - // if (node.isNodeType(SlcTypes.SLC_AGENT_FACTORY)) { - // List wrappers = new - // ArrayList(); - // for (NodeIterator nit = node.getNodes(); nit.hasNext();) { - // wrappers.add(new AgentNodesWrapper(nit.nextNode())); - // } - // return wrappers.toArray(); - // } - // return super.getChildren(node); - // } - @Override protected Object[] sort(Object parent, Object[] children) { Object[] sorted = new Object[children.length]; @@ -229,26 +216,23 @@ public class JcrExecutionModulesView extends ViewPart implements SlcTypes, } - // /** Wraps the execution modules of an agent. */ - // static class AgentNodesWrapper extends NodesWrapper { + // private void addContextMenu(TreeViewer flowsViewer) { // - // public AgentNodesWrapper(Node node) { - // super(node); - // } + // final MenuManager menuMgr = new MenuManager(); + // menuMgr.setRemoveAllWhenShown(true); + // menuMgr.addMenuListener(new IMenuListener() { // - // protected List getWrappedNodes() - // throws RepositoryException { - // List children = new ArrayList(); - // Node executionModules = getNode(); - // for (NodeIterator nit = executionModules.getNodes(); nit.hasNext();) { - // for (NodeIterator nitVersions = nit.nextNode().getNodes(); nitVersions - // .hasNext();) { - // children.add(new WrappedNode(this, nitVersions.nextNode())); + // public void menuAboutToShow(IMenuManager manager) { + // menuMgr.add(new Action("Test") { + // public void run() { + // log.debug("do something"); // } + // }); // } - // return children; - // } - // + // }); + // Menu menu = menuMgr.createContextMenu(flowsViewer.getControl()); + // flowsViewer.getTree().setMenu(menu); + // getSite().registerContextMenu(menuMgr, flowsViewer); // } class VmAgentObserver extends AsyncUiEventListener { @@ -274,13 +258,6 @@ public class JcrExecutionModulesView extends ViewPart implements SlcTypes, } } - // try { - // Node vmAgentNode = session - // .getNode(SlcJcrConstants.VM_AGENT_FACTORY_PATH); - // viewer.refresh(vmAgentNode); - // } catch (RepositoryException e) { - // log.warn("Cannot process event : " + e); - // } // TODO: optimize based on event viewer.refresh(); } @@ -354,46 +331,8 @@ public class JcrExecutionModulesView extends ViewPart implements SlcTypes, if (obj instanceof Node) { Node node = (Node) obj; if (node.isNodeType(SLC_EXECUTION_MODULE)) { - String name = node.getProperty(SLC_NAME).getString(); - String version = node.getProperty(SLC_VERSION) - .getString(); - final NameVersion nameVersion = new BasicNameVersion( - name, version); - Boolean started = node.getProperty(SLC_STARTED) - .getBoolean(); - - Job job; - if (started) { - job = new Job("Stop " + nameVersion) { - protected IStatus run(IProgressMonitor monitor) { - monitor.beginTask("Stop " + nameVersion, 1); - modulesManager.stop(nameVersion); - monitor.worked(1); - return Status.OK_STATUS; - } - - protected void canceling() { - getThread().interrupt(); - super.canceling(); - } - }; - } else { - job = new Job("Start " + nameVersion) { - protected IStatus run(IProgressMonitor monitor) { - monitor.beginTask("Start " + nameVersion, 1); - modulesManager.start(nameVersion); - monitor.worked(1); - return Status.OK_STATUS; - } - - protected void canceling() { - getThread().interrupt(); - super.canceling(); - } - }; - } - job.setUser(true); - job.schedule(); + ClientUiPlugin.startStopExecutionModule(modulesManager, + node); } else { String path = node.getPath(); // TODO factorize with editor @@ -413,8 +352,6 @@ public class JcrExecutionModulesView extends ViewPart implements SlcTypes, paths.add(nit.nextNode().getPath()); } - // List paths = new ArrayList(); - // paths.add(node.getPath()); IWorkbenchPage activePage = PlatformUI.getWorkbench() .getActiveWorkbenchWindow().getActivePage(); activePage.openEditor(new ProcessEditorInput( @@ -431,28 +368,89 @@ public class JcrExecutionModulesView extends ViewPart implements SlcTypes, /** Listen to drags */ class ViewDragListener extends DragSourceAdapter { + + // Check if the drag action should start. + public void dragStart(DragSourceEvent event) { + // we only start drag if at least one of the selected elements is + // valid + boolean doIt = false; + IStructuredSelection selection = (IStructuredSelection) viewer + .getSelection(); + @SuppressWarnings("rawtypes") + Iterator it = selection.iterator(); + try { + while (it.hasNext()) { + Object obj = it.next(); + if (obj instanceof Node) { + Node node = (Node) obj; + if (node.isNodeType(SlcTypes.SLC_EXECUTION_FLOW) + || node.isNodeType(SlcTypes.SLC_EXECUTION_MODULE)) { + doIt = true; + } + } + } + } catch (RepositoryException e) { + throw new SlcException("Cannot read node to set drag data", e); + } + event.doit = doIt; + } + public void dragSetData(DragSourceEvent event) { IStructuredSelection selection = (IStructuredSelection) viewer .getSelection(); - if (selection.getFirstElement() instanceof Node) { - Node node = (Node) selection.getFirstElement(); - if (TextTransfer.getInstance().isSupportedType(event.dataType)) { - try { - event.data = node.getPath(); - } catch (RepositoryException e) { - throw new SlcException("Cannot read node", e); + StringBuilder buf = new StringBuilder(); + @SuppressWarnings("rawtypes") + Iterator it = selection.iterator(); + try { + + while (it.hasNext()) { + Object obj = it.next(); + + if (obj instanceof Node) { + Node node = (Node) obj; + if ((node.isNodeType(SlcTypes.SLC_EXECUTION_FLOW) || node + .isNodeType(SlcTypes.SLC_EXECUTION_MODULE)) + && TextTransfer.getInstance().isSupportedType( + event.dataType)) { + buf.append(node.getPath()).append('\n'); + } } } + } catch (RepositoryException e) { + throw new SlcException("Cannot read node to set drag data", e); + } + + if (buf.length() > 0) { + if (buf.charAt(buf.length() - 1) == '\n') + buf.deleteCharAt(buf.length() - 1); + event.data = buf.toString(); + log.debug("data set to : " + buf.toString()); } } } - public void setSession(Session session) { - this.session = session; + public void dispose() { + JcrUtils.logoutQuietly(session); + super.dispose(); } + // DEPENDENCY INJECTION + public void setModulesManager(ExecutionModulesManager modulesManager) { this.modulesManager = modulesManager; } + @Deprecated + public void setSession(Session session) { + this.session = session; + } + + public void setRepository(Repository repository) { + try { + session = repository.login(); + } catch (RepositoryException re) { + throw new SlcException("Unable to log in Repository " + repository, + re); + } + } } \ No newline at end of file