use of au.gov.asd.tac.constellation.plugins.parameters.types.BooleanParameterType.BooleanParameterValue in project constellation by constellation-app.
the class MergeNodesPluginNGTest method createParameters.
@Test
public void createParameters() {
final PluginParameters actual = mergeNodesPlugin.createParameters();
final Map<String, PluginParameter<?>> parameters = actual.getParameters();
assertEquals(parameters.keySet(), Set.of("MergeNodesPlugin.merge_type", "MergeNodesPlugin.threshold", "MergeNodesPlugin.merger", "MergeNodesPlugin.lead", "MergeNodesPlugin.selected"));
final PluginParameter<SingleChoiceParameterValue> mergeTypeParameter = (PluginParameter<SingleChoiceParameterValue>) parameters.get("MergeNodesPlugin.merge_type");
assertEquals(mergeTypeParameter.getName(), "Merge By");
assertEquals(mergeTypeParameter.getDescription(), "Nodes will be merged based on this");
assertEquals(mergeTypeParameter.getParameterValue().getOptions(), List.of(TestMergeType.NAME, "Geospatial Distance", "Identifier Prefix Length", "Identifier Suffix Length", "Supported Type"));
assertEquals(mergeTypeParameter.getProperty("choices").getClass(), Object.class);
final PluginParameter<IntegerParameterValue> thresholdParameter = (PluginParameter<IntegerParameterValue>) parameters.get("MergeNodesPlugin.threshold");
assertEquals(thresholdParameter.getName(), "Threshold");
assertEquals(thresholdParameter.getDescription(), "The maximum nodes to merge");
assertFalse(thresholdParameter.isEnabled());
final PluginParameter<SingleChoiceParameterValue> mergingRuleParameter = (PluginParameter<SingleChoiceParameterValue>) parameters.get("MergeNodesPlugin.merger");
assertEquals(mergingRuleParameter.getName(), "Merging Rule");
assertEquals(mergingRuleParameter.getDescription(), "The rule deciding how attributes are merged");
assertEquals(mergingRuleParameter.getParameterValue().getOptions(), List.of("Retain lead vertex attributes if present", "Retain lead vertex attributes always", "Copy merged vertex attributes if present", "Copy merged vertex attributes always"));
assertEquals(mergingRuleParameter.getProperty("choices").getClass(), Object.class);
assertEquals(mergingRuleParameter.getParameterValue().getChoice(), "Retain lead vertex attributes if present");
assertFalse(mergingRuleParameter.isEnabled());
final PluginParameter<SingleChoiceParameterValue> leadNodeParameter = (PluginParameter<SingleChoiceParameterValue>) parameters.get("MergeNodesPlugin.lead");
assertEquals(leadNodeParameter.getName(), "Lead Node");
assertEquals(leadNodeParameter.getDescription(), "The rule deciding how to choose the lead node");
assertEquals(leadNodeParameter.getParameterValue().getOptions(), List.of("Longest Value", "Shortest Value", "Ask Me"));
assertEquals(leadNodeParameter.getProperty("choices").getClass(), Object.class);
assertEquals(leadNodeParameter.getParameterValue().getChoice(), "Longest Value");
assertFalse(leadNodeParameter.isEnabled());
final PluginParameter<BooleanParameterValue> selectedOnlyParameter = (PluginParameter<BooleanParameterValue>) parameters.get("MergeNodesPlugin.selected");
assertEquals(selectedOnlyParameter.getName(), "Selected Only");
assertEquals(selectedOnlyParameter.getDescription(), "Merge Only Selected Nodes");
assertTrue(selectedOnlyParameter.getBooleanValue());
assertFalse(selectedOnlyParameter.isEnabled());
final Map<String, PluginParameterController> controllers = actual.getControllers();
assertEquals(controllers.keySet(), Set.of("MergeNodesPlugin.merge_type"));
}
use of au.gov.asd.tac.constellation.plugins.parameters.types.BooleanParameterType.BooleanParameterValue in project constellation by constellation-app.
the class ExtractWordsFromTextPluginNGTest method testUpdateParameters.
/**
* Test updateParameters
*/
@Test
public void testUpdateParameters() {
ExtractWordsFromTextPlugin instance = new ExtractWordsFromTextPlugin();
PluginParameters parameters = new PluginParameters();
final PluginParameter<SingleChoiceParameterValue> attributeType = SingleChoiceParameterType.build(ATTRIBUTE_PARAMETER_ID);
parameters.addParameter(attributeType);
final PluginParameter<StringParameterValue> textParameter = StringParameterType.build(WORDS_PARAMETER_ID);
textParameter.setStringValue("text");
parameters.addParameter(textParameter);
final PluginParameter<BooleanParameterValue> useRegexParameter = BooleanParameterType.build(USE_REGEX_PARAMETER_ID);
useRegexParameter.setBooleanValue(true);
parameters.addParameter(useRegexParameter);
Graph graph1 = new DualGraph(graph.getSchema(), graph);
instance.updateParameters(graph1, parameters);
assertEquals(parameters.getParameters().size(), 3);
assertTrue(parameters.hasParameter(ExtractWordsFromTextPlugin.ATTRIBUTE_PARAMETER_ID));
assertEquals(parameters.getParameters().get(ExtractWordsFromTextPlugin.WORDS_PARAMETER_ID).getStringValue(), "text");
assertEquals(parameters.getParameters().get(ExtractWordsFromTextPlugin.USE_REGEX_PARAMETER_ID).getBooleanValue(), true);
assertFalse(parameters.hasParameter(ExtractWordsFromTextPlugin.SELECTED_ONLY_PARAMETER_ID));
parameters = instance.createParameters();
instance.updateParameters(graph1, parameters);
assertEquals(parameters.getParameters().size(), 11);
assertTrue(parameters.hasParameter(ExtractWordsFromTextPlugin.SELECTED_ONLY_PARAMETER_ID));
}
use of au.gov.asd.tac.constellation.plugins.parameters.types.BooleanParameterType.BooleanParameterValue 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.BooleanParameterType.BooleanParameterValue in project constellation by constellation-app.
the class CloseGraphPlugin method createParameters.
@Override
public PluginParameters createParameters() {
final PluginParameters parameters = new PluginParameters();
final PluginParameter<StringParameterValue> graphIdParameter = StringParameterType.build(GRAPH_PARAMETER_ID);
graphIdParameter.setName("graphId");
graphIdParameter.setDescription("The Id of the graph");
parameters.addParameter(graphIdParameter);
final PluginParameter<BooleanParameterValue> forcedParameter = BooleanParameterType.build(FORCED_PARAMETER_ID);
forcedParameter.setName("forced");
forcedParameter.setDescription("Whether the graph will be force closed or not");
forcedParameter.setBooleanValue(false);
parameters.addParameter(forcedParameter);
return parameters;
}
use of au.gov.asd.tac.constellation.plugins.parameters.types.BooleanParameterType.BooleanParameterValue in project constellation by constellation-app.
the class CreateTransactionPlugin method createParameters.
@Override
public PluginParameters createParameters() {
final PluginParameters parameters = new PluginParameters();
final PluginParameter<IntegerParameterValue> sourceParam = IntegerParameterType.build(SOURCE_PARAMETER_ID);
sourceParam.setName("Source");
sourceParam.setDescription("The source vertex id");
sourceParam.setIntegerValue(0);
parameters.addParameter(sourceParam);
final PluginParameter<IntegerParameterValue> destinationParam = IntegerParameterType.build(DESTINATION_PARAMETER_ID);
destinationParam.setName("Destination");
destinationParam.setDescription("The destination vertex id");
destinationParam.setIntegerValue(0);
parameters.addParameter(destinationParam);
final PluginParameter<BooleanParameterValue> directedParam = BooleanParameterType.build(DIRECTED_PARAMETER_ID);
directedParam.setName("Directed");
directedParam.setDescription("If True then make it a directed transaction, default is True");
directedParam.setBooleanValue(true);
parameters.addParameter(directedParam);
return parameters;
}
Aggregations