use of eu.esdihumboldt.hale.ui.service.instance.sample.InstanceSampleService in project hale by halestudio.
the class SourceDataView method onSelectionChange.
/**
* @see AbstractDataView#onSelectionChange(Iterable)
*/
@Override
protected void onSelectionChange(Iterable<Instance> selection) {
InstanceSampleService rss = PlatformUI.getWorkbench().getService(InstanceSampleService.class);
List<Instance> res = new ArrayList<Instance>();
if (selection != null) {
for (Instance instance : selection) {
res.add(instance);
}
}
rss.setReferenceInstances(res);
}
use of eu.esdihumboldt.hale.ui.service.instance.sample.InstanceSampleService in project hale by halestudio.
the class TransformationView method dispose.
/**
* @see WorkbenchPart#dispose()
*/
@Override
public void dispose() {
if (alignmentListener != null) {
AlignmentService as = PlatformUI.getWorkbench().getService(AlignmentService.class);
as.removeListener(alignmentListener);
}
if (instanceSampleObserver != null) {
InstanceSampleService iss = PlatformUI.getWorkbench().getService(InstanceSampleService.class);
iss.deleteObserver(instanceSampleObserver);
}
super.dispose();
}
use of eu.esdihumboldt.hale.ui.service.instance.sample.InstanceSampleService 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.instance.sample.InstanceSampleService 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();
}
});
}
Aggregations