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

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

Introduction

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

Prototype

public void setOpenOnRun(boolean openOnRun) 

Source Link

Document

Sets whether the dialog should be opened before the operation is run.

Usage

From source file:org.nightlabs.jfire.reporting.admin.ui.layout.action.delete.DeleteRegistryItemAction.java

License:Open Source License

public @Override void run(final Collection<ReportRegistryItem> reportRegistryItems) {
    // confirm the delete
    boolean confirm = MessageDialog.openConfirm(Display.getCurrent().getActiveShell(), Messages.getString(
            "org.nightlabs.jfire.reporting.admin.ui.layout.action.delete.deleteregistryitemaction.title"), //$NON-NLS-1$
            Messages.getString(/*w w w. jav a 2s  . c o  m*/
                    "org.nightlabs.jfire.reporting.admin.ui.layout.action.delete.deleteregistryitemaction.description")); //$NON-NLS-1$
    if (!confirm)
        return;

    ProgressMonitorDialog progressDialog = new ProgressMonitorDialog(RCPUtil.getActiveShell());
    progressDialog.setOpenOnRun(true);
    try {
        progressDialog.run(false, false, new IRunnableWithProgress() {
            @Override
            public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
                monitor.beginTask("Removing...", reportRegistryItems.size());
                try {
                    for (final ReportRegistryItem reportRegistryItem : reportRegistryItems) {
                        final ReportRegistryItemID itemID = (ReportRegistryItemID) JDOHelper
                                .getObjectId(reportRegistryItem);
                        Display.getDefault().asyncExec(new Runnable() {
                            @Override
                            public void run() {
                                if (reportRegistryItem instanceof ReportLayout) {
                                    RCPUtil.closeEditor(new JFireRemoteReportEditorInput(itemID), false);
                                } else if (reportRegistryItem instanceof ReportCategory) {
                                    // closes all open ReportLayouts in the Editor if we delete a category
                                    RCPUtil.getActiveWorkbenchPage().closeAllEditors(false);
                                }
                            }
                        });
                        ReportManagerRemote rm = JFireEjb3Factory.getRemoteBean(ReportManagerRemote.class,
                                Login.getLogin().getInitialContextProperties());
                        rm.deleteRegistryItem(itemID);
                        monitor.worked(1);
                    }
                } catch (Exception e) {
                    monitor.setCanceled(true);
                    throw new InvocationTargetException(e);
                } finally {
                    monitor.done();
                }
            }
        });
    } catch (InvocationTargetException e) {
        throw new RuntimeException(e.getTargetException());
    } catch (InterruptedException e) {
        throw new RuntimeException(e);
    }
}

From source file:org.occiware.clouddesigner.occi.infrastructure.connector.vmware.utils.thread.UIDialog.java

License:Open Source License

/**
 * Encapsulate in a thread the runnable with dialog progress if in cloud
 * designer mode//  ww w.j  a va 2s . c  o  m
 * 
 * @param runnable
 */
public static void executeActionThread(final IRunnableWithProgress runnable, final String actionName) {

    try {
        IRunnableWithProgress runnableWithProgress = new IRunnableWithProgress() {

            @Override
            public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
                if (!monitor.isCanceled()) {
                    monitor.beginTask("Operation in progress : " + actionName, 0);
                    runnable.run(monitor);
                    monitor.done();
                } else {
                    return;
                }
            }
        };
        Shell shell = getCurrentShell();

        ProgressMonitorDialog dialog = new ProgressMonitorDialog(shell);

        dialog.setOpenOnRun(true);

        dialog.run(true, true, runnableWithProgress);

    } catch (IllegalStateException | InvocationTargetException | InterruptedException ex) {
        LOGGER.error("Error while executing an action task : " + ex.getMessage());
        ex.printStackTrace();
    }

}

From source file:org.ow2.petals.client.swt.SwtUtils.java

License:Open Source License

/**
 * Clears the history and shows a progress bar.
 * @param shell the parent shell//from   w  w w .  j  a  v a2 s . com
 * @param olderThan see {@link Utils#clearHistory(int)}
 * @param clientApp the client application
 * @throws Exception
 */
public static void clearHistoryWithProgressBar(Shell shell, final int olderThan, ClientApplication clientApp) {

    // Display a warning if required
    if (!PreferencesManager.INSTANCE.isDefaultHistoryDirectory()) {
        boolean proceed = MessageDialog.openQuestion(shell, "Proceed?",
                "The history directory has been modified. Clearing the history will remove TXT files"
                        + " located in this directory. Proceed?");

        if (!proceed)
            return;
    }

    // Create the runnable
    IRunnableWithProgress runnable = new IRunnableWithProgress() {
        @Override
        public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {

            try {
                monitor.beginTask("Clearing the History...", IProgressMonitor.UNKNOWN);
                Utils.clearHistory(olderThan);

            } finally {
                monitor.done();
            }
        }
    };

    // Execute it
    ProgressMonitorDialog dlg = new ProgressMonitorDialog(shell);
    dlg.setOpenOnRun(true);
    try {
        dlg.run(true, false, runnable);

    } catch (InvocationTargetException e) {
        clientApp.log(null, e, Level.INFO);
        openErrorDialog(shell, "The history could not be cleared correctly.");

    } catch (InterruptedException e) {
        // nothing
    }
}

