Search in sources :

Example 1 with Population

use of eu.esdihumboldt.hale.ui.common.service.population.Population in project hale by halestudio.

the class DefinitionImages method getImage.

/**
 * Get the image for the given definition
 *
 * @param entityDef the entity definition, may be <code>null</code>
 * @param def the definition
 * @return the image, may be <code>null</code>
 */
protected Image getImage(EntityDefinition entityDef, Definition<?> def) {
    Classification clazz = Classification.getClassification(def);
    String imageName = getImageForClassification(clazz);
    // retrieve image for key
    Image image;
    if (imageName == null) {
        // default
        imageName = ISharedImages.IMG_OBJ_ELEMENT;
        image = PlatformUI.getWorkbench().getSharedImages().getImage(imageName);
    } else {
        image = CommonSharedImages.getImageRegistry().get(imageName);
    }
    // XXX not supported yet
    if (def instanceof TypeDefinition && !((TypeDefinition) def).getConstraint(AbstractFlag.class).isEnabled() && hasGeometry((TypeDefinition) def)) {
        TypeDefinition type = (TypeDefinition) def;
        DataSet dataSet = DataSet.SOURCE;
        // defined styles
        if (entityDef != null) {
            dataSet = DataSet.forSchemaSpace(entityDef.getSchemaSpace());
        }
        String typeKey = dataSet.name() + "::" + type.getIdentifier();
        // XXX check if style image is already there?
        // XXX how to handle style changes?
        BufferedImage img = getLegendImage(type, dataSet, true);
        if (img != null) {
            // replace image with style image
            ImageData imgData = SwingRcpUtilities.convertToSWT(img);
            image = new Image(Display.getCurrent(), imgData);
            final Image old;
            if (styleImages.containsKey(typeKey)) {
                old = styleImages.get(typeKey);
            } else {
                old = null;
            }
            styleImages.put(typeKey, image);
            if (old != null) {
                // schedule image to be disposed when there are no
                // references to it
                handles.addReference(image);
            }
        }
    } else // check for inline attributes
    {
        boolean attribute = (def instanceof PropertyDefinition) && ((PropertyDefinition) def).getConstraint(XmlAttributeFlag.class).isEnabled();
        boolean mandatory = false;
        if (!suppressMandatory) {
            if (def instanceof PropertyDefinition) {
                Cardinality cardinality = ((PropertyDefinition) def).getConstraint(Cardinality.class);
                mandatory = cardinality.getMinOccurs() > 0 && !((PropertyDefinition) def).getConstraint(NillableFlag.class).isEnabled();
            } else if (def instanceof GroupPropertyDefinition) {
                Cardinality cardinality = ((GroupPropertyDefinition) def).getConstraint(Cardinality.class);
                mandatory = cardinality.getMinOccurs() > 0;
            }
        }
        boolean deflt = false;
        boolean faded = false;
        if (entityDef != null) {
            // entity definition needed to determine if item is a default
            // geometry
            deflt = DefaultGeometryUtil.isDefaultGeometry(entityDef);
            // and to determine population
            PopulationService ps = PlatformUI.getWorkbench().getService(PopulationService.class);
            if (ps != null && ps.hasPopulation(entityDef.getSchemaSpace())) {
                Population pop = ps.getPopulation(entityDef);
                faded = (pop != null && pop.getOverallCount() == 0);
            }
        }
        if (deflt || mandatory || attribute || faded) {
            // overlayed image
            ImageConf conf = new ImageConf(imageName, attribute, deflt, mandatory, faded);
            Image overlayedImage = overlayedImages.get(conf);
            if (overlayedImage == null) {
                // apply overlays to image
                Image copy = new Image(image.getDevice(), image.getBounds());
                // draw on image
                GC gc = new GC(copy);
                try {
                    gc.drawImage(image, 0, 0);
                    if (attribute) {
                        gc.drawImage(attribOverlay, 0, 0);
                    }
                    if (deflt) {
                        gc.drawImage(defOverlay, 0, 0);
                    }
                    if (mandatory) {
                        gc.drawImage(mandatoryOverlay, 0, 0);
                    }
                } finally {
                    gc.dispose();
                }
                if (faded) {
                    ImageData imgData = copy.getImageData();
                    imgData.alpha = 150;
                    Image copy2 = new Image(image.getDevice(), imgData);
                    copy.dispose();
                    copy = copy2;
                }
                image = copy;
                overlayedImages.put(conf, copy);
            } else {
                image = overlayedImage;
            }
        }
    }
    return image;
}
Also used : GroupPropertyDefinition(eu.esdihumboldt.hale.common.schema.model.GroupPropertyDefinition) Cardinality(eu.esdihumboldt.hale.common.schema.model.constraint.property.Cardinality) DataSet(eu.esdihumboldt.hale.common.instance.model.DataSet) Image(org.eclipse.swt.graphics.Image) BufferedImage(java.awt.image.BufferedImage) GroupPropertyDefinition(eu.esdihumboldt.hale.common.schema.model.GroupPropertyDefinition) PropertyDefinition(eu.esdihumboldt.hale.common.schema.model.PropertyDefinition) BufferedImage(java.awt.image.BufferedImage) TypeDefinition(eu.esdihumboldt.hale.common.schema.model.TypeDefinition) ImageData(org.eclipse.swt.graphics.ImageData) Classification(eu.esdihumboldt.hale.common.schema.Classification) PopulationService(eu.esdihumboldt.hale.ui.common.service.population.PopulationService) Population(eu.esdihumboldt.hale.ui.common.service.population.Population) GC(org.eclipse.swt.graphics.GC)

