Search in sources :

Example 36 with AlignmentService

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();
        }
    });
}
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 37 with AlignmentService

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();
        }
    });
}
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)

Example 38 with AlignmentService

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;
}
Also used : EntityDefinition(eu.esdihumboldt.hale.common.align.model.EntityDefinition) Alignment(eu.esdihumboldt.hale.common.align.model.Alignment) AlignmentService(eu.esdihumboldt.hale.ui.service.align.AlignmentService)

Example 39 with AlignmentService

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++);
    }
}
Also used : ActionContributionItem(org.eclipse.jface.action.ActionContributionItem) IAction(org.eclipse.jface.action.IAction) AlignmentService(eu.esdihumboldt.hale.ui.service.align.AlignmentService) IContributionItem(org.eclipse.jface.action.IContributionItem)

Example 40 with AlignmentService

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);
    }
}
Also used : AbstractWizardAction(eu.esdihumboldt.hale.ui.function.contribution.internal.AbstractWizardAction) ActionContributionItem(org.eclipse.jface.action.ActionContributionItem) AlignmentService(eu.esdihumboldt.hale.ui.service.align.AlignmentService) IContributionItem(org.eclipse.jface.action.IContributionItem) ArrayList(java.util.ArrayList) MenuItem(org.eclipse.swt.widgets.MenuItem) Separator(org.eclipse.jface.action.Separator)

Aggregations

AlignmentService (eu.esdihumboldt.hale.ui.service.align.AlignmentService)43 Cell (eu.esdihumboldt.hale.common.align.model.Cell)16 Alignment (eu.esdihumboldt.hale.common.align.model.Alignment)11 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)9 ArrayList (java.util.ArrayList)8 DefaultCell (eu.esdihumboldt.hale.common.align.model.impl.DefaultCell)6 ISelection (org.eclipse.jface.viewers.ISelection)6 EntityDefinition (eu.esdihumboldt.hale.common.align.model.EntityDefinition)5 MutableCell (eu.esdihumboldt.hale.common.align.model.MutableCell)5 AlignmentServiceAdapter (eu.esdihumboldt.hale.ui.service.align.AlignmentServiceAdapter)5 ActionContributionItem (org.eclipse.jface.action.ActionContributionItem)5 IContributionItem (org.eclipse.jface.action.IContributionItem)5 TypeEntityDefinition (eu.esdihumboldt.hale.common.align.model.impl.TypeEntityDefinition)4 CompatibilityService (eu.esdihumboldt.hale.ui.common.service.compatibility.CompatibilityService)4 HashSet (java.util.HashSet)4 Display (org.eclipse.swt.widgets.Display)4 BaseAlignmentCell (eu.esdihumboldt.hale.common.align.model.BaseAlignmentCell)3 IAction (org.eclipse.jface.action.IAction)3 ControlAdapter (org.eclipse.swt.events.ControlAdapter)3 ControlEvent (org.eclipse.swt.events.ControlEvent)3