Example usage for org.eclipse.jface.dialogs ProgressMonitorDialog run

List of usage examples for org.eclipse.jface.dialogs ProgressMonitorDialog run

Introduction

In this page you can find the example usage for org.eclipse.jface.dialogs ProgressMonitorDialog run.

Prototype

@Override
public void run(boolean fork, boolean cancelable, IRunnableWithProgress runnable)
        throws InvocationTargetException, InterruptedException 

Source Link

Document

This implementation of IRunnableContext#run(boolean, boolean, IRunnableWithProgress) runs the given IRunnableWithProgress using the progress monitor for this progress dialog and blocks until the runnable has been run, regardless of the value of fork.

Usage

From source file:net.ostis.confman.ui.handlers.SaveHandler.java

License:Open Source License

@Execute
public void execute(final IEclipseContext context, @Named(IServiceConstants.ACTIVE_SHELL) final Shell shell,
        @Named(IServiceConstants.ACTIVE_PART) final MContribution contribution)
        throws InvocationTargetException, InterruptedException {

    final IEclipseContext pmContext = context.createChild();

    final ProgressMonitorDialog dialog = new ProgressMonitorDialog(shell);
    dialog.open();//from w w  w .ja v  a 2s. c om
    dialog.run(true, true, new IRunnableWithProgress() {

        @Override
        public void run(final IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {

            pmContext.set(IProgressMonitor.class.getName(), monitor);
            if (contribution != null) {
                final Object clientObject = contribution.getObject();
                //               ContextInjectionFactory.invoke(clientObject, Persist.class, //$NON-NLS-1$
                // pmContext, null);
            }
        }
    });

    pmContext.dispose();
}

From source file:net.refractions.udig.internal.ui.UDIGApplication.java

License:Open Source License

/**
 * We have a couple things that need to happen
 * before the workbench is opened. The org.eclipse.ui.startup
 * extension point is willing to run stuff for us *after*
 * the workbench is opened - but that is not so useful
 * when we need to configure the EPSG database for libs
 * and load up the local catalog.//  www  .j a  v a 2 s .c  om
 * <p>
 * Long term we will want to create a startup list
 * (much like we have shutdown hooks).
 */
@SuppressWarnings("restriction")
protected boolean init() {
    ProgressMonitorDialog progress = new ProgressMonitorDialog(Display.getCurrent().getActiveShell());
    final Bundle bundle = Platform.getBundle(Activator.ID);

    // We should kick the libs plugin to load the EPSG database now
    File epsgFile = Activator.epsgDatabaseFile();
    boolean unpacked = epsgFile != null && epsgFile.exists();
    if (unpacked) {
        // if there is not going to be a long delay don't annoy users with a dialog
        Activator.initializeReferencingModule(null);
    } else {
        // We are going to take a couple of minutes to set this up
        // so we better set up a progress dialog thing
        //
        try {
            progress.run(false, false, new IRunnableWithProgress() {
                public void run(IProgressMonitor monitor)
                        throws InvocationTargetException, InterruptedException {
                    Activator.initializeReferencingModule(monitor);
                }
            });
        } catch (InvocationTargetException e) {
            Platform.getLog(bundle).log(
                    new Status(IStatus.ERROR, UiPlugin.ID, e.getCause().getLocalizedMessage(), e.getCause()));
            return false;
        } catch (InterruptedException e) {
            Platform.getLog(bundle).log(
                    new Status(IStatus.ERROR, UiPlugin.ID, e.getCause().getLocalizedMessage(), e.getCause()));
            return false;
        }
    }
    // We should kick the CatalogPlugin to load now...
    return true;
}

From source file:net.refractions.udig.project.internal.impl.MapImpl.java

License:Open Source License

public void executeSyncWithoutUndo(final MapCommand command) {
    command.setMap(this);
    if (Display.getCurrent() != null) {
        ProgressMonitorDialog dialog = new ProgressMonitorDialog(
                PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell());
        dialog.setOpenOnRun(true);//from w  w w . j  a v a  2 s.  co m
        try {
            dialog.run(false, false, new IRunnableWithProgress() {

                public void run(IProgressMonitor monitor)
                        throws InvocationTargetException, InterruptedException {
                    try {
                        command.run(monitor);
                    } catch (Exception e) {
                        ProjectPlugin.log("Error executing command: " + command.getName(), e); //$NON-NLS-1$
                    }
                }

            });
        } catch (InvocationTargetException e) {
            ProjectPlugin.log("Error executing command: " + command.getName(), e); //$NON-NLS-1$
        } catch (InterruptedException e) {
            ProjectPlugin.log("Error executing command: " + command.getName(), e); //$NON-NLS-1$
        }
    } else {
        try {
            command.run(new NullProgressMonitor());
        } catch (Exception e) {
            ProjectPlugin.log("Error executing command: " + command.getName(), e); //$NON-NLS-1$
        }
    }
}

From source file:net.refractions.udig.render.internal.wms.basic.BasicWMSRenderer2.java

License:Open Source License

private static Collection<String> extractEPSG(final IMap map, final CoordinateReferenceSystem crs) {

    if (CRS.equalsIgnoreMetadata(crs, DefaultGeographicCRS.WGS84)) {
        return Collections.singleton(EPSG_4326);
    }//from   ww  w. jav  a  2 s . c  o m
    final Collection<String> codes = new HashSet<String>();
    codes.addAll(CRSUtil.extractAuthorityCodes(crs));

    final String DONT_FIND = "DONT_FIND";
    boolean search = map.getBlackboard().get(EPSG_CODE) != DONT_FIND;
    if (codes.isEmpty() && search) {
        PlatformGIS.syncInDisplayThread(new Runnable() {
            public void run() {
                Shell shell = Display.getCurrent().getActiveShell();

                ProgressMonitorDialog dialog = new ProgressMonitorDialog(shell);
                try {
                    dialog.run(false, true, new IRunnableWithProgress() {

                        public void run(IProgressMonitor monitor)
                                throws InvocationTargetException, InterruptedException {
                            CoordinateReferenceSystem found = CRSUtil.findEPSGCode(crs, monitor);
                            if (found == null) {
                                return;
                            }

                            ViewportModel model = (ViewportModel) map.getViewportModel();
                            model.eSetDeliver(false);
                            try {
                                model.setCRS(found);
                                codes.addAll(CRSUtil.extractAuthorityCodes(found));
                            } finally {
                                model.eSetDeliver(true);
                            }
                        }

                    });
                } catch (InvocationTargetException e) {
                    WMSPlugin.log("Error tracking down EPSG Code", e);
                    dontFind(map, DONT_FIND);
                } catch (InterruptedException e) {
                    WMSPlugin.log("Error tracking down EPSG Code", e);
                    dontFind(map, DONT_FIND);
                }
                dontFind(map, DONT_FIND);
            }
        });
    }

    return codes;
}

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 w  ww. ja  va2  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.
 * //from   ww  w  . ja v  a  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.refractions.udig.ui.ShutdownTaskList.java

License:Open Source License

public void postShutdown(final IWorkbench workbench) {

    try {/*from   ww w  . j  av a2  s.co m*/
        final ProgressMonitorDialog dialog = getDialog(workbench);
        dialog.run(true, false, new IRunnableWithProgress() {

            public void run(IProgressMonitor monitor2) throws InvocationTargetException, InterruptedException {
                OffThreadProgressMonitor monitor = new OffThreadProgressMonitor(monitor2,
                        dialog.getShell().getDisplay());

                int totalsteps = 0;
                for (PostTask task : postShutdownTasks) {
                    try {
                        task.steps = task.task.getProgressMonitorSteps();
                        totalsteps += task.steps;
                    } catch (Throwable e) {
                        UiPlugin.log("error calling getProgressMonitorSteps() on " + task.task, e); //$NON-NLS-1$
                    }
                }

                monitor.beginTask(Messages.ShutdownTaskList_shutDown, totalsteps);

                for (PostTask task : postShutdownTasks) {
                    IProgressMonitor subMonitor = new ProgressMonitorTaskNamer(monitor, task.steps);
                    try {
                        task.task.postShutdown(subMonitor, workbench);
                    } catch (Throwable t) {
                        task.task.handlePostShutdownException(t);
                    } finally {
                        subMonitor.done();
                    }
                }
            }

        });
    } 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.ShutdownTaskList.java

License:Open Source License

public boolean preShutdown(final IWorkbench workbench, final boolean forced) {
    final ProgressMonitorDialog dialog = getDialog(workbench);

    final boolean[] allowShutdown = new boolean[1];
    allowShutdown[0] = true;/*from w ww. j a  v  a2 s. com*/

    workbench.getActiveWorkbenchWindow().getShell().setVisible(false);

    final Display display = Display.getCurrent();
    try {
        dialog.run(true, forced, new IRunnableWithProgress() {

            public void run(IProgressMonitor monitor2) throws InvocationTargetException, InterruptedException {

                IProgressMonitor monitor = new OffThreadProgressMonitor(monitor2, display);

                int totalsteps = 0;
                for (PreTask task : preShutdownTasks) {
                    try {
                        task.steps = task.task.getProgressMonitorSteps();
                        totalsteps += task.steps;
                    } catch (Throwable e) {
                        UiPlugin.log("error calling getProgressMonitorSteps() on " + task.task, e); //$NON-NLS-1$
                    }
                }
                monitor.beginTask(Messages.ShutdownTaskList_shutDown, totalsteps);

                for (PreTask task : preShutdownTasks) {
                    IProgressMonitor subMonitor = new ProgressMonitorTaskNamer(monitor, task.steps);
                    boolean result;
                    try {
                        result = task.task.preShutdown(subMonitor, workbench, forced);
                    } catch (Throwable t) {
                        result = task.task.handlePreShutdownException(t, forced);
                    } finally {
                        subMonitor.done();
                    }
                    if (!forced) {
                        if (monitor.isCanceled() || !result)
                            allowShutdown[0] = false;
                        if (monitor.isCanceled())
                            return;
                    }
                }
            }

        });
    } catch (InvocationTargetException e) {
        throw (RuntimeException) new RuntimeException().initCause(e);
    } catch (InterruptedException e) {
        throw (RuntimeException) new RuntimeException().initCause(e);
    }

    if (!allowShutdown[0])
        workbench.getActiveWorkbenchWindow().getShell().setVisible(true);

    return allowShutdown[0];
}

From source file:net.rim.ejde.internal.ui.views.profiler.ProfilerView.java

License:Open Source License

/**
 * Save view content to a XML file.//  w  w w .ja  v  a 2  s .c o m
 * <p>
 * <b>subclasses need to override this method.</b>
 */
public void saveXML() {
    File xmlFile = chooseDataFile();
    if (xmlFile == null) {
        return;
    }
    if (!xmlFile.exists()) {
        xmlFile = ProjectUtils.createFile(xmlFile);
        if (xmlFile == null || !xmlFile.exists()) {
            return;
        }
    }
    ProgressMonitorDialog dialog = new ProgressMonitorDialog(ContextManager.getActiveWorkbenchShell());
    SaveDataRunnale runnable = new SaveDataRunnale(xmlFile, this);
    try {
        dialog.run(false, true, runnable);
    } catch (InvocationTargetException e) {
        log.error(e);
        MessageDialog.openError(ContextManager.getActiveWorkbenchShell(), e.getMessage(),
                Messages.ErrorHandler_DIALOG_TITLE);
    } catch (InterruptedException e) {
        log.error(e);
        MessageDialog.openError(ContextManager.getActiveWorkbenchShell(), e.getMessage(),
                Messages.ErrorHandler_DIALOG_TITLE);
    }
}

From source file:net.rim.ejde.internal.ui.views.profiler.ProfilerView.java

License:Open Source License

/**
 * Save raw data of the view content to a XML file.
 * <p>/*  w  w w.j  a v  a 2s  .  c  o  m*/
 * <b>subclasses need to override this method.</b>
 */
public void saveRawToXML() {
    File xmlFile = chooseRawDataFile();
    if (xmlFile == null) {
        return;
    }
    if (!xmlFile.exists()) {
        xmlFile = ProjectUtils.createFile(xmlFile);
        if (xmlFile == null || !xmlFile.exists()) {
            return;
        }
    }
    ProgressMonitorDialog dialog = new ProgressMonitorDialog(ContextManager.getActiveWorkbenchShell());
    SaveRawDataRunnale runnable = new SaveRawDataRunnale(xmlFile, this);
    try {
        dialog.run(false, true, runnable);
    } catch (InvocationTargetException e) {
        log.error(e);
        MessageDialog.openError(ContextManager.getActiveWorkbenchShell(), e.getMessage(),
                Messages.ErrorHandler_DIALOG_TITLE);
    } catch (InterruptedException e) {
        log.error(e);
        MessageDialog.openError(ContextManager.getActiveWorkbenchShell(), e.getMessage(),
                Messages.ErrorHandler_DIALOG_TITLE);
    }
}