Search in sources :

Example 1 with SchemaSpaceID

use of eu.esdihumboldt.hale.common.schema.SchemaSpaceID in project hale by halestudio.

the class PopulationServiceImpl method addToPopulation.

/**
 * @see PopulationService#addToPopulation(Instance, DataSet)
 */
@Override
public void addToPopulation(Instance instance, DataSet dataSet) {
    SchemaSpaceID schemaSpace;
    if (dataSet != null) {
        switch(dataSet) {
            case TRANSFORMED:
                schemaSpace = SchemaSpaceID.TARGET;
                break;
            case SOURCE:
            default:
                schemaSpace = SchemaSpaceID.SOURCE;
        }
    } else {
        throw new IllegalArgumentException("Invalid data set specified.");
    }
    // count for each Type definitions of instance type
    Collection<? extends TypeEntityDefinition> typeDefinitions = entityDefinitionService.getTypeEntities(instance.getDefinition(), schemaSpace);
    for (TypeEntityDefinition def : typeDefinitions) {
        if (def.getFilter() == null || def.getFilter().match(instance)) {
            increase(def, 1);
            populationCount.addToPopulation(instance, def);
        }
    }
}
Also used : TypeEntityDefinition(eu.esdihumboldt.hale.common.align.model.impl.TypeEntityDefinition) SchemaSpaceID(eu.esdihumboldt.hale.common.schema.SchemaSpaceID)

Example 2 with SchemaSpaceID

use of eu.esdihumboldt.hale.common.schema.SchemaSpaceID in project hale by halestudio.

the class PopulationServiceImpl method resetPopulation.

/**
 * @see PopulationService#resetPopulation(DataSet)
 */
@Override
public void resetPopulation(DataSet dataSet) {
    SchemaSpaceID schemaSpace;
    switch(dataSet) {
        case TRANSFORMED:
            schemaSpace = SchemaSpaceID.TARGET;
            break;
        case SOURCE:
        default:
            schemaSpace = SchemaSpaceID.SOURCE;
    }
    synchronized (this) {
        Map<EntityDefinition, PopulationImpl> population = (schemaSpace == SchemaSpaceID.TARGET) ? (targetPopulation) : (sourcePopulation);
        population.clear();
    }
// XXX rely on dataSetChanged events for update
}
Also used : TypeEntityDefinition(eu.esdihumboldt.hale.common.align.model.impl.TypeEntityDefinition) EntityDefinition(eu.esdihumboldt.hale.common.align.model.EntityDefinition) SchemaSpaceID(eu.esdihumboldt.hale.common.schema.SchemaSpaceID)

Example 3 with SchemaSpaceID

use of eu.esdihumboldt.hale.common.schema.SchemaSpaceID in project hale by halestudio.

the class EntityAccessorUtil method createEntity.

/**
 * Create an entity definition from a path.
 *
 * @param path the path, the topmost element has to represent an
 *            {@link EntityDefinition}, all other elements must represent
 *            {@link ChildContext}s
 * @return the created entity definition or <code>null</code> if the path
 *         was <code>null</code>
 */
public static EntityDefinition createEntity(Path<PathElement> path) {
    if (path == null) {
        return null;
    }
    List<PathElement> elements = new ArrayList<>(path.getElements());
    // create entity definition
    PathElement top = elements.remove(0);
    if (top.getRoot() == null) {
        throw new IllegalArgumentException("Topmost path element must be an entity definition");
    }
    EntityDefinition entity = top.getRoot();
    // collect type information
    TypeDefinition type = entity.getType();
    SchemaSpaceID schemaSpace = entity.getSchemaSpace();
    Filter filter = entity.getFilter();
    List<ChildContext> contextPath = new ArrayList<>(entity.getPropertyPath());
    for (PathElement element : elements) {
        ChildContext cc = element.getChild();
        if (cc == null) {
            throw new IllegalArgumentException("All child elements must be defined by a child context");
        }
        contextPath.add(cc);
    }
    return AlignmentUtil.createEntity(type, contextPath, schemaSpace, filter);
}
Also used : EntityDefinition(eu.esdihumboldt.hale.common.align.model.EntityDefinition) PathElement(eu.esdihumboldt.hale.common.align.groovy.accessor.PathElement) Filter(eu.esdihumboldt.hale.common.instance.model.Filter) ArrayList(java.util.ArrayList) ChildContext(eu.esdihumboldt.hale.common.align.model.ChildContext) SchemaSpaceID(eu.esdihumboldt.hale.common.schema.SchemaSpaceID) TypeDefinition(eu.esdihumboldt.hale.common.schema.model.TypeDefinition)

Example 4 with SchemaSpaceID

use of eu.esdihumboldt.hale.common.schema.SchemaSpaceID in project hale by halestudio.

the class OccurringValuesSection method createControls.

