use of eu.esdihumboldt.hale.ui.io.action.ActionUI in project hale by halestudio.
the class IOWizard method performFinish.
/**
* @see Wizard#performFinish()
*
* @return <code>true</code> if executing the I/O provider was successful
*/
@Override
public boolean performFinish() {
if (getProvider() == null) {
return false;
}
if (!applyConfiguration()) {
return false;
}
// create default report
IOReporter defReport = provider.createReporter();
// validate and execute provider
try {
// validate configuration
provider.validate();
ProjectService ps = PlatformUI.getWorkbench().getService(ProjectService.class);
URI projectLoc = ps.getLoadLocation() == null ? null : ps.getLoadLocation();
boolean isProjectResource = false;
if (actionId != null) {
// XXX instead move project resource to action?
ActionUI factory = ActionUIExtension.getInstance().findActionUI(actionId);
isProjectResource = factory.isProjectResource();
}
// prevent loading of duplicate resources
if (isProjectResource && provider instanceof ImportProvider && !getProviderFactory().allowDuplicateResource()) {
String currentResource = ((ImportProvider) provider).getSource().getLocation().toString();
URI currentAbsolute = URI.create(currentResource);
if (projectLoc != null && !currentAbsolute.isAbsolute()) {
currentAbsolute = projectLoc.resolve(currentAbsolute);
}
for (IOConfiguration conf : ((Project) ps.getProjectInfo()).getResources()) {
Value otherResourceValue = conf.getProviderConfiguration().get(ImportProvider.PARAM_SOURCE);
if (otherResourceValue == null) {
continue;
}
String otherResource = otherResourceValue.as(String.class);
URI otherAbsolute = URI.create(otherResource);
if (projectLoc != null && !otherAbsolute.isAbsolute()) {
otherAbsolute = projectLoc.resolve(otherAbsolute);
}
String action = conf.getActionId();
// resource is already loaded into the project
if (currentAbsolute.equals(otherAbsolute) && Objects.equal(actionId, action)) {
// check if the resource is loaded with a provider that
// allows duplicates
boolean allowDuplicate = false;
IOProviderDescriptor providerFactory = IOProviderExtension.getInstance().getFactory(conf.getProviderId());
if (providerFactory != null) {
allowDuplicate = providerFactory.allowDuplicateResource();
}
if (!allowDuplicate) {
log.userError("Resource is already loaded. Loading duplicate resources is aborted!");
return false;
}
}
}
}
// enable provider internal caching
if (isProjectResource && provider instanceof CachingImportProvider) {
((CachingImportProvider) provider).setProvideCache();
}
IOReport report = execute(provider, defReport);
if (report != null) {
// add report to report server
ReportService repService = PlatformUI.getWorkbench().getService(ReportService.class);
repService.addReport(report);
// show message to user
if (report.isSuccess()) {
// let advisor handle results
try {
getContainer().run(true, false, new IRunnableWithProgress() {
@Override
public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
monitor.beginTask("Completing operation...", IProgressMonitor.UNKNOWN);
try {
advisor.handleResults(getProvider());
} finally {
monitor.done();
}
}
});
} catch (InvocationTargetException e) {
log.userError("Error processing results:\n" + e.getCause().getLocalizedMessage(), e.getCause());
return false;
} catch (Exception e) {
log.userError("Error processing results:\n" + e.getLocalizedMessage(), e);
return false;
}
// add to project service if necessary
if (isProjectResource)
ps.rememberIO(actionId, getProviderFactory().getIdentifier(), provider);
return true;
} else {
// error message
log.userError(report.getSummary() + "\nPlease see the report for details.");
return false;
}
} else
return true;
} catch (IOProviderConfigurationException e) {
// user feedback
log.userError("Validation of the provider configuration failed:\n" + e.getLocalizedMessage(), e);
return false;
}
}
use of eu.esdihumboldt.hale.ui.io.action.ActionUI in project hale by halestudio.
the class ActionUIWizardPage method createViewer.
/**
* @see ViewerWizardSelectionPage#createViewer(Composite)
*/
@Override
protected Pair<StructuredViewer, Control> createViewer(Composite parent) {
ListViewer viewer = new ListViewer(parent);
viewer.setLabelProvider(new LabelProvider() {
@Override
public Image getImage(Object element) {
if (element instanceof ActionUIWizardNode) {
return ((ActionUIWizardNode) element).getImage();
}
return super.getImage(element);
}
@Override
public String getText(Object element) {
if (element instanceof ActionUIWizardNode) {
return ((ActionUIWizardNode) element).getActionUI().getDisplayName();
}
return super.getText(element);
}
});
viewer.setContentProvider(ArrayContentProvider.getInstance());
List<ActionUI> list = ActionUIExtension.getInstance().getFactories(filter);
List<ActionUIWizardNode> nodes = new ArrayList<ActionUIWizardNode>();
for (ActionUI action : list) {
nodes.add(new ActionUIWizardNode(action, getContainer()));
}
viewer.setInput(nodes);
return new Pair<StructuredViewer, Control>(viewer, viewer.getControl());
}
use of eu.esdihumboldt.hale.ui.io.action.ActionUI in project hale by halestudio.
the class ResourcesLabelProvider method getImage.
@Override
public Image getImage(Object element) {
if (element instanceof IOAction) {
IOAction action = (IOAction) element;
Image actionImage = actionImages.get(action.getId());
if (actionImage == null) {
ActionUI actionUI = ActionUIExtension.getInstance().findActionUI(action.getId());
URL iconUrl = actionUI.getIconURL();
if (iconUrl != null) {
actionImage = ImageDescriptor.createFromURL(iconUrl).createImage();
actionImages.put(action.getId(), actionImage);
}
}
if (actionImage != null) {
return actionImage;
}
return PlatformUI.getWorkbench().getSharedImages().getImage(ISharedImages.IMG_OBJ_FOLDER);
}
if (element instanceof Resource) {
return PlatformUI.getWorkbench().getSharedImages().getImage(ISharedImages.IMG_OBJ_FILE);
}
if (element instanceof ProjectToken) {
return projectImage;
}
return null;
}
use of eu.esdihumboldt.hale.ui.io.action.ActionUI in project hale by halestudio.
the class RemoveResourceHandler method execute.
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
ISelection selection = HandlerUtil.getCurrentSelection(event);
if (selection != null && !selection.isEmpty() && selection instanceof IStructuredSelection) {
Object element = ((IStructuredSelection) selection).getFirstElement();
if (element instanceof Resource) {
Resource resource = (Resource) element;
// retrieve action UI advisor
ActionUI actionUI = ActionUIExtension.getInstance().findActionUI(resource.getActionId());
if (actionUI != null) {
IOAction action = IOActionExtension.getInstance().get(resource.getActionId());
ActionUIAdvisor<?> advisor = actionUI.getUIAdvisor();
if (advisor != null && advisor.supportsRemoval()) {
String name = null;
if (resource.getSource() != null) {
String location = resource.getSource().toString();
int index = location.lastIndexOf('/');
if (index > 0 && index < location.length()) {
name = location.substring(index + 1);
}
}
String resourceType = null;
if (action != null) {
resourceType = action.getResourceName();
}
if (resourceType == null) {
resourceType = "resource";
}
String message;
if (name == null) {
message = MessageFormat.format("Do you really want to remove this {0}?", resourceType);
} else {
message = MessageFormat.format("Do you really want to remove the {0} {1}?", resourceType, name);
}
if (MessageDialog.openQuestion(HandlerUtil.getActiveShell(event), "Remove resource", message)) {
// do the actual removal
String id = resource.getResourceId();
if (advisor.removeResource(id)) {
// removal succeeded, so remove from project as
// well
ProjectService ps = PlatformUI.getWorkbench().getService(ProjectService.class);
ps.removeResource(id);
}
}
} else {
log.userError("Removing this resource is not supported.");
}
}
}
}
return null;
}
use of eu.esdihumboldt.hale.ui.io.action.ActionUI in project hale by halestudio.
the class ActionUIWizardPage method acceptWizard.
/**
* @see ViewerWizardSelectionPage#acceptWizard(IWizardNode)
*/
@Override
protected String acceptWizard(IWizardNode wizardNode) {
if (wizardNode instanceof ActionUIWizardNode) {
ActionUI actionUI = ((ActionUIWizardNode) wizardNode).getActionUI();
Expression enabledWhen = actionUI.getEnabledWhen();
if (enabledWhen == null) {
return null;
}
IEvaluationService ies = PlatformUI.getWorkbench().getService(IEvaluationService.class);
try {
EvaluationResult evalResult = enabledWhen.evaluate(ies.getCurrentState());
if (evalResult == EvaluationResult.FALSE) {
// disabled
return actionUI.getDisabledReason();
}
// enabled
return null;
} catch (CoreException e) {
String message = "Could not evaluate enabledWhen expression";
log.error(message, e);
return message;
}
}
return super.acceptWizard(wizardNode);
}
Aggregations