Search in sources :

Example 26 with MultiChoiceParameterValue

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

the class SelectTopNNGTest method testEditWithTopTwoLocationsContainingDifferentTransactionTypes.

@Test
public void testEditWithTopTwoLocationsContainingDifferentTransactionTypes() 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 < 2; 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());
        }
    }
    for (int i = 3; 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.NETWORK);
        }
    }
    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 27 with MultiChoiceParameterValue

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

the class CompareGraphPlugin method createParameters.

@Override
public PluginParameters createParameters() {
    final PluginParameters parameters = new PluginParameters();
    final PluginParameter<SingleChoiceParameterValue> originalGraph = SingleChoiceParameterType.build(ORIGINAL_GRAPH_PARAMETER_ID);
    originalGraph.setName("Original Graph");
    originalGraph.setDescription("The graph used as the starting point for the comparison");
    parameters.addParameter(originalGraph);
    // Controller listens for value change so that the compare graph cannot be compared against itself
    parameters.addController(ORIGINAL_GRAPH_PARAMETER_ID, (PluginParameter<?> master, Map<String, PluginParameter<?>> params, ParameterChange change) -> {
        // When value has changed, remove choice from the comparison graph dialog
        if (change == ParameterChange.VALUE) {
            final String originalGraphName = params.get(ORIGINAL_GRAPH_PARAMETER_ID).getStringValue();
            if (originalGraphName != null) {
                final List<String> graphNames = new ArrayList<>();
                final Map<String, Graph> allGraphs = GraphNode.getAllGraphs();
                if (allGraphs != null) {
                    for (final String graphId : allGraphs.keySet()) {
                        graphNames.add(GraphNode.getGraphNode(graphId).getDisplayName());
                    }
                }
                // remove the current original graph selection from the list of graphs allowed to compare with
                graphNames.remove(originalGraphName);
                // sort drop down list
                graphNames.sort(String::compareTo);
                // COMPARE_GRAPH_PARAMETER_ID will always be of type SingleChoiceParameterValue
                @SuppressWarnings("unchecked") final PluginParameter<SingleChoiceParameterValue> compareParamter = (PluginParameter<SingleChoiceParameterValue>) params.get(COMPARE_GRAPH_PARAMETER_ID);
                SingleChoiceParameterType.setOptions(compareParamter, graphNames);
            }
        }
    });
    final PluginParameter<SingleChoiceParameterValue> compareGraph = SingleChoiceParameterType.build(COMPARE_GRAPH_PARAMETER_ID);
    compareGraph.setName("Compare With Graph");
    compareGraph.setDescription("The graph used to compare against the original graph");
    parameters.addParameter(compareGraph);
    final PluginParameter<MultiChoiceParameterValue> ignoreVertexAttributes = MultiChoiceParameterType.build(IGNORE_VERTEX_ATTRIBUTES_PARAMETER_ID);
    ignoreVertexAttributes.setName("Ignore Node Attributes");
    ignoreVertexAttributes.setDescription("Ignore these attributes when comparing nodes");
    parameters.addParameter(ignoreVertexAttributes);
    final PluginParameter<MultiChoiceParameterValue> ignoreTransactionAttributes = MultiChoiceParameterType.build(IGNORE_TRANSACTION_ATTRIBUTES_PARAMETER_ID);
    ignoreTransactionAttributes.setName("Ignore Transaction Attributes");
    ignoreTransactionAttributes.setDescription("Ignore these attributes when comparing transactions");
    parameters.addParameter(ignoreTransactionAttributes);
    final PluginParameter<ColorParameterValue> addedColour = ColorParameterType.build(ADDED_COLOUR_PARAMETER_ID);
    addedColour.setName("Added Color");
    addedColour.setDescription("The colour to indicate a node/transaction addition");
    addedColour.setColorValue(ConstellationColor.GREEN);
    parameters.addParameter(addedColour);
    final PluginParameter<ColorParameterValue> removedColour = ColorParameterType.build(REMOVED_COLOUR_PARAMETER_ID);
    removedColour.setName("Removed Color");
    removedColour.setDescription("The colour to indicate a node/transaction removal");
    removedColour.setColorValue(ConstellationColor.RED);
    parameters.addParameter(removedColour);
    final PluginParameter<ColorParameterValue> changedColour = ColorParameterType.build(CHANGED_COLOUR_PARAMETER_ID);
    changedColour.setName("Changed Color");
    changedColour.setDescription("The colour to indicate a node/transaction change");
    changedColour.setColorValue(ConstellationColor.YELLOW);
    parameters.addParameter(changedColour);
    final PluginParameter<ColorParameterValue> unchangedColour = ColorParameterType.build(UNCHANGED_COLOUR_PARAMETER_ID);
    unchangedColour.setName("Unchanged Color");
    unchangedColour.setDescription("The colour to indicate no node/transaction change");
    unchangedColour.setColorValue(ConstellationColor.GREY);
    parameters.addParameter(unchangedColour);
    return parameters;
}
Also used : ParameterChange(au.gov.asd.tac.constellation.plugins.parameters.ParameterChange) MultiChoiceParameterValue(au.gov.asd.tac.constellation.plugins.parameters.types.MultiChoiceParameterType.MultiChoiceParameterValue) ArrayList(java.util.ArrayList) ColorParameterValue(au.gov.asd.tac.constellation.plugins.parameters.types.ColorParameterType.ColorParameterValue) WritableGraph(au.gov.asd.tac.constellation.graph.WritableGraph) ReadableGraph(au.gov.asd.tac.constellation.graph.ReadableGraph) Graph(au.gov.asd.tac.constellation.graph.Graph) PluginParameters(au.gov.asd.tac.constellation.plugins.parameters.PluginParameters) PluginParameter(au.gov.asd.tac.constellation.plugins.parameters.PluginParameter) HashMap(java.util.HashMap) Map(java.util.Map) SingleChoiceParameterValue(au.gov.asd.tac.constellation.plugins.parameters.types.SingleChoiceParameterType.SingleChoiceParameterValue)

