Add generic "Open in..." context menu to referencing objects view
authorPatrick Plitzner <p.plitzner@bgbm.org>
Mon, 4 Jan 2016 07:13:04 +0000 (08:13 +0100)
committerPatrick Plitzner <p.plitzner@bgbm.org>
Mon, 4 Jan 2016 07:13:04 +0000 (08:13 +0100)
eu.etaxonomy.taxeditor.bulkeditor/plugin.xml
eu.etaxonomy.taxeditor.bulkeditor/src/main/java/eu/etaxonomy/taxeditor/bulkeditor/referencingobjects/ReferencingObjectsView.java

index b6d585bc93b32ac723276251405de5063ff677b5..d6659a71aa1837279c4e041a814f364bb79d7da4 100644 (file)
             </visibleWhen>
          </command>
       </menuContribution>
+      <menuContribution
+            allPopups="false"
+            locationURI="popup:eu.etaxonomy.taxeditor.bulkeditor.view.referencingobjects">
+         <dynamic
+               class="eu.etaxonomy.taxeditor.view.CdmViewerContextMenu"
+               id="eu.etaxonomy.taxeditor.referencingObjectsView.cdmViewerContextMenu">
+         </dynamic>
+      </menuContribution>
    </extension>
    <extension
          point="org.eclipse.ui.commands">
index 7895964773c63c68547bb0b15525b5c50780fab0..8573b617bf11d22d6f23bb7a5941352d0ee4b892 100644 (file)
@@ -22,6 +22,7 @@ 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.action.MenuManager;
 import org.eclipse.jface.viewers.CellEditor;
 import org.eclipse.jface.viewers.ICellModifier;
 import org.eclipse.jface.viewers.ISelection;
@@ -33,7 +34,9 @@ import org.eclipse.jface.viewers.TextCellEditor;
 import org.eclipse.jface.viewers.Viewer;
 import org.eclipse.swt.SWT;
 import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
 import org.eclipse.swt.widgets.Display;
+import org.eclipse.swt.widgets.Menu;
 import org.eclipse.swt.widgets.Table;
 import org.eclipse.ui.IWorkbenchPart;
 
@@ -62,8 +65,6 @@ import eu.etaxonomy.taxeditor.store.CdmStore;
 import eu.etaxonomy.taxeditor.view.AbstractCdmViewPart;
 
 /**
- * <p>ReferencingObjectsView class.</p>
- *
  * @author p.ciardelli
  * @created 08.07.2009
  * @version 1.0
@@ -72,7 +73,6 @@ public class ReferencingObjectsView extends AbstractCdmViewPart {
        private static final Logger logger = Logger
                        .getLogger(ReferencingObjectsView.class);
 
-       /** Constant <code>ID="eu.etaxonomy.taxeditor.bulkeditor.refer"{trunked}</code> */
        public static final String ID = "eu.etaxonomy.taxeditor.bulkeditor.view.referencingobjects";
 
        private TableViewer viewer;
@@ -85,9 +85,6 @@ public class ReferencingObjectsView extends AbstractCdmViewPart {
            cdmEntitySession = CdmStore.getCurrentSessionManager().bindNullSession();
        }
 
