Search in sources :

Example 6 with HaleWizardDialog

use of eu.esdihumboldt.hale.ui.util.wizard.HaleWizardDialog in project hale by halestudio.

the class NewRelationPage method createViewer.

/**
 * @see ViewerWizardSelectionPage#createViewer(Composite)
 */
@Override
protected Pair<StructuredViewer, Control> createViewer(Composite parent) {
    PatternFilter filter = new PatternFilter();
    filter.setIncludeLeadingWildcard(true);
    FilteredTree tree = new FilteredTree(parent, SWT.SINGLE | SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL, filter, true);
    viewer = tree.getViewer();
    viewer.setContentProvider(new FunctionWizardNodeContentProvider(getContainer(), initialSelection, selectionMatcher));
    viewer.setLabelProvider(new FunctionWizardNodeLabelProvider());
    // no input needed, but we have to set something
    viewer.setInput(Boolean.TRUE);
    // set focus on viewer control to prevent odd behavior
    viewer.getControl().setFocus();
    // expand selection
    viewer.expandAll();
    // selection context
    contextProvider = new HALEContextProvider(viewer, null);
    // help update on page shown
    if (getContainer() instanceof IPageChangeProvider) {
        ((IPageChangeProvider) getContainer()).addPageChangedListener(changeListener = new IPageChangedListener() {

            @Override
            public void pageChanged(PageChangedEvent event) {
                if (event.getSelectedPage() == NewRelationPage.this) {
                    // update the help button
                    if (getContainer() instanceof HaleWizardDialog) {
                        ((HaleWizardDialog) getContainer()).setHelpButtonEnabled(getHelpContext() != null);
                    }
                }
            }
        });
    }
    // help update on selection change
    viewer.addSelectionChangedListener(new ISelectionChangedListener() {

        @Override
        public void selectionChanged(SelectionChangedEvent event) {
            IContext context = getHelpContext();
            // update the help button
            if (getContainer() instanceof HaleWizardDialog) {
                ((HaleWizardDialog) getContainer()).setHelpButtonEnabled(context != null);
            }
            // update the help
            if (context != null) {
                TrayDialog trayDialog = (TrayDialog) getContainer();
                if (trayDialog.getTray() != null) {
                    // if the tray is already open, update the help
                    performHelp();
                }
            }
        }
    });
    // load page configuration
    // XXX would be better if called from outside
    ProjectService ps = PlatformUI.getWorkbench().getService(ProjectService.class);
    restore(ps.getConfigurationService());
    return new Pair<StructuredViewer, Control>(viewer, tree);
}
Also used : PatternFilter(org.eclipse.ui.dialogs.PatternFilter) IContext(org.eclipse.help.IContext) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) IPageChangeProvider(org.eclipse.jface.dialogs.IPageChangeProvider) ProjectService(eu.esdihumboldt.hale.ui.service.project.ProjectService) PageChangedEvent(org.eclipse.jface.dialogs.PageChangedEvent) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) FilteredTree(org.eclipse.ui.dialogs.FilteredTree) TrayDialog(org.eclipse.jface.dialogs.TrayDialog) HALEContextProvider(eu.esdihumboldt.hale.ui.HALEContextProvider) IPageChangedListener(org.eclipse.jface.dialogs.IPageChangedListener) HaleWizardDialog(eu.esdihumboldt.hale.ui.util.wizard.HaleWizardDialog) Pair(eu.esdihumboldt.util.Pair)

Example 7 with HaleWizardDialog

use of eu.esdihumboldt.hale.ui.util.wizard.HaleWizardDialog in project hale by halestudio.

the class IOWizardAction method run.

/**
 * @see Action#run()
 */
@SuppressWarnings({ "unchecked", "rawtypes" })
@Override
public void run() {
    try {
        // retrieve action ID
        final String actionId = getFactory().getActionID();
        // find associated advisor
        IOAdvisor<?> advisor = IOAdvisorExtension.getInstance().findAdvisor(actionId, HaleUI.getServiceProvider());
        checkState(advisor != null, "No advisor for action found");
        // create wizard
        IOWizard<?> wizard = getFactory().createExtensionObject();
        // set advisor and action ID
        ((IOWizard) wizard).setAdvisor(advisor, actionId);
        Shell shell = Display.getCurrent().getActiveShell();
        HaleWizardDialog dialog = new HaleWizardDialog(shell, wizard);
        notifyResult(dialog.open() == Window.OK);
    } catch (Exception e) {
        log.error("Could not launch I/O wizard for advisor " + getFactory().getIdentifier(), e);
    }
}
Also used : Shell(org.eclipse.swt.widgets.Shell) IOWizard(eu.esdihumboldt.hale.ui.io.IOWizard) HaleWizardDialog(eu.esdihumboldt.hale.ui.util.wizard.HaleWizardDialog)

Example 8 with HaleWizardDialog

use of eu.esdihumboldt.hale.ui.util.wizard.HaleWizardDialog in project hale by halestudio.

the class SchemaUpdateComponent method updateSelectedSchema.

/**
 */
