From fb8c3106527706556bfa777257dd539efb1d5672 Mon Sep 17 00:00:00 2001 From: Rike Meyer Date: Mon, 14 Dec 2020 16:02:29 +0100 Subject: [PATCH 1/3] [UI][E] Menu Migration from Eclipse3 to Eclipse4 Migration of the Main-Menu, as well as all Commands and Handlers to the E4 Platform. Explanation: Since 2012 Saros/E uses the compatibility layer provided by Eclipse for the UI to function. To drop the need for the compatibility layer all UI Elements have to be migrated and all references to org.eclipse.ui have to be removed. --- eclipse/META-INF/MANIFEST.MF | 17 +- eclipse/build.gradle.kts | 3 + eclipse/fragment.e4xmi | 73 +++ eclipse/plugin.xml | 429 ++---------------- eclipse/src/saros/Saros.java | 14 +- .../command_handlers/AddContactHandler.java | 24 +- .../AddXMPPAccountHandler.java | 10 +- .../CreateXMPPAccountHandler.java | 10 +- .../GettingStartedHandler.java | 12 +- .../OpenSarosPreferencesHandler.java | 11 +- .../SessionAddContactsHandler.java | 29 +- .../SessionAddResourcesHandler.java | 30 +- .../SessionAddSelectedContactsHandler.java | 38 +- .../SessionAddSelectedResourcesHandler.java | 46 +- .../command_handlers/SessionLeaveHandler.java | 29 +- .../ShareResourcesHandler.java | 30 +- .../StartSarosConfigurationHandler.java | 10 +- eclipse/src/saros/ui/util/SWTUtils.java | 7 +- stf/build.gradle.kts | 3 + 19 files changed, 359 insertions(+), 466 deletions(-) create mode 100644 eclipse/fragment.e4xmi diff --git a/eclipse/META-INF/MANIFEST.MF b/eclipse/META-INF/MANIFEST.MF index 964becbc8e..1c6fdd5d98 100644 --- a/eclipse/META-INF/MANIFEST.MF +++ b/eclipse/META-INF/MANIFEST.MF @@ -20,7 +20,18 @@ Require-Bundle: org.eclipse.ui, org.eclipse.equinox.security, org.junit;resolution:=optional, org.eclipse.jdt.launching;resolution:=optional, - saros.core + org.eclipse.e4.ui.model.workbench, + org.eclipse.e4.ui.di, + org.eclipse.osgi, + org.eclipse.e4.ui.services, + org.eclipse.e4.core.di.annotations, + saros.core, + org.eclipse.osgi.services, + org.eclipse.e4.ui.workbench, + org.eclipse.equinox.ds, + org.eclipse.equinox.event, + org.eclipse.equinox.util, + org.eclipse.e4.ui.workbench.addons.swt Bundle-ActivationPolicy: lazy Export-Package: saros; uses:="org.eclipse.core.runtime, @@ -129,4 +140,6 @@ Export-Package: saros; saros.util;uses:="org.eclipse.core.resources,org.jivesoftware.smack.packet" Bundle-Vendor: Saros Project Bundle-RequiredExecutionEnvironment: JavaSE-1.8 -Import-Package: org.eclipse.core.filesystem \ No newline at end of file +Import-Package: javax.annotation;version="1.2.0", + javax.inject, + org.eclipse.core.filesystem diff --git a/eclipse/build.gradle.kts b/eclipse/build.gradle.kts index 2ddf6d5b04..407eeedb82 100644 --- a/eclipse/build.gradle.kts +++ b/eclipse/build.gradle.kts @@ -45,6 +45,9 @@ dependencies { // This is a workaround for https://github.com/saros-project/saros/issues/1114 implementation("org.eclipse.platform:org.eclipse.ui.ide:3.17.200") implementation("org.eclipse.platform:org.eclipse.ui.workbench:3.120.0") + // This is a workaround for an Issues, same as https://github.com/saros-project/saros/issues/1114 + implementation("org.eclipse.platform:org.eclipse.e4.ui.services:1.3.700") + implementation("javax.inject:javax.inject:1") testImplementation(project(path = ":saros.core", configuration = "testing")) } diff --git a/eclipse/fragment.e4xmi b/eclipse/fragment.e4xmi new file mode 100644 index 0000000000..6c5565c79e --- /dev/null +++ b/eclipse/fragment.e4xmi @@ -0,0 +1,73 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/eclipse/plugin.xml b/eclipse/plugin.xml index 28d01713c5..2c14cf2eff 100644 --- a/eclipse/plugin.xml +++ b/eclipse/plugin.xml @@ -2,6 +2,12 @@ + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -1088,6 +707,20 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/eclipse/src/saros/Saros.java b/eclipse/src/saros/Saros.java index 9d9edc6ab5..b7adbb1e29 100644 --- a/eclipse/src/saros/Saros.java +++ b/eclipse/src/saros/Saros.java @@ -3,6 +3,7 @@ import java.io.File; import java.io.InputStream; import java.util.concurrent.atomic.AtomicBoolean; +import javax.inject.Inject; import org.apache.log4j.Logger; import org.apache.logging.log4j.Level; import org.apache.logging.log4j.core.config.ConfigurationSource; @@ -11,12 +12,16 @@ import org.apache.logging.log4j.status.StatusLogger; import org.eclipse.core.runtime.Platform; import org.eclipse.core.runtime.preferences.ConfigurationScope; +import org.eclipse.e4.core.di.annotations.Optional; +import org.eclipse.e4.ui.di.UIEventTopic; +import org.eclipse.e4.ui.workbench.UIEvents; import org.eclipse.swt.SWTException; import org.eclipse.swt.widgets.Display; import org.eclipse.ui.IWorkbench; import org.eclipse.ui.IWorkbenchListener; import org.eclipse.ui.plugin.AbstractUIPlugin; import org.osgi.framework.BundleContext; +import org.osgi.service.event.Event; import org.osgi.service.prefs.BackingStoreException; import org.osgi.service.prefs.Preferences; import saros.annotations.Component; @@ -130,10 +135,17 @@ public void start(BundleContext context) throws Exception { isLifecycleStarted = true; - getWorkbench().addWorkbenchListener(workbenchShutdownListener); isInitialized = true; } + @Inject + @Optional + public void applicationStarted( + @UIEventTopic(UIEvents.UILifeCycle.APP_STARTUP_COMPLETE) Event event, Saros saros) { + + saros.getWorkbench().addWorkbenchListener(saros.workbenchShutdownListener); + } + @Override public void stop(BundleContext context) throws Exception { diff --git a/eclipse/src/saros/ui/command_handlers/AddContactHandler.java b/eclipse/src/saros/ui/command_handlers/AddContactHandler.java index f7b27fed3c..b775d6fc36 100644 --- a/eclipse/src/saros/ui/command_handlers/AddContactHandler.java +++ b/eclipse/src/saros/ui/command_handlers/AddContactHandler.java @@ -1,15 +1,27 @@ package saros.ui.command_handlers; -import org.eclipse.core.commands.AbstractHandler; -import org.eclipse.core.commands.ExecutionEvent; -import org.eclipse.core.commands.ExecutionException; +import org.eclipse.e4.core.di.annotations.CanExecute; +import org.eclipse.e4.core.di.annotations.Execute; +import saros.SarosPluginContext; +import saros.communication.connection.ConnectionHandler; +import saros.repackaged.picocontainer.annotations.Inject; import saros.ui.util.WizardUtils; -public class AddContactHandler extends AbstractHandler { +public class AddContactHandler { + @Inject private ConnectionHandler connectionHandler; - @Override - public Object execute(ExecutionEvent event) throws ExecutionException { + public AddContactHandler() { + SarosPluginContext.initComponent(this); + } + + @Execute + public Object execute() { WizardUtils.openAddContactWizard(); return null; } + + @CanExecute + public boolean canExecute() { + return connectionHandler != null && connectionHandler.isConnected(); + } } diff --git a/eclipse/src/saros/ui/command_handlers/AddXMPPAccountHandler.java b/eclipse/src/saros/ui/command_handlers/AddXMPPAccountHandler.java index 62f228759b..95bc54946b 100644 --- a/eclipse/src/saros/ui/command_handlers/AddXMPPAccountHandler.java +++ b/eclipse/src/saros/ui/command_handlers/AddXMPPAccountHandler.java @@ -1,14 +1,12 @@ package saros.ui.command_handlers; -import org.eclipse.core.commands.AbstractHandler; -import org.eclipse.core.commands.ExecutionEvent; -import org.eclipse.core.commands.ExecutionException; +import org.eclipse.e4.core.di.annotations.Execute; import saros.ui.util.WizardUtils; -public class AddXMPPAccountHandler extends AbstractHandler { +public class AddXMPPAccountHandler { - @Override - public Object execute(ExecutionEvent event) throws ExecutionException { + @Execute + public Object execute() { WizardUtils.openAddXMPPAccountWizard(); return null; } diff --git a/eclipse/src/saros/ui/command_handlers/CreateXMPPAccountHandler.java b/eclipse/src/saros/ui/command_handlers/CreateXMPPAccountHandler.java index eee81f8206..921315e176 100644 --- a/eclipse/src/saros/ui/command_handlers/CreateXMPPAccountHandler.java +++ b/eclipse/src/saros/ui/command_handlers/CreateXMPPAccountHandler.java @@ -1,14 +1,12 @@ package saros.ui.command_handlers; -import org.eclipse.core.commands.AbstractHandler; -import org.eclipse.core.commands.ExecutionEvent; -import org.eclipse.core.commands.ExecutionException; +import org.eclipse.e4.core.di.annotations.Execute; import saros.ui.util.WizardUtils; -public class CreateXMPPAccountHandler extends AbstractHandler { +public class CreateXMPPAccountHandler { - @Override - public Object execute(ExecutionEvent event) throws ExecutionException { + @Execute + public Object execute() { WizardUtils.openCreateXMPPAccountWizard(true); diff --git a/eclipse/src/saros/ui/command_handlers/GettingStartedHandler.java b/eclipse/src/saros/ui/command_handlers/GettingStartedHandler.java index 9dc9a9cc1b..6d24ed9017 100644 --- a/eclipse/src/saros/ui/command_handlers/GettingStartedHandler.java +++ b/eclipse/src/saros/ui/command_handlers/GettingStartedHandler.java @@ -1,18 +1,14 @@ package saros.ui.command_handlers; -import org.eclipse.core.commands.AbstractHandler; -import org.eclipse.core.commands.ExecutionEvent; -import org.eclipse.core.commands.ExecutionException; +import org.eclipse.e4.core.di.annotations.Execute; import saros.ui.util.SWTUtils; -public class GettingStartedHandler extends AbstractHandler { +public class GettingStartedHandler { - @Override - public Object execute(ExecutionEvent event) throws ExecutionException { + @Execute + public void execute() { SWTUtils.openInternalBrowser( "https://www.saros-project.org/documentation/getting-started.html", "Welcome to Saros"); - - return null; } } diff --git a/eclipse/src/saros/ui/command_handlers/OpenSarosPreferencesHandler.java b/eclipse/src/saros/ui/command_handlers/OpenSarosPreferencesHandler.java index 1ff118f79d..114b557020 100644 --- a/eclipse/src/saros/ui/command_handlers/OpenSarosPreferencesHandler.java +++ b/eclipse/src/saros/ui/command_handlers/OpenSarosPreferencesHandler.java @@ -1,19 +1,16 @@ package saros.ui.command_handlers; -import org.eclipse.core.commands.AbstractHandler; -import org.eclipse.core.commands.ExecutionEvent; -import org.eclipse.core.commands.ExecutionException; +import org.eclipse.e4.core.di.annotations.Execute; import org.eclipse.jface.preference.PreferenceDialog; import org.eclipse.ui.dialogs.PreferencesUtil; -public class OpenSarosPreferencesHandler extends AbstractHandler { +public class OpenSarosPreferencesHandler { - @Override - public Object execute(ExecutionEvent event) throws ExecutionException { + @Execute + public Object execute() { PreferenceDialog pref = PreferencesUtil.createPreferenceDialogOn(null, "saros.preferences", null, null); if (pref != null) pref.open(); - return null; } } diff --git a/eclipse/src/saros/ui/command_handlers/SessionAddContactsHandler.java b/eclipse/src/saros/ui/command_handlers/SessionAddContactsHandler.java index 0b62b50e27..133f332950 100644 --- a/eclipse/src/saros/ui/command_handlers/SessionAddContactsHandler.java +++ b/eclipse/src/saros/ui/command_handlers/SessionAddContactsHandler.java @@ -1,10 +1,13 @@ package saros.ui.command_handlers; -import org.eclipse.core.commands.AbstractHandler; -import org.eclipse.core.commands.ExecutionEvent; -import org.eclipse.core.commands.ExecutionException; +import org.eclipse.e4.core.di.annotations.CanExecute; +import org.eclipse.e4.core.di.annotations.Execute; +import saros.SarosPluginContext; +import saros.communication.connection.ConnectionHandler; import saros.net.xmpp.JID; +import saros.repackaged.picocontainer.annotations.Inject; import saros.session.ISarosSession; +import saros.session.ISarosSessionManager; import saros.ui.util.WizardUtils; import saros.ui.wizards.AddResourcesToSessionWizard; @@ -12,11 +15,25 @@ * Handles the addition of {@link JID}s that must explicitly be selected in the opening {@link * AddResourcesToSessionWizard} to the running {@link ISarosSession}. */ -public class SessionAddContactsHandler extends AbstractHandler { +public class SessionAddContactsHandler { + @Inject private ConnectionHandler connectionHandler; + @Inject private ISarosSessionManager sessionManager; - @Override - public Object execute(ExecutionEvent event) throws ExecutionException { + public SessionAddContactsHandler() { + SarosPluginContext.initComponent(this); + } + + @Execute + public Object execute() { WizardUtils.openAddContactsToSessionWizard(); return null; } + + @CanExecute + public boolean canExecute() { + return connectionHandler != null + && connectionHandler.isConnected() + && sessionManager != null + && sessionManager.getSession() != null; + } } diff --git a/eclipse/src/saros/ui/command_handlers/SessionAddResourcesHandler.java b/eclipse/src/saros/ui/command_handlers/SessionAddResourcesHandler.java index 81f60f2564..b9d3ccb742 100644 --- a/eclipse/src/saros/ui/command_handlers/SessionAddResourcesHandler.java +++ b/eclipse/src/saros/ui/command_handlers/SessionAddResourcesHandler.java @@ -1,10 +1,13 @@ package saros.ui.command_handlers; -import org.eclipse.core.commands.AbstractHandler; -import org.eclipse.core.commands.ExecutionEvent; -import org.eclipse.core.commands.ExecutionException; import org.eclipse.core.resources.IResource; +import org.eclipse.e4.core.di.annotations.CanExecute; +import org.eclipse.e4.core.di.annotations.Execute; +import saros.SarosPluginContext; +import saros.communication.connection.ConnectionHandler; +import saros.repackaged.picocontainer.annotations.Inject; import saros.session.ISarosSession; +import saros.session.ISarosSessionManager; import saros.ui.util.WizardUtils; import saros.ui.wizards.AddResourcesToSessionWizard; @@ -15,11 +18,26 @@ *

