Search in sources :

Example 11 with MultiChoiceParameterValue

use of au.gov.asd.tac.constellation.plugins.parameters.types.MultiChoiceParameterType.MultiChoiceParameterValue in project constellation by constellation-app.

the class SelectTopNNGTest method testEditWithTopTwoContactsAndEverythingIsCommunicationTransactions.

@Test
public void testEditWithTopTwoContactsAndEverythingIsCommunicationTransactions() throws Exception {
    final StoreGraph graph = new StoreGraph(SchemaFactoryUtilities.getSchemaFactory(AnalyticSchemaFactory.ANALYTIC_SCHEMA_ID).createSchema());
    final int vertexLabelAttr = VisualConcept.VertexAttribute.LABEL.ensure(graph);
    final int vertexSelectedAttr = VisualConcept.VertexAttribute.SELECTED.ensure(graph);
    final int vertexTypeAttr = AnalyticConcept.VertexAttribute.TYPE.ensure(graph);
    final int transactionTypeAttr = AnalyticConcept.TransactionAttribute.TYPE.ensure(graph);
    final int sourceVxId = graph.addVertex();
    graph.setStringValue(vertexLabelAttr, sourceVxId, "source");
    graph.setBooleanValue(vertexSelectedAttr, sourceVxId, true);
    // buildId the graph
    for (int i = 0; i < 10; i++) {
        final int desintationVxId = graph.addVertex();
        graph.setStringValue(vertexLabelAttr, desintationVxId, String.format("destination %s", i));
        for (int j = i; j < 10; j++) {
            int txId = graph.addTransaction(sourceVxId, desintationVxId, true);
            graph.setObjectValue(transactionTypeAttr, txId, AnalyticConcept.TransactionType.COMMUNICATION.getName());
        }
    }
    final PluginInteraction interaction = new TextPluginInteraction();
    final SelectTopNPlugin instance = new SelectTopNPlugin();
    final PluginParameters parameters = instance.createParameters();
    parameters.getParameters().get(SelectTopNPlugin.MODE_PARAMETER_ID).setStringValue(SelectTopNPlugin.TRANSACTION);
    parameters.getParameters().get(SelectTopNPlugin.TYPE_CATEGORY_PARAMETER_ID).setStringValue(AnalyticConcept.TransactionType.COMMUNICATION.getName());
    // TYPE_PARAMETER will always be of type MultiChoiceParameter
    @SuppressWarnings("unchecked") final PluginParameter<MultiChoiceParameterValue> subTypeParameter = (PluginParameter<MultiChoiceParameterValue>) parameters.getParameters().get(SelectTopNPlugin.TYPE_PARAMETER_ID);
    final List<String> arrayList = new ArrayList<>();
    arrayList.add(AnalyticConcept.TransactionType.COMMUNICATION.getName());
    MultiChoiceParameterType.setChoices(subTypeParameter, arrayList);
    parameters.getParameters().get(SelectTopNPlugin.LIMIT_PARAMETER_ID).setIntegerValue(2);
    instance.edit(graph, interaction, parameters);
    assertTrue(graph.getBooleanValue(vertexSelectedAttr, sourceVxId));
    assertTrue(graph.getBooleanValue(vertexSelectedAttr, sourceVxId + 1));
    assertTrue(graph.getBooleanValue(vertexSelectedAttr, sourceVxId + 2));
    for (int i = 3; i < 10; i++) {
        assertFalse(graph.getBooleanValue(vertexSelectedAttr, sourceVxId + i));
    }
}
Also used : MultiChoiceParameterValue(au.gov.asd.tac.constellation.plugins.parameters.types.MultiChoiceParameterType.MultiChoiceParameterValue) ArrayList(java.util.ArrayList) PluginInteraction(au.gov.asd.tac.constellation.plugins.PluginInteraction) TextPluginInteraction(au.gov.asd.tac.constellation.plugins.text.TextPluginInteraction) PluginParameters(au.gov.asd.tac.constellation.plugins.parameters.PluginParameters) PluginParameter(au.gov.asd.tac.constellation.plugins.parameters.PluginParameter) TextPluginInteraction(au.gov.asd.tac.constellation.plugins.text.TextPluginInteraction) StoreGraph(au.gov.asd.tac.constellation.graph.StoreGraph) Test(org.testng.annotations.Test)

Example 12 with MultiChoiceParameterValue

use of au.gov.asd.tac.constellation.plugins.parameters.types.MultiChoiceParameterType.MultiChoiceParameterValue in project constellation by constellation-app.

