Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStefan Dirix2015-07-30 09:01:36 +0000
committerMickael Istria2020-01-17 22:37:03 +0000
commit91927cb3b3916b6ea17b8ba234ae55a03d94b839 (patch)
tree558636781ee6f1dca40e9c279a987d3d29069023 /bundles/org.eclipse.compare/compare/org/eclipse/compare/internal/Utilities.java
parente8832328f3e127882d9fa3c66c0d20e8bdf92989 (diff)
downloadeclipse.platform.team-91927cb3b3916b6ea17b8ba234ae55a03d94b839.tar.gz
eclipse.platform.team-91927cb3b3916b6ea17b8ba234ae55a03d94b839.tar.xz
eclipse.platform.team-91927cb3b3916b6ea17b8ba234ae55a03d94b839.zip
Removes runtime dependencies to the workbench which allows pure E4 applications to execute comparisons within dialogs without exceptions. Bug: 473847 Signed-off-by: Stefan Dirix <sdirix@eclipsesource.com> Change-Id: I51851b0cab6dace0bc44bc9b6d30dfad32eeff39
Diffstat (limited to 'bundles/org.eclipse.compare/compare/org/eclipse/compare/internal/Utilities.java')
-rw-r--r--bundles/org.eclipse.compare/compare/org/eclipse/compare/internal/Utilities.java74
1 files changed, 74 insertions, 0 deletions
diff --git a/bundles/org.eclipse.compare/compare/org/eclipse/compare/internal/Utilities.java b/bundles/org.eclipse.compare/compare/org/eclipse/compare/internal/Utilities.java
index 2f2bc3b74..78d22a874 100644
--- a/bundles/org.eclipse.compare/compare/org/eclipse/compare/internal/Utilities.java
+++ b/bundles/org.eclipse.compare/compare/org/eclipse/compare/internal/Utilities.java
@@ -1,8 +1,14 @@
/*******************************************************************************
+<<<<<<< HEAD
* Copyright (c) 2000, 2017 IBM Corporation and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
+=======
+ * Copyright (c) 2000, 2016 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+>>>>>>> Bug 473847 - Support DialogCompare for pure E4 applications
* which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-2.0/
*
@@ -10,6 +16,7 @@
*
* Contributors:
* IBM Corporation - initial API and implementation
+ * Stefan Dirix (sdirix@eclipsesource.com) - Bug 473847: Minimum E4 Compatibility of Compare
*******************************************************************************/
package org.eclipse.compare.internal;
@@ -60,6 +67,7 @@ import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.ListenerList;
import org.eclipse.core.runtime.MultiStatus;
+import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.core.runtime.OperationCanceledException;
import org.eclipse.core.runtime.Path;
import org.eclipse.core.runtime.SafeRunner;
@@ -69,6 +77,7 @@ import org.eclipse.core.runtime.jobs.Job;
import org.eclipse.jface.action.IAction;
import org.eclipse.jface.dialogs.ErrorDialog;
import org.eclipse.jface.operation.IRunnableContext;
+import org.eclipse.jface.operation.IRunnableWithProgress;
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.jface.text.IDocument;
import org.eclipse.jface.text.IRegion;
@@ -77,9 +86,13 @@ import org.eclipse.jface.util.PropertyChangeEvent;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.swt.custom.BusyIndicator;
+import org.eclipse.swt.events.DisposeEvent;
+import org.eclipse.swt.events.DisposeListener;
+import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Display;
+import org.eclipse.swt.widgets.Item;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Widget;
import org.eclipse.ui.IActionBars;
@@ -88,6 +101,7 @@ import org.eclipse.ui.IViewPart;
import org.eclipse.ui.IWorkbenchPart;
import org.eclipse.ui.IWorkbenchPartSite;
import org.eclipse.ui.IWorkbenchSite;
+import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.progress.IWorkbenchSiteProgressService;
import org.eclipse.ui.texteditor.IDocumentProvider;
@@ -911,4 +925,64 @@ public class Utilities {
}
return buffer.toString();
}
+
+ /**
+ * Executes the given runnable. Uses the {@link org.eclipse.ui.progress.IProgressService IProgressService}
+ * if available.
+ *
+ * @param runnable
+ * The {@link IRunnableWithProgress} to execute.
+ * @throws InvocationTargetException
+ * @throws InterruptedException
+ */
+ public static void executeRunnable(IRunnableWithProgress runnable) throws InvocationTargetException,
+ InterruptedException {
+ executeRunnable(runnable, true, true);
+ }
+
+ /**
+ * Executes the given runnable. Uses the {@link org.eclipse.ui.progress.IProgressService IProgressService}
+ * if available.
+ *
+ * @param runnable
+ * The {@link IRunnableWithProgress} to execute.
+ * @param fork indicates whether to run within a separate thread.
+ * @param cancelable indicates whether the operation shall be cancelable
+ * @throws InvocationTargetException
+ * @throws InterruptedException
+ */
+ public static void executeRunnable(IRunnableWithProgress runnable, boolean fork, boolean cancelable) throws InvocationTargetException,
+ InterruptedException {
+ if (PlatformUI.isWorkbenchRunning()) {
+ PlatformUI.getWorkbench().getProgressService().run(fork, cancelable, runnable);
+ } else {
+ runnable.run(new NullProgressMonitor());
+ }
+ }
+
+ /**
+ * Sets the menu image for the given {@link Item}. Uses the workbench shared image if available, otherwise
+ * creates a new image and adds a dispose listener.
+ *
+ * @param item
+ * The {@link Item} for which the menu image is to be set.
+ */
+ public static void setMenuImage(final Item item) {
+ final Image image;
+ if (PlatformUI.isWorkbenchRunning()) {
+ image = PlatformUI.getWorkbench().getSharedImages().getImage(
+ /* IWorkbenchGraphicConstants */"IMG_LCL_VIEW_MENU"); //$NON-NLS-1$
+ } else {
+ image = CompareUIPlugin.getImageDescriptor("elcl16/view_menu.png").createImage(); //$NON-NLS-1$
+ item.addDisposeListener(new DisposeListener() {
+ public void widgetDisposed(DisposeEvent e) {
+ Image img = item.getImage();
+ if ((img != null) && (!img.isDisposed())) {
+ img.dispose();
+ }
+ }
+ });
+ }
+ item.setImage(image);
+ }
}

Back to the top