]> git.argeo.org Git - gpl/argeo-slc.git/commitdiff
Improve RCP
authorMathieu Baudier <mbaudier@argeo.org>
Mon, 2 May 2011 15:32:07 +0000 (15:32 +0000)
committerMathieu Baudier <mbaudier@argeo.org>
Mon, 2 May 2011 15:32:07 +0000 (15:32 +0000)
git-svn-id: https://svn.argeo.org/slc/trunk@4492 4cfe0d0a-d680-48aa-b62c-e0a02a3f76cc

12 files changed:
eclipse/plugins/org.argeo.slc.client.rcp/META-INF/MANIFEST.MF
eclipse/plugins/org.argeo.slc.client.rcp/plugin.xml
eclipse/plugins/org.argeo.slc.client.rcp/src/main/java/org/argeo/slc/client/rcp/ApplicationActionBarAdvisor.java [deleted file]
eclipse/plugins/org.argeo.slc.client.rcp/src/main/java/org/argeo/slc/client/rcp/SlcSecureWorkbenchWindowAdvisor.java
eclipse/plugins/org.argeo.slc.client.rcp/src/main/java/org/argeo/slc/client/rcp/commands/ExitHandler.java [deleted file]
eclipse/plugins/org.argeo.slc.client.ui/plugin.xml
eclipse/plugins/org.argeo.slc.client.ui/src/main/java/org/argeo/slc/client/ui/views/JcrExecutionModulesView.java
eclipse/plugins/org.argeo.slc.client.ui/src/main/java/org/argeo/slc/client/ui/views/JcrResultListView.java
runtime/org.argeo.slc.support.jcr/src/main/java/org/argeo/slc/jcr/SlcNames.java
runtime/org.argeo.slc.support.jcr/src/main/java/org/argeo/slc/jcr/SlcTypes.java
runtime/org.argeo.slc.support.jcr/src/main/java/org/argeo/slc/jcr/execution/JcrResultListener.java
runtime/org.argeo.slc.support.jcr/src/main/resources/org/argeo/slc/jcr/slc.cnd

index 304491516e29e3eb519b88ee4362d6e96f33458a..0d00d903f831949212de137200a2f223da176a16 100644 (file)
@@ -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
index dc5ca4392c42eece2236b0c23b5686ab2ed594d7..3cc0f922a3690d555ef1865ed05b5cf103abef03 100644 (file)
            sequence="CTRL+R">
      </key>
   </extension>
-   <extension
-         id="product"
-         point="org.eclipse.core.runtime.products">
-      <product
-            application="org.argeo.slc.client.rcp.application"
-            name="SLC">
-         <property
-               name="windowImages"
-               value="icons/argeo-icon-256.png">
-         </property>
-         <property
-               name="appName"
-               value="SLC">
-         </property>
-      </product>
-   </extension>
 </plugin>
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 (file)
index 5f013ce..0000000
+++ /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) {
-       }
-
-}
index 1cfd3ddd161bed7dfb08eb415e14f22f2de23a75..d83f8c9ead86249317491d21dfc828a24b040f09 100644 (file)
@@ -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 (file)
index 0b59373..0000000
+++ /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;
-       }
-
-}
index 01b2efc3cc4d5c343947cc35bc0df96a8475aadc..d066fe2d28992f75f5a232995ad6036fc1123412 100644 (file)
@@ -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">
           </view>
           <view
index e5696ee9e652a8a10d3ae346e7377e4e4eab502c..d87be4f29f90cfab9f9a8fcf52218fd6dfe16963 100644 (file)
@@ -3,6 +3,7 @@ package org.argeo.slc.client.ui.views;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Comparator;
+import java.util.Iterator;
 import java.util.List;
 
 import javax.jcr.Node;
@@ -125,6 +126,17 @@ public class JcrExecutionModulesView extends ViewPart implements SlcTypes,
                        Arrays.sort(sorted, new ViewComparator());
                        return sorted;
                }
+
+               @Override
+               protected List<Node> filterChildren(List<Node> children)
+                               throws RepositoryException {
+                       for (Iterator<Node> 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<Object> {
index a886e050cd45a62bed707649a82f74dce3fff319..3a05f08637ed2474f6a092294401b2854e27040c 100644 (file)
@@ -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);
                }
 
        }
index d41f80cf0537846902369de86833dc6b2e5fa207..f1ff9c1a80f7c0c0e6cbd45a42a61eaab3dc0f28 100644 (file)
@@ -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";
 
 }
index 9afbb73c23da357c8a6d36158b8b07f95071ba1a..5996b9331ea7d9108fcc64619d4aac8f8746eed3 100644 (file)
@@ -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";
 
 }
index 7f7244e13ac31f2327ca90b32ebdd44c10bf4be7..733bac7fbbd2cfbc0b1ecbf4448fab06c6f5e70d 100644 (file)
@@ -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<String, String> 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);
+               }
+       }
 }
index cb88e55046e6ed5ccf9f2b9a5811d2341ab967bf..d644de3ca63177e54f584600270b0fa6e146015c 100644 (file)
@@ -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