Search in sources :

Example 6 with ParameterChange

use of au.gov.asd.tac.constellation.plugins.parameters.ParameterChange 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 7 with ParameterChange

use of au.gov.asd.tac.constellation.plugins.parameters.ParameterChange in project constellation by constellation-app.

the class CompareGraphPlugin method createParameters.

@Override
public PluginParameters createParameters() {
    final PluginParameters parameters = new PluginParameters();
    final PluginParameter<SingleChoiceParameterValue> originalGraph = SingleChoiceParameterType.build(ORIGINAL_GRAPH_PARAMETER_ID);
    originalGraph.setName("Original Graph");
    originalGraph.setDescription("The graph used as the starting point for the comparison");
    parameters.addParameter(originalGraph);
    // Controller listens for value change so that the compare graph cannot be compared against itself
    parameters.addController(ORIGINAL_GRAPH_PARAMETER_ID, (PluginParameter<?> master, Map<String, PluginParameter<?>> params, ParameterChange change) -> {
        // When value has changed, remove choice from the comparison graph dialog
        if (change == ParameterChange.VALUE) {
            final String originalGraphName = params.get(ORIGINAL_GRAPH_PARAMETER_ID).getStringValue();
            if (originalGraphName != null) {
                final List<String> graphNames = new ArrayList<>();
                final Map<String, Graph> allGraphs = GraphNode.getAllGraphs();
                if (allGraphs != null) {
                    for (final String graphId : allGraphs.keySet()) {
                        graphNames.add(GraphNode.getGraphNode(graphId).getDisplayName());
                    }
                }
                // remove the current original graph selection from the list of graphs allowed to compare with
                graphNames.remove(originalGraphName);
                // sort drop down list
                graphNames.sort(String::compareTo);
                // COMPARE_GRAPH_PARAMETER_ID will always be of type SingleChoiceParameterValue
                @SuppressWarnings("unchecked") final PluginParameter<SingleChoiceParameterValue> compareParamter = (PluginParameter<SingleChoiceParameterValue>) params.get(COMPARE_GRAPH_PARAMETER_ID);
                SingleChoiceParameterType.setOptions(compareParamter, graphNames);
            }
        }
    });
    final PluginParameter<SingleChoiceParameterValue> compareGraph = SingleChoiceParameterType.build(COMPARE_GRAPH_PARAMETER_ID);
    compareGraph.setName("Compare With Graph");
    compareGraph.setDescription("The graph used to compare against the original graph");
    parameters.addParameter(compareGraph);
    final PluginParameter<MultiChoiceParameterValue> ignoreVertexAttributes = MultiChoiceParameterType.build(IGNORE_VERTEX_ATTRIBUTES_PARAMETER_ID);
    ignoreVertexAttributes.setName("Ignore Node Attributes");
    ignoreVertexAttributes.setDescription("Ignore these attributes when comparing nodes");
    parameters.addParameter(ignoreVertexAttributes);
    final PluginParameter<MultiChoiceParameterValue> ignoreTransactionAttributes = MultiChoiceParameterType.build(IGNORE_TRANSACTION_ATTRIBUTES_PARAMETER_ID);
    ignoreTransactionAttributes.setName("Ignore Transaction Attributes");
    ignoreTransactionAttributes.setDescription("Ignore these attributes when comparing transactions");
    parameters.addParameter(ignoreTransactionAttributes);
    final PluginParameter<ColorParameterValue> addedColour = ColorParameterType.build(ADDED_COLOUR_PARAMETER_ID);
    addedColour.setName("Added Color");
    addedColour.setDescription("The colour to indicate a node/transaction addition");
    addedColour.setColorValue(ConstellationColor.GREEN);
    parameters.addParameter(addedColour);
    final PluginParameter<ColorParameterValue> removedColour = ColorParameterType.build(REMOVED_COLOUR_PARAMETER_ID);
    removedColour.setName("Removed Color");
    removedColour.setDescription("The colour to indicate a node/transaction removal");
    removedColour.setColorValue(ConstellationColor.RED);
    parameters.addParameter(removedColour);
    final PluginParameter<ColorParameterValue> changedColour = ColorParameterType.build(CHANGED_COLOUR_PARAMETER_ID);
    changedColour.setName("Changed Color");
    changedColour.setDescription("The colour to indicate a node/transaction change");
    changedColour.setColorValue(ConstellationColor.YELLOW);
    parameters.addParameter(changedColour);
    final PluginParameter<ColorParameterValue> unchangedColour = ColorParameterType.build(UNCHANGED_COLOUR_PARAMETER_ID);
    unchangedColour.setName("Unchanged Color");
    unchangedColour.setDescription("The colour to indicate no node/transaction change");
    unchangedColour.setColorValue(ConstellationColor.GREY);
    parameters.addParameter(unchangedColour);
    return parameters;
}
Also used : ParameterChange(au.gov.asd.tac.constellation.plugins.parameters.ParameterChange) MultiChoiceParameterValue(au.gov.asd.tac.constellation.plugins.parameters.types.MultiChoiceParameterType.MultiChoiceParameterValue) ArrayList(java.util.ArrayList) ColorParameterValue(au.gov.asd.tac.constellation.plugins.parameters.types.ColorParameterType.ColorParameterValue) WritableGraph(au.gov.asd.tac.constellation.graph.WritableGraph) ReadableGraph(au.gov.asd.tac.constellation.graph.ReadableGraph) Graph(au.gov.asd.tac.constellation.graph.Graph) PluginParameters(au.gov.asd.tac.constellation.plugins.parameters.PluginParameters) PluginParameter(au.gov.asd.tac.constellation.plugins.parameters.PluginParameter) HashMap(java.util.HashMap) Map(java.util.Map) SingleChoiceParameterValue(au.gov.asd.tac.constellation.plugins.parameters.types.SingleChoiceParameterType.SingleChoiceParameterValue)

