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:org.apache.cactus.eclipse.runner.containers.ant.AntContainerManager.java

License:Apache License

/**
 * Launches a new progress dialog for preparation cancellation.
 * //from ww  w  .  j a v  a 2  s . c  o  m
 * @param theProvider the provider which preparation to cancel
 */
private void cancelPreparation(final IContainerProvider theProvider) {
    ProgressMonitorDialog dialog = new ProgressMonitorDialog(getShell());
    IRunnableWithProgress tearDownRunnable = new IRunnableWithProgress() {
        public void run(IProgressMonitor thePM) throws InterruptedException {
            try {
                teardownCactusTests(thePM, theProvider);
            } catch (CoreException e) {
                throw new InterruptedException(e.getMessage());
            }
        }
    };
    try {
        dialog.run(true, true, tearDownRunnable);
    } catch (InvocationTargetException tearDownE) {
        CactusPlugin.displayErrorMessage(CactusMessages.getString("CactusLaunch.message.teardown.error"),
                tearDownE.getTargetException().getMessage(), null);
    } catch (InterruptedException tearDownE) {
        CactusPlugin.displayErrorMessage(CactusMessages.getString("CactusLaunch.message.teardown.error"),
                tearDownE.getMessage(), null);
    }
}

From source file:org.apache.openjpa.eclipse.PluginLibrary.java

License:Apache License

/**
 * Gets the runtime libraries required for this bundle to the given project.
 * //  w w w. j a v a 2  s . c o m
 * @param list of patterns that matches an actual library. null implies all runtime libraries.
 * @param copy if true then the libraries are copied to the given project directory.
 */
public IClasspathEntry[] getLibraryClasspaths(IProject project, List<String> libs, boolean copy)
        throws CoreException {
    if (libs != null && libs.isEmpty())
        return new IClasspathEntry[0];
    Bundle bundle = Platform.getBundle(BUNDLE_ID);
    List<String> libraries = getRuntimeLibraries(bundle);
    List<IClasspathEntry> entries = new ArrayList<IClasspathEntry>();
    ProgressMonitorDialog progress = null;
    for (String lib : libraries) {
        try {
            if (".".equals(lib))
                continue;
            URL url = bundle.getEntry(lib);
            url = FileLocator.resolve(url);
            String urlString = url.getFile();
            if (!urlString.endsWith(".jar") || !matchesPattern(urlString, libs))
                continue;
            String libName = urlString.substring(urlString.indexOf('!') + 1);
            IFile iFile = project.getFile(libName);
            if (iFile == null) {
                continue;
            }
            IPath outPath = iFile.getRawLocation();
            File outFile = outPath.toFile();
            if (!outFile.getParentFile().exists() && copy) {
                outFile.getParentFile().mkdirs();
            }
            if (!outFile.exists() && copy) {
                outFile.createNewFile();
            }
            if (copy) {
                boolean firstTask = progress == null;
                if (progress == null) {
                    progress = new ProgressMonitorDialog(Activator.getShell());
                }
                if (firstTask) {
                    int nTask = libs == null ? libraries.size() : libs.size();
                    progress.run(true, false, new JarCopier(url.openStream(), outFile, true, nTask));
                } else {
                    progress.run(true, false, new JarCopier(url.openStream(), outFile));
                }
            }
            IClasspathEntry classpath = JavaCore.newLibraryEntry(outPath, null, null);
            entries.add(classpath);
        } catch (Exception e) {
            Activator.log(e);
        } finally {
            if (progress != null) {
                progress.getProgressMonitor().done();
            }
        }
    }
    return entries.toArray(new IClasspathEntry[entries.size()]);
}

From source file:org.apache.sling.ide.eclipse.ui.internal.InstallEditorSection.java

License:Apache License