From source file:org.rssowl.ui.internal.dialogs.NewsFiltersListDialog.java

License:Open Source License

private void applyFilter(final List<SearchHit<NewsReference>> news, final ISearchFilter filter) {
    IRunnableWithProgress runnable = new IRunnableWithProgress() {
        public void run(IProgressMonitor monitor) {
            List<List<SearchHit<NewsReference>>> chunks = CoreUtils.toChunks(news, FILTER_CHUNK_SIZE);
            monitor.beginTask(NLS.bind(Messages.NewsFiltersListDialog_WAIT_FILTER_APPLIED, filter.getName()),
                    chunks.size());//from   w w  w .  jav a2s.  c om

            if (monitor.isCanceled())
                return;

            int counter = 0;
            for (List<SearchHit<NewsReference>> chunk : chunks) {
                if (monitor.isCanceled())
                    return;

                monitor.subTask(NLS.bind(Messages.NewsFiltersListDialog_FILTERED_N_OF_M_NEWS,
                        (counter * FILTER_CHUNK_SIZE), news.size()));
                List<INews> newsItemsToFilter = new ArrayList<INews>(FILTER_CHUNK_SIZE);
                for (SearchHit<NewsReference> chunkItem : chunk) {
                    INews newsItemToFilter = chunkItem.getResult().resolve();
                    if (newsItemToFilter != null && newsItemToFilter.isVisible())
                        newsItemsToFilter.add(newsItemToFilter);
                    else
                        CoreUtils.reportIndexIssue();
                }

                applyFilterOnChunks(newsItemsToFilter, filter);
                monitor.worked(1);
                counter++;
            }

            monitor.done();
        }
    };

    /* Show progress and allow for cancellation */
    ProgressMonitorDialog dialog = new ProgressMonitorDialog(getShell());
    dialog.setBlockOnOpen(false);
    dialog.setCancelable(true);
    dialog.setOpenOnRun(true);
    try {
        dialog.run(true, true, runnable);
    } catch (InvocationTargetException e) {
        Activator.getDefault().logError(e.getMessage(), e);
    } catch (InterruptedException e) {
        Activator.getDefault().logError(e.getMessage(), e);
    }
}

From source file:org.talend.commons.ui.swt.dialogs.ProgressDialog.java

License:Open Source License

public void executeProcess(boolean useAsync) throws InvocationTargetException, InterruptedException {
    Display display2 = null;/*  w  w w . j a  v a 2  s  . co  m*/
    if (parentShell != null) {
        display2 = parentShell.getDisplay();
    }
    final Display display = display2;
    final InvocationTargetException[] iteHolder = new InvocationTargetException[1];
    try {
        final IRunnableWithProgress op = new IRunnableWithProgress() {

            public void run(final IProgressMonitor monitor)
                    throws InvocationTargetException, InterruptedException {
                final InvocationTargetException[] iteHolder1 = new InvocationTargetException[1];
                try {
                    ProgressDialog.this.run(monitor);
                } catch (InvocationTargetException e) {
                    // Pass it outside the workspace runnable
                    iteHolder1[0] = e;
                } catch (InterruptedException e) {
                    // Re-throw as OperationCanceledException, which will be
                    // caught and re-thrown as InterruptedException below.
                    throw new OperationCanceledException(e.getMessage());
                }
                // CoreException and OperationCanceledException are propagated

                // Re-throw the InvocationTargetException, if any occurred
                if (iteHolder1[0] != null) {
                    throw iteHolder1[0];
                }
            }
        };

        if (useAsync) {
            display.asyncExec(new Runnable() {

                public void run() {
                    final ProgressMonitorDialog progressMonitorDialog = new ProgressMonitorDialog(parentShell);
                    if (timeBeforeShowDialog > 0) {
                        progressMonitorDialog.setOpenOnRun(false);
                        // for bug 16801
                        AsynchronousThreading asynchronousThreading = new AsynchronousThreading(
                                timeBeforeShowDialog, true, display, new Runnable() {

                                    public void run() {
                                        progressMonitorDialog.open();
                                    }
                                });
                        asynchronousThreading.start();
                    }

                    try {
                        progressMonitorDialog.run(false, true, op);
                    } catch (InvocationTargetException e) {
                        // Pass it outside the workspace runnable
                        iteHolder[0] = e;
                    } catch (InterruptedException e) {
                        // Re-throw as OperationCanceledException, which will be
                        // caught and re-thrown as InterruptedException below.
                        throw new OperationCanceledException(e.getMessage());
                    }
                }
            });
        } else {
            display.syncExec(new Runnable() {

                public void run() {
                    final ProgressMonitorDialog progressMonitorDialog = new ProgressMonitorDialog(parentShell);
                    if (timeBeforeShowDialog > 0) {
                        progressMonitorDialog.setOpenOnRun(false);
                        // for bug 16801
                        AsynchronousThreading asynchronousThreading = new AsynchronousThreading(
                                timeBeforeShowDialog, true, display, new Runnable() {

                                    public void run() {
                                        progressMonitorDialog.open();
                                    }
                                });
                        asynchronousThreading.start();
                    }

                    try {
                        progressMonitorDialog.run(false, true, op);
                    } catch (InvocationTargetException e) {
                        // Pass it outside the workspace runnable
                        iteHolder[0] = e;
                    } catch (InterruptedException e) {
                        // Re-throw as OperationCanceledException, which will be
                        // caught and re-thrown as InterruptedException below.
                        throw new OperationCanceledException(e.getMessage());
                    }
                }
            });
        }

    } catch (OperationCanceledException e) {
        throw new InterruptedException(e.getMessage());
    }
    // Re-throw the InvocationTargetException, if any occurred
    if (iteHolder[0] != null) {
        throw iteHolder[0];
    }
}

