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.android.uiautomator.actions.ScreenshotAction.java

License:Apache License

@Override
public void run() {
    if (!DebugBridge.isInitialized()) {
        MessageDialog.openError(mViewer.getShell(), "Error obtaining Device Screenshot",
                "Unable to connect to adb. Check if adb is installed correctly.");
        return;//  w  w  w .j  av a  2s.  c o m
    }

    final IDevice device = pickDevice();
    if (device == null) {
        return;
    }

    ProgressMonitorDialog dialog = new ProgressMonitorDialog(mViewer.getShell());
    try {
        dialog.run(true, false, new IRunnableWithProgress() {
            @Override
            public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
                UiAutomatorResult result = null;
                try {
                    result = UiAutomatorHelper.takeSnapshot(device, monitor, mCompressed);
                } catch (UiAutomatorException e) {
                    monitor.done();
                    showError(e.getMessage(), e);
                    return;
                }

                mViewer.setModel(result.model, result.uiHierarchy, result.screenshot);
                monitor.done();
            }
        });
    } catch (Exception e) {
        showError("Unexpected error while obtaining UI hierarchy", e);
    }
}

From source file:com.aptana.editor.js.preferences.NodePreferencePage.java

License:Open Source License

private void downloadNodeJS() {
    final ProgressMonitorDialog downloadProgressMonitor = new ProgressMonitorDialog(UIUtils.getActiveShell());
    try {/*from w w  w  .  j  a  va 2  s  .c  om*/
        downloadProgressMonitor.run(true, true, new IRunnableWithProgress() {

            public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
                try {
                    final INodeJS node = getDetectedPath();
                    IStatus status = node.downloadSource(monitor);
                    if (status.isOK()) {
                        // Set the path in the editor field
                        Control control = NodePreferencePage.this.getControl();
                        if (control != null && !control.isDisposed()) {
                            UIUtils.runInUIThread(new Runnable() {

                                public void run() {
                                    sourceEditor.setStringValue(node.getSourcePath().toOSString());
                                }
                            });
                        }

                    }
                } catch (Exception e) {
                    IdeLog.logError(JSPlugin.getDefault(), "Error while downloading NodeJS sources", e); //$NON-NLS-1$
                }

            }
        });
    } catch (Exception e) {
        IdeLog.logError(JSPlugin.getDefault(), e);
    }
    // setStringValue(value)
}

From source file:com.aptana.ide.ui.io.properties.FileInfoPropertyPage.java

License:Open Source License