-       /* (non-Javadoc)
-        * @see eu.etaxonomy.taxeditor.model.AbstractCdmViewPart#createViewer(org.eclipse.swt.widgets.Composite)
-        */
        /** {@inheritDoc} */
        @Override
        public void createViewer(Composite parent) {
@@ -99,11 +96,8 @@ public class ReferencingObjectsView extends AbstractCdmViewPart {
                viewer.setContentProvider(new ReferencingObjectsContentProvider());
                viewer.setLabelProvider(new ReferencingObjectsLabelProvider());
                viewer.setCellModifier(new ICellModifier() {
-
             @Override
             public void modify(Object element, String property, Object value) {
-                // TODO Auto-generated method stub
-
             }
 
             @Override
@@ -126,7 +120,16 @@ public class ReferencingObjectsView extends AbstractCdmViewPart {
                 return true;
             }
         });
-//             viewer.setInput(new ArrayList<CdmBase>());
+
+        //create context menu
+        MenuManager menuManager = new MenuManager();
+        getSite().registerContextMenu(menuManager, viewer);
+        Control control = viewer.getControl();
+        Menu menu = menuManager.createContextMenu(control);
+        control.setMenu(menu);
+
+        // Propagate selection from viewer
+        getSite().setSelectionProvider(viewer);
        }
 
        /**
@@ -159,11 +162,7 @@ public class ReferencingObjectsView extends AbstractCdmViewPart {
        public void setFocus() {
            cdmEntitySession.bind();
        }
-       /**
-        * <p>updateReferencingObjects</p>
-        *
-        * @param entity a {@link eu.etaxonomy.cdm.model.common.IdentifiableEntity} object.
-        */
+
        public void updateReferencingObjects(final UUID entityUUID, final Class objectClass) {
 
                final Display display = Display.getCurrent();
@@ -246,9 +245,6 @@ public class ReferencingObjectsView extends AbstractCdmViewPart {
 
        class ReferencingClassComparator implements Comparator<CdmBase> {
 
-               /* (non-Javadoc)
-                * @see java.util.Comparator#compare(java.lang.Object, java.lang.Object)
-                */
                @Override
         public int compare(CdmBase o1, CdmBase o2) {
                        String string1 = o1.getClass().getSimpleName();
@@ -264,9 +260,6 @@ public class ReferencingObjectsView extends AbstractCdmViewPart {
                }
        }
 
-       /**
-        *
-        */
        private void updateView(List<CdmBase> referencingObjects) {
                if (viewer != null && !viewer.getControl().isDisposed()){
                        try{
@@ -287,6 +280,9 @@ public class ReferencingObjectsView extends AbstractCdmViewPart {
        /** {@inheritDoc} */
        @Override
     public void selectionChanged(IWorkbenchPart part, ISelection selection) {
+        if(part == this){
+            return;
+        }
                if(! (part instanceof BulkEditor)){
                        setContentDescription("");
                        showEmptyPage();
@@ -309,9 +305,6 @@ public class ReferencingObjectsView extends AbstractCdmViewPart {
                showViewer(part, lineSelection);
        }
 
-       /* (non-Javadoc)
-        * @see eu.etaxonomy.taxeditor.model.AbstractCdmViewPart#showViewer(org.eclipse.ui.IWorkbenchPart, org.eclipse.jface.viewers.ISelection)
-        */
        /** {@inheritDoc} */
        @Override
        public void showViewer(IWorkbenchPart part, IStructuredSelection selection) {
@@ -331,27 +324,18 @@ public class ReferencingObjectsView extends AbstractCdmViewPart {
 
        }
 
-       /* (non-Javadoc)
-        * @see eu.etaxonomy.taxeditor.model.AbstractCdmViewPart#getViewer()
-        */
        /** {@inheritDoc} */
        @Override
        public Viewer getViewer() {
                return viewer;
        }
 
-       /* (non-Javadoc)
-        * @see eu.etaxonomy.taxeditor.model.AbstractCdmViewPart#dirtyStateChanged()
-        */
        /** {@inheritDoc} */
        @Override
        public void changed(Object object) {
                // no editing in this view
        }
 
-       /* (non-Javadoc)
-        * @see eu.etaxonomy.taxeditor.operations.IPostOperationEnabled#onComplete()
-        */
        /** {@inheritDoc} */
        @Override
        public boolean onComplete() {
@@ -359,7 +343,6 @@ public class ReferencingObjectsView extends AbstractCdmViewPart {
        }
 
        public void refresh(){
-
                selectionService.removePostSelectionListener(this);
                selectionService.removeSelectionListener(this);
                selectionService.addPostSelectionListener(this);