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;
}
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;
}
}
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();
}
}
}
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);
}
}
}
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(","));
}
Aggregations