From source file:org.talend.designer.runtime.visualization.internal.actions.OpenDeclarationAction.java

License:Open Source License

/**
 * Searches the source for the given class name with progress monitor.
 * /*from  w  ww. ja  va  2s  . c  om*/
 * @return The source
 * @throws InterruptedException if operation is canceled
 */
private IType searchSource() throws InterruptedException {
    final ProgressMonitorDialog dialog = new ProgressMonitorDialog(
            PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell());
    dialog.setOpenOnRun(false);

    // search source corresponding to the class name
    final IType[] source = new IType[1];
    IRunnableWithProgress op = new IRunnableWithProgress() {

        @Override
        public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
            if (!searchEngineInitialized) {
                monitor.subTask(Messages.searchingSoruceMsg);
                searchEngineInitialized = true;
            }

            // open progress monitor dialog when it takes long time
            new Timer().schedule(new TimerTask() {

                @Override
                public void run() {
                    Display.getDefault().syncExec(new Runnable() {

                        @Override
                        public void run() {
                            dialog.open();
                        }
                    });
                }
            }, 400);

            if (className == null) {
                return;
            }

            try {
                source[0] = doSearchSource(className);
            } catch (CoreException e) {
                throw new InvocationTargetException(e);
            }
            if (monitor.isCanceled()) {
                throw new InterruptedException();
            }
        }
    };

    try {
        dialog.run(true, true, op);
    } catch (InvocationTargetException e) {
        Activator.log(IStatus.ERROR, NLS.bind(Messages.searchClassFailedMsg, className), e);
    }

    return source[0];
}

From source file:org.xmind.ui.internal.handlers.SaveWorkbookAsHandler.java

License:Open Source License

@Override
public Object execute(final ExecutionEvent event) throws ExecutionException {
    final IWorkbenchWindow window = HandlerUtil.getActiveWorkbenchWindowChecked(event);
    Object selection = HandlerUtil.getCurrentSelectionChecked(event);
    if (selection instanceof IStructuredSelection) {
        selection = ((IStructuredSelection) selection).getFirstElement();
    }//from w w w .ja  v a2 s.  com
    if (!(selection instanceof IWorkbookRef))
        return null;

    final String preferredWizardId = event.getParameter(MindMapCommandConstants.SAVE_AS_WIZARD_ID_PARAM);
    final Set<String> excludedWizardIds = getExcludedWizardIds(event);

    final IWorkbookRef oldWorkbookRef = (IWorkbookRef) selection;
    final IWorkbookRef[] result = new IWorkbookRef[1];

    final ProgressMonitorDialog jobRunner = new ProgressMonitorDialog(window.getShell());
    jobRunner.setOpenOnRun(false);

    SafeRunner.run(new SafeRunnable() {
        @Override
        public void run() throws Exception {
            result[0] = org.xmind.ui.internal.e4handlers.SaveWorkbookAsHandler
                    .saveWorkbookAs(new ISaveContext() {

                        @Override
                        public Object getContextVariable(String key) {
                            Object variable = HandlerUtil.getVariable(event, key);
                            return variable == IEvaluationContext.UNDEFINED_VARIABLE ? null : variable;
                        }

                        @Override
                        public <T> T getContextVariable(Class<T> key) {
                            return window.getService(key);
                        }
                    }, oldWorkbookRef, jobRunner, new IFilter() {
                        @Override
                        public boolean select(Object wizardId) {
                            if (preferredWizardId != null) {
                                return preferredWizardId.equals(wizardId);
                            } else if (!excludedWizardIds.isEmpty()) {
                                return !excludedWizardIds.contains(wizardId);
                            }
                            return true;
                        }
                    }, false);
        }
    });

    final IWorkbookRef newWorkbookRef = result[0];
    if (newWorkbookRef == null || newWorkbookRef.equals(oldWorkbookRef))
        return null;

    MessageDialog dialog = new MessageDialog(window.getShell(),
            MindMapMessages.SaveWorkbookAsHandler_doneDialog_title, null,
            MindMapMessages.SaveWorkbookAsHandler_doneDialog_message, MessageDialog.CONFIRM, new String[] {

                    MindMapMessages.SaveWorkbookAsHandler_doneDialog_okButton_text,

                    MindMapMessages.SaveWorkbookAsHandler_doneDialog_cancelButton_text

            }, 0);
    if (dialog.open() != MessageDialog.OK)
        return null;

    try {
        window.getActivePage().openEditor(MindMapUI.getEditorInputFactory().createEditorInput(newWorkbookRef),
                MindMapUI.MINDMAP_EDITOR_ID, true);
    } catch (PartInitException e) {
        throw new ExecutionException(e.getMessage(), e);
    }

    return null;
}

