use of eu.esdihumboldt.hale.ui.service.align.AlignmentService in project hale by halestudio.
the class TransformationView method createViewControl.
/**
* @see eu.esdihumboldt.hale.ui.views.mapping.AbstractMappingView#createViewControl(org.eclipse.swt.widgets.Composite)
*/
@Override
public void createViewControl(Composite parent) {
super.createViewControl(parent);
IActionBars bars = getViewSite().getActionBars();
bars.getToolBarManager().add(instanceAction = new Action("Apply sample instances", IAction.AS_CHECK_BOX) {
@Override
public void run() {
update();
}
});
instanceAction.setImageDescriptor(TransformationViewPlugin.getImageDescriptor("icons/samples.gif"));
instanceAction.setChecked(initInstanceAction);
update();
AlignmentService as = PlatformUI.getWorkbench().getService(AlignmentService.class);
as.addListener(alignmentListener = new AlignmentServiceAdapter() {
@Override
public void alignmentCleared() {
update();
}
@Override
public void cellsRemoved(Iterable<Cell> cells) {
update();
}
@Override
public void cellsReplaced(Map<? extends Cell, ? extends Cell> cells) {
update();
}
@Override
public void cellsAdded(Iterable<Cell> cells) {
update();
}
@Override
public void alignmentChanged() {
update();
}
@Override
public void customFunctionsChanged() {
update();
}
@Override
public void cellsPropertyChanged(Iterable<Cell> cells, String propertyName) {
if (Cell.PROPERTY_DISABLE_FOR.equals(propertyName) || Cell.PROPERTY_ENABLE_FOR.equals(propertyName))
// Could add/remove cells from transformation tree
update();
else {
final Display display = PlatformUI.getWorkbench().getDisplay();
display.syncExec(new Runnable() {
@Override
public void run() {
// refresh view
getViewer().refresh();
}
});
}
}
});
final InstanceSampleService iss = PlatformUI.getWorkbench().getService(InstanceSampleService.class);
iss.addObserver(instanceSampleObserver = new Observer() {
@SuppressWarnings("unchecked")
@Override
public void update(Observable o, Object arg) {
if (!instanceAction.isChecked()) {
return;
}
Object input = getViewer().getInput();
Collection<Instance> oldInstances = null;
int sampleCount = 0;
if (input instanceof Pair<?, ?>) {
Object second = ((Pair<?, ?>) input).getSecond();
if (second instanceof Collection<?>) {
oldInstances = (Collection<Instance>) second;
sampleCount = oldInstances.size();
}
}
Collection<Instance> newSamples = iss.getReferenceInstances();
if (sampleCount == newSamples.size()) {
// still to decide if update is necessary
if (sampleCount == 0) {
return;
}
// check if instances equal?
Set<Instance> test = new HashSet<Instance>(oldInstances);
test.removeAll(newSamples);
if (test.isEmpty()) {
return;
}
}
TransformationView.this.update();
}
});
}
use of eu.esdihumboldt.hale.ui.service.align.AlignmentService in project hale by halestudio.
the class TransformationView method update.
/**
* Set the current alignment
*/
private void update() {
final Display display = PlatformUI.getWorkbench().getDisplay();
// TODO add configuration option if instances should be included?
display.syncExec(new Runnable() {
@Override
public void run() {
AlignmentService as = PlatformUI.getWorkbench().getService(AlignmentService.class);
Alignment alignment = as.getAlignment();
InstanceSampleService iss = PlatformUI.getWorkbench().getService(InstanceSampleService.class);
Collection<Instance> instances = iss.getReferenceInstances();
if (instanceAction.isChecked()) {
if (instances != null && !instances.isEmpty()) {
instances = new ArrayList<Instance>(instances);
// alignment paired with instances as input
getViewer().setInput(new Pair<Object, Object>(alignment, instances));
} else {
getViewer().setInput(null);
}
} else {
// only the alignment as input
getViewer().setInput(alignment);
}
getViewer().applyLayout();
}
});
}
use of eu.esdihumboldt.hale.ui.service.align.AlignmentService in project hale by halestudio.
the class SchemaExplorerLabelProvider method getBackground.
/**
* @see IColorProvider#getBackground(Object)
*/
@Override
public Color getBackground(Object element) {
if (element instanceof EntityDefinition) {
AlignmentService as = PlatformUI.getWorkbench().getService(AlignmentService.class);
Alignment alignment = as.getAlignment();
EntityDefinition entityDef = (EntityDefinition) element;
return getEntityBackground(entityDef, alignment, entityDef.getPropertyPath().isEmpty());
}
return null;
}
use of eu.esdihumboldt.hale.ui.service.align.AlignmentService in project hale by halestudio.
the class AbstractFunctionWizardContribution method fill.
/**
* @see ContributionItem#fill(ToolBar, int)
*/
@Override
public void fill(ToolBar parent, int index) {
AlignmentService alignmentService = PlatformUI.getWorkbench().getService(AlignmentService.class);
for (FunctionWizardDescriptor<?> descriptor : getFunctionWizardDescriptors()) {
IAction action = createWizardAction(descriptor, alignmentService);
IContributionItem item = new ActionContributionItem(action);
item.fill(parent, index++);
}
}
use of eu.esdihumboldt.hale.ui.service.align.AlignmentService in project hale by halestudio.
the class AbstractFunctionWizardContribution method fill.
/**
* @see ContributionItem#fill(Menu, int)
*/
@Override
public void fill(Menu menu, int index) {
boolean added = false;
AlignmentService alignmentService = PlatformUI.getWorkbench().getService(AlignmentService.class);
List<AbstractWizardAction<?>> augmentationActions = new ArrayList<AbstractWizardAction<?>>();
for (FunctionWizardDescriptor<?> descriptor : getFunctionWizardDescriptors()) {
if (!descriptor.getFunction().isAugmentation() || showAugmentations) {
AbstractWizardAction<?> action = createWizardAction(descriptor, alignmentService);
if (action.isActive()) {
if (descriptor.getFunction().isAugmentation()) {
augmentationActions.add(action);
} else {
IContributionItem item = new ActionContributionItem(action);
item.fill(menu, index++);
added = true;
}
}
}
}
if (!augmentationActions.isEmpty()) {
if (added) {
new Separator().fill(menu, index++);
}
// get augmentation target name
// ISelection selection = selectionService.getSelection();
// AlignmentInfo info = null;
//
// if (selection instanceof DefaultSchemaSelection) {
// SchemaSelection schemaSelection = (SchemaSelection) selection;
// info = new SchemaSelectionInfo(schemaSelection, alignmentService);
// }
// else if (selection instanceof CellSelection) {
// CellSelection cellSelection = (CellSelection) selection;
// info = new CellSelectionInfo(cellSelection);
// }
//
String augmentations;
// if (info != null && info.getTargetItemCount() == 1) {
// augmentations = MessageFormat.format(Messages.FunctionWizardContribution_0, info.getFirstTargetItem().getName().getLocalPart());
// }
// else {
augmentations = Messages.FunctionWizardContribution_1;
// }
//
MenuItem augItem = new MenuItem(menu, SWT.PUSH, index++);
augItem.setText(augmentations);
augItem.setEnabled(false);
new Separator().fill(menu, index++);
for (AbstractWizardAction<?> action : augmentationActions) {
IContributionItem item = new ActionContributionItem(action);
item.fill(menu, index++);
added = true;
}
}
if (!added) {
MenuItem item = new MenuItem(menu, SWT.PUSH, index++);
// $NON-NLS-1$
item.setText(Messages.FunctionWizardContribution_2);
item.setEnabled(false);
}
}
Aggregations