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