Search in sources :

Example 6 with IOAction

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;
}
Also used : Resource(eu.esdihumboldt.hale.common.core.io.project.model.Resource) ArrayList(java.util.ArrayList) IOAction(eu.esdihumboldt.hale.common.core.io.IOAction)

Example 7 with IOAction

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;
}
Also used : ISelection(org.eclipse.jface.viewers.ISelection) Resource(eu.esdihumboldt.hale.common.core.io.project.model.Resource) ActionUI(eu.esdihumboldt.hale.ui.io.action.ActionUI) ProjectService(eu.esdihumboldt.hale.ui.service.project.ProjectService) IOAction(eu.esdihumboldt.hale.common.core.io.IOAction) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection)

Aggregations

IOAction (eu.esdihumboldt.hale.common.core.io.IOAction)7 Resource (eu.esdihumboldt.hale.common.core.io.project.model.Resource)5 IOAdvisor (eu.esdihumboldt.hale.common.core.io.IOAdvisor)2 ActionUI (eu.esdihumboldt.hale.ui.io.action.ActionUI)2 ProjectService (eu.esdihumboldt.hale.ui.service.project.ProjectService)2 ExportProvider (eu.esdihumboldt.hale.common.core.io.ExportProvider)1 ImportProvider (eu.esdihumboldt.hale.common.core.io.ImportProvider)1 FileIOSupplier (eu.esdihumboldt.hale.common.core.io.supplier.FileIOSupplier)1 IOException (java.io.IOException)1 URL (java.net.URL)1 ArrayList (java.util.ArrayList)1 IContentType (org.eclipse.core.runtime.content.IContentType)1 ISelection (org.eclipse.jface.viewers.ISelection)1 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)1 StyledString (org.eclipse.jface.viewers.StyledString)1 Image (org.eclipse.swt.graphics.Image)1