Search in sources :

Example 31 with SingleChoiceParameterValue

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));
    }
}
Also used : ReadableGraph(au.gov.asd.tac.constellation.graph.ReadableGraph) ArrayList(java.util.ArrayList) PluginParameter(au.gov.asd.tac.constellation.plugins.parameters.PluginParameter) SingleChoiceParameterValue(au.gov.asd.tac.constellation.plugins.parameters.types.SingleChoiceParameterType.SingleChoiceParameterValue)

Example 32 with SingleChoiceParameterValue

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;
}
Also used : ParameterChange(au.gov.asd.tac.constellation.plugins.parameters.ParameterChange) ArrayList(java.util.ArrayList) BooleanParameterValue(au.gov.asd.tac.constellation.plugins.parameters.types.BooleanParameterType.BooleanParameterValue) IntegerParameterValue(au.gov.asd.tac.constellation.plugins.parameters.types.IntegerParameterType.IntegerParameterValue) PluginParameters(au.gov.asd.tac.constellation.plugins.parameters.PluginParameters) PluginParameter(au.gov.asd.tac.constellation.plugins.parameters.PluginParameter) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) SingleChoiceParameterValue(au.gov.asd.tac.constellation.plugins.parameters.types.SingleChoiceParameterType.SingleChoiceParameterValue)

Example 33 with SingleChoiceParameterValue

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;
}
Also used : ParameterChange(au.gov.asd.tac.constellation.plugins.parameters.ParameterChange) SchemaVertexType(au.gov.asd.tac.constellation.graph.schema.type.SchemaVertexType) MultiChoiceParameterValue(au.gov.asd.tac.constellation.plugins.parameters.types.MultiChoiceParameterType.MultiChoiceParameterValue) ArrayList(java.util.ArrayList) SchemaTransactionType(au.gov.asd.tac.constellation.graph.schema.type.SchemaTransactionType) IntegerParameterValue(au.gov.asd.tac.constellation.plugins.parameters.types.IntegerParameterType.IntegerParameterValue) PluginParameters(au.gov.asd.tac.constellation.plugins.parameters.PluginParameters) PluginParameter(au.gov.asd.tac.constellation.plugins.parameters.PluginParameter) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) SingleChoiceParameterValue(au.gov.asd.tac.constellation.plugins.parameters.types.SingleChoiceParameterType.SingleChoiceParameterValue)

Example 34 with SingleChoiceParameterValue

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;
}
Also used : ArrayList(java.util.ArrayList) PluginParameters(au.gov.asd.tac.constellation.plugins.parameters.PluginParameters) SingleChoiceParameterValue(au.gov.asd.tac.constellation.plugins.parameters.types.SingleChoiceParameterType.SingleChoiceParameterValue)

Example 35 with SingleChoiceParameterValue

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);
}
Also used : Schema(au.gov.asd.tac.constellation.graph.schema.Schema) PluginParameters(au.gov.asd.tac.constellation.plugins.parameters.PluginParameters) PluginParameter(au.gov.asd.tac.constellation.plugins.parameters.PluginParameter) SingleChoiceParameterValue(au.gov.asd.tac.constellation.plugins.parameters.types.SingleChoiceParameterType.SingleChoiceParameterValue) DualGraph(au.gov.asd.tac.constellation.graph.locking.DualGraph) Test(org.testng.annotations.Test)

Aggregations

SingleChoiceParameterValue (au.gov.asd.tac.constellation.plugins.parameters.types.SingleChoiceParameterType.SingleChoiceParameterValue)37 PluginParameters (au.gov.asd.tac.constellation.plugins.parameters.PluginParameters)29 ArrayList (java.util.ArrayList)21 PluginParameter (au.gov.asd.tac.constellation.plugins.parameters.PluginParameter)19 BooleanParameterValue (au.gov.asd.tac.constellation.plugins.parameters.types.BooleanParameterType.BooleanParameterValue)13 IntegerParameterValue (au.gov.asd.tac.constellation.plugins.parameters.types.IntegerParameterType.IntegerParameterValue)12 StringParameterValue (au.gov.asd.tac.constellation.plugins.parameters.types.StringParameterValue)9 ParameterChange (au.gov.asd.tac.constellation.plugins.parameters.ParameterChange)8 Map (java.util.Map)8 ReadableGraph (au.gov.asd.tac.constellation.graph.ReadableGraph)6 MultiChoiceParameterValue (au.gov.asd.tac.constellation.plugins.parameters.types.MultiChoiceParameterType.MultiChoiceParameterValue)6 LinkedHashMap (java.util.LinkedHashMap)5 Test (org.testng.annotations.Test)5 Graph (au.gov.asd.tac.constellation.graph.Graph)4 FloatParameterValue (au.gov.asd.tac.constellation.plugins.parameters.types.FloatParameterType.FloatParameterValue)4 DualGraph (au.gov.asd.tac.constellation.graph.locking.DualGraph)3 ParameterValue (au.gov.asd.tac.constellation.plugins.parameters.types.ParameterValue)3 GraphElementType (au.gov.asd.tac.constellation.graph.GraphElementType)2 WritableGraph (au.gov.asd.tac.constellation.graph.WritableGraph)2 SchemaTransactionType (au.gov.asd.tac.constellation.graph.schema.type.SchemaTransactionType)2