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=f0ec30ed91406448220fd1386ab87222aa3ee18d;hb=48b6f7647f12f4b96d1914bcafc95efd7f43cc43;hp=8fcea20aa0ecb23def8c1ffcc2270c2c468f18e2;hpb=a59b94ef7611d278b2ed1b60b51f15fcece52e4e;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 8fcea20aa..f0ec30ed9 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 @@ -19,11 +19,13 @@ 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.Repository; import javax.jcr.RepositoryException; import javax.jcr.Session; import javax.jcr.nodetype.NodeType; @@ -39,6 +41,8 @@ import org.argeo.slc.SlcException; import org.argeo.slc.client.ui.ClientUiPlugin; import org.argeo.slc.client.ui.SlcUiConstants; import org.argeo.slc.client.ui.commands.AddResultFolder; +import org.argeo.slc.client.ui.commands.DeleteItems; +import org.argeo.slc.client.ui.commands.RefreshJcrResultTreeView; import org.argeo.slc.client.ui.commands.RenameResultFolder; import org.argeo.slc.client.ui.commands.RenameResultNode; import org.argeo.slc.client.ui.editors.ProcessEditor; @@ -53,13 +57,13 @@ 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; @@ -75,7 +79,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; @@ -124,17 +127,8 @@ public class JcrResultTreeView extends ViewPart { 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 isResultFolder = false; - // FIXME we cache the fact that we are moving a node to avoid exception - // triggered by the "Add Node" event while moving - // boolean isMoveInProgress = false; - /** * To be overridden to adapt size of form and result frames. */ @@ -195,9 +189,9 @@ public class JcrResultTreeView extends ViewPart { */ private void setOrderedInput(TreeViewer viewer) { // Add specific ordering - resultTreeViewer.setInput(null); + viewer.setInput(null); viewer.setComparator(null); - resultTreeViewer.setInput(initializeResultTree()); + viewer.setInput(initializeResultTree()); viewer.setComparator(new ResultItemsComparator()); } @@ -221,8 +215,7 @@ public class JcrResultTreeView extends ViewPart { // 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. + // corresponding TreeViewer.getSelection() method. viewer.setComparer(new ResultItemsComparer()); // viewer.setLabelProvider(rtLblProvider); @@ -243,6 +236,8 @@ public class JcrResultTreeView extends ViewPart { } }); viewer.getTree().setMenu(menu); + menuManager.setRemoveAllWhenShown(true); + getSite().registerContextMenu(menuManager, viewer); // add change listener to display TestResult information in the property @@ -276,7 +271,7 @@ public class JcrResultTreeView extends ViewPart { else if (SlcNames.SLC_MESSAGE.equals(name)) value = "Message"; else if (SlcNames.SLC_ERROR_MESSAGE.equals(name)) - value = "Error"; + value = "Error"; return value; } catch (RepositoryException e) { throw new ArgeoException( @@ -303,9 +298,9 @@ public class JcrResultTreeView extends ViewPart { value = dateFormat.format(date.getTime()); } else if (SlcNames.SLC_SUCCESS.equals(name)) { if (property.getValue().getBoolean()) - value = "SUCCESS"; + value = "PASSED"; else { - if (property.getParent().hasNode( + if (property.getParent().hasProperty( SlcNames.SLC_ERROR_MESSAGE)) value = "ERROR"; else @@ -395,7 +390,7 @@ public class JcrResultTreeView extends ViewPart { 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(); @@ -403,9 +398,9 @@ public class JcrResultTreeView extends ViewPart { 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; @@ -491,10 +486,13 @@ public class JcrResultTreeView extends ViewPart { boolean canAddSubfolder = false; boolean canRenamefolder = false; boolean isSingleResultNode = false; - // Building conditions - if (selection.size() == 1) { - Object obj = selection.getFirstElement(); - try { + boolean isUnderMyResult = false; + boolean validMultipleDelete = false; + try { + + // Building conditions + if (selection.size() == 1) { + Object obj = selection.getFirstElement(); if (obj instanceof SingleResultNode) isSingleResultNode = true; else if (obj instanceof ParentNodeFolder) { @@ -502,18 +500,50 @@ public class JcrResultTreeView extends ViewPart { if (cNode.isNodeType(SlcTypes.SLC_RESULT_FOLDER)) { canAddSubfolder = true; canRenamefolder = true; + isUnderMyResult = 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", - re); + } else { + @SuppressWarnings("rawtypes") + Iterator it = selection.iterator(); + multicheck: while (it.hasNext()) { + validMultipleDelete = true; + Object obj = it.next(); + if (obj instanceof SingleResultNode) + continue multicheck; + else if (obj instanceof ParentNodeFolder) { + Node cNode = ((ParentNodeFolder) obj).getNode(); + if (cNode.isNodeType(SlcTypes.SLC_RESULT_FOLDER)) + continue multicheck; + else { + validMultipleDelete = false; + break multicheck; + } + } else { + validMultipleDelete = false; + break multicheck; + } + } } + } catch (RepositoryException re) { + throw new SlcException( + "unexpected error while building condition for context menu", + re); } + // Effective Refresh + CommandUtils.refreshCommand(menuManager, window, + RefreshJcrResultTreeView.ID, + RefreshJcrResultTreeView.DEFAULT_LABEL, + RefreshJcrResultTreeView.DEFAULT_IMG_DESCRIPTOR, true); + + CommandUtils.refreshCommand(menuManager, window, DeleteItems.ID, + DeleteItems.DEFAULT_LABEL, DeleteItems.DEFAULT_IMG_DESCRIPTOR, + isUnderMyResult || isSingleResultNode || validMultipleDelete); + CommandUtils.refreshCommand(menuManager, window, AddResultFolder.ID, AddResultFolder.DEFAULT_LABEL, ClientUiPlugin.getDefault().getWorkbench().getSharedImages() @@ -524,9 +554,21 @@ public class JcrResultTreeView extends ViewPart { RenameResultFolder.DEFAULT_LABEL, RenameResultFolder.DEFAULT_IMG_DESCRIPTOR, canRenamefolder); + // Command removed for the time being. CommandUtils.refreshCommand(menuManager, window, RenameResultNode.ID, RenameResultNode.DEFAULT_LABEL, - RenameResultNode.DEFAULT_IMG_DESCRIPTOR, isSingleResultNode); + RenameResultNode.DEFAULT_IMG_DESCRIPTOR, false); + + // Test to be removed + // If you use this pattern, do not forget to call + // menuManager.setRemoveAllWhenShown(true); + // when creating the menuManager + + // menuManager.add(new Action("Test") { + // public void run() { + // log.debug("do something"); + // } + // }); } /* INNER CLASSES */ @@ -537,29 +579,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; } @@ -567,15 +621,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(); + StringBuilder nodes = new StringBuilder(); + 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()).append(";"); + } + } + } + event.data = nodes.toString(); } } catch (RepositoryException re) { throw new SlcException("unexpected error while setting data", @@ -618,31 +684,8 @@ public class JcrResultTreeView extends ViewPart { } 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) { - source = ((ParentNodeFolder) lastSelectedSourceElement) - .getNode(); - if (tpNode.getPath().startsWith(source.getPath()) - || source.getParent().getPath() - .equals(tpNode.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) { - targetParentNode = tpNode; - validDrop = true; - // lastSelectedTargetElement = (ResultParent) target; - } + targetParentNode = tpNode; + validDrop = true; } } catch (RepositoryException re) { throw new SlcException( @@ -656,65 +699,108 @@ public class JcrResultTreeView extends ViewPart { // clear selection to prevent unwanted scrolling of the UI resultTreeViewer.setSelection(null); try { - Node source = session.getNodeByIdentifier((String) data); - - 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(); - } + 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; - boolean passedStatus = source.getNode(SlcNames.SLC_STATUS) - .getProperty(SlcNames.SLC_SUCCESS).getBoolean(); - if (!isActionUnderMyResult) {// Copy - target = targetParentNode.addNode(source.getName(), 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); - // session.save(); // Update passed status of the parent source Node ResultParentUtils.updatePassedStatus( session.getNode(JcrUtils.parentPath(sourcePath)), true); - target = session.getNode(destPath); + // 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 = false; + if (source.hasNode(SlcNames.SLC_AGGREGATED_STATUS)) + 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); + // 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(); } - if (!target.isNodeType(NodeType.MIX_TITLE)) - target.addMixin(NodeType.MIX_TITLE); - target.setProperty(Property.JCR_TITLE, name); - ResultParentUtils.updatePassedStatus(target.getParent(), - passedStatus); - session.save(); } catch (RepositoryException re) { throw new SlcException( "unexpected error while copying dropped node", re); + } return true; } @@ -769,8 +855,9 @@ public class JcrResultTreeView extends ViewPart { protected void onEventInUiThread(List events) throws RepositoryException { - if (lastSelectedSourceElementParent != null) - refresh(lastSelectedSourceElementParent); + refresh(null); + // if (lastSelectedSourceElementParent != null) + // refresh(lastSelectedSourceElementParent); } } @@ -792,8 +879,9 @@ public class JcrResultTreeView extends ViewPart { 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_STATUS)) { - Node status = node.getNode(SlcNames.SLC_STATUS); + 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 @@ -828,27 +916,27 @@ public class JcrResultTreeView extends ViewPart { 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; + // 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; } } } @@ -861,8 +949,23 @@ public class JcrResultTreeView extends ViewPart { } /* DEPENDENCY INJECTION */ + @Deprecated public void setSession(Session session) { this.session = session; } -} + public void dispose() { + // JcrUtils.unregisterQuietly(session.getWorkspace(), resultsObserver); + JcrUtils.logoutQuietly(session); + super.dispose(); + } + + public void setRepository(Repository repository) { + try { + session = repository.login(); + } catch (RepositoryException re) { + throw new SlcException("Unable to log in Repository " + repository, + re); + } + } +} \ No newline at end of file