]> git.argeo.org Git - gpl/argeo-slc.git/blobdiff - eclipse/plugins/runtime/org.argeo.slc.client.ui/src/main/java/org/argeo/slc/client/ui/views/ResultListView.java
Finalise excel support for windows
[gpl/argeo-slc.git] / eclipse / plugins / runtime / org.argeo.slc.client.ui / src / main / java / org / argeo / slc / client / ui / views / ResultListView.java
index c61f8de348de45e2c35628b32989c772b145a43f..ca2b4a5b6b9dcfe31052d3882d4e24279ceedc03 100644 (file)
@@ -13,6 +13,7 @@ import org.eclipse.core.commands.Command;
 import org.eclipse.core.commands.IParameter;
 import org.eclipse.core.commands.Parameterization;
 import org.eclipse.core.commands.ParameterizedCommand;
+import org.eclipse.jface.action.MenuManager;
 import org.eclipse.jface.viewers.DoubleClickEvent;
 import org.eclipse.jface.viewers.IDoubleClickListener;
 import org.eclipse.jface.viewers.IStructuredContentProvider;
@@ -25,6 +26,8 @@ import org.eclipse.swt.SWT;
 import org.eclipse.swt.graphics.Image;
 import org.eclipse.swt.layout.GridData;
 import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Menu;
+import org.eclipse.swt.widgets.MenuItem;
 import org.eclipse.swt.widgets.Table;
 import org.eclipse.swt.widgets.TableColumn;
 import org.eclipse.ui.IWorkbench;
@@ -49,6 +52,22 @@ public class ResultListView extends ViewPart {
                viewer.setContentProvider(new ViewContentProvider());
                viewer.setInput(getViewSite());
                viewer.addDoubleClickListener(new ViewDoubleClickListener());
+
+               // Context Menu for the end user to choose what kind of display he wants
+               // Problem to dynamically add parameters linked with the current
+               // selected object
+               MenuManager menuManager = new MenuManager();
+               Menu menu = menuManager.createContextMenu(viewer.getControl());
+
+               // unable excel commands if not on windows
+               MenuItem[] items = menu.getItems();
+               String platform = SWT.getPlatform();
+               if (!(platform.equals("win32") || platform.equals("wpf"))) {
+                       items[1].setEnabled(false);
+               }
+
+               viewer.getControl().setMenu(menu);
+               getSite().registerContextMenu(menuManager, viewer);
        }
 
        protected Table createTable(Composite parent) {
@@ -56,7 +75,7 @@ public class ResultListView extends ViewPart {
                                | SWT.FULL_SELECTION | SWT.HIDE_SELECTION;
 
                Table table = new Table(parent, style);
-
+               // table.addMouseListener(new RightClickListener());
                GridData gridData = new GridData(GridData.FILL_BOTH);
                gridData.grabExcessVerticalSpace = true;
                gridData.grabExcessHorizontalSpace = true;
@@ -77,6 +96,26 @@ public class ResultListView extends ViewPart {
                return table;
        }
 
+       // TODO : Improve this methods.
+       // For now it is a workaround because we cannot dynamically update context
+       // menu to pass the UUID as command parameter
+       public String[] getSelectedResult() {
+               Object obj = ((IStructuredSelection) viewer.getSelection())
+                               .getFirstElement();
+
+               String[] attributes = new String[2];
+
+               if (obj == null || !(obj instanceof ResultAttributes))
+                       return null;
+               else {
+                       ResultAttributes ra = (ResultAttributes) obj;
+                       attributes[0] = ra.getUuid();
+                       attributes[1] = (ra.getAttributes().get("testCase") == null) ? null
+                                       : ra.getAttributes().get("testCase");
+                       return attributes;
+               }
+       }
+
        // View Specific inner class
        protected static class ViewContentProvider implements
                        IStructuredContentProvider {
@@ -135,6 +174,7 @@ public class ResultListView extends ViewPart {
        }
 
        // Handle Events
+
        /**
         * The ResultAttributes expose a part of the information contained in the
         * TreeTestResult, It has the same UUID as the corresponding treeTestResult.
@@ -146,7 +186,6 @@ public class ResultListView extends ViewPart {
 
                        if (obj instanceof ResultAttributes) {
                                ResultAttributes ra = (ResultAttributes) obj;
-                               log.debug("Double-clic on result with UUID" + ra.getUuid());
 
                                IWorkbench iw = ClientUiPlugin.getDefault().getWorkbench();
                                IHandlerService handlerService = (IHandlerService) iw
@@ -189,10 +228,9 @@ public class ResultListView extends ViewPart {
                }
        }
 
-       // Ioc
+       // IoC
        public void setTestResultCollectionDao(
                        TreeTestResultCollectionDao testResultCollectionDao) {
                this.testResultCollectionDao = testResultCollectionDao;
        }
-
 }