use of eu.esdihumboldt.hale.common.core.io.project.model.Resource in project hale by halestudio.
the class TemplateProject method onSuccess.
@Override
protected void onSuccess(Void context, String projectId, File projectFile, Project project, ReportFile reportFile) {
super.onSuccess(context, projectId, projectFile, project, reportFile);
// update locations in project file
LocationUpdater updater = new LocationUpdater(project, projectFile.toURI());
updater.updateProject(false);
resources.clear();
List<Path> invalidSources = new ArrayList<>();
Path projectFolder = getProjectFolder().toPath();
// validate resources
for (IOConfiguration config : project.getResources()) {
Resource resource = new IOConfigurationResource(config, getProjectFile().toURI());
// check if file URIs are valid and inside project folder
URI source = resource.getSource();
if (source != null) {
Path path = null;
if (source.getScheme() == null) {
// is a relative URI
path = projectFile.toPath().resolve(source.toString()).normalize();
} else if ("file".equals(source.getScheme())) {
// is a file URI
path = Paths.get(source).normalize();
}
if (path != null) {
if (!path.startsWith(projectFolder) || !Files.exists(path)) {
// invalid source
invalidSources.add(path);
}
}
}
resources.put(resource.getActionId(), resource);
}
valid = invalidSources.isEmpty();
if (!valid) {
StringBuilder builder = new StringBuilder("Files referenced by the project could not be found: ");
for (int i = 0; i < invalidSources.size(); i++) {
if (i > 0)
builder.append(", ");
Path path = invalidSources.get(i);
builder.append(path.getFileName().toString());
}
notValidMessage = builder.toString();
} else {
notValidMessage = "";
}
// additionally, try to find out cell count
definedRelations = 0;
// check if default alignment file exists
try {
File defAlignmentFile = new File(URI.create(projectFile.toURI().toASCIIString() + "." + AlignmentIO.PROJECT_FILE_ALIGNMENT));
if (defAlignmentFile.exists()) {
try (InputStream in = new BufferedInputStream(new FileInputStream(defAlignmentFile))) {
/*
* Try loading the file with JAXB - only supports 2.6+
* projects.
*/
AlignmentType alignment = JaxbToAlignment.load(in, null);
// XXX ignoring base alignments
int count = 0;
for (Object element : alignment.getCellOrModifier()) {
if (element instanceof CellType) {
count++;
}
}
definedRelations = count;
} catch (Exception e) {
// ignore
}
}
} catch (Exception e) {
// ignore
}
}
use of eu.esdihumboldt.hale.common.core.io.project.model.Resource in project hale by halestudio.
the class ProjectServiceImpl method removeResources.
@Override
public List<? extends Resource> removeResources(String actionId) {
Builder<Resource> removedBuilder = ImmutableList.builder();
synchronized (this) {
Iterator<IOConfiguration> iter = main.getResources().iterator();
while (iter.hasNext()) {
IOConfiguration conf = iter.next();
if (conf.getActionId().equals(actionId)) {
iter.remove();
removedBuilder.add(new IOConfigurationResource(conf, projectLocation));
}
}
}
setChanged();
List<Resource> removedResources = removedBuilder.build();
notifyResourcesRemoved(actionId, removedResources);
return removedResources;
}
use of eu.esdihumboldt.hale.common.core.io.project.model.Resource in project hale by halestudio.
the class TransformDataWizardSourcePage method createControl.
/**
* @see org.eclipse.jface.dialogs.IDialogPage#createControl(org.eclipse.swt.widgets.Composite)
*/
@Override
public void createControl(Composite parent) {
Composite content = new Composite(parent, SWT.NONE);
content.setLayout(GridLayoutFactory.swtDefaults().create());
final ListViewer listViewer = new ListViewer(content);
listViewer.getControl().setLayoutData(GridDataFactory.fillDefaults().grab(true, true).create());
if (!useProjectData) {
Button addButton = new Button(content, SWT.PUSH);
addButton.setText("Add source file");
addButton.setLayoutData(GridDataFactory.swtDefaults().align(SWT.END, SWT.CENTER).create());
addButton.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
InstanceImportWizard importWizard = new InstanceImportWizard();
TransformDataImportAdvisor advisor = new TransformDataImportAdvisor();
// specifying null as actionId results in no call to
// ProjectService.rememberIO
importWizard.setAdvisor(advisor, null);
if (new HaleWizardDialog(getShell(), importWizard).open() == Dialog.OK) {
if (advisor.getInstances() != null) {
sourceCollections.add(advisor.getInstances());
listViewer.add(advisor.getLocation());
getContainer().updateButtons();
}
}
}
});
} else {
// initialize project source data
IRunnableWithProgress op = new IRunnableWithProgress() {
@Override
public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
monitor.beginTask("Prepare data sources", IProgressMonitor.UNKNOWN);
ProjectService ps = PlatformUI.getWorkbench().getService(ProjectService.class);
final List<URI> locations = new ArrayList<>();
for (Resource resource : ps.getResources()) {
if (InstanceIO.ACTION_LOAD_SOURCE_DATA.equals(resource.getActionId())) {
// resource is source data
IOConfiguration conf = resource.copyConfiguration(true);
TransformDataImportAdvisor advisor = new TransformDataImportAdvisor();
ProjectResourcesUtil.executeConfiguration(conf, advisor, false, null);
if (advisor.getInstances() != null) {
sourceCollections.add(advisor.getInstances());
locations.add(advisor.getLocation());
}
}
}
PlatformUI.getWorkbench().getDisplay().syncExec(new Runnable() {
@Override
public void run() {
for (URI location : locations) {
listViewer.add(location);
}
}
});
monitor.done();
}
};
try {
ThreadProgressMonitor.runWithProgressDialog(op, false);
} catch (Exception e) {
throw new IllegalStateException(e);
}
}
setControl(content);
}
use of eu.esdihumboldt.hale.common.core.io.project.model.Resource 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;
ActionUI actionUI = null;
if (resource.getActionId() != null) {
actionUI = ActionUIExtension.getInstance().findActionUI(resource.getActionId());
}
if (actionUI != null && actionUI.getUIAdvisor() != null && actionUI.getUIAdvisor().supportsCustomName()) {
String name = actionUI.getUIAdvisor().getCustomName(resource.getResourceId());
if (name != null) {
return name;
}
}
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.project.model.Resource 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;
}
Aggregations