use of au.gov.asd.tac.constellation.plugins.parameters.PluginParameter 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.PluginParameter 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;
}
use of au.gov.asd.tac.constellation.plugins.parameters.PluginParameter in project constellation by constellation-app.
the class MapViewTopComponent method createParameters.
private PluginParameters createParameters() {
final PluginParameters parameters = new PluginParameters();
final PluginParameter<SingleChoiceParameterValue> geoTypeParameter = SingleChoiceParameterType.build(PARAMETER_TYPE);
geoTypeParameter.setName("Geo Type");
SingleChoiceParameterType.setOptions(geoTypeParameter, Arrays.asList(GEO_TYPE_COORDINATE, GEO_TYPE_GEOHASH, GEO_TYPE_MGRS));
SingleChoiceParameterType.setChoice(geoTypeParameter, GEO_TYPE_COORDINATE);
parameters.addParameter(geoTypeParameter);
final PluginParameter<StringParameterValue> locationParameter = StringParameterType.build(PARAMETER_LOCATION);
locationParameter.setName("Location");
locationParameter.setDescription("Enter a coordinate in decimal degrees (and optionally " + "a radius in kilometers) with components separated by spaces or commas");
locationParameter.setStringValue(null);
parameters.addParameter(locationParameter);
PluginParameterController controller = ((master, params, change) -> {
// master will need to be of type SingleChoiceParameter
@SuppressWarnings("unchecked") final PluginParameter<SingleChoiceParameterValue> typedMaster = (PluginParameter<SingleChoiceParameterValue>) master;
switch(SingleChoiceParameterType.getChoice(typedMaster)) {
case GEO_TYPE_COORDINATE:
params.get(PARAMETER_LOCATION).setDescription("Enter a coordinate in decimal degrees (and optionally a radius " + "in kilometers) with components separated by spaces or commas");
break;
case GEO_TYPE_GEOHASH:
params.get(PARAMETER_LOCATION).setDescription("Enter a base-16 geohash value");
break;
case GEO_TYPE_MGRS:
params.get(PARAMETER_LOCATION).setDescription("Enter an MGRS value");
break;
default:
break;
}
});
parameters.addController(PARAMETER_TYPE, controller);
return parameters;
}
use of au.gov.asd.tac.constellation.plugins.parameters.PluginParameter in project constellation by constellation-app.
the class DelegatingConstellationLogger method sanitiseParameters.
/**
* Sanitise parameters, including removing passwords.
*
* @param parameters The parameters to sanitise.
* @return a sanitised copy of the parameters.
*/
private static PluginParameters sanitiseParameters(final PluginParameters parameters) {
if (parameters == null) {
return null;
}
final PluginParameters sanitisedParameters = parameters.copy();
final Map<String, PluginParameter<?>> parametersMap = sanitisedParameters.getParameters();
parametersMap.keySet().stream().filter(key -> (parametersMap.get(key).getType().getId().equals(PasswordParameterType.ID))).forEachOrdered(key -> parametersMap.get(key).setStringValue("*******"));
return sanitisedParameters;
}
use of au.gov.asd.tac.constellation.plugins.parameters.PluginParameter in project constellation by constellation-app.
the class BooleanParameterTypeNGTest method testBuild_String.
/**
* Test of build method, of class BooleanParameterType.
*/
@Test
public void testBuild_String() {
System.out.println("build_string");
String id = "booleanParameter";
PluginParameter result = BooleanParameterType.build(id);
BooleanParameterValue expectedValue = new BooleanParameterValue();
assertEquals(result.getId(), id);
assertTrue(result.getType() instanceof BooleanParameterType);
assertEquals(result.getParameterValue(), expectedValue);
}
Aggregations