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=99d131d8fb50c3fcf3079200b9d5660351de6bd8;hb=89114859830f6e159a259937375bd063f25f80c9;hp=9a9fb696268ac2612f02a26287fbb97b7a5b079b;hpb=78a1f1f21b5785919ffe25ddb9baf12aadff5f37;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 9a9fb6962..99d131d8f 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 @@ -15,18 +15,18 @@ */ package org.argeo.slc.client.ui.views; +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; @@ -56,13 +56,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; @@ -78,7 +78,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; @@ -103,6 +102,9 @@ import org.eclipse.ui.part.ViewPart; public class JcrResultTreeView extends ViewPart { public final static String ID = ClientUiPlugin.ID + ".jcrResultTreeView"; + private final static DateFormat dateFormat = new SimpleDateFormat( + SlcUiConstants.DEFAULT_DISPLAY_DATE_TIME_FORMAT); + private final static Log log = LogFactory.getLog(JcrResultTreeView.class); /* DEPENDENCY INJECTION */ @@ -124,10 +126,10 @@ public class JcrResultTreeView extends ViewPart { SlcTypes.SLC_TEST_RESULT, NodeType.NT_UNSTRUCTURED }; // FIXME cache to ease D&D - private boolean isActionUnderMyResult = false; + // private boolean isActionUnderMyResult = false; // private ResultParent lastSelectedTargetElement; - private ResultParent lastSelectedSourceElement; - private ResultParent lastSelectedSourceElementParent; + // private ResultParent lastSelectedSourceElement; + // private ResultParent lastSelectedSourceElementParent; private boolean isResultFolder = false; // FIXME we cache the fact that we are moving a node to avoid exception @@ -260,11 +262,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); @@ -273,39 +287,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); @@ -388,7 +396,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(); @@ -396,9 +404,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; @@ -530,29 +538,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; } @@ -560,15 +580,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", @@ -611,29 +643,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())) - 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( @@ -647,65 +658,171 @@ 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 = 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(); } - 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; } @@ -742,42 +859,6 @@ public class JcrResultTreeView extends ViewPart { for (Node node : nodesToRefresh) jcrRefresh(node); refresh(null); - - // 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); } } @@ -796,11 +877,9 @@ public class JcrResultTreeView extends ViewPart { protected void onEventInUiThread(List events) throws RepositoryException { - for (Event event : events) { - if (log.isDebugEnabled()) - log.debug("Received event " + event); - } - refresh(lastSelectedSourceElementParent); + refresh(null); + // if (lastSelectedSourceElementParent != null) + // refresh(lastSelectedSourceElementParent); } } @@ -815,14 +894,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); @@ -844,27 +938,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; } } } @@ -880,5 +974,4 @@ public class JcrResultTreeView extends ViewPart { public void setSession(Session session) { this.session = session; } - -} +} \ No newline at end of file