use of eu.esdihumboldt.hale.ui.selection.SchemaSelection in project hale by halestudio.
the class AlignmentView method createViewControl.
/**
* @see eu.esdihumboldt.hale.ui.views.mapping.AbstractMappingView#createViewControl(org.eclipse.swt.widgets.Composite)
*/
@Override
public void createViewControl(Composite parent) {
Composite page = new Composite(parent, SWT.NONE);
page.setLayout(GridLayoutFactory.fillDefaults().create());
// create type relation selection control
sourceTargetSelector = new SourceTargetTypeSelector(page);
sourceTargetSelector.getControl().setLayoutData(GridDataFactory.swtDefaults().align(SWT.FILL, SWT.CENTER).grab(true, false).create());
sourceTargetSelector.addSelectionChangedListener(new ISelectionChangedListener() {
@Override
public void selectionChanged(SelectionChangedEvent event) {
getViewer().setInput(sourceTargetSelector.getSelectedCell());
if (deactivatedCellFilterAction != null) {
deactivatedCellFilterAction.setEnabled(sourceTargetSelector.isCellSelected());
if (!sourceTargetSelector.isCellSelected())
deactivatedCellFilterAction.setChecked(true);
}
refreshGraph();
}
});
// typeRelations = new ComboViewer(page, SWT.DROP_DOWN | SWT.READ_ONLY);
// typeRelations.setContentProvider(ArrayContentProvider.getInstance());
// typeRelations.setLabelProvider(new LabelProvider() {
//
// @Override
// public Image getImage(Object element) {
// if (element instanceof Cell) {
// // use function image if possible
// Cell cell = (Cell) element;
// String functionId = cell.getTransformationIdentifier();
// AbstractFunction<?> function = FunctionUtil.getFunction(functionId);
// if (function != null) {
// return functionLabels.getImage(function);
// }
// return null;
// }
//
// return super.getImage(element);
// }
//
// @Override
// public String getText(Object element) {
// if (element instanceof Cell) {
// Cell cell = (Cell) element;
//
// return CellUtil.getCellDescription(cell);
// }
//
// return super.getText(element);
// }
//
// });
// typeRelations.addSelectionChangedListener(new ISelectionChangedListener() {
//
// @Override
// public void selectionChanged(SelectionChangedEvent event) {
// updateGraph();
// }
// });
// typeRelations.getControl().setLayoutData(
// GridDataFactory.swtDefaults().align(SWT.FILL, SWT.CENTER).grab(true, false)
// .create());
// create viewer
Composite viewerContainer = new Composite(page, SWT.NONE);
viewerContainer.setLayout(new FillLayout());
viewerContainer.setLayoutData(GridDataFactory.fillDefaults().grab(true, true).create());
super.createViewControl(viewerContainer);
updateLayout(false);
AlignmentService as = PlatformUI.getWorkbench().getService(AlignmentService.class);
// update();
as.addListener(alignmentListener = new AlignmentServiceAdapter() {
@Override
public void alignmentCleared() {
PlatformUI.getWorkbench().getDisplay().syncExec(new Runnable() {
@Override
public void run() {
sourceTargetSelector.setSelection(StructuredSelection.EMPTY);
}
});
}
@Override
public void cellsRemoved(Iterable<Cell> cells) {
if (sourceTargetSelector.isCellSelected() && Iterables.contains(cells, sourceTargetSelector.getSelectedCell()))
sourceTargetSelector.setSelection(StructuredSelection.EMPTY);
refreshGraph();
}
@Override
public void cellsReplaced(Map<? extends Cell, ? extends Cell> cells) {
if (sourceTargetSelector.isCellSelected() && cells.keySet().contains(sourceTargetSelector.getSelectedCell()))
sourceTargetSelector.setSelection(StructuredSelection.EMPTY);
refreshGraph();
}
@Override
public void cellsAdded(Iterable<Cell> cells) {
refreshGraph();
}
@Override
public void alignmentChanged() {
PlatformUI.getWorkbench().getDisplay().syncExec(new Runnable() {
@Override
public void run() {
sourceTargetSelector.setSelection(StructuredSelection.EMPTY);
}
});
}
@Override
public void cellsPropertyChanged(Iterable<Cell> cells, String propertyName) {
refreshGraph();
}
@Override
public void customFunctionsChanged() {
refreshGraph();
}
});
TaskService taskService = PlatformUI.getWorkbench().getService(TaskService.class);
taskService.addListener(tasksListener = new TaskServiceListener() {
@Override
public void tasksRemoved(Iterable<Task<?>> tasks) {
refreshGraph();
}
@Override
public void tasksAdded(Iterable<Task<?>> tasks) {
refreshGraph();
}
@Override
public void taskUserDataChanged(ResolvedTask<?> task) {
refreshGraph();
}
});
// initialize compatibility checkup and display
CompatibilityService cs = PlatformUI.getWorkbench().getService(CompatibilityService.class);
cs.addListener(compListener = new ExclusiveExtensionListener<CompatibilityMode, CompatibilityModeFactory>() {
@Override
public void currentObjectChanged(final CompatibilityMode arg0, final CompatibilityModeFactory arg1) {
refreshGraph();
}
});
// listen on SchemaSelections
getSite().getWorkbenchWindow().getSelectionService().addPostSelectionListener(selectionListener = new ISelectionListener() {
@Override
public void selectionChanged(IWorkbenchPart part, ISelection selection) {
if (!(selection instanceof SchemaSelection)) {
// only react on schema selections
return;
}
if (part != AlignmentView.this) {
updateRelation((SchemaSelection) selection);
}
}
});
// select type cell, if it is double clicked
getViewer().addDoubleClickListener(new IDoubleClickListener() {
@Override
public void doubleClick(DoubleClickEvent event) {
IStructuredSelection selection = (IStructuredSelection) event.getSelection();
if (selection.size() == 1) {
Object selected = selection.getFirstElement();
if (selected instanceof Cell && AlignmentUtil.isTypeCell((Cell) selected))
sourceTargetSelector.setSelection(selection);
}
}
});
// listen on size changes
getViewer().getControl().addControlListener(new ControlAdapter() {
@Override
public void controlResized(ControlEvent e) {
updateLayout(true);
}
});
getViewer().setInput(new DefaultCell());
}
use of eu.esdihumboldt.hale.ui.selection.SchemaSelection in project hale by halestudio.
the class MappingView method createViewControl.
@Override
public void createViewControl(Composite parent) {
super.createViewControl(parent);
updateLayout(false);
getSite().getWorkbenchWindow().getSelectionService().addPostSelectionListener(selectionListener = new ISelectionListener() {
@Override
public void selectionChanged(IWorkbenchPart part, ISelection selection) {
if (!(selection instanceof SchemaSelection)) {
// only react on schema selections
return;
}
if (part != MappingView.this) {
update((SchemaSelection) selection);
}
}
});
AlignmentService as = PlatformUI.getWorkbench().getService(AlignmentService.class);
// update();
as.addListener(alignmentListener = new AlignmentServiceAdapter() {
@Override
public void cellsRemoved(Iterable<Cell> cells) {
updateViewWithCurrentSelection(cells);
}
@Override
public void cellsReplaced(Map<? extends Cell, ? extends Cell> cells) {
List<Cell> changedCells = new ArrayList<Cell>(2);
changedCells.addAll(cells.keySet());
changedCells.addAll(cells.values());
updateViewWithCurrentSelection(changedCells);
}
@Override
public void customFunctionsChanged() {
SchemaSelection current = SchemaSelectionHelper.getSchemaSelection();
if (current != null) {
update(current);
}
}
@Override
public void cellsAdded(Iterable<Cell> cells) {
updateViewWithCurrentSelection(cells);
}
@Override
public void cellsPropertyChanged(Iterable<Cell> cells, String propertyName) {
updateViewWithCurrentSelection(cells);
}
});
TaskService taskService = PlatformUI.getWorkbench().getService(TaskService.class);
taskService.addListener(new TaskServiceListener() {
@Override
public void tasksRemoved(Iterable<Task<?>> tasks) {
updateViewWithCurrentSelection(getAffectedCells(tasks));
}
@Override
public void tasksAdded(Iterable<Task<?>> tasks) {
updateViewWithCurrentSelection(getAffectedCells(tasks));
}
@Override
public void taskUserDataChanged(ResolvedTask<?> task) {
updateViewWithCurrentSelection(getAffectedCells(Collections.singleton(task)));
}
private List<Cell> getAffectedCells(Iterable<Task<?>> tasks) {
List<Cell> affectedCells = new ArrayList<>();
tasks.forEach(t -> {
if (t.getMainContext() instanceof Cell) {
affectedCells.add((Cell) t.getMainContext());
}
});
return affectedCells;
}
});
SchemaSelection current = SchemaSelectionHelper.getSchemaSelection();
if (current != null) {
update(current);
}
// listen on size changes
getViewer().getControl().addControlListener(new ControlAdapter() {
@Override
public void controlResized(ControlEvent e) {
updateLayout(true);
}
});
}
use of eu.esdihumboldt.hale.ui.selection.SchemaSelection in project hale by halestudio.
the class MappingView method createLabelProvider.
@Override
protected IBaseLabelProvider createLabelProvider(GraphViewer viewer) {
return new GraphLabelProvider(viewer, HaleUI.getServiceProvider()) {
@Override
protected boolean isInherited(Cell cell) {
// cannot inherit type cells
if (AlignmentUtil.isTypeCell(cell))
return false;
SchemaSelection selection = SchemaSelectionHelper.getSchemaSelection();
if (selection != null && !selection.isEmpty()) {
DefaultCell dummyTypeCell = new DefaultCell();
ListMultimap<String, Type> sources = ArrayListMultimap.create();
ListMultimap<String, Type> targets = ArrayListMultimap.create();
Pair<Set<EntityDefinition>, Set<EntityDefinition>> items = getDefinitionsFromSelection(selection);
for (EntityDefinition def : items.getFirst()) sources.put(null, new DefaultType(AlignmentUtil.getTypeEntity(def)));
for (EntityDefinition def : items.getSecond()) targets.put(null, new DefaultType(AlignmentUtil.getTypeEntity(def)));
dummyTypeCell.setSource(sources);
dummyTypeCell.setTarget(targets);
return AlignmentUtil.reparentCell(cell, dummyTypeCell, true) != cell;
} else
return false;
}
};
}
use of eu.esdihumboldt.hale.ui.selection.SchemaSelection in project hale by halestudio.
the class SchemasView method createViewControl.
/**
* @see eu.esdihumboldt.hale.ui.views.properties.PropertiesViewPart#createViewControl(org.eclipse.swt.widgets.Composite)
*/
@Override
public void createViewControl(Composite _parent) {
Composite modelComposite = new Composite(_parent, SWT.BEGINNING);
GridLayout layout = new GridLayout(3, false);
layout.verticalSpacing = 3;
layout.horizontalSpacing = 0;
modelComposite.setLayout(layout);
// source schema toolbar, filter and explorer
// sourceExplorer = new SchemaExplorer(modelComposite, "Source");
sourceExplorer = new EntitySchemaExplorer(modelComposite, "Source", SchemaSpaceID.SOURCE);
GridDataFactory.fillDefaults().grab(true, true).hint(400, 10).applyTo(sourceExplorer.getControl());
sourceExplorerManager = new ServiceSchemaExplorer(sourceExplorer, SchemaSpaceID.SOURCE);
// function button
final Button functionButton = new Button(modelComposite, SWT.PUSH | SWT.FLAT);
// $NON-NLS-1$
functionImage = SchemasViewPlugin.getImageDescriptor("icons/mapping.gif").createImage();
// $NON-NLS-1$
augmentImage = SchemasViewPlugin.getImageDescriptor("icons/augment.gif").createImage();
functionButton.setImage(functionImage);
functionButton.setToolTipText(Messages.ModelNavigationView_FunctionButtonToolTipText);
functionButton.setEnabled(false);
functionButton.setLayoutData(new GridData(SWT.CENTER, SWT.CENTER, false, false));
MenuManager manager = new MenuManager();
manager.setRemoveAllWhenShown(true);
final SchemaFunctionContribution functionContribution = new SchemaFunctionContribution();
manager.addMenuListener(new IMenuListener() {
@Override
public void menuAboutToShow(IMenuManager manager) {
// populate context menu
manager.add(functionContribution);
}
});
final Menu functionMenu = manager.createContextMenu(functionButton);
functionButton.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
// show menu on button press
functionMenu.setLocation(Display.getCurrent().getCursorLocation());
functionMenu.setVisible(true);
}
});
// target schema toolbar, filter and explorer
targetExplorer = new EntitySchemaExplorer(modelComposite, "Target", SchemaSpaceID.TARGET);
GridDataFactory.fillDefaults().grab(true, true).hint(400, 10).applyTo(targetExplorer.getControl());
targetExplorerManager = new ServiceSchemaExplorer(targetExplorer, SchemaSpaceID.TARGET);
// source context menu
new ViewerMenu(getSite(), sourceExplorer.getTreeViewer());
// target context menu
new ViewerMenu(getSite(), targetExplorer.getTreeViewer());
// register selection provider
getSite().setSelectionProvider(selectionProvider = new SchemasSelectionProvider());
// listen for selection changes and update function button
selectionProvider.addSelectionChangedListener(new ISelectionChangedListener() {
@Override
public void selectionChanged(SelectionChangedEvent event) {
functionButton.setEnabled(functionContribution.hasActiveFunctions());
if (event.getSelection() instanceof SchemaSelection) {
SchemaSelection selection = (SchemaSelection) event.getSelection();
if (selection.getSourceItems().size() == 0 && selection.getTargetItems().size() > 0) {
// augmentation
functionButton.setImage(augmentImage);
} else {
// function
functionButton.setImage(functionImage);
}
}
}
});
// view toolbar
getViewSite().getActionBars().getToolBarManager().add(cellSyncAction = new CellSyncAction(getSite().getPage().getWorkbenchWindow().getSelectionService(), sourceExplorer, targetExplorer));
}
Aggregations