use of eu.esdihumboldt.hale.ui.service.align.AlignmentService in project hale by halestudio.
the class AlignmentView method menuAboutToShow.
/**
* @see eu.esdihumboldt.hale.ui.views.mapping.AbstractMappingView#menuAboutToShow(org.eclipse.jface.action.IMenuManager)
*/
@Override
protected void menuAboutToShow(IMenuManager manager) {
ISelection cellSelection = getViewer().getSelection();
final Cell typeCell = sourceTargetSelector.getSelectedCell();
// is a type relation selected
if (!sourceTargetSelector.isCellSelected())
return;
// is a cell selected?
if (!(cellSelection instanceof IStructuredSelection) || ((IStructuredSelection) cellSelection).size() != 1 || !(((IStructuredSelection) cellSelection).getFirstElement() instanceof Cell))
return;
final Cell selectedCell = (Cell) ((IStructuredSelection) cellSelection).getFirstElement();
// ignore type cell
if (AlignmentUtil.isTypeCell(selectedCell))
return;
// check current disable status
if (!selectedCell.getDisabledFor().contains(typeCell.getId())) {
manager.add(new Action("Disable") {
/**
* @see org.eclipse.jface.action.Action#run()
*/
@Override
public void run() {
AlignmentService as = PlatformUI.getWorkbench().getService(AlignmentService.class);
as.setCellProperty(selectedCell.getId(), Cell.PROPERTY_DISABLE_FOR, typeCell);
}
});
} else {
manager.add(new Action("Enable") {
/**
* @see org.eclipse.jface.action.Action#run()
*/
@Override
public void run() {
AlignmentService as = PlatformUI.getWorkbench().getService(AlignmentService.class);
as.setCellProperty(selectedCell.getId(), Cell.PROPERTY_ENABLE_FOR, typeCell);
}
/**
* @see org.eclipse.jface.action.Action#isEnabled()
*/
@Override
public boolean isEnabled() {
// Still show the action for clarity.
if (selectedCell instanceof BaseAlignmentCell)
return !((BaseAlignmentCell) selectedCell).getBaseDisabledFor().contains(typeCell.getId());
return true;
}
});
}
}
use of eu.esdihumboldt.hale.ui.service.align.AlignmentService in project hale by halestudio.
the class MappingView method dispose.
/**
* @see WorkbenchPart#dispose()
*/
@Override
public void dispose() {
if (alignmentListener != null) {
AlignmentService as = PlatformUI.getWorkbench().getService(AlignmentService.class);
as.removeListener(alignmentListener);
}
if (selectionListener != null) {
getSite().getWorkbenchWindow().getSelectionService().removePostSelectionListener(selectionListener);
}
super.dispose();
}
use of eu.esdihumboldt.hale.ui.service.align.AlignmentService in project hale by halestudio.
the class MappingView method update.
/**
* Update the view
*
* @param selection the selection
*/
protected void update(SchemaSelection selection) {
AlignmentService as = PlatformUI.getWorkbench().getService(AlignmentService.class);
Alignment alignment = as.getAlignment();
List<Cell> cells = new ArrayList<Cell>();
Pair<Set<EntityDefinition>, Set<EntityDefinition>> items = getDefinitionsFromSelection(selection);
// find cells associated with the selection
for (Cell cell : alignment.getCells()) {
if ((cell.getSource() != null && associatedWith(items.getFirst(), cell)) || associatedWith(items.getSecond(), cell)) {
cells.add(cell);
}
}
getViewer().setInput(cells);
updateLayout(true);
}
use of eu.esdihumboldt.hale.ui.service.align.AlignmentService 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.service.align.AlignmentService in project hale by halestudio.
the class TransformationReportPage method onDoubleClick.
@Override
protected void onDoubleClick(Message m) {
if (m instanceof TransformationMessage) {
TransformationMessage tm = (TransformationMessage) m;
AlignmentService as = PlatformUI.getWorkbench().getService(AlignmentService.class);
if (as != null && as.getAlignment().getCell(tm.getCellId()) != null) {
IWorkbenchWindow activeWindow = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
// pin the property sheet if possible
IViewReference ref = activeWindow.getActivePage().findViewReference(IPageLayout.ID_PROP_SHEET);
if (ref != null) {
IViewPart part = ref.getView(false);
if (part instanceof PropertySheet) {
PropertySheet sheet = (PropertySheet) part;
if (!sheet.isPinned()) {
sheet.setPinned(true);
}
}
}
// show cell in mapping view
try {
IViewPart part = activeWindow.getActivePage().showView(MappingView.ID);
if (part instanceof MappingView) {
((MappingView) part).selectCell(tm.getCellId());
}
} catch (PartInitException e) {
// ignore
}
}
}
super.onDoubleClick(m);
}
Aggregations