use of eu.esdihumboldt.hale.ui.common.service.population.Population 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.ui.common.service.population.Population 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);
}
use of eu.esdihumboldt.hale.ui.common.service.population.Population in project hale by halestudio.
the class UnpopulatedPropertiesFilter method select.
/**
* @see ViewerFilter#select(Viewer, Object, Object)
*/
@Override
public boolean select(Viewer viewer, Object parentElement, Object element) {
if (ps != null) {
if (element instanceof TreePath) {
element = ((TreePath) element).getLastSegment();
}
if (element instanceof EntityDefinition) {
EntityDefinition entityDef = (EntityDefinition) element;
if (filterOnlyPopulatedTypes) {
TypeEntityDefinition type = AlignmentUtil.getTypeEntity(entityDef);
int typeCount = ps.getPopulation(type).getOverallCount();
if (typeCount == 0 || typeCount == Population.UNKNOWN) {
// all
return true;
}
}
if (!entityDef.getPropertyPath().isEmpty() && // only filter properties
ps.hasPopulation(entityDef.getSchemaSpace())) {
// only filter if there is a population
Population pop = ps.getPopulation(entityDef);
return pop != null && pop.getOverallCount() != 0;
}
}
}
return true;
}
Aggregations