@Override
public void createControls(Composite parent, TabbedPropertySheetPage aTabbedPropertySheetPage) {
    super.createControls(parent, aTabbedPropertySheetPage);
    Composite page = getWidgetFactory().createComposite(parent);
    GridLayoutFactory.swtDefaults().numColumns(2).applyTo(page);
    // refresh button
    refresh = getWidgetFactory().createButton(page, null, SWT.PUSH);
    refresh.setImage(CommonSharedImages.getImageRegistry().get(CommonSharedImages.IMG_REFRESH));
    refresh.setToolTipText("Update the occurring values");
    refresh.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            service.updateOccurringValues((PropertyEntityDefinition) getEntity());
        }
    });
    GridDataFactory.swtDefaults().align(SWT.END, SWT.BEGINNING).grab(false, false).applyTo(refresh);
    // values table
    values = new TableViewer(getWidgetFactory().createTable(page, SWT.MULTI | SWT.BORDER));
    GridDataFactory.fillDefaults().grab(true, true).span(1, 2).applyTo(values.getControl());
    values.setContentProvider(new ArrayContentProvider() {

        @Override
        public Object[] getElements(Object inputElement) {
            if (inputElement instanceof OccurringValues) {
                return ((OccurringValues) inputElement).getValues().entrySet().toArray();
            }
            return new Object[] {};
        }
    });
    values.setLabelProvider(new LabelProvider() {

        @Override
        public String getText(Object element) {
            if (element instanceof Entry) {
                // XXX use styled label provider instead?
                Entry<?> entry = (Entry<?>) element;
                if (entry.getCount() > 1) {
                    return super.getText(entry.getElement()) + "\t(\u00d7" + entry.getCount() + ")";
                } else
                    return super.getText(entry.getElement());
            }
            return super.getText(element);
        }
    });
    values.setInput(null);
    // values context menu
    MenuManager manager = new MenuManager();
    manager.setRemoveAllWhenShown(true);
    manager.addMenuListener(new IMenuListener() {

        @Override
        public void menuAboutToShow(IMenuManager manager) {
            // populate context menu
            // get selection
            ISelection selection = values.getSelection();
            if (!selection.isEmpty() && selection instanceof IStructuredSelection) {
                Object[] sels = ((IStructuredSelection) selection).toArray();
                List<String> values = new ArrayList<String>();
                for (Object sel : sels) {
                    if (sel instanceof Entry<?>) {
                        values.add(((Entry<?>) sel).getElement().toString());
                    }
                }
                if (!values.isEmpty()) {
                    manager.add(new AddConditionAction(getEntity(), values, false));
                    manager.add(new AddParentConditionAction(getEntity(), values, false));
                    if (values.size() > 1) {
                        manager.add(new Separator());
                        manager.add(new AddConditionAction(getEntity(), values, true));
                        manager.add(new AddParentConditionAction(getEntity(), values, true));
                    }
                }
            }
        }
    });
    manager.setRemoveAllWhenShown(true);
    final Menu valuesMenu = manager.createContextMenu(values.getControl());
    values.getControl().setMenu(valuesMenu);
    // copy button
    copy = getWidgetFactory().createButton(page, null, SWT.PUSH);
    copy.setImage(PlatformUI.getWorkbench().getSharedImages().getImage(ISharedImages.IMG_TOOL_COPY));
    copy.setToolTipText("Copy values to the clipboard");
    copy.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            copyToClipboard();
        }
    });
    GridDataFactory.swtDefaults().align(SWT.END, SWT.BEGINNING).grab(false, false).applyTo(copy);
    // add listener to service
    service.addListener(ovlistener = new OccurringValuesListener() {

        @Override
        public void occurringValuesUpdated(PropertyEntityDefinition property) {
            if (property.equals(OccurringValuesSection.this.getEntity())) {
                update();
            }
        }

        @Override
        public void occurringValuesInvalidated(SchemaSpaceID schemaSpace) {
            if (schemaSpace.equals(OccurringValuesSection.this.getEntity().getSchemaSpace())) {
                update();
            }
        }
    });
    update();
}
Also used : IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) Entry(com.google.common.collect.Multiset.Entry) SelectionEvent(org.eclipse.swt.events.SelectionEvent) ISelection(org.eclipse.jface.viewers.ISelection) ArrayList(java.util.ArrayList) List(java.util.List) OccurringValuesListener(eu.esdihumboldt.hale.ui.service.values.OccurringValuesListener) Menu(org.eclipse.swt.widgets.Menu) OccurringValues(eu.esdihumboldt.hale.ui.service.values.OccurringValues) Composite(org.eclipse.swt.widgets.Composite) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) IMenuListener(org.eclipse.jface.action.IMenuListener) SchemaSpaceID(eu.esdihumboldt.hale.common.schema.SchemaSpaceID) PropertyEntityDefinition(eu.esdihumboldt.hale.common.align.model.impl.PropertyEntityDefinition) ArrayContentProvider(org.eclipse.jface.viewers.ArrayContentProvider) MenuManager(org.eclipse.jface.action.MenuManager) IMenuManager(org.eclipse.jface.action.IMenuManager) IMenuManager(org.eclipse.jface.action.IMenuManager) TableViewer(org.eclipse.jface.viewers.TableViewer) LabelProvider(org.eclipse.jface.viewers.LabelProvider) Separator(org.eclipse.jface.action.Separator)

