use of eu.esdihumboldt.hale.common.instance.model.DataSet 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;
}
use of eu.esdihumboldt.hale.common.instance.model.DataSet in project hale by halestudio.
the class TypeStyleHandler method execute.
/**
* @see IHandler#execute(ExecutionEvent)
*/
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
// collect types and associated data sets
SetMultimap<DataSet, TypeDefinition> types = collectTypesFromSelection(event);
Pair<TypeDefinition, DataSet> typeInfo = null;
// select a type
if (types.size() == 1) {
Entry<DataSet, TypeDefinition> entry = types.entries().iterator().next();
typeInfo = new Pair<TypeDefinition, DataSet>(entry.getValue(), entry.getKey());
} else if (!types.isEmpty()) {
// choose through dialog
DataSetTypeSelectionDialog dialog = new DataSetTypeSelectionDialog(Display.getCurrent().getActiveShell(), "Multiple types: select which to change the style for", null, types);
if (dialog.open() == DataSetTypeSelectionDialog.OK) {
typeInfo = dialog.getObject();
}
}
if (typeInfo != null) {
try {
FeatureStyleDialog dialog = new FeatureStyleDialog(typeInfo.getFirst(), typeInfo.getSecond());
dialog.setBlockOnOpen(false);
dialog.open();
} catch (Exception e) {
throw new ExecutionException("Could not open style dialog", e);
}
}
return null;
}
use of eu.esdihumboldt.hale.common.instance.model.DataSet in project hale by halestudio.
the class TypeStyleHandler method collectTypesFromSelection.
/**
* Collect all type definitions and data sets from the current selection of
* {@link TypeDefinition}s, {@link EntityDefinition}s, {@link Instance}s and
* {@link InstanceReference}s.
*
* @param event the handler execution event
* @return the collected type definitions
*/
public static SetMultimap<DataSet, TypeDefinition> collectTypesFromSelection(ExecutionEvent event) {
SetMultimap<DataSet, TypeDefinition> types = HashMultimap.create();
ISelection selection = HandlerUtil.getCurrentSelection(event);
if (selection instanceof IStructuredSelection && !selection.isEmpty()) {
for (Object object : ((IStructuredSelection) selection).toArray()) {
if (object instanceof TypeDefinition) {
TypeDefinition type = (TypeDefinition) object;
if (!types.containsValue(type)) {
DataSet dataSet = findDataSet(type);
types.put(dataSet, type);
}
}
if (object instanceof EntityDefinition) {
EntityDefinition entityDef = (EntityDefinition) object;
if (entityDef.getPropertyPath().isEmpty()) {
DataSet dataSet = (entityDef.getSchemaSpace() == SchemaSpaceID.SOURCE) ? (DataSet.SOURCE) : (DataSet.TRANSFORMED);
types.put(dataSet, entityDef.getType());
}
}
if (object instanceof InstanceReference) {
InstanceService is = HandlerUtil.getActiveWorkbenchWindow(event).getWorkbench().getService(InstanceService.class);
object = is.getInstance((InstanceReference) object);
}
if (object instanceof Instance) {
Instance instance = (Instance) object;
types.put(instance.getDataSet(), instance.getDefinition());
}
}
}
return types;
}
use of eu.esdihumboldt.hale.common.instance.model.DataSet in project hale by halestudio.
the class InstanceValidationStatusAction method createListeners.
/**
* Registers needed listeners.
*/
private void createListeners() {
InstanceService is = PlatformUI.getWorkbench().getService(InstanceService.class);
is.addListener(new InstanceServiceAdapter() {
@Override
public void datasetAboutToChange(DataSet type) {
report = null;
PlatformUI.getWorkbench().getDisplay().asyncExec(new Runnable() {
@Override
public void run() {
updateStatus();
}
});
}
});
final InstanceValidationService ivs = PlatformUI.getWorkbench().getService(InstanceValidationService.class);
ivs.addListener(new InstanceValidationListener() {
@Override
public void instancesValidated(InstanceValidationReport report) {
InstanceValidationStatusAction.this.report = report;
PlatformUI.getWorkbench().getDisplay().asyncExec(new Runnable() {
@Override
public void run() {
updateStatus();
}
});
}
@Override
public void validationEnabledChange() {
// don't care
}
});
}
use of eu.esdihumboldt.hale.common.instance.model.DataSet in project hale by halestudio.
the class StyleHelper method getRandomStyles.
/**
* Returns a default style for the given type.
*
* @param dataSetTypes type definitions associated to their data set
* @return the style
*/
public static Style getRandomStyles(SetMultimap<DataSet, TypeDefinition> dataSetTypes) {
int defWidth = StylePreferences.getDefaultWidth();
Style style = styleFactory.createStyle();
for (Entry<DataSet, TypeDefinition> entry : dataSetTypes.entries()) {
DataSet dataSet = entry.getKey();
TypeDefinition typeDef = entry.getValue();
FeatureTypeStyle fts;
// TODO based on default geometry?
// polygon is always OK as it contains stroke and fill
// Color color = generateRandomColor(Color.WHITE);
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;
}
Color color = generateRandomColor(saturation, brightness);
fts = createPolygonStyle(color, defWidth);
fts.featureTypeNames().add(new NameImpl(getFeatureTypeName(typeDef)));
style.featureTypeStyles().add(fts);
}
return style;
}
Aggregations