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