Search in sources :

Example 6 with Resource

use of eu.esdihumboldt.hale.common.core.io.project.model.Resource in project hale by halestudio.

the class ResourcesView method createViewControl.

@Override
protected void createViewControl(Composite parent) {
    viewer = new TreeViewer(parent);
    viewer.setContentProvider(new ResourcesContentProvider());
    viewer.setLabelProvider(new ResourcesLabelProvider());
    ProjectService ps = PlatformUI.getWorkbench().getService(ProjectService.class);
    ps.addListener(projectServiceListener = new ProjectServiceAdapter() {

        @Override
        public void resourceAdded(String actionId, Resource resource) {
            updateInDisplayThread();
        }

        @Override
        public void resourcesRemoved(String actionId, List<Resource> resources) {
            updateInDisplayThread();
        }

        @Override
        public void afterLoad(ProjectService projectService) {
            updateInDisplayThread();
        }

        @Override
        public void projectInfoChanged(ProjectInfo info) {
            PlatformUI.getWorkbench().getDisplay().syncExec(new Runnable() {

                @Override
                public void run() {
                    viewer.update(ProjectToken.TOKEN, null);
                }
            });
        }
    });
    viewer.setUseHashlookup(true);
    viewer.setAutoExpandLevel(3);
    update();
    new ViewerMenu(getSite(), viewer);
    getSite().setSelectionProvider(viewer);
}
Also used : ProjectServiceAdapter(eu.esdihumboldt.hale.ui.service.project.ProjectServiceAdapter) TreeViewer(org.eclipse.jface.viewers.TreeViewer) ResourcesLabelProvider(eu.esdihumboldt.hale.ui.views.resources.internal.ResourcesLabelProvider) Resource(eu.esdihumboldt.hale.common.core.io.project.model.Resource) ProjectInfo(eu.esdihumboldt.hale.common.core.io.project.ProjectInfo) ProjectService(eu.esdihumboldt.hale.ui.service.project.ProjectService) ResourcesContentProvider(eu.esdihumboldt.hale.ui.views.resources.internal.ResourcesContentProvider) List(java.util.List) ViewerMenu(eu.esdihumboldt.hale.ui.util.viewer.ViewerMenu)

Example 7 with Resource

use of eu.esdihumboldt.hale.common.core.io.project.model.Resource in project hale by halestudio.

the class ResourcesContentProvider method inputChanged.

@SuppressWarnings("unchecked")
@Override
public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
    resources.clear();
    if (newInput instanceof Iterable<?>) {
        for (Resource resource : (Iterable<Resource>) newInput) {
            String actionId = resource.getActionId();
            IOAction action = IOActionExtension.getInstance().get(actionId);
            if (action != null) {
                resources.put(action, resource);
            } else {
                log.warn("Resource is not displayed because action {} was not found", actionId);
            }
        }
    }
}
Also used : Resource(eu.esdihumboldt.hale.common.core.io.project.model.Resource) IOAction(eu.esdihumboldt.hale.common.core.io.IOAction)

Example 8 with Resource

use of eu.esdihumboldt.hale.common.core.io.project.model.Resource 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 9 with Resource

use of eu.esdihumboldt.hale.common.core.io.project.model.Resource in project hale by halestudio.

the class ResourcesLabelProvider method update.

@Override
public void update(ViewerCell cell) {
    Object element = cell.getElement();
    cell.setImage(getImage(element));
    StyledString text = new StyledString(getText(element));
    if (element instanceof Resource) {
        Resource resource = (Resource) element;
        if (resource.getContentType() != null) {
            text.append(" (" + resource.getContentType().getName() + ")", StyledString.DECORATIONS_STYLER);
        }
    }
    cell.setText(text.getString());
    cell.setStyleRanges(text.getStyleRanges());
    super.update(cell);
}
Also used : Resource(eu.esdihumboldt.hale.common.core.io.project.model.Resource) StyledString(org.eclipse.jface.viewers.StyledString)

Example 10 with Resource

use of eu.esdihumboldt.hale.common.core.io.project.model.Resource 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

Resource (eu.esdihumboldt.hale.common.core.io.project.model.Resource)12 IOAction (eu.esdihumboldt.hale.common.core.io.IOAction)5 IOConfiguration (eu.esdihumboldt.hale.common.core.io.project.model.IOConfiguration)5 ProjectService (eu.esdihumboldt.hale.ui.service.project.ProjectService)5 ArrayList (java.util.ArrayList)4 IOConfigurationResource (eu.esdihumboldt.hale.common.core.io.project.model.IOConfigurationResource)3 ActionUI (eu.esdihumboldt.hale.ui.io.action.ActionUI)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)2 URI (java.net.URI)2 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)2 IRunnableWithProgress (org.eclipse.jface.operation.IRunnableWithProgress)2 StyledString (org.eclipse.jface.viewers.StyledString)2 AlignmentType (eu.esdihumboldt.hale.common.align.io.impl.internal.generated.AlignmentType)1 CellType (eu.esdihumboldt.hale.common.align.io.impl.internal.generated.CellType)1 Value (eu.esdihumboldt.hale.common.core.io.Value)1 ProjectInfo (eu.esdihumboldt.hale.common.core.io.project.ProjectInfo)1 LocationUpdater (eu.esdihumboldt.hale.common.core.io.project.util.LocationUpdater)1 ReportFile (eu.esdihumboldt.hale.common.headless.report.ReportFile)1 DataSet (eu.esdihumboldt.hale.common.instance.model.DataSet)1 InstanceCollection (eu.esdihumboldt.hale.common.instance.model.InstanceCollection)1