From 91927cb3b3916b6ea17b8ba234ae55a03d94b839 Mon Sep 17 00:00:00 2001 From: Stefan Dirix Date: Thu, 30 Jul 2015 11:01:36 +0200 Subject: Bug 473847 - Support DialogCompare for pure E4 applications 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 Change-Id: I51851b0cab6dace0bc44bc9b6d30dfad32eeff39 --- .../org/eclipse/compare/internal/Utilities.java | 74 ++++++++++++++++++++++ 1 file changed, 74 insertions(+) (limited to 'bundles/org.eclipse.compare/compare/org/eclipse/compare/internal/Utilities.java') 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); + } } -- cgit v1.2.3