List of usage examples for org.eclipse.jface.operation IRunnableWithProgress run
public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException;
From source file:melnorme.lang.ide.ui.utils.operations.WorkbenchOperationExecutor.java
License:Open Source License
protected final void runRunnableWithProgress(IRunnableWithProgress progressRunnable) throws InvocationTargetException, InterruptedException { if (allowBackgroundAlready && Display.getCurrent() == null) { assertTrue(executeInUIOnly == false); // Perform computation directly in this thread, but cancellation won't be possible. progressRunnable.run(new NullProgressMonitor()); } else {//ww w . ja va 2 s . c o m assertTrue(Display.getCurrent() != null); doRunRunnableWithProgress(progressRunnable); } }
From source file:net.refractions.udig.catalog.internal.shp.ShpServiceImpl.java
License:Open Source License
private void openIndexGenerationDialog(final ShapefileDataStore ds) { rLock.lock();//from ww w . j a va 2 s .co m try { if (ds instanceof IndexedShapefileDataStore) { IndexedShapefileDataStore ids = (IndexedShapefileDataStore) ds; if (ids.isIndexed()) return; String name = getIdentifier().getFile(); int lastIndexOf = name.lastIndexOf(File.separator); if (lastIndexOf > 0) name = name.substring(lastIndexOf + 1); final String finalName = name; IRunnableWithProgress runnable = new IRunnableWithProgress() { public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { monitor.beginTask(Messages.ShpPreferencePage_createindex + " " + finalName, //$NON-NLS-1$ IProgressMonitor.UNKNOWN); index(ds, ds.getTypeNames()[0]); monitor.done(); } }; if (PlatformUI.getWorkbench().isClosing() && false) { try { runnable.run(new NullProgressMonitor()); } catch (InvocationTargetException e) { ShpPlugin.log("", e); //$NON-NLS-1$ } catch (InterruptedException e) { ShpPlugin.log("", e); //$NON-NLS-1$ } } else { PlatformGIS.runInProgressDialog(Messages.ShpServiceImpl_indexing + " " + finalName, true, //$NON-NLS-1$ runnable, false); } } } finally { rLock.unlock(); } }
From source file:net.refractions.udig.catalog.internal.ui.ResourceSelectionPage.java
License:Open Source License
private List<IResolve> getGeoResources(final IResolve resolve, boolean fork) { if (resolveMap.get(resolve) == null || resolveMap.isEmpty()) { final List<IResolve> list = new ArrayList<IResolve>(); try {//from w w w.j a va 2 s . c o m IRunnableWithProgress runnable = new IRunnableWithProgress() { @SuppressWarnings("unchecked") public void run(IProgressMonitor monitor) { monitor.beginTask(Messages.ResourceSelectionPage_searching, IProgressMonitor.UNKNOWN); try { List<IResolve> members = resolve.members(monitor); list.addAll(members); if (schemaSelected != null) { for (IResolve resolve2 : members) { IResolveFolder folder = (IResolveFolder) resolve2; if (folder.getTitle() != schemaSelected) { list.remove(resolve2); } } } } catch (Exception e) { // do nothing CatalogUIPlugin.log("Error finding resources", e); //$NON-NLS-1$ } monitor.done(); } }; if (fork) { getContainer().run(false, true, runnable); } else { runnable.run(new NullProgressMonitor()); } } catch (Exception e) { CatalogUIPlugin.log("", e); //$NON-NLS-1$ } resolveMap.put(resolve, list); } return resolveMap.get(resolve); }
From source file:net.refractions.udig.catalog.ui.workflow.EndConnectionState.java
License:Open Source License
private void disposeOldServices(IProgressMonitor monitor) { if (services == null || services.isEmpty()) { return;// w w w. j av a 2 s. co m } final List<IService> toDispose = new ArrayList<IService>(services); services.clear(); IRunnableWithProgress runnable = new IRunnableWithProgress() { public void run(IProgressMonitor monitor) { monitor.beginTask("Disposing dereferenced services", toDispose.size()); // dispose old services for (IService service : toDispose) { if (service.parent(monitor) == null) { service.dispose(SubMonitor.convert(monitor)); } monitor.worked(1); } } }; // disposing of services could take a long time so do it in a non-UI thread if (Display.getCurrent() != null) { PlatformGIS.run(runnable); } else { try { runnable.run(new NullProgressMonitor()); } catch (InvocationTargetException e) { throw (RuntimeException) new RuntimeException().initCause(e); } catch (InterruptedException e) { throw (RuntimeException) new RuntimeException().initCause(e); } } }
From source file:net.refractions.udig.ui.PlatformGIS.java
License:Open Source License
/** * This method runs the runnable in a separate thread. It is useful in cases where a thread must * wait for a long running and potentially blocking operation (for example an IO operation). If * the IO is done in the UI thread then the user interface will lock up. This allows synchronous * execution of a long running thread in the UI thread without locking the UI. * /* w ww. j ava 2s .co m*/ * @param runnable The runnable(operation) to run * @param monitor the progress monitor to update. * @throws InvocationTargetException * @throws InterruptedException */ public static void runBlockingOperation(final IRunnableWithProgress runnable, final IProgressMonitor monitor2) throws InvocationTargetException, InterruptedException { final IProgressMonitor monitor = monitor2 == null ? new NullProgressMonitor() : monitor2; final InterruptedException[] interruptedException = new InterruptedException[1]; final InvocationTargetException[] invocationTargetException = new InvocationTargetException[1]; Display d = Display.getCurrent(); if (d == null) d = Display.getDefault(); final Display display = d; final AtomicBoolean done = new AtomicBoolean(); final Object mutex = new Object(); done.set(false); Future<Object> future = executor.submit(new Callable<Object>() { @SuppressWarnings("unused") Exception e = new Exception("For debugging"); //$NON-NLS-1$ public Object call() throws Exception { try { runnable.run(new OffThreadProgressMonitor( monitor != null ? monitor : ProgressManager.instance().get(), display)); } catch (InvocationTargetException ite) { invocationTargetException[0] = ite; } catch (InterruptedException ie) { interruptedException[0] = ie; } finally { done.set(true); synchronized (mutex) { mutex.notify(); } } return null; } }); while (!monitor.isCanceled() && !done.get() && !Thread.interrupted()) { Thread.yield(); if (Display.getCurrent() == null) { wait(mutex, 200); } else { try { if (!d.readAndDispatch()) { wait(mutex, 200); } } catch (Exception e) { UiPlugin.log( "Error occurred net.refractions.udig.issues.internal while waiting for an operation to complete", //$NON-NLS-1$ e); } } } if (monitor.isCanceled()) { future.cancel(true); } if (interruptedException[0] != null) throw interruptedException[0]; else if (invocationTargetException[0] != null) throw invocationTargetException[0]; }
From source file:net.refractions.udig.ui.PlatformGIS.java
License:Open Source License
/** * Runs a blocking task in a ProgressDialog. It is ran in such a way that even if the task * blocks it can be cancelled. This is unlike the normal ProgressDialog.run(...) method which * requires that the {@link IProgressMonitor} be checked and the task to "nicely" cancel. * //from ww w .j av a 2 s .c o m * @param dialogTitle The title of the Progress dialog * @param showRunInBackground if true a button added to the dialog that will make the job be ran * in the background. * @param runnable the task to execute. * @param runASync if true the runnable will be ran asynchronously */ public static void runInProgressDialog(final String dialogTitle, final boolean showRunInBackground, final IRunnableWithProgress runnable, boolean runASync) { Runnable object = new Runnable() { public void run() { Shell shell = Display.getDefault().getActiveShell(); ProgressMonitorDialog dialog = new ProgressMonitorDialog(shell) { @Override protected void configureShell(Shell shell) { super.configureShell(shell); shell.setText(dialogTitle); } @Override protected void createButtonsForButtonBar(Composite parent) { if (showRunInBackground) createBackgroundButton(parent); super.createButtonsForButtonBar(parent); } private void createBackgroundButton(Composite parent) { createButton(parent, IDialogConstants.BACK_ID, Messages.PlatformGIS_background, true); } @Override protected void buttonPressed(int buttonId) { if (buttonId == IDialogConstants.BACK_ID) { getShell().setVisible(false); } else super.buttonPressed(buttonId); } }; try { dialog.run(true, true, new IRunnableWithProgress() { public void run(IProgressMonitor monitor) { try { runBlockingOperation(new IRunnableWithProgress() { public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { runnable.run(monitor); } }, monitor); } catch (Exception e) { UiPlugin.log("", e); //$NON-NLS-1$ } } }); } catch (Exception e) { UiPlugin.log("", e); //$NON-NLS-1$ } } }; if (runASync) Display.getDefault().asyncExec(object); else syncInDisplayThread(object); }
From source file:net.refractions.udig.ui.PlatformJobs.java
License:Open Source License
/** * Runs a blocking task in a ProgressDialog. It is ran in such a way that even if the task * blocks it can be cancelled. This is unlike the normal ProgressDialog.run(...) method which * requires that the {@link IProgressMonitor} be checked and the task to "nicely" cancel. * /* w w w.java 2 s.c om*/ * @param dialogTitle The title of the Progress dialog * @param showRunInBackground if true a button added to the dialog that will make the job be ran * in the background. * @param runnable the task to execute. * @param runASync if true the runnable will be ran asynchronously */ public static void runInProgressDialog(final String dialogTitle, final boolean showRunInBackground, final IRunnableWithProgress runnable, boolean runASync) { Runnable object = new Runnable() { public void run() { Shell shell = Display.getDefault().getActiveShell(); ProgressMonitorDialog dialog = new ProgressMonitorDialog(shell) { @Override protected void configureShell(Shell shell) { super.configureShell(shell); shell.setText(dialogTitle); } @Override protected void createButtonsForButtonBar(Composite parent) { if (showRunInBackground) createBackgroundButton(parent); super.createButtonsForButtonBar(parent); } private void createBackgroundButton(Composite parent) { createButton(parent, IDialogConstants.BACK_ID, Messages.get("PlatformGIS_background"), true); } @Override protected void buttonPressed(int buttonId) { if (buttonId == IDialogConstants.BACK_ID) { getShell().setVisible(false); } else super.buttonPressed(buttonId); } }; try { final Display display = Display.getCurrent(); dialog.run(true, true, new IRunnableWithProgress() { public void run(final IProgressMonitor monitor) { try { UICallBack.runNonUIThreadWithFakeContext(display, new Runnable() { public void run() { try { // thread already forked by the dialog runnable.run(monitor); } catch (InvocationTargetException e) { throw new RuntimeException("", e.getTargetException()); } catch (InterruptedException e) { throw new RuntimeException(e.getMessage()); } } }); // runSync(new IRunnableWithProgress(){ // // public void run( IProgressMonitor monitor ) // throws InvocationTargetException, InterruptedException { // runnable.run(monitor); // } // }, monitor); } catch (Exception e) { UiPlugin.log("", e); //$NON-NLS-1$ } } }); } catch (Exception e) { UiPlugin.log("", e); //$NON-NLS-1$ } } }; Display.getCurrent().syncExec(object); // if (runASync) // Display.getDefault().asyncExec(object); // else // PlatformGIS.syncInDisplayThread(object); }
From source file:net.sf.eclipsensis.EclipseNSISPlugin.java
License:Open Source License
public void run(final boolean fork, final boolean cancelable, final IRunnableWithProgress runnable) { try {//from w ww. j a v a 2s .c o m if (Display.getCurrent() == null) { //fork and cancelable are meaningless here runnable.run(new NullProgressMonitor()); } else { boolean useWorkbenchWindow = false; try { useWorkbenchWindow = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell() .isVisible(); } catch (Exception e) { useWorkbenchWindow = false; } if (!useWorkbenchWindow) { if (mBundleContext != null && mBundleContext.getBundle().getState() == Bundle.STARTING) { //Startup in progress- overlay the splash screen String splashFile = System.getProperty("org.eclipse.equinox.launcher.splash.location"); //$NON-NLS-1$ if (!Common.isEmpty(splashFile)) { File file = new File(splashFile); if (IOUtility.isValidFile(file)) { ImageDescriptor desc = ImageDescriptor.createFromURL(file.toURI().toURL()); final Image image = desc.createImage(); Rectangle rect = image.getBounds(); String foregroundColor = null; IProduct product = Platform.getProduct(); if (product != null) { foregroundColor = product .getProperty(IProductConstants.STARTUP_FOREGROUND_COLOR); } RGB fgRGB; try { fgRGB = ColorManager.getRGB(Integer.parseInt(foregroundColor, 16)); } catch (Exception ex) { fgRGB = ColorManager.getRGB(13817855); // D2D7FF=white } Monitor monitor = Display.getCurrent().getPrimaryMonitor(); Point pt = Geometry.centerPoint(monitor.getBounds()); MinimalProgressMonitorDialog dialog = new MinimalProgressMonitorDialog( Display.getCurrent().getActiveShell(), rect.width, rect.width); dialog.setBGImage(image); dialog.setForegroundRGB(fgRGB); dialog.create(); Shell shell = dialog.getShell(); shell.setLocation(shell.getLocation().x, pt.y + rect.height / 2); shell.addDisposeListener(new DisposeListener() { public void widgetDisposed(DisposeEvent e) { image.dispose(); } }); dialog.run(fork, cancelable, runnable); return; } } } new MinimalProgressMonitorDialog(Display.getDefault().getActiveShell()).run(fork, cancelable, runnable); } else { PlatformUI.getWorkbench().getActiveWorkbenchWindow().run(fork, cancelable, runnable); } } } catch (Exception e) { log(e); } }
From source file:net.tourbook.database.TourDatabase.java
License:Open Source License
private boolean sqlInit_10_IsDbInitialized() { if (_isDbInitialized) { return true; }//from w w w . j a va 2 s .c o m // check if the derby driver can be loaded try { Class.forName(DERBY_DRIVER_CLASS); } catch (final ClassNotFoundException e) { StatusUtil.showStatus(e.getMessage(), e); return false; } final boolean[] returnState = { false }; try { /* * Get progress monitor */ final IProgressMonitor progressMonitor; final MyTourbookSplashHandler splashHandler = TourbookPlugin.getSplashHandler(); if (splashHandler == null) { progressMonitor = new NullProgressMonitor(); } else { progressMonitor = splashHandler.getBundleProgressMonitor(); } /* * Check or setup sql */ final IRunnableWithProgress runnable = new IRunnableWithProgress() { @Override public void run(final IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { try { sqlInit_20_CheckServer(); sqlInit_30_Check_DbIsCreated(); } catch (final Throwable e) { StatusUtil.log(e); return; } sqlInit_40_CheckTable(monitor); if (sqlInit_60_IsVersionValid(monitor) == false) { return; } sqlInit_80_Check_DbIsUpgraded(monitor); sqlInit_90_SetupEntityManager(monitor); returnState[0] = true; } }; runnable.run(progressMonitor); } catch (final InvocationTargetException e) { StatusUtil.log(e); } catch (final InterruptedException e) { StatusUtil.log(e); } finally { _isDbInitialized = returnState[0]; } return returnState[0]; }
From source file:org.bonitasoft.studio.engine.command.AbstractOpenConsoleCommand.java
License:Open Source License
private void executeJob() { try {/*ww w . ja va 2s. c o m*/ final IRunnableWithProgress runnable = new IRunnableWithProgress() { @Override public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { try { monitor.beginTask(Messages.initializingUserXP, IProgressMonitor.UNKNOWN); BOSEngineManager.getInstance().start(); setURL(getURLBuilder().toURL(monitor)); if (refreshTheme) { String currentTheme = BonitaStudioPreferencesPlugin.getDefault().getPreferenceStore() .getString(BonitaPreferenceConstants.DEFAULT_USERXP_THEME); String installedTheme = BonitaUserXpPreferencePage.getInstalledThemeId(); if (installedTheme != null && !installedTheme.equals(currentTheme)) { BonitaStudioPreferencesPlugin.getDefault().getPreferenceStore() .setValue(BonitaPreferenceConstants.DEFAULT_USERXP_THEME, currentTheme); BonitaUserXpPreferencePage.updateBonitaHome(); } } if (!runSynchronously) { new OpenBrowserCommand(url, BonitaPreferenceConstants.CONSOLE_BROWSER_ID, "Bonita User Experience").execute(null); //$NON-NLS-1$ } } catch (Exception e) { BonitaStudioLog.error(e); } finally { monitor.done(); } } }; if (runSynchronously) { runnable.run(new NullProgressMonitor()); } else { final IProgressService progressManager = PlatformUI.getWorkbench().getProgressService(); Display.getDefault().syncExec(new Runnable() { @Override public void run() { try { progressManager.run(true, false, runnable); } catch (Exception e) { BonitaStudioLog.error(e); } } }); } } catch (Exception e) { BonitaStudioLog.error(e); } }