Example 2 with Population

use of eu.esdihumboldt.hale.ui.common.service.population.Population in project hale by halestudio.

the class StyledDefinitionLabelProvider method update.

/**
 * @see StyledCellLabelProvider#update(ViewerCell)
 */
@Override
public void update(ViewerCell cell) {
    Object element = cell.getElement();
    element = extractElement(element);
    StyledString text = new StyledString(defaultLabels.getText(element));
    cell.setImage(defaultLabels.getImage(element));
    String contextText = null;
    String countText = null;
    if (element instanceof EntityDefinition) {
        PopulationService ps = PlatformUI.getWorkbench().getService(PopulationService.class);
        if (ps != null) {
            Population pop = ps.getPopulation((EntityDefinition) element);
            int count = pop.getOverallCount();
            int parents = pop.getParentsCount();
            switch(count) {
                case Population.UNKNOWN:
                    countText = "\u00d7?";
                    break;
                case 0:
                    break;
                default:
                    countText = "\u00d7" + count;
                    if (parents != count) {
                        countText += " (" + parents + ")";
                    }
            }
        }
        contextText = AlignmentUtil.getContextText((EntityDefinition) element);
        element = ((EntityDefinition) element).getDefinition();
    }
    // append cardinality
    if (!suppressCardinality && element instanceof ChildDefinition<?>) {
        Cardinality cardinality = null;
        if (((ChildDefinition<?>) element).asGroup() != null) {
            cardinality = ((ChildDefinition<?>) element).asGroup().getConstraint(Cardinality.class);
        } else if (((ChildDefinition<?>) element).asProperty() != null) {
            cardinality = ((ChildDefinition<?>) element).asProperty().getConstraint(Cardinality.class);
        }
        if (cardinality != null) {
            // only append cardinality if it isn't 1/1
            if (cardinality.getMinOccurs() != 1 || cardinality.getMaxOccurs() != 1) {
                String card = " " + MessageFormat.format("({0}..{1})", new Object[] { Long.valueOf(cardinality.getMinOccurs()), (cardinality.getMaxOccurs() == Cardinality.UNBOUNDED) ? ("n") : (Long.valueOf(cardinality.getMaxOccurs())) });
                text.append(card, StyledString.COUNTER_STYLER);
            }
        }
    }
    if (contextText != null) {
        contextText = " " + contextText;
        text.append(contextText, StyledString.DECORATIONS_STYLER);
    }
    if (countText != null) {
        countText = " " + countText;
        text.append(countText, StyledString.QUALIFIER_STYLER);
    }
    cell.setText(text.toString());
    cell.setStyleRanges(text.getStyleRanges());
    Color foreground = getForeground(cell.getElement());
    cell.setForeground(foreground);
    Color background = getBackground(cell.getElement());
    cell.setBackground(background);
    super.update(cell);
}
Also used : EntityDefinition(eu.esdihumboldt.hale.common.align.model.EntityDefinition) Cardinality(eu.esdihumboldt.hale.common.schema.model.constraint.property.Cardinality) Color(org.eclipse.swt.graphics.Color) PopulationService(eu.esdihumboldt.hale.ui.common.service.population.PopulationService) ChildDefinition(eu.esdihumboldt.hale.common.schema.model.ChildDefinition) Population(eu.esdihumboldt.hale.ui.common.service.population.Population) StyledString(org.eclipse.jface.viewers.StyledString) StyledString(org.eclipse.jface.viewers.StyledString)

