use of eu.esdihumboldt.hale.common.core.io.IOAction in project hale by halestudio.
the class ResourcesContentProvider method getChildren.
@Override
public Object[] getChildren(Object parentElement) {
if (parentElement instanceof ProjectToken) {
return resources.keySet().toArray();
}
if (parentElement instanceof IOAction) {
return resources.get((IOAction) parentElement).toArray();
}
if (parentElement instanceof Resource) {
Resource resource = (Resource) parentElement;
List<Object> children = new ArrayList<>();
// location
if (resource.getSource() != null) {
children.add(resource.getSource());
}
return children.toArray();
}
return null;
}
use of eu.esdihumboldt.hale.common.core.io.IOAction 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;
}
Aggregations