Search in sources :

Example 11 with PropertyDefinition

use of eu.esdihumboldt.hale.common.schema.model.PropertyDefinition 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 12 with PropertyDefinition

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

the class DefaultDefinitionLabelFactory method createLabel.

/**
 * @see DefinitionLabelFactory#createLabel(Composite, Definition, boolean)
 */
@Override
public Control createLabel(Composite parent, Definition<?> definition, boolean verbose) {
    String name = definition.getDisplayName();
    String description = definition.getDescription();
    if (description != null && !description.isEmpty()) {
        // link for displaying documentation
        // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
        String linkText = "<a href=\"" + definition.getIdentifier() + "\">" + name + "</a>";
        final Map<String, String> tips = new HashMap<String, String>();
        tips.put(definition.getIdentifier(), description);
        if (verbose && definition instanceof PropertyDefinition) {
            TypeDefinition parentType = ((PropertyDefinition) definition).getParentType();
            String typeDescription = parentType.getDescription();
            if (typeDescription != null) {
                tips.put(parentType.getIdentifier(), typeDescription);
                linkText = // $NON-NLS-1$ //$NON-NLS-2$
                "<a href=\"" + parentType.getIdentifier() + "\">" + parentType.getDisplayName() + "</a>." + // $NON-NLS-1$
                linkText;
            } else {
                // $NON-NLS-1$
                linkText = parentType.getDisplayName() + "." + linkText;
            }
        }
        final Link link = new Link(parent, SWT.NONE);
        link.setText(linkText);
        link.addSelectionListener(new SelectionAdapter() {

            private Shell lastShell = null;

            @Override
            public void widgetSelected(SelectionEvent e) {
                // link target is in e.text - but not needed here
                String href = e.text;
                // show tip
                String tip = tips.get(href);
                if (tip != null) {
                    BrowserTip.hideToolTip(lastShell);
                    lastShell = browserTip.showToolTip(link, 0, link.getSize().y, tip);
                }
            }
        });
        return link;
    } else {
        Label label = new Label(parent, SWT.NONE);
        if (verbose && definition instanceof PropertyDefinition) {
            label.setText(((PropertyDefinition) definition).getParentType().getDisplayName() + "." + // $NON-NLS-1$
            name);
        } else {
            label.setText(name);
        }
        return label;
    }
}
Also used : Shell(org.eclipse.swt.widgets.Shell) HashMap(java.util.HashMap) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) SelectionEvent(org.eclipse.swt.events.SelectionEvent) Label(org.eclipse.swt.widgets.Label) PropertyDefinition(eu.esdihumboldt.hale.common.schema.model.PropertyDefinition) Link(org.eclipse.swt.widgets.Link) TypeDefinition(eu.esdihumboldt.hale.common.schema.model.TypeDefinition)

Example 13 with PropertyDefinition

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

the class AssignParameterPage method onShowPage.

/**
 * @see eu.esdihumboldt.hale.ui.HaleWizardPage#onShowPage(boolean)
 */
@Override
protected void onShowPage(boolean firstShow) {
    super.onShowPage(firstShow);
    // should never be null here, but better be safe than sorry
    if (getWizard().getUnfinishedCell().getTarget() != null) {
        PropertyDefinition propDef = (PropertyDefinition) getWizard().getUnfinishedCell().getTarget().values().iterator().next().getDefinition().getDefinition();
        if (!propDef.equals(target)) {
            // target property definition changed, rebuild editor
            target = propDef;
            if (title != null) {
                title.dispose();
            }
            if (editor != null)
                editor.getControl().dispose();
            createContent(page);
            page.layout();
        }
    }
}
Also used : PropertyDefinition(eu.esdihumboldt.hale.common.schema.model.PropertyDefinition)

Example 14 with PropertyDefinition

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

the class RegexAnalysisParameterPage method onShowPage.

/**
 * @see eu.esdihumboldt.hale.ui.HaleWizardPage#onShowPage(boolean)
 */
