Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthew Piggott2011-03-08 15:59:04 +0000
committerIgor Fedorenko2011-03-08 16:59:50 +0000
commit0b0636480c27b34860f44a1c6ba6d192b4832d39 (patch)
tree3a18783c0d513b75d6b9d35670579f4796e2a446 /org.eclipse.m2e.discovery
parentcf3055482504d8e2c694dbc99a12633e84194cf8 (diff)
downloadm2e-core-0b0636480c27b34860f44a1c6ba6d192b4832d39.tar.gz
m2e-core-0b0636480c27b34860f44a1c6ba6d192b4832d39.tar.xz
m2e-core-0b0636480c27b34860f44a1c6ba6d192b4832d39.zip
bug 338868 - Changed page used by wizard
Diffstat (limited to 'org.eclipse.m2e.discovery')
-rw-r--r--org.eclipse.m2e.discovery/META-INF/MANIFEST.MF4
-rw-r--r--org.eclipse.m2e.discovery/src/org/eclipse/m2e/internal/discovery/MavenDiscoveryService.java217
-rw-r--r--org.eclipse.m2e.discovery/src/org/eclipse/m2e/internal/discovery/wizards/DiscoverySelectableIUsPage.java461
-rw-r--r--org.eclipse.m2e.discovery/src/org/eclipse/m2e/internal/discovery/wizards/MavenDiscoveryInstallWizard.java22
4 files changed, 665 insertions, 39 deletions
diff --git a/org.eclipse.m2e.discovery/META-INF/MANIFEST.MF b/org.eclipse.m2e.discovery/META-INF/MANIFEST.MF
index a6802e76..1157bd53 100644
--- a/org.eclipse.m2e.discovery/META-INF/MANIFEST.MF
+++ b/org.eclipse.m2e.discovery/META-INF/MANIFEST.MF
@@ -22,7 +22,8 @@ Require-Bundle: org.eclipse.equinox.p2.ui.discovery,
org.eclipse.m2e.core.ui;bundle-version="[0.13.0,0.14.0)",
org.slf4j.api;bundle-version="1.5.11",
org.eclipse.m2e.maven.runtime;bundle-version="[0.13.0,0.14.0)",
- org.eclipse.equinox.p2.repository
+ org.eclipse.equinox.p2.repository,
+ org.eclipse.equinox.p2.ui
Export-Package: org.eclipse.m2e.internal.discovery;x-internal:=true,
org.eclipse.m2e.internal.discovery.handlers;x-internal:=true,
org.eclipse.m2e.internal.discovery.markers;x-internal:=true,
@@ -36,6 +37,7 @@ Import-Package: org.apache.maven.model,
org.eclipse.equinox.internal.p2.ui,
org.eclipse.equinox.internal.p2.ui.dialogs,
org.eclipse.equinox.internal.p2.ui.model,
+ org.eclipse.equinox.internal.p2.ui.viewers,
org.eclipse.equinox.internal.provisional.configurator,
org.eclipse.equinox.p2.engine,
org.eclipse.equinox.p2.metadata,
diff --git a/org.eclipse.m2e.discovery/src/org/eclipse/m2e/internal/discovery/MavenDiscoveryService.java b/org.eclipse.m2e.discovery/src/org/eclipse/m2e/internal/discovery/MavenDiscoveryService.java
index ed9c3ee2..43e814bd 100644
--- a/org.eclipse.m2e.discovery/src/org/eclipse/m2e/internal/discovery/MavenDiscoveryService.java
+++ b/org.eclipse.m2e.discovery/src/org/eclipse/m2e/internal/discovery/MavenDiscoveryService.java
@@ -13,10 +13,14 @@ package org.eclipse.m2e.internal.discovery;
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
+import java.net.URI;
import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.HashSet;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
+import java.util.Set;
import org.apache.maven.execution.MavenExecutionRequest;
import org.apache.maven.plugin.MojoExecution;
@@ -24,7 +28,10 @@ import org.apache.maven.project.MavenProject;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.NullProgressMonitor;
+import org.eclipse.core.runtime.OperationCanceledException;
import org.eclipse.core.runtime.Status;
+import org.eclipse.core.runtime.SubMonitor;
import org.eclipse.equinox.internal.p2.core.helpers.ServiceHelper;
import org.eclipse.equinox.internal.p2.discovery.Catalog;
import org.eclipse.equinox.internal.p2.discovery.model.CatalogItem;
@@ -32,15 +39,21 @@ import org.eclipse.equinox.internal.p2.ui.ProvUI;
import org.eclipse.equinox.internal.p2.ui.ProvUIActivator;
import org.eclipse.equinox.internal.p2.ui.ProvUIImages;
import org.eclipse.equinox.internal.p2.ui.ProvUIMessages;
-import org.eclipse.equinox.internal.p2.ui.dialogs.InstallWizardPage;
import org.eclipse.equinox.internal.p2.ui.model.AvailableIUElement;
import org.eclipse.equinox.internal.p2.ui.model.IUElementListRoot;
import org.eclipse.equinox.internal.provisional.configurator.Configurator;
import org.eclipse.equinox.p2.metadata.IInstallableUnit;
+import org.eclipse.equinox.p2.metadata.IVersionedId;
+import org.eclipse.equinox.p2.metadata.VersionedId;
import org.eclipse.equinox.p2.operations.ProvisioningJob;
-import org.eclipse.equinox.p2.ui.AcceptLicensesWizardPage;
+import org.eclipse.equinox.p2.operations.RepositoryTracker;
+import org.eclipse.equinox.p2.query.IQueryResult;
+import org.eclipse.equinox.p2.query.QueryUtil;
+import org.eclipse.equinox.p2.repository.metadata.IMetadataRepository;
+import org.eclipse.equinox.p2.repository.metadata.IMetadataRepositoryManager;
import org.eclipse.equinox.p2.ui.ProvisioningUI;
import org.eclipse.jface.operation.IRunnableContext;
+import org.eclipse.jface.operation.IRunnableWithProgress;
import org.eclipse.jface.wizard.IWizardPage;
import org.eclipse.m2e.core.MavenPlugin;
import org.eclipse.m2e.core.embedder.IMaven;
@@ -60,18 +73,23 @@ import org.eclipse.m2e.core.project.configurator.MojoExecutionKey;
import org.eclipse.m2e.core.ui.internal.wizards.IImportWizardPageFactory;
import org.eclipse.m2e.internal.discovery.operation.MavenDiscoveryInstallOperation;
import org.eclipse.m2e.internal.discovery.operation.RestartInstallOperation;
-import org.eclipse.m2e.internal.discovery.wizards.MavenDiscoveryInstallWizard;
+import org.eclipse.m2e.internal.discovery.wizards.DiscoverySelectableIUsPage;
+import org.eclipse.osgi.util.NLS;
import org.eclipse.ui.progress.IProgressConstants;
import org.eclipse.ui.progress.IProgressConstants2;
import org.eclipse.ui.statushandlers.StatusManager;
import org.osgi.framework.Bundle;
import org.osgi.framework.ServiceFactory;
import org.osgi.framework.ServiceRegistration;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
@SuppressWarnings({"restriction", "rawtypes"})
public class MavenDiscoveryService implements IImportWizardPageFactory, IMavenDiscovery, ServiceFactory {
+ private static final Logger log = LoggerFactory.getLogger(MavenDiscoveryService.class);
+
public static class CatalogItemCacheEntry {
private final CatalogItem item;
@@ -348,54 +366,179 @@ public class MavenDiscoveryService implements IImportWizardPageFactory, IMavenDi
/* (non-Javadoc)
* @see org.eclipse.m2e.core.ui.internal.wizards.IImportWizardPageFactory#getPage(java.util.List, org.eclipse.jface.operation.IRunnableContext)
*/
- public IWizardPage getPage(List<IMavenDiscoveryProposal> proposals, IRunnableContext context)
+ public IWizardPage getPage(final List<IMavenDiscoveryProposal> proposals, IRunnableContext context)
throws InvocationTargetException, InterruptedException {
+ final IWizardPage[] page = new IWizardPage[1];
if(proposals != null && !proposals.isEmpty()) {
- List<CatalogItem> installableConnectors = new ArrayList<CatalogItem>(proposals.size());
- for(IMavenDiscoveryProposal proposal : proposals) {
- if(proposal instanceof InstallCatalogItemMavenDiscoveryProposal) {
- installableConnectors.add(((InstallCatalogItemMavenDiscoveryProposal) proposal).getCatalogItem());
- }
- }
- if(installableConnectors.size() > 0) {
- MavenDiscoveryInstallOperation op = new MavenDiscoveryInstallOperation(installableConnectors,
- MavenDiscovery.requireRestart(installableConnectors));
- context.run(true, true, op);
-
- RestartInstallOperation operation = op.getOperation();
- IUElementListRoot root = new IUElementListRoot();
- ArrayList<AvailableIUElement> list = new ArrayList<AvailableIUElement>(operation.getIUs().size());
- for(IInstallableUnit iu : operation.getIUs()) {
- AvailableIUElement element = new AvailableIUElement(root, iu, ProvisioningUI.getDefaultUI().getProfileId(),
- false);
- list.add(element);
+ context.run(false, false, new IRunnableWithProgress() {
+
+ public void run(IProgressMonitor monitor) throws InvocationTargetException {
+ SubMonitor subMon = SubMonitor.convert(monitor, 11);
+ try {
+ List<CatalogItem> installableConnectors = new ArrayList<CatalogItem>(proposals.size());
+ for(IMavenDiscoveryProposal proposal : proposals) {
+ if(proposal instanceof InstallCatalogItemMavenDiscoveryProposal) {
+ installableConnectors.add(((InstallCatalogItemMavenDiscoveryProposal) proposal).getCatalogItem());
+ }
+ }
+ addRepositories(installableConnectors, subMon.newChild(10));
+ IInstallableUnit[] ius = computeInstallableUnits(installableConnectors, subMon.newChild(1));
+ RestartInstallOperation operation = new RestartInstallOperation(ProvisioningUI.getDefaultUI().getSession(),
+ Arrays.asList(ius));
+
+ IUElementListRoot root = new IUElementListRoot();
+ ArrayList<AvailableIUElement> list = new ArrayList<AvailableIUElement>(operation.getIUs().size());
+ for(IInstallableUnit iu : operation.getIUs()) {
+ AvailableIUElement element = new AvailableIUElement(root, iu, ProvisioningUI.getDefaultUI()
+ .getProfileId(), false);
+ list.add(element);
+ }
+ root.setChildren(list.toArray());
+ page[0] = new DiscoverySelectableIUsPage(ProvisioningUI.getDefaultUI(), operation, root, ius);
+ } catch(CoreException e) {
+ throw new InvocationTargetException(e);
+ } finally {
+ subMon.done();
+ }
}
- root.setChildren(list.toArray());
+ });
+ }
+ return page[0];
+ }
- return new InstallPage(ProvisioningUI.getDefaultUI(), root, operation);
+ /*
+ * Compute the InstallableUnits & IMetadataRepository
+ */
+ private static IInstallableUnit[] computeInstallableUnits(List<CatalogItem> installableConnectors,
+ IProgressMonitor progressMonitor) throws CoreException {
+ SubMonitor monitor = SubMonitor.convert(progressMonitor);
+ try {
+ List<IMetadataRepository> repositories = addRepositories(installableConnectors, monitor.newChild(50));
+ final List<IInstallableUnit> installableUnits = queryInstallableUnits(installableConnectors,
+ monitor.newChild(50), repositories);
+
+ return installableUnits.toArray(new IInstallableUnit[installableUnits.size()]);
+ } finally {
+ monitor.done();
+ }
+ }
+
+ /*
+ * Get IUs to install from the specified repository
+ */
+ private static List<IInstallableUnit> queryInstallableUnits(List<CatalogItem> installableConnectors, IProgressMonitor progressMonitor,
+ List<IMetadataRepository> repositories) {
+ final List<IInstallableUnit> installableUnits = new ArrayList<IInstallableUnit>(installableConnectors.size());
+
+ SubMonitor monitor = SubMonitor.convert(progressMonitor, installableConnectors.size());
+ try {
+ for(CatalogItem item : installableConnectors) {
+ SubMonitor subMon = monitor.newChild(1);
+ checkCancelled(monitor);
+ URI address = URI.create(item.getSiteUrl());
+ // get repository
+ IMetadataRepository repository = null;
+ for(IMetadataRepository candidate : repositories) {
+ if(address.equals(candidate.getLocation())) {
+ repository = candidate;
+ break;
+ }
+ }
+ if(repository == null) {
+ log.warn(NLS.bind(Messages.MavenDiscoveryInstallOperation_missingRepository, item.getName(),
+ item.getSiteUrl()));
+ // Continue so we gather all the problems before telling the user
+ continue;
+ }
+ // get IUs
+ checkCancelled(monitor);
+
+ Set<IVersionedId> ids = getDescriptorIds(installableConnectors, repository);
+ for(IVersionedId versionedId : ids) {
+ IQueryResult<IInstallableUnit> result = repository.query(QueryUtil.createIUQuery(versionedId),
+ subMon.newChild(1));
+ Set<IInstallableUnit> matches = result.toSet();
+ if(matches.size() == 1) {
+ installableUnits.addAll(matches);
+ } else if(matches.size() == 0) {
+ log.warn(NLS.bind(Messages.MavenDiscoveryInstallOperation_missingIU, item.getName(), versionedId.toString()));
+ } else {
+ // Choose the highest available version
+ IInstallableUnit match = null;
+ for(IInstallableUnit iu : matches) {
+ if(match == null || iu.getVersion().compareTo(match.getVersion()) > 0) {
+ match = iu;
+ }
+ }
+ if(match != null) {
+ installableUnits.add(match);
+ }
+ }
+ }
}
+ return installableUnits;
+ } finally {
+ monitor.done();
}
- return null;
}
- private static class InstallPage extends InstallWizardPage {
- private RestartInstallOperation operation;
+ /*
+ * Add the necessary repositories
+ */
+ private static List<IMetadataRepository> addRepositories(List<CatalogItem> installableConnectors, SubMonitor monitor)
+ throws CoreException {
+ // tell p2 that it's okay to use these repositories
+ Set<URI> repositoryLocations = new HashSet<URI>();
+ for(CatalogItem items : installableConnectors) {
+ repositoryLocations.add(URI.create(items.getSiteUrl()));
+ }
- private AcceptLicensesWizardPage nextPage;
+ RepositoryTracker repositoryTracker = ProvisioningUI.getDefaultUI().getRepositoryTracker();
+ monitor.setWorkRemaining(installableConnectors.size() * 5);
+ for(CatalogItem descriptor : installableConnectors) {
+ URI uri = URI.create(descriptor.getSiteUrl());
+ if(repositoryLocations.add(uri)) {
+ checkCancelled(monitor);
+ repositoryTracker.addRepository(uri, null, ProvisioningUI.getDefaultUI().getSession());
+ }
+ monitor.worked(1);
+ }
- public InstallPage(ProvisioningUI ui, IUElementListRoot root, RestartInstallOperation operation) {
- super(ui, new MavenDiscoveryInstallWizard(ui, operation, operation.getIUs(), null), root, operation);
- this.operation = operation;
+ // fetch meta-data for these repositories
+ ArrayList<IMetadataRepository> repositories = new ArrayList<IMetadataRepository>();
+ monitor.setWorkRemaining(repositories.size());
+ IMetadataRepositoryManager manager = (IMetadataRepositoryManager) ProvisioningUI.getDefaultUI().getSession()
+ .getProvisioningAgent().getService(IMetadataRepositoryManager.SERVICE_NAME);
+ monitor.setTaskName("Contacting repositories");
+ for(URI uri : repositoryLocations) {
+ checkCancelled(monitor);
+ IMetadataRepository repository = manager.loadRepository(uri, new NullProgressMonitor());
+ monitor.worked(1);
+ repositories.add(repository);
}
+ return repositories;
+ }
- public IWizardPage getNextPage() {
- if(nextPage == null) {
- nextPage = new AcceptLicensesWizardPage(ProvisioningUI.getDefaultUI().getLicenseManager(), operation.getIUs()
- .toArray(new IInstallableUnit[operation.getIUs().size()]), operation);
- nextPage.setWizard(getWizard());
+ /*
+ * Get the IVersionedId expected to be in the repository
+ */
+ protected static Set<IVersionedId> getDescriptorIds(List<CatalogItem> installableConnectors,
+ IMetadataRepository repository) {
+ Set<IVersionedId> ids = new HashSet<IVersionedId>();
+ for(CatalogItem item : installableConnectors) {
+ if(repository.getLocation().equals(URI.create(item.getSiteUrl()))) {
+ for(String id : item.getInstallableUnits()) {
+ ids.add(VersionedId.parse(id));
+ }
}
- return nextPage;
+ }
+ return ids;
+ }
+
+ private static void checkCancelled(IProgressMonitor monitor) {
+ if(monitor.isCanceled()) {
+ throw new OperationCanceledException();
}
}
}
diff --git a/org.eclipse.m2e.discovery/src/org/eclipse/m2e/internal/discovery/wizards/DiscoverySelectableIUsPage.java b/org.eclipse.m2e.discovery/src/org/eclipse/m2e/internal/discovery/wizards/DiscoverySelectableIUsPage.java
new file mode 100644
index 00000000..3e4e9157
--- /dev/null
+++ b/org.eclipse.m2e.discovery/src/org/eclipse/m2e/internal/discovery/wizards/DiscoverySelectableIUsPage.java
@@ -0,0 +1,461 @@
+
+package org.eclipse.m2e.internal.discovery.wizards;
+
+import java.util.ArrayList;
+
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.equinox.internal.p2.ui.ProvUI;
+import org.eclipse.equinox.internal.p2.ui.ProvUIMessages;
+import org.eclipse.equinox.internal.p2.ui.dialogs.CopyUtils;
+import org.eclipse.equinox.internal.p2.ui.dialogs.ILayoutConstants;
+import org.eclipse.equinox.internal.p2.ui.dialogs.IResolutionErrorReportingPage;
+import org.eclipse.equinox.internal.p2.ui.dialogs.IUDetailsGroup;
+import org.eclipse.equinox.internal.p2.ui.dialogs.InstallWizardPage;
+import org.eclipse.equinox.internal.p2.ui.dialogs.ResolutionStatusPage;
+import org.eclipse.equinox.internal.p2.ui.model.AvailableIUElement;
+import org.eclipse.equinox.internal.p2.ui.model.ElementUtils;
+import org.eclipse.equinox.internal.p2.ui.model.IUElementListRoot;
+import org.eclipse.equinox.internal.p2.ui.viewers.IUColumnConfig;
+import org.eclipse.equinox.internal.p2.ui.viewers.IUComparator;
+import org.eclipse.equinox.internal.p2.ui.viewers.IUDetailsLabelProvider;
+import org.eclipse.equinox.internal.p2.ui.viewers.ProvElementComparer;
+import org.eclipse.equinox.internal.p2.ui.viewers.ProvElementContentProvider;
+import org.eclipse.equinox.p2.metadata.IInstallableUnit;
+import org.eclipse.equinox.p2.operations.ProfileChangeOperation;
+import org.eclipse.equinox.p2.ui.AcceptLicensesWizardPage;
+import org.eclipse.equinox.p2.ui.Policy;
+import org.eclipse.equinox.p2.ui.ProvisioningUI;
+import org.eclipse.jface.dialogs.Dialog;
+import org.eclipse.jface.dialogs.IDialogConstants;
+import org.eclipse.jface.viewers.CheckStateChangedEvent;
+import org.eclipse.jface.viewers.CheckboxTableViewer;
+import org.eclipse.jface.viewers.ICheckStateListener;
+import org.eclipse.jface.viewers.ISelectionChangedListener;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.jface.viewers.SelectionChangedEvent;
+import org.eclipse.jface.wizard.IWizardPage;
+import org.eclipse.m2e.internal.discovery.operation.RestartInstallOperation;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.custom.SashForm;
+import org.eclipse.swt.layout.FillLayout;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Button;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.swt.widgets.Event;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.Listener;
+import org.eclipse.swt.widgets.Table;
+import org.eclipse.swt.widgets.TableColumn;
+
+/**
+ * A wizard page that presents a check box list of IUs and allows the user
+ * to select and deselect them. Typically the first page in a provisioning
+ * operation wizard, and usually it is the page used to report resolution errors
+ * before advancing to resolution detail.
+ *
+ * @since 3.5
+ *
+ */
+@SuppressWarnings("restriction")
+public class DiscoverySelectableIUsPage extends ResolutionStatusPage implements IResolutionErrorReportingPage {
+
+ private static final String DIALOG_SETTINGS_SECTION = "SelectableIUsPage"; //$NON-NLS-1$
+ private RestartInstallOperation operation;
+
+ private Object[] planSelections;
+
+ private IWizardPage previousPage;
+
+ IUElementListRoot root;
+ Object[] initialSelections;
+ CheckboxTableViewer tableViewer;
+ IUDetailsGroup iuDetailsGroup;
+ ProvElementContentProvider contentProvider;
+ IUDetailsLabelProvider labelProvider;
+ protected Display display;
+ protected Policy policy;
+ SashForm sashForm;
+
+ public DiscoverySelectableIUsPage(ProvisioningUI ui, RestartInstallOperation operation, IUElementListRoot root,
+ IInstallableUnit[] ius) {
+ super("IUSelectionPage", ui, new MavenDiscoveryInstallWizard(ui, operation, operation.getIUs(), null)); //$NON-NLS-1$
+ this.initialSelections = ius;
+ this.root = root;
+ this.operation = operation;
+ setTitle(ProvUIMessages.InstallWizardPage_Title);
+ setDescription(ProvUIMessages.PreselectedIUInstallWizard_Description);
+ initializeResolutionModelElements(this.initialSelections);
+ ((MavenDiscoveryInstallWizard) getProvisioningWizard()).setMainPage(this);
+ ((MavenDiscoveryInstallWizard) getProvisioningWizard()).setResolutionResultsPage(createResolutionPage());
+ updateStatus(root, operation);
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.eclipse.jface.dialogs.IDialogPage#createControl(org.eclipse.swt.widgets.Composite)
+ */
+ public void createControl(Composite parent) {
+ display = parent.getDisplay();
+ sashForm = new SashForm(parent, SWT.VERTICAL);
+ FillLayout layout = new FillLayout();
+ sashForm.setLayout(layout);
+ GridData data = new GridData(GridData.FILL_BOTH);
+ sashForm.setLayoutData(data);
+ initializeDialogUnits(sashForm);
+
+ Composite composite = new Composite(sashForm, SWT.NONE);
+ GridLayout gridLayout = new GridLayout();
+ gridLayout.marginWidth = 0;
+ gridLayout.marginHeight = 0;
+ composite.setLayout(gridLayout);
+
+ tableViewer = createTableViewer(composite);
+ data = new GridData(GridData.FILL_BOTH);
+ data.heightHint = convertHeightInCharsToPixels(ILayoutConstants.DEFAULT_TABLE_HEIGHT);
+ data.widthHint = convertWidthInCharsToPixels(ILayoutConstants.DEFAULT_TABLE_WIDTH);
+ Table table = tableViewer.getTable();
+ table.setLayoutData(data);
+ table.setHeaderVisible(true);
+ activateCopy(table);
+ IUColumnConfig[] columns = getColumnConfig();
+ for (int i = 0; i < columns.length; i++) {
+ TableColumn tc = new TableColumn(table, SWT.LEFT, i);
+ tc.setResizable(true);
+ tc.setText(columns[i].getColumnTitle());
+ tc.setWidth(columns[i].getWidthInPixels(table));
+ }
+
+ tableViewer.addSelectionChangedListener(new ISelectionChangedListener() {
+ public void selectionChanged(SelectionChangedEvent event) {
+ setDetailText(operation);
+ }
+ });
+
+ tableViewer.addCheckStateListener(new ICheckStateListener() {
+ public void checkStateChanged(CheckStateChangedEvent event) {
+ updateSelection();
+ }
+ });
+
+ // Filters and sorters before establishing content, so we don't refresh unnecessarily.
+ IUComparator comparator = new IUComparator(IUComparator.IU_NAME);
+ comparator.useColumnConfig(ProvUI.getIUColumnConfig());
+ tableViewer.setComparator(comparator);
+ tableViewer.setComparer(new ProvElementComparer());
+
+ contentProvider = new ProvElementContentProvider();
+ tableViewer.setContentProvider(contentProvider);
+ labelProvider = new IUDetailsLabelProvider(null, ProvUI.getIUColumnConfig(), getShell());
+ tableViewer.setLabelProvider(labelProvider);
+ tableViewer.setInput(root);
+ setInitialCheckState();
+
+ // Select and Deselect All buttons
+ createSelectButtons(composite);
+
+ // The text area shows a description of the selected IU, or error detail if applicable.
+ iuDetailsGroup = new IUDetailsGroup(sashForm, tableViewer, convertWidthInCharsToPixels(ILayoutConstants.DEFAULT_TABLE_WIDTH), true);
+
+ updateStatus(root, operation);
+ setControl(sashForm);
+ sashForm.setWeights(getSashWeights());
+ Dialog.applyDialogFont(sashForm);
+ }
+
+ private void createSelectButtons(Composite parent) {
+ Composite buttonParent = new Composite(parent, SWT.NONE);
+ GridLayout gridLayout = new GridLayout();
+ gridLayout.numColumns = 3;
+ gridLayout.marginWidth = 0;
+ gridLayout.horizontalSpacing = convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_SPACING);
+ buttonParent.setLayout(gridLayout);
+ GridData data = new GridData(SWT.FILL, SWT.DEFAULT, true, false);
+ buttonParent.setLayoutData(data);
+
+ Button selectAll = new Button(buttonParent, SWT.PUSH);
+ selectAll.setText(ProvUIMessages.SelectableIUsPage_Select_All);
+ setButtonLayoutData(selectAll);
+ selectAll.addListener(SWT.Selection, new Listener() {
+ public void handleEvent(Event event) {
+ tableViewer.setAllChecked(true);
+ updateSelection();
+ }
+ });
+
+ Button deselectAll = new Button(buttonParent, SWT.PUSH);
+ deselectAll.setText(ProvUIMessages.SelectableIUsPage_Deselect_All);
+ setButtonLayoutData(deselectAll);
+ deselectAll.addListener(SWT.Selection, new Listener() {
+ public void handleEvent(Event event) {
+ tableViewer.setAllChecked(false);
+ updateSelection();
+ }
+ });
+
+ // dummy to take extra space
+ Label dummy = new Label(buttonParent, SWT.NONE);
+ data = new GridData(SWT.FILL, SWT.FILL, true, true);
+ dummy.setLayoutData(data);
+
+ // separator underneath
+ Label sep = new Label(buttonParent, SWT.HORIZONTAL | SWT.SEPARATOR);
+ data = new GridData(SWT.FILL, SWT.DEFAULT, true, false);
+ data.horizontalSpan = 3;
+ sep.setLayoutData(data);
+ }
+
+ protected CheckboxTableViewer createTableViewer(Composite parent) {
+ // The viewer allows selection of IU's for browsing the details,
+ // and checking to include in the provisioning operation.
+ CheckboxTableViewer v = CheckboxTableViewer.newCheckList(parent, SWT.BORDER | SWT.FULL_SELECTION | SWT.MULTI);
+ return v;
+ }
+
+ public Object[] getCheckedIUElements() {
+ if (tableViewer == null)
+ return initialSelections;
+ return tableViewer.getCheckedElements();
+ }
+
+ public Object[] getSelectedIUElements() {
+ return ((IStructuredSelection) tableViewer.getSelection()).toArray();
+ }
+
+ protected Object[] getSelectedElements() {
+ return ((IStructuredSelection) tableViewer.getSelection()).toArray();
+ }
+
+ protected IInstallableUnit[] elementsToIUs(Object[] elements) {
+ IInstallableUnit[] theIUs = new IInstallableUnit[elements.length];
+ for (int i = 0; i < elements.length; i++) {
+ theIUs[i] = ProvUI.getAdapter(elements[i], IInstallableUnit.class);
+ }
+ return theIUs;
+ }
+
+ protected void setInitialCheckState() {
+ if (initialSelections != null)
+ tableViewer.setCheckedElements(initialSelections);
+ }
+
+ /*
+ * Overridden so that we don't call getNextPage().
+ * We use getNextPage() to start resolving the operation so
+ * we only want to do that when the next button is pressed.
+ *
+ * (non-Javadoc)
+ * @see org.eclipse.jface.wizard.WizardPage#canFlipToNextPage()
+ */
+ public boolean canFlipToNextPage() {
+ return isPageComplete();
+ }
+
+ protected String getClipboardText(Control control) {
+ StringBuffer buffer = new StringBuffer();
+ Object[] elements = getSelectedElements();
+ for (int i = 0; i < elements.length; i++) {
+ if (i > 0)
+ buffer.append(CopyUtils.NEWLINE);
+ buffer.append(labelProvider.getClipboardText(elements[i], CopyUtils.DELIMITER));
+ }
+ return buffer.toString();
+ }
+
+ protected IInstallableUnit getSelectedIU() {
+ java.util.List<IInstallableUnit> units = ElementUtils.elementsToIUs(getSelectedElements());
+ if (units.size() == 0)
+ return null;
+ return units.get(0);
+ }
+
+ protected IUDetailsGroup getDetailsGroup() {
+ return iuDetailsGroup;
+ }
+
+ protected boolean isCreated() {
+ return tableViewer != null;
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.eclipse.equinox.internal.p2.ui.dialogs.ResolutionStatusPage#updateCaches(org.eclipse.equinox.internal.p2.ui.model.IUElementListRoot, org.eclipse.equinox.p2.operations.ProfileChangeOperation)
+ */
+ protected void updateCaches(IUElementListRoot newRoot, ProfileChangeOperation op) {
+ //resolvedOperation = op;
+ if (newRoot != null && root != newRoot) {
+ root = newRoot;
+ if (tableViewer != null)
+ tableViewer.setInput(newRoot);
+ }
+
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.equinox.internal.p2.ui.dialogs.ISelectableIUsPage#setCheckedElements(java.lang.Object[])
+ */
+ public void setCheckedElements(Object[] elements) {
+ if (tableViewer == null)
+ initialSelections = elements;
+ else
+ tableViewer.setCheckedElements(elements);
+ }
+
+ protected SashForm getSashForm() {
+ return sashForm;
+ }
+
+ protected String getDialogSettingsName() {
+ return getWizard().getClass().getName() + "." + DIALOG_SETTINGS_SECTION; //$NON-NLS-1$
+ }
+
+ protected int getColumnWidth(int index) {
+ return tableViewer.getTable().getColumn(index).getWidth();
+ }
+
+ void updateSelection() {
+ setPageComplete(tableViewer.getCheckedElements().length == 0 || operation.getResolutionResult().isOK());
+ getProvisioningWizard().operationSelectionsChanged(this);
+ }
+
+ private void setDetailText(ProfileChangeOperation resolvedOperation) {
+ String detail = null;
+ IInstallableUnit selectedIU = getSelectedIU();
+ IUDetailsGroup detailsGroup = getDetailsGroup();
+
+ // We either haven't resolved, or we failed to resolve and reported some error
+ // while doing so.
+ if(resolvedOperation == null || !resolvedOperation.hasResolved()
+ || getProvisioningWizard().statusOverridesOperation()) {
+ // See if the wizard status knows something more about it.
+ IStatus currentStatus = getProvisioningWizard().getCurrentStatus();
+ if(!currentStatus.isOK()) {
+ detail = currentStatus.getMessage();
+ detailsGroup.enablePropertyLink(false);
+ } else if(selectedIU != null) {
+ detail = getIUDescription(selectedIU);
+ detailsGroup.enablePropertyLink(true);
+ } else {
+ detail = ""; //$NON-NLS-1$
+ detailsGroup.enablePropertyLink(false);
+ }
+ detailsGroup.setDetailText(detail);
+ return;
+ }
+
+ // An IU is selected and we have resolved. Look for information about the specific IU.
+ if(selectedIU != null) {
+ detail = resolvedOperation.getResolutionDetails(selectedIU);
+ if(detail != null) {
+ detailsGroup.enablePropertyLink(false);
+ detailsGroup.setDetailText(detail);
+ return;
+ }
+ // No specific error about this IU. Show the overall error if it is in error.
+ if(resolvedOperation.getResolutionResult().getSeverity() == IStatus.ERROR) {
+ detail = resolvedOperation.getResolutionDetails();
+ if(detail != null) {
+ detailsGroup.enablePropertyLink(false);
+ detailsGroup.setDetailText(detail);
+ return;
+ }
+ }
+
+ // The overall status is not an error, or else there was no explanatory text for an error.
+ // We may as well just show info about this iu.
+ detailsGroup.enablePropertyLink(true);
+ detailsGroup.setDetailText(getIUDescription(selectedIU));
+ return;
+ }
+
+ //No IU is selected, give the overall report
+ detail = resolvedOperation.getResolutionDetails();
+ detailsGroup.enablePropertyLink(false);
+ if(detail == null)
+ detail = ""; //$NON-NLS-1$
+ detailsGroup.setDetailText(detail);
+ }
+
+ public IWizardPage getNextPage() {
+ // If we are moving from the main page or error page, we may need to resolve before
+ // advancing.
+ // Do we need to resolve?
+ if(operation == null
+ || (operation != null && ((MavenDiscoveryInstallWizard) getProvisioningWizard()).shouldRecomputePlan(this))) {
+ getProvisioningWizard().recomputePlan(getContainer());
+ } else {
+ // the selections have not changed from an IU point of view, but we want
+ // to reinitialize the resolution model elements to ensure they are up to
+ // date.
+ initializeResolutionModelElements(planSelections);
+ }
+ IStatus status = operation.getResolutionResult();
+ if(status == null || status.getSeverity() == IStatus.ERROR) {
+ return this;
+ } else if(status.getSeverity() == IStatus.CANCEL) {
+ return this;
+ } else {
+ IWizardPage page = createResolutionPage();
+ page.setWizard(getWizard());
+ return page;
+ }
+ }
+
+ public IWizardPage getPreviousPage() {
+ if(previousPage != null) {
+ return previousPage;
+ }
+
+ if(getWizard() == null) {
+ return null;
+ }
+
+ return getWizard().getPreviousPage(this);
+ }
+
+ public void setPreviousPage(IWizardPage page) {
+ previousPage = page;
+ }
+
+ private InstallPage createResolutionPage() {
+ return new InstallPage(getProvisioningUI(), root, operation);
+ }
+
+ protected void initializeResolutionModelElements(Object[] selectedElements) {
+ root = new IUElementListRoot();
+ ArrayList<AvailableIUElement> list = new ArrayList<AvailableIUElement>(selectedElements.length);
+ ArrayList<AvailableIUElement> selected = new ArrayList<AvailableIUElement>(selectedElements.length);
+ for(int i = 0; i < selectedElements.length; i++ ) {
+ IInstallableUnit iu = ElementUtils.getIU(selectedElements[i]);
+ if(iu != null) {
+ AvailableIUElement element = new AvailableIUElement(root, iu, operation.getProfileId(), false);
+ list.add(element);
+ selected.add(element);
+ }
+ }
+ root.setChildren(list.toArray());
+ planSelections = selected.toArray();
+ }
+
+ private static class InstallPage extends InstallWizardPage {
+ private RestartInstallOperation operation;
+
+ private AcceptLicensesWizardPage nextPage;
+
+ public InstallPage(ProvisioningUI ui, IUElementListRoot root, RestartInstallOperation operation) {
+ super(ui, new MavenDiscoveryInstallWizard(ui, operation, operation.getIUs(), null), root, operation);
+ this.operation = operation;
+ }
+
+ public IWizardPage getNextPage() {
+ if(nextPage == null) {
+ nextPage = new AcceptLicensesWizardPage(ProvisioningUI.getDefaultUI().getLicenseManager(), operation.getIUs()
+ .toArray(new IInstallableUnit[operation.getIUs().size()]), operation);
+ nextPage.setWizard(getWizard());
+ }
+ return nextPage;
+ }
+ }
+}
diff --git a/org.eclipse.m2e.discovery/src/org/eclipse/m2e/internal/discovery/wizards/MavenDiscoveryInstallWizard.java b/org.eclipse.m2e.discovery/src/org/eclipse/m2e/internal/discovery/wizards/MavenDiscoveryInstallWizard.java
index 964b6574..5e29f4e1 100644
--- a/org.eclipse.m2e.discovery/src/org/eclipse/m2e/internal/discovery/wizards/MavenDiscoveryInstallWizard.java
+++ b/org.eclipse.m2e.discovery/src/org/eclipse/m2e/internal/discovery/wizards/MavenDiscoveryInstallWizard.java
@@ -12,7 +12,10 @@ package org.eclipse.m2e.internal.discovery.wizards;
import java.util.Collection;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.equinox.internal.p2.ui.dialogs.ISelectableIUsPage;
import org.eclipse.equinox.internal.p2.ui.dialogs.PreselectedIUInstallWizard;
+import org.eclipse.equinox.internal.p2.ui.dialogs.ResolutionResultsWizardPage;
import org.eclipse.equinox.internal.p2.ui.model.ElementUtils;
import org.eclipse.equinox.p2.metadata.IInstallableUnit;
import org.eclipse.equinox.p2.operations.ProfileChangeOperation;
@@ -20,12 +23,14 @@ import org.eclipse.equinox.p2.ui.LoadMetadataRepositoryJob;
import org.eclipse.equinox.p2.ui.ProvisioningUI;
import org.eclipse.m2e.internal.discovery.operation.RestartInstallOperation;
-
/*
* This exists to allow us to return a ProfileChangeOperation which changes the restart policy for provisioning jobs.
*/
+@SuppressWarnings("restriction")
public class MavenDiscoveryInstallWizard extends PreselectedIUInstallWizard {
+ private boolean waitingForOtherJobs;
+
public MavenDiscoveryInstallWizard(ProvisioningUI ui, RestartInstallOperation operation,
Collection<IInstallableUnit> initialSelections, LoadMetadataRepositoryJob job) {
super(ui, operation, initialSelections, job);
@@ -41,4 +46,19 @@ public class MavenDiscoveryInstallWizard extends PreselectedIUInstallWizard {
op.setProfileId(getProfileId());
return op;
}
+
+ public boolean shouldRecomputePlan(ISelectableIUsPage page) {
+ boolean previouslyWaiting = waitingForOtherJobs;
+ boolean previouslyCanceled = getCurrentStatus().getSeverity() == IStatus.CANCEL;
+ waitingForOtherJobs = ui.hasScheduledOperations();
+ return waitingForOtherJobs || previouslyWaiting || previouslyCanceled || pageSelectionsHaveChanged(page);
+ }
+
+ public void setMainPage(ISelectableIUsPage page) {
+ mainPage = page;
+ }
+
+ public void setResolutionResultsPage(ResolutionResultsWizardPage page) {
+ resolutionPage = page;
+ }
}

Back to the top