From source file:org.xmind.ui.internal.sharing.SharingUtils.java

License:Open Source License

public static void run(final IRunnableWithProgress runnable, Display display) {
    final Throwable[] exception = new Throwable[] { null };
    if (display != null && !display.isDisposed()) {
        display.syncExec(new Runnable() {
            public void run() {
                final ProgressMonitorDialog dialog = new ProgressMonitorDialog(null);
                dialog.setOpenOnRun(false);
                final boolean[] completed = new boolean[] { false };
                Display.getCurrent().timerExec(240, new Runnable() {
                    public void run() {
                        if (!completed[0])
                            dialog.open();
                    }/* w  w w .  ja v  a 2s. c  o  m*/
                });
                try {
                    dialog.run(true, false, runnable);
                } catch (InterruptedException e) {
                    // ignore
                } catch (InvocationTargetException e) {
                    exception[0] = e.getCause();
                } catch (Throwable e) {
                    exception[0] = e;
                } finally {
                    completed[0] = true;
                    dialog.close();
                    Shell shell = dialog.getShell();
                    if (shell != null) {
                        shell.dispose();
                    }
                }
            }
        });
    } else {
        try {
            runnable.run(new NullProgressMonitor());
        } catch (InterruptedException e) {
            // ignore
        } catch (InvocationTargetException e) {
            exception[0] = e.getCause();
        } catch (Throwable e) {
            exception[0] = e;
        }
    }
    if (exception[0] != null) {
        LocalNetworkSharingUI.log("Failed to disconnect from local network sharing service:", //$NON-NLS-1$
                exception[0]);

    }
}

From source file:org.xmind.ui.internal.spelling.SpellingCheckPrefPage.java

License:Open Source License

private void addDictionary(final Element element) {
    final String path = element.getPath();
    if (path == null)
        return;// ww  w .  jav  a  2s  .c o m

    try {
        ProgressMonitorDialog progress = new ProgressMonitorDialog(getShell());
        progress.setOpenOnRun(false);
        progress.run(true, false, new IRunnableWithProgress() {
            public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
                monitor.beginTask(Messages.addingDictionary, 1);
                SafeRunner.run(new SafeRunnable() {
                    public void run() throws Exception {
                        ISpellCheckerDescriptor descriptor = SpellCheckerRegistry.getInstance()
                                .importDictFile(new File(path), element.getName());
                        element.setPath(null);
                        element.setDescriptor(descriptor);
                    }
                });
                monitor.done();
            }
        });
    } catch (InvocationTargetException e) {
    } catch (InterruptedException e) {
    }
}

From source file:org.xmind.ui.internal.spelling.SpellingCheckPrefPage.java

License:Open Source License

private void removeDictionary(final ISpellCheckerDescriptor descriptor) {
    // Remove dictionary descriptor and local file
    try {/*from   w  w  w.  j a  v  a2s. co m*/
        ProgressMonitorDialog progress = new ProgressMonitorDialog(getShell());
        progress.setOpenOnRun(false);
        progress.run(true, false, new IRunnableWithProgress() {
            public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
                monitor.beginTask(Messages.removingDictionary, 1);
                SafeRunner.run(new SafeRunnable() {
                    public void run() throws Exception {
                        SpellCheckerRegistry.getInstance().removeDictionary(descriptor);
                    }
                });
                monitor.done();
            }
        });
    } catch (InvocationTargetException e) {
    } catch (InterruptedException e) {
    }
}