From: Bruno Sinou Date: Thu, 8 Nov 2012 18:54:35 +0000 (+0000) Subject: + Fix some bugs on ResultTree Observer X-Git-Tag: argeo-slc-2.1.7~551 X-Git-Url: http://git.argeo.org/?a=commitdiff_plain;h=3529ae56c3bafe8c21e7014d54788ea6fb86f73e;p=gpl%2Fargeo-slc.git + Fix some bugs on ResultTree Observer + optimize cnd for the UI + some cleaning git-svn-id: https://svn.argeo.org/slc/trunk@5757 4cfe0d0a-d680-48aa-b62c-e0a02a3f76cc --- diff --git a/plugins/org.argeo.slc.client.ui/plugin.xml b/plugins/org.argeo.slc.client.ui/plugin.xml index 85f5bf4b5..a3f9e70f8 100644 --- a/plugins/org.argeo.slc.client.ui/plugin.xml +++ b/plugins/org.argeo.slc.client.ui/plugin.xml @@ -43,6 +43,11 @@ id="org.argeo.slc.client.ui.addResultFolder" name="Add result folder"> + + lst = ((IStructuredSelection) selection).iterator(); + while (lst.hasNext()) { + Object obj = lst.next(); + if (obj instanceof ResultParent) { + ResultParent rp = ((ResultParent) obj); + buf.append(rp.getName()).append(", "); + } + } + + String msg = "Nothing to delete"; + // remove last separator + if (buf.lastIndexOf(", ") > -1) { + msg = "Do you want to delete following objects: " + + buf.substring(0, buf.lastIndexOf(", ")) + "?"; + } + Boolean ok = MessageDialog.openConfirm( + HandlerUtil.getActiveShell(event), "Confirm deletion", msg); + + if (!ok) + return null; + + Job job = new Job("Delete results") { + @Override + protected IStatus run(IProgressMonitor monitor) { + if (selection != null + && selection instanceof IStructuredSelection) { + List nodes = new ArrayList(); + Iterator it = ((IStructuredSelection) selection) + .iterator(); + Object obj = null; + while (it.hasNext()) { + obj = it.next(); + if (obj instanceof ResultFolder) { + Node node = ((ResultFolder) obj).getNode(); + nodes.add(node); + } else if (obj instanceof SingleResultNode) { + Node node = ((SingleResultNode) obj).getNode(); + nodes.add(node); + } + } + try { + if (!nodes.isEmpty()) { + Session session = nodes.get(0).getSession(); + monitor.beginTask("Delete results", nodes.size()); + for (Node node : nodes) { + Node parent = node.getParent(); + node.remove(); + ResultParentUtils.updateStatusOnRemoval(parent); + monitor.worked(1); + } + session.save(); + } + + } catch (RepositoryException e) { + throw new SlcException( + "Unexpected error while deleteting node(s)", e); + } + monitor.done(); + } + return Status.OK_STATUS; + } + + }; + job.setUser(true); + job.schedule(); + return null; + } +} diff --git a/plugins/org.argeo.slc.client.ui/src/main/java/org/argeo/slc/client/ui/commands/DeleteResult.java b/plugins/org.argeo.slc.client.ui/src/main/java/org/argeo/slc/client/ui/commands/DeleteResult.java deleted file mode 100644 index 5e4636870..000000000 --- a/plugins/org.argeo.slc.client.ui/src/main/java/org/argeo/slc/client/ui/commands/DeleteResult.java +++ /dev/null @@ -1,132 +0,0 @@ -/* - * 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.commands; - -import java.util.ArrayList; -import java.util.Iterator; -import java.util.List; - -import javax.jcr.Node; -import javax.jcr.RepositoryException; -import javax.jcr.Session; - -import org.argeo.eclipse.ui.ErrorFeedback; -import org.argeo.slc.client.ui.model.ResultFolder; -import org.argeo.slc.client.ui.model.ResultParent; -import org.argeo.slc.client.ui.model.ResultParentUtils; -import org.argeo.slc.client.ui.model.SingleResultNode; -import org.eclipse.core.commands.AbstractHandler; -import org.eclipse.core.commands.ExecutionEvent; -import org.eclipse.core.commands.ExecutionException; -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.dialogs.MessageDialog; -import org.eclipse.jface.viewers.ISelection; -import org.eclipse.jface.viewers.IStructuredSelection; -import org.eclipse.ui.handlers.HandlerUtil; - -/** Deletes one or many results */ -public class DeleteResult extends AbstractHandler { - /* DEPENDENCY INJECTION */ - private Session session; - - public Object execute(final ExecutionEvent event) throws ExecutionException { - final ISelection selection = HandlerUtil - .getActiveWorkbenchWindow(event).getActivePage().getSelection(); - - // confirmation - StringBuffer buf = new StringBuffer(""); - Iterator lst = ((IStructuredSelection) selection).iterator(); - while (lst.hasNext()) { - Object obj = lst.next(); - if (obj instanceof ResultParent) { - ResultParent rp = ((ResultParent) obj); - buf.append(rp.getName()).append(", "); - } - - } - - String msg = "Nothing to delete"; - // remove last separator - if (buf.lastIndexOf(", ") > -1) { - msg = "Do you want to delete following objects: " - + buf.substring(0, buf.lastIndexOf(", ")) + "?"; - } - Boolean ok = MessageDialog.openConfirm( - HandlerUtil.getActiveShell(event), "Confirm deletion", msg); - - if (!ok) - return null; - - Job job = new Job("Delete results") { - @Override - protected IStatus run(IProgressMonitor monitor) { - if (selection != null - && selection instanceof IStructuredSelection) { - List nodes = new ArrayList(); - Iterator it = ((IStructuredSelection) selection) - .iterator(); - Object obj = null; - try { - while (it.hasNext()) { - obj = it.next(); - if (obj instanceof ResultFolder) { - Node node = ((ResultFolder) obj).getNode(); - nodes.add(node.getPath()); - } else if (obj instanceof SingleResultNode) { - Node node = ((SingleResultNode) obj).getNode(); - nodes.add(node.getPath()); - } - } - } catch (RepositoryException e) { - ErrorFeedback.show("Cannot list nodes", e); - return null; - } - monitor.beginTask("Delete results", nodes.size()); - Node node = null; - try { - for (final String path : nodes) { - if (session.itemExists(path)) { - node = session.getNode(path); - Node parent = node.getParent(); - node.remove(); - ResultParentUtils.updateStatusOnRemoval(parent); - } - monitor.worked(1); - } - session.save(); - } catch (RepositoryException e) { - ErrorFeedback.show("Cannot delete node " + node, e); - } - monitor.done(); - } - return Status.OK_STATUS; - } - - }; - job.setUser(true); - job.schedule(); - return null; - } - - /* DEPENDENCY INJECTION */ - public void setSession(Session session) { - this.session = session; - } -} diff --git a/plugins/org.argeo.slc.client.ui/src/main/java/org/argeo/slc/client/ui/model/ParentNodeFolder.java b/plugins/org.argeo.slc.client.ui/src/main/java/org/argeo/slc/client/ui/model/ParentNodeFolder.java index 85da2632e..a58068fa5 100644 --- a/plugins/org.argeo.slc.client.ui/src/main/java/org/argeo/slc/client/ui/model/ParentNodeFolder.java +++ b/plugins/org.argeo.slc.client.ui/src/main/java/org/argeo/slc/client/ui/model/ParentNodeFolder.java @@ -21,12 +21,12 @@ import javax.jcr.RepositoryException; import javax.jcr.nodetype.NodeType; import org.argeo.slc.SlcException; -import org.argeo.slc.jcr.SlcJcrResultUtils; import org.argeo.slc.jcr.SlcNames; import org.argeo.slc.jcr.SlcTypes; /** - * UI Tree component that wrap a node of type NT_UNSTRUCTURED. + * UI Tree component that wrap a node of type NT_UNSTRUCTURED or base node for + * UI specific, user defined tree structure of type SLC_MY_RESULTS_ROOT_FOLDER. * * It is used for *
    @@ -104,8 +104,7 @@ public class ParentNodeFolder extends ResultParent { public synchronized Object[] getChildren() { Object[] children = super.getChildren(); try { - if (node.getPath().equals( - SlcJcrResultUtils.getMyResultsBasePath(node.getSession()))) + if (node.isNodeType(SlcTypes.SLC_MY_RESULT_ROOT_FOLDER)) return ResultParentUtils.orderChildren(children); else return children; diff --git a/plugins/org.argeo.slc.client.ui/src/main/java/org/argeo/slc/client/ui/model/ResultParent.java b/plugins/org.argeo.slc.client.ui/src/main/java/org/argeo/slc/client/ui/model/ResultParent.java index 0e4899c71..eff41cf34 100644 --- a/plugins/org.argeo.slc.client.ui/src/main/java/org/argeo/slc/client/ui/model/ResultParent.java +++ b/plugins/org.argeo.slc.client.ui/src/main/java/org/argeo/slc/client/ui/model/ResultParent.java @@ -28,7 +28,6 @@ public abstract class ResultParent extends TreeParent { } private boolean isPassed = true; - private boolean isDisposed = false; protected synchronized void setPassed(boolean isPassed) { this.isPassed = isPassed; @@ -40,17 +39,15 @@ public abstract class ResultParent extends TreeParent { @Override public synchronized boolean hasChildren() { - // sometimes in UI, disposed objects are still called. - if (isDisposed) - return false; + // only initialize when needed : correctly called by the jface framework if (!isLoaded()) initialize(); return super.hasChildren(); } public void forceFullRefresh() { - if (isDisposed) - return; + // if (isDisposed) + // return; if (hasChildren()) clearChildren(); initialize(); @@ -58,9 +55,7 @@ public abstract class ResultParent extends TreeParent { public synchronized void dispose() { super.dispose(); - isDisposed = true; } protected abstract void initialize(); - } diff --git a/plugins/org.argeo.slc.client.ui/src/main/java/org/argeo/slc/client/ui/model/ResultParentUtils.java b/plugins/org.argeo.slc.client.ui/src/main/java/org/argeo/slc/client/ui/model/ResultParentUtils.java index e16bdc195..2e3dcb0df 100644 --- a/plugins/org.argeo.slc.client.ui/src/main/java/org/argeo/slc/client/ui/model/ResultParentUtils.java +++ b/plugins/org.argeo.slc.client.ui/src/main/java/org/argeo/slc/client/ui/model/ResultParentUtils.java @@ -53,7 +53,7 @@ public class ResultParentUtils { return orderedChildren; } - public static ResultParent[] getResultsForDates(Session session, + public static List getResultsForDates(Session session, List dateRelPathes) { if (dateRelPathes == null || dateRelPathes.size() == 0) throw new SlcException("Specify at least one correct date as Path"); @@ -84,18 +84,11 @@ public class ResultParentUtils { QueryResult result = q.execute(); NodeIterator ni = result.getNodes(); - ResultParent[] results = new ResultParent[(int) ni.getSize()]; - int i = 0; + List nodes = new ArrayList(); while (ni.hasNext()) { - Node currNode = ni.nextNode(); - SingleResultNode srn = new SingleResultNode(null, currNode, - currNode.getProperty(SlcNames.SLC_TEST_CASE) - .getString()); - - results[i] = srn; - i++; + nodes.add(ni.nextNode()); } - return results; + return nodes; } catch (RepositoryException re) { throw new SlcException( "Unexpected error while getting Results for given date", re); @@ -194,7 +187,8 @@ public class ResultParentUtils { return; } } catch (RepositoryException e) { - throw new SlcException("Unexpected error while updating status on removal", e); + throw new SlcException( + "Unexpected error while updating status on removal", e); } } diff --git a/plugins/org.argeo.slc.client.ui/src/main/java/org/argeo/slc/client/ui/model/VirtualFolder.java b/plugins/org.argeo.slc.client.ui/src/main/java/org/argeo/slc/client/ui/model/VirtualFolder.java index 5a6bc77ce..e212a741d 100644 --- a/plugins/org.argeo.slc.client.ui/src/main/java/org/argeo/slc/client/ui/model/VirtualFolder.java +++ b/plugins/org.argeo.slc.client.ui/src/main/java/org/argeo/slc/client/ui/model/VirtualFolder.java @@ -15,35 +15,45 @@ */ package org.argeo.slc.client.ui.model; +import java.util.List; + +import javax.jcr.Node; +import javax.jcr.RepositoryException; + +import org.argeo.slc.SlcException; +import org.argeo.slc.jcr.SlcNames; +import org.argeo.slc.jcr.SlcTypes; + /** - * UI Tree component. Virtual folder to list either other folders and/or a list - * of results. Keeps a reference to its parent that might be null if the . + * UI Tree component. Virtual folder to list a list of results. Keeps a + * reference to its parent that might be null. It also keeps a reference to all + * nodes that must be displayed as children of the current virtual folder. */ public class VirtualFolder extends ResultParent { - ResultParent[] children; + List displayedNodes; - public VirtualFolder(VirtualFolder parent, ResultParent[] children, + public VirtualFolder(VirtualFolder parent, List displayedNodes, String name) { super(name); setParent(parent); - this.children = children; - } - - @Override - public synchronized void dispose() { - super.dispose(); + this.displayedNodes = displayedNodes; } @Override protected void initialize() { - if (children != null) - for (ResultParent child : children) - addChild(child); - } - - public void resetChildren(ResultParent[] children) { - clearChildren(); - this.children = children; - initialize(); + try { + for (Node currNode : displayedNodes) { + if (currNode.isNodeType(SlcTypes.SLC_TEST_RESULT)) { + SingleResultNode srn = new SingleResultNode(this, currNode, + currNode.getProperty(SlcNames.SLC_TEST_CASE) + .getString()); + addChild(srn); + } + } + } catch (RepositoryException re) { + throw new SlcException( + "Unexpected error while initializing ParentNodeFolder : " + + getName(), re); + } } } \ No newline at end of file diff --git a/plugins/org.argeo.slc.client.ui/src/main/java/org/argeo/slc/client/ui/views/JcrResultTreeView.java b/plugins/org.argeo.slc.client.ui/src/main/java/org/argeo/slc/client/ui/views/JcrResultTreeView.java index e1a5759ef..57ea55eb6 100644 --- a/plugins/org.argeo.slc.client.ui/src/main/java/org/argeo/slc/client/ui/views/JcrResultTreeView.java +++ b/plugins/org.argeo.slc.client.ui/src/main/java/org/argeo/slc/client/ui/views/JcrResultTreeView.java @@ -1,6 +1,5 @@ package org.argeo.slc.client.ui.views; -import java.awt.Window; import java.util.ArrayList; import java.util.Calendar; import java.util.List; @@ -142,6 +141,8 @@ public class JcrResultTreeView extends ViewPart { sashForm.setWeights(getWeights()); + resultTreeViewer.setInput(initializeResultTree()); + // Initialize observer try { ObservationManager observationManager = session.getWorkspace() .getObservationManager(); @@ -154,9 +155,6 @@ public class JcrResultTreeView extends ViewPart { } catch (RepositoryException e) { throw new SlcException("Cannot register listeners", e); } - - // Refresh the view to initialize it - refresh(null); } // The main tree viewer @@ -308,8 +306,8 @@ public class JcrResultTreeView extends ViewPart { * */ public void refresh(ResultParent resultParent) { - if (log.isDebugEnabled()) - log.debug("Refreshing '" + resultParent + "'..."); + // if (log.isDebugEnabled()) + // log.debug("Refreshing '" + resultParent + "'..."); // Thread.dumpStack(); if (resultParent == null) { resultTreeViewer.setInput(initializeResultTree()); @@ -335,8 +333,9 @@ public class JcrResultTreeView extends ViewPart { * */ public boolean jcrRefresh(Node node) { - if (log.isDebugEnabled()) - log.debug(" JCR refreshing " + node + "..."); + // if (log.isDebugEnabled()) + // log.debug(" JCR refreshing " + node + "..."); + // Thread.dumpStack(); boolean isPassed = true; try { if (node.isNodeType(SlcTypes.SLC_TEST_RESULT)) { @@ -368,56 +367,54 @@ public class JcrResultTreeView extends ViewPart { private ResultParent[] initializeResultTree() { try { - if (session.nodeExists(SlcJcrResultUtils - .getSlcResultsBasePath(session))) { - ResultParent[] roots = new ResultParent[5]; - - // My results - roots[0] = new ParentNodeFolder(null, - SlcJcrResultUtils.getMyResultParentNode(session), - SlcUiConstants.DEFAULT_MY_RESULTS_FOLDER_LABEL); - - // today - Calendar cal = Calendar.getInstance(); - String relPath = JcrUtils.dateAsPath(cal); - List datePathes = new ArrayList(); - datePathes.add(relPath); - roots[1] = new VirtualFolder(null, - ResultParentUtils.getResultsForDates(session, - datePathes), "Today"); - - // Yesterday - cal = Calendar.getInstance(); - cal.add(Calendar.DAY_OF_YEAR, -1); + // Force initialization of the tree structure if needed + SlcJcrResultUtils.getSlcResultsParentNode(session); + SlcJcrResultUtils.getMyResultParentNode(session); + ResultParent[] roots = new ResultParent[5]; + + // My results + roots[0] = new ParentNodeFolder(null, + SlcJcrResultUtils.getMyResultParentNode(session), + SlcUiConstants.DEFAULT_MY_RESULTS_FOLDER_LABEL); + + // today + Calendar cal = Calendar.getInstance(); + String relPath = JcrUtils.dateAsPath(cal); + List datePathes = new ArrayList(); + datePathes.add(relPath); + roots[1] = new VirtualFolder(null, + ResultParentUtils.getResultsForDates(session, datePathes), + "Today"); + + // Yesterday + cal = Calendar.getInstance(); + cal.add(Calendar.DAY_OF_YEAR, -1); + relPath = JcrUtils.dateAsPath(cal); + datePathes = new ArrayList(); + datePathes.add(relPath); + roots[2] = new VirtualFolder(null, + ResultParentUtils.getResultsForDates(session, datePathes), + "Yesterday"); + // Last 7 days + + cal = Calendar.getInstance(); + datePathes = new ArrayList(); + + for (int i = 0; i < 7; i++) { + cal.add(Calendar.DAY_OF_YEAR, -i); relPath = JcrUtils.dateAsPath(cal); - datePathes = new ArrayList(); datePathes.add(relPath); - roots[2] = new VirtualFolder(null, - ResultParentUtils.getResultsForDates(session, - datePathes), "Yesterday"); - // Last 7 days - - cal = Calendar.getInstance(); - datePathes = new ArrayList(); - - for (int i = 0; i < 7; i++) { - cal.add(Calendar.DAY_OF_YEAR, -i); - relPath = JcrUtils.dateAsPath(cal); - datePathes.add(relPath); - } - roots[3] = new VirtualFolder(null, - ResultParentUtils.getResultsForDates(session, - datePathes), "Last 7 days"); - - // All results - Node otherResultsPar = session.getNode(SlcJcrResultUtils - .getSlcResultsBasePath(session)); - roots[4] = new ParentNodeFolder(null, otherResultsPar, - "All results"); - return roots; - } else - // no test has yet been processed, we leave the viewer blank - return null; + } + roots[3] = new VirtualFolder(null, + ResultParentUtils.getResultsForDates(session, datePathes), + "Last 7 days"); + + // All results + Node otherResultsPar = session.getNode(SlcJcrResultUtils + .getSlcResultsBasePath(session)); + roots[4] = new ParentNodeFolder(null, otherResultsPar, + "All results"); + return roots; } catch (RepositoryException re) { throw new ArgeoException( "Unexpected error while initializing ResultTree.", re); @@ -432,27 +429,27 @@ public class JcrResultTreeView extends ViewPart { IWorkbenchWindow window = ClientUiPlugin.getDefault().getWorkbench() .getActiveWorkbenchWindow(); - // Building conditions IStructuredSelection selection = (IStructuredSelection) resultTreeViewer .getSelection(); boolean canAddSubfolder = false; + boolean canRenamefolder = false; boolean isSingleResultNode = false; + // Building conditions if (selection.size() == 1) { Object obj = selection.getFirstElement(); try { - // if (obj instanceof ResultFolder - // && (((ResultFolder) obj).getNode()) - // .isNodeType(SlcTypes.SLC_RESULT_FOLDER)) - if (isResultFolder) - canAddSubfolder = true; - else if (obj instanceof SingleResultNode) + if (obj instanceof SingleResultNode) isSingleResultNode = true; - else if (obj instanceof ParentNodeFolder - && (((ParentNodeFolder) obj).getNode().getPath() - .startsWith(SlcJcrResultUtils - .getMyResultsBasePath(session)))) - canAddSubfolder = true; - + else if (obj instanceof ParentNodeFolder) { + Node cNode = ((ParentNodeFolder) obj).getNode(); + if (cNode.isNodeType(SlcTypes.SLC_RESULT_FOLDER)) { + canAddSubfolder = true; + canRenamefolder = true; + } else if (cNode + .isNodeType(SlcTypes.SLC_MY_RESULT_ROOT_FOLDER)) { + canAddSubfolder = true; + } + } } catch (RepositoryException re) { throw new SlcException( "unexpected error while building condition for context menu", @@ -468,7 +465,7 @@ public class JcrResultTreeView extends ViewPart { CommandUtils.refreshCommand(menuManager, window, RenameResultFolder.ID, RenameResultFolder.DEFAULT_LABEL, - RenameResultFolder.DEFAULT_IMG_DESCRIPTOR, canAddSubfolder); + RenameResultFolder.DEFAULT_IMG_DESCRIPTOR, canRenamefolder); CommandUtils.refreshCommand(menuManager, window, RenameResultNode.ID, RenameResultNode.DEFAULT_LABEL, @@ -545,39 +542,41 @@ public class JcrResultTreeView extends ViewPart { @Override public boolean validateDrop(Object target, int operation, TransferData transferType) { - boolean validDrop = false; try { // We can only drop under myResults Node tpNode = null; - if (target instanceof ResultFolder) { + if (target instanceof SingleResultNode) { + Node currNode = ((SingleResultNode) target).getNode(); + String pPath = currNode.getParent().getPath(); + if (pPath.startsWith(SlcJcrResultUtils + .getMyResultsBasePath(session))) + tpNode = currNode.getParent(); + } else if (target instanceof ResultFolder) { tpNode = ((ResultFolder) target).getNode(); } else if (target instanceof ParentNodeFolder) { - if ((((ParentNodeFolder) target).getNode().getPath() - .startsWith(SlcJcrResultUtils - .getMyResultsBasePath(session)))) + Node node = ((ParentNodeFolder) target).getNode(); + if (node.isNodeType(SlcTypes.SLC_MY_RESULT_ROOT_FOLDER)) tpNode = ((ParentNodeFolder) target).getNode(); - } else if (target instanceof SingleResultNode) { - Node currNode = ((SingleResultNode) target).getNode(); - if (currNode - .getParent() - .getPath() - .startsWith( - SlcJcrResultUtils - .getMyResultsBasePath(session))) - tpNode = currNode.getParent(); } if (tpNode != null) { // Sanity check : we cannot move a folder to one of its sub + // folder or neither move an object in the same parent // folder boolean doit = true; + Node source = null; if (isResultFolder) { - Node source = ((ParentNodeFolder) lastSelectedSourceElement) + source = ((ParentNodeFolder) lastSelectedSourceElement) .getNode(); - String sourcePath = source.getPath(); - String targetPath = tpNode.getPath(); - if (targetPath.startsWith(sourcePath)) + if (tpNode.getPath().startsWith(source.getPath())) + doit = false; + } else if (lastSelectedSourceElement instanceof SingleResultNode) { + source = ((SingleResultNode) lastSelectedSourceElement) + .getNode(); + String sourceParentPath = JcrUtils.parentPath(source + .getPath()); + if (tpNode.getPath().equals(sourceParentPath)) doit = false; } if (doit) { @@ -586,7 +585,6 @@ public class JcrResultTreeView extends ViewPart { lastSelectedTargetElement = (ResultParent) target; } } - } catch (RepositoryException re) { throw new SlcException( "unexpected error while validating drop target", re); @@ -616,7 +614,7 @@ public class JcrResultTreeView extends ViewPart { name, targetParentNode); WizardDialog dialog = new WizardDialog(Display.getDefault() .getActiveShell(), wizard); - + if (dialog.open() == WizardDialog.CANCEL) return true; @@ -671,40 +669,43 @@ public class JcrResultTreeView extends ViewPart { protected void onEventInUiThread(List events) throws RepositoryException { - int i = 0; - - for (Event event : events) { - i++; - // if (log.isDebugEnabled()) - // log.debug("Received event " + event); - int eventType = event.getType(); - if (eventType == Event.NODE_REMOVED) { - String path = event.getPath(); - String parPath = JcrUtils.parentPath(path); - if (session.nodeExists(parPath)) { - Node currNode = session.getNode(parPath); - if (currNode.isNodeType(NodeType.NT_UNSTRUCTURED)) { - // jcrRefresh(currNode); - refresh(lastSelectedSourceElementParent); - } - } - } else if (eventType == Event.NODE_ADDED) { - // refresh(lastSelectedTargetElement); - String path = event.getPath(); - if (session.nodeExists(path)) { - Node currNode = session.getNode(path); - if (currNode.isNodeType(SlcTypes.SLC_TEST_RESULT) - || currNode - .isNodeType(SlcTypes.SLC_RESULT_FOLDER)) { - refresh(lastSelectedTargetElement); - // resultTreeViewer.expandToLevel( - // lastSelectedTargetElement, 1); - } - } - } - } - if (log.isDebugEnabled()) - log.debug("treated events: " + i); + refresh(lastSelectedSourceElementParent); + + // boolean wasRemoved = false; + // boolean wasAdded = false; + // + // for (Event event : events) { + // // if (log.isDebugEnabled()) + // // log.debug("Received event " + event); + // int eventType = event.getType(); + // if (eventType == Event.NODE_REMOVED) { + // String path = event.getPath(); + // String parPath = JcrUtils.parentPath(path); + // if (session.nodeExists(parPath)) { + // Node currNode = session.getNode(parPath); + // if (currNode.isNodeType(NodeType.NT_UNSTRUCTURED)) { + // // jcrRefresh(currNode); + // wasRemoved = true; + // } + // } + // } else if (eventType == Event.NODE_ADDED) { + // // refresh(lastSelectedTargetElement); + // String path = event.getPath(); + // if (session.nodeExists(path)) { + // Node currNode = session.getNode(path); + // if (currNode.isNodeType(SlcTypes.SLC_TEST_RESULT) + // || currNode + // .isNodeType(SlcTypes.SLC_RESULT_FOLDER)) { + // // refresh(lastSelectedTargetElement); + // wasAdded = true; + // // resultTreeViewer.expandToLevel( + // // lastSelectedTargetElement, 1); + // } + // } + // } + // } + // if (wasRemoved || wasAdded) + // refresh(lastSelectedSourceElementParent); } } diff --git a/runtime/org.argeo.slc.support.jcr/src/main/java/org/argeo/slc/jcr/SlcJcrResultUtils.java b/runtime/org.argeo.slc.support.jcr/src/main/java/org/argeo/slc/jcr/SlcJcrResultUtils.java index ba54c1378..e82bd4a3f 100644 --- a/runtime/org.argeo.slc.support.jcr/src/main/java/org/argeo/slc/jcr/SlcJcrResultUtils.java +++ b/runtime/org.argeo.slc.support.jcr/src/main/java/org/argeo/slc/jcr/SlcJcrResultUtils.java @@ -47,6 +47,38 @@ public class SlcJcrResultUtils { } } + /** + * Returns the base node to store SlcResults. If it does not exists, it is + * created. If a node already exists at the given path with the wrong type, + * it throws an exception. + * + * @param session + * @return + */ + public static Node getSlcResultsParentNode(Session session) { + try { + String absPath = getSlcResultsBasePath(session); + if (session.nodeExists(absPath)) { + Node currNode = session.getNode(absPath); + if (currNode.isNodeType(NodeType.NT_UNSTRUCTURED)) + return currNode; + else + throw new SlcException( + "A node already exists at this path : " + absPath + + " that has the wrong type. "); + } else { + Node slcResParNode = JcrUtils.mkdirs(session, absPath); + slcResParNode.setPrimaryType(NodeType.NT_UNSTRUCTURED); + session.save(); + return slcResParNode; + } + } catch (RepositoryException re) { + throw new SlcException( + "Unexpected error while creating slcResult root parent node.", + re); + } + } + /** * Returns the path to the current Result UI specific node, depending the * current user @@ -66,9 +98,9 @@ public class SlcJcrResultUtils { } /** - * Creates a new node with type NodeType.NT_UNSTRUCTURED at the given - * absolute path. If a node already exists at the given path, returns that - * node if it has the correct type and throws an exception otherwise. + * Creates a new node with type SlcTypes.SLC_MY_RESULT_ROOT_FOLDER at the + * given absolute path. If a node already exists at the given path, returns + * that node if it has the correct type and throws an exception otherwise. * * @param session * @return @@ -78,7 +110,7 @@ public class SlcJcrResultUtils { String absPath = getMyResultsBasePath(session); if (session.nodeExists(absPath)) { Node currNode = session.getNode(absPath); - if (currNode.isNodeType(NodeType.NT_UNSTRUCTURED)) + if (currNode.isNodeType(SlcTypes.SLC_MY_RESULT_ROOT_FOLDER)) return currNode; else throw new SlcException( @@ -86,7 +118,7 @@ public class SlcJcrResultUtils { + " that has the wrong type. "); } else { Node myResParNode = JcrUtils.mkdirs(session, absPath); - myResParNode.setPrimaryType(NodeType.NT_UNSTRUCTURED); + myResParNode.setPrimaryType(SlcTypes.SLC_MY_RESULT_ROOT_FOLDER); session.save(); return myResParNode; } diff --git a/runtime/org.argeo.slc.support.jcr/src/main/java/org/argeo/slc/jcr/SlcJcrUtils.java b/runtime/org.argeo.slc.support.jcr/src/main/java/org/argeo/slc/jcr/SlcJcrUtils.java index 8e78d7fcd..7267b58ea 100644 --- a/runtime/org.argeo.slc.support.jcr/src/main/java/org/argeo/slc/jcr/SlcJcrUtils.java +++ b/runtime/org.argeo.slc.support.jcr/src/main/java/org/argeo/slc/jcr/SlcJcrUtils.java @@ -90,7 +90,7 @@ public class SlcJcrUtils implements SlcNames { + JcrUtils.dateAsPath(now, true) + uuid; } - /** GEt the base for the user processeses. */ + /** Get the base for the user processi. */ public static String getSlcProcessesBasePath(Session session) { try { Node userHome = UserJcrUtils.getUserHome(session); 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 25f830d97..76f56fe3e 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 @@ -35,6 +35,9 @@ public interface SlcTypes { public final static String SLC_CHECK = "slc:check"; public final static String SLC_PROPERTY = "slc:property"; public final static String SLC_DIFF_RESULT = "slc:diffResult"; + + // Node types used for user defined and managed result UI tree + public final static String SLC_MY_RESULT_ROOT_FOLDER = "slc:myResultRootFolder"; public final static String SLC_RESULT_FOLDER = "slc:resultFolder"; // Log levels 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 f527902cb..96439ca60 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 @@ -110,6 +110,12 @@ mixin + * (slc:resultFolder) * + * (slc:testResult) * +// base node for user defined and managed result tree +// simplify UI management +[slc:myResultRootFolder] > nt:unstructured ++ * (slc:resultFolder) * ++ * (slc:testResult) * + [slc:check] > nt:unstructured // true for PASSED, false for FAILED or ERROR - slc:success (BOOLEAN) ! m