use of eu.esdihumboldt.hale.common.schema.model.TypeDefinition in project hale by halestudio.
the class DataSetTypeSelectionDialog method setupViewer.
@Override
protected void setupViewer(TreeViewer viewer, Pair<TypeDefinition, DataSet> initialSelection) {
viewer.setLabelProvider(new DefinitionLabelProvider(viewer) {
@Override
public String getText(Object element) {
if (element instanceof DataSet) {
switch((DataSet) element) {
case TRANSFORMED:
return "Transformed";
case SOURCE:
default:
return "Source";
}
}
if (element instanceof Pair) {
element = ((Pair<?, ?>) element).getFirst();
}
return super.getText(element);
}
@Override
public Image getImage(Object element) {
if (element instanceof DataSet) {
return PlatformUI.getWorkbench().getSharedImages().getImage(ISharedImages.IMG_OBJ_FOLDER);
}
if (element instanceof Pair) {
element = ((Pair<?, ?>) element).getFirst();
}
return super.getImage(element);
}
});
viewer.setContentProvider(new TypeIndexContentProvider(viewer) {
@Override
public Object[] getElements(Object inputElement) {
return types.keySet().toArray();
}
@Override
public Object[] getChildren(Object parentElement) {
if (parentElement instanceof DataSet) {
DataSet dataSet = (DataSet) parentElement;
List<Pair<TypeDefinition, DataSet>> typeList = new ArrayList<Pair<TypeDefinition, DataSet>>();
for (TypeDefinition type : types.get(dataSet)) {
typeList.add(new Pair<TypeDefinition, DataSet>(type, dataSet));
}
return typeList.toArray();
}
return new Object[] {};
}
@Override
public boolean hasChildren(Object parentElement) {
return parentElement instanceof DataSet && !types.get((DataSet) parentElement).isEmpty();
}
});
viewer.setAutoExpandLevel(2);
viewer.setInput(types);
if (initialSelection != null) {
viewer.setSelection(new StructuredSelection(initialSelection));
}
}
use of eu.esdihumboldt.hale.common.schema.model.TypeDefinition in project hale by halestudio.
the class StyleHelper method getSpectrumStyles.
/**
* Returns a default style for the given type.
*
* @param dataSetTypes type definitions associated to their data set
* @return the style
*/
public static Style getSpectrumStyles(SetMultimap<DataSet, TypeDefinition> dataSetTypes) {
int defWidth = StylePreferences.getDefaultWidth();
Style style = styleFactory.createStyle();
GeometrySchemaService gss = PlatformUI.getWorkbench().getService(GeometrySchemaService.class);
for (DataSet dataSet : dataSetTypes.keySet()) {
float saturation;
float brightness;
switch(dataSet) {
case TRANSFORMED:
saturation = 0.8f;
brightness = 0.6f;
break;
case SOURCE:
default:
saturation = 0.75f;
brightness = 0.8f;
break;
}
Set<TypeDefinition> types = new HashSet<>(dataSetTypes.get(dataSet));
Iterator<TypeDefinition> it = types.iterator();
while (it.hasNext()) {
TypeDefinition type = it.next();
// remove invalid types
if (type.getConstraint(AbstractFlag.class).isEnabled() || gss.getDefaultGeometry(type) == null) {
it.remove();
}
}
int numberOfTypes = types.size();
int index = 0;
for (TypeDefinition typeDef : types) {
FeatureTypeStyle fts;
// TODO based on default geometry?
// polygon is always OK as it contains stroke and fill
// Color color = generateRandomColor(Color.WHITE);
Color color;
if (numberOfTypes == 1) {
color = generateRandomColor(saturation, brightness);
} else {
color = Color.getHSBColor((float) index / (float) numberOfTypes, saturation, brightness);
}
fts = createPolygonStyle(color, defWidth);
fts.featureTypeNames().add(new NameImpl(getFeatureTypeName(typeDef)));
style.featureTypeStyles().add(fts);
index++;
}
}
return style;
}
use of eu.esdihumboldt.hale.common.schema.model.TypeDefinition in project hale by halestudio.
the class RuleStylePage method createEditor.
/**
* Create a rule editor
*
* @param rule the rule
* @param parent the parent composite
*
* @return the {@link Rule} editor
*/
private Editor<Rule> createEditor(Rule rule, Composite parent) {
TypeDefinition type = getParent().getType();
Filter filter = rule.getFilter();
Symbolizer symbolizer = null;
Symbolizer[] symbolizers = rule.getSymbolizers();
if (symbolizers != null && symbolizers.length > 0) {
symbolizer = symbolizers[0];
}
if (symbolizer == null) {
// fallback if there is no symbolizer defined
FeatureTypeStyle fts = StyleHelper.getDefaultStyle(type, getParent().getDataSet());
symbolizer = fts.rules().get(0).getSymbolizers()[0];
}
Editor<Rule> editor;
if (symbolizer instanceof PointSymbolizer) {
editor = createEditor(parent, type, filter, PointSymbolizer.class, (PointSymbolizer) symbolizer);
} else if (symbolizer instanceof PolygonSymbolizer) {
editor = createEditor(parent, type, filter, PolygonSymbolizer.class, (PolygonSymbolizer) symbolizer);
} else {
// TODO support other symbolizers
// default: LineSymbolizer
editor = createEditor(parent, type, filter, LineSymbolizer.class, (LineSymbolizer) symbolizer);
}
return editor;
}
use of eu.esdihumboldt.hale.common.schema.model.TypeDefinition in project hale by halestudio.
the class SpectrumColorSchemeHandler method execute.
/**
* @see IHandler#execute(ExecutionEvent)
*/
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
// collect all types
SetMultimap<DataSet, TypeDefinition> types = HashMultimap.create();
SchemaService schemas = PlatformUI.getWorkbench().getService(SchemaService.class);
for (TypeDefinition type : schemas.getSchemas(SchemaSpaceID.SOURCE).getMappingRelevantTypes()) {
types.put(DataSet.SOURCE, type);
}
for (TypeDefinition type : schemas.getSchemas(SchemaSpaceID.TARGET).getMappingRelevantTypes()) {
types.put(DataSet.TRANSFORMED, type);
}
Style style = StyleHelper.getSpectrumStyles(types);
StyleService styleService = PlatformUI.getWorkbench().getService(StyleService.class);
styleService.addStyles(style);
return null;
}
use of eu.esdihumboldt.hale.common.schema.model.TypeDefinition in project hale by halestudio.
the class TypeRandomColorHandler method execute.
/**
* @see IHandler#execute(ExecutionEvent)
*/
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
// collect types and associated data sets
SetMultimap<DataSet, TypeDefinition> types = TypeStyleHandler.collectTypesFromSelection(event);
Style style = StyleHelper.getRandomStyles(types);
StyleService styleService = PlatformUI.getWorkbench().getService(StyleService.class);
styleService.addStyles(style);
return null;
}
Aggregations