Search in sources :

Example 81 with MultiStatus

use of org.eclipse.core.runtime.MultiStatus in project eclipse-integration-commons by spring-projects.

the class DashboardExtensionsPage method createFormContent.

@Override
protected void createFormContent(final IManagedForm managedForm) {
    Composite body = managedForm.getForm().getBody();
    body.setLayout(new GridLayout(5, false));
    discoveryViewer = new DashboardDiscoveryViewer(getSite(), this);
    initialize(discoveryViewer);
    discoveryViewer.setDirectoryUrl(ResourceProvider.getUrl(RESOURCE_DISCOVERY_DIRECTORY).replace("%VERSION%", IdeUiUtils.getShortVersion()));
    discoveryViewer.setShowConnectorDescriptorKindFilter(false);
    discoveryViewer.createControl(body);
    FormToolkit toolkit = managedForm.getToolkit();
    adaptRecursively(discoveryViewer.getControl(), toolkit);
    GridDataFactory.fillDefaults().span(5, 1).grab(true, true).applyTo(discoveryViewer.getControl());
    findUpdatesButton = toolkit.createButton(body, "&Find Updates", SWT.NONE);
    findUpdatesButton.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent event) {
            IHandlerService handlerService = (IHandlerService) getSite().getService(IHandlerService.class);
            try {
                handlerService.executeCommand("org.eclipse.equinox.p2.ui.sdk.update", new Event());
            } catch (Exception e) {
                StatusManager.getManager().handle(new Status(IStatus.ERROR, IdeUiPlugin.PLUGIN_ID, "Find updates failed with an unexpected error.", e), StatusManager.SHOW | StatusManager.LOG);
            }
        }
    });
    Hyperlink configureLink = toolkit.createHyperlink(body, "Configure Extensions...", SWT.NONE);
    configureLink.addHyperlinkListener(new HyperlinkAdapter() {

        @Override
        public void linkActivated(HyperlinkEvent event) {
            PreferenceDialog dialog = PreferencesUtil.createPreferenceDialogOn(getSite().getShell(), ID_PREFERENCE_PAGE, new String[] { ID_PREFERENCE_PAGE }, null);
            dialog.open();
        }
    });
    progressMonitorPart = new ProgressMonitorPart(body, null);
    monitor.attach(progressMonitorPart);
    progressMonitorPart.addDisposeListener(new DisposeListener() {

        public void widgetDisposed(DisposeEvent e) {
            monitor.setCanceled(true);
            monitor.detach(progressMonitorPart);
        }
    });
    adaptRecursively(progressMonitorPart, toolkit);
    GridDataFactory.fillDefaults().grab(true, false).applyTo(progressMonitorPart);
    // Button refreshButton = toolkit.createButton(body, "Refresh",
    // SWT.NONE);
    // refreshButton.addSelectionListener(new SelectionAdapter() {
    // @Override
    // public void widgetSelected(SelectionEvent e) {
    // pane.updateDiscovery();
    // }
    // });
    cancelButton = toolkit.createButton(body, "&Cancel", SWT.NONE);
    cancelButton.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            cancelButton.setEnabled(false);
            progressMonitorPart.setCanceled(true);
        }
    });
    installButton = toolkit.createButton(body, "&Install", SWT.NONE);
    installButton.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            // check for conflicts
            List<ConnectorDescriptor> selection = discoveryViewer.getInstallableConnectors();
            IStatus conflictStatus = new MultiStatus(IdeUiPlugin.PLUGIN_ID, -1, new IStatus[] { checkForConflicts(SVN_FEATURES, " Please select only one SVN team provider.", selection), checkForConflicts(M2E_EXTENSION_IDS, " Please select only one m2e version to install.", selection) }, "Could not perform install due to conflicts.", null);
            if (!conflictStatus.isOK()) {
                StatusManager.getManager().handle(conflictStatus, StatusManager.SHOW | StatusManager.BLOCK);
                return;
            }
            // now, if m2e is going to be installed, ensure that all other
            // versions of m2e are uninstalled first.
            Set<String> featuresToUninstall = chooseUnwantedFeatures(selection);
            if (!featuresToUninstall.isEmpty()) {
                IStatus uninstallResult = uninstallFeatures(featuresToUninstall);
                if (!uninstallResult.isOK()) {
                    if (uninstallResult.getSeverity() != IStatus.CANCEL) {
                        StatusManager.getManager().handle(uninstallResult, StatusManager.SHOW | StatusManager.LOG | StatusManager.BLOCK);
                    }
                    return;
                }
            }
            DiscoveryUi.install(discoveryViewer.getInstallableConnectors(), DashboardExtensionsPage.this);
        }

        private IStatus uninstallFeatures(final Set<String> featuresToUninstall) {
            String allInstalled = findFeaturesToUninstall(featuresToUninstall, discoveryViewer.getInstalledFeatures());
            if (allInstalled.length() == 0) {
                return Status.OK_STATUS;
            }
            boolean res = MessageDialog.openQuestion(getPartControl().getShell(), "Perform uninstall?", "In order to switch versions of m2eclipse, the following features will be uninstalled:\n" + allInstalled + "Do you want to continue?");
            if (!res) {
                return Status.CANCEL_STATUS;
            }
            // uninstall previous Maven tooling
            AbstractInstallJob job = DiscoveryUi.createInstallJob();
            try {
                return job.uninstall(new UninstallRequest() {

                    /**
                     * Uninstall all features that are somehow related to
                     * m2eclipse
                     */
                    @Override
                    public boolean select(InstalledItem item) {
                        String featureId = item.getId();
                        return isRelatedToM2e(featuresToUninstall, featureId);
                    }
                }, new NullProgressMonitor());
            } catch (Exception e) {
                return new Status(IStatus.ERROR, IdeUiPlugin.PLUGIN_ID, NLS.bind("Could not uninstall features:\n{0},\n try uninstalling manually.", featuresToUninstall), e);
            }
        }

        private String findFeaturesToUninstall(Set<String> featuresToUninstall, Set<String> installedFeatures) {
            StringBuilder sb = new StringBuilder();
            for (String featureId : installedFeatures) {
                if (isRelatedToM2e(featuresToUninstall, featureId)) {
                    if (featureId.endsWith(".feature.group")) {
                        featureId = featureId.substring(0, featureId.length() - ".feature.group".length());
                    }
                    sb.append("   " + featureId + "\n");
                }
            }
            return sb.toString();
        }

        private Set<String> chooseUnwantedFeatures(List<ConnectorDescriptor> selection) {
            boolean uninstallOld = false;
            boolean uninstallNew = false;
            for (ConnectorDescriptor feature : selection) {
                // first and vice versa
                if (feature.getId().equals(NEW_M2E_EXTENSION_ID)) {
                    uninstallOld = true;
                } else if (feature.getId().equals(OLD_M2E_EXTENSION_ID)) {
                    uninstallNew = true;
                }
            }
            Set<String> maybeUninstall;
            if (uninstallOld) {
                maybeUninstall = OLD_M2E_FEATURES;
            } else if (uninstallNew) {
                maybeUninstall = NEW_M2E_FEATURES;
            } else {
                maybeUninstall = Collections.emptySet();
            }
            Set<String> installedFeatures = DashboardExtensionsPage.this.discoveryViewer.getInstalledFeatures();
            Set<String> definitelyUninstall = new HashSet<String>();
            for (String feature : maybeUninstall) {
                if (installedFeatures.contains(feature)) {
                    definitelyUninstall.add(feature);
                }
            }
            if (definitelyUninstall.size() > 0) {
                IdeUiPlugin.log(new Status(IStatus.INFO, IdeUiPlugin.PLUGIN_ID, "To make way for a new version of m2eclipse, we will uninstall these features: " + definitelyUninstall));
            }
            return definitelyUninstall;
        }

        /**
         * This method checks for conflicts with requested installs. If a
         * conflict is found, this method will pop up a dialog explaining
         * the conflict and it will return true.
         * @param featuresToCheck set of features of which only one can be
         * installed at once.
         * @param message message to add if there is an error
         * @param selection
         *
         * @return true iff there is a conflict.
         */
        public IStatus checkForConflicts(Set<String> featuresToCheck, String prependedMessage, List<ConnectorDescriptor> selection) {
            StringBuilder message = new StringBuilder();
            List<ConnectorDescriptor> conflicting = new ArrayList<ConnectorDescriptor>();
            for (ConnectorDescriptor descriptor : selection) {
                if (featuresToCheck.contains(descriptor.getId())) {
                    conflicting.add(descriptor);
                    if (message.length() > 0) {
                        message.append(", ");
                    }
                    message.append(descriptor.getName());
                }
            }
            if (conflicting.size() > 1) {
                return new Status(IStatus.WARNING, IdeUiPlugin.PLUGIN_ID, NLS.bind("The following extensions can not be installed at the same time: {0}.", message.toString()));
            } else {
                return Status.OK_STATUS;
            }
        }
    });
    Display.getCurrent().asyncExec(new Runnable() {

        public void run() {
            if (!managedForm.getForm().isDisposed()) {
                discoveryViewer.updateDiscovery();
            }
        }
    });
    discoveryViewer.addSelectionChangedListener(new ISelectionChangedListener() {

        public void selectionChanged(SelectionChangedEvent event) {
            installButton.setEnabled(discoveryViewer.isComplete());
        }
    });
}
Also used : DisposeListener(org.eclipse.swt.events.DisposeListener) NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) IStatus(org.eclipse.core.runtime.IStatus) HyperlinkEvent(org.eclipse.ui.forms.events.HyperlinkEvent) Set(java.util.Set) HashSet(java.util.HashSet) FormToolkit(org.eclipse.ui.forms.widgets.FormToolkit) MultiStatus(org.eclipse.core.runtime.MultiStatus) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) DisposeEvent(org.eclipse.swt.events.DisposeEvent) InstalledItem(org.eclipse.mylyn.internal.discovery.ui.InstalledItem) UninstallRequest(org.eclipse.mylyn.internal.discovery.ui.UninstallRequest) GridLayout(org.eclipse.swt.layout.GridLayout) PreferenceDialog(org.eclipse.jface.preference.PreferenceDialog) SelectionEvent(org.eclipse.swt.events.SelectionEvent) ProgressMonitorPart(org.eclipse.jface.wizard.ProgressMonitorPart) List(java.util.List) ArrayList(java.util.ArrayList) MultiStatus(org.eclipse.core.runtime.MultiStatus) IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) Composite(org.eclipse.swt.widgets.Composite) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) InvocationTargetException(java.lang.reflect.InvocationTargetException) ConnectorDescriptor(org.eclipse.mylyn.internal.discovery.core.model.ConnectorDescriptor) IHandlerService(org.eclipse.ui.handlers.IHandlerService) DisposeEvent(org.eclipse.swt.events.DisposeEvent) HyperlinkEvent(org.eclipse.ui.forms.events.HyperlinkEvent) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) Event(org.eclipse.swt.widgets.Event) SelectionEvent(org.eclipse.swt.events.SelectionEvent) AbstractInstallJob(org.eclipse.mylyn.internal.discovery.ui.AbstractInstallJob) Hyperlink(org.eclipse.ui.forms.widgets.Hyperlink) HyperlinkAdapter(org.eclipse.ui.forms.events.HyperlinkAdapter)