the class AbstractGeoExportPlugin method createParameters.

@Override
// the fallthrough at the switch statement is intentional
@SuppressWarnings("fallthrough")
public PluginParameters createParameters() {
    final PluginParameters parameters = new PluginParameters();
    final PluginParameter<FileParameterValue> outputParameter = FileParameterType.build(OUTPUT_PARAMETER_ID);
    outputParameter.setName("Output File");
    outputParameter.setDescription("The name of the output file");
    FileParameterType.setKind(outputParameter, FileParameterType.FileParameterKind.SAVE);
    FileParameterType.setFileFilters(outputParameter, getExportType());
    parameters.addParameter(outputParameter);
    if (includeSpatialReference()) {
        final PluginParameter<SingleChoiceParameterValue> spatialReferenceParameter = SingleChoiceParameterType.build(SPATIAL_REFERENCE_PARAMETER_ID, SpatialReferenceParameterValue.class);
        spatialReferenceParameter.setName("Spatial Reference");
        spatialReferenceParameter.setDescription("The spatial reference to use for the geopackage");
        final List<SpatialReferenceParameterValue> spatialReferences = Arrays.asList(Shape.SpatialReference.values()).stream().map(spatialReference -> new SpatialReferenceParameterValue(spatialReference)).collect(Collectors.toList());
        SingleChoiceParameterType.setOptionsData(spatialReferenceParameter, spatialReferences);
        SingleChoiceParameterType.setChoiceData(spatialReferenceParameter, spatialReferences.get(0));
        parameters.addParameter(spatialReferenceParameter);
    }
    final PluginParameter<SingleChoiceParameterValue> elementTypeParameter = SingleChoiceParameterType.build(ELEMENT_TYPE_PARAMETER_ID, ElementTypeParameterValue.class);
    elementTypeParameter.setName("Element Type");
    elementTypeParameter.setDescription("The graph element type");
    final List<ElementTypeParameterValue> elementTypes = new ArrayList<>();
    elementTypes.add(new ElementTypeParameterValue(GraphElementType.TRANSACTION));
    elementTypes.add(new ElementTypeParameterValue(GraphElementType.VERTEX));
    SingleChoiceParameterType.setOptionsData(elementTypeParameter, elementTypes);
    parameters.addParameter(elementTypeParameter);
    final PluginParameter<MultiChoiceParameterValue> attributesParameter = MultiChoiceParameterType.build(ATTRIBUTES_PARAMETER_ID, GraphAttributeParameterValue.class);
    attributesParameter.setName("Attributes");
    attributesParameter.setDescription("The list of attribute names to include in the export");
    attributesParameter.setEnabled(false);
    parameters.addParameter(attributesParameter);
    final PluginParameter<BooleanParameterValue> selectedOnlyParameter = BooleanParameterType.build(SELECTED_ONLY_PARAMETER_ID);
    selectedOnlyParameter.setName("Selected Only");
    selectedOnlyParameter.setDescription("If True, only export the selected nodes. The default is False.");
    selectedOnlyParameter.setBooleanValue(false);
    parameters.addParameter(selectedOnlyParameter);
    parameters.addController(ELEMENT_TYPE_PARAMETER_ID, (master, params, change) -> {
        if (change == ParameterChange.VALUE) {
            final Graph activeGraph = GraphManager.getDefault().getActiveGraph();
            if (activeGraph != null) {
                // create options by getting attributes for the chosen element type from the graph
                final List<GraphAttributeParameterValue> attributeOptions = new ArrayList<>();
                final ReadableGraph readableGraph = activeGraph.getReadableGraph();
                try {
                    final ParameterValue pv = params.get(master.getId()).getSingleChoice();
                    assert (pv instanceof ElementTypeParameterValue);
                    final GraphElementType elementType = ((ElementTypeParameterValue) pv).getGraphElementType();
                    switch(elementType) {
                        case TRANSACTION:
                            final int transactionAttributeCount = readableGraph.getAttributeCount(GraphElementType.TRANSACTION);
                            for (int attributePosition = 0; attributePosition < transactionAttributeCount; attributePosition++) {
                                final int attributeId = readableGraph.getAttribute(GraphElementType.TRANSACTION, attributePosition);
                                final GraphAttribute graphAttribute = new GraphAttribute(readableGraph, attributeId);
                                attributeOptions.add(new GraphAttributeParameterValue(graphAttribute));
                            }
                        // fall through
                        case VERTEX:
                            final int vertexAttributeCount = readableGraph.getAttributeCount(GraphElementType.VERTEX);
                            for (int attributePosition = 0; attributePosition < vertexAttributeCount; attributePosition++) {
                                final int attributeId = readableGraph.getAttribute(GraphElementType.VERTEX, attributePosition);
                                final GraphAttribute graphAttribute = new GraphAttribute(readableGraph, attributeId);
                                attributeOptions.add(new GraphAttributeParameterValue(graphAttribute));
                            }
                            break;
                        default:
                            return;
                    }
                } finally {
                    readableGraph.release();
                }
                // create choices by deselecting lowercase attributes by default
                final List<GraphAttributeParameterValue> attributeChoices = attributeOptions.stream().filter(attributeOption -> !((GraphAttribute) attributeOption.getObjectValue()).getName().matches("[a-z]{1}.*")).collect(Collectors.toList());
                // sort options and choices lists
                Collections.sort(attributeOptions);
                Collections.sort(attributeChoices);
                // update attributes parameter
                // Attrbutes_Parameter is created as a MultiChoice parameter in this class on line 137.
                @SuppressWarnings("unchecked") final PluginParameter<MultiChoiceParameterValue> updatedAttributesParameter = (PluginParameter<MultiChoiceParameterValue>) params.get(ATTRIBUTES_PARAMETER_ID);
                MultiChoiceParameterType.setOptionsData(updatedAttributesParameter, attributeOptions);
                MultiChoiceParameterType.setChoicesData(updatedAttributesParameter, attributeChoices);
                updatedAttributesParameter.setEnabled(true);
            }
        }
    });
    return parameters;
}
Also used : Arrays(java.util.Arrays) Tuple(au.gov.asd.tac.constellation.utilities.datastructure.Tuple) ReadableGraph(au.gov.asd.tac.constellation.graph.ReadableGraph) GraphAttributeParameterValue(au.gov.asd.tac.constellation.plugins.parameters.types.GraphAttributeParameterValue) ParameterChange(au.gov.asd.tac.constellation.plugins.parameters.ParameterChange) SingleChoiceParameterType(au.gov.asd.tac.constellation.plugins.parameters.types.SingleChoiceParameterType) MultiChoiceParameterValue(au.gov.asd.tac.constellation.plugins.parameters.types.MultiChoiceParameterType.MultiChoiceParameterValue) SimpleReadPlugin(au.gov.asd.tac.constellation.plugins.templates.SimpleReadPlugin) SpatialConcept(au.gov.asd.tac.constellation.graph.schema.analytic.concept.SpatialConcept) HashMap(java.util.HashMap) VisualConcept(au.gov.asd.tac.constellation.graph.schema.visual.concept.VisualConcept) StringUtils(org.apache.commons.lang3.StringUtils) GraphConstants(au.gov.asd.tac.constellation.graph.GraphConstants) ArrayList(java.util.ArrayList) Graph(au.gov.asd.tac.constellation.graph.Graph) FileParameterValue(au.gov.asd.tac.constellation.plugins.parameters.types.FileParameterType.FileParameterValue) PluginInteraction(au.gov.asd.tac.constellation.plugins.PluginInteraction) Shape(au.gov.asd.tac.constellation.utilities.geospatial.Shape) PluginParameter(au.gov.asd.tac.constellation.plugins.parameters.PluginParameter) Map(java.util.Map) GraphReadMethods(au.gov.asd.tac.constellation.graph.GraphReadMethods) GraphManager(au.gov.asd.tac.constellation.graph.manager.GraphManager) OUTPUT_PARAMETER_ID(au.gov.asd.tac.constellation.plugins.importexport.geospatial.AbstractGeoExportPlugin.OUTPUT_PARAMETER_ID) GraphAttribute(au.gov.asd.tac.constellation.graph.GraphAttribute) ELEMENT_TYPE_PARAMETER_ID(au.gov.asd.tac.constellation.plugins.importexport.geospatial.AbstractGeoExportPlugin.ELEMENT_TYPE_PARAMETER_ID) ElementTypeParameterValue(au.gov.asd.tac.constellation.plugins.parameters.types.ElementTypeParameterValue) PluginParameters(au.gov.asd.tac.constellation.plugins.parameters.PluginParameters) FileParameterType(au.gov.asd.tac.constellation.plugins.parameters.types.FileParameterType) MultiChoiceParameterType(au.gov.asd.tac.constellation.plugins.parameters.types.MultiChoiceParameterType) GraphElementType(au.gov.asd.tac.constellation.graph.GraphElementType) BooleanParameterValue(au.gov.asd.tac.constellation.plugins.parameters.types.BooleanParameterType.BooleanParameterValue) ParameterValue(au.gov.asd.tac.constellation.plugins.parameters.types.ParameterValue) IOException(java.io.IOException) GraphRecordStoreUtilities(au.gov.asd.tac.constellation.graph.processing.GraphRecordStoreUtilities) PluginException(au.gov.asd.tac.constellation.plugins.PluginException) Collectors(java.util.stream.Collectors) File(java.io.File) BooleanParameterType(au.gov.asd.tac.constellation.plugins.parameters.types.BooleanParameterType) PluginNotificationLevel(au.gov.asd.tac.constellation.plugins.PluginNotificationLevel) List(java.util.List) NotifyDescriptor(org.openide.NotifyDescriptor) NotifyDisplayer(au.gov.asd.tac.constellation.utilities.gui.NotifyDisplayer) ConstellationLoggerHelper(au.gov.asd.tac.constellation.plugins.logging.ConstellationLoggerHelper) GraphNode(au.gov.asd.tac.constellation.graph.node.GraphNode) GeometryType(au.gov.asd.tac.constellation.utilities.geospatial.Shape.GeometryType) ExtensionFilter(javafx.stage.FileChooser.ExtensionFilter) SingleChoiceParameterValue(au.gov.asd.tac.constellation.plugins.parameters.types.SingleChoiceParameterType.SingleChoiceParameterValue) Collections(java.util.Collections) ReadableGraph(au.gov.asd.tac.constellation.graph.ReadableGraph) ElementTypeParameterValue(au.gov.asd.tac.constellation.plugins.parameters.types.ElementTypeParameterValue) MultiChoiceParameterValue(au.gov.asd.tac.constellation.plugins.parameters.types.MultiChoiceParameterType.MultiChoiceParameterValue) GraphAttribute(au.gov.asd.tac.constellation.graph.GraphAttribute) ArrayList(java.util.ArrayList) GraphElementType(au.gov.asd.tac.constellation.graph.GraphElementType) BooleanParameterValue(au.gov.asd.tac.constellation.plugins.parameters.types.BooleanParameterType.BooleanParameterValue) PluginParameters(au.gov.asd.tac.constellation.plugins.parameters.PluginParameters) PluginParameter(au.gov.asd.tac.constellation.plugins.parameters.PluginParameter) GraphAttributeParameterValue(au.gov.asd.tac.constellation.plugins.parameters.types.GraphAttributeParameterValue) MultiChoiceParameterValue(au.gov.asd.tac.constellation.plugins.parameters.types.MultiChoiceParameterType.MultiChoiceParameterValue) FileParameterValue(au.gov.asd.tac.constellation.plugins.parameters.types.FileParameterType.FileParameterValue) ElementTypeParameterValue(au.gov.asd.tac.constellation.plugins.parameters.types.ElementTypeParameterValue) BooleanParameterValue(au.gov.asd.tac.constellation.plugins.parameters.types.BooleanParameterType.BooleanParameterValue) ParameterValue(au.gov.asd.tac.constellation.plugins.parameters.types.ParameterValue) SingleChoiceParameterValue(au.gov.asd.tac.constellation.plugins.parameters.types.SingleChoiceParameterType.SingleChoiceParameterValue) GraphAttributeParameterValue(au.gov.asd.tac.constellation.plugins.parameters.types.GraphAttributeParameterValue) FileParameterValue(au.gov.asd.tac.constellation.plugins.parameters.types.FileParameterType.FileParameterValue) ReadableGraph(au.gov.asd.tac.constellation.graph.ReadableGraph) Graph(au.gov.asd.tac.constellation.graph.Graph) SingleChoiceParameterValue(au.gov.asd.tac.constellation.plugins.parameters.types.SingleChoiceParameterType.SingleChoiceParameterValue)

