Search in sources :

Example 1 with DefaultSchemaSelection

use of eu.esdihumboldt.hale.ui.selection.impl.DefaultSchemaSelection 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)

Example 2 with DefaultSchemaSelection

use of eu.esdihumboldt.hale.ui.selection.impl.DefaultSchemaSelection in project hale by halestudio.

the class MapTargetAction method createRelation.

/**
 * Create the relation.
 *
 * @param target the target entity
 * @param source the source entities the target should be mapped from,
 *            <code>null</code> by default
 * @param manager the cheat sheet manager
 * @return the created cell or <code>null</code>
 */
protected Cell createRelation(EntityDefinition target, Iterable<EntityDefinition> source, ICheatSheetManager manager) {
    // try selecting the entities in the schema explorer
    DefaultSchemaSelection ss = new DefaultSchemaSelection();
    ss.addTargetItem(target);
    if (source != null) {
        for (EntityDefinition item : source) {
            ss.addSourceItem(item);
        }
    }
    try {
        IViewPart view = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().findView(SchemasView.ID);
        view.getSite().getSelectionProvider().setSelection(ss);
    } catch (Exception e) {
    // ignore
    }
    // launch the wizard
    if (functionId == null) {
        return FunctionWizardUtil.addRelationForTarget(target, source);
    } else {
        return FunctionWizardUtil.createNewWizard(functionId, ss);
    }
}
Also used : EntityDefinition(eu.esdihumboldt.hale.common.align.model.EntityDefinition) IViewPart(org.eclipse.ui.IViewPart) DefaultSchemaSelection(eu.esdihumboldt.hale.ui.selection.impl.DefaultSchemaSelection)

Example 3 with DefaultSchemaSelection

use of eu.esdihumboldt.hale.ui.selection.impl.DefaultSchemaSelection in project hale by halestudio.

the class ReplaceFunctionWizardContribution method getSelection.

/**
 * @see SchemaSelectionFunctionContribution#getSelection()
 */
@Override
public SchemaSelection getSelection() {
    // derive a schema selection from the cell
    DefaultSchemaSelection sel = new DefaultSchemaSelection();
    Cell orgCell = getOriginalCell();
    if (orgCell != null) {
        if (orgCell.getSource() != null) {
            for (Entity source : getOriginalCell().getSource().values()) {
                sel.addSourceItem(source.getDefinition());
            }
        }
        if (orgCell.getTarget() != null) {
            for (Entity target : getOriginalCell().getTarget().values()) {
                sel.addTargetItem(target.getDefinition());
            }
        }
    }
    return sel;
}
Also used : Entity(eu.esdihumboldt.hale.common.align.model.Entity) DefaultSchemaSelection(eu.esdihumboldt.hale.ui.selection.impl.DefaultSchemaSelection) Cell(eu.esdihumboldt.hale.common.align.model.Cell)

Example 4 with DefaultSchemaSelection

use of eu.esdihumboldt.hale.ui.selection.impl.DefaultSchemaSelection in project hale by halestudio.

the class SchemaSelectionHelper method getSchemaSelection.

/**
 * Get the current schema selection
 *
 * @return the current schema selection or an empty model selection if it
 *         can't be determined
 */
public static SchemaSelection getSchemaSelection() {
    SchemaSelection result = null;
    try {
        ISelectionService ss = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getSelectionService();
        ISelection selection = ss.getSelection();
        if (selection instanceof SchemaSelection) {
            result = (SchemaSelection) selection;
        }
    } catch (Throwable e) {
        log.warn("Could not get current selection", e);
    }
    if (result == null) {
        SelectionTracker tracker = SelectionTrackerUtil.getTracker();
        if (tracker != null) {
            result = tracker.getSelection(SchemaSelection.class);
        }
    }
    if (result == null) {
        result = new DefaultSchemaSelection();
    }
    return result;
}
Also used : SelectionTracker(eu.esdihumboldt.hale.ui.util.selection.SelectionTracker) DefaultSchemaSelection(eu.esdihumboldt.hale.ui.selection.impl.DefaultSchemaSelection) ISelection(org.eclipse.jface.viewers.ISelection) ISelectionService(org.eclipse.ui.ISelectionService) DefaultSchemaSelection(eu.esdihumboldt.hale.ui.selection.impl.DefaultSchemaSelection)

Aggregations

DefaultSchemaSelection (eu.esdihumboldt.hale.ui.selection.impl.DefaultSchemaSelection)4 EntityDefinition (eu.esdihumboldt.hale.common.align.model.EntityDefinition)2 Cell (eu.esdihumboldt.hale.common.align.model.Cell)1 Entity (eu.esdihumboldt.hale.common.align.model.Entity)1 SchemaSelectionFunctionMatcher (eu.esdihumboldt.hale.ui.function.contribution.SchemaSelectionFunctionMatcher)1 NewRelationWizard (eu.esdihumboldt.hale.ui.function.internal.NewRelationWizard)1 SelectionTracker (eu.esdihumboldt.hale.ui.util.selection.SelectionTracker)1 HaleWizardDialog (eu.esdihumboldt.hale.ui.util.wizard.HaleWizardDialog)1 ISelection (org.eclipse.jface.viewers.ISelection)1 Shell (org.eclipse.swt.widgets.Shell)1 ISelectionService (org.eclipse.ui.ISelectionService)1 IViewPart (org.eclipse.ui.IViewPart)1