@Override
protected Control createContents(Composite parent) {
    // first try to adapt to IFileStore directly
    final IFileStore fileStore = Utils.getFileStore(getElement());
    if (fileStore == null) {
        Label label = new Label(parent, SWT.NONE);
        label.setText(IDEWorkbenchMessages.ResourceInfoPage_noResource);
        return label;
    }/*w  ww . j  ava2  s .  c o  m*/
    try {
        if (getElement().getAdapter(File.class) != null) {
            fFileInfo = fileStore.fetchInfo(EFS.NONE, new NullProgressMonitor());
        } else {
            final IFileInfo[] result = new IFileInfo[1];
            ProgressMonitorDialog dlg = new ProgressMonitorDialog(parent.getShell());
            try {
                dlg.run(true, true, new IRunnableWithProgress() {
                    public void run(IProgressMonitor monitor)
                            throws InvocationTargetException, InterruptedException {
                        try {
                            result[0] = fileStore.fetchInfo(IExtendedFileStore.DETAILED, monitor);
                        } catch (CoreException e) {
                            throw new InvocationTargetException(e, e.getLocalizedMessage());
                        } finally {
                            monitor.done();
                        }
                    }
                });
            } catch (InvocationTargetException e) {
                throw (CoreException) e.getTargetException();
            } catch (InterruptedException e) {
                e.getCause();
            }
            fFileInfo = result[0];
        }
    } catch (CoreException e) {
        UIUtils.showErrorMessage(Messages.FileInfoPropertyPage_FailedToFetchInfo, e);
    }
    if (fFileInfo == null) {
        Label label = new Label(parent, SWT.NONE);
        label.setText(IDEWorkbenchMessages.ResourceInfoPage_noResource);
        return label;
    }

    Composite composite = new Composite(parent, SWT.NONE);
    composite.setLayout(GridLayoutFactory.swtDefaults().margins(0, 0).create());
    composite.setLayoutData(GridDataFactory.fillDefaults().grab(true, false).create());

    Composite basicInfo = createBasicInfoGroup(composite, fileStore, fFileInfo);
    basicInfo.setLayoutData(GridDataFactory.fillDefaults().create());

    Label separator = new Label(composite, SWT.SEPARATOR | SWT.HORIZONTAL);
    separator.setLayoutData(GridDataFactory.fillDefaults().grab(true, false).create());

    Composite state = createStateGroup(composite, fileStore, fFileInfo);
    state.setLayoutData(GridDataFactory.fillDefaults().create());

    if (fFileInfo instanceof IExtendedFileInfo) {
        IExtendedFileInfo extendedInfo = (IExtendedFileInfo) fFileInfo;
        Composite owner = createOwnerGroup(composite, extendedInfo);
        owner.setLayoutData(GridDataFactory.fillDefaults().grab(true, false).indent(0, 10).create());

        Composite permissions = createPermissionsGroup(composite, extendedInfo);
        permissions.setLayoutData(GridDataFactory.fillDefaults().grab(true, false).indent(0, 5).create());

    }

    /*
     * TODO new Label(composite, SWT.NONE); // a vertical spacer encodingEditor = new EncodingFieldEditor("",
     * fileInfo.isDirectory() ? IDEWorkbenchMessages.ResourceInfo_fileEncodingTitle :
     * IDEWorkbenchMessages.WorkbenchPreference_encoding, composite); encodingEditor.setPreferenceStore(null);
     * encodingEditor.setPage(this); encodingEditor.load(); encodingEditor.setPropertyChangeListener(new
     * IPropertyChangeListener() { public void propertyChange(PropertyChangeEvent event) { if
     * (event.getProperty().equals(FieldEditor.IS_VALID)) { setValid(encodingEditor.isValid()); } } }); if
     * (fileInfo.isDirectory()) { lineDelimiterEditor = new LineDelimiterEditor(composite, resource.getProject());
     * lineDelimiterEditor.doLoad(); }
     */

    Dialog.applyDialogFont(composite);

    return composite;
}

From source file:com.aptana.ide.update.eclipse36.P2Eclipse36PluginManager.java

License:Open Source License

