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:com.bdaum.zoom.core.internal.CoreActivator.java

License:Open Source License

public void deleteTrashCan() {
    if (dbManager.hasTrash()) {
        IRunnableWithProgress runnable = new IRunnableWithProgress() {
            public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
                List<Trash> set = dbManager.obtainTrashToDelete(true);
                monitor.beginTask(Messages.CoreActivator_Cleaning_up, set.size() + 1);
                for (Trash t : set) {
                    t.deleteFiles();//  ww  w.  java  2  s .co  m
                    monitor.worked(1);
                }
                dbManager.closeTrash();
                monitor.done();
            }
        };
        try {
            IWorkbenchWindow workbenchWindow = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
            if (workbenchWindow != null)
                new ProgressMonitorDialog(workbenchWindow.getShell()).run(false, true, runnable);
            else
                runnable.run(new NullProgressMonitor());
        } catch (InvocationTargetException e) {
            // ignore
        } catch (InterruptedException e) {
            // ignore
        }
    }
}

From source file:com.bdaum.zoom.core.internal.CoreActivator.java

License:Open Source License

private void convertDatabase(final Meta meta) {
    final IDbManager db = getDbManager();
    int catVersion = meta.getVersion();
    int supportedVersion = db.getVersion();
    if (catVersion > supportedVersion)
        Core.getCore().getDbFactory().getErrorHandler().fatalError(Messages.CoreActivator_unsupported_version,
                NLS.bind(Messages.CoreActivator_use_newer_version, Constants.APPLICATION_NAME,
                        db.getFileName()),
                (IAdaptable) db);//from   w  w  w.ja v  a 2  s .  co  m
    else if (catVersion < supportedVersion) {
        IRunnableWithProgress runnable = new IRunnableWithProgress() {
            public void run(IProgressMonitor monitor) {
                monitor.beginTask(Messages.CoreActivator_converting_cat, IProgressMonitor.UNKNOWN);
                monitor.subTask(Messages.CoreActivator_backing_up_cat);
                db.performBackup(0L, -1L, true);
                monitor.subTask(Messages.CoreActivator_converting_to_new_version);
                CatalogConverter.convert(db, monitor);
                logInfo(NLS.bind(Messages.CoreActivator_catalog_converted, db.getVersion()));
                monitor.done();
            }
        };
        IWorkbench workbench = PlatformUI.getWorkbench();
        Shell shell = workbench.getWorkbenchWindowCount() > 0 ? workbench.getWorkbenchWindows()[0].getShell()
                : null;
        if (shell != null) {
            shell.getDisplay().syncExec(() -> {
                try {
                    new ProgressMonitorDialog(shell).run(true, false, runnable);
                } catch (InvocationTargetException e1) {
                    logError(NLS.bind(Messages.CoreActivator_error_when_updating_to_version_n, db.getVersion()),
                            e1);
                } catch (InterruptedException e2) {
                    // should never happen
                }
            });
        } else
            try {
                runnable.run(new NullProgressMonitor());
            } catch (InvocationTargetException e) {
                logError(NLS.bind(Messages.CoreActivator_error_when_updating_to_version_n, db.getVersion()), e);
            } catch (InterruptedException e) {
                // should never happen
            }
    }
}

From source file:com.bdaum.zoom.db.internal.DbManager.java

License:Open Source License