Example 82 with MultiStatus

use of org.eclipse.core.runtime.MultiStatus in project eclipse-integration-commons by spring-projects.

the class ContentManager method refresh.

/**
 * Refreshes the list of descriptors, and persists them in the state file.
 * It then re-initialises all the content items.
 * @param monitor
 * @param shouldDownloadRemotes
 * @param bundle optional. can be null
 * @return
 */
public IStatus refresh(IProgressMonitor monitor, boolean shouldDownloadRemotes) {
    File targetFile = getStateFile();
    Assert.isNotNull(targetFile, "stateFile not initialized");
    isRefreshing = true;
    SubMonitor progress = SubMonitor.convert(monitor, 100);
    try {
        progress.beginTask("Refreshing", 200);
        MultiStatus result = new MultiStatus(ContentPlugin.PLUGIN_ID, 0, "Results of template project refresh:", null);
        DescriptorReader reader = new DescriptorReader();
        if (shouldDownloadRemotes) {
            markLocalTemplatesAsLocal(progress, result, reader);
            for (String descriptorLocation : getRemoteDescriptorLocations()) {
                // remote descriptor
                try {
                    if (descriptorLocation != null && descriptorLocation.length() > 0) {
                        readFromUrl(reader, descriptorLocation, progress.newChild(70));
                    }
                } catch (CoreException e) {
                    String message = NLS.bind("Error while downloading or parsing descriptors file ''{0}'':\n\n{1}", descriptorLocation, e);
                    result.add(new Status(IStatus.ERROR, ContentPlugin.PLUGIN_ID, message, e));
                }
            }
        } else {
            try {
                reader.read(targetFile);
            } catch (CoreException e) {
                String message = NLS.bind("Failed to store updated descriptors to ''{0}''", targetFile.getAbsolutePath());
                result.add(new Status(IStatus.ERROR, ContentPlugin.PLUGIN_ID, message, e));
            }
            markLocalTemplatesAsLocal(progress, result, reader);
        }
        // store on disk
        try {
            if (result.isOK()) {
                reader.write(targetFile);
                init();
            }
        } catch (CoreException e) {
            String message = NLS.bind("Failed to store updated descriptors to ''{0}''", targetFile.getAbsolutePath());
            result.add(new Status(IStatus.ERROR, ContentPlugin.PLUGIN_ID, message, e));
        }
        if (result.isOK()) {
            isDirty = false;
        }
        return result;
    } finally {
        isRefreshing = false;
        progress.done();
    }
}
Also used : MultiStatus(org.eclipse.core.runtime.MultiStatus) IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) CoreException(org.eclipse.core.runtime.CoreException) SubMonitor(org.eclipse.core.runtime.SubMonitor) MultiStatus(org.eclipse.core.runtime.MultiStatus) File(java.io.File) DescriptorReader(org.springsource.ide.eclipse.commons.content.core.util.DescriptorReader)