private static IInstallableUnit[] getInstallationUnits(final IPlugin[] plugins, final String profileId)
        throws PluginManagerException {
    final List<IInstallableUnit> units = new ArrayList<IInstallableUnit>();

    IRunnableWithProgress runnable = new IRunnableWithProgress() {

        public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
            SubMonitor sub = SubMonitor.convert(monitor, plugins.length * 4);
            sub.setTaskName(P2Eclipse36Messages.P2PluginManager_Locating_selected_features_job_title);
            try {
                for (IPlugin plugin : plugins) {
                    URI siteURL = plugin.getURL().toURI();

                    IMetadataRepositoryManager manager = getMetadataRepositoryManager();
                    IMetadataRepository repo = manager.loadRepository(siteURL, sub.newChild(1));
                    if (repo == null) {
                        throw new ProvisionException(
                                P2Eclipse36Messages.P2PluginManager_ERR_MSG_Metadata_repo_not_found + siteURL);
                    }//from   w ww.jav a  2  s .  c  o m
                    if (!manager.isEnabled(siteURL)) {
                        manager.setEnabled(siteURL, true);
                    }

                    IArtifactRepositoryManager artifactManager = getArtifactRepositoryManager();
                    IArtifactRepository artifactRepo = artifactManager.loadRepository(siteURL, sub.newChild(1));
                    if (artifactRepo == null) {
                        throw new ProvisionException(
                                P2Eclipse36Messages.P2PluginManager_ERR_MSG_Artifact_repo_not_found + siteURL);
                    }
                    if (!artifactManager.isEnabled(siteURL)) {
                        artifactManager.setEnabled(siteURL, true);
                    }

                    IQuery<IInstallableUnit> query = QueryUtil.createIUQuery(getFeatureGroupName(plugin));
                    query = QueryUtil.createLatestQuery(query);
                    IQueryResult<IInstallableUnit> roots = repo.query(query, sub.newChild(2));

                    if (roots.isEmpty()) {
                        if (monitor.isCanceled()) {
                            return;
                        }

                        IProfile profile = getProfile(profileId);
                        if (profile == null) {
                            profile = getFirstProfile();
                        }
                        roots = profile.query(query, sub.newChild(2));
                    }
                    units.addAll(roots.toUnmodifiableSet());
                }
            } catch (Exception e) {
                throw new InvocationTargetException(e);
            } finally {
                sub.done();
            }
        }
    };
    try {
        new ProgressMonitorDialog(Display.getDefault().getActiveShell()).run(true, true, runnable);
    } catch (InterruptedException e) {
        // don't report thread interruption
    } catch (InvocationTargetException e) {
        throw new PluginManagerException(P2Eclipse36Messages.ProfileModificationAction_UnexpectedError,
                e.getCause());
    }
    return units.toArray(new IInstallableUnit[units.size()]);
}

From source file:com.aptana.ide.update.internal.manager.P2Eclipse35PluginManager.java

License:Open Source License

private static IInstallableUnit[] getInstallationUnits(final IPlugin[] plugins, final String profileId)
        throws PluginManagerException {
    final List<IInstallableUnit> units = new ArrayList<IInstallableUnit>();

    IRunnableWithProgress runnable = new IRunnableWithProgress() {

        public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
            SubMonitor sub = SubMonitor.convert(monitor, plugins.length * 4);
            sub.setTaskName(P2Eclipse35Messages.P2PluginManager_Locating_selected_features_job_title);
            try {
                for (IPlugin plugin : plugins) {
                    URI siteURL = plugin.getURL().toURI();

                    IMetadataRepositoryManager manager = (IMetadataRepositoryManager) ServiceHelper.getService(
                            P2Eclipse35Activator.getContext(), IMetadataRepositoryManager.class.getName());
                    IMetadataRepository repo = manager.loadRepository(siteURL, new NullProgressMonitor());
                    if (repo == null) {
                        throw new ProvisionException(
                                P2Eclipse35Messages.P2PluginManager_ERR_MSG_Metadata_repo_not_found + siteURL);
                    }//  w  w  w  .j a v a 2 s. c  o m
                    if (!manager.isEnabled(siteURL)) {
                        manager.setEnabled(siteURL, true);
                    }
                    sub.worked(1);

                    IArtifactRepositoryManager artifactManager = (IArtifactRepositoryManager) ServiceHelper
                            .getService(P2Eclipse35Activator.getContext(),
                                    IArtifactRepositoryManager.class.getName());
                    IArtifactRepository artifactRepo = artifactManager.loadRepository(siteURL,
                            new NullProgressMonitor());
                    if (artifactRepo == null) {
                        throw new ProvisionException(
                                P2Eclipse35Messages.P2PluginManager_ERR_MSG_Artifact_repo_not_found + siteURL);
                    }
                    if (!artifactManager.isEnabled(siteURL)) {
                        artifactManager.setEnabled(siteURL, true);
                    }
                    sub.worked(1);

                    InstallableUnitQuery query = new InstallableUnitQuery(getFeatureGroupName(plugin),
                            VersionRange.emptyRange);
                    Collector roots = repo.query(query, new LatestIUVersionCollector(), monitor);

                    if (roots.size() <= 0) {
                        if (monitor.isCanceled()) {
                            return;
                        }

                        IProfile profile = ProvisioningUtil.getProfile(profileId);
                        roots = profile.query(query, roots, monitor);
                    }
                    units.addAll(roots.toCollection());
                    sub.worked(2);
                }
            } catch (Exception e) {
                throw new InvocationTargetException(e);
            } finally {
                sub.done();
            }
        }
    };
    try {
        new ProgressMonitorDialog(Display.getDefault().getActiveShell()).run(true, true, runnable);
    } catch (InterruptedException e) {
        // don't report thread interruption
    } catch (InvocationTargetException e) {
        throw new PluginManagerException(P2Eclipse35Messages.ProfileModificationAction_UnexpectedError,
                e.getCause());
    }
    return units.toArray(new IInstallableUnit[units.size()]);
}

