use of au.gov.asd.tac.constellation.graph.GraphElementType in project constellation by constellation-app.
the class TestParametersPlugin method createParameters.
@Override
public PluginParameters createParameters() {
final PluginParameters params = new PluginParameters();
final String css = TestParametersPlugin.class.getResource("resources/test.css").toExternalForm();
final BooleanParameterValue selectedpv = new BooleanParameterValue(true);
selectedpv.setGuiInit(control -> {
final CheckBox field = (CheckBox) control;
field.getStylesheets().add(css);
});
final PluginParameter<BooleanParameterValue> selected = BooleanParameterType.build(SELECTED_PARAMETER_ID, selectedpv);
selected.setName("Use selected");
selected.setDescription("Only use selected elements");
params.addParameter(selected);
final PluginParameter<StringParameterValue> queryName = CoreGlobalParameters.QUERY_NAME_PARAMETER;
params.addParameter(queryName);
final PluginParameter<DateTimeRangeParameterValue> dt = CoreGlobalParameters.DATETIME_RANGE_PARAMETER;
params.addParameter(dt);
final PluginParameter<StringParameterValue> string1 = StringParameterType.build(TEST1_PARAMETER_ID);
string1.setName("Test1");
string1.setDescription("A test string");
string1.setStringValue("Plugh.");
params.addParameter(string1);
final StringParameterValue string2pv = new StringParameterValue();
string2pv.setGuiInit(control -> {
final TextArea field = (TextArea) control;
field.getStylesheets().add(css);
});
final PluginParameter<StringParameterValue> string2 = StringParameterType.build(TEST2_PARAMETER_ID, string2pv);
string2.setName("Test2");
string2.setDescription("A two line test string");
StringParameterType.setLines(string2, 2);
params.addParameter(string2);
final PluginParameter<PasswordParameterValue> passwd = PasswordParameterType.build(PASSWORD_PARAMETER_ID);
passwd.setName("Password");
passwd.setDescription("Everyone needs a password");
params.addParameter(passwd);
final PluginParameter<LocalDateParameterValue> date = LocalDateParameterType.build(LOCAL_DATE_PARAMETER_ID);
date.setName("Date");
date.setDescription("Pick a day");
date.setLocalDateValue(LocalDate.of(2001, Month.JANUARY, 1));
params.addParameter(date);
final List<GraphElementTypeParameterValue> elementTypeOptions = new ArrayList<>();
for (final GraphElementType elementType : GraphElementType.values()) {
elementTypeOptions.add(new GraphElementTypeParameterValue(elementType));
}
final PluginParameter<SingleChoiceParameterValue> elementType = SingleChoiceParameterType.build(ELEMENT_TYPE_PARAMETER_ID, GraphElementTypeParameterValue.class);
elementType.setName("Graph element type");
elementType.setDescription("Graph element type");
SingleChoiceParameterType.setOptionsData(elementType, elementTypeOptions);
params.addParameter(elementType);
// A single choice list with a subtype of String.
final SingleChoiceParameterValue robotpv = new SingleChoiceParameterValue(StringParameterValue.class);
robotpv.setGuiInit(control -> {
// control will be of type ComboBox<ParameterValue> which extends from Region
@SuppressWarnings("unchecked") final ComboBox<ParameterValue> field = (ComboBox<ParameterValue>) control;
final Image img = new Image(ALIEN_ICON);
field.setCellFactory((ListView<ParameterValue> param) -> new ListCell<ParameterValue>() {
@Override
protected void updateItem(final ParameterValue item, final boolean empty) {
super.updateItem(item, empty);
this.setText(empty ? "" : item.toString());
final float f = empty ? 0 : item.toString().length() / 11F;
final Color c = Color.color(1 - f / 2F, 0, 0);
setTextFill(c);
setGraphic(new ImageView(img));
}
});
});
final PluginParameter<SingleChoiceParameterValue> robotOptions = SingleChoiceParameterType.build(ROBOT_PARAMETER_ID, robotpv);
robotOptions.setName("Robot options");
robotOptions.setDescription("A list of robots to choose from");
// Use the helper method to add string options.
SingleChoiceParameterType.setOptions(robotOptions, Arrays.asList("Bender", "Gort", "Maximillian", "Robbie", "Tom Servo"));
// Create a ParameterValue of the underlying type (in this case, String) to set the default choice.
final StringParameterValue robotChoice = new StringParameterValue("Gort");
SingleChoiceParameterType.setChoiceData(robotOptions, robotChoice);
params.addParameter(robotOptions);
final PluginParameter<ParameterValue> buttonParam = ActionParameterType.build(REFRESH_PARAMETER_ID);
buttonParam.setName("Refresh");
buttonParam.setDescription("Update the available robots");
params.addParameter(buttonParam);
final PluginParameter<MultiChoiceParameterValue> planetOptions = MultiChoiceParameterType.build(PLANETS_PARAMETER_ID);
planetOptions.setName("Planets");
planetOptions.setDescription("Some planets");
MultiChoiceParameterType.setOptions(planetOptions, Arrays.asList("Mercury", "Venus", "Earth", "Mars", "Jupiter", "Saturn", "Uranus", "Neptune", "Coruscant"));
final List<String> checked = new ArrayList<>();
checked.add("Earth");
MultiChoiceParameterType.setChoices(planetOptions, checked);
params.addParameter(planetOptions);
final PluginParameter<IntegerParameterValue> diceOptions = IntegerParameterType.build(DICE_PARAMETER_ID);
diceOptions.setName("Dice");
diceOptions.setDescription("2d6");
IntegerParameterType.setMinimum(diceOptions, 2);
IntegerParameterType.setMaximum(diceOptions, 12);
diceOptions.setIntegerValue(7);
params.addParameter(diceOptions);
final PluginParameter<FloatParameterValue> probability = FloatParameterType.build(PROBABILITY_PARAMETER_ID);
probability.setName("Probability");
probability.setDescription("0 <= p <= 1");
FloatParameterType.setMinimum(probability, 0F);
FloatParameterType.setMaximum(probability, 1F);
FloatParameterType.setStep(probability, 0.1F);
probability.setFloatValue(1F);
params.addParameter(probability);
final PluginParameter<FileParameterValue> openFileParam = FileParameterType.build(INPUT_FILE_PARAMETER_ID);
openFileParam.setName("Input file");
openFileParam.setDescription("A file to read stuff from");
params.addParameter(openFileParam);
final PluginParameter<FileParameterValue> saveFileParam = FileParameterType.build(OUTPUT_FILE_PARAMETER_ID);
saveFileParam.setName("Output file");
saveFileParam.setDescription("A file to write stuff to");
FileParameterType.setKind(saveFileParam, FileParameterType.FileParameterKind.SAVE);
FileParameterType.setFileFilters(saveFileParam, new FileChooser.ExtensionFilter("Text files", "*.txt"));
params.addParameter(saveFileParam);
final PluginParameter<ColorParameterValue> color = ColorParameterType.build(COLOR_PARAMETER_ID);
color.setName("Color");
color.setDescription("Your favourite colour");
color.setColorValue(ConstellationColor.BLUE);
params.addParameter(color);
final PluginParameter<BooleanParameterValue> crash = BooleanParameterType.build(CRASH_PARAMETER_ID);
crash.setName("Crash");
crash.setDescription("Simulate plugin failure");
params.addParameter(crash);
final PluginParameter<SingleChoiceParameterValue> interactionOptions = SingleChoiceParameterType.build(INTERACTION_PARAMETER_ID);
interactionOptions.setName("Interaction level");
interactionOptions.setDescription("Interaction level for some interaction with the user");
SingleChoiceParameterType.setOptions(interactionOptions, Arrays.asList(NONE, DEBUG, INFO, WARNING, ERROR, FATAL));
params.addParameter(interactionOptions);
final PluginParameter<SingleChoiceParameterValue> levelOptions = SingleChoiceParameterType.build(LEVEL_PARAMETER_ID);
levelOptions.setName("PluginException level");
levelOptions.setDescription("PluginException level to throw an exception at");
levelOptions.setHelpID("not.actually.helpful");
SingleChoiceParameterType.setOptions(levelOptions, Arrays.asList(NONE, DEBUG, INFO, WARNING, ERROR, FATAL));
params.addParameter(levelOptions);
final PluginParameter<IntegerParameterValue> sleepParam = IntegerParameterType.build(SLEEP_PARAMETER_ID);
sleepParam.setName("Sleep");
sleepParam.setDescription("Seconds");
IntegerParameterType.setMinimum(sleepParam, 0);
IntegerParameterType.setMaximum(sleepParam, 20);
sleepParam.setIntegerValue(0);
params.addParameter(sleepParam);
params.addController(SELECTED_PARAMETER_ID, (final PluginParameter<?> master, final Map<String, PluginParameter<?>> parameters, final ParameterChange change) -> {
if (change == ParameterChange.VALUE) {
final boolean masterBoolean = master.getBooleanValue();
// TEST1_PARAMETER will always be of type StringParameter
@SuppressWarnings("unchecked") final PluginParameter<StringParameterValue> t1 = (PluginParameter<StringParameterValue>) parameters.get(TEST1_PARAMETER_ID);
t1.setEnabled(masterBoolean);
// TEST1_PARAMETER will always be of type StringParameter
@SuppressWarnings("unchecked") final PluginParameter<StringParameterValue> t2 = (PluginParameter<StringParameterValue>) parameters.get(TEST2_PARAMETER_ID);
t2.setEnabled(masterBoolean);
// PLANETS_PARAMETER will always be of type MultiChoiceParameter
@SuppressWarnings("unchecked") final PluginParameter<MultiChoiceParameterValue> p = (PluginParameter<MultiChoiceParameterValue>) parameters.get(PLANETS_PARAMETER_ID);
p.setEnabled(masterBoolean);
// DICE_PARAMETER will always be of type IntegerParameter
@SuppressWarnings("unchecked") final PluginParameter<IntegerParameterValue> d = (PluginParameter<IntegerParameterValue>) parameters.get(DICE_PARAMETER_ID);
d.setEnabled(masterBoolean);
// COLOR_PARAMETER will always be of type ColorParameter
@SuppressWarnings("unchecked") final PluginParameter<ColorParameterValue> c = (PluginParameter<ColorParameterValue>) parameters.get(COLOR_PARAMETER_ID);
c.setVisible(masterBoolean);
}
});
params.addController(REFRESH_PARAMETER_ID, (final PluginParameter<?> master, final Map<String, PluginParameter<?>> parameters, final ParameterChange change) -> {
if (change == ParameterChange.NO_CHANGE) {
// button pressed
// ROBOT_PARAMETER will always be of type SingleChoiceParameter
@SuppressWarnings("unchecked") final PluginParameter<SingleChoiceParameterValue> robot = (PluginParameter<SingleChoiceParameterValue>) parameters.get(ROBOT_PARAMETER_ID);
final int n = (int) (System.currentTimeMillis() % 100);
SingleChoiceParameterType.setOptions(robot, Arrays.asList("Kryton " + n, "C-3PO " + n, "R2-D2 " + n));
SingleChoiceParameterType.setChoice(robot, "C-3PO " + n);
}
});
return params;
}
use of au.gov.asd.tac.constellation.graph.GraphElementType in project constellation by constellation-app.
the class TestParametersPluginNGTest method testGraphElementType1.
/**
* Test of query method, of class TestParametersPlugin. Tests throwing
* runtime exception
*/
@Test
public void testGraphElementType1() throws Exception {
System.out.println("test graph element type1");
final TestParametersPlugin instance = new TestParametersPlugin();
final PluginParameters result = instance.createParameters();
// Set plugin query name here before execution
result.getParameters().get(CoreGlobalParameters.QUERY_NAME_PARAMETER_ID).setStringValue("TESTPARAMETERSPLUGIN");
// Set plugin parameters here before execution
final GraphElementTypeParameterValue graphElementType = new GraphElementTypeParameterValue();
assertTrue(graphElementType.set(GraphElementType.META));
// return false when setting same attribute
assertFalse(graphElementType.set(GraphElementType.META));
assertTrue(graphElementType.setObjectValue(GraphElementType.VERTEX));
// return false when setting same attribute
assertFalse(graphElementType.setObjectValue(GraphElementType.VERTEX));
for (final GraphElementType elementType : GraphElementType.values()) {
graphElementType.setObjectValue(elementType);
result.getParameters().get(TestParametersPlugin.ELEMENT_TYPE_PARAMETER_ID).setObjectValue(graphElementType);
// Ensure it is still selected as the correct value
assertEquals(SingleChoiceParameterType.getChoice((PluginParameter<SingleChoiceParameterType.SingleChoiceParameterValue>) result.getParameters().get(TestParametersPlugin.ELEMENT_TYPE_PARAMETER_ID)), elementType.getShortLabel());
}
}
use of au.gov.asd.tac.constellation.graph.GraphElementType in project constellation by constellation-app.
the class FindViewTopComponent method UpdateUI.
/**
* This calls all the necessary functions for each tab to update the
* attributes list based on what attributes are available for the user.
*/
public void UpdateUI() {
// Update the basic find tab
final GraphElementType basicFindType = GraphElementType.getValue(getFindViewPane().getTabs().getBasicFindTab().getLookForChoiceBox().getSelectionModel().getSelectedItem());
getFindViewPane().getTabs().getBasicFindTab().saveSelected(basicFindType);
getFindViewPane().getTabs().getBasicFindTab().populateAttributes(basicFindType);
getFindViewPane().getTabs().getBasicFindTab().updateSelectedAttributes(getFindViewPane().getTabs().getBasicFindTab().getMatchingAttributeList(basicFindType));
// Update the replace tab
final GraphElementType replaceType = GraphElementType.getValue(getFindViewPane().getTabs().getReplaceTab().getLookForChoiceBox().getSelectionModel().getSelectedItem());
getFindViewPane().getTabs().getReplaceTab().saveSelected(replaceType);
getFindViewPane().getTabs().getReplaceTab().populateAttributes(replaceType);
getFindViewPane().getTabs().getReplaceTab().updateSelectedAttributes(getFindViewPane().getTabs().getReplaceTab().getMatchingAttributeList(replaceType));
// Update each of the advanced find tabs criteria panes
final GraphElementType advancedType = GraphElementType.getValue(getFindViewPane().getTabs().getAdvancedFindTab().getLookForChoiceBox().getSelectionModel().getSelectedItem());
for (final AdvancedCriteriaBorderPane criteriaPane : getFindViewPane().getTabs().getAdvancedFindTab().getCorrespondingCriteriaList(advancedType)) {
/**
* set the updateUI variable to true. This avoids the change
* criteria pane function from occurring when re selecting the
* currently selected element after updating the attribute list
*/
criteriaPane.setUpdateUI(true);
criteriaPane.updateAttributesList(advancedType);
// set the updateUI variable back to false to maintian normal
// functionality for the change criteriapane function
criteriaPane.setUpdateUI(false);
}
}
use of au.gov.asd.tac.constellation.graph.GraphElementType in project constellation by constellation-app.
the class FindTopComponent method cmbGraphElementTypeActionPerformed.
// GEN-LAST:event_cmbMatchActionPerformed
/**
* Event handler for <code>cmbGraphElement</code> selection changes.
* <p>
* This triggers float validation checks.
*
* @param evt The registered event.
*/
private void cmbGraphElementTypeActionPerformed(java.awt.event.ActionEvent evt) {
// GEN-FIRST:event_cmbGraphElementTypeActionPerformed
if (evt.getSource().equals(cmbGraphElementType)) {
final GraphElementType currentType = type;
if (cmbGraphElementType.getSelectedItem().equals(Bundle.Find_VERTEX())) {
type = GraphElementType.VERTEX;
} else if (cmbGraphElementType.getSelectedItem().equals(Bundle.Find_TRANSACTION())) {
type = GraphElementType.TRANSACTION;
} else if (cmbGraphElementType.getSelectedItem().equals(Bundle.Find_EDGE())) {
type = GraphElementType.EDGE;
} else if (cmbGraphElementType.getSelectedItem().equals(Bundle.Find_LINK())) {
type = GraphElementType.LINK;
} else {
// We don't have a valid type, so don't perform any further action.
return;
}
// Make sure we are actually dealing with a new type here:
if (!type.equals(currentType)) {
// We have a new type, so make sure we have a new slate to accompany it:
panelFind.removeAll();
// Ensure that we know that we need to refresh attributes:
attributeModificationCounter++;
determineAttributes();
setDefaultFindCriteriaPanels();
}
// saveStateToGraph(), not saving the state as there are too many write
// locks. The state is saved when you run a search, which is good enough.
}
}
use of au.gov.asd.tac.constellation.graph.GraphElementType in project constellation by constellation-app.
the class QueryServices method selectOnGraph.
/**
* Selects each item in the given list on the graph.
*
* @param graph the graph on which to perform the selection.
* @param content A list of <code>FindResult</code>s, with each item
* representing one match on the graph.
* @param clearSelection <code>true</code> to clear previously selected
* items on the graph, <code>false</code> to add to them.
*/
public static void selectOnGraph(final GraphWriteMethods graph, final List<FindResult> content, final boolean clearSelection) {
if (!clearSelection) {
clearSelection(graph);
}
final int selectedVertexAttr = graph.getAttribute(GraphElementType.VERTEX, SELECTED);
final int selectedLinkAttr = graph.getAttribute(GraphElementType.LINK, SELECTED);
final int selectedEdgeAttr = graph.getAttribute(GraphElementType.EDGE, SELECTED);
final int selectedTranAttr = graph.getAttribute(GraphElementType.TRANSACTION, SELECTED);
for (FindResult result : content) {
final int id = result.getID();
final GraphElementType type = result.getType();
final long uid = type.getUID(graph, id);
if (type.elementExists(graph, id) && uid == result.getUID()) {
// Select relevant:
if (result.getType() == GraphElementType.VERTEX && selectedVertexAttr != Graph.NOT_FOUND) {
graph.setBooleanValue(selectedVertexAttr, result.getID(), true);
}
if (result.getType() == GraphElementType.LINK) {
if (selectedLinkAttr != Graph.NOT_FOUND) {
graph.setBooleanValue(selectedLinkAttr, result.getID(), true);
}
// Select any child edges:
final int edgeCount = graph.getLinkEdgeCount(result.getID());
if (selectedEdgeAttr != Graph.NOT_FOUND) {
for (int position = 0; position < edgeCount; position++) {
final int edge = graph.getLinkEdge(result.getID(), position);
graph.setBooleanValue(selectedEdgeAttr, edge, true);
}
}
// Select any child transactions:
final int transactionCount = graph.getLinkTransactionCount(result.getID());
if (selectedTranAttr != Graph.NOT_FOUND) {
for (int position = 0; position < transactionCount; position++) {
final int transaction = graph.getLinkTransaction(result.getID(), position);
graph.setBooleanValue(selectedTranAttr, transaction, true);
}
}
}
if (result.getType() == GraphElementType.EDGE) {
if (selectedEdgeAttr != Graph.NOT_FOUND) {
graph.setBooleanValue(selectedEdgeAttr, result.getID(), true);
}
// Select any child transactions:
final int transactionCount = graph.getEdgeTransactionCount(result.getID());
if (selectedEdgeAttr != Graph.NOT_FOUND) {
for (int position = 0; position < transactionCount; position++) {
final int transaction = graph.getEdgeTransaction(result.getID(), position);
graph.setBooleanValue(selectedTranAttr, transaction, true);
}
}
}
if (result.getType() == GraphElementType.TRANSACTION && selectedTranAttr != Graph.NOT_FOUND) {
graph.setBooleanValue(selectedTranAttr, result.getID(), true);
}
}
}
}
Aggregations