Example 83 with MultiStatus

use of org.eclipse.core.runtime.MultiStatus in project eclipse-integration-commons by spring-projects.

the class ContentManager method markLocalTemplatesAsLocal.

// Right after a template project is downloaded, the ContentManager doesn't
// know yet that the project has been downloaded. The way that the
// ContentManager finds that out is by walking the installation directory
// and marking every project it finds as local.
// Note that the ContentManager determines if a download was successful by
// looking to see if that project is now marked as local.
public void markLocalTemplatesAsLocal(SubMonitor progress, MultiStatus result, DescriptorReader reader) {
    IStatus descriptorParseStatus = new Status(IStatus.OK, ContentPlugin.PLUGIN_ID, NLS.bind("No descriptors were found.", null));
    File dir = getInstallDirectory();
    File[] children = dir.listFiles();
    if (children == null || children.length <= 0) {
        progress.setWorkRemaining(70);
        return;
    }
    SubMonitor loopProgress = progress.newChild(30).setWorkRemaining(children.length);
    for (File childDirectory : children) {
        if (childDirectory.isDirectory()) {
            if ((new File(childDirectory, IContentConstants.TEMPLATE_DATA_FILE_NAME).exists())) {
                descriptorParseStatus = setDirectoryDescriptorsToLocal(reader, childDirectory);
            } else {
                // Files downloaded directly from template.xml (as opposed
                // to via descriptors.xml) can be in a subdirectory when
                // they first get extracted. They will eventually get moved
                // up one directory level, but that might not happen by the
                // time we reach here.
                File[] grandchildren = childDirectory.listFiles();
                for (File grandchildDirectory : grandchildren) {
                    if (grandchildDirectory.isDirectory()) {
                        descriptorParseStatus = setDirectoryDescriptorsToLocal(reader, grandchildDirectory);
                    }
                }
            }
            if (!descriptorParseStatus.isOK()) {
                result.add(descriptorParseStatus);
            }
        }
        loopProgress.worked(1);
    }
}
Also used : MultiStatus(org.eclipse.core.runtime.MultiStatus) IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) IStatus(org.eclipse.core.runtime.IStatus) SubMonitor(org.eclipse.core.runtime.SubMonitor) File(java.io.File)