From source file:com.aptana.ide.update.internal.manager.P2PluginManager.java

private static IInstallableUnit[] getInstallationUnits(final IPlugin[] plugins, final String profileId)
        throws PluginManagerException {
    final List<IInstallableUnit> units = new ArrayList<IInstallableUnit>();
    IRunnableWithProgress runnable = new IRunnableWithProgress() {
        public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException

        {//from  w  w w . ja v  a  2 s  .c o m
            SubMonitor sub = SubMonitor.convert(monitor, plugins.length * 4);
            sub.setTaskName(Messages.P2PluginManager_Locating_selected_features_job_title);
            try {
                for (int i = 0; i < plugins.length; i++) {
                    IPlugin plugin = plugins[i];
                    IMetadataRepositoryManager manager = (IMetadataRepositoryManager) ServiceHelper
                            .getService(P2Activator.getContext(), IMetadataRepositoryManager.class.getName());
                    IMetadataRepository repo = manager.loadRepository(plugin.getURL(),
                            new NullProgressMonitor());
                    if (repo == null) {
                        throw new ProvisionException(
                                Messages.P2PluginManager_ERR_MSG_Metadata_repo_not_found + plugin.getURL());
                    }
                    if (!manager.isEnabled(plugin.getURL()))
                        manager.setEnabled(plugin.getURL(), true);
                    sub.worked(1);

                    IArtifactRepositoryManager artifactManager = (IArtifactRepositoryManager) ServiceHelper
                            .getService(P2Activator.getContext(), IArtifactRepositoryManager.class.getName());
                    IArtifactRepository artifactRepo = artifactManager.loadRepository(plugin.getURL(),
                            new NullProgressMonitor());
                    if (artifactRepo == null) {
                        throw new ProvisionException(
                                Messages.P2PluginManager_ERR_MSG_Artifact_repo_not_found + plugin.getURL());
                    }
                    if (!artifactManager.isEnabled(plugin.getURL()))
                        artifactManager.setEnabled(plugin.getURL(), true);
                    sub.worked(1);

                    InstallableUnitQuery query = new InstallableUnitQuery(getFeatureGroupName(plugin),
                            VersionRange.emptyRange);
                    Collector roots = repo.query(query, new LatestIUVersionCollector(), monitor);

                    if (roots.size() <= 0) {
                        if (monitor.isCanceled())
                            return;

                        IProfile profile = ProvisioningHelper.getProfile(profileId);
                        roots = profile.query(query, roots, monitor);
                    }
                    units.addAll(roots.toCollection());
                    sub.worked(2);
                }
            } catch (Exception e) {
                throw new InvocationTargetException(e);
            } finally {
                sub.done();
            }
        }
    };
    try {
        new ProgressMonitorDialog(Display.getDefault().getActiveShell()).run(true, true, runnable);
    } catch (InterruptedException e) {
        // don't report thread interruption
    } catch (InvocationTargetException e) {
        throw new PluginManagerException(Messages.ProfileModificationAction_UnexpectedError, e.getCause());
    }
    return units.toArray(new IInstallableUnit[units.size()]);
}

From source file:com.aptana.ide.update.internal.manager.P2PluginManager.java