Example 28 with MultiChoiceParameterValue

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

the class CompareGraphPlugin method updateParameters.

@Override
public void updateParameters(final Graph graph, final PluginParameters parameters) {
    final List<String> graphNames = new ArrayList<>();
    final Map<String, Graph> allGraphs = GraphNode.getAllGraphs();
    if (allGraphs != null) {
        for (final String graphId : allGraphs.keySet()) {
            graphNames.add(GraphNode.getGraphNode(graphId).getDisplayName());
        }
    }
    // sort drop down list
    graphNames.sort(String::compareTo);
    // make a list of attributes that should be ignored.
    final ReadableGraph rg = graph.getReadableGraph();
    final Set<String> registeredVertexAttributes;
    final Set<String> registeredTransactionAttributes;
    try {
        registeredVertexAttributes = AttributeUtilities.getRegisteredAttributeIdsFromGraph(rg, GraphElementType.VERTEX).keySet();
        registeredTransactionAttributes = AttributeUtilities.getRegisteredAttributeIdsFromGraph(rg, GraphElementType.TRANSACTION).keySet();
    } finally {
        rg.release();
    }
    // ignore lowercase attributes
    final List<String> ignoredVertexAttributes = new ArrayList<>();
    for (final String attribute : registeredVertexAttributes) {
        if (attribute.substring(0, 1).matches("[a-z]")) {
            ignoredVertexAttributes.add(attribute);
        }
    }
    final List<String> ignoredTransactionAttributes = new ArrayList<>();
    for (final String attribute : registeredTransactionAttributes) {
        if (attribute.substring(0, 1).matches("[a-z]")) {
            ignoredTransactionAttributes.add(attribute);
        }
    }
    // ORIGINAL_GRAPH_PARAMETER will always be of type SingleChoiceParameter
    @SuppressWarnings("unchecked") final PluginParameter<SingleChoiceParameterValue> originalGraph = (PluginParameter<SingleChoiceParameterValue>) parameters.getParameters().get(ORIGINAL_GRAPH_PARAMETER_ID);
    SingleChoiceParameterType.setOptions(originalGraph, graphNames);
    SingleChoiceParameterType.setChoice(originalGraph, GraphNode.getGraphNode(graph.getId()).getDisplayName());
    // IGNORE_VERTEX_ATTRIBUTES_PARAMETER will always be of type MultiChoiceParameter
    @SuppressWarnings("unchecked") final PluginParameter<MultiChoiceParameterValue> ignoreVertexAttributes = (PluginParameter<MultiChoiceParameterValue>) parameters.getParameters().get(IGNORE_VERTEX_ATTRIBUTES_PARAMETER_ID);
    MultiChoiceParameterType.setOptions(ignoreVertexAttributes, new ArrayList<>(registeredVertexAttributes));
    MultiChoiceParameterType.setChoices(ignoreVertexAttributes, ignoredVertexAttributes);
    // IGNORE_TRANSACTION_ATTRIBUTES_PARAMETER will always be of type MultiChoiceParameter
    @SuppressWarnings("unchecked") final PluginParameter<MultiChoiceParameterValue> ignoreTransactionAttributes = (PluginParameter<MultiChoiceParameterValue>) parameters.getParameters().get(IGNORE_TRANSACTION_ATTRIBUTES_PARAMETER_ID);
    MultiChoiceParameterType.setOptions(ignoreTransactionAttributes, new ArrayList<>(registeredTransactionAttributes));
    MultiChoiceParameterType.setChoices(ignoreTransactionAttributes, ignoredTransactionAttributes);
}
Also used : ReadableGraph(au.gov.asd.tac.constellation.graph.ReadableGraph) MultiChoiceParameterValue(au.gov.asd.tac.constellation.plugins.parameters.types.MultiChoiceParameterType.MultiChoiceParameterValue) ArrayList(java.util.ArrayList) WritableGraph(au.gov.asd.tac.constellation.graph.WritableGraph) ReadableGraph(au.gov.asd.tac.constellation.graph.ReadableGraph) Graph(au.gov.asd.tac.constellation.graph.Graph) PluginParameter(au.gov.asd.tac.constellation.plugins.parameters.PluginParameter) SingleChoiceParameterValue(au.gov.asd.tac.constellation.plugins.parameters.types.SingleChoiceParameterType.SingleChoiceParameterValue)

Example 29 with MultiChoiceParameterValue

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

the class MultiChoiceParameterType method setOptionsData.

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

Example 30 with MultiChoiceParameterValue

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

the class MultiChoiceParameterType method setChoicesData.

/**
 * Set the list of selected values for the given parameter from a list of
 * {@link ParameterValue} objects.
 *
 * @param parameter A {@link PluginParameter} of this type.
 * @param choices A List of {@link ParameterValue} objects to set as the
 * selected values for the given parameter.
 */
public static void setChoicesData(final PluginParameter<MultiChoiceParameterValue> parameter, final List<? extends ParameterValue> choices) {
    final MultiChoiceParameterValue mc = parameter.getMultiChoiceValue() == null ? new MultiChoiceParameterValue() : new MultiChoiceParameterValue(parameter.getMultiChoiceValue());
    mc.setChoicesData(choices);
    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