public void checkDbSanity(final boolean force) {
    // MessageDialog.openInformation(null, "", systemInfo.freespaceSize()
    // + ", " + systemInfo.totalSize() + "; "
    // + systemInfo.freespaceEntryCount());
    if (!emergency)
        try {// www . j  ava 2  s  .co m
            if (force || needsDefragmentation()) {
                Meta meta1 = getMeta(false);
                boolean hasBackups = meta1 == null
                        || meta1.getBackupLocation() != null && !meta1.getBackupLocation().isEmpty();
                if (force || hasBackups
                        || factory.getErrorHandler().question(Messages.DbManager_Catalog_maintenance,
                                Messages.DbManager_The_cat_seems_to_be_fragmented, this)) {
                    SystemInfo systemInfo = getSystemInfo();
                    long totalSize = systemInfo.totalSize();
                    long freespaceSize = systemInfo.freespaceSize();
                    long occupiedspaceSize = totalSize - freespaceSize;
                    final long reserve = isReadOnly() ? occupiedspaceSize / 100 : occupiedspaceSize / 20;
                    final long defragSpaceSize = occupiedspaceSize + reserve;
                    long requiredSpace = defragSpaceSize + (force ? 0 : totalSize);
                    long availableSpace = file.getUsableSpace();
                    if (availableSpace < requiredSpace) {
                        factory.getErrorHandler().showError(Messages.DbManager_Catalog_maintenance, NLS.bind(
                                Messages.DbManager_not_enough_disc_space, requiredSpace, availableSpace), this);
                        return;
                    }
                    final String backupPath = fileName + ".defrag"; //$NON-NLS-1$
                    File backup = new File(backupPath);
                    ProgressMonitorDialog dialog = new ProgressMonitorDialog(null);
                    try {
                        dialog.run(true, false, new IRunnableWithProgress() {

                            public void run(IProgressMonitor monitor)
                                    throws InvocationTargetException, InterruptedException {
                                try {
                                    monitor.beginTask(NLS.bind(Messages.DbManager_Defragmenting_, fileName),
                                            IProgressMonitor.UNKNOWN);
                                    if (!force) {
                                        monitor.subTask(Messages.DbManager_backing_up_cat);
                                        performBackup(0L, -1L, true);
                                    }

                                    db.close();
                                    db = null;
                                    monitor.subTask(Messages.DbManager_defragmenting_cat);

                                    DefragmentConfig config = new DefragmentConfig(fileName, backupPath);
                                    boolean fileNeedsUpgrade = config.fileNeedsUpgrade();
                                    EmbeddedConfiguration ef = createDatabaseConfiguration(fileNeedsUpgrade,
                                            fileName, defragSpaceSize);
                                    try {
                                        defragment(fileName, backupPath, ef);
                                        ef = createDatabaseConfiguration(false, fileName, -1L);
                                        db = Db4oEmbedded.openFile(ef, fileName);
                                        SystemInfo systemInfo = getSystemInfo();
                                        long newFreespaceSize = systemInfo.freespaceSize();
                                        long newTotalSize = systemInfo.totalSize();
                                        db.close();
                                        db = null;
                                        if (newFreespaceSize > 3 * reserve) {
                                            monitor.subTask(Messages.DbManager_defrag_cat_2);
                                            long newOccupiedspaceSize = newTotalSize - newFreespaceSize;
                                            long newReserve = isReadOnly() ? newOccupiedspaceSize / 100
                                                    : newOccupiedspaceSize / 20;
                                            long newDefragSpaceSize = newOccupiedspaceSize + newReserve;
                                            ef = createDatabaseConfiguration(fileNeedsUpgrade, fileName,
                                                    newDefragSpaceSize);
                                            defragment(fileName, backupPath, ef);
                                        }
                                    } catch (Exception e) {
                                        File target = new File(fileName);
                                        target.delete();
                                        new File(backupPath).renameTo(target);
                                        throw new InvocationTargetException(e);
                                    }
                                    if (fileNeedsUpgrade) {
                                        monitor.subTask(Messages.DbManager_updating_database_version);
                                        db = Db4oEmbedded.openFile(ef, fileName);
                                        db.close();
                                        db = null;
                                        DbActivator.getDefault()
                                                .logInfo(NLS.bind(
                                                        Messages.DbManager_database_converted_to_version_n,
                                                        Db4o.version()));
                                    }
                                } finally {
                                    if (db == null)
                                        db = createDatabase(fileName, false);
                                }
                            }
                        });
                    } catch (InvocationTargetException e1) {
                        factory.getErrorHandler().showError(Messages.DbManager_Defrag_error,
                                NLS.bind(Messages.DbManager_Defrag_failed, e1.getCause()), this);
                        DbActivator.getDefault().logError(Messages.DbManager_Defrag_error, e1);
                        return;
                    } catch (InterruptedException e1) {
                        // should never happen
                    } finally {
                        if (!file.exists()) {
                            if (backup.exists())
                                backup.renameTo(file);
                            DbActivator.getDefault().logError(Messages.DbManager_defragmentation_failed, null);
                            return;
                        }
                    }
                    backup.delete();
                    DbActivator.getDefault().logInfo(Messages.DbManager_defragmentation_successfiul);
                }
            }
        } catch (Throwable e) {
            DbActivator.getDefault().logError(Messages.DbManager_error_checking_sanity, e);
        }
}