private void initialize() {

    final ISlingLaunchpadConfiguration config = launchpadServer.getConfiguration();

    quickLocalInstallButton.setSelection(config.bundleInstallLocally());
    bundleLocalInstallButton.setSelection(!config.bundleInstallLocally());

    SelectionListener listener = new SelectionAdapter() {

        @Override//from   w ww.  j  av a 2 s  .c o m
        public void widgetSelected(SelectionEvent e) {
            execute(new SetBundleInstallLocallyCommand(server, quickLocalInstallButton.getSelection()));
        }
    };

    quickLocalInstallButton.addSelectionListener(listener);
    bundleLocalInstallButton.addSelectionListener(listener);

    Version serverVersion = launchpadServer
            .getBundleVersion(EmbeddedArtifactLocator.SUPPORT_BUNDLE_SYMBOLIC_NAME);
    final EmbeddedArtifact supportBundle = artifactLocator.loadToolingSupportBundle();

    final Version embeddedVersion = new Version(supportBundle.getVersion());

    updateActionArea(serverVersion, embeddedVersion);

    installOrUpdateSupportBundleLink.addHyperlinkListener(new HyperlinkAdapter() {

        @Override
        public void linkActivated(HyperlinkEvent e) {

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

                    @Override
                    public void run(IProgressMonitor monitor)
                            throws InvocationTargetException, InterruptedException {
                        final Version remoteVersion;
                        monitor.beginTask("Installing support bundle", 3);
                        // double-check, just in case
                        monitor.setTaskName("Getting remote bundle version");

                        Version deployedVersion;
                        final String message;
                        try {
                            RepositoryInfo repositoryInfo = ServerUtil.getRepositoryInfo(server.getOriginal(),
                                    monitor);
                            OsgiClient client = osgiClientFactory.createOsgiClient(repositoryInfo);
                            remoteVersion = client
                                    .getBundleVersion(EmbeddedArtifactLocator.SUPPORT_BUNDLE_SYMBOLIC_NAME);
                            deployedVersion = remoteVersion;

                            monitor.worked(1);

                            if (remoteVersion != null && remoteVersion.compareTo(embeddedVersion) >= 0) {
                                // version already up-to-date, due to bundle version
                                // changing between startup check and now
                                message = "Bundle is already installed and up to date";
                            } else {
                                monitor.setTaskName("Installing bundle");
                                InputStream contents = null;
                                try {
                                    contents = supportBundle.openInputStream();
                                    client.installBundle(contents, supportBundle.getName());
                                } finally {
                                    IOUtils.closeQuietly(contents);
                                }
                                deployedVersion = embeddedVersion;
                                message = "Bundle version " + embeddedVersion + " installed";

                            }
                            monitor.worked(1);

                            monitor.setTaskName("Updating server configuration");
                            final Version finalDeployedVersion = deployedVersion;
                            Display.getDefault().syncExec(new Runnable() {
                                @Override
                                public void run() {
                                    execute(new SetBundleVersionCommand(server,
                                            EmbeddedArtifactLocator.SUPPORT_BUNDLE_SYMBOLIC_NAME,
                                            finalDeployedVersion.toString()));
                                    try {
                                        server.save(false, new NullProgressMonitor());
                                    } catch (CoreException e) {
                                        Activator.getDefault().getLog().log(e.getStatus());
                                    }
                                }
                            });
                            monitor.worked(1);

                        } catch (OsgiClientException e) {
                            throw new InvocationTargetException(e);
                        } catch (URISyntaxException e) {
                            throw new InvocationTargetException(e);
                        } catch (IOException e) {
                            throw new InvocationTargetException(e);
                        } finally {
                            monitor.done();
                        }

                        Display.getDefault().asyncExec(new Runnable() {
                            @Override
                            public void run() {
                                MessageDialog.openInformation(getShell(), "Support bundle install operation",
                                        message);
                            }
                        });
                    }
                });
            } catch (InvocationTargetException e1) {

                IStatus status = new Status(Status.ERROR, Activator.PLUGIN_ID,
                        "Error while installing support bundle: " + e1.getTargetException().getMessage(),
                        e1.getTargetException());

                ErrorDialog.openError(getShell(), "Error while installing support bundle", e1.getMessage(),
                        status);
            } catch (InterruptedException e1) {
                Thread.currentThread().interrupt();
                return;
            }
        }
    });
}

From source file:org.archicontribs.modelrepository.actions.CloneModelAction.java

License:Open Source License

