Search in sources :

Example 1 with IOAction

use of eu.esdihumboldt.hale.common.core.io.IOAction 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;
}
Also used : Resource(eu.esdihumboldt.hale.common.core.io.project.model.Resource) ActionUI(eu.esdihumboldt.hale.ui.io.action.ActionUI) IOAction(eu.esdihumboldt.hale.common.core.io.IOAction) Image(org.eclipse.swt.graphics.Image) URL(java.net.URL)

Example 2 with IOAction

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

the class ResourcesLabelProvider method getText.

@Override
public String getText(Object element) {
    if (element instanceof ProjectToken) {
        ProjectService ps = PlatformUI.getWorkbench().getService(ProjectService.class);
        String name = ps.getProjectInfo().getName();
        if (name == null) {
            return "<Unnamed project>";
        }
        return name;
    }
    if (element instanceof IOAction) {
        IOAction action = (IOAction) element;
        // resource category name
        if (action.getResourceCategoryName() != null) {
            return action.getResourceCategoryName();
        }
        // action name
        if (action.getName() != null) {
            return action.getName();
        }
        // action ID
        return action.getId();
    }
    if (element instanceof Resource) {
        Resource resource = (Resource) element;
        if (resource.getSource() != null) {
            String location = resource.getSource().toString();
            int index = location.lastIndexOf('/');
            if (index > 0 && index < location.length()) {
                return location.substring(index + 1);
            } else {
                return location;
            }
        }
        return resource.getResourceId();
    }
    if (element instanceof IContentType) {
        IContentType ct = (IContentType) element;
        return ct.getName();
    }
    return element.toString();
}
Also used : Resource(eu.esdihumboldt.hale.common.core.io.project.model.Resource) ProjectService(eu.esdihumboldt.hale.ui.service.project.ProjectService) IOAction(eu.esdihumboldt.hale.common.core.io.IOAction) IContentType(org.eclipse.core.runtime.content.IContentType) StyledString(org.eclipse.jface.viewers.StyledString)

Example 3 with IOAction

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

the class ActionProjectFile method apply.

/**
 * @see ProjectFile#apply()
 */
@SuppressWarnings("unchecked")
@Override
public void apply() {
    if (applyFile == null) {
        return;
    }
    try {
        // load the temporary file using an ImportProvider
        LocatableInputSupplier<? extends InputStream> tmpIn = new FileIOSupplier(applyFile);
        // get the action
        IOAction action = IOActionExtension.getInstance().get(loadActionId);
        checkState(ImportProvider.class.isAssignableFrom(action.getProviderType()), "Load action not compatible to ImportProvider");
        // try specified provider
        ImportProvider provider = null;
        if (loadProviderId != null) {
            try {
                provider = (ImportProvider) HaleIO.createIOProvider(action.getProviderType(), null, loadProviderId);
            } catch (Exception e) {
                // ignore
                log.error("Could not get specified import provider, trying auto-detection instead", e);
            }
        }
        // find provider if necessary
        if (provider == null) {
            provider = (ImportProvider) HaleIO.findIOProvider(action.getProviderType(), tmpIn, null);
        }
        if (provider == null) {
            throw new IllegalStateException("No provider for loading project file found (Action ID " + action.getId() + ")");
        }
        // find advisor
        @SuppressWarnings("rawtypes") IOAdvisor advisor = getLoadAdvisor(loadActionId, serviceProvider);
        checkState(advisor != null, "No advisor for loading project file found");
        // configure provider
        // set given parameters
        setParameters(provider, loadParameters);
        // set source
        provider.setSource(tmpIn);
        // execute the provider
        executeProvider(provider, advisor);
    } catch (Exception e) {
        // project file apply fails currently are one logged (the project
        // reader is not involved with it)
        log.error("Error applying loaded project file", e);
    } finally {
        if (!applyFile.delete()) {
            applyFile.deleteOnExit();
            applyFile = null;
        }
    }
}
Also used : IOAdvisor(eu.esdihumboldt.hale.common.core.io.IOAdvisor) ImportProvider(eu.esdihumboldt.hale.common.core.io.ImportProvider) FileIOSupplier(eu.esdihumboldt.hale.common.core.io.supplier.FileIOSupplier) IOAction(eu.esdihumboldt.hale.common.core.io.IOAction) IOException(java.io.IOException)

Example 4 with IOAction

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

the class ActionProjectFile method store.

/**
 * @see ProjectFile#store(LocatableOutputSupplier)
 */
@SuppressWarnings("unchecked")
@Override
public void store(final LocatableOutputSupplier<OutputStream> target) throws Exception {
    // get the action
    IOAction action = IOActionExtension.getInstance().get(saveActionId);
    checkState(ExportProvider.class.isAssignableFrom(action.getProviderType()), "Save action not compatible to ExportProvider");
    // get specified provider
    ExportProvider provider = (ExportProvider) HaleIO.createIOProvider(action.getProviderType(), null, saveProviderId);
    if (provider == null) {
        throw new IllegalStateException("No provider for saving project file found");
    }
    // find advisor
    @SuppressWarnings("rawtypes") IOAdvisor advisor = advisorRegister.findAdvisor(saveActionId, serviceProvider);
    checkState(advisor != null, "No advisor for saving project file found");
    // configure provider
    // set given parameters
    setParameters(provider, saveParameters);
    // set target
    provider.setTarget(target);
    // execute the provider -> error is propagated outside (so project
    // writer knows of it)
    executeProvider(provider, advisor);
}
Also used : IOAdvisor(eu.esdihumboldt.hale.common.core.io.IOAdvisor) IOAction(eu.esdihumboldt.hale.common.core.io.IOAction) ExportProvider(eu.esdihumboldt.hale.common.core.io.ExportProvider)

Example 5 with IOAction

use of eu.esdihumboldt.hale.common.core.io.IOAction 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)

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