From source file:com.bdaum.zoom.db.internal.DbManager.java

License:Open Source License

public void pruneEmptySystemCollections() {
    if (!readOnly && hasDirtyCollection()) {
        IRunnableWithProgress runnable = new IRunnableWithProgress() {
            public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
                pruneEmptySystemCollections(monitor, false);
            }/*  ww w  . j a va2 s . c o m*/
        };
        try {
            IWorkbenchWindow workbenchWindow = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
            if (workbenchWindow != null) {
                ProgressMonitorDialog dialog = new ProgressMonitorDialog(workbenchWindow.getShell());
                dialog.create();
                dialog.getShell().setText(Constants.APPLICATION_NAME);
                dialog.run(false, true, runnable);
            } else
                runnable.run(new NullProgressMonitor());
        } catch (InvocationTargetException e) {
            // ignore
        } catch (InterruptedException e) {
            // ignore
        }
    }
}

From source file:com.beck.ep.team.internal.TeamListBuilder.java

License:BSD License

public String[] createList(Shell shell, IProject project) throws Exception {
    error = null;/* ww w  .  j  a v  a  2  s .c om*/
    RepositoryProvider provider = RepositoryProvider.getProvider(project);
    if (provider == null) {
        error = "No Repository provider exist. Project: " + project.getName();
        return null;
    }
    IListBuilder lb = newListBuilder(provider.getID());
    if (lb != null) {
        String[] sa = lb.createList(shell, project);
        error = lb.getError();
        return sa;
    }

    Subscriber subscriber = provider.getSubscriber();

    SyncInfoSet set = new SyncInfoSet();
    //set.add(SyncInfo.CONFLICTING);

    Filter filter = new Filter();
    ProgressMonitorDialog monitor = new ProgressMonitorDialog(shell);
    monitor.setCancelable(true);
    monitor.open();
    IResource[] members = project.members();
    subscriber.collectOutOfSync(members, IResource.DEPTH_INFINITE, set, monitor.getProgressMonitor());
    monitor.close();

    SyncInfo[] infos = set.getNodes(filter);
    String[] sa = new String[infos.length];
    for (int i = 0; i < infos.length; i++) {
        sa[i] = infos[i].getLocal().getProjectRelativePath().toString();
    }
    return sa;
}

From source file:com.binge.workforce.app.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  ww w. j  av a 2 s  . c  om
    dialog.run(true, true, new IRunnableWithProgress() {
        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:com.bluexml.side.application.presentation.ApplicationEditor.java

License:Open Source License

/**
 * This is for implementing {@link IEditorPart} and simply saves the model file.
 * <!-- begin-user-doc -->/*from ww w .  j  a  va  2 s .c o  m*/
 * <!-- end-user-doc -->
 * @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.
        //
        ApplicationEditorPlugin.INSTANCE.log(exception);
    }
    updateProblemIndication = true;
    updateProblemIndication();
}

From source file:com.bluexml.side.clazz.presentation.ClazzEditor.java

License:Open Source License

/**
 * This is for implementing {@link IEditorPart} and simply saves the model file.
 * <!-- begin-user-doc -->//  w  w w .  j  a v a 2  s .c o  m
 * <!-- end-user-doc -->
 * @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.
        //
        ClassEditorPlugin.INSTANCE.log(exception);
    }
    updateProblemIndication = true;
    updateProblemIndication();
}

From source file:com.bluexml.side.form.presentation.FormEditor.java

License:Open Source License

/**
 * This is for implementing {@link IEditorPart} and simply saves the model file. <!--
 * begin-user-doc --> <!-- end-user-doc -->
 * /*www  . j  av  a 2  s  . co  m*/
 * @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.
        //
        FormsEditorPlugin.INSTANCE.log(exception);
    }
    updateProblemIndication = true;
    updateProblemIndication();
}

From source file:com.bluexml.side.portal.presentation.PortalEditor.java

License:Open Source License

/**
 * This is for implementing {@link IEditorPart} and simply saves the model file.
 * <!-- begin-user-doc -->/*from ww  w. j  ava 2s  .c o  m*/
 * <!-- end-user-doc -->
 * @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.
        //
        PortalEditorPlugin.INSTANCE.log(exception);
    }
    updateProblemIndication = true;
    updateProblemIndication();
}