Example 13 with MultiChoiceParameterValue

use of au.gov.asd.tac.constellation.plugins.parameters.types.MultiChoiceParameterType.MultiChoiceParameterValue in project constellation by constellation-app.

the class MultiChoiceParameterType method setState.

/**
 * Set both the collection of options and list of selected values for the
 * given parameter from lists of Strings.
 *
 * @param parameter A {@link PluginParameter} of this type.
 * @param options A List of Strings to set as the options for the given
 * parameter.
 * @param choices A List of Strings objects to set as the selected values
 * for the given parameter.
 */
public static void setState(final PluginParameter<MultiChoiceParameterValue> parameter, final List<String> options, final List<String> choices) {
    MultiChoiceParameterValue mc = parameter.getMultiChoiceValue() == null ? new MultiChoiceParameterValue() : new MultiChoiceParameterValue(parameter.getMultiChoiceValue());
    mc.setOptions(options);
    mc.setChoices(choices);
    parameter.setObjectValue(mc);
}
Also used : MultiChoiceParameterValue(au.gov.asd.tac.constellation.plugins.parameters.types.MultiChoiceParameterType.MultiChoiceParameterValue)

Example 14 with MultiChoiceParameterValue

use of au.gov.asd.tac.constellation.plugins.parameters.types.MultiChoiceParameterType.MultiChoiceParameterValue in project constellation by constellation-app.

