ref #6913 Remove executeCommand() from AbstractUtility
authorPatrick Plitzner <p.plitzner@bgbm.org>
Thu, 2 Nov 2017 09:04:14 +0000 (10:04 +0100)
committerPatrick Plitzner <p.plitzner@bgbm.org>
Thu, 2 Nov 2017 09:04:14 +0000 (10:04 +0100)
eu.etaxonomy.taxeditor.store/fragment.e4xmi
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/model/AbstractUtility.java
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/view/sessions/InspectSessionHandler.java [new file with mode: 0644]
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/view/sessions/SessionsViewPart.java

index 0e31bbf261cf129f48a9cff62f16a5aa68dad709..c7bf09bcb6b42ba8fcf3c469a7fb359c559d0c32 100644 (file)
@@ -5,6 +5,7 @@
   <fragments xsi:type="fragment:StringModelFragment" xmi:id="_xVa1wCXXEeex9MwMOgUeWw" featurename="descriptors" parentElementId="xpath:/">
     <elements xsi:type="basic:PartDescriptor" xmi:id="_2xmxoCXXEeex9MwMOgUeWw" elementId="eu.etaxonomy.taxeditor.view.sessions.SessionsViewPart" label="%view.name.SESSIONS" iconURI="platform:/plugin/eu.etaxonomy.taxeditor.store/icons/applications-office.png" closeable="true" contributionURI="bundleclass://eu.etaxonomy.taxeditor.store/eu.etaxonomy.taxeditor.view.sessions.SessionsViewPart">
       <tags>nonRestore</tags>
+      <handlers xmi:id="_gbMXAL-rEeegz7IDD8MJaw" elementId="eu.etaxonomy.taxeditor.view.sessions.InspectSessionHandler" contributionURI="bundleclass://eu.etaxonomy.taxeditor.store/eu.etaxonomy.taxeditor.view.sessions.InspectSessionHandler" command="_dQ0swL-rEeegz7IDD8MJaw"/>
     </elements>
     <elements xsi:type="basic:PartDescriptor" xmi:id="_J-3UEEqgEeeN-dEYnw7m3g" elementId="eu.etaxonomy.taxeditor.featuretree.e4.FeatureTreeEditor" label="%partdescriptor.label.featureTreeEditor" allowMultiple="true" closeable="true" dirtyable="true" contributionURI="bundleclass://eu.etaxonomy.taxeditor.store/eu.etaxonomy.taxeditor.featuretree.e4.FeatureTreeEditor">
       <tags>nonRestore</tags>
     <elements xsi:type="commands:Command" xmi:id="_bfjZwK2fEeeykrJkROy5EA" elementId="eu.etaxonomy.taxeditor.store.open.OpenDistributionEditorWizardHandler" commandName="%command.name.11"/>
     <elements xsi:type="commands:Command" xmi:id="_KQP_sK2gEeeykrJkROy5EA" elementId="eu.etaxonomy.taxeditor.store.operations.reconnect" commandName="%command.name.RE_CONNECT"/>
     <elements xsi:type="commands:Command" xmi:id="_SXZF8K2gEeeykrJkROy5EA" elementId="eu.etaxonomy.taxeditor.store.openPasswordWizzard" commandName="%command.name.10"/>
+    <elements xsi:type="commands:Command" xmi:id="_dQ0swL-rEeegz7IDD8MJaw" elementId="eu.etaxonomy.taxeditor.store.open.InspectSessionsDialog" commandName="Inspect Session"/>
   </fragments>
   <fragments xsi:type="fragment:StringModelFragment" xmi:id="_swGH0GhvEee3K4uKJljEYg" featurename="handlers" parentElementId="xpath:/">
     <elements xsi:type="commands:Handler" xmi:id="_rVEdIGcjEee0qLTtA2ZpVQ" elementId="eu.etaxonomy.taxeditor.featuretree.e4.handler.RemoveFeatureHandler" contributionURI="bundleclass://eu.etaxonomy.taxeditor.store/eu.etaxonomy.taxeditor.featuretree.e4.handler.RemoveFeatureHandler" command="_fNBtQGcjEee0qLTtA2ZpVQ"/>
index 9904a92c2809fea8c3c6475a41219a7cf50d0193..ffb2879bcb1797f6ab661d2195b243efc8714d6c 100644 (file)
@@ -30,9 +30,6 @@ import java.util.zip.ZipOutputStream;
 import org.apache.commons.lang.StringUtils;
 import org.apache.log4j.Logger;
 import org.eclipse.core.commands.ExecutionException;
-import org.eclipse.core.commands.NotEnabledException;
-import org.eclipse.core.commands.NotHandledException;
-import org.eclipse.core.commands.common.NotDefinedException;
 import org.eclipse.core.commands.operations.AbstractOperation;
 import org.eclipse.core.commands.operations.IOperationHistory;
 import org.eclipse.core.runtime.IAdaptable;
