Search in sources :

Example 1 with Classification

use of eu.esdihumboldt.hale.common.schema.Classification 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 Classification

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

the class ClassificationFilter method select.

/**
 * @see ViewerFilter#select(Viewer, Object, Object)
 */
@Override
public boolean select(Viewer viewer, Object parentElement, Object element) {
    if (element instanceof TreePath) {
        element = ((TreePath) element).getLastSegment();
    }
    if (element instanceof EntityDefinition) {
        element = ((EntityDefinition) element).getDefinition();
    }
    if (hidden.isEmpty() || !(element instanceof Definition<?>)) {
        // fast exit
        return true;
    }
    Definition<?> def = (Definition<?>) element;
    Classification clazz = Classification.getClassification(def);
    return !hidden.contains(clazz);
}
Also used : EntityDefinition(eu.esdihumboldt.hale.common.align.model.EntityDefinition) TreePath(org.eclipse.jface.viewers.TreePath) Classification(eu.esdihumboldt.hale.common.schema.Classification) EntityDefinition(eu.esdihumboldt.hale.common.align.model.EntityDefinition) Definition(eu.esdihumboldt.hale.common.schema.model.Definition)

Aggregations

Classification (eu.esdihumboldt.hale.common.schema.Classification)2 EntityDefinition (eu.esdihumboldt.hale.common.align.model.EntityDefinition)1 DataSet (eu.esdihumboldt.hale.common.instance.model.DataSet)1 Definition (eu.esdihumboldt.hale.common.schema.model.Definition)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 Cardinality (eu.esdihumboldt.hale.common.schema.model.constraint.property.Cardinality)1 Population (eu.esdihumboldt.hale.ui.common.service.population.Population)1 PopulationService (eu.esdihumboldt.hale.ui.common.service.population.PopulationService)1 BufferedImage (java.awt.image.BufferedImage)1 TreePath (org.eclipse.jface.viewers.TreePath)1 GC (org.eclipse.swt.graphics.GC)1 Image (org.eclipse.swt.graphics.Image)1 ImageData (org.eclipse.swt.graphics.ImageData)1