Example 3 with Population

use of eu.esdihumboldt.hale.ui.common.service.population.Population in project hale by halestudio.

the class UnpopulatedPropertiesFilter method select.

/**
 * @see ViewerFilter#select(Viewer, Object, Object)
 */
@Override
public boolean select(Viewer viewer, Object parentElement, Object element) {
    if (ps != null) {
        if (element instanceof TreePath) {
            element = ((TreePath) element).getLastSegment();
        }
        if (element instanceof EntityDefinition) {
            EntityDefinition entityDef = (EntityDefinition) element;
            if (filterOnlyPopulatedTypes) {
                TypeEntityDefinition type = AlignmentUtil.getTypeEntity(entityDef);
                int typeCount = ps.getPopulation(type).getOverallCount();
                if (typeCount == 0 || typeCount == Population.UNKNOWN) {
                    // all
                    return true;
                }
            }
            if (!entityDef.getPropertyPath().isEmpty() && // only filter properties
            ps.hasPopulation(entityDef.getSchemaSpace())) {
                // only filter if there is a population
                Population pop = ps.getPopulation(entityDef);
                return pop != null && pop.getOverallCount() != 0;
            }
        }
    }
    return true;
}
Also used : TypeEntityDefinition(eu.esdihumboldt.hale.common.align.model.impl.TypeEntityDefinition) EntityDefinition(eu.esdihumboldt.hale.common.align.model.EntityDefinition) TypeEntityDefinition(eu.esdihumboldt.hale.common.align.model.impl.TypeEntityDefinition) TreePath(org.eclipse.jface.viewers.TreePath) Population(eu.esdihumboldt.hale.ui.common.service.population.Population)

Aggregations

Population (eu.esdihumboldt.hale.ui.common.service.population.Population)3 EntityDefinition (eu.esdihumboldt.hale.common.align.model.EntityDefinition)2 Cardinality (eu.esdihumboldt.hale.common.schema.model.constraint.property.Cardinality)2 PopulationService (eu.esdihumboldt.hale.ui.common.service.population.PopulationService)2 TypeEntityDefinition (eu.esdihumboldt.hale.common.align.model.impl.TypeEntityDefinition)1 DataSet (eu.esdihumboldt.hale.common.instance.model.DataSet)1 Classification (eu.esdihumboldt.hale.common.schema.Classification)1 ChildDefinition (eu.esdihumboldt.hale.common.schema.model.ChildDefinition)1 GroupPropertyDefinition (eu.esdihumboldt.hale.common.schema.model.GroupPropertyDefinition)1 PropertyDefinition (eu.esdihumboldt.hale.common.schema.model.PropertyDefinition)1 TypeDefinition (eu.esdihumboldt.hale.common.schema.model.TypeDefinition)1 BufferedImage (java.awt.image.BufferedImage)1 StyledString (org.eclipse.jface.viewers.StyledString)1 TreePath (org.eclipse.jface.viewers.TreePath)1 Color (org.eclipse.swt.graphics.Color)1 GC (org.eclipse.swt.graphics.GC)1 Image (org.eclipse.swt.graphics.Image)1 ImageData (org.eclipse.swt.graphics.ImageData)1