use of org.eclipse.epp.mpc.ui.Operation in project epp.mpc by eclipse.
the class SelectionModel method computeProvisioningOperationViability.
/**
* Determine what message related to finishing the wizard should correspond to the current selection.
*
* @return the message, or null if there should be no message.
*/
public IStatus computeProvisioningOperationViability() {
IStatus featureStatus = computeFeatureOperationViability();
if (featureStatus == null || !featureStatus.isOK()) {
return featureStatus;
}
Map<Operation, List<CatalogItem>> operationToItem = computeOperationToItem();
if (operationToItem.size() == 0) {
return new Status(IStatus.ERROR, MarketplaceClientUi.BUNDLE_ID, Messages.SelectionModel_Nothing_Selected);
} else if (operationToItem.size() == 1) {
Entry<Operation, List<CatalogItem>> entry = operationToItem.entrySet().iterator().next();
return new Status(IStatus.INFO, MarketplaceClientUi.BUNDLE_ID, NLS.bind(Messages.SelectionModel_count_selectedFor_operation, entry.getValue().size() == 1 ? Messages.SelectionModel_oneSolution : NLS.bind(Messages.SelectionModel_countSolutions, entry.getValue().size()), entry.getKey().getLabel()));
} else if (operationToItem.size() == 2 && operationToItem.containsKey(Operation.INSTALL) && operationToItem.containsKey(Operation.UPDATE)) {
int count = 0;
for (List<CatalogItem> items : operationToItem.values()) {
count += items.size();
}
return new Status(IStatus.INFO, MarketplaceClientUi.BUNDLE_ID, NLS.bind(Messages.SelectionModel_countSolutionsSelectedForInstallUpdate, count));
} else {
return new Status(IStatus.ERROR, MarketplaceClientUi.BUNDLE_ID, Messages.SelectionModel_cannotInstallRemoveConcurrently);
}
}
use of org.eclipse.epp.mpc.ui.Operation in project epp.mpc by eclipse.
the class SelectionModel method getFeatureEntryToOperation.
public Map<FeatureEntry, Operation> getFeatureEntryToOperation(boolean includeNone, boolean verify) {
Map<FeatureEntry, Operation> featureEntries = new HashMap<FeatureEntry, Operation>();
for (CatalogItemEntry entry : getCatalogItemEntries()) {
for (FeatureEntry featureEntry : entry.getChildren()) {
Operation operation = featureEntry.computeChangeOperation();
if (operation != null && (includeNone || operation != Operation.NONE)) {
Operation old = featureEntries.put(featureEntry, operation);
if (old != null && old != Operation.NONE) {
if (operation == Operation.NONE) {
featureEntries.put(featureEntry, old);
old = null;
} else if (verify && !old.equals(operation)) {
IStatus error = new Status(IStatus.ERROR, MarketplaceClientUi.BUNDLE_ID, NLS.bind(Messages.SelectionModel_Inconsistent_Actions, new Object[] { featureEntry.getFeatureDescriptor().getName(), old, operation }));
throw new IllegalStateException(new CoreException(error));
}
}
}
}
}
return Collections.unmodifiableMap(featureEntries);
}
use of org.eclipse.epp.mpc.ui.Operation in project epp.mpc by eclipse.
the class SelectionModel method select.
/**
* Select the given item with the given operation.
*
* @param item
* the item to select
* @param operation
* the operation to perform. Providing {@link Operation#NONE} removes the selection
*/
public boolean select(CatalogItem item, Operation operation) {
boolean changed = false;
Operation sanitizedOperation = operation;
if (operation != null && Operation.NONE != operation && item instanceof MarketplaceNodeCatalogItem) {
MarketplaceNodeCatalogItem nodeItem = (MarketplaceNodeCatalogItem) item;
List<Operation> availableOperations = nodeItem.getAvailableOperations();
if (!availableOperations.contains(operation)) {
sanitizedOperation = null;
switch(operation) {
case INSTALL:
if (availableOperations.contains(Operation.UPDATE)) {
sanitizedOperation = Operation.UPDATE;
}
break;
case UPDATE:
if (availableOperations.contains(Operation.INSTALL)) {
sanitizedOperation = Operation.UPDATE;
}
break;
}
}
}
if (sanitizedOperation == null || Operation.NONE == sanitizedOperation) {
if (itemToOperation.remove(item) != Operation.NONE) {
changed = true;
}
if (entries != null) {
Iterator<CatalogItemEntry> it = entries.iterator();
while (it.hasNext()) {
CatalogItemEntry entry = it.next();
if (entry.getItem().equals(item)) {
it.remove();
}
}
}
} else {
Operation previous = itemToOperation.put(item, sanitizedOperation);
if (previous != sanitizedOperation) {
changed = true;
if (entries != null) {
Iterator<CatalogItemEntry> it = entries.iterator();
while (it.hasNext()) {
CatalogItemEntry entry = it.next();
if (entry.getItem().equals(item)) {
it.remove();
}
}
CatalogItemEntry itemEntry = createItemEntry(item, sanitizedOperation);
entries.add(itemEntry);
}
}
}
if (changed) {
selectionChanged();
}
return changed;
}
use of org.eclipse.epp.mpc.ui.Operation in project epp.mpc by eclipse.
the class MarketplaceViewer method modifySelection.
protected void modifySelection(CatalogItem connector, Operation operation) {
if (operation == null) {
throw new IllegalArgumentException();
}
Operation selectedOperation = selectionModel.getSelectedOperation(connector);
selectionModel.select(connector, operation);
super.modifySelection(connector, operation != Operation.NONE);
if (selectedOperation != operation) {
getViewer().refresh(connector);
}
}
use of org.eclipse.epp.mpc.ui.Operation in project epp.mpc by eclipse.
the class MarketplaceWizard method updateProfileChangeOperation.
public void updateProfileChangeOperation() {
removeAddedRepositoryLocations();
addedRepositoryLocations = null;
profileChangeOperation = null;
operationIUs = null;
IWizardContainer wizardContainer = getContainer();
if (getSelectionModel().computeProvisioningOperationViable()) {
ProfileChangeOperationComputer provisioningOperation = null;
try {
final Map<CatalogItem, Operation> itemToOperation = getSelectionModel().getItemToSelectedOperation();
final Set<CatalogItem> selectedItems = getSelectionModel().getSelectedCatalogItems();
OperationType operationType = null;
for (Map.Entry<CatalogItem, Operation> entry : itemToOperation.entrySet()) {
if (!selectedItems.contains(entry.getKey())) {
continue;
}
OperationType entryOperationType = OperationType.map(entry.getValue());
if (entryOperationType != null) {
if (operationType == null || operationType == OperationType.UPDATE || entryOperationType == OperationType.CHANGE) {
operationType = entryOperationType;
}
}
}
Map<FeatureEntry, Operation> featureEntries = getSelectionModel().getFeatureEntryToOperation(false, false);
if (operationType == OperationType.CHANGE || operationType == OperationType.UPDATE) {
Set<OperationType> featureOperations = EnumSet.noneOf(OperationType.class);
for (Entry<FeatureEntry, Operation> entry : featureEntries.entrySet()) {
OperationType operation = OperationType.map(entry.getValue());
if (operation != null) {
featureOperations.add(operation);
}
}
if (featureOperations.contains(OperationType.INSTALL) && featureOperations.contains(OperationType.UPDATE)) {
// just perform install instead, which covers update
featureOperations.remove(OperationType.UPDATE);
}
if (featureOperations.size() == 1) {
operationType = featureOperations.iterator().next();
}
}
URI dependenciesRepository = null;
if (getConfiguration().getCatalogDescriptor().getDependenciesRepository() != null) {
try {
dependenciesRepository = getConfiguration().getCatalogDescriptor().getDependenciesRepository().toURI();
} catch (URISyntaxException e) {
throw new InvocationTargetException(e);
}
}
provisioningOperation = new ProfileChangeOperationComputer(operationType, selectedItems, featureEntries.keySet(), dependenciesRepository, getConfiguration().getCatalogDescriptor().isInstallFromAllRepositories() ? ProfileChangeOperationComputer.ResolutionStrategy.FALLBACK_STRATEGY : ProfileChangeOperationComputer.ResolutionStrategy.SELECTED_REPOSITORIES, withRemediation);
wizardContainer.run(true, true, provisioningOperation);
profileChangeOperation = provisioningOperation.getOperation();
operationIUs = provisioningOperation.getIus();
addedRepositoryLocations = provisioningOperation.getAddedRepositoryLocations();
operationNewInstallItems = computeNewInstallCatalogItems();
errorMessage = provisioningOperation.getErrorMessage();
final IStatus result = profileChangeOperation.getResolutionResult();
if (result != null && operationIUs != null && operationIUs.length > 0 && operationType == OperationType.INSTALL) {
switch(result.getSeverity()) {
case IStatus.ERROR:
Job job = new Job(Messages.MarketplaceWizard_errorNotificationJob) {
IStatus r = result;
Set<CatalogItem> items = new HashSet<CatalogItem>(itemToOperation.keySet());
IInstallableUnit[] ius = operationIUs;
String details = profileChangeOperation.getResolutionDetails();
{
setSystem(false);
setUser(false);
setPriority(LONG);
}
@Override
protected IStatus run(IProgressMonitor monitor) {
getCatalog().installErrorReport(monitor, r, items, ius, details);
return monitor.isCanceled() ? Status.CANCEL_STATUS : Status.OK_STATUS;
}
};
job.schedule();
}
}
} catch (InvocationTargetException e) {
Throwable cause = e.getCause();
IStatus status;
if (cause instanceof CoreException) {
status = ((CoreException) cause).getStatus();
} else {
status = new Status(IStatus.ERROR, MarketplaceClientUi.BUNDLE_ID, NLS.bind(Messages.MarketplaceWizard_problemsPerformingProvisioningOperation, new Object[] { cause.getMessage() }), cause);
}
MarketplaceClientUi.handle(status, StatusManager.SHOW | StatusManager.BLOCK | StatusManager.LOG);
} catch (InterruptedException e) {
// canceled
MarketplaceClientUi.log(IStatus.CANCEL, MarketplaceClientUi.BUNDLE_ID, Messages.MarketplaceWizard_ProvisioningOperationCancelled, e);
} finally {
if (provisioningOperation != null) {
addedRepositoryLocations = provisioningOperation.getAddedRepositoryLocations();
}
}
}
// re-get the container - in case the wizard was closed in the meantime, this will be null...
wizardContainer = getContainer();
if (wizardContainer != null && wizardContainer.getCurrentPage() == featureSelectionWizardPage) {
featureSelectionWizardPage.updateMessage();
}
}
Aggregations