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

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

Introduction

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

Prototype

public ProgressMonitorDialog(Shell parent) 

Source Link

Document

Creates a progress monitor dialog under the given shell.

Usage

From source file:de.blizzy.backup.restore.RestoreDialog.java

License:Open Source License

private void restore(final Collection<Entry> entries) {
    String folder = null;/*from   w w w .  j  a v a  2s  .c  o  m*/
    for (;;) {
        DirectoryDialog dlg = new DirectoryDialog(getShell(), SWT.SAVE);
        dlg.setText(Messages.Title_SelectOutputFolder);
        dlg.setFilterPath(folder);
        folder = dlg.open();
        if (folder == null) {
            break;
        }

        if (new File(folder).list().length > 0) {
            MessageDialog.openError(getShell(), Messages.Title_FolderNotEmpty, NLS.bind(Messages.FolderNotEmpty,
                    Utils.getSimpleName(new FileSystemFileOrFolder(new File(folder)))));
            continue;
        }

        break;
    }

    if (folder != null) {
        alwaysRestoreFromOlderBackups = null;

        final String myFolder = folder;
        Backup backup = (Backup) ((IStructuredSelection) backupsViewer.getSelection()).getFirstElement();
        final int backupId = backup.id;
        final int numEntries = backup.numEntries;
        final ProgressMonitorDialog dlg = new ProgressMonitorDialog(getShell());
        IRunnableWithProgress runnable = new IRunnableWithProgress() {
            @Override
            public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {

                try {
                    monitor.beginTask(Messages.Title_RestoreFromBackup, numEntries);
                    for (Entry entry : entries) {
                        restoreEntry(entry, new File(myFolder), settings.getOutputFolder(), backupId, monitor,
                                dlg.getShell());
                    }
                } catch (IOException e) {
                    throw new InvocationTargetException(e);
                } finally {
                    monitor.done();
                }
            }
        };
        try {
            dlg.run(true, true, runnable);
        } catch (InvocationTargetException e) {
            // TODO
            BackupPlugin.getDefault().logError("error while restoring from backup", e.getCause()); //$NON-NLS-1$
        } catch (InterruptedException e) {
            // okay
        }
    }
}

From source file:de.blizzy.backup.Updater.java

License:Open Source License

public boolean update(Shell shell) throws Throwable {
    final boolean[] restartNecessary = new boolean[1];
    if (needsCheck()) {
        final ProgressMonitorDialog pmd = new ProgressMonitorDialog(shell);
        IRunnableWithProgress runnable = new IRunnableWithProgress() {
            @Override// ww w. java 2 s  . c o m
            @SuppressWarnings("synthetic-access")
            public void run(IProgressMonitor monitor) {
                SubMonitor progress = SubMonitor.convert(monitor);
                restartNecessary[0] = updateInJob(progress, pmd.getShell());
                monitor.done();
            }
        };
        try {
            pmd.run(true, true, runnable);
        } catch (InvocationTargetException e) {
            throw e.getCause();
        }
    }
    if (restartNecessary[0]) {
        IDialogSettings settings = Utils.getSection("versionCheck"); //$NON-NLS-1$
        settings.put("cleanupOldFeatures", true); //$NON-NLS-1$
    }
    return restartNecessary[0];
}

From source file:de.byteholder.geoclipse.mapprovider.MapProviderManager.java

License:Open Source License

/**
 * @param mpWms/*from   w ww  . ja v  a 2  s .  co m*/
 * @param capsUrl
 * @param returnMpWms
 *            Contains the checked wms map provider
 */