This class is used to define the behavior of the saros menu entry to add reference points to a * running session. */ -public class SessionAddResourcesHandler extends AbstractHandler { +public class SessionAddResourcesHandler { + @Inject private ConnectionHandler connectionHandler; + @Inject private ISarosSessionManager sessionManager; - @Override - public Object execute(ExecutionEvent event) throws ExecutionException { + public SessionAddResourcesHandler() { + SarosPluginContext.initComponent(this); + } + + @Execute + public Object execute() { WizardUtils.openAddResourcesToSessionWizard(null); return null; } + + @CanExecute + public boolean canExecute() { + return connectionHandler != null + && connectionHandler.isConnected() + && sessionManager != null + && sessionManager.getSession() != null + && sessionManager.getSession().hasWriteAccess(); + } } diff --git a/eclipse/src/saros/ui/command_handlers/SessionAddSelectedContactsHandler.java b/eclipse/src/saros/ui/command_handlers/SessionAddSelectedContactsHandler.java index 3c1335fb0c..009a408c46 100644 --- a/eclipse/src/saros/ui/command_handlers/SessionAddSelectedContactsHandler.java +++ b/eclipse/src/saros/ui/command_handlers/SessionAddSelectedContactsHandler.java @@ -1,23 +1,49 @@ package saros.ui.command_handlers; import java.util.List; -import org.eclipse.core.commands.AbstractHandler; -import org.eclipse.core.commands.ExecutionEvent; -import org.eclipse.core.commands.ExecutionException; +import javax.inject.Named; +import org.eclipse.e4.core.di.annotations.CanExecute; +import org.eclipse.e4.core.di.annotations.Execute; +import org.eclipse.e4.core.di.annotations.Optional; +import org.eclipse.e4.ui.services.IServiceConstants; +import saros.SarosPluginContext; +import saros.communication.connection.ConnectionHandler; import saros.net.xmpp.JID; +import saros.net.xmpp.contact.XMPPContactsService; +import saros.repackaged.picocontainer.annotations.Inject; import saros.session.ISarosSession; +import saros.session.ISarosSessionManager; import saros.ui.util.CollaborationUtils; import saros.ui.util.selection.retriever.SelectionRetrieverFactory; /** Handles the addition of selected {@link JID}s to the running {@link ISarosSession}. */ -public class SessionAddSelectedContactsHandler extends AbstractHandler { +public class SessionAddSelectedContactsHandler { - @Override - public Object execute(ExecutionEvent event) throws ExecutionException { + @Inject private ConnectionHandler connectionHandler; + @Inject private ISarosSessionManager sessionManager; + @Inject private XMPPContactsService contactsService; + + public SessionAddSelectedContactsHandler() { + SarosPluginContext.initComponent(this); + } + + @Execute + public Object execute() { List jids = SelectionRetrieverFactory.getSelectionRetriever(JID.class).getSelection(); CollaborationUtils.addContactsToSession(jids); return null; } + + @CanExecute + public boolean canExecute(@Named(IServiceConstants.ACTIVE_SELECTION) @Optional JID contact) { + final JID jid = contact; + return (connectionHandler != null + && connectionHandler.isConnected() + && sessionManager != null + && sessionManager.getSession() != null + && sessionManager.getSession().hasWriteAccess() + && !sessionManager.getSession().getUsers().stream().anyMatch(u -> u.getJID().equals(jid))); + } } diff --git a/eclipse/src/saros/ui/command_handlers/SessionAddSelectedResourcesHandler.java b/eclipse/src/saros/ui/command_handlers/SessionAddSelectedResourcesHandler.java index 391f7c3556..932110cb7e 100644 --- a/eclipse/src/saros/ui/command_handlers/SessionAddSelectedResourcesHandler.java +++ b/eclipse/src/saros/ui/command_handlers/SessionAddSelectedResourcesHandler.java @@ -2,11 +2,21 @@ import java.util.HashSet; import java.util.List; -import org.eclipse.core.commands.AbstractHandler; -import org.eclipse.core.commands.ExecutionEvent; -import org.eclipse.core.commands.ExecutionException; +import java.util.Set; +import javax.inject.Named; import org.eclipse.core.resources.IResource; +import org.eclipse.e4.core.di.annotations.CanExecute; +import org.eclipse.e4.core.di.annotations.Execute; +import org.eclipse.e4.core.di.annotations.Optional; +import org.eclipse.e4.ui.services.IServiceConstants; +import saros.SarosPluginContext; +import saros.communication.connection.ConnectionHandler; +import saros.filesystem.IReferencePoint; +import saros.filesystem.ResourceConverter; +import saros.repackaged.picocontainer.annotations.Inject; import saros.session.ISarosSession; +import saros.session.ISarosSessionManager; +import saros.ui.expressions.ResourcePropertyTester; import saros.ui.util.WizardUtils; import saros.ui.util.selection.retriever.SelectionRetrieverFactory; @@ -19,10 +29,17 @@ *

This class is used to define the behavior of the package explorer context menu entry to add * reference points to a running session. */ -public class SessionAddSelectedResourcesHandler extends AbstractHandler { +public class SessionAddSelectedResourcesHandler { + @Inject private ConnectionHandler connectionHandler; + @Inject private ISarosSessionManager sessionManager; + @Inject private ResourcePropertyTester resourcePropertyTester; - @Override - public Object execute(ExecutionEvent event) throws ExecutionException { + public SessionAddSelectedResourcesHandler() { + SarosPluginContext.initComponent(this); + } + + @Execute + public Object execute() { List selectedResources = SelectionRetrieverFactory.getSelectionRetriever(IResource.class).getSelection(); @@ -31,4 +48,21 @@ public Object execute(ExecutionEvent event) throws ExecutionException { return null; } + + @CanExecute + public boolean canExecute( + @Named(IServiceConstants.ACTIVE_SELECTION) @Optional IResource resource) { + if (!(connectionHandler != null + && connectionHandler.isConnected() + && sessionManager != null + && sessionManager.getSession() != null + && sessionManager.getSession().hasWriteAccess())) { + return false; + } + final ISarosSession session = sessionManager.getSession(); + Set sharedReferencePoints = session.getReferencePoints(); + saros.filesystem.IResource wrappedResource = + ResourceConverter.convertToResource(sharedReferencePoints, resource); + return !session.isShared(wrappedResource); + } } diff --git a/eclipse/src/saros/ui/command_handlers/SessionLeaveHandler.java b/eclipse/src/saros/ui/command_handlers/SessionLeaveHandler.java index a0942cee0c..33601e0496 100644 --- a/eclipse/src/saros/ui/command_handlers/SessionLeaveHandler.java +++ b/eclipse/src/saros/ui/command_handlers/SessionLeaveHandler.java @@ -1,15 +1,32 @@ package saros.ui.command_handlers; -import org.eclipse.core.commands.AbstractHandler; -import org.eclipse.core.commands.ExecutionEvent; -import org.eclipse.core.commands.ExecutionException; +import org.eclipse.e4.core.di.annotations.CanExecute; +import org.eclipse.e4.core.di.annotations.Execute; +import saros.SarosPluginContext; +import saros.communication.connection.ConnectionHandler; +import saros.repackaged.picocontainer.annotations.Inject; +import saros.session.ISarosSessionManager; import saros.ui.util.CollaborationUtils; -public class SessionLeaveHandler extends AbstractHandler { +public class SessionLeaveHandler { + @Inject private ConnectionHandler connectionHandler; + @Inject private ISarosSessionManager sessionManager; - @Override - public Object execute(ExecutionEvent event) throws ExecutionException { + public SessionLeaveHandler() { + SarosPluginContext.initComponent(this); + } + + @Execute + public Object execute() { CollaborationUtils.leaveSession(); return null; } + + @CanExecute + public boolean canExecute() { + return connectionHandler != null + && connectionHandler.isConnected() + && sessionManager != null + && sessionManager.getSession() != null; + } } diff --git a/eclipse/src/saros/ui/command_handlers/ShareResourcesHandler.java b/eclipse/src/saros/ui/command_handlers/ShareResourcesHandler.java index 3220ba4292..b85a7d02cb 100644 --- a/eclipse/src/saros/ui/command_handlers/ShareResourcesHandler.java +++ b/eclipse/src/saros/ui/command_handlers/ShareResourcesHandler.java @@ -1,9 +1,12 @@ package saros.ui.command_handlers; -import org.eclipse.core.commands.AbstractHandler; -import org.eclipse.core.commands.ExecutionEvent; -import org.eclipse.core.commands.ExecutionException; import org.eclipse.core.resources.IResource; +import org.eclipse.e4.core.di.annotations.CanExecute; +import org.eclipse.e4.core.di.annotations.Execute; +import saros.SarosPluginContext; +import saros.communication.connection.ConnectionHandler; +import saros.repackaged.picocontainer.annotations.Inject; +import saros.session.ISarosSessionManager; import saros.ui.menu_contributions.StartSessionWithProjects; import saros.ui.util.WizardUtils; import saros.ui.util.selection.retriever.SelectionRetrieverFactory; @@ -35,12 +38,27 @@ * *

Notice that this is done via the {@link saros.ui.wizards.StartSessionWizard}. */ -public class ShareResourcesHandler extends AbstractHandler { +public class ShareResourcesHandler { - @Override - public Object execute(ExecutionEvent event) throws ExecutionException { + @Inject private ConnectionHandler connectionHandler; + @Inject private ISarosSessionManager sessionManager; + + public ShareResourcesHandler() { + SarosPluginContext.initComponent(this); + } + + @Execute + public Object execute() { WizardUtils.openStartSessionWizard( SelectionRetrieverFactory.getSelectionRetriever(IResource.class).getSelection()); return null; } + + @CanExecute + public boolean canExecute() { + return connectionHandler != null + && connectionHandler.isConnected() + && sessionManager != null + && sessionManager.getSession() == null; + } } diff --git a/eclipse/src/saros/ui/command_handlers/StartSarosConfigurationHandler.java b/eclipse/src/saros/ui/command_handlers/StartSarosConfigurationHandler.java index df54518659..37c730bdb1 100644 --- a/eclipse/src/saros/ui/command_handlers/StartSarosConfigurationHandler.java +++ b/eclipse/src/saros/ui/command_handlers/StartSarosConfigurationHandler.java @@ -1,14 +1,12 @@ package saros.ui.command_handlers; -import org.eclipse.core.commands.AbstractHandler; -import org.eclipse.core.commands.ExecutionEvent; -import org.eclipse.core.commands.ExecutionException; +import org.eclipse.e4.core.di.annotations.Execute; import saros.ui.util.WizardUtils; -public class StartSarosConfigurationHandler extends AbstractHandler { +public class StartSarosConfigurationHandler { - @Override - public Object execute(ExecutionEvent event) throws ExecutionException { + @Execute + public Object execute() { WizardUtils.openSarosConfigurationWizard(); return null; } diff --git a/eclipse/src/saros/ui/util/SWTUtils.java b/eclipse/src/saros/ui/util/SWTUtils.java index c92eeb658b..857c8691f0 100644 --- a/eclipse/src/saros/ui/util/SWTUtils.java +++ b/eclipse/src/saros/ui/util/SWTUtils.java @@ -187,7 +187,12 @@ public static void runSafeSWTSync(final Logger log, final Runnable runnable) { * @return the display of the current workbench */ public static Display getDisplay() { - return PlatformUI.getWorkbench().getDisplay(); + // return PlatformUI.getWorkbench().getDisplay(); + Display display = Display.getCurrent(); + if (display == null) { + display = Display.getDefault(); + } + return display; } /** diff --git a/stf/build.gradle.kts b/stf/build.gradle.kts index efc7af91a5..460c972942 100644 --- a/stf/build.gradle.kts +++ b/stf/build.gradle.kts @@ -33,6 +33,9 @@ dependencies { // This is a workaround for https://github.com/saros-project/saros/issues/1114 implementation("org.eclipse.platform:org.eclipse.ui.ide:3.17.200") implementation("org.eclipse.platform:org.eclipse.ui.workbench:3.120.0") + // This is a workaround for an Issues, same as https://github.com/saros-project/saros/issues/1114 + implementation("org.eclipse.platform:org.eclipse.e4.ui.services:1.3.700") + implementation("javax.inject:javax.inject:1") compile(project(path = ":saros.eclipse", configuration = "testing")) releaseDep(fileTree("libs")) From 0d392bfb1375cb8e5a87c74f7e6c30380ddd6cfc Mon Sep 17 00:00:00 2001 From: Erik Antes Date: Mon, 8 Feb 2021 11:38:42 +0100 Subject: [PATCH 2/3] [UI][E] Menu Migration Fix session null checks Fix ActiveSelection Resource Conversion Remove unecessary injected Fields --- .../command_handlers/AddContactHandler.java | 2 +- .../SessionAddContactsHandler.java | 5 +-- .../SessionAddResourcesHandler.java | 7 ++-- .../SessionAddSelectedContactsHandler.java | 30 +++++++++-------- .../SessionAddSelectedResourcesHandler.java | 32 +++++++++++-------- .../command_handlers/SessionLeaveHandler.java | 5 +-- .../ShareResourcesHandler.java | 15 +++++---- 7 files changed, 48 insertions(+), 48 deletions(-) diff --git a/eclipse/src/saros/ui/command_handlers/AddContactHandler.java b/eclipse/src/saros/ui/command_handlers/AddContactHandler.java index b775d6fc36..5b8e5f5fbf 100644 --- a/eclipse/src/saros/ui/command_handlers/AddContactHandler.java +++ b/eclipse/src/saros/ui/command_handlers/AddContactHandler.java @@ -22,6 +22,6 @@ public Object execute() { @CanExecute public boolean canExecute() { - return connectionHandler != null && connectionHandler.isConnected(); + return connectionHandler.isConnected(); } } diff --git a/eclipse/src/saros/ui/command_handlers/SessionAddContactsHandler.java b/eclipse/src/saros/ui/command_handlers/SessionAddContactsHandler.java index 133f332950..230cdb82c7 100644 --- a/eclipse/src/saros/ui/command_handlers/SessionAddContactsHandler.java +++ b/eclipse/src/saros/ui/command_handlers/SessionAddContactsHandler.java @@ -31,9 +31,6 @@ public Object execute() { @CanExecute public boolean canExecute() { - return connectionHandler != null - && connectionHandler.isConnected() - && sessionManager != null - && sessionManager.getSession() != null; + return connectionHandler.isConnected() && sessionManager.getSession() != null; } } diff --git a/eclipse/src/saros/ui/command_handlers/SessionAddResourcesHandler.java b/eclipse/src/saros/ui/command_handlers/SessionAddResourcesHandler.java index b9d3ccb742..18c0dac8f9 100644 --- a/eclipse/src/saros/ui/command_handlers/SessionAddResourcesHandler.java +++ b/eclipse/src/saros/ui/command_handlers/SessionAddResourcesHandler.java @@ -34,10 +34,7 @@ public Object execute() { @CanExecute public boolean canExecute() { - return connectionHandler != null - && connectionHandler.isConnected() - && sessionManager != null - && sessionManager.getSession() != null - && sessionManager.getSession().hasWriteAccess(); + final ISarosSession session = sessionManager.getSession(); + return connectionHandler.isConnected() && session != null && session.hasWriteAccess(); } } diff --git a/eclipse/src/saros/ui/command_handlers/SessionAddSelectedContactsHandler.java b/eclipse/src/saros/ui/command_handlers/SessionAddSelectedContactsHandler.java index 009a408c46..ef64dd9d5d 100644 --- a/eclipse/src/saros/ui/command_handlers/SessionAddSelectedContactsHandler.java +++ b/eclipse/src/saros/ui/command_handlers/SessionAddSelectedContactsHandler.java @@ -6,44 +6,48 @@ import org.eclipse.e4.core.di.annotations.Execute; import org.eclipse.e4.core.di.annotations.Optional; import org.eclipse.e4.ui.services.IServiceConstants; +import org.eclipse.jface.viewers.ISelection; import saros.SarosPluginContext; import saros.communication.connection.ConnectionHandler; import saros.net.xmpp.JID; -import saros.net.xmpp.contact.XMPPContactsService; import saros.repackaged.picocontainer.annotations.Inject; import saros.session.ISarosSession; import saros.session.ISarosSessionManager; import saros.ui.util.CollaborationUtils; -import saros.ui.util.selection.retriever.SelectionRetrieverFactory; +import saros.ui.util.selection.SelectionUtils; /** Handles the addition of selected {@link JID}s to the running {@link ISarosSession}. */ public class SessionAddSelectedContactsHandler { @Inject private ConnectionHandler connectionHandler; @Inject private ISarosSessionManager sessionManager; - @Inject private XMPPContactsService contactsService; public SessionAddSelectedContactsHandler() { SarosPluginContext.initComponent(this); } @Execute - public Object execute() { + public Object execute(@Named(IServiceConstants.ACTIVE_SELECTION) @Optional ISelection selection) { - List jids = SelectionRetrieverFactory.getSelectionRetriever(JID.class).getSelection(); + List jids = SelectionUtils.getAdaptableObjects(selection, JID.class); CollaborationUtils.addContactsToSession(jids); return null; } @CanExecute - public boolean canExecute(@Named(IServiceConstants.ACTIVE_SELECTION) @Optional JID contact) { - final JID jid = contact; - return (connectionHandler != null - && connectionHandler.isConnected() - && sessionManager != null - && sessionManager.getSession() != null - && sessionManager.getSession().hasWriteAccess() - && !sessionManager.getSession().getUsers().stream().anyMatch(u -> u.getJID().equals(jid))); + public boolean canExecute( + @Named(IServiceConstants.ACTIVE_SELECTION) @Optional ISelection selection) { + final ISarosSession session = sessionManager.getSession(); + if (!(connectionHandler.isConnected() && session != null && session.hasWriteAccess())) { + return false; + } + List jids = SelectionUtils.getAdaptableObjects(selection, JID.class); + for (JID jid : jids) { + if (session.getUsers().stream().anyMatch(u -> u.getJID().equals(jid))) { + return false; + } + } + return true; } } diff --git a/eclipse/src/saros/ui/command_handlers/SessionAddSelectedResourcesHandler.java b/eclipse/src/saros/ui/command_handlers/SessionAddSelectedResourcesHandler.java index 932110cb7e..c14e8ac7b4 100644 --- a/eclipse/src/saros/ui/command_handlers/SessionAddSelectedResourcesHandler.java +++ b/eclipse/src/saros/ui/command_handlers/SessionAddSelectedResourcesHandler.java @@ -9,6 +9,7 @@ import org.eclipse.e4.core.di.annotations.Execute; import org.eclipse.e4.core.di.annotations.Optional; import org.eclipse.e4.ui.services.IServiceConstants; +import org.eclipse.jface.viewers.ISelection; import saros.SarosPluginContext; import saros.communication.connection.ConnectionHandler; import saros.filesystem.IReferencePoint; @@ -16,9 +17,8 @@ import saros.repackaged.picocontainer.annotations.Inject; import saros.session.ISarosSession; import saros.session.ISarosSessionManager; -import saros.ui.expressions.ResourcePropertyTester; import saros.ui.util.WizardUtils; -import saros.ui.util.selection.retriever.SelectionRetrieverFactory; +import saros.ui.util.selection.SelectionUtils; /** * Handles the addition of selected {@link IResource}s to the running {@link ISarosSession}. @@ -32,17 +32,16 @@ public class SessionAddSelectedResourcesHandler { @Inject private ConnectionHandler connectionHandler; @Inject private ISarosSessionManager sessionManager; - @Inject private ResourcePropertyTester resourcePropertyTester; public SessionAddSelectedResourcesHandler() { SarosPluginContext.initComponent(this); } @Execute - public Object execute() { + public Object execute(@Named(IServiceConstants.ACTIVE_SELECTION) @Optional ISelection selection) { List selectedResources = - SelectionRetrieverFactory.getSelectionRetriever(IResource.class).getSelection(); + SelectionUtils.getAdaptableObjects(selection, IResource.class); WizardUtils.openAddResourcesToSessionWizard(new HashSet<>(selectedResources)); @@ -51,18 +50,23 @@ public Object execute() { @CanExecute public boolean canExecute( - @Named(IServiceConstants.ACTIVE_SELECTION) @Optional IResource resource) { - if (!(connectionHandler != null - && connectionHandler.isConnected() - && sessionManager != null - && sessionManager.getSession() != null - && sessionManager.getSession().hasWriteAccess())) { + @Named(IServiceConstants.ACTIVE_SELECTION) @Optional ISelection selection) { + List resources = SelectionUtils.getAdaptableObjects(selection, IResource.class); + if (!(resources.size() > 0)) { return false; } final ISarosSession session = sessionManager.getSession(); + if (!(connectionHandler.isConnected() && session != null && session.hasWriteAccess())) { + return false; + } Set sharedReferencePoints = session.getReferencePoints(); - saros.filesystem.IResource wrappedResource = - ResourceConverter.convertToResource(sharedReferencePoints, resource); - return !session.isShared(wrappedResource); + for (IResource resource : resources) { + saros.filesystem.IResource wrappedResource = + ResourceConverter.convertToResource(sharedReferencePoints, resource); + if (session.isShared(wrappedResource)) { + return false; + } + } + return true; } } diff --git a/eclipse/src/saros/ui/command_handlers/SessionLeaveHandler.java b/eclipse/src/saros/ui/command_handlers/SessionLeaveHandler.java index 33601e0496..0416ea9389 100644 --- a/eclipse/src/saros/ui/command_handlers/SessionLeaveHandler.java +++ b/eclipse/src/saros/ui/command_handlers/SessionLeaveHandler.java @@ -24,9 +24,6 @@ public Object execute() { @CanExecute public boolean canExecute() { - return connectionHandler != null - && connectionHandler.isConnected() - && sessionManager != null - && sessionManager.getSession() != null; + return connectionHandler.isConnected() && sessionManager.getSession() != null; } } diff --git a/eclipse/src/saros/ui/command_handlers/ShareResourcesHandler.java b/eclipse/src/saros/ui/command_handlers/ShareResourcesHandler.java index b85a7d02cb..50a36abb0c 100644 --- a/eclipse/src/saros/ui/command_handlers/ShareResourcesHandler.java +++ b/eclipse/src/saros/ui/command_handlers/ShareResourcesHandler.java @@ -1,15 +1,19 @@ package saros.ui.command_handlers; +import javax.inject.Named; import org.eclipse.core.resources.IResource; import org.eclipse.e4.core.di.annotations.CanExecute; import org.eclipse.e4.core.di.annotations.Execute; +import org.eclipse.e4.core.di.annotations.Optional; +import org.eclipse.e4.ui.services.IServiceConstants; +import org.eclipse.jface.viewers.ISelection; import saros.SarosPluginContext; import saros.communication.connection.ConnectionHandler; import saros.repackaged.picocontainer.annotations.Inject; import saros.session.ISarosSessionManager; import saros.ui.menu_contributions.StartSessionWithProjects; import saros.ui.util.WizardUtils; -import saros.ui.util.selection.retriever.SelectionRetrieverFactory; +import saros.ui.util.selection.SelectionUtils; /** * @JTourBusStop 1, Invitation Process: @@ -48,17 +52,14 @@ public ShareResourcesHandler() { } @Execute - public Object execute() { + public Object execute(@Named(IServiceConstants.ACTIVE_SELECTION) @Optional ISelection selection) { WizardUtils.openStartSessionWizard( - SelectionRetrieverFactory.getSelectionRetriever(IResource.class).getSelection()); + SelectionUtils.getAdaptableObjects(selection, IResource.class)); return null; } @CanExecute public boolean canExecute() { - return connectionHandler != null - && connectionHandler.isConnected() - && sessionManager != null - && sessionManager.getSession() == null; + return connectionHandler.isConnected() && sessionManager.getSession() == null; } } From 51c5047d3034deda69309846c8dc23befef04188 Mon Sep 17 00:00:00 2001 From: Erik Antes Date: Sat, 13 Feb 2021 15:43:24 +0100 Subject: [PATCH 3/3] [UI][E] Temporary fix for getDisplay() This is a temporary workaround for PlatformUI.getWorkbench().getDisplay() to ensure that the functionality stays the same, by manually keeping track of the Display after it is first instantiated. --- eclipse/src/saros/ui/util/SWTUtils.java | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/eclipse/src/saros/ui/util/SWTUtils.java b/eclipse/src/saros/ui/util/SWTUtils.java index 857c8691f0..b6de3ec798 100644 --- a/eclipse/src/saros/ui/util/SWTUtils.java +++ b/eclipse/src/saros/ui/util/SWTUtils.java @@ -21,6 +21,8 @@ public class SWTUtils { private static final Logger log = Logger.getLogger(SWTUtils.class); + private static Display display; + private static class CallableResult { private T result; private Exception exception; @@ -187,10 +189,19 @@ public static void runSafeSWTSync(final Logger log, final Runnable runnable) { * @return the display of the current workbench */ public static Display getDisplay() { - // return PlatformUI.getWorkbench().getDisplay(); - Display display = Display.getCurrent(); + /** + * This is a temporary solution. Migrating the UI from Eclipse3 to Eclipse4 caused an earlier + * initialization of Saros and its context. Calling PlatformUI.getWorkbench.getDisplay() can not + * be used, since the Workbench wont be created at that point, when this function is first + * called. Continuing the migration it would be best to find an other solution by replacing all + * calls to this function and keeping track of the display another way or find an equivalent to + * PlatformUI.getWorkbench.getDisplay() working in E4. + */ if (display == null) { - display = Display.getDefault(); + display = Display.getCurrent(); + if (display == null) { + display = Display.getDefault(); + } } return display; }