@Override
public void run() {
    CloneInputDialog dialog = new CloneInputDialog(fWindow.getShell());
    if (dialog.open() != Window.OK) {
        return;/*from ww  w. ja v a2s .c om*/
    }

    final String repoURL = dialog.getURL();
    final String userName = dialog.getUsername();
    final String userPassword = dialog.getPassword();

    if (!StringUtils.isSet(repoURL) && !StringUtils.isSet(userName) && !StringUtils.isSet(userPassword)) {
        return;
    }

    File localGitFolder = new File(ModelRepositoryPlugin.INSTANCE.getUserModelRepositoryFolder(),
            GraficoUtils.getLocalGitFolderName(repoURL));

    // Folder is not empty
    if (localGitFolder.exists() && localGitFolder.isDirectory() && localGitFolder.list().length > 0) {
        MessageDialog.openError(fWindow.getShell(), Messages.CloneModelAction_0,
                Messages.CloneModelAction_2 + " " + localGitFolder.getAbsolutePath()); //$NON-NLS-1$

        return;
    }

    class Progress extends EmptyProgressMonitor implements IRunnableWithProgress {
        private IProgressMonitor monitor;

        @Override
        public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
            try {
                this.monitor = monitor;

                monitor.beginTask(Messages.CloneModelAction_4, IProgressMonitor.UNKNOWN);

                // Clone
                GraficoUtils.cloneModel(localGitFolder, repoURL, userName, userPassword, this);

                monitor.subTask(Messages.CloneModelAction_5);

                // Load
                GraficoUtils.loadModel(localGitFolder, fWindow.getShell());

                // Store credentials if option is set
                if (ModelRepositoryPlugin.INSTANCE.getPreferenceStore()
                        .getBoolean(IPreferenceConstants.PREFS_STORE_REPO_CREDENTIALS)) {
                    SimpleCredentialsStorage sc = new SimpleCredentialsStorage(localGitFolder);
                    sc.store(userName, userPassword);
                }
            } catch (GitAPIException | IOException | NoSuchAlgorithmException | InvalidKeySpecException ex) {
                ex.printStackTrace();
                MessageDialog.openError(fWindow.getShell(), Messages.CloneModelAction_0,
                        Messages.CloneModelAction_3 + " " + //$NON-NLS-1$
                                ex.getMessage());
            } finally {
                monitor.done();
            }
        }

        @Override
        public void beginTask(String title, int totalWork) {
            monitor.subTask(title);
        }

        @Override
        public boolean isCancelled() {
            return monitor.isCanceled();
        }
    }

    Display.getCurrent().asyncExec(new Runnable() {
        @Override
        public void run() {
            try {
                ProgressMonitorDialog pmDialog = new ProgressMonitorDialog(fWindow.getShell());
                pmDialog.run(false, true, new Progress());
            } catch (InvocationTargetException | InterruptedException ex) {
                ex.printStackTrace();
            }
        }
    });
}

From source file:org.archicontribs.modelrepository.actions.PushModelAction.java

License:Open Source License

@Override
public void run() {
    boolean doPush = MessageDialog.openConfirm(fWindow.getShell(), "Publish", "Publish changes?");

    if (!doPush) {
        return;//from  w w w .jav a2s.c  om
    }

    String credentials[] = null;
    try {
        credentials = UserDetails.getUserNameAndPasswordFromCredentialsFileOrDialog(getGitRepository(),
                fWindow.getShell());
    } catch (IOException ex) {
        ex.printStackTrace();
    }
    if (credentials == null) {
        return;
    }

    final String userName = credentials[0];
    final String userPassword = credentials[1];

    class Progress extends EmptyProgressMonitor implements IRunnableWithProgress {
        private IProgressMonitor monitor;

        @Override
        public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
            try {
                this.monitor = monitor;

                // First we need to Pull and resolve any conflicts
                PullResult pullResult = GraficoUtils.pullFromRemote(getGitRepository(), userName, userPassword,
                        this);

                if (!pullResult.isSuccessful()) {
                    monitor.done();

                    Display.getCurrent().asyncExec(new Runnable() {
                        @Override
                        public void run() {
                            try {
                                MergeConflictHandler handler = new MergeConflictHandler(
                                        pullResult.getMergeResult(), getGitRepository(), fWindow.getShell());
                                boolean result = handler.checkForMergeConflicts();
                                if (result) {
                                    handler.mergeAndCommit();
                                    // We should return now and ask the user to try again, in case there have been more changes since this
                                    MessageDialog.openInformation(fWindow.getShell(), "Publish",
                                            "Conflicts resolved. Please Publish again.");
                                } else {
                                    // User cancelled - do nothing (I think!)
                                }
                            } catch (IOException | GitAPIException ex) {
                                displayErrorDialog(ex);
                            }
                        }
                    });
                } else {
                    monitor.beginTask("Publishing", IProgressMonitor.UNKNOWN);

                    // Push
                    GraficoUtils.pushToRemote(getGitRepository(), userName, userPassword, this);
                }
            } catch (IOException | GitAPIException ex) {
                ex.printStackTrace();
            } finally {
                monitor.done();
            }
        }

        @Override
        public void beginTask(String title, int totalWork) {
            monitor.subTask(title);
        }

        @Override
        public boolean isCancelled() {
            return monitor.isCanceled();
        }
    }

    Display.getCurrent().asyncExec(new Runnable() {
        @Override
        public void run() {
            try {
                ProgressMonitorDialog pmDialog = new ProgressMonitorDialog(fWindow.getShell());
                pmDialog.run(false, true, new Progress());
            } catch (InvocationTargetException | InterruptedException ex) {
                ex.printStackTrace();
            }
        }
    });
}

From source file:org.archicontribs.modelrepository.actions.RefreshModelAction.java

License:Open Source License