@@ -56,7 +53,6 @@ import org.eclipse.swt.widgets.Display;
 import org.eclipse.swt.widgets.Shell;
 import org.eclipse.ui.IWorkbench;
 import org.eclipse.ui.PlatformUI;
-import org.eclipse.ui.handlers.IHandlerService;
 import org.eclipse.ui.ide.undo.WorkspaceUndoUtil;
 import org.eclipse.ui.progress.IProgressConstants;
 import org.eclipse.ui.progress.IProgressService;
@@ -669,32 +665,6 @@ public abstract class AbstractUtility {
         }
     }
 
-
-    public static void executeCommand(String commandId, Object source, String pluginId) {
-        IHandlerService handlerService = (IHandlerService) AbstractUtility.getService(IHandlerService.class);
-        Exception exception = null;
-        try {
-            handlerService.executeCommand(commandId, null);
-        } catch (ExecutionException e) {
-            exception = e;
-        } catch (NotDefinedException e) {
-            exception = e;
-        } catch (NotEnabledException e) {
-            exception = e;
-        } catch (NotHandledException e) {
-            exception = e;
-        } finally {
-            if(exception != null) {
-                MessagingUtils.errorDialog("Error executing command",
-                        source,
-                        "Could not execute command with id " + commandId ,
-                        pluginId,
-                        exception,
-                        true);
-            }
-        }
-    }
-
     public static Object getElementsFromSelectionChangedEvent(SelectionChangedEvent event) {
         IStructuredSelection selection = (IStructuredSelection) event.getSelection();
         Object selectionToSet = selection;
diff --git a/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/view/sessions/InspectSessionHandler.java b/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/view/sessions/InspectSessionHandler.java
new file mode 100644 (file)
index 0000000..c67129e
--- /dev/null
@@ -0,0 +1,30 @@
+/**
+* Copyright (C) 2017 EDIT
+* European Distributed Institute of Taxonomy
+* http://www.e-taxonomy.eu
+*
+* The contents of this file are subject to the Mozilla Public License Version 1.1
+* See LICENSE.TXT at the top of this package for the full license terms.
+*/
+package eu.etaxonomy.taxeditor.view.sessions;
+
+import javax.inject.Named;
+
+import org.eclipse.e4.core.di.annotations.Execute;
+import org.eclipse.e4.ui.services.IServiceConstants;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.widgets.Shell;
+
+/**
+ * @author pplitzner
+ * @since Nov 2, 2017
+ *
+ */
+public class InspectSessionHandler {
+
+    @Execute
+    public void canExecute(@Named(IServiceConstants.ACTIVE_SHELL)Shell shell){
+        InspectSessionsDialog dialog = new InspectSessionsDialog(shell, SWT.NONE);
+        dialog.open();
+    }
+}
index 368c3ff024acd07a79d471a9a85c407a6f76ee6b..d696de710bc4255135c40494ac94723b80b5ae36 100644 (file)
@@ -14,6 +14,10 @@ import java.util.Collection;
 import javax.annotation.PostConstruct;
 import javax.inject.Inject;
 
+import org.eclipse.core.commands.Command;
+import org.eclipse.core.commands.ParameterizedCommand;
+import org.eclipse.e4.core.commands.ECommandService;
+import org.eclipse.e4.core.commands.EHandlerService;
 import org.eclipse.swt.SWT;
 import org.eclipse.swt.events.SelectionAdapter;
 import org.eclipse.swt.events.SelectionEvent;
@@ -29,7 +33,6 @@ import org.eclipse.swt.widgets.Text;
 import org.eclipse.wb.swt.SWTResourceManager;
 
 import eu.etaxonomy.cdm.api.cache.CdmCacher;
-import eu.etaxonomy.taxeditor.model.AbstractUtility;
 import eu.etaxonomy.taxeditor.remoting.cache.CdmRemoteCacheManager;
 import eu.etaxonomy.taxeditor.session.ICdmEntitySession;
 import eu.etaxonomy.taxeditor.session.ICdmEntitySessionManager;
@@ -61,6 +64,12 @@ public class SessionsViewPart implements ICdmEntitySessionManagerObserver {
     private Text txtCdmModelOnDisk;
     private Text txtDefaultOnDisk;
 
+    @Inject
+    private ECommandService commandService;
+
+    @Inject
+    private EHandlerService handlerService;
+
     @Inject
     public SessionsViewPart() {
         this.cdmEntitySessionManager = CdmStore.getCurrentSessionManager();
@@ -210,7 +219,8 @@ public class SessionsViewPart implements ICdmEntitySessionManagerObserver {
             btnInspectActiveSession.addSelectionListener(new SelectionAdapter() {
                 @Override
                 public void widgetSelected(SelectionEvent e) {
-                    AbstractUtility.executeCommand(OPEN_INSPECT_SESSIONS_DIALOG_ID, this, null);
+                    Command command = commandService.getCommand(OPEN_INSPECT_SESSIONS_DIALOG_ID);
+                    handlerService.executeHandler(ParameterizedCommand.generateCommand(command, null));
                 }
             });
             btnInspectActiveSession.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false, 2, 1));