private static ProvisioningPlan getInstallationProvisioningPlan(final IInstallableUnit[] ius,
        final String profileId) {
    final ProvisioningPlan[] plan = new ProvisioningPlan[1];
    IRunnableWithProgress runnable = new IRunnableWithProgress() {
        public void run(IProgressMonitor monitor) {
            try {
                plan[0] = InstallAction.computeProvisioningPlan(ius, profileId, monitor);
            } catch (ProvisionException e) {
                ProvUI.handleException(e, Messages.ProfileModificationAction_UnexpectedError,
                        StatusManager.BLOCK | StatusManager.LOG);
            }/*  w w w.jav  a 2s .c o  m*/
        }
    };
    try {
        new ProgressMonitorDialog(Display.getDefault().getActiveShell()).run(true, true, runnable);
    } catch (InterruptedException e) {
        // don't report thread interruption
    } catch (InvocationTargetException e) {
        ProvUI.handleException(e.getCause(), Messages.ProfileModificationAction_UnexpectedError,
                StatusManager.BLOCK | StatusManager.LOG);
    }
    return plan[0];
}

From source file:com.aptana.ide.update.internal.manager.P2PluginManager.java

private static ProvisioningPlan getUninstallationProvisioningPlan(final IInstallableUnit[] ius,
        final String profileId) {
    final ProvisioningPlan[] plan = new ProvisioningPlan[1];
    IRunnableWithProgress runnable = new IRunnableWithProgress() {
        public void run(IProgressMonitor monitor) {
            try {
                ProfileChangeRequest request = ProfileChangeRequest.createByProfileId(profileId);
                request.removeInstallableUnits(ius);
                plan[0] = ProvisioningUtil.getProvisioningPlan(request, new ProvisioningContext(), monitor);
            } catch (ProvisionException e) {
                ProvUI.handleException(e, Messages.ProfileModificationAction_UnexpectedError,
                        StatusManager.BLOCK | StatusManager.LOG);
            }//  w ww.  j  av  a2  s . com
        }
    };
    try {
        new ProgressMonitorDialog(Display.getDefault().getActiveShell()).run(true, true, runnable);
    } catch (InterruptedException e) {
        // don't report thread interruption
    } catch (InvocationTargetException e) {
        ProvUI.handleException(e.getCause(), Messages.ProfileModificationAction_UnexpectedError,
                StatusManager.BLOCK | StatusManager.LOG);
    }
    return plan[0];
}

From source file:com.aptana.php.debug.ui.phpini.PHPIniValidator.java

License:Open Source License

/**
 * Validate the php.ini directives.//from   w  w w.j a v a  2 s  .  c o  m
 */
public void validate() {
    synchronized (lock) {
        if (isRunning) {
            return;
        }
        isRunning = true;
    }
    List<PHPIniEntry> extensions = new ArrayList<PHPIniEntry>();
    extensions.addAll(mappedEntries.values());
    // Mark all entries as unknown.
    for (PHPIniEntry entry : extensions) {
        entry.setValidationState(VALIDATION.UNKNOWN, null);
    }
    Shell activeShell = PHPDebugPlugin.getDefault().getWorkbench().getActiveWorkbenchWindow().getShell();
    try {
        IRunnableWithProgress op = new ExtensionsValidatorRunnable(extensions);
        ProgressMonitorDialog progressMonitorDialog = new ProgressMonitorDialog(activeShell);
        progressMonitorDialog.run(true, true, op);
    } catch (InvocationTargetException e) {
        // handle exception
        IdeLog.logError(PHPDebugPlugin.getDefault(), "Error while validating the PHP extensions", e, //$NON-NLS-1$
                IDebugScopes.DEBUG);
    } catch (InterruptedException e) // $codepro.audit.disable emptyCatchClause
    {
        // handle cancellation in the finally block

    } finally {
        // Revert the changes made to the ini
        for (PHPIniEntry entry : faultingExtensions) {
            provider.uncommentEntry(entry);
        }
        faultingExtensions.clear();
        // Mark all the unknown entries as resolved.
        for (PHPIniEntry entry : mappedEntries.values()) {
            if (validationCanceled) {
                entry.setValidationState(VALIDATION.UNKNOWN, null);
            } else if (entry.getValidationState() == VALIDATION.UNKNOWN) {
                entry.setValidationState(VALIDATION.OK, null);
            }
        }
        try {
            provider.save();
        } catch (IOException e) {
            IdeLog.logError(PHPDebugPlugin.getDefault(), "Error while saving the php.ini configuration.", e); //$NON-NLS-1$
        }
        synchronized (lock) {
            isRunning = false;
        }
    }
}

