From 6a5737bbf4cd63e00e61a3fd81e6673b5ad9341f Mon Sep 17 00:00:00 2001 From: Mathieu Baudier Date: Mon, 2 May 2011 15:32:07 +0000 Subject: [PATCH] Improve RCP git-svn-id: https://svn.argeo.org/slc/trunk@4492 4cfe0d0a-d680-48aa-b62c-e0a02a3f76cc --- .../META-INF/MANIFEST.MF | 1 + .../org.argeo.slc.client.rcp/plugin.xml | 16 --- .../rcp/ApplicationActionBarAdvisor.java | 35 ------ .../rcp/SlcSecureWorkbenchWindowAdvisor.java | 58 ++++------ .../slc/client/rcp/commands/ExitHandler.java | 17 --- .../org.argeo.slc.client.ui/plugin.xml | 2 +- .../ui/views/JcrExecutionModulesView.java | 12 ++ .../client/ui/views/JcrResultListView.java | 59 ++++++---- .../main/java/org/argeo/slc/jcr/SlcNames.java | 1 + .../main/java/org/argeo/slc/jcr/SlcTypes.java | 1 + .../slc/jcr/execution/JcrResultListener.java | 103 +++++++++++++++++- .../main/resources/org/argeo/slc/jcr/slc.cnd | 6 +- 12 files changed, 179 insertions(+), 132 deletions(-) delete mode 100644 eclipse/plugins/org.argeo.slc.client.rcp/src/main/java/org/argeo/slc/client/rcp/ApplicationActionBarAdvisor.java delete mode 100644 eclipse/plugins/org.argeo.slc.client.rcp/src/main/java/org/argeo/slc/client/rcp/commands/ExitHandler.java diff --git a/eclipse/plugins/org.argeo.slc.client.rcp/META-INF/MANIFEST.MF b/eclipse/plugins/org.argeo.slc.client.rcp/META-INF/MANIFEST.MF index 304491516..0d00d903f 100644 --- a/eclipse/plugins/org.argeo.slc.client.rcp/META-INF/MANIFEST.MF +++ b/eclipse/plugins/org.argeo.slc.client.rcp/META-INF/MANIFEST.MF @@ -15,3 +15,4 @@ Import-Package: org.argeo.security.ui.rcp, org.argeo.slc.runtime, org.argeo.slc.services, org.argeo.slc.services.impl +Export-Package: org.argeo.slc.client.rcp diff --git a/eclipse/plugins/org.argeo.slc.client.rcp/plugin.xml b/eclipse/plugins/org.argeo.slc.client.rcp/plugin.xml index dc5ca4392..3cc0f922a 100644 --- a/eclipse/plugins/org.argeo.slc.client.rcp/plugin.xml +++ b/eclipse/plugins/org.argeo.slc.client.rcp/plugin.xml @@ -40,20 +40,4 @@ sequence="CTRL+R"> - - - - - - - - diff --git a/eclipse/plugins/org.argeo.slc.client.rcp/src/main/java/org/argeo/slc/client/rcp/ApplicationActionBarAdvisor.java b/eclipse/plugins/org.argeo.slc.client.rcp/src/main/java/org/argeo/slc/client/rcp/ApplicationActionBarAdvisor.java deleted file mode 100644 index 5f013ced1..000000000 --- a/eclipse/plugins/org.argeo.slc.client.rcp/src/main/java/org/argeo/slc/client/rcp/ApplicationActionBarAdvisor.java +++ /dev/null @@ -1,35 +0,0 @@ -package org.argeo.slc.client.rcp; - -import org.eclipse.jface.action.IMenuManager; -import org.eclipse.ui.IWorkbenchWindow; -import org.eclipse.ui.application.ActionBarAdvisor; -import org.eclipse.ui.application.IActionBarConfigurer; - -/** - * An action bar advisor is responsible for creating, adding, and disposing of - * the actions added to a workbench window. Each window will be populated with - * new actions. - */ -public class ApplicationActionBarAdvisor extends ActionBarAdvisor { - - // Actions - important to allocate these only in makeActions, and then use - // them in the fill methods. This ensures that the actions aren't recreated - // when fillActionBars is called with FILL_PROXY. - - public ApplicationActionBarAdvisor(IActionBarConfigurer configurer) { - super(configurer); - } - - protected void makeActions(final IWorkbenchWindow window) { - // Creates the actions and registers them. - // Registering is needed to ensure that key bindings work. - // The corresponding commands keybindings are defined in the plugin.xml - // file. - // Registering also provides automatic disposal of the actions when - // the window is closed. - } - - protected void fillMenuBar(IMenuManager menuBar) { - } - -} diff --git a/eclipse/plugins/org.argeo.slc.client.rcp/src/main/java/org/argeo/slc/client/rcp/SlcSecureWorkbenchWindowAdvisor.java b/eclipse/plugins/org.argeo.slc.client.rcp/src/main/java/org/argeo/slc/client/rcp/SlcSecureWorkbenchWindowAdvisor.java index 1cfd3ddd1..d83f8c9ea 100644 --- a/eclipse/plugins/org.argeo.slc.client.rcp/src/main/java/org/argeo/slc/client/rcp/SlcSecureWorkbenchWindowAdvisor.java +++ b/eclipse/plugins/org.argeo.slc.client.rcp/src/main/java/org/argeo/slc/client/rcp/SlcSecureWorkbenchWindowAdvisor.java @@ -16,12 +16,7 @@ import org.eclipse.ui.IWorkbenchWindow; import org.eclipse.ui.application.IWorkbenchWindowConfigurer; import org.eclipse.ui.part.EditorInputTransfer; -/** - * Set here initial default size of the UI - * - * @author bsinou - * - */ +/** Set here initial default size of the UI */ public class SlcSecureWorkbenchWindowAdvisor extends SecureWorkbenchWindowAdvisor { @@ -32,46 +27,39 @@ public class SlcSecureWorkbenchWindowAdvisor extends super(configurer, username); } - // public ActionBarAdvisor createActionBarAdvisor( - // IActionBarConfigurer configurer) { - // return new ApplicationActionBarAdvisor(configurer); - // } - - - public void postWindowOpen() { initTray(); } - - @Override public void preWindowOpen() { - getWindowConfigurer().addEditorAreaTransfer(EditorInputTransfer.getInstance()); - getWindowConfigurer().configureEditorAreaDropListener(new DropTargetAdapter() { - - @Override - public void dragEnter(DropTargetEvent event) { - System.out.println("DROP enter!!! " + event); - } + getWindowConfigurer().addEditorAreaTransfer( + EditorInputTransfer.getInstance()); + getWindowConfigurer().configureEditorAreaDropListener( + new DropTargetAdapter() { + + @Override + public void dragEnter(DropTargetEvent event) { + System.out.println("DROP enter!!! " + event); + } - @Override - public void dragLeave(DropTargetEvent event) { - System.out.println("DROP leave!!! " + event); - } + @Override + public void dragLeave(DropTargetEvent event) { + System.out.println("DROP leave!!! " + event); + } - public void drop(DropTargetEvent event) { - System.out.println("DROP drop!!! " + event); + public void drop(DropTargetEvent event) { + System.out.println("DROP drop!!! " + event); - } + } - @Override - public void dropAccept(DropTargetEvent event) { - System.out.println("DROP accept!!! " + event); - super.dropAccept(event); - } + @Override + public void dropAccept(DropTargetEvent event) { + System.out.println("DROP accept!!! " + event); + super.dropAccept(event); + } - }); + }); super.preWindowOpen(); } diff --git a/eclipse/plugins/org.argeo.slc.client.rcp/src/main/java/org/argeo/slc/client/rcp/commands/ExitHandler.java b/eclipse/plugins/org.argeo.slc.client.rcp/src/main/java/org/argeo/slc/client/rcp/commands/ExitHandler.java deleted file mode 100644 index 0b593732a..000000000 --- a/eclipse/plugins/org.argeo.slc.client.rcp/src/main/java/org/argeo/slc/client/rcp/commands/ExitHandler.java +++ /dev/null @@ -1,17 +0,0 @@ -package org.argeo.slc.client.rcp.commands; - -import org.eclipse.core.commands.AbstractHandler; -import org.eclipse.core.commands.ExecutionEvent; -import org.eclipse.core.commands.ExecutionException; -import org.eclipse.ui.handlers.HandlerUtil; - -public class ExitHandler extends AbstractHandler { - - // TODO: Could be implemented using default RCP commands. - - public Object execute(ExecutionEvent event) throws ExecutionException { - HandlerUtil.getActiveWorkbenchWindow(event).close(); - return null; - } - -} diff --git a/eclipse/plugins/org.argeo.slc.client.ui/plugin.xml b/eclipse/plugins/org.argeo.slc.client.ui/plugin.xml index 01b2efc3c..d066fe2d2 100644 --- a/eclipse/plugins/org.argeo.slc.client.ui/plugin.xml +++ b/eclipse/plugins/org.argeo.slc.client.ui/plugin.xml @@ -9,7 +9,7 @@ id="org.argeo.slc.client.ui.jcrExecutionModulesView" class="org.argeo.eclipse.spring.SpringExtensionFactory" icon="icons/execution_module.gif" - name="Execution Modules" + name="Execution" restorable="true"> filterChildren(List children) + throws RepositoryException { + for (Iterator it = children.iterator(); it.hasNext();) { + Node node = it.next(); + if (node.getName().equals(SLC_EXECUTION_SPECS)) + it.remove(); + } + return super.filterChildren(children); + } } static class ViewComparator implements Comparator { diff --git a/eclipse/plugins/org.argeo.slc.client.ui/src/main/java/org/argeo/slc/client/ui/views/JcrResultListView.java b/eclipse/plugins/org.argeo.slc.client.ui/src/main/java/org/argeo/slc/client/ui/views/JcrResultListView.java index a886e050c..3a05f0863 100644 --- a/eclipse/plugins/org.argeo.slc.client.ui/src/main/java/org/argeo/slc/client/ui/views/JcrResultListView.java +++ b/eclipse/plugins/org.argeo.slc.client.ui/src/main/java/org/argeo/slc/client/ui/views/JcrResultListView.java @@ -26,6 +26,7 @@ import org.argeo.slc.jcr.SlcNames; import org.argeo.slc.jcr.SlcTypes; import org.eclipse.jface.viewers.ColumnLabelProvider; import org.eclipse.jface.viewers.DoubleClickEvent; +import org.eclipse.jface.viewers.IBaseLabelProvider; import org.eclipse.jface.viewers.IDoubleClickListener; import org.eclipse.jface.viewers.IStructuredContentProvider; import org.eclipse.jface.viewers.IStructuredSelection; @@ -58,8 +59,8 @@ public class JcrResultListView extends ViewPart implements SlcNames { public void createPartControl(Composite parent) { Table table = createTable(parent); viewer = new TableViewer(table); - viewer.setLabelProvider(new LabelProvider()); - viewer.setContentProvider(new ContentProvider()); + viewer.setLabelProvider(createLabelProvider()); + viewer.setContentProvider(new ViewContentProvider()); viewer.setInput(getViewSite()); viewer.addDoubleClickListener(new ViewDoubleClickListener()); @@ -75,8 +76,7 @@ public class JcrResultListView extends ViewPart implements SlcNames { observationManager.addEventListener(resultsObserver, Event.NODE_ADDED | Event.NODE_REMOVED | Event.PROPERTY_CHANGED, - SlcJcrConstants.RESULTS_BASE_PATH, true, null, null, - false); + SlcJcrConstants.RESULTS_BASE_PATH, true, null, null, false); } catch (RepositoryException e) { throw new SlcException("Cannot register listeners", e); } @@ -86,7 +86,7 @@ public class JcrResultListView extends ViewPart implements SlcNames { protected Table createTable(Composite parent) { int style = SWT.SINGLE | SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL | SWT.FULL_SELECTION; - // does not function with RAP, commented for the time being + // does not work with RAP, commented for the time being // | SWT.HIDE_SELECTION; Table table = new Table(parent, style); @@ -105,6 +105,32 @@ public class JcrResultListView extends ViewPart implements SlcNames { return table; } + /* + * METHODS TO BE OVERRIDDEN + */ + protected IBaseLabelProvider createLabelProvider() { + return new ViewLabelProvider(); + } + + protected void processDoubleClick(DoubleClickEvent evt) { + Object obj = ((IStructuredSelection) evt.getSelection()) + .getFirstElement(); + try { + if (obj instanceof Node) { + Node node = (Node) obj; + if (node.isNodeType(SlcTypes.SLC_PROCESS)) { + IWorkbenchPage activePage = PlatformUI.getWorkbench() + .getActiveWorkbenchWindow().getActivePage(); + activePage.openEditor( + new ProcessEditorInput(node.getPath()), + ProcessEditor.ID); + } + } + } catch (Exception e) { + throw new SlcException("Cannot open " + obj, e); + } + } + public void setFocus() { viewer.getControl().setFocus(); } @@ -115,7 +141,7 @@ public class JcrResultListView extends ViewPart implements SlcNames { super.dispose(); } - class ContentProvider implements IStructuredContentProvider { + class ViewContentProvider implements IStructuredContentProvider { public Object[] getElements(Object inputElement) { try { @@ -144,7 +170,7 @@ public class JcrResultListView extends ViewPart implements SlcNames { } - class LabelProvider extends ColumnLabelProvider implements + class ViewLabelProvider extends ColumnLabelProvider implements ITableLabelProvider { public Image getColumnImage(Object obj, int columnIndex) { @@ -152,7 +178,7 @@ public class JcrResultListView extends ViewPart implements SlcNames { return null; try { Node node = (Node) obj; - if(node.hasProperty(SLC_COMPLETED)){ + if (node.hasProperty(SLC_COMPLETED)) { // TODO } return null; @@ -183,22 +209,7 @@ public class JcrResultListView extends ViewPart implements SlcNames { class ViewDoubleClickListener implements IDoubleClickListener { public void doubleClick(DoubleClickEvent evt) { - Object obj = ((IStructuredSelection) evt.getSelection()) - .getFirstElement(); - try { - if (obj instanceof Node) { - Node node = (Node) obj; - if (node.isNodeType(SlcTypes.SLC_PROCESS)) { - IWorkbenchPage activePage = PlatformUI.getWorkbench() - .getActiveWorkbenchWindow().getActivePage(); - activePage.openEditor( - new ProcessEditorInput(node.getPath()), - ProcessEditor.ID); - } - } - } catch (Exception e) { - throw new SlcException("Cannot open " + obj, e); - } + processDoubleClick(evt); } } diff --git a/runtime/org.argeo.slc.support.jcr/src/main/java/org/argeo/slc/jcr/SlcNames.java b/runtime/org.argeo.slc.support.jcr/src/main/java/org/argeo/slc/jcr/SlcNames.java index d41f80cf0..f1ff9c1a8 100644 --- a/runtime/org.argeo.slc.support.jcr/src/main/java/org/argeo/slc/jcr/SlcNames.java +++ b/runtime/org.argeo.slc.support.jcr/src/main/java/org/argeo/slc/jcr/SlcNames.java @@ -26,6 +26,7 @@ public interface SlcNames { // result public final static String SLC_SUCCESS = "slc:success"; public final static String SLC_MESSAGE = "slc:message"; + public final static String SLC_TAG = "slc:tag"; public final static String SLC_ERROR_MESSAGE = "slc:errorMessage"; } diff --git a/runtime/org.argeo.slc.support.jcr/src/main/java/org/argeo/slc/jcr/SlcTypes.java b/runtime/org.argeo.slc.support.jcr/src/main/java/org/argeo/slc/jcr/SlcTypes.java index 9afbb73c2..5996b9331 100644 --- a/runtime/org.argeo.slc.support.jcr/src/main/java/org/argeo/slc/jcr/SlcTypes.java +++ b/runtime/org.argeo.slc.support.jcr/src/main/java/org/argeo/slc/jcr/SlcTypes.java @@ -18,5 +18,6 @@ public interface SlcTypes { public final static String SLC_RESULT = "slc:result"; public final static String SLC_CHECK = "slc:check"; + public final static String SLC_PROPERTY = "slc:property"; } diff --git a/runtime/org.argeo.slc.support.jcr/src/main/java/org/argeo/slc/jcr/execution/JcrResultListener.java b/runtime/org.argeo.slc.support.jcr/src/main/java/org/argeo/slc/jcr/execution/JcrResultListener.java index 7f7244e13..733bac7fb 100644 --- a/runtime/org.argeo.slc.support.jcr/src/main/java/org/argeo/slc/jcr/execution/JcrResultListener.java +++ b/runtime/org.argeo.slc.support.jcr/src/main/java/org/argeo/slc/jcr/execution/JcrResultListener.java @@ -6,14 +6,20 @@ import java.util.HashMap; import java.util.Map; import javax.jcr.Node; +import javax.jcr.NodeIterator; +import javax.jcr.Property; +import javax.jcr.PropertyIterator; import javax.jcr.RepositoryException; import javax.jcr.Session; import javax.jcr.query.Query; +import javax.jcr.query.QueryManager; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.argeo.jcr.JcrUtils; +import org.argeo.slc.SlcException; import org.argeo.slc.core.attachment.Attachment; +import org.argeo.slc.core.structure.SimpleSElement; import org.argeo.slc.core.structure.tree.TreeSPath; import org.argeo.slc.core.test.tree.TreeTestResult; import org.argeo.slc.core.test.tree.TreeTestResultListener; @@ -61,11 +67,25 @@ public class JcrResultListener implements TreeTestResultListener, SlcNames { } // create part node // TODO find a better name - String partNodeName = Long.toString(System.currentTimeMillis()); + SimpleSElement element = null; + if (testResult.getElements().containsKey(currentPath)) { + element = (SimpleSElement) testResult.getElements().get( + currentPath); + } + + String elementLabel = element != null && element.getLabel() != null + && !element.getLabel().trim().equals("") ? element + .getLabel() : null; + String partNodeName = elementLabel != null ? JcrUtils + .replaceInvalidChars(elementLabel, '_') : Long + .toString(System.currentTimeMillis()); + Node resultPartNode = partParentNode.addNode(partNodeName, SlcTypes.SLC_CHECK); resultPartNode.setProperty(SLC_SUCCESS, testResultPart.getStatus() == TestStatus.PASSED); + if (elementLabel != null) + resultPartNode.setProperty(Property.JCR_TITLE, elementLabel); if (testResultPart.getMessage() != null) resultPartNode.setProperty(SLC_MESSAGE, testResultPart.getMessage()); @@ -73,9 +93,28 @@ public class JcrResultListener implements TreeTestResultListener, SlcNames { resultPartNode.setProperty(SLC_ERROR_MESSAGE, testResultPart.getExceptionMessage()); // JcrUtils.debug(resultPartNode); - + JcrUtils.updateLastModified(resultNode); - + + if (element != null) { + element = (SimpleSElement) testResult.getElements().get( + currentPath); + if (log.isTraceEnabled()) + log.trace(" Path= " + currentPath + ", part=" + + testResultPart.getMessage()); + for (Map.Entry tag : element.getTags() + .entrySet()) { + String tagNodeName = JcrUtils.replaceInvalidChars( + tag.getKey(), '_'); + // log.debug("key=" + tag.getKey() + ", tagNodeName=" + // + tagNodeName); + Node tagNode = resultPartNode.addNode(tagNodeName, + SlcTypes.SLC_PROPERTY); + tagNode.setProperty(SLC_NAME, tag.getKey()); + tagNode.setProperty(SLC_VALUE, tag.getValue()); + } + } + session.save(); } catch (RepositoryException e) { JcrUtils.discardQuietly(session); @@ -150,4 +189,62 @@ public class JcrResultListener implements TreeTestResultListener, SlcNames { this.session = session; } + /** + * Creates and populates a {@link TreeTestResult} from the related result + * node. Meant to simplify migration of legacy applications. This is no + * stable API. + */ + public static TreeTestResult nodeToTreeTestResult(Node resultNode) { + try { + String resultPath = resultNode.getPath(); + TreeTestResult ttr = new TreeTestResult(); + // base properties + ttr.setUuid(resultNode.getProperty(SLC_UUID).getString()); + if (resultNode.hasProperty(SLC_COMPLETED)) + ttr.setCloseDate(resultNode.getProperty(SLC_COMPLETED) + .getDate().getTime()); + // attributes + for (PropertyIterator pit = resultNode.getProperties(); pit + .hasNext();) { + Property p = pit.nextProperty(); + if (p.getName().indexOf(':') < 0) { + ttr.getAttributes().put(p.getName(), p.getString()); + } + } + + QueryManager qm = resultNode.getSession().getWorkspace() + .getQueryManager(); + String statement = "SELECT * FROM [" + SlcTypes.SLC_CHECK + + "] WHERE ISDESCENDANTNODE(['" + resultPath + "'])"; + NodeIterator nit = qm.createQuery(statement, Query.JCR_SQL2) + .execute().getNodes(); + while (nit.hasNext()) { + Node checkNode = nit.nextNode(); + String relPath = checkNode.getPath().substring( + resultPath.length()); + TreeSPath tsp = new TreeSPath(relPath); + + // TODO result part + + // element + SimpleSElement elem = new SimpleSElement(); + if (checkNode.hasProperty(Property.JCR_TITLE)) + elem.setLabel(checkNode.getProperty(Property.JCR_TITLE) + .getString()); + else + elem.setLabel("");// some legacy code expect it to be set + for (NodeIterator tagIt = checkNode.getNodes(); tagIt.hasNext();) { + Node tagNode = tagIt.nextNode(); + elem.getTags().put( + tagNode.getProperty(SLC_NAME).getString(), + tagNode.getProperty(SLC_VALUE).getString()); + } + ttr.getElements().put(tsp, elem); + } + return ttr; + } catch (RepositoryException e) { + throw new SlcException("Cannot generate tree test result from " + + resultNode, e); + } + } } diff --git a/runtime/org.argeo.slc.support.jcr/src/main/resources/org/argeo/slc/jcr/slc.cnd b/runtime/org.argeo.slc.support.jcr/src/main/resources/org/argeo/slc/jcr/slc.cnd index cb88e5504..d644de3ca 100644 --- a/runtime/org.argeo.slc.support.jcr/src/main/resources/org/argeo/slc/jcr/slc.cnd +++ b/runtime/org.argeo.slc.support.jcr/src/main/resources/org/argeo/slc/jcr/slc.cnd @@ -75,10 +75,14 @@ mixin - slc:uuid (STRING) ! m - slc:completed (DATE) -[slc:check] > nt:unstructured, mix:created +[slc:check] > nt:unstructured // true for PASSED, false for FAILED or ERROR - slc:success (BOOLEAN) ! m - slc:message (STRING) // ERROR if set, the check could not be performed because of an unexpected exception - slc:errorMessage (STRING) ++ * (slc:property) * +[slc:property] > nt:unstructured +- slc:name (STRING) ! m +- slc:value (STRING) m -- 2.39.2