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;
}
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();
}
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;
}
}
}
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);
}
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);
}
}
}
}
Aggregations