@Override
public void run() {
    // TODO we need to prompt user to save/commit changes before a pull and reload

    if (IEditorModelManager.INSTANCE.isModelLoaded(getGitRepository())) {
        MessageDialog.openInformation(fWindow.getShell(), "Refresh",
                "Model is already open. Close it and retry.");
        return;//from   w ww .j a v a 2 s . co m
    }

    String credentials[] = null;
    try {
        credentials = UserDetails.getUserNameAndPasswordFromCredentialsFileOrDialog(getGitRepository(),
                fWindow.getShell());
    } catch (IOException ex) {
        ex.printStackTrace();
    }
    if (credentials == null) {
        return;
    }

    final String userName = credentials[0];
    final String userPassword = credentials[1];

    class Progress extends EmptyProgressMonitor implements IRunnableWithProgress {
        private IProgressMonitor monitor;

        @Override
        public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
            try {
                this.monitor = monitor;

                monitor.beginTask("Refreshing", IProgressMonitor.UNKNOWN);

                // First we need to Pull and check for conflicts
                PullResult pullResult = GraficoUtils.pullFromRemote(getGitRepository(), userName, userPassword,
                        this);

                monitor.done();

                Display.getCurrent().asyncExec(new Runnable() {
                    @Override
                    public void run() {
                        // Conflict merger
                        if (!pullResult.isSuccessful()) {
                            try {
                                MergeConflictHandler handler = new MergeConflictHandler(
                                        pullResult.getMergeResult(), getGitRepository(), fWindow.getShell());
                                boolean result = handler.checkForMergeConflicts();
                                if (result) {
                                    handler.mergeAndCommit();
                                } else {
                                    // User cancelled - we assume user has committed all changes so we can reset
                                    handler.resetToLocalState();
                                    return;
                                }
                            } catch (IOException | GitAPIException ex) {
                                displayErrorDialog(ex);
                            }
                        }

                        // Load
                        try {
                            GraficoUtils.loadModel(getGitRepository(), fWindow.getShell());
                        } catch (IOException ex) {
                            displayErrorDialog(ex);
                        }
                    }
                });
            } catch (GitAPIException | IOException ex) {
                displayErrorDialog(ex);
            } finally {
                monitor.done();
            }
        }

        @Override
        public void beginTask(String title, int totalWork) {
            monitor.subTask(title);
        }

        @Override
        public boolean isCancelled() {
            return monitor.isCanceled();
        }
    }

    Display.getCurrent().asyncExec(new Runnable() {
        @Override
        public void run() {
            try {
                ProgressMonitorDialog pmDialog = new ProgressMonitorDialog(fWindow.getShell());
                pmDialog.run(false, true, new Progress());
            } catch (InvocationTargetException | InterruptedException ex) {
                ex.printStackTrace();
            }
        }
    });

}

From source file:org.atomictagging.ui.handlers.SaveHandler.java

License:Open Source License

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

    ProgressMonitorDialog dialog = new ProgressMonitorDialog(shell);
    dialog.open();/*from w  ww.  ja  v  a 2  s.  c  o  m*/
    dialog.run(true, true, new IRunnableWithProgress() {
        @Override
        public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
            pmContext.set(IProgressMonitor.class.getName(), monitor);
            if (contribution != null) {
                Object clientObject = contribution.getObject();
                //               ContextInjectionFactory.invoke(clientObject, Persist.class, //$NON-NLS-1$
                // pmContext, null);
            }
        }
    });

    if (pmContext instanceof IDisposable) {
        ((IDisposable) pmContext).dispose();
    }
}

From source file:org.bbaw.pdr.ae.backup.commands.CreateEmptyDBHandler.java

License:Open Source License