Example 84 with MultiStatus

use of org.eclipse.core.runtime.MultiStatus in project eclipse-integration-commons by spring-projects.

the class ContentManager method init.

public void init() {
    itemById.clear();
    itemsByKind.clear();
    MultiStatus result = new MultiStatus(ContentPlugin.PLUGIN_ID, 0, NLS.bind("Reading of content failed", null), null);
    File file = getStateFile();
    if (file != null && file.exists()) {
        try {
            read(file);
        } catch (CoreException e) {
            StatusHandler.log(new Status(IStatus.WARNING, ContentPlugin.PLUGIN_ID, NLS.bind("Detected error in ''{0}''", file.getAbsoluteFile()), e));
        }
    }
    file = getDefaultStateFile();
    if (file != null) {
        try {
            read(file);
        } catch (CoreException e) {
            StatusHandler.log(new Status(IStatus.WARNING, ContentPlugin.PLUGIN_ID, NLS.bind("Detected error in ''{0}''", file.getAbsoluteFile()), e));
        }
    }
    if (!result.isOK()) {
        StatusHandler.log(result);
    }
    firePropertyChangeEvent(EVENT_REFRESH);
}
Also used : MultiStatus(org.eclipse.core.runtime.MultiStatus) IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) CoreException(org.eclipse.core.runtime.CoreException) MultiStatus(org.eclipse.core.runtime.MultiStatus) File(java.io.File)

