use of au.gov.asd.tac.constellation.plugins.parameters.types.SingleChoiceParameterType.SingleChoiceParameterValue in project constellation by constellation-app.
the class SplitNodesPlugin method updateParameters.
@Override
public void updateParameters(final Graph graph, final PluginParameters parameters) {
if (parameters != null && parameters.getParameters() != null && !parameters.getParameters().get(DUPLICATE_TRANSACTIONS_PARAMETER_ID).getBooleanValue()) {
final List<String> types = new ArrayList<>();
if (graph != null && graph.getSchema() != null) {
for (final SchemaTransactionType type : SchemaTransactionTypeUtilities.getTypes(graph.getSchema().getFactory().getRegisteredConcepts())) {
types.add(type.getName());
}
if (!types.isEmpty()) {
types.sort(String::compareTo);
}
}
// TRANSACTION_TYPE_PARAMETER is always of type SingleChoiceParameter
@SuppressWarnings("unchecked") final PluginParameter<SingleChoiceParameterValue> transactionType = (PluginParameter<SingleChoiceParameterValue>) parameters.getParameters().get(TRANSACTION_TYPE_PARAMETER_ID);
SingleChoiceParameterType.setOptions(transactionType, types);
transactionType.suppressEvent(true, new ArrayList<>());
if (transactionType.getSingleChoice() == null && types.contains(AnalyticConcept.TransactionType.CORRELATION.getName())) {
SingleChoiceParameterType.setChoice(transactionType, AnalyticConcept.TransactionType.CORRELATION.getName());
}
transactionType.suppressEvent(false, new ArrayList<>());
transactionType.setObjectValue(parameters.getObjectValue(TRANSACTION_TYPE_PARAMETER_ID));
}
}
use of au.gov.asd.tac.constellation.plugins.parameters.types.SingleChoiceParameterType.SingleChoiceParameterValue 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.SingleChoiceParameterType.SingleChoiceParameterValue 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.SingleChoiceParameterType.SingleChoiceParameterValue 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.SingleChoiceParameterType.SingleChoiceParameterValue in project constellation by constellation-app.
the class DateAttributeTranslator method createParameters.
@Override
public PluginParameters createParameters() {
final PluginParameters parameters = new PluginParameters();
final PluginParameter<SingleChoiceParameterValue> formatParam = SingleChoiceParameterType.build(FORMAT_PARAMETER_ID);
formatParam.setName("Date Format");
formatParam.setDescription("The date format");
final List<String> datetimeLabels = new ArrayList<>(DATE_FORMATS.keySet());
SingleChoiceParameterType.setOptions(formatParam, datetimeLabels);
SingleChoiceParameterType.setChoice(formatParam, datetimeLabels.get(0));
parameters.addParameter(formatParam);
final PluginParameter<StringParameterValue> customParam = StringParameterType.build(CUSTOM_PARAMETER_ID);
customParam.setName("Custom Format");
customParam.setDescription("A custom date format");
customParam.setEnabled(false);
customParam.setStringValue("");
parameters.addParameter(customParam);
parameters.addController(FORMAT_PARAMETER_ID, (final PluginParameter<?> master, final Map<String, PluginParameter<?>> params, final ParameterChange change) -> {
if (change == ParameterChange.VALUE) {
final PluginParameter<?> slave = params.get(CUSTOM_PARAMETER_ID);
slave.setEnabled("CUSTOM".equals(master.getStringValue()));
}
});
return parameters;
}
Aggregations