@Override
public final Object execute(final ExecutionEvent event) throws ExecutionException {
    if (!_urChecker.isUserGuest()) {
        Shell activeShell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell();
        ProgressMonitorDialog dialog = new ProgressMonitorDialog(activeShell);

        try {//from  w  w w .j  a  v a2  s . c  o  m
            dialog.run(true, true, new IRunnableWithProgress() {
                @Override
                public void run(final IProgressMonitor monitor) {
                    monitor.beginTask("Delete Data from Database and create new and empty Databases", HUNDRED);
                    boolean backupSuccessfull = false;
                    UIJob job = new UIJob("Feedbackup") {
                        @Override
                        public IStatus runInUIThread(final IProgressMonitor monitor) {
                            IWorkbench workbench = PlatformUI.getWorkbench();
                            Display display = workbench.getDisplay();
                            Shell shell = new Shell(display);
                            String message = NLMessages.getString("Handler_empty_db_warning");
                            message += "\n" + NLMessages.getString("Handler_empty_db_warning2");
                            MessageDialog messageDialog = new MessageDialog(shell,
                                    NLMessages.getString("Handler_empty_db_title"), null, message,
                                    MessageDialog.INFORMATION,
                                    new String[] { NLMessages.getString("Handler_yes"), //$NON-NLS-1$
                                            NLMessages.getString("Handler_no") }, //$NON-NLS-1$
                                    1);
                            _messageReturnCode = messageDialog.open();
                            return Status.OK_STATUS;
                        }
                    };
                    job.setUser(true);
                    job.schedule();
                    try {
                        job.join();
                    } catch (InterruptedException e1) {
                        // TODO Auto-generated catch block
                        e1.printStackTrace();
                    }
                    monitor.worked(TEN);
                    if (_messageReturnCode == 0) {
                        job = new UIJob("Feedbackup") {
                            @Override
                            public IStatus runInUIThread(final IProgressMonitor monitor) {
                                IWorkbench workbench = PlatformUI.getWorkbench();
                                Display display = workbench.getDisplay();
                                Shell shell = new Shell(display);
                                String message = NLMessages.getString("WriteLocalBackupHandler_warning0"); //$NON-NLS-1$
                                message += NLMessages.getString("WriteLocalBackupHandler_warning1"); //$NON-NLS-1$
                                MessageDialog messageDialog = new MessageDialog(shell,
                                        NLMessages.getString("WriteLocalBackupHandler_title"), null, //$NON-NLS-1$
                                        message, MessageDialog.WARNING,
                                        new String[] { NLMessages.getString("Handler_yes"), //$NON-NLS-1$
                                                NLMessages.getString("Handler_no") }, //$NON-NLS-1$
                                        1);
                                _messageReturnCode = messageDialog.open();
                                return Status.OK_STATUS;
                            }
                        };
                        job.setUser(true);
                        job.schedule();
                        try {
                            job.join();
                        } catch (InterruptedException e1) {
                            // TODO Auto-generated catch block
                            e1.printStackTrace();
                        }
                        monitor.worked(TEN);
                        if (_messageReturnCode == 0) {
                            job = new UIJob("Feedbackup") {
                                @Override
                                public IStatus runInUIThread(final IProgressMonitor monitor) {
                                    IWorkbench workbench = PlatformUI.getWorkbench();
                                    Display display = workbench.getDisplay();
                                    Shell shell = new Shell(display);
                                    DirectoryDialog directoryDialog = new DirectoryDialog(shell);
                                    directoryDialog.setFilterPath("/"); //$NON-NLS-1$
                                    directoryDialog.setMessage(
                                            NLMessages.getString("WriteLocalBackupHandler_message")); //$NON-NLS-1$
                                    directoryDialog
                                            .setText(NLMessages.getString("WriteLocalBackupHandler_title2")); //$NON-NLS-1$
                                    _selectedDirectory = directoryDialog.open();
                                    return Status.OK_STATUS;
                                }
                            };
                            job.setUser(true);
                            job.schedule();
                            try {
                                job.join();
                            } catch (InterruptedException e1) {
                                e1.printStackTrace();
                            }
                            monitor.worked(TEN);
                            if (_selectedDirectory != null) {
                                IDBManager dbm = Facade.getInstanz().getDBManager();
                                try {
                                    dbm.writeToLocalBackup(_selectedDirectory);
                                    monitor.worked(FIFTY);
                                    backupSuccessfull = true;
                                    job = new UIJob("Feedbackup") {
                                        @Override
                                        public IStatus runInUIThread(final IProgressMonitor monitor) {
                                            IWorkbench workbench = PlatformUI.getWorkbench();
                                            Display display = workbench.getDisplay();
                                            Shell shell = new Shell(display);
                                            String info = NLMessages
                                                    .getString("Commands_message_local_backup_success");
                                            MessageDialog infoDialog = new MessageDialog(shell,
                                                    NLMessages.getString("Commands_title_local_backup_success"),
                                                    null, info, MessageDialog.INFORMATION,
                                                    new String[] { NLMessages.getString("Handler_ok") }, 0); //$NON-NLS-1$
                                            infoDialog.open();
                                            return Status.OK_STATUS;
                                        }
                                    };
                                    job.setUser(true);
                                    job.schedule();
                                    try {
                                        job.join();
                                    } catch (InterruptedException e1) {
                                        // TODO Auto-generated catch block
                                        e1.printStackTrace();
                                    }
                                    monitor.worked(TEN);

                                } catch (Exception e) {
                                    backupSuccessfull = false;
                                    showBackupErrorDialog();
                                    e.printStackTrace();
                                }
                            }
                        }
                        if (new UserRichtsChecker().isUserPDRAdmin() || backupSuccessfull) {
                            IDBManager dbm = Facade.getInstanz().getDBManager();
                            try {
                                dbm.createEmptyDB("person");
                                monitor.worked(TEN);
                                dbm.createEmptyDB("aspect");
                                monitor.worked(TEN);
                                dbm.createEmptyDB("reference");
                                monitor.worked(TEN);
                                IPdrIdService idService = Facade.getInstanz().getIdService();
                                try {
                                    idService.clearAllUpdateStates();
                                } catch (Exception e1) {
                                    // TODO Auto-generated catch block
                                    e1.printStackTrace();
                                }
                                try {
                                    idService.setUpdateTimeStamp(AEConstants.FIRST_EVER_UPDATE_TIMESTAMP);
                                } catch (Exception e1) {
                                    // TODO Auto-generated catch block
                                    e1.printStackTrace();
                                }
                                try {
                                    idService.clearAllUpdateStates();
                                } catch (Exception e) {
                                    // TODO Auto-generated catch block
                                    e.printStackTrace();
                                }
                                job = new UIJob("Feedbackup") {
                                    @Override
                                    public IStatus runInUIThread(final IProgressMonitor monitor) {
                                        Facade.getInstanz().refreshAllData();
                                        IWorkbench workbench = PlatformUI.getWorkbench();
                                        Display display = workbench.getDisplay();
                                        Shell shell = new Shell(display);
                                        String info = NLMessages.getString("Handler_empty_db_successful");
                                        MessageDialog infoDialog = new MessageDialog(shell,
                                                NLMessages.getString("Handler_empty_db_successful"), null, info,
                                                MessageDialog.INFORMATION,
                                                new String[] { NLMessages.getString("Handler_ok") }, 0); //$NON-NLS-1$
                                        infoDialog.open();
                                        return Status.OK_STATUS;
                                    }
                                };
                                job.setUser(true);
                                job.schedule();
                                monitor.worked(TEN);
                            } catch (Exception e) {
                                showEmptyErrorDialog();
                                e.printStackTrace();
                            }
                        }
                    }
                    monitor.done();
                }
            });
        } catch (InvocationTargetException e) {
            showEmptyErrorDialog();
            e.printStackTrace();
        } catch (InterruptedException e) {
            showEmptyErrorDialog();
            e.printStackTrace();
        }
    } else {
        MessageDialog.openInformation(HandlerUtil.getActiveWorkbenchWindow(event).getShell(),
                NLMessages.getString("Commandsr_guest_user"),
                NLMessages.getString("Commandsr_guest_user_denied")); //$NON-NLS-1$
    }

    return null;
}

