Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 321d47d48644b791ab586fe7988e05baf9e90039 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
/*******************************************************************************
 * Copyright (c) 2011 Sonatype, Inc.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *      Sonatype, Inc. - initial API and implementation
 *******************************************************************************/

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;
import org.eclipse.equinox.p2.ui.AcceptLicensesWizardPage;
import org.eclipse.equinox.p2.ui.LoadMetadataRepositoryJob;
import org.eclipse.equinox.p2.ui.ProvisioningUI;
import org.eclipse.jface.wizard.IWizardPage;

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;

  private RestartInstallOperation originalOperation;

  public MavenDiscoveryInstallWizard(ProvisioningUI ui, RestartInstallOperation operation,
      Collection<IInstallableUnit> initialSelections, LoadMetadataRepositoryJob job) {
    super(ui, operation, initialSelections, job);
    this.originalOperation = operation;
  }

  @Override
  protected ProfileChangeOperation getProfileChangeOperation(Object[] elements) {
    RestartInstallOperation op = ((RestartInstallOperation) originalOperation)
        .copy(ElementUtils.elementsToIUs(elements));
    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;
  }

  @Override
  protected void initializeResolutionModelElements(Object[] selectedElements) {
    super.initializeResolutionModelElements(selectedElements);
    // https://bugs.eclipse.org/bugs/show_bug.cgi?id=348660
    // PreselectedIUInstallWizard does not ask to approve licenses if original selection has not changed
    // give license page analyse preselected and do it's thing if necessary
    // TODO remove when Bug348660 is fixed in p2
    workaroundBug348660();
  }

  private void workaroundBug348660() {
    for(IWizardPage page : getPages()) {
      if(page instanceof AcceptLicensesWizardPage) {
        AcceptLicensesWizardPage licensePage = (AcceptLicensesWizardPage) page;
        licensePage.update(ElementUtils.elementsToIUs(planSelections).toArray(new IInstallableUnit[0]), operation);
      }
    }
  }

}

Back to the top