Example 8 with ParameterChange

use of au.gov.asd.tac.constellation.plugins.parameters.ParameterChange in project constellation by constellation-app.

the class DatetimeAttributeTranslator method createParameters.

@Override
public PluginParameters createParameters() {
    final PluginParameters parameters = new PluginParameters();
    final PluginParameter<SingleChoiceParameterValue> formatParam = SingleChoiceParameterType.build(FORMAT_PARAMETER_ID);
    formatParam.setName("Datetime Format");
    formatParam.setDescription("The datetime format");
    final List<String> datetimeLabels = new ArrayList<>(DATETIME_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 datetime format");
    // customParam should be enabled and editable if "CUSTOM" format has been specified.
    customParam.setEnabled(formatParam.getStringValue().equals(CUSTOM));
    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(master.getStringValue().equals(CUSTOM));
        }
    });
    return parameters;
}
Also used : ParameterChange(au.gov.asd.tac.constellation.plugins.parameters.ParameterChange) ArrayList(java.util.ArrayList) StringParameterValue(au.gov.asd.tac.constellation.plugins.parameters.types.StringParameterValue) 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)

Aggregations

ParameterChange (au.gov.asd.tac.constellation.plugins.parameters.ParameterChange)8 PluginParameter (au.gov.asd.tac.constellation.plugins.parameters.PluginParameter)8 PluginParameters (au.gov.asd.tac.constellation.plugins.parameters.PluginParameters)8 Map (java.util.Map)8 SingleChoiceParameterValue (au.gov.asd.tac.constellation.plugins.parameters.types.SingleChoiceParameterType.SingleChoiceParameterValue)7 ArrayList (java.util.ArrayList)7 LinkedHashMap (java.util.LinkedHashMap)5 IntegerParameterValue (au.gov.asd.tac.constellation.plugins.parameters.types.IntegerParameterType.IntegerParameterValue)4 StringParameterValue (au.gov.asd.tac.constellation.plugins.parameters.types.StringParameterValue)4 BooleanParameterValue (au.gov.asd.tac.constellation.plugins.parameters.types.BooleanParameterType.BooleanParameterValue)3 MultiChoiceParameterValue (au.gov.asd.tac.constellation.plugins.parameters.types.MultiChoiceParameterType.MultiChoiceParameterValue)3 ColorParameterValue (au.gov.asd.tac.constellation.plugins.parameters.types.ColorParameterType.ColorParameterValue)2 HashMap (java.util.HashMap)2 Graph (au.gov.asd.tac.constellation.graph.Graph)1 GraphElementType (au.gov.asd.tac.constellation.graph.GraphElementType)1 ReadableGraph (au.gov.asd.tac.constellation.graph.ReadableGraph)1 WritableGraph (au.gov.asd.tac.constellation.graph.WritableGraph)1 SchemaTransactionType (au.gov.asd.tac.constellation.graph.schema.type.SchemaTransactionType)1 SchemaVertexType (au.gov.asd.tac.constellation.graph.schema.type.SchemaVertexType)1 DateTimeRangeParameterValue (au.gov.asd.tac.constellation.plugins.parameters.types.DateTimeRangeParameterType.DateTimeRangeParameterValue)1