From source file:com.aptana.portal.ui.eclipse36.dispatch.configurationProcessors.PluginsConfigurationProcessor.java

License:Open Source License

private Collection<IInstallableUnit> getInstallationUnits(final String updateSite, final String featureID,
        final String profileId, final ProvisioningUI provisioningUI) throws InvocationTargetException {
    final List<IInstallableUnit> units = new ArrayList<IInstallableUnit>();

    IRunnableWithProgress runnable = new IRunnableWithProgress() {
        public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
            SubMonitor sub = SubMonitor.convert(monitor, 1);
            sub.setTaskName(Messages.PluginsConfigurationProcessor_locatingFeatures);
            try {
                URI siteURL = new URI(updateSite);
                IMetadataRepository repo = provisioningUI.loadMetadataRepository(siteURL, true,
                        new NullProgressMonitor());
                if (repo == null) {
                    throw new ProvisionException(
                            Messages.PluginsConfigurationProcessor_metadataRepoNotFound + siteURL);
                }/*  ww w  .j  a v a 2s . c  o m*/
                sub.worked(1);
                IArtifactRepositoryManager artifactManager = (IArtifactRepositoryManager) provisioningUI
                        .getSession().getProvisioningAgent()
                        .getService(IArtifactRepositoryManager.SERVICE_NAME);
                IArtifactRepository artifactRepo = artifactManager.loadRepository(siteURL,
                        new NullProgressMonitor());
                if (artifactRepo == null) {
                    throw new ProvisionException(
                            Messages.PluginsConfigurationProcessor_artifactRepoNotFound + siteURL);
                }
                if (!artifactManager.isEnabled(siteURL)) {
                    artifactManager.setEnabled(siteURL, true);
                }
                sub.worked(1);

                IQuery<IInstallableUnit> query;
                if (featureID == null) {
                    query = QueryUtil.createIUQuery(null, VersionRange.emptyRange);
                } else {
                    query = QueryUtil.createIUQuery(featureID + FEATURE_IU_SUFFIX, VersionRange.emptyRange);
                }
                IQueryResult<IInstallableUnit> roots = repo.query(query, monitor);

                if (roots.isEmpty()) {
                    if (monitor.isCanceled()) {
                        return;
                    }

                    IProfile profile = ProvUI.getProfileRegistry(provisioningUI.getSession())
                            .getProfile(profileId);
                    if (profile != null) {
                        roots = profile.query(query, monitor);
                    } else {
                        // Log this
                        IdeLog.logError(PortalUI36Plugin.getDefault(),
                                MessageFormat.format(
                                        "Error while retrieving the profile for ''{0}'' update site", //$NON-NLS-1$
                                        updateSite),
                                new RuntimeException(MessageFormat.format("The profile for ''{0}'' was null", //$NON-NLS-1$
                                        profileId)));
                    }
                }
                units.addAll(roots.toSet());
                sub.worked(2);
            } catch (Exception e) {
                throw new InvocationTargetException(e);
            } finally {
                sub.done();
            }
        }
    };
    try {
        new ProgressMonitorDialog(Display.getDefault().getActiveShell()).run(true, true, runnable);
    } catch (InterruptedException e) {
        // don't report thread interruption
    }
    return units;
}