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%2FJcrResultTreeView.java;h=c0e750187bd4db39d2a8c2cee0aef5328042cc99;hb=0d236262a853a1286b317c30d64d4692bc21c7a4;hp=e1a5759eff3d92d3257a9998ad409893838e999d;hpb=30d79020a5436aced32f7744d9d07444d6297925;p=gpl%2Fargeo-slc.git 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..c0e750187 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,30 +1,41 @@ +/* + * 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. + * 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.views; -import java.awt.Window; +import java.text.DateFormat; +import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Calendar; +import java.util.Iterator; import java.util.List; import javax.jcr.Node; import javax.jcr.NodeIterator; import javax.jcr.Property; -import javax.jcr.PropertyIterator; -import javax.jcr.PropertyType; import javax.jcr.RepositoryException; import javax.jcr.Session; -import javax.jcr.Value; import javax.jcr.nodetype.NodeType; import javax.jcr.observation.Event; import javax.jcr.observation.EventListener; import javax.jcr.observation.ObservationManager; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; import org.argeo.ArgeoException; import org.argeo.eclipse.ui.jcr.AsyncUiEventListener; import org.argeo.eclipse.ui.utils.CommandUtils; import org.argeo.jcr.JcrUtils; -import org.argeo.jcr.UserJcrUtils; import org.argeo.slc.SlcException; import org.argeo.slc.client.ui.ClientUiPlugin; import org.argeo.slc.client.ui.SlcUiConstants; @@ -35,19 +46,21 @@ import org.argeo.slc.client.ui.editors.ProcessEditor; import org.argeo.slc.client.ui.editors.ProcessEditorInput; import org.argeo.slc.client.ui.model.ParentNodeFolder; import org.argeo.slc.client.ui.model.ResultFolder; +import org.argeo.slc.client.ui.model.ResultItemsComparator; +import org.argeo.slc.client.ui.model.ResultItemsComparer; 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.argeo.slc.client.ui.model.VirtualFolder; import org.argeo.slc.client.ui.providers.ResultTreeContentProvider; import org.argeo.slc.client.ui.providers.ResultTreeLabelProvider; -import org.argeo.slc.client.ui.wizards.ConfirmOverwriteWizard; import org.argeo.slc.jcr.SlcJcrResultUtils; import org.argeo.slc.jcr.SlcNames; import org.argeo.slc.jcr.SlcTypes; import org.eclipse.jface.action.IMenuListener; import org.eclipse.jface.action.IMenuManager; import org.eclipse.jface.action.MenuManager; +import org.eclipse.jface.dialogs.MessageDialog; import org.eclipse.jface.viewers.ColumnLabelProvider; import org.eclipse.jface.viewers.DecoratingLabelProvider; import org.eclipse.jface.viewers.DoubleClickEvent; @@ -63,7 +76,6 @@ import org.eclipse.jface.viewers.TreePath; import org.eclipse.jface.viewers.TreeViewer; import org.eclipse.jface.viewers.Viewer; import org.eclipse.jface.viewers.ViewerDropAdapter; -import org.eclipse.jface.wizard.WizardDialog; import org.eclipse.swt.SWT; import org.eclipse.swt.custom.SashForm; import org.eclipse.swt.dnd.DND; @@ -88,7 +100,11 @@ import org.eclipse.ui.part.ViewPart; public class JcrResultTreeView extends ViewPart { public final static String ID = ClientUiPlugin.ID + ".jcrResultTreeView"; - private final static Log log = LogFactory.getLog(JcrResultTreeView.class); + private final static DateFormat dateFormat = new SimpleDateFormat( + SlcUiConstants.DEFAULT_DISPLAY_DATE_TIME_FORMAT); + + // private final static Log log = + // LogFactory.getLog(JcrResultTreeView.class); /* DEPENDENCY INJECTION */ private Session session; @@ -97,17 +113,22 @@ public class JcrResultTreeView extends ViewPart { private TreeViewer resultTreeViewer; private TableViewer propertiesViewer; - private EventListener resultsObserver = null; + private EventListener myResultsObserver = null; + private EventListener allResultsObserver = null; - private final static String[] observedNodeTypes = { + // under My Results + private final static String[] observedNodeTypesUnderMyResult = { SlcTypes.SLC_TEST_RESULT, SlcTypes.SLC_RESULT_FOLDER, - NodeType.NT_UNSTRUCTURED }; + SlcTypes.SLC_MY_RESULT_ROOT_FOLDER }; + + private final static String[] observedNodeTypesUnderAllResults = { + SlcTypes.SLC_TEST_RESULT, NodeType.NT_UNSTRUCTURED }; // FIXME cache to ease D&D - private boolean isActionUnderMyResult = false; - private ResultParent lastSelectedTargetElement; - private ResultParent lastSelectedSourceElement; - private ResultParent lastSelectedSourceElementParent; + // private boolean isActionUnderMyResult = false; + // private ResultParent lastSelectedTargetElement; + // private ResultParent lastSelectedSourceElement; + // private ResultParent lastSelectedSourceElementParent; private boolean isResultFolder = false; // FIXME we cache the fact that we are moving a node to avoid exception @@ -142,21 +163,42 @@ public class JcrResultTreeView extends ViewPart { sashForm.setWeights(getWeights()); + setOrderedInput(resultTreeViewer); + + // Initialize observer try { ObservationManager observationManager = session.getWorkspace() .getObservationManager(); - resultsObserver = new ResultObserver(resultTreeViewer.getTree() - .getDisplay()); - observationManager.addEventListener(resultsObserver, - Event.NODE_MOVED | Event.NODE_ADDED | Event.NODE_REMOVED, - UserJcrUtils.getUserHome(session).getPath(), true, null, - observedNodeTypes, false); + myResultsObserver = new MyResultsObserver(resultTreeViewer + .getTree().getDisplay()); + allResultsObserver = new AllResultsObserver(resultTreeViewer + .getTree().getDisplay()); + + // observe tree changes under MyResults + observationManager.addEventListener(myResultsObserver, + Event.NODE_ADDED | Event.NODE_REMOVED, + SlcJcrResultUtils.getMyResultsBasePath(session), true, + null, observedNodeTypesUnderMyResult, false); + // observe tree changes under All results + observationManager.addEventListener(allResultsObserver, + Event.NODE_ADDED | Event.NODE_REMOVED, + SlcJcrResultUtils.getSlcResultsBasePath(session), true, + null, observedNodeTypesUnderAllResults, false); } catch (RepositoryException e) { throw new SlcException("Cannot register listeners", e); } + } - // Refresh the view to initialize it - refresh(null); + /** + * Override default behaviour so that default defined order remains + * unchanged on first level of the tree + */ + private void setOrderedInput(TreeViewer viewer) { + // Add specific ordering + resultTreeViewer.setInput(null); + viewer.setComparator(null); + resultTreeViewer.setInput(initializeResultTree()); + viewer.setComparator(new ResultItemsComparator()); } // The main tree viewer @@ -177,6 +219,12 @@ public class JcrResultTreeView extends ViewPart { decorator)); viewer.addDoubleClickListener(new ViewDoubleClickListener()); + // Override default behaviour to insure that 2 distincts results that + // have the same name will be correctly and distincly returned by + // corresponding + // TreeViewer.getSelection() method. + viewer.setComparer(new ResultItemsComparer()); + // viewer.setLabelProvider(rtLblProvider); getSite().setSelectionProvider(viewer); @@ -213,11 +261,23 @@ public class JcrResultTreeView extends ViewPart { TableViewerColumn col = new TableViewerColumn(propertiesViewer, SWT.NONE); col.getColumn().setText("Name"); - col.getColumn().setWidth(200); + col.getColumn().setWidth(100); col.setLabelProvider(new ColumnLabelProvider() { public String getText(Object element) { try { - return ((Property) element).getName(); + String name = ((Property) element).getName(); + String value = null; + if (SlcNames.SLC_TEST_CASE.equals(name)) + value = "Test case"; + else if (SlcNames.SLC_COMPLETED.equals(name)) + value = "Completed on"; + else if (SlcNames.SLC_SUCCESS.equals(name)) + value = "Status"; + else if (SlcNames.SLC_MESSAGE.equals(name)) + value = "Message"; + else if (SlcNames.SLC_ERROR_MESSAGE.equals(name)) + value = "Error"; + return value; } catch (RepositoryException e) { throw new ArgeoException( "Unexpected exception in label provider", e); @@ -226,39 +286,33 @@ public class JcrResultTreeView extends ViewPart { }); col = new TableViewerColumn(propertiesViewer, SWT.NONE); col.getColumn().setText("Value"); - col.getColumn().setWidth(400); + col.getColumn().setWidth(200); col.setLabelProvider(new ColumnLabelProvider() { public String getText(Object element) { try { Property property = (Property) element; - if (property.getType() == PropertyType.BINARY) - return ""; - else if (property.isMultiple()) { - StringBuffer buf = new StringBuffer("["); - Value[] values = property.getValues(); - for (int i = 0; i < values.length; i++) { - if (i != 0) - buf.append(", "); - buf.append(values[i].getString()); + String name = property.getName(); + String value = null; + + if (SlcNames.SLC_TEST_CASE.equals(name) + || SlcNames.SLC_ERROR_MESSAGE.equals(name) + || SlcNames.SLC_MESSAGE.equals(name)) + value = property.getValue().getString(); + else if (SlcNames.SLC_COMPLETED.equals(name)) { + Calendar date = property.getValue().getDate(); + value = dateFormat.format(date.getTime()); + } else if (SlcNames.SLC_SUCCESS.equals(name)) { + if (property.getValue().getBoolean()) + value = "SUCCESS"; + else { + if (property.getParent().hasNode( + SlcNames.SLC_ERROR_MESSAGE)) + value = "ERROR"; + else + value = "FAILED"; } - buf.append(']'); - return buf.toString(); - } else - return property.getValue().getString(); - } catch (RepositoryException e) { - throw new ArgeoException( - "Unexpected exception in label provider", e); - } - } - }); - col = new TableViewerColumn(propertiesViewer, SWT.NONE); - col.getColumn().setText("Type"); - col.getColumn().setWidth(200); - col.setLabelProvider(new ColumnLabelProvider() { - public String getText(Object element) { - try { - return PropertyType.nameFromValue(((Property) element) - .getType()); + } + return value; } catch (RepositoryException e) { throw new ArgeoException( "Unexpected exception in label provider", e); @@ -308,11 +362,13 @@ public class JcrResultTreeView extends ViewPart { * */ public void refresh(ResultParent resultParent) { - if (log.isDebugEnabled()) - log.debug("Refreshing '" + resultParent + "'..."); - // Thread.dumpStack(); if (resultParent == null) { - resultTreeViewer.setInput(initializeResultTree()); + if (!resultTreeViewer.getTree().isDisposed()) { + TreePath[] tps = resultTreeViewer.getExpandedTreePaths(); + setOrderedInput(resultTreeViewer); + resultTreeViewer.setExpandedTreePaths(tps); + } else + setOrderedInput(resultTreeViewer); } else { if (resultParent instanceof ParentNodeFolder) { ParentNodeFolder currFolder = (ParentNodeFolder) resultParent; @@ -320,10 +376,8 @@ public class JcrResultTreeView extends ViewPart { currFolder.forceFullRefresh(); } // FIXME: specific refresh does not work - // resultTreeViewer.refresh(currFolder, true); - TreePath[] tps = resultTreeViewer.getExpandedTreePaths(); - resultTreeViewer.setInput(initializeResultTree()); - resultTreeViewer.setExpandedTreePaths(tps); + // resultTreeViewer.refresh(resultParent, true); + refresh(null); } } @@ -335,25 +389,23 @@ 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)) { - isPassed = node.getNode(SlcNames.SLC_STATUS) + isPassed = node.getNode(SlcNames.SLC_AGGREGATED_STATUS) .getProperty(SlcNames.SLC_SUCCESS).getBoolean(); } else if (node.isNodeType(SlcTypes.SLC_RESULT_FOLDER)) { NodeIterator ni = node.getNodes(); - // quicker but wrong : refresh will stop as soon as a failed - // test is found and the whole tree won't be refreshed - // while (isPassed && ni.hasNext()){ while (ni.hasNext()) { Node currChild = ni.nextNode(); isPassed = isPassed & jcrRefresh(currChild); } - if (isPassed != node.getNode(SlcNames.SLC_STATUS) + if (isPassed != node.getNode(SlcNames.SLC_AGGREGATED_STATUS) .getProperty(SlcNames.SLC_SUCCESS).getBoolean()) { - node.getNode(SlcNames.SLC_STATUS).setProperty( + node.getNode(SlcNames.SLC_AGGREGATED_STATUS).setProperty( SlcNames.SLC_SUCCESS, isPassed); node.getSession().save(); return isPassed; @@ -368,56 +420,58 @@ 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); - 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; + // Force initialization of the tree structure if needed + SlcJcrResultUtils.getSlcResultsParentNode(session); + SlcJcrResultUtils.getMyResultParentNode(session); + // Remove yesterday and last 7 days virtual folders + // ResultParent[] roots = new ResultParent[5]; + ResultParent[] roots = new ResultParent[3]; + + // 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.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"); + roots[2] = new ParentNodeFolder(null, otherResultsPar, + "All results"); + return roots; } catch (RepositoryException re) { throw new ArgeoException( "Unexpected error while initializing ResultTree.", re); @@ -432,27 +486,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 +522,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, @@ -483,29 +537,41 @@ public class JcrResultTreeView extends ViewPart { IStructuredSelection selection = (IStructuredSelection) resultTreeViewer .getSelection(); boolean doIt = false; - // only one node at a time for the time being. - if (selection.size() == 1) { - try { + + // FIXME clean this code. + try { + if (selection.size() == 1) { Object obj = selection.getFirstElement(); - if (obj instanceof SingleResultNode) { - Node tNode = ((SingleResultNode) obj).getNode(); - if (tNode.getPrimaryNodeType().isNodeType( - SlcTypes.SLC_TEST_RESULT)) { - doIt = true; - isResultFolder = false; - } - } else if (obj instanceof ResultFolder) { + if (obj instanceof ResultFolder) { Node tNode = ((ResultFolder) obj).getNode(); if (tNode.getPrimaryNodeType().isNodeType( SlcTypes.SLC_RESULT_FOLDER)) { doIt = true; isResultFolder = true; } + } else + isResultFolder = false; + } else + isResultFolder = false; + + if (!isResultFolder) { + @SuppressWarnings("rawtypes") + Iterator it = selection.iterator(); + while (it.hasNext()) { + Object obj = it.next(); + if (obj instanceof SingleResultNode) { + Node tNode = ((SingleResultNode) obj).getNode(); + if (tNode.getPrimaryNodeType().isNodeType( + SlcTypes.SLC_TEST_RESULT)) { + doIt = true; + } + } } - } catch (RepositoryException re) { - throw new SlcException( - "unexpected error while validating drag source", re); } + + } catch (RepositoryException re) { + throw new SlcException( + "unexpected error while validating drag source", re); } event.doit = doIt; } @@ -513,15 +579,27 @@ public class JcrResultTreeView extends ViewPart { public void dragSetData(DragSourceEvent event) { IStructuredSelection selection = (IStructuredSelection) resultTreeViewer .getSelection(); - Object obj = selection.getFirstElement(); + try { - Node first; - if (obj instanceof SingleResultNode) { - first = ((SingleResultNode) obj).getNode(); - event.data = first.getIdentifier(); - } else if (obj instanceof ResultFolder) { - first = ((ResultFolder) obj).getNode(); - event.data = first.getIdentifier(); + // specific case of a result folder + if (isResultFolder) { + Object obj = selection.getFirstElement(); + event.data = ((ResultFolder) obj).getNode().getIdentifier(); + } else { + @SuppressWarnings("rawtypes") + Iterator it = selection.iterator(); + StringBuffer nodes = new StringBuffer(); + while (it.hasNext()) { + Object obj = it.next(); + if (obj instanceof SingleResultNode) { + Node tNode = ((SingleResultNode) obj).getNode(); + if (tNode.getPrimaryNodeType().isNodeType( + SlcTypes.SLC_TEST_RESULT)) { + nodes.append(tNode.getIdentifier() + ";"); + } + } + } + event.data = nodes.toString(); } } catch (RepositoryException re) { throw new SlcException("unexpected error while setting data", @@ -545,48 +623,28 @@ 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 - boolean doit = true; - if (isResultFolder) { - Node source = ((ParentNodeFolder) lastSelectedSourceElement) - .getNode(); - String sourcePath = source.getPath(); - String targetPath = tpNode.getPath(); - if (targetPath.startsWith(sourcePath)) - doit = false; - } - if (doit) { - targetParentNode = tpNode; - validDrop = true; - lastSelectedTargetElement = (ResultParent) target; - } + targetParentNode = tpNode; + validDrop = true; } - } catch (RepositoryException re) { throw new SlcException( "unexpected error while validating drop target", re); @@ -599,66 +657,179 @@ public class JcrResultTreeView extends ViewPart { // clear selection to prevent unwanted scrolling of the UI resultTreeViewer.setSelection(null); try { - Node source = session.getNodeByIdentifier((String) data); - - // Check is a node with same name already exists at destination - String name; - if (source.hasProperty(Property.JCR_TITLE)) - name = source.getProperty(Property.JCR_TITLE).getString(); - else if (source.hasProperty(SlcNames.SLC_TEST_CASE)) - name = source.getProperty(SlcNames.SLC_TEST_CASE) - .getString(); - else - name = source.getName(); - - if (targetParentNode.hasNode(name)) { - ConfirmOverwriteWizard wizard = new ConfirmOverwriteWizard( - name, targetParentNode); - WizardDialog dialog = new WizardDialog(Display.getDefault() - .getActiveShell(), wizard); - - if (dialog.open() == WizardDialog.CANCEL) - return true; - - if (wizard.overwrite()) { - targetParentNode.getNode(name).remove(); - // session.save(); - } else - name = wizard.newName(); - } + if (isResultFolder) { + // Sanity check : we cannot move a folder to one of its sub + // folder or neither move an object in the same parent + // folder + Node source = session.getNodeByIdentifier((String) data); + if (targetParentNode.getPath().startsWith(source.getPath()) + || source.getParent().getPath() + .equals(targetParentNode.getPath())) + return false; - Node target; - if (!isActionUnderMyResult) {// Copy - target = targetParentNode.addNode(name, source - .getPrimaryNodeType().getName()); - JcrUtils.copy(source, target); - } else {// move + // Move String sourcePath = source.getPath(); - String destPath = targetParentNode.getPath() + "/" + name; + String destPath = targetParentNode.getPath() + "/" + + source.getName(); session.move(sourcePath, destPath); + // Update passed status of the parent source Node + ResultParentUtils.updatePassedStatus( + session.getNode(JcrUtils.parentPath(sourcePath)), + true); + // Node target = session.getNode(destPath); + session.save(); + return true; + } + + String[] datas = ((String) data).split(";"); + nodesToCopy: for (String id : datas) { + + Node source = session.getNodeByIdentifier(id); + String name; + if (source.hasProperty(Property.JCR_TITLE)) + name = source.getProperty(Property.JCR_TITLE) + .getString(); + else if (source.hasProperty(SlcNames.SLC_TEST_CASE)) + name = source.getProperty(SlcNames.SLC_TEST_CASE) + .getString(); + else + name = source.getName(); + + // Check if another copy of the same test instance already + // exists at target + NodeIterator ni = targetParentNode.getNodes(); + String slcUid = source.getProperty(SlcNames.SLC_UUID) + .getString(); + while (ni.hasNext()) { + Node curr = ni.nextNode(); + if (curr.hasProperty(SlcNames.SLC_UUID) + && slcUid.equals(curr.getProperty( + SlcNames.SLC_UUID).getString())) { + MessageDialog + .openWarning( + PlatformUI.getWorkbench() + .getDisplay() + .getActiveShell(), + "Duplicated instance.", + "An instance of the same test case (" + + name + + ") exists at destination.\n " + + "This item will not be neither copied nor moved."); + continue nodesToCopy; + + } + } + + Node target; + boolean passedStatus = source + .getNode(SlcNames.SLC_AGGREGATED_STATUS) + .getProperty(SlcNames.SLC_SUCCESS).getBoolean(); + + boolean isActionUnderMyResult = source.getPath() + .startsWith( + SlcJcrResultUtils + .getMyResultsBasePath(session)); + + if (!isActionUnderMyResult) {// Copy + target = targetParentNode.addNode(source.getName(), + source.getPrimaryNodeType().getName()); + JcrUtils.copy(source, target); + } else {// move + String sourcePath = source.getPath(); + String destPath = targetParentNode.getPath() + "/" + + name; + session.move(sourcePath, destPath); + // session.save(); + // Update passed status of the parent source Node + ResultParentUtils + .updatePassedStatus(session.getNode(JcrUtils + .parentPath(sourcePath)), true); + target = session.getNode(destPath); + + } + if (!target.isNodeType(NodeType.MIX_TITLE)) + target.addMixin(NodeType.MIX_TITLE); + target.setProperty(Property.JCR_TITLE, name); + ResultParentUtils.updatePassedStatus(target.getParent(), + passedStatus); + session.save(); + + // try { + // Node source = session.getNodeByIdentifier(id); + // String name; + // if (source.hasProperty(Property.JCR_TITLE)) + // name = source.getProperty(Property.JCR_TITLE) + // .getString(); + // else if (source.hasProperty(SlcNames.SLC_TEST_CASE)) + // name = source.getProperty(SlcNames.SLC_TEST_CASE) + // .getString(); + // else + // name = source.getName(); + // + // // Check if a user defined folder result with same name + // // exists + // // at target + // if (targetParentNode.hasNode(name) + // && targetParentNode.getNode(name).isNodeType( + // SlcTypes.SLC_RESULT_FOLDER)) { + // ConfirmOverwriteWizard wizard = new + // ConfirmOverwriteWizard( + // name, targetParentNode); + // WizardDialog dialog = new WizardDialog(Display + // .getDefault().getActiveShell(), wizard); + // + // if (dialog.open() == WizardDialog.CANCEL) + // return true; + // + // if (wizard.overwrite()) { + // targetParentNode.getNode(name).remove(); + // // session.save(); + // } else + // name = wizard.newName(); + // } + // + // Node target; + // boolean passedStatus = source + // .getNode(SlcNames.SLC_AGGREGATED_STATUS) + // .getProperty(SlcNames.SLC_SUCCESS).getBoolean(); + // + // if (!isActionUnderMyResult) {// Copy + // target = targetParentNode.addNode(source.getName(), + // source.getPrimaryNodeType().getName()); + // JcrUtils.copy(source, target); + // } else {// move + // String sourcePath = source.getPath(); + // String destPath = targetParentNode.getPath() + "/" + // + name; + // session.move(sourcePath, destPath); + // // session.save(); + // // Update passed status of the parent source Node + // ResultParentUtils + // .updatePassedStatus(session.getNode(JcrUtils + // .parentPath(sourcePath)), true); + // target = session.getNode(destPath); + // + // } + // if (!target.isNodeType(NodeType.MIX_TITLE)) + // target.addMixin(NodeType.MIX_TITLE); + // target.setProperty(Property.JCR_TITLE, name); + // ResultParentUtils.updatePassedStatus(target.getParent(), + // passedStatus); // session.save(); - target = session.getNode(destPath); + } - if (!target.isNodeType(NodeType.MIX_TITLE)) - target.addMixin(NodeType.MIX_TITLE); - target.setProperty(Property.JCR_TITLE, name); - ResultParentUtils - .updatePassedStatus(target, - target.getNode(SlcNames.SLC_STATUS) - .getProperty(SlcNames.SLC_SUCCESS) - .getBoolean()); - session.save(); } catch (RepositoryException re) { throw new SlcException( "unexpected error while copying dropped node", re); + } return true; } } - class ResultObserver extends AsyncUiEventListener { + class MyResultsObserver extends AsyncUiEventListener { - public ResultObserver(Display display) { + public MyResultsObserver(Display display) { super(display); } @@ -671,40 +842,43 @@ public class JcrResultTreeView extends ViewPart { protected void onEventInUiThread(List events) throws RepositoryException { - int i = 0; + List nodesToRefresh = new ArrayList(); 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); - } + String parPath = JcrUtils.parentPath(event.getPath()); + if (session.nodeExists(parPath)) { + Node node = session.getNode(parPath); + if (!nodesToRefresh.contains(node)) { + nodesToRefresh.add(node); } } } - if (log.isDebugEnabled()) - log.debug("treated events: " + i); + + // Update check nodes + for (Node node : nodesToRefresh) + jcrRefresh(node); + refresh(null); + } + } + + class AllResultsObserver extends AsyncUiEventListener { + + public AllResultsObserver(Display display) { + super(display); + } + + @Override + protected Boolean willProcessInUiThread(List events) + throws RepositoryException { + // unfiltered for the time being + return true; + } + + protected void onEventInUiThread(List events) + throws RepositoryException { + refresh(null); + // if (lastSelectedSourceElementParent != null) + // refresh(lastSelectedSourceElementParent); } } @@ -719,14 +893,29 @@ public class JcrResultTreeView extends ViewPart { public Object[] getElements(Object inputElement) { try { if (inputElement instanceof Node) { - List props = new ArrayList(); - PropertyIterator pit = ((Node) inputElement) - .getProperties(); - while (pit.hasNext()) - props.add(pit.nextProperty()); - return props.toArray(); + Node node = (Node) inputElement; + if (node.isNodeType(SlcTypes.SLC_TEST_RESULT)) { + List props = new ArrayList(); + if (node.hasProperty(SlcNames.SLC_TEST_CASE)) + props.add(node.getProperty(SlcNames.SLC_TEST_CASE)); + if (node.hasProperty(SlcNames.SLC_COMPLETED)) + props.add(node.getProperty(SlcNames.SLC_COMPLETED)); + if (node.hasNode(SlcNames.SLC_AGGREGATED_STATUS)) { + Node status = node + .getNode(SlcNames.SLC_AGGREGATED_STATUS); + props.add(status.getProperty(SlcNames.SLC_SUCCESS)); + if (status.hasProperty(SlcNames.SLC_MESSAGE)) + props.add(status + .getProperty(SlcNames.SLC_MESSAGE)); + if (status.hasProperty(SlcNames.SLC_ERROR_MESSAGE)) + props.add(status + .getProperty(SlcNames.SLC_ERROR_MESSAGE)); + } + return props.toArray(); + } } return new Object[] {}; + } catch (RepositoryException e) { throw new ArgeoException("Cannot get element for " + inputElement, e); @@ -747,28 +936,28 @@ public class JcrResultTreeView extends ViewPart { else propertiesViewer.setInput(null); // update cache for Drag & drop - lastSelectedTargetElement = firstItem; - lastSelectedSourceElement = firstItem; - lastSelectedSourceElementParent = (ResultParent) firstItem - .getParent(); - String pPath = ""; - try { - - if (firstItem instanceof ParentNodeFolder) - pPath = ((ParentNodeFolder) firstItem).getNode() - .getPath(); - else if (firstItem instanceof SingleResultNode) - pPath = ((SingleResultNode) firstItem).getNode() - .getPath(); - } catch (RepositoryException e) { - throw new SlcException( - "Unexpected error while checking parent UI tree", e); - } - if ((pPath.startsWith(SlcJcrResultUtils - .getMyResultsBasePath(session)))) - isActionUnderMyResult = true; - else - isActionUnderMyResult = false; + // lastSelectedTargetElement = firstItem; + // lastSelectedSourceElement = firstItem; + // lastSelectedSourceElementParent = (ResultParent) firstItem + // .getParent(); + // String pPath = ""; + // try { + // + // if (firstItem instanceof ParentNodeFolder) + // pPath = ((ParentNodeFolder) firstItem).getNode() + // .getPath(); + // else if (firstItem instanceof SingleResultNode) + // pPath = ((SingleResultNode) firstItem).getNode() + // .getPath(); + // } catch (RepositoryException e) { + // throw new SlcException( + // "Unexpected error while checking parent UI tree", e); + // } + // if ((pPath.startsWith(SlcJcrResultUtils + // .getMyResultsBasePath(session)))) + // isActionUnderMyResult = true; + // else + // isActionUnderMyResult = false; } } } @@ -784,5 +973,4 @@ public class JcrResultTreeView extends ViewPart { public void setSession(Session session) { this.session = session; } - -} +} \ No newline at end of file