Search in sources :

Example 1 with InstanceImportWizard

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);
}
Also used : InstanceImportWizard(eu.esdihumboldt.hale.ui.io.instance.InstanceImportWizard) ListViewer(org.eclipse.jface.viewers.ListViewer) Composite(org.eclipse.swt.widgets.Composite) IOConfiguration(eu.esdihumboldt.hale.common.core.io.project.model.IOConfiguration) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) ArrayList(java.util.ArrayList) Resource(eu.esdihumboldt.hale.common.core.io.project.model.Resource) ProjectService(eu.esdihumboldt.hale.ui.service.project.ProjectService) URI(java.net.URI) InvocationTargetException(java.lang.reflect.InvocationTargetException) IRunnableWithProgress(org.eclipse.jface.operation.IRunnableWithProgress) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) Button(org.eclipse.swt.widgets.Button) SelectionEvent(org.eclipse.swt.events.SelectionEvent) HaleWizardDialog(eu.esdihumboldt.hale.ui.util.wizard.HaleWizardDialog)

Aggregations

IOConfiguration (eu.esdihumboldt.hale.common.core.io.project.model.IOConfiguration)1 Resource (eu.esdihumboldt.hale.common.core.io.project.model.Resource)1 InstanceImportWizard (eu.esdihumboldt.hale.ui.io.instance.InstanceImportWizard)1 ProjectService (eu.esdihumboldt.hale.ui.service.project.ProjectService)1 HaleWizardDialog (eu.esdihumboldt.hale.ui.util.wizard.HaleWizardDialog)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 URI (java.net.URI)1 ArrayList (java.util.ArrayList)1 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)1 IRunnableWithProgress (org.eclipse.jface.operation.IRunnableWithProgress)1 ListViewer (org.eclipse.jface.viewers.ListViewer)1 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)1 SelectionEvent (org.eclipse.swt.events.SelectionEvent)1 Button (org.eclipse.swt.widgets.Button)1 Composite (org.eclipse.swt.widgets.Composite)1