private static void checkWmsRunnable(final MPWms mpWms, final String capsUrl, final MPWms[] returnMpWms) {

    final IRunnableWithProgress progressRunnable = new IRunnableWithProgress() {

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

            final String capsUrlFinal = mpWms == null ? //
            capsUrl : mpWms.getCapabilitiesUrl();

            monitor.beginTask(Messages.MP_Manager_Task_GetWms, 1);
            monitor.subTask(capsUrlFinal);

            try {

                returnMpWms[0] = initializeWMS(mpWms, capsUrlFinal);

            } catch (final Exception e) {

                StatusUtil.showStatus(e.getMessage(), e);

                /*
                 * disable this wms map provider, it is possible that
                 * the server is currently not available
                 */
                for (final MP mapProvider : _allMapProviders) {

                    if (mapProvider instanceof MPWms) {

                        final MPWms wmsMp = (MPWms) mapProvider;

                        if (wmsMp.getCapabilitiesUrl().equalsIgnoreCase(capsUrlFinal)) {
                            wmsMp.setWmsEnabled(false);
                        }

                    } else if (mapProvider instanceof MPProfile) {

                        final MPProfile mpProfile = (MPProfile) mapProvider;

                        for (final MPWrapper mpWrapper : mpProfile.getAllWrappers()) {
                            final MP mp = mpWrapper.getMP();
                            if (mp instanceof MPWms) {
                                final MPWms wmsMp = (MPWms) mp;
                                if (wmsMp.getCapabilitiesUrl().equalsIgnoreCase(capsUrlFinal)) {
                                    wmsMp.setWmsEnabled(false);
                                }
                            }
                        }
                    }
                }

                returnMpWms[0] = null;
            }
        }
    };

    final Display display = Display.getDefault();

    display.syncExec(new Runnable() {
        public void run() {
            try {
                new ProgressMonitorDialog(display.getActiveShell()).run(false, false, progressRunnable);
            } catch (final InvocationTargetException e1) {
                StatusUtil.showStatus(e1.getMessage(), e1);
            } catch (final InterruptedException e1) {
                StatusUtil.showStatus(e1.getMessage(), e1);
            }
        }
    });
}

From source file:de.byteholder.geoclipse.mapprovider.MapProviderManager.java

License:Open Source License

private static void deleteOfflineMapFiles(final File offlineFolder, final boolean isDeletePartImages) {

    _isDeleteError = false;/*  ww w . j a v a2 s. com*/
    _deleteUIUpdateTime = System.currentTimeMillis();

    try {

        final IRunnableWithProgress runnable = new IRunnableWithProgress() {

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

                monitor.beginTask(UI.EMPTY_STRING, IProgressMonitor.UNKNOWN);

                deleteOfflineMapFilesFolder(offlineFolder, isDeletePartImages, monitor);
            }
        };

        new ProgressMonitorDialog(Display.getCurrent().getActiveShell()).run(true, true, runnable);

    } catch (final InvocationTargetException e) {
        e.printStackTrace();
    } catch (final InterruptedException e) {
        e.printStackTrace();
    }

    if (_isDeleteError) {
        StatusUtil.showStatus(
                NLS.bind(Messages.MP_Manager_DeleteOfflineImages_CannotDeleteFolder, offlineFolder),
                new Exception());
    }
}

From source file:de.clausthal.tu.ielf.resusdesigner.ResusEditor.java

License:Open Source License