the class MultiChoiceParameterType method setChoices.

/**
 * Set the list of selected values for the given parameter from a list of
 * Strings
 *
 * @param parameter A {@link PluginParameter} of this type.
 * @param choices A List of Strings objects to set as the selected values
 * for the given parameter.
 */
public static void setChoices(final PluginParameter<MultiChoiceParameterValue> parameter, final List<String> choices) {
    final MultiChoiceParameterValue mc = parameter.getMultiChoiceValue() == null ? new MultiChoiceParameterValue() : new MultiChoiceParameterValue(parameter.getMultiChoiceValue());
    mc.setChoices(choices);
    parameter.setObjectValue(mc);
}
Also used : MultiChoiceParameterValue(au.gov.asd.tac.constellation.plugins.parameters.types.MultiChoiceParameterType.MultiChoiceParameterValue)

Example 15 with MultiChoiceParameterValue

use of au.gov.asd.tac.constellation.plugins.parameters.types.MultiChoiceParameterType.MultiChoiceParameterValue in project constellation by constellation-app.

the class MultiChoiceParameterType method setOptions.

/**
 * Set the collection of options for the given parameter from a list of
 * Strings.
 *
 * @param parameter A {@link PluginParameter} of this type.
 * @param options A List of Strings to set as the options for the given
 * parameter.
 */
