ref #6925 Add generic ExpandHandler
[taxeditor.git] / eu.etaxonomy.taxeditor.navigation / src / main / java / eu / etaxonomy / taxeditor / navigation / navigator / e4 / TaxonNavigatorE4.java
index 05cc7db17d60a2888a04909106f912846b253631..32c3285037aa4d27ac8241c93ec4aa6097dcb8c2 100644 (file)
@@ -25,8 +25,6 @@ import javax.annotation.PostConstruct;
 import javax.annotation.PreDestroy;
 import javax.inject.Inject;
 
-import org.eclipse.core.commands.Command;
-import org.eclipse.core.commands.common.NotDefinedException;
 import org.eclipse.core.commands.operations.UndoContext;
 import org.eclipse.core.runtime.IAdaptable;
 import org.eclipse.core.runtime.IProgressMonitor;
@@ -35,14 +33,11 @@ import org.eclipse.e4.core.di.annotations.Optional;
 import org.eclipse.e4.ui.di.Focus;
 import org.eclipse.e4.ui.di.UIEventTopic;
 import org.eclipse.e4.ui.di.UISynchronize;
-import org.eclipse.e4.ui.model.application.commands.MCommand;
-import org.eclipse.e4.ui.model.application.commands.MCommandsFactory;
+import org.eclipse.e4.ui.model.application.MApplication;
 import org.eclipse.e4.ui.model.application.ui.basic.MPart;
-import org.eclipse.e4.ui.model.application.ui.menu.ItemType;
-import org.eclipse.e4.ui.model.application.ui.menu.MHandledToolItem;
-import org.eclipse.e4.ui.model.application.ui.menu.MMenuFactory;
-import org.eclipse.e4.ui.model.application.ui.menu.MToolBar;
 import org.eclipse.e4.ui.services.EMenuService;
+import org.eclipse.e4.ui.workbench.modeling.EModelService;
+import org.eclipse.e4.ui.workbench.modeling.EPartService;
 import org.eclipse.e4.ui.workbench.modeling.ESelectionService;
 import org.eclipse.jface.util.LocalSelectionTransfer;
 import org.eclipse.jface.viewers.ISelection;
@@ -90,6 +85,7 @@ import eu.etaxonomy.taxeditor.session.ICdmEntitySessionEnabled;
 import eu.etaxonomy.taxeditor.store.CdmStore;
 import eu.etaxonomy.taxeditor.store.LoginManager;
 import eu.etaxonomy.taxeditor.ui.element.LayoutConstants;
+import eu.etaxonomy.taxeditor.workbench.part.ICollapsableExpandable;
 
 /**
  *
@@ -99,7 +95,8 @@ import eu.etaxonomy.taxeditor.ui.element.LayoutConstants;
  */
 public class TaxonNavigatorE4 implements
                IPostOperationEnabled, IConversationEnabled, Observer,
-               ICdmEntitySessionEnabled, ICdmChangeListener, IContextListener {
+               ICdmEntitySessionEnabled, ICdmChangeListener, IContextListener,
+               ICollapsableExpandable {
 
     private static final String RESTORING_TAXON_NAVIGATOR = Messages.TaxonNavigator_RESTORE;
 
@@ -132,6 +129,15 @@ public class TaxonNavigatorE4 implements
     @Inject
     private MPart thisPart;
 
+    @Inject
+    private MApplication application;
+
+    @Inject
+    private EModelService modelService;
+
+    @Inject
+    private EPartService partService;
+
     private boolean linkWithTaxon = false;
 
     @Inject
@@ -158,7 +164,7 @@ public class TaxonNavigatorE4 implements
             if(selection instanceof IStructuredSelection){
                 Object firstElement = ((IStructuredSelection) selection).getFirstElement();
                 if(firstElement instanceof ICdmBase){
-                    NavigationUtil.openEditor((ICdmBase) firstElement, viewer.getControl().getShell());
+                    NavigationUtil.openEditor((ICdmBase) firstElement, viewer.getControl().getShell(), modelService, partService, application);
                 }
             }
         });
@@ -176,21 +182,21 @@ public class TaxonNavigatorE4 implements
         viewer.addDropSupport(dndOperations, transfers, new TreeNodeDropAdapterE4(this));
 
         //add toolbar
-        MToolBar toolBar = MMenuFactory.INSTANCE.createToolBar();
-        MHandledToolItem linkWithEditor = MMenuFactory.INSTANCE.createHandledToolItem();
-        linkWithEditor.setIconURI("platform:/plugin/eu.etaxonomy.taxeditor.store/icons/synced.gif");
-        Command command = commandService.getCommand("eu.etaxonomy.taxeditor.navigation.command.linkWithTaxon");
-        MCommand mCommand = MCommandsFactory.INSTANCE.createCommand();
-        mCommand.setElementId(command.getId());
-        try {
-            mCommand.setCommandName(command.getName());
-        } catch (NotDefinedException e) {
-            e.printStackTrace();
-        }
-        linkWithEditor.setCommand(mCommand);
-        linkWithEditor.setType(ItemType.CHECK);
-        toolBar.getChildren().add(linkWithEditor);
-        thisPart.setToolbar(toolBar);
+//        MToolBar toolBar = MMenuFactory.INSTANCE.createToolBar();
+//        MHandledToolItem linkWithEditor = MMenuFactory.INSTANCE.createHandledToolItem();
+//        linkWithEditor.setIconURI("platform:/plugin/eu.etaxonomy.taxeditor.store/icons/synced.gif");
+//        Command command = commandService.getCommand("eu.etaxonomy.taxeditor.navigation.command.linkWithTaxon");
+//        MCommand mCommand = MCommandsFactory.INSTANCE.createCommand();
+//        mCommand.setElementId(command.getId());
+//        try {
+//            mCommand.setCommandName(command.getName());
+//        } catch (NotDefinedException e) {
+//            e.printStackTrace();
+//        }
+//        linkWithEditor.setCommand(mCommand);
+//        linkWithEditor.setType(ItemType.CHECK);
+//        toolBar.getChildren().add(linkWithEditor);
+//        thisPart.setToolbar(toolBar);
 
            init();
        }
@@ -370,6 +376,22 @@ public class TaxonNavigatorE4 implements
                return new TreePath(pathList.toArray());
        }
 
+       /**
+        * {@inheritDoc}
+        */
+       @Override
+       public void collapse() {
+           viewer.collapseAll();
+       }
+
+       /**
+        * {@inheritDoc}
+        */
+       @Override
+       public void expand() {
+           viewer.expandAll();
+       }
+
        @Override
        public ConversationHolder getConversationHolder() {
                return conversation;