use of eu.esdihumboldt.hale.ui.io.instance.InstanceImportWizard 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);
}
Aggregations