Example 85 with MultiStatus

use of org.eclipse.core.runtime.MultiStatus in project eclipse-integration-commons by spring-projects.

the class LegacySTSChecker method earlyStartup.

/**
 * This entry to the checker comes at the startup of the workbench
 */
public void earlyStartup() {
    PREFERENCE_STORE.setDefault(AUTO_CHECK_FOR_LEGACY_STS_PROJECTS, true);
    if (shouldPerformProjectCheck()) {
        Job job = new LegacyProjectsJob(false);
        job.schedule();
        ResourcesPlugin.getWorkspace().addResourceChangeListener(LegacyProjectListener.LISTENER, IResourceChangeEvent.POST_CHANGE);
    }
    if (shouldPerformWorkspaceMigration()) {
        new // $NON-NLS-1$
        UIJob(// $NON-NLS-1$
        "Convert legacy STS 2.x preferences") {

            @Override
            public IStatus runInUIThread(IProgressMonitor monitor) {
                IStatus status = new LegacyWorkspaceConverter().convert(monitor);
                IStatus status2 = new PerspectiveMigrator().migratePerspective(GRAILS_OLD_PERSPECTIVE_ID, GRAILS_NEW_PERSPECTIVE_ID, monitor);
                MultiStatus statuses = new MultiStatus(FrameworkUIActivator.PLUGIN_ID, 0, new IStatus[] { status, status2 }, "Legacy workspace migration", null);
                return statuses;
            }
        }.schedule();
    }
}
Also used : IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) IStatus(org.eclipse.core.runtime.IStatus) LegacyWorkspaceConverter(org.springsource.ide.eclipse.commons.frameworks.core.legacyconversion.LegacyWorkspaceConverter) MultiStatus(org.eclipse.core.runtime.MultiStatus) Job(org.eclipse.core.runtime.jobs.Job) UIJob(org.eclipse.ui.progress.UIJob)

Aggregations

MultiStatus (org.eclipse.core.runtime.MultiStatus)146 IStatus (org.eclipse.core.runtime.IStatus)102 Status (org.eclipse.core.runtime.Status)62 CoreException (org.eclipse.core.runtime.CoreException)41 ArrayList (java.util.ArrayList)29 File (java.io.File)24 SubMonitor (org.eclipse.core.runtime.SubMonitor)24 IOException (java.io.IOException)14 InvocationTargetException (java.lang.reflect.InvocationTargetException)13 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)13 List (java.util.List)11 HashMap (java.util.HashMap)10 OperationCanceledException (org.eclipse.core.runtime.OperationCanceledException)10 IPath (org.eclipse.core.runtime.IPath)8 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)8 FileNotFoundException (java.io.FileNotFoundException)7 HashSet (java.util.HashSet)7 IProject (org.eclipse.core.resources.IProject)7 IContainer (org.eclipse.core.resources.IContainer)6 URI (java.net.URI)5