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