Example usage for com.google.common.collect SetMultimap containsValue

List of usage examples for com.google.common.collect SetMultimap containsValue

Introduction

In this page you can find the example usage for com.google.common.collect SetMultimap containsValue.

Prototype

boolean containsValue(@Nullable Object value);

Source Link

Document

Returns true if this multimap contains at least one key-value pair with the value value .

Usage

From source file:eu.esdihumboldt.hale.ui.style.handler.TypeStyleHandler.java

/**
 * 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.//  www. j a v  a2 s.c  om
 * 
 * @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;
}

From source file:eu.esdihumboldt.hale.ui.style.TypeStyleHandler.java

/**
 * @see IHandler#execute(ExecutionEvent)
 *///from w ww .  j  a  va 2  s. c om
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
    ISelection selection = HandlerUtil.getCurrentSelection(event);

    // collect types and associated data sets
    SetMultimap<DataSet, TypeDefinition> types = HashMultimap.create();
    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 = (InstanceService) 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());
            }
        }
    }

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