@Override
protected void onShowPage(boolean firstShow) {
    super.onShowPage(firstShow);
    // should never be null here, but better be safe than sorry
    Cell unfinishedCell = getWizard().getUnfinishedCell();
    if (unfinishedCell.getTarget() != null) {
        PropertyDefinition propDef = (PropertyDefinition) unfinishedCell.getTarget().values().iterator().next().getDefinition().getDefinition();
        if (!propDef.equals(target)) {
            // target property definition changed, rebuild editor
            target = propDef;
            createContent(page);
            page.layout();
            setDefaultData(unfinishedCell);
        }
    }
}
Also used : Cell(eu.esdihumboldt.hale.common.align.model.Cell) PropertyDefinition(eu.esdihumboldt.hale.common.schema.model.PropertyDefinition)

Example 15 with PropertyDefinition

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

the class CellInfo method getName.

private String getName(CellType cellType, boolean fullName) {
    Iterator<? extends Entity> iterator;
    ListMultimap<String, ? extends Entity> entities;
    PropertyDefinition child = null;
    switch(cellType) {
        case SOURCE:
            if ((entities = getCell().getSource()) == null)
                return null;
            iterator = entities.values().iterator();
            break;
        case TARGET:
            if ((entities = getCell().getTarget()) == null)
                return null;
            iterator = entities.values().iterator();
            break;
        default:
            return null;
    }
    StringBuffer sb = new StringBuffer();
    while (iterator.hasNext()) {
        Entity entity = iterator.next();
        if (fullName) {
            for (ChildContext childContext : entity.getDefinition().getPropertyPath()) {
                child = childContext.getChild().asProperty();
                if (child != null) {
                    sb.append(child.getDisplayName());
                    sb.append(".");
                }
            }
            sb.append(entity.getDefinition().getDefinition().getDisplayName());
            sb.append(",\n");
        } else {
            sb.append(entity.getDefinition().getDefinition().getDisplayName());
            sb.append(", ");
        }
    }
    String result = sb.toString();
    if (fullName)
        return result.substring(0, result.lastIndexOf(",\n"));
    else
        return result.substring(0, result.lastIndexOf(","));
}
Also used : Entity(eu.esdihumboldt.hale.common.align.model.Entity) ChildContext(eu.esdihumboldt.hale.common.align.model.ChildContext) PropertyDefinition(eu.esdihumboldt.hale.common.schema.model.PropertyDefinition)

Aggregations

PropertyDefinition (eu.esdihumboldt.hale.common.schema.model.PropertyDefinition)64 TypeDefinition (eu.esdihumboldt.hale.common.schema.model.TypeDefinition)38 QName (javax.xml.namespace.QName)24 ChildContext (eu.esdihumboldt.hale.common.align.model.ChildContext)12 PropertyEntityDefinition (eu.esdihumboldt.hale.common.align.model.impl.PropertyEntityDefinition)12 GroupPropertyDefinition (eu.esdihumboldt.hale.common.schema.model.GroupPropertyDefinition)11 ArrayList (java.util.ArrayList)11 EntityDefinition (eu.esdihumboldt.hale.common.align.model.EntityDefinition)10 DefaultTypeDefinition (eu.esdihumboldt.hale.common.schema.model.impl.DefaultTypeDefinition)10 DefaultPropertyDefinition (eu.esdihumboldt.hale.common.schema.model.impl.DefaultPropertyDefinition)9 Test (org.junit.Test)9 Cell (eu.esdihumboldt.hale.common.align.model.Cell)8 TypeEntityDefinition (eu.esdihumboldt.hale.common.align.model.impl.TypeEntityDefinition)8 Cardinality (eu.esdihumboldt.hale.common.schema.model.constraint.property.Cardinality)7 XmlIndex (eu.esdihumboldt.hale.io.xsd.model.XmlIndex)7 DefaultInputSupplier (eu.esdihumboldt.hale.common.core.io.supplier.DefaultInputSupplier)6 URI (java.net.URI)6 Entity (eu.esdihumboldt.hale.common.align.model.Entity)5 Property (eu.esdihumboldt.hale.common.align.model.Property)5 MutableAlignment (eu.esdihumboldt.hale.common.align.model.MutableAlignment)4