use of au.gov.asd.tac.constellation.plugins.parameters.types.SingleChoiceParameterType.SingleChoiceParameterValue in project constellation by constellation-app.
the class ExtractWordsFromTextPlugin method updateParameters.
/**
* Updating parameters to retrieve the transaction attributes
*
* @param graph
* @param parameters
*/
@Override
public void updateParameters(final Graph graph, final PluginParameters parameters) {
final List<String> attributes = new ArrayList<>();
if (graph != null) {
final ReadableGraph readableGraph = graph.getReadableGraph();
try {
final int attributeCount = readableGraph.getAttributeCount(GraphElementType.TRANSACTION);
for (int attributePosition = 0; attributePosition < attributeCount; attributePosition++) {
final int attributeId = readableGraph.getAttribute(GraphElementType.TRANSACTION, attributePosition);
final String attributeType = readableGraph.getAttributeType(attributeId);
if (attributeType.equals(StringAttributeDescription.ATTRIBUTE_NAME)) {
attributes.add(readableGraph.getAttributeName(attributeId));
}
}
} finally {
readableGraph.release();
}
}
attributes.sort(String::compareTo);
if (parameters != null && parameters.getParameters() != null) {
// ATTRIBUTE_PARAMETER will always be of type SingleChoiceParameter
@SuppressWarnings("unchecked") final PluginParameter<SingleChoiceParameterValue> contentAttribute = (PluginParameter<SingleChoiceParameterValue>) parameters.getParameters().get(ATTRIBUTE_PARAMETER_ID);
SingleChoiceParameterType.setOptions(contentAttribute, attributes);
contentAttribute.suppressEvent(true, new ArrayList<>());
if (contentAttribute.getSingleChoice() == null && attributes.contains(ContentConcept.TransactionAttribute.CONTENT.getName())) {
SingleChoiceParameterType.setChoice(contentAttribute, ContentConcept.TransactionAttribute.CONTENT.getName());
}
contentAttribute.suppressEvent(false, new ArrayList<>());
contentAttribute.setObjectValue(parameters.getObjectValue(ATTRIBUTE_PARAMETER_ID));
}
}
use of au.gov.asd.tac.constellation.plugins.parameters.types.SingleChoiceParameterType.SingleChoiceParameterValue in project constellation by constellation-app.
the class MergeTransactionsPlugin method createParameters.
@Override
public PluginParameters createParameters() {
PluginParameters params = new PluginParameters();
final PluginParameter<SingleChoiceParameterValue> mergeType = SingleChoiceParameterType.build(MERGE_TYPE_PARAMETER_ID);
mergeType.setName("Merge By");
mergeType.setDescription("Transactions will be merged based on this");
List<String> mergeTypes = new ArrayList<>(MERGE_TYPES.keySet());
SingleChoiceParameterType.setOptions(mergeType, mergeTypes);
params.addParameter(mergeType);
final PluginParameter<IntegerParameterValue> threshold = IntegerParameterType.build(THRESHOLD_PARAMETER_ID);
threshold.setName("Threshold");
threshold.setIntegerValue(0);
IntegerParameterType.setMinimum(threshold, 0);
threshold.setEnabled(false);
params.addParameter(threshold);
final PluginParameter<SingleChoiceParameterValue> mergingRule = SingleChoiceParameterType.build(MERGER_PARAMETER_ID);
mergingRule.setName("Merging Rule");
mergingRule.setDescription("The rule deciding how attributes are merged");
List<String> mergerNames = new ArrayList<>(MERGERS.keySet());
SingleChoiceParameterType.setOptions(mergingRule, mergerNames);
SingleChoiceParameterType.setChoice(mergingRule, mergerNames.get(0));
mergingRule.setEnabled(false);
params.addParameter(mergingRule);
final PluginParameter<SingleChoiceParameterValue> leadParam = SingleChoiceParameterType.build(LEAD_PARAMETER_ID);
leadParam.setName("Lead Transaction");
leadParam.setDescription("The rule deciding how to choose the lead transaction");
List<String> leadTransactionChooserNames = new ArrayList<>(LEAD_TRANSACTION_CHOOSERS.keySet());
SingleChoiceParameterType.setOptions(leadParam, leadTransactionChooserNames);
SingleChoiceParameterType.setChoice(leadParam, leadTransactionChooserNames.get(0));
leadParam.setEnabled(false);
params.addParameter(leadParam);
final PluginParameter<BooleanParameterValue> selectedParam = BooleanParameterType.build(SELECTED_PARAMETER_ID);
selectedParam.setName("Selected Only");
selectedParam.setDescription("Merge Only Selected Transactions");
selectedParam.setBooleanValue(false);
selectedParam.setEnabled(false);
params.addParameter(selectedParam);
params.addController(MERGE_TYPE_PARAMETER_ID, (final PluginParameter<?> master, final Map<String, PluginParameter<?>> parameters, final ParameterChange change) -> {
if (change == ParameterChange.VALUE) {
final String selectedMergeType = parameters.get(MERGE_TYPE_PARAMETER_ID).getStringValue();
if (MERGE_TYPES.containsKey(selectedMergeType)) {
final MergeTransactionType mergeTransactionTypeSelected = MERGE_TYPES.get(selectedMergeType);
mergeTransactionTypeSelected.updateParameters(parameters);
}
}
});
return params;
}
use of au.gov.asd.tac.constellation.plugins.parameters.types.SingleChoiceParameterType.SingleChoiceParameterValue in project constellation by constellation-app.
the class SelectTopNPlugin method createParameters.
@Override
public PluginParameters createParameters() {
final PluginParameters params = new PluginParameters();
final List<String> modes = new ArrayList<>();
modes.add(NODE);
modes.add(TRANSACTION);
final PluginParameter<SingleChoiceParameterValue> modeParameter = SingleChoiceParameterType.build(MODE_PARAMETER_ID);
modeParameter.setName("Mode");
modeParameter.setDescription("Select either the Node or Transaction mode");
SingleChoiceParameterType.setOptions(modeParameter, modes);
params.addParameter(modeParameter);
final PluginParameter<SingleChoiceParameterValue> typeCategoryParameter = SingleChoiceParameterType.build(TYPE_CATEGORY_PARAMETER_ID);
typeCategoryParameter.setName("Type Category");
typeCategoryParameter.setDescription("The high level type category");
params.addParameter(typeCategoryParameter);
final PluginParameter<MultiChoiceParameterValue> typeParameter = MultiChoiceParameterType.build(TYPE_PARAMETER_ID);
typeParameter.setName("Specific Types");
typeParameter.setDescription("The specific types to include when calculating the top N");
params.addParameter(typeParameter);
final PluginParameter<IntegerParameterValue> limitParameter = IntegerParameterType.build(LIMIT_PARAMETER_ID);
limitParameter.setName("Limit");
limitParameter.setDescription("The limit, default being 10");
limitParameter.setIntegerValue(10);
params.addParameter(limitParameter);
params.addController(MODE_PARAMETER_ID, (PluginParameter<?> master, Map<String, PluginParameter<?>> parameters, ParameterChange change) -> {
if (change == ParameterChange.VALUE) {
final String mode = parameters.get(MODE_PARAMETER_ID).getStringValue();
if (mode != null) {
final List<String> types = new ArrayList<>();
switch(mode) {
case NODE:
for (final SchemaVertexType type : SchemaVertexTypeUtilities.getTypes()) {
if (type.isTopLevelType()) {
types.add(type.getName());
}
}
break;
case TRANSACTION:
for (final SchemaTransactionType type : SchemaTransactionTypeUtilities.getTypes()) {
if (type.isTopLevelType()) {
types.add(type.getName());
}
}
break;
default:
LOGGER.severe("Invalid mode provided. Mode values accepted are " + NODE + " or " + TRANSACTION);
}
// TYPE_CATEGORY_PARAMETER will always be of type SingleChoiceParameter
@SuppressWarnings("unchecked") final PluginParameter<SingleChoiceParameterValue> typeCategoryParamter = (PluginParameter<SingleChoiceParameterValue>) parameters.get(TYPE_CATEGORY_PARAMETER_ID);
types.sort(String::compareTo);
SingleChoiceParameterType.setOptions(typeCategoryParamter, types);
}
}
});
params.addController(TYPE_CATEGORY_PARAMETER_ID, (PluginParameter<?> master, Map<String, PluginParameter<?>> parameters, ParameterChange change) -> {
if (change == ParameterChange.VALUE) {
final String mode = parameters.get(MODE_PARAMETER_ID).getStringValue();
final String typeCategory = parameters.get(TYPE_CATEGORY_PARAMETER_ID).getStringValue();
if (mode != null && typeCategory != null) {
final List<String> types = new ArrayList<>();
switch(mode) {
case NODE:
final SchemaVertexType typeCategoryVertexType = SchemaVertexTypeUtilities.getType(typeCategory);
for (final SchemaVertexType type : SchemaVertexTypeUtilities.getTypes()) {
if (type.getSuperType().equals(typeCategoryVertexType)) {
types.add(type.getName());
}
}
break;
case TRANSACTION:
final SchemaTransactionType typeCategoryTransactionType = SchemaTransactionTypeUtilities.getType(typeCategory);
for (final SchemaTransactionType type : SchemaTransactionTypeUtilities.getTypes()) {
if (type.getSuperType().equals(typeCategoryTransactionType)) {
types.add(type.getName());
}
}
break;
default:
break;
}
// update the sub level types
// TYPE_PARAMETER will always be of type MultiChoiceParameter
@SuppressWarnings("unchecked") final PluginParameter<MultiChoiceParameterValue> typeParamter = (PluginParameter<MultiChoiceParameterValue>) parameters.get(TYPE_PARAMETER_ID);
types.sort(String::compareTo);
MultiChoiceParameterType.setOptions(typeParamter, types);
MultiChoiceParameterType.setChoices(typeParamter, types);
}
}
});
return params;
}
use of au.gov.asd.tac.constellation.plugins.parameters.types.SingleChoiceParameterType.SingleChoiceParameterValue in project constellation by constellation-app.
the class FilterPlugin method createParameters.
@Override
public PluginParameters createParameters() {
final PluginParameters parameters = new PluginParameters();
final PluginParameter<SingleChoiceParameterValue> filterType = SingleChoiceParameterType.build(FILTER_TYPE_PARAMETER_ID, FilterTypeParameterValue.class);
filterType.setName("Filter Type");
filterType.setDescription("The name of the filter");
final List<FilterTypeParameterValue> filterTypes = new ArrayList<>();
filterTypes.add(new FilterTypeParameterValue(FilterType.REMOVE_FILTER));
filterTypes.add(new FilterTypeParameterValue(FilterType.DESELECT_FILTER));
filterTypes.add(new FilterTypeParameterValue(FilterType.SELECT_FILTER));
SingleChoiceParameterType.setOptionsData(filterType, filterTypes);
SingleChoiceParameterType.setChoiceData(filterType, filterTypes.get(0));
parameters.addParameter(filterType);
return parameters;
}
use of au.gov.asd.tac.constellation.plugins.parameters.types.SingleChoiceParameterType.SingleChoiceParameterValue in project constellation by constellation-app.
the class SplitNodesPluginNGTest method testUpdateParameters.
/**
* Test of createParameters method, of class SplitNodesPlugin.
*/
@Test
public void testUpdateParameters() {
final SplitNodesPlugin instance = new SplitNodesPlugin();
final PluginParameters params = instance.createParameters();
final PluginParameter<SingleChoiceParameterValue> transactionTypeParam = (PluginParameter<SingleChoiceParameterValue>) params.getParameters().get(SplitNodesPlugin.TRANSACTION_TYPE_PARAMETER_ID);
assertTrue(SingleChoiceParameterType.getOptions(transactionTypeParam).isEmpty());
final Schema schema = SchemaFactoryUtilities.getSchemaFactory(AnalyticSchemaFactory.ANALYTIC_SCHEMA_ID).createSchema();
instance.updateParameters(new DualGraph(schema, graph), params);
// 9 is the number of transaction types in the analytic schema
assertEquals(SingleChoiceParameterType.getOptions(transactionTypeParam).size(), 9);
}
Aggregations