Search in sources :

Example 1 with PopulationService

use of eu.esdihumboldt.hale.ui.common.service.population.PopulationService 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 PopulationService

use of eu.esdihumboldt.hale.ui.common.service.population.PopulationService 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 PopulationService

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

the class ServiceSchemaExplorer method dispose.

/**
 * Remove all service listeners.
 */
public void dispose() {
    if (schemaListener != null) {
        schemaService.removeSchemaServiceListener(schemaListener);
    }
    if (alignmentListener != null) {
        AlignmentService as = PlatformUI.getWorkbench().getService(AlignmentService.class);
        as.removeListener(alignmentListener);
    }
    if (entityListener != null) {
        EntityDefinitionService eds = PlatformUI.getWorkbench().getService(EntityDefinitionService.class);
        eds.removeListener(entityListener);
    }
    if (geometryListener != null) {
        GeometrySchemaService gss = PlatformUI.getWorkbench().getService(GeometrySchemaService.class);
        gss.removeListener(geometryListener);
    }
    if (populationListener != null) {
        PopulationService ps = PlatformUI.getWorkbench().getService(PopulationService.class);
        ps.removeListener(populationListener);
    }
}
Also used : AlignmentService(eu.esdihumboldt.hale.ui.service.align.AlignmentService) PopulationService(eu.esdihumboldt.hale.ui.common.service.population.PopulationService) GeometrySchemaService(eu.esdihumboldt.hale.ui.geometry.service.GeometrySchemaService) EntityDefinitionService(eu.esdihumboldt.hale.ui.service.entity.EntityDefinitionService)

Example 4 with PopulationService

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

the class OrientInstanceService method doRetransform.

/**
 * @see AbstractInstanceService#doRetransform()
 */
@Override
protected void doRetransform() {
    notifyDatasetAboutToChange(DataSet.TRANSFORMED);
    transformed.clear();
    /*
		 * XXX cause population updated are currently coupled to
		 * StoreInstancesJob/OrientInstanceSink and not to events, we have to
		 * clear the transformed population at this point.
		 */
    PopulationService ps = PlatformUI.getWorkbench().getService(PopulationService.class);
    if (ps != null) {
        ps.resetPopulation(DataSet.TRANSFORMED);
    }
    boolean success = performTransformation();
    if (!success) {
        // there may be some (inconsistent) transformed instances from a
        // canceled transformation
        // disable transformation (will clear transformed instances)
        setTransformationEnabled(false);
        log.userInfo("Live transformation has been disabled.\nYou can again enable it in the main toolbar or in the File menu.");
    } else {
        // notify about transformed instances
        notifyDatasetChanged(DataSet.TRANSFORMED);
    }
}
Also used : PopulationService(eu.esdihumboldt.hale.ui.common.service.population.PopulationService)

Aggregations

PopulationService (eu.esdihumboldt.hale.ui.common.service.population.PopulationService)4 Cardinality (eu.esdihumboldt.hale.common.schema.model.constraint.property.Cardinality)2 Population (eu.esdihumboldt.hale.ui.common.service.population.Population)2 EntityDefinition (eu.esdihumboldt.hale.common.align.model.EntityDefinition)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 GeometrySchemaService (eu.esdihumboldt.hale.ui.geometry.service.GeometrySchemaService)1 AlignmentService (eu.esdihumboldt.hale.ui.service.align.AlignmentService)1 EntityDefinitionService (eu.esdihumboldt.hale.ui.service.entity.EntityDefinitionService)1 BufferedImage (java.awt.image.BufferedImage)1 StyledString (org.eclipse.jface.viewers.StyledString)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