public static void setOptions(final PluginParameter<MultiChoiceParameterValue> parameter, final List<String> options) {
    final MultiChoiceParameterValue mc = parameter.getMultiChoiceValue() == null ? new MultiChoiceParameterValue() : new MultiChoiceParameterValue(parameter.getMultiChoiceValue());
    mc.setOptions(options);
    parameter.setObjectValue(mc);
}
Also used : MultiChoiceParameterValue(au.gov.asd.tac.constellation.plugins.parameters.types.MultiChoiceParameterType.MultiChoiceParameterValue)

Aggregations

MultiChoiceParameterValue (au.gov.asd.tac.constellation.plugins.parameters.types.MultiChoiceParameterType.MultiChoiceParameterValue)34 PluginParameter (au.gov.asd.tac.constellation.plugins.parameters.PluginParameter)25 PluginParameters (au.gov.asd.tac.constellation.plugins.parameters.PluginParameters)19 ArrayList (java.util.ArrayList)16 Test (org.testng.annotations.Test)12 SchemaTransactionType (au.gov.asd.tac.constellation.graph.schema.type.SchemaTransactionType)9 StoreGraph (au.gov.asd.tac.constellation.graph.StoreGraph)8 PluginInteraction (au.gov.asd.tac.constellation.plugins.PluginInteraction)7 SingleChoiceParameterValue (au.gov.asd.tac.constellation.plugins.parameters.types.SingleChoiceParameterType.SingleChoiceParameterValue)6 TextPluginInteraction (au.gov.asd.tac.constellation.plugins.text.TextPluginInteraction)6 ReadableGraph (au.gov.asd.tac.constellation.graph.ReadableGraph)5 BooleanParameterValue (au.gov.asd.tac.constellation.plugins.parameters.types.BooleanParameterType.BooleanParameterValue)5 IntegerParameterValue (au.gov.asd.tac.constellation.plugins.parameters.types.IntegerParameterType.IntegerParameterValue)5 SchemaVertexType (au.gov.asd.tac.constellation.graph.schema.type.SchemaVertexType)4 ParameterChange (au.gov.asd.tac.constellation.plugins.parameters.ParameterChange)4 ParameterValue (au.gov.asd.tac.constellation.plugins.parameters.types.ParameterValue)4 HashSet (java.util.HashSet)4 Map (java.util.Map)4 Graph (au.gov.asd.tac.constellation.graph.Graph)3 DualGraph (au.gov.asd.tac.constellation.graph.locking.DualGraph)3