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