use of org.eclipse.epp.mpc.ui.Operation in project epp.mpc by eclipse.
the class MarketplaceWizard method handleInstallRequest.
protected boolean handleInstallRequest(final SolutionInstallationInfo installInfo, String url) {
final String installId = installInfo.getInstallId();
if (installId == null) {
return false;
}
try {
final MarketplacePage catalogPage = getCatalogPage();
IStatus showingDescriptor = catalogPage.showMarketplace(installInfo.getCatalogDescriptor());
if (!showingDescriptor.isOK()) {
return true;
}
final SelectionModel selectionModel = getSelectionModel();
final Map<String, Operation> nodeIdToOperation = new HashMap<String, Operation>();
nodeIdToOperation.putAll(getSelectionModel().getItemIdToSelectedOperation());
try {
nodeIdToOperation.put(URLDecoder.decode(installId, UTF_8), Operation.INSTALL);
} catch (UnsupportedEncodingException e) {
// should be unreachable
throw new IllegalStateException();
}
getContainer().run(true, true, new IRunnableWithProgress() {
public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
SelectionModelStateSerializer stateSerializer = new SelectionModelStateSerializer(getCatalog(), selectionModel);
stateSerializer.deserialize(installInfo.getState(), nodeIdToOperation, monitor);
}
});
if (selectionModel.getItemToSelectedOperation().size() > 0) {
Display display = getShell().getDisplay();
if (!display.isDisposed()) {
display.asyncExec(new Runnable() {
public void run() {
MarketplacePage catalogPage = getCatalogPage();
IWizardPage currentPage = getContainer().getCurrentPage();
if (catalogPage == currentPage) {
catalogPage.getViewer().setSelection(new StructuredSelection(selectionModel.getSelectedCatalogItems().toArray()));
catalogPage.show(installInfo.getCatalogDescriptor(), ContentType.SELECTION);
IWizardPage nextPage = catalogPage.getNextPage();
if (nextPage != null && catalogPage.isPageComplete()) {
getContainer().showPage(nextPage);
}
}
}
});
}
}
return true;
} catch (InvocationTargetException e) {
IStatus status = MarketplaceClientCore.computeStatus(e, Messages.MarketplaceViewer_unexpectedException);
MarketplaceClientUi.handle(status, StatusManager.SHOW | StatusManager.BLOCK | StatusManager.LOG);
} catch (InterruptedException e) {
// action canceled, but this still counts as handled
return true;
}
return false;
}
use of org.eclipse.epp.mpc.ui.Operation in project epp.mpc by eclipse.
the class SelectionModel method computeInitiallyChecked.
private Boolean computeInitiallyChecked(FeatureEntry featureEntry) {
CatalogItemEntry parent = featureEntry.getParent();
Operation selectedOperation = parent.getSelectedOperation();
switch(selectedOperation) {
case INSTALL:
if (!featureEntry.isInstalled()) {
return featureEntry.isRequiredInstall() || featureEntry.getInstallableUnitItem().isDefaultSelected();
}
return featureEntry.hasUpdateAvailable();
case UNINSTALL:
return featureEntry.isInstalled();
case UPDATE:
return featureEntry.hasUpdateAvailable() || featureEntry.isRequiredInstall();
case CHANGE:
return featureEntry.isInstalled();
}
return false;
}
use of org.eclipse.epp.mpc.ui.Operation in project epp.mpc by eclipse.
the class SelectionModel method getCatalogItemEntries.
public List<CatalogItemEntry> getCatalogItemEntries() {
if (entries == null) {
List<CatalogItemEntry> entries = new ArrayList<CatalogItemEntry>();
for (Entry<CatalogItem, Operation> entry : itemToOperation.entrySet()) {
CatalogItem item = entry.getKey();
Operation operation = entry.getValue();
CatalogItemEntry itemEntry = createItemEntry(item, operation);
entries.add(itemEntry);
}
this.entries = entries;
}
return entries;
}
use of org.eclipse.epp.mpc.ui.Operation in project epp.mpc by eclipse.
the class SelectionModelStateSerializer method serialize.
public String serialize() {
StringBuilder state = new StringBuilder(1024);
for (Map.Entry<CatalogItem, Operation> entry : selectionModel.getItemToSelectedOperation().entrySet()) {
if (entry.getValue() != Operation.NONE) {
if (state.length() > 0) {
state.append(' ');
}
INode data = (INode) entry.getKey().getData();
state.append(data.getId());
state.append('=');
state.append(entry.getValue().name());
}
}
return state.toString();
}
use of org.eclipse.epp.mpc.ui.Operation in project epp.mpc by eclipse.
the class SelectionModelStateSerializer method deserialize.
/**
* @param state
* the state to restore
* @param operationByNodeExtras
* additional operations to include
* @param monitor
*/
public void deserialize(String state, Map<String, Operation> operationByNodeExtras, IProgressMonitor monitor) {
Map<String, Operation> operationByNodeId = new HashMap<String, Operation>();
if (state != null && state.length() > 0) {
// $NON-NLS-1$
Pattern pattern = Pattern.compile("([^\\s=]+)=(\\S+)");
Matcher matcher = pattern.matcher(state);
while (matcher.find()) {
String nodeId = matcher.group(1);
String operationName = matcher.group(2);
Operation operation = Operation.valueOf(operationName);
operationByNodeId.put(nodeId, operation);
}
}
if (operationByNodeExtras != null) {
operationByNodeId.putAll(operationByNodeExtras);
}
if (!operationByNodeId.isEmpty()) {
catalog.performQuery(monitor, operationByNodeId.keySet());
for (CatalogItem item : catalog.getItems()) {
if (item instanceof MarketplaceNodeCatalogItem) {
MarketplaceNodeCatalogItem nodeItem = (MarketplaceNodeCatalogItem) item;
Operation operation = operationByNodeId.get(nodeItem.getData().getId());
if (operation != null && operation != Operation.NONE) {
if (nodeItem.isInstalled() && operation == Operation.INSTALL) {
operation = Operation.UPDATE;
}
selectionModel.select(nodeItem, operation);
}
}
}
}
}
Aggregations