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;
}
}
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);
}
}
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;
}
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;
}
Aggregations