protected void updateSelectedSchema() {
    ISelection sel = tableViewer.getSelection();
    if (!sel.isEmpty() && sel instanceof IStructuredSelection) {
        final IOConfiguration selected = (IOConfiguration) ((IStructuredSelection) sel).getFirstElement();
        SchemaImportWizard wizard = new SchemaImportWizard() {

            @Override
            public boolean performFinish() {
                if (!applyConfiguration()) {
                    return false;
                }
                IOConfiguration configuration = new IOConfiguration();
                configuration.setActionId(getActionId());
                configuration.setProviderId(getProviderFactory().getIdentifier());
                getProvider().storeConfiguration(configuration.getProviderConfiguration());
                // replace the previously selected I/O configuration
                int index = configurations.indexOf(selected);
                configurations.set(index, configuration);
                // refresh table viewer to reflect the changes
                tableViewer.refresh(true);
                return true;
            }
        };
        // configure advisor
        // FIXME
        SchemaImportAdvisor advisor = new SchemaImportAdvisor(SchemaSpaceID.TARGET);
        advisor.setServiceProvider(HaleUI.getServiceProvider());
        advisor.setActionId(SchemaIO.ACTION_LOAD_TARGET_SCHEMA);
        wizard.setAdvisor(advisor, actionId);
        // open wizard
        Shell shell = Display.getCurrent().getActiveShell();
        HaleWizardDialog dialog = new HaleWizardDialog(shell, wizard);
        dialog.open();
    }
}
Also used : Shell(org.eclipse.swt.widgets.Shell) SchemaImportAdvisor(eu.esdihumboldt.hale.ui.io.schema.SchemaImportAdvisor) IOConfiguration(eu.esdihumboldt.hale.common.core.io.project.model.IOConfiguration) ISelection(org.eclipse.jface.viewers.ISelection) SchemaImportWizard(eu.esdihumboldt.hale.ui.io.schema.SchemaImportWizard) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) HaleWizardDialog(eu.esdihumboldt.hale.ui.util.wizard.HaleWizardDialog)

Example 9 with HaleWizardDialog

use of eu.esdihumboldt.hale.ui.util.wizard.HaleWizardDialog 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)

Example 10 with HaleWizardDialog

use of eu.esdihumboldt.hale.ui.util.wizard.HaleWizardDialog in project hale by halestudio.

the class FunctionWizardUtil method addRelationForTarget.

/**
 * Launches a wizard for mapping to a specific target entity.
 *
 * @param target the target entity
 * @param source the source entities the target should be mapped from, or
 *            <code>null</code>
 * @return the created cell or <code>null</code>
 */
public static Cell addRelationForTarget(EntityDefinition target, Iterable<EntityDefinition> source) {
    DefaultSchemaSelection initialSelection = new DefaultSchemaSelection();
    initialSelection.addTargetItem(target);
    if (source != null) {
        for (EntityDefinition sourceEntity : source) {
            initialSelection.addSourceItem(sourceEntity);
        }
    }
    SchemaSelectionFunctionMatcher selectionMatcher;
    if (source == null) {
        // ignore source
        selectionMatcher = new SchemaSelectionFunctionMatcher(true, false);
    } else {
        // respect source
        selectionMatcher = new SchemaSelectionFunctionMatcher(false, false);
    }
    NewRelationWizard wizard = new NewRelationWizard(initialSelection, selectionMatcher);
    wizard.setWindowTitle("Map to " + target.getDefinition().getDisplayName());
    Shell shell = Display.getCurrent().getActiveShell();
    HaleWizardDialog dialog = new HaleWizardDialog(shell, wizard);
    if (dialog.open() == Window.OK) {
        return wizard.getCreatedCell();
    } else {
        return null;
    }
}
Also used : EntityDefinition(eu.esdihumboldt.hale.common.align.model.EntityDefinition) Shell(org.eclipse.swt.widgets.Shell) DefaultSchemaSelection(eu.esdihumboldt.hale.ui.selection.impl.DefaultSchemaSelection) NewRelationWizard(eu.esdihumboldt.hale.ui.function.internal.NewRelationWizard) SchemaSelectionFunctionMatcher(eu.esdihumboldt.hale.ui.function.contribution.SchemaSelectionFunctionMatcher) HaleWizardDialog(eu.esdihumboldt.hale.ui.util.wizard.HaleWizardDialog)

Aggregations

HaleWizardDialog (eu.esdihumboldt.hale.ui.util.wizard.HaleWizardDialog)18 Shell (org.eclipse.swt.widgets.Shell)6 MutableCell (eu.esdihumboldt.hale.common.align.model.MutableCell)3 ISelection (org.eclipse.jface.viewers.ISelection)3 ISelectionChangedListener (org.eclipse.jface.viewers.ISelectionChangedListener)3 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)3 SelectionChangedEvent (org.eclipse.jface.viewers.SelectionChangedEvent)3 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)3 SelectionEvent (org.eclipse.swt.events.SelectionEvent)3 Composite (org.eclipse.swt.widgets.Composite)3 IOConfiguration (eu.esdihumboldt.hale.common.core.io.project.model.IOConfiguration)2 HaleWizardPage (eu.esdihumboldt.hale.ui.HaleWizardPage)2 FunctionWizard (eu.esdihumboldt.hale.ui.function.FunctionWizard)2 AlignmentService (eu.esdihumboldt.hale.ui.service.align.AlignmentService)2 ProjectService (eu.esdihumboldt.hale.ui.service.project.ProjectService)2 IPageChangingListener (org.eclipse.jface.dialogs.IPageChangingListener)2 PageChangingEvent (org.eclipse.jface.dialogs.PageChangingEvent)2 TypeFunction (eu.esdihumboldt.hale.common.align.extension.function.TypeFunction)1 Cell (eu.esdihumboldt.hale.common.align.model.Cell)1 EntityDefinition (eu.esdihumboldt.hale.common.align.model.EntityDefinition)1