Search in sources :

Example 1 with InstanceSampleService

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);
}
Also used : Instance(eu.esdihumboldt.hale.common.instance.model.Instance) ArrayList(java.util.ArrayList) InstanceSampleService(eu.esdihumboldt.hale.ui.service.instance.sample.InstanceSampleService)

Example 2 with InstanceSampleService

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();
}
Also used : AlignmentService(eu.esdihumboldt.hale.ui.service.align.AlignmentService) InstanceSampleService(eu.esdihumboldt.hale.ui.service.instance.sample.InstanceSampleService)

Example 3 with InstanceSampleService

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();
        }
    });
}
Also used : IAction(org.eclipse.jface.action.IAction) Action(org.eclipse.jface.action.Action) Instance(eu.esdihumboldt.hale.common.instance.model.Instance) Observable(java.util.Observable) AlignmentService(eu.esdihumboldt.hale.ui.service.align.AlignmentService) Observer(java.util.Observer) InstanceSampleService(eu.esdihumboldt.hale.ui.service.instance.sample.InstanceSampleService) Collection(java.util.Collection) AlignmentServiceAdapter(eu.esdihumboldt.hale.ui.service.align.AlignmentServiceAdapter) Map(java.util.Map) Cell(eu.esdihumboldt.hale.common.align.model.Cell) IActionBars(org.eclipse.ui.IActionBars) Display(org.eclipse.swt.widgets.Display) Pair(eu.esdihumboldt.util.Pair) HashSet(java.util.HashSet)

Example 4 with InstanceSampleService

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();
        }
    });
}
Also used : Alignment(eu.esdihumboldt.hale.common.align.model.Alignment) AlignmentService(eu.esdihumboldt.hale.ui.service.align.AlignmentService) ArrayList(java.util.ArrayList) InstanceSampleService(eu.esdihumboldt.hale.ui.service.instance.sample.InstanceSampleService) Collection(java.util.Collection) Display(org.eclipse.swt.widgets.Display) Pair(eu.esdihumboldt.util.Pair)

Aggregations

InstanceSampleService (eu.esdihumboldt.hale.ui.service.instance.sample.InstanceSampleService)4 AlignmentService (eu.esdihumboldt.hale.ui.service.align.AlignmentService)3 Instance (eu.esdihumboldt.hale.common.instance.model.Instance)2 Pair (eu.esdihumboldt.util.Pair)2 ArrayList (java.util.ArrayList)2 Collection (java.util.Collection)2 Display (org.eclipse.swt.widgets.Display)2 Alignment (eu.esdihumboldt.hale.common.align.model.Alignment)1 Cell (eu.esdihumboldt.hale.common.align.model.Cell)1 AlignmentServiceAdapter (eu.esdihumboldt.hale.ui.service.align.AlignmentServiceAdapter)1 HashSet (java.util.HashSet)1 Map (java.util.Map)1 Observable (java.util.Observable)1 Observer (java.util.Observer)1 Action (org.eclipse.jface.action.Action)1 IAction (org.eclipse.jface.action.IAction)1 IActionBars (org.eclipse.ui.IActionBars)1