Example 5 with SchemaSpaceID

use of eu.esdihumboldt.hale.common.schema.SchemaSpaceID in project hale by halestudio.

the class EntitiesPage method createEntityGroup.

/**
 * Create an entity group
 *
 * @param ssid the schema space id
 * @param parent the parent composite
 * @return the main group control
 */
protected Control createEntityGroup(SchemaSpaceID ssid, Composite parent) {
    // return another Composite, since the returned Control's layoutData are
    // overwritten.
    Composite holder = new Composite(parent, SWT.NONE);
    holder.setLayout(GridLayoutFactory.fillDefaults().create());
    // Important: Field does rely on DynamicScrolledComposite to be the
    // parent of its parent,
    // because sadly layout(true, true) on the Shell does not seem to
    // propagate to this place.
    ScrolledComposite sc = new DynamicScrolledComposite(holder, SWT.V_SCROLL);
    sc.setExpandHorizontal(true);
    sc.setLayoutData(GridDataFactory.fillDefaults().grab(true, true).hint(200, 200).create());
    Group main = new Group(sc, SWT.NONE);
    sc.setContent(main);
    main.setLayout(GridLayoutFactory.swtDefaults().numColumns(1).margins(10, 5).create());
    // set group title
    switch(ssid) {
        case SOURCE:
            main.setText("Source");
            break;
        case TARGET:
            main.setText("Target");
            break;
    }
    // determine fields
    T function = getWizard().getFunction();
    final Set<? extends D> fields;
    switch(ssid) {
        case SOURCE:
            fields = function.getSource();
            break;
        case TARGET:
            fields = function.getTarget();
            break;
        default:
            fields = new HashSet<D>();
    }
    // create fields
    for (D field : fields) {
        F functionField = createField(ssid, field, main);
        if (functionField != null) {
            functionFields.add(functionField);
            functionField.addObserver(fieldObserver);
        }
    }
    return holder;
}
Also used : DynamicScrolledComposite(eu.esdihumboldt.hale.ui.util.components.DynamicScrolledComposite) Group(org.eclipse.swt.widgets.Group) Composite(org.eclipse.swt.widgets.Composite) DynamicScrolledComposite(eu.esdihumboldt.hale.ui.util.components.DynamicScrolledComposite) ScrolledComposite(org.eclipse.swt.custom.ScrolledComposite) SWT(org.eclipse.swt.SWT) SchemaSpaceID(eu.esdihumboldt.hale.common.schema.SchemaSpaceID) DynamicScrolledComposite(eu.esdihumboldt.hale.ui.util.components.DynamicScrolledComposite) ScrolledComposite(org.eclipse.swt.custom.ScrolledComposite)

Aggregations

SchemaSpaceID (eu.esdihumboldt.hale.common.schema.SchemaSpaceID)7 Composite (org.eclipse.swt.widgets.Composite)3 EntityDefinition (eu.esdihumboldt.hale.common.align.model.EntityDefinition)2 TypeEntityDefinition (eu.esdihumboldt.hale.common.align.model.impl.TypeEntityDefinition)2 TypeDefinition (eu.esdihumboldt.hale.common.schema.model.TypeDefinition)2 SchemaService (eu.esdihumboldt.hale.ui.service.schema.SchemaService)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 Entry (com.google.common.collect.Multiset.Entry)1 PathElement (eu.esdihumboldt.hale.common.align.groovy.accessor.PathElement)1 ChildContext (eu.esdihumboldt.hale.common.align.model.ChildContext)1 PropertyEntityDefinition (eu.esdihumboldt.hale.common.align.model.impl.PropertyEntityDefinition)1 ProjectInfo (eu.esdihumboldt.hale.common.core.io.project.ProjectInfo)1 Resource (eu.esdihumboldt.hale.common.core.io.project.model.Resource)1 DataSet (eu.esdihumboldt.hale.common.instance.model.DataSet)1 Filter (eu.esdihumboldt.hale.common.instance.model.Filter)1 DefinitionAccessor (eu.esdihumboldt.hale.common.schema.groovy.DefinitionAccessor)1 Definition (eu.esdihumboldt.hale.common.schema.model.Definition)1 PropertyDefinition (eu.esdihumboldt.hale.common.schema.model.PropertyDefinition)1 Schema (eu.esdihumboldt.hale.common.schema.model.Schema)1