protected boolean performSaveAs() {
    SaveAsDialog dialog = new SaveAsDialog(getSite().getWorkbenchWindow().getShell());
    dialog.setOriginalFile(((IFileEditorInput) getEditorInput()).getFile());
    dialog.open();/*from   w  ww . j av  a2s.  c om*/
    IPath path = dialog.getResult();

    if (path == null)
        return false;

    IWorkspace workspace = ResourcesPlugin.getWorkspace();
    final IFile file = workspace.getRoot().getFile(path);

    if (!file.exists()) {
        WorkspaceModifyOperation op = new WorkspaceModifyOperation() {
            public void execute(final IProgressMonitor monitor) {
                saveProperties();
                try {
                    ByteArrayOutputStream out = new ByteArrayOutputStream();
                    writeToOutputStream(out);
                    file.create(new ByteArrayInputStream(out.toByteArray()), true, monitor);
                    out.close();
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        };
        try {
            new ProgressMonitorDialog(getSite().getWorkbenchWindow().getShell()).run(false, true, op);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    try {
        superSetInput(new FileEditorInput(file));
        getCommandStack().markSaveLocation();
    } catch (Exception e) {
        e.printStackTrace();
    }
    return true;
}

From source file:de.dfki.iui.mmds.sdk.editors.grammar_rules.RulesEditor.java

License:Creative Commons License

/**
 * This is for implementing {@link IEditorPart} and simply saves the model
 * file. <!-- begin-user-doc --> <!-- end-user-doc -->
 * //from ww  w .j  a v a  2 s.  com
 * @generated
 */
@Override
public void doSave(IProgressMonitor progressMonitor) {
    // Save only resources that have actually changed.
    //
    final Map<Object, Object> saveOptions = new HashMap<Object, Object>();
    saveOptions.put(Resource.OPTION_SAVE_ONLY_IF_CHANGED, Resource.OPTION_SAVE_ONLY_IF_CHANGED_MEMORY_BUFFER);

    // Do the work within an operation because this is a long running
    // activity that modifies the workbench.
    //
    WorkspaceModifyOperation operation = new WorkspaceModifyOperation() {
        // This is the method that gets invoked when the operation runs.
        //
        @Override
        public void execute(IProgressMonitor monitor) {
            // Save the resources to the file system.
            //
            boolean first = true;
            for (Resource resource : editingDomain.getResourceSet().getResources()) {
                if ((first || !resource.getContents().isEmpty() || isPersisted(resource))
                        && !editingDomain.isReadOnly(resource)) {
                    try {
                        long timeStamp = resource.getTimeStamp();
                        resource.save(saveOptions);
                        if (resource.getTimeStamp() != timeStamp) {
                            savedResources.add(resource);
                        }
                    } catch (Exception exception) {
                        resourceToDiagnosticMap.put(resource, analyzeResourceProblems(resource, exception));
                    }
                    first = false;
                }
            }
        }
    };

    updateProblemIndication = false;
    try {
        // This runs the options, and shows progress.
        //
        new ProgressMonitorDialog(getSite().getShell()).run(true, false, operation);

        // Refresh the necessary state.
        //
        ((BasicCommandStack) editingDomain.getCommandStack()).saveIsDone();
        firePropertyChange(IEditorPart.PROP_DIRTY);
    } catch (Exception exception) {
        // Something went wrong that shouldn't.
        //
        Speech_recognitionEditorPlugin.INSTANCE.log(exception);
    }
    updateProblemIndication = true;
    updateProblemIndication();
}

From source file:de.dfki.iui.mmds.sdk.editors.model.ProjectEditor.java

License:Creative Commons License

/**
 * This is for implementing {@link IEditorPart} and simply saves the model
 * file. <!-- begin-user-doc --> <!-- end-user-doc -->
 * /*w w w  .java 2s  .  c  o  m*/
 * @generated NOT
 */
@Override
public void doSave(IProgressMonitor progressMonitor) {
    // Save only resources that have actually changed.
    //
    final Map<String, Object> saveOptions = new HashMap<String, Object>();
    saveOptions.put(Resource.OPTION_SAVE_ONLY_IF_CHANGED, Resource.OPTION_SAVE_ONLY_IF_CHANGED_MEMORY_BUFFER);
    saveOptions.put(Resource.OPTION_LINE_DELIMITER, Resource.OPTION_LINE_DELIMITER_UNSPECIFIED);
    saveOptions.put(XMIResource.OPTION_KEEP_DEFAULT_CONTENT, Boolean.FALSE);

    // Do the work within an operation because this is a long running
    // activity that modifies the workbench.
    //
    WorkspaceModifyOperation operation = new WorkspaceModifyOperation() {
        // This is the method that gets invoked when the operation runs.
        //
        @Override
        public void execute(IProgressMonitor monitor) {
            // Save the resources to the file system.
            //
            boolean first = true;
            for (Resource resource : editingDomain.getResourceSet().getResources()) {
                if ((first || !resource.getContents().isEmpty() || isPersisted(resource))
                        && !editingDomain.isReadOnly(resource)) {
                    try {
                        long timeStamp = resource.getTimeStamp();
                        EmfPersistence.write(resource, null, saveOptions);
                        if (resource.getTimeStamp() != timeStamp) {
                            savedResources.add(resource);
                        }
                    } catch (Exception exception) {
                        resourceToDiagnosticMap.put(resource, analyzeResourceProblems(resource, exception));
                    }
                    first = false;
                }
            }
        }
    };

    updateProblemIndication = false;
    try {
        // This runs the options, and shows progress.
        //
        new ProgressMonitorDialog(getSite().getShell()).run(true, false, operation);

        // Refresh the necessary state.
        //
        ((BasicCommandStack) editingDomain.getCommandStack()).saveIsDone();
        firePropertyChange(IEditorPart.PROP_DIRTY);
    } catch (Exception exception) {
        // Something went wrong that shouldn't.
        //
        ProjectEditorPlugin.INSTANCE.log(exception);
    }
    updateProblemIndication = true;
    updateProblemIndication();
}

From source file:de.fu_berlin.inf.dpp.project.SharedResourcesManager.java

License:Open Source License

protected void handleVCSActivity(VCSActivity activity) {
    final VCSActivity.Type activityType = activity.getType();
    SPath path = activity.getPath();/*from  w w  w  .  j a v  a  2s  .  c  o  m*/

    final IResource resource = ((EclipseResourceImpl) path.getResource()).getDelegate();

    final IProject project = ((EclipseProjectImpl) path.getProject()).getDelegate();

    final String url = activity.getURL();
    final String directory = activity.getDirectory();
    final String revision = activity.getParam1();

    // Connect is special since the project doesn't have a VCSAdapter
    // yet.
    final VCSAdapter vcs = activityType == VCSActivity.Type.CONNECT ? VCSAdapter.getAdapter(revision)
            : VCSAdapter.getAdapter(project);
    if (vcs == null) {
        log.warn("Could not execute VCS activity. Do you have the Subclipse plug-in installed?");
        if (activity.containedActivity.size() > 0) {
            log.trace("contained activities: " + activity.containedActivity.toString());
        }
        for (IResourceActivity a : activity.containedActivity) {
            consumer.exec(a);
        }
        return;
    }

    try {
        // TODO Should these operations run in an IWorkspaceRunnable?
        Shell shell = SWTUtils.getShell();
        ProgressMonitorDialog progressMonitorDialog = new ProgressMonitorDialog(shell);
        progressMonitorDialog.open();
        Shell pmdShell = progressMonitorDialog.getShell();
        pmdShell.setText("Saros running VCS operation");
        log.trace("about to call progressMonitorDialog.run");
        progressMonitorDialog.run(true, false, new IRunnableWithProgress() {
            @Override
            public void run(IProgressMonitor progress)

                    throws InvocationTargetException, InterruptedException {
                log.trace("progressMonitorDialog.run started");
                if (!SWTUtils.isSWT())
                    log.trace("not in SWT thread");
                if (activityType == VCSActivity.Type.CONNECT) {
                    vcs.connect(project, url, directory, progress);
                } else if (activityType == VCSActivity.Type.DISCONNECT) {
                    vcs.disconnect(project, revision != null, progress);
                } else if (activityType == VCSActivity.Type.SWITCH) {
                    vcs.switch_(resource, url, revision, progress);
                } else if (activityType == VCSActivity.Type.UPDATE) {
                    vcs.update(resource, revision, progress);
                } else {
                    log.error("VCS activity type not implemented yet.");
                }
                log.trace("progressMonitorDialog.run done");
            }

        });
        pmdShell.dispose();
    } catch (InvocationTargetException e) {
        // TODO We can't get here, right?
        throw new IllegalStateException(e);
    } catch (InterruptedException e) {
        log.error("Code not designed to be interrupted!");
    }
}

From source file:de.fu_berlin.inf.dpp.ui.actions.ConnectionTestAction.java

License:Open Source License

/**
 * @review runSafe OK/*  ww w.j a v  a  2s.c  om*/
 */
@Override
public void run() {

    RosterEntry rosterEntry = null;
    List<RosterEntry> selectedRosterEntries = SelectionRetrieverFactory.getSelectionRetriever(RosterEntry.class)
            .getSelection();
    if (selectedRosterEntries.size() == 1) {
        rosterEntry = selectedRosterEntries.get(0);
    }

    if (rosterEntry == null) {
        log.error("RosterEntry should not be null at this point!");
        return;
    }

    final JID recipient = new JID(rosterEntry.getUser());

    final TestResult[] testResult = new TestResult[1];
    try {
        new ProgressMonitorDialog(null).run(true, true, new IRunnableWithProgress() {

            public void run(IProgressMonitor progress) throws InvocationTargetException, InterruptedException {
                try {
                    testResult[0] = connectionTestManager.runConnectionTest(recipient, 65536,
                            SubMonitor.convert(progress));
                } catch (XMPPException e) {
                    throw new InvocationTargetException(e);
                }
            }
        });
    } catch (InvocationTargetException e) {
        ErrorDialog.openError(EditorAPI.getShell(), "Connection Test failed",
                "Connection Test with buddy " + recipient + " failed", new Status(IStatus.ERROR,
                        "de.fu_berlin.inf.dpp", IStatus.ERROR, Utils.getMessage(e.getCause()), e.getCause()));
        return;
    } catch (InterruptedException e) {
        log.error(e);
        return;
    }
    MessageDialog.openInformation(EditorAPI.getShell(), "Connection test successful",
            "Connection Test with buddy " + recipient + " using " + testResult[0].mode.toString() + " "
                    + Utils.throughput(testResult[0].dataSize, testResult[0].transferTime));

}

From source file:de.fu_berlin.inf.dpp.ui.SarosUI.java

License:Open Source License

/**
 * @swt//from   w  ww . j a v a 2  s . c  om
 */
public void performPermissionChange(final User user, final Permission newPermission) {

    ProgressMonitorDialog dialog = new ProgressMonitorDialog(EditorAPI.getAWorkbenchWindow().getShell());

    try {
        dialog.run(true, true, new IRunnableWithProgress() {
            public void run(final IProgressMonitor monitor) {

                final SubMonitor progress = SubMonitor.convert(monitor);

                try {

                    progress.beginTask("Performing permission change", IProgressMonitor.UNKNOWN);

                    sessionManager.getSarosSession().initiatePermissionChange(user, newPermission, progress);

                } catch (CancellationException e) {
                    log.warn("Permission change failed because buddy" + " canceled the permission change");
                    Utils.runSafeSWTSync(log, new Runnable() {
                        public void run() {
                            MessageDialog.openInformation(EditorAPI.getAWorkbenchWindow().getShell(),
                                    "Permission Change Canceled", "The permission change was canceled.");
                        }
                    });
                } catch (InterruptedException e) {
                    log.error("Code not designed to be interruptable", e);
                } finally {
                    progress.done();
                }
            }
        });
    } catch (InvocationTargetException e) {
        log.error("Internal Error: ", e);
        MessageDialog.openError(EditorAPI.getAWorkbenchWindow().getShell(), "Permission Change Failed",
                "Permission change failed because of an internal error.\n\n" + " Please try again.");
    } catch (InterruptedException e) {
        log.error("Code not designed to be interruptable", e);
    }
}