From source file:org.bbaw.pdr.ae.backup.commands.LoadLocalBackupHandler.java

License:Open Source License

/** execute method.
 * @param event to be executed.// w  w w .  j a v  a2 s. c  o  m
 * @throws ExecutionException ee.
 * @return null. */
public final Object execute(final ExecutionEvent event) throws ExecutionException {
    if (!_urChecker.isUserGuest()) {
        String message = NLMessages.getString("LoadLocalBackupHandler_warning0");
        message += NLMessages.getString("LoadLocalBackupHandler_warning1");
        MessageDialog messageDialog = new MessageDialog(HandlerUtil.getActiveWorkbenchWindow(event).getShell(),
                NLMessages.getString("LoadLocalBackupHandler_title"), null, message, MessageDialog.WARNING,
                new String[] { NLMessages.getString("Handler_yes"), NLMessages.getString("Handler_no") }, 1);
        if (messageDialog.open() == 0) {
            DirectoryDialog directoryDialog = new DirectoryDialog(
                    PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell());
            directoryDialog.setFilterPath("/"); //$NON-NLS-1$
            directoryDialog.setMessage(NLMessages.getString("LoadLocalBackupHandler_message"));
            directoryDialog.setText(NLMessages.getString("LoadLocalBackupHandler_title2"));
            final String selectedDirectory = directoryDialog.open();
            if (selectedDirectory != null) {
                //             System.out.println(selectedDirectory + " was selected."); //$NON-NLS-1$
                final IDBManager dbm = Facade.getInstanz().getDBManager();

                final ProgressMonitorDialog dialog = new ProgressMonitorDialog(new Shell());
                dialog.setCancelable(false);

                try {
                    dialog.run(true, true, new IRunnableWithProgress() {

                        @Override
                        public void run(final IProgressMonitor monitor) {
                            monitor.beginTask("Load Local Backup", 100);
                            // if (monitor.isCanceled())
                            // {
                            // return Status.CANCEL_STATUS;
                            // }
                            dbm.loadLocalBackup(selectedDirectory, monitor);
                            monitor.done();

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

                IHandlerService handlerService = (IHandlerService) PlatformUI.getWorkbench()
                        .getService(IHandlerService.class);
                try {
                    handlerService.executeCommand("org.bbaw.pdr.ae.base.commands.RefreshFromDB", null); //$NON-NLS-1$
                } catch (ExecutionException e) {
                    e.printStackTrace();
                } catch (NotDefinedException e) {
                    e.printStackTrace();
                } catch (NotEnabledException e) {
                    e.printStackTrace();
                } catch (NotHandledException e) {
                    e.printStackTrace();
                }
            }

        }
    } else {
        MessageDialog.openInformation(HandlerUtil.getActiveWorkbenchWindow(event).getShell(),
                NLMessages.getString("Commandsr_guest_user"),
                NLMessages.getString("Commandsr_guest_user_denied")); //$NON-NLS-1$
    }
    return null;
}

From source file:org.bbaw.pdr.ae.repositoryconnection.commands.UpdateAllDataHandler.java

License:Open Source License

@Override
public final Object execute(final ExecutionEvent event) throws ExecutionException {

    if (!_urChecker.isUserGuest()) {

        ProgressMonitorDialog dialog = new ProgressMonitorDialog(
                PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell());
        dialog.setCancelable(true);/*from   ww w .  ja  va 2s  . c  o  m*/

        try {
            dialog.run(true, true, new IRunnableWithProgress() {
                private IStatus _updateStatus;

                @Override
                public void run(final IProgressMonitor monitor) {
                    // Activator.getDefault().getPreferenceStore().getString("REPOSITORY_URL"));
                    if (monitor.isCanceled()) {
                        monitor.setCanceled(true);
                    }
                    final User user = Facade.getInstanz().getCurrentUser();

                    IUpdateManager[] updateManagers = Facade.getInstanz().getUpdateManagers();
                    for (IUpdateManager manager : updateManagers) {
                        try {
                            if (user != null) {
                                _updateStatus = manager.updateAllData(user.getPdrId().toString(),
                                        user.getAuthentication().getPassword(), monitor);
                            }
                        } catch (final Exception e) {
                            e.printStackTrace();

                            UIJob job = new UIJob("Feedbackup") {
                                @Override
                                public IStatus runInUIThread(final IProgressMonitor monitor) {
                                    IWorkbench workbench = PlatformUI.getWorkbench();
                                    //Display display = workbench.getDisplay();
                                    //Shell shell = new Shell(display);
                                    Shell shell = HandlerUtil.getActiveWorkbenchWindow(event).getShell();
                                    String info = NLMessages.getString("Command_update_error") + "\n\n"
                                            + e.getMessage();
                                    MessageDialog infoDialog = new MessageDialog(shell,
                                            NLMessages.getString("Command_update_error"), null, info,
                                            MessageDialog.ERROR, new String[] { "OK" }, 0); //$NON-NLS-1$
                                    infoDialog.open();

                                    return Status.OK_STATUS;
                                }
                            };
                            job.setUser(true);
                            job.schedule();
                        }
                        //                     catch (final UnsupportedEncodingException e)
                        //                     {
                        //                        e.printStackTrace();
                        //
                        //                        UIJob job = new UIJob("Feedbackup")
                        //                        {
                        //                           @Override
                        //                           public IStatus runInUIThread(final IProgressMonitor monitor)
                        //                           {
                        //                              IWorkbench workbench = PlatformUI.getWorkbench();
                        //                              Display display = workbench.getDisplay();
                        //                              Shell shell = new Shell(display);
                        //                              String info = NLMessages.getString("Command_update_error") + "\n\n"
                        //                                    + e.getMessage();
                        //                              MessageDialog infoDialog = new MessageDialog(shell, NLMessages
                        //                                    .getString("Command_update_error"), null, info, MessageDialog.ERROR,
                        //                                    new String[]
                        //                                    {"OK"}, 0); //$NON-NLS-1$
                        //                              infoDialog.open();
                        //
                        //                              return Status.OK_STATUS;
                        //                           }
                        //                        };
                        //                        job.setUser(true);
                        //                        job.schedule();
                        //                     }
                        //                     catch (final Exception e)
                        //                     {
                        //                        e.printStackTrace();
                        //
                        //                        UIJob job = new UIJob("Feedbackup")
                        //                        {
                        //                           @Override
                        //                           public IStatus runInUIThread(final IProgressMonitor monitor)
                        //                           {
                        //                              IWorkbench workbench = PlatformUI.getWorkbench();
                        //                              Display display = workbench.getDisplay();
                        //                              Shell shell = new Shell(display);
                        //                              String info = NLMessages.getString("Command_update_error") + "\n\n"
                        //                                    + e.getMessage();
                        //                              MessageDialog infoDialog = new MessageDialog(shell, NLMessages
                        //                                    .getString("Command_update_error"), null, info, MessageDialog.ERROR,
                        //                                    new String[]
                        //                                    {"OK"}, 0); //$NON-NLS-1$
                        //                              infoDialog.open();
                        //                              return Status.OK_STATUS;
                        //                           }
                        //                        };
                        //                        job.setUser(true);
                        //                        job.schedule();
                        //                     }
                    } // for-loop

                    UIJob job = new UIJob("Feedbackup") {
                        @Override
                        public IStatus runInUIThread(final IProgressMonitor monitor) {
                            Facade.getInstanz().refreshAllData();

                            IWorkbench workbench = PlatformUI.getWorkbench();
                            Display display = workbench.getDisplay();
                            Shell shell = new Shell(display);
                            String info = null;
                            if (_updateStatus != null)
                                if (_updateStatus.isMultiStatus()) {

                                    info = NLMessages.getString("Command_update_error");
                                    for (IStatus status : _updateStatus.getChildren()) {
                                        info += "\n\n" + status.getMessage();
                                        Throwable e = status.getException();
                                        if (e != null) {
                                            info += "\n\n" + e.getMessage();
                                            for (StackTraceElement ste : e.getStackTrace())
                                                info += "\n" + ste;
                                        }
                                    }
                                    RepoUpdateStatusDialog statusDialog = new RepoUpdateStatusDialog(shell,
                                            _updateStatus,
                                            _updateStatus.getSeverity() < IStatus.WARNING
                                                    ? NLMessages.getString("Command_update_successful")
                                                    : NLMessages.getString("Command_update_error"));
                                    statusDialog.setTitle("Update Status Report");
                                    statusDialog.open();

                                } else {
                                    if (_updateStatus.equals(Status.OK_STATUS)) {
                                        info = NLMessages.getString("Command_update_successful");
                                    } else {
                                        if (_updateStatus.equals(Status.CANCEL_STATUS)) {
                                            info = NLMessages.getString("Command_update_error");
                                        } else {
                                            info = NLMessages.getString("Command_update_error_server");
                                            info += "\n\n" + ((Status) _updateStatus).getMessage();
                                            if (_updateStatus.getException() != null) {
                                                info += "\n";
                                                for (StackTraceElement ste : _updateStatus.getException()
                                                        .getStackTrace())
                                                    info += "\n" + ste;
                                            }
                                        }
                                    }
                                    MessageDialog infoDialog = new MessageDialog(shell, info, null, info,
                                            MessageDialog.INFORMATION, new String[] { "OK" }, 0); //$NON-NLS-1$
                                    infoDialog.open();
                                }
                            return Status.OK_STATUS;
                        }
                    };
                    job.setUser(true);
                    job.schedule();

                    monitor.done();
                }
            });
        } catch (final InvocationTargetException e) {
            e.printStackTrace();

            UIJob job = new UIJob("Feedbackup") {
                @Override
                public IStatus runInUIThread(final IProgressMonitor monitor) {
                    IWorkbench workbench = PlatformUI.getWorkbench();
                    Display display = workbench.getDisplay();
                    Shell shell = new Shell(display);
                    String info = NLMessages.getString("Command_update_error") + e.toString() + "\n\n"
                            + e.getMessage() + "\n\n" + e.getCause().toString() + "\n"
                            + e.getCause().getMessage();
                    MessageDialog infoDialog = new MessageDialog(shell,
                            NLMessages.getString("Command_update_error"), null, info, MessageDialog.ERROR,
                            new String[] { "OK" }, 0); //$NON-NLS-1$
                    infoDialog.open();
                    return Status.OK_STATUS;
                }
            };
            job.setUser(true);
            job.schedule();
        } catch (final InterruptedException e) {
            e.printStackTrace();

            UIJob job = new UIJob("Feedbackup") {
                @Override
                public IStatus runInUIThread(final IProgressMonitor monitor) {
                    IWorkbench workbench = PlatformUI.getWorkbench();
                    Display display = workbench.getDisplay();
                    Shell shell = new Shell(display);
                    String info = NLMessages.getString("Command_update_error") + e.toString() + "\n\n"
                            + e.getMessage();
                    MessageDialog infoDialog = new MessageDialog(shell,
                            NLMessages.getString("Command_update_error"), null, info, MessageDialog.ERROR,
                            new String[] { "OK" }, 0); //$NON-NLS-1$
                    infoDialog.open();
                    return Status.OK_STATUS;
                }
            };
            job.setUser(true);
            job.schedule();
        }
    } else {
        MessageDialog.openInformation(HandlerUtil.getActiveWorkbenchWindow(event).getShell(),
                NLMessages.getString("Commandsr_guest_user"), //$NON-NLS-1$
                NLMessages.getString("Commandsr_guest_user_denied"));
    }
    return null;
}