use of au.gov.asd.tac.constellation.plugins.parameters.types.ElementTypeParameterValue in project constellation by constellation-app.
the class HistogramTopComponent method filterOnSelection.
void filterOnSelection() {
if (currentGraph != null) {
Plugin plugin = new HistogramFilterOnSelectionPlugin();
PluginParameters params = plugin.createParameters();
params.getParameters().get(HistogramFilterOnSelectionPlugin.ELEMENT_TYPE_PARAMETER_ID).setObjectValue(new ElementTypeParameterValue(currentHistogramState.getElementType()));
PluginExecution.withPlugin(plugin).withParameters(params).executeLater(currentGraph);
}
}
use of au.gov.asd.tac.constellation.plugins.parameters.types.ElementTypeParameterValue in project constellation by constellation-app.
the class AbstractGeoExportPlugin method read.
@Override
public void read(final GraphReadMethods graph, final PluginInteraction interaction, final PluginParameters parameters) throws InterruptedException, PluginException {
if (parameters.getStringValue(OUTPUT_PARAMETER_ID) == null) {
NotifyDisplayer.display("Invalid output file provided, cannot be empty", NotifyDescriptor.ERROR_MESSAGE);
return;
}
if (parameters.getSingleChoice(ELEMENT_TYPE_PARAMETER_ID) == null) {
NotifyDisplayer.display("Invalid element type provided, cannot be empty", NotifyDescriptor.ERROR_MESSAGE);
return;
}
final File output = new File(parameters.getStringValue(OUTPUT_PARAMETER_ID));
final GraphElementType elementType = (GraphElementType) ((ElementTypeParameterValue) parameters.getSingleChoice(ELEMENT_TYPE_PARAMETER_ID)).getObjectValue();
final List<GraphAttribute> graphAttributes = parameters.getMultiChoiceValue(ATTRIBUTES_PARAMETER_ID).getChoicesData().stream().map(attributeChoice -> (GraphAttribute) ((GraphAttributeParameterValue) attributeChoice).getObjectValue()).collect(Collectors.toList());
final boolean selectedOnly = parameters.getBooleanValue(SELECTED_ONLY_PARAMETER_ID);
final int vertexIdentifierAttributeId = VisualConcept.VertexAttribute.IDENTIFIER.get(graph);
final int vertexSelectedAttributeId = VisualConcept.VertexAttribute.SELECTED.get(graph);
final int vertexLatitudeAttributeId = SpatialConcept.VertexAttribute.LATITUDE.get(graph);
final int vertexLongitudeAttributeId = SpatialConcept.VertexAttribute.LONGITUDE.get(graph);
final int vertexShapeAttributeId = SpatialConcept.VertexAttribute.SHAPE.get(graph);
final int transactionIdentifierAttributeId = VisualConcept.TransactionAttribute.IDENTIFIER.get(graph);
final int transactionSelectedAttributeId = VisualConcept.TransactionAttribute.SELECTED.get(graph);
final int transactionLatitudeAttributeId = SpatialConcept.TransactionAttribute.LATITUDE.get(graph);
final int transactionLongitudeAttributeId = SpatialConcept.TransactionAttribute.LONGITUDE.get(graph);
final int transactionShapeAttributeId = SpatialConcept.TransactionAttribute.SHAPE.get(graph);
final Map<String, String> shapes = new HashMap<>();
final Map<String, Map<String, Object>> attributes = new HashMap<>();
switch(elementType) {
case VERTEX:
final int vertexCount = graph.getVertexCount();
for (int vertexPosition = 0; vertexPosition < vertexCount; vertexPosition++) {
final int vertexId = graph.getVertex(vertexPosition);
final boolean vertexSelected = graph.getBooleanValue(vertexSelectedAttributeId, vertexId);
final String vertexIdentifier = graph.getStringValue(vertexIdentifierAttributeId, vertexId);
final Float vertexLatitude = vertexLatitudeAttributeId == GraphConstants.NOT_FOUND ? null : graph.getObjectValue(vertexLatitudeAttributeId, vertexId);
final Float vertexLongitude = vertexLongitudeAttributeId == GraphConstants.NOT_FOUND ? null : graph.getObjectValue(vertexLongitudeAttributeId, vertexId);
final String vertexShape = vertexShapeAttributeId == GraphConstants.NOT_FOUND ? null : graph.getStringValue(vertexShapeAttributeId, vertexId);
// if the vertex represents a valid geospatial shape, record it
boolean shapeFound = false;
if ((!selectedOnly || vertexSelected) && StringUtils.isNotBlank(vertexShape) && Shape.isValidGeoJson(vertexShape)) {
shapes.put(vertexIdentifier, vertexShape);
shapeFound = true;
} else if ((!selectedOnly || vertexSelected) && vertexLatitude != null && vertexLongitude != null) {
try {
final String vertexPoint = Shape.generateShape(vertexIdentifier, GeometryType.POINT, Arrays.asList(Tuple.create((double) vertexLongitude, (double) vertexLatitude)));
shapes.put(vertexIdentifier, vertexPoint);
shapeFound = true;
} catch (IOException ex) {
throw new PluginException(PluginNotificationLevel.ERROR, ex);
}
} else {
// Do nothing
}
// ... and record all its attributes
if (shapeFound) {
final Map<String, Object> attributeMap = new HashMap<>();
for (final GraphAttribute graphAttribute : graphAttributes) {
final Object attributeValue = graph.getObjectValue(graphAttribute.getId(), vertexId);
attributeMap.put(graphAttribute.getName(), attributeValue);
}
attributes.put(vertexIdentifier, attributeMap);
}
}
break;
case TRANSACTION:
final int transactionCount = graph.getTransactionCount();
for (int transactionPosition = 0; transactionPosition < transactionCount; transactionPosition++) {
final int transactionId = graph.getTransaction(transactionPosition);
final boolean transactionSelected = graph.getBooleanValue(transactionSelectedAttributeId, transactionId);
final String transactionIdentifier = graph.getStringValue(transactionIdentifierAttributeId, transactionId);
final Float transactionLatitude = transactionLatitudeAttributeId == GraphConstants.NOT_FOUND ? null : graph.getObjectValue(transactionLatitudeAttributeId, transactionId);
final Float transactionLongitude = transactionLongitudeAttributeId == GraphConstants.NOT_FOUND ? null : graph.getObjectValue(transactionLongitudeAttributeId, transactionId);
final String transactionShape = transactionShapeAttributeId == GraphConstants.NOT_FOUND ? null : graph.getStringValue(transactionShapeAttributeId, transactionId);
final int sourceVertexId = graph.getTransactionSourceVertex(transactionId);
final String sourceVertexIdentifier = graph.getStringValue(vertexIdentifierAttributeId, sourceVertexId);
final Float sourceVertexLatitude = vertexLatitudeAttributeId == GraphConstants.NOT_FOUND ? null : graph.getObjectValue(vertexLatitudeAttributeId, sourceVertexId);
final Float sourceVertexLongitude = vertexLongitudeAttributeId == GraphConstants.NOT_FOUND ? null : graph.getObjectValue(vertexLongitudeAttributeId, sourceVertexId);
final String sourceVertexShape = vertexShapeAttributeId == GraphConstants.NOT_FOUND ? null : graph.getStringValue(vertexShapeAttributeId, sourceVertexId);
final int destinationVertexId = graph.getTransactionDestinationVertex(transactionId);
final String destinationVertexIdentifier = graph.getStringValue(vertexIdentifierAttributeId, destinationVertexId);
final Float destinationVertexLatitude = vertexLatitudeAttributeId == GraphConstants.NOT_FOUND ? null : graph.getObjectValue(vertexLatitudeAttributeId, destinationVertexId);
final Float destinationVertexLongitude = vertexLongitudeAttributeId == GraphConstants.NOT_FOUND ? null : graph.getObjectValue(vertexLongitudeAttributeId, destinationVertexId);
final String destinationVertexShape = vertexShapeAttributeId == GraphConstants.NOT_FOUND ? null : graph.getStringValue(vertexShapeAttributeId, destinationVertexId);
// if the transaction represents a valid geospatial shape, record it
boolean shapeFound = false;
if ((!selectedOnly || transactionSelected) && StringUtils.isNotBlank(transactionShape) && Shape.isValidGeoJson(transactionShape)) {
shapes.put(transactionIdentifier, transactionShape);
shapeFound = true;
} else if ((!selectedOnly || transactionSelected) && transactionLatitude != null && transactionLongitude != null) {
try {
final String transactionPoint = Shape.generateShape(transactionIdentifier, GeometryType.POINT, Arrays.asList(Tuple.create((double) transactionLongitude, (double) transactionLatitude)));
shapes.put(transactionIdentifier, transactionPoint);
shapeFound = true;
} catch (IOException ex) {
throw new PluginException(PluginNotificationLevel.ERROR, ex);
}
} else {
// Do nothing
}
// ... and record all its attributes
if (shapeFound) {
final Map<String, Object> attributeMap = new HashMap<>();
final int transactionAttributeCount = graph.getAttributeCount(GraphElementType.TRANSACTION);
for (int transactionAttributePosition = 0; transactionAttributePosition < transactionAttributeCount; transactionAttributePosition++) {
final int transactionAttributeId = graph.getAttribute(GraphElementType.TRANSACTION, transactionAttributePosition);
final String transactionAttributeName = graph.getAttributeName(transactionAttributeId);
if (Character.isUpperCase(transactionAttributeName.charAt(0))) {
final Object transactionAttributeValue = graph.getObjectValue(transactionAttributeId, transactionId);
attributeMap.put(GraphRecordStoreUtilities.TRANSACTION + transactionAttributeName, transactionAttributeValue);
}
}
final int vertexAttributeCount = graph.getAttributeCount(GraphElementType.VERTEX);
for (int vertexAttributePosition = 0; vertexAttributePosition < vertexAttributeCount; vertexAttributePosition++) {
final int vertexAttributeId = graph.getAttribute(GraphElementType.VERTEX, vertexAttributePosition);
final String sourceVertexAttributeName = graph.getAttributeName(vertexAttributeId);
if (Character.isUpperCase(sourceVertexAttributeName.charAt(0))) {
final Object sourceVertexAttributeValue = graph.getObjectValue(vertexAttributeId, sourceVertexId);
attributeMap.put(GraphRecordStoreUtilities.SOURCE + sourceVertexAttributeName, sourceVertexAttributeValue);
}
final String destinationVertexAttributeName = graph.getAttributeName(vertexAttributeId);
if (Character.isUpperCase(destinationVertexAttributeName.charAt(0))) {
final Object destinationVertexAttributeValue = graph.getObjectValue(vertexAttributeId, destinationVertexId);
attributeMap.put(GraphRecordStoreUtilities.DESTINATION + destinationVertexAttributeName, destinationVertexAttributeValue);
}
}
attributes.put(transactionIdentifier, attributeMap);
}
// if the source vertex represents a valid geospatial shape, record it
shapeFound = false;
if ((!selectedOnly || transactionSelected) && StringUtils.isNotBlank(sourceVertexShape) && Shape.isValidGeoJson(sourceVertexShape)) {
shapes.put(sourceVertexIdentifier, sourceVertexShape);
shapeFound = true;
} else if ((!selectedOnly || transactionSelected) && sourceVertexLatitude != null && sourceVertexLongitude != null) {
try {
final String vertexPoint = Shape.generateShape(sourceVertexIdentifier, GeometryType.POINT, Arrays.asList(Tuple.create((double) sourceVertexLongitude, (double) sourceVertexLatitude)));
shapes.put(sourceVertexIdentifier, vertexPoint);
shapeFound = true;
} catch (IOException ex) {
throw new PluginException(PluginNotificationLevel.ERROR, ex);
}
} else {
// Do nothing
}
// ... and record all its attributes
if (shapeFound) {
final Map<String, Object> attributeMap = new HashMap<>();
final int transactionAttributeCount = graph.getAttributeCount(GraphElementType.TRANSACTION);
for (int transactionAttributePosition = 0; transactionAttributePosition < transactionAttributeCount; transactionAttributePosition++) {
final int transactionAttributeId = graph.getAttribute(GraphElementType.TRANSACTION, transactionAttributePosition);
final String transactionAttributeName = graph.getAttributeName(transactionAttributeId);
if (Character.isUpperCase(transactionAttributeName.charAt(0))) {
final Object transactionAttributeValue = graph.getObjectValue(transactionAttributeId, transactionId);
attributeMap.put(GraphRecordStoreUtilities.TRANSACTION + transactionAttributeName, transactionAttributeValue);
}
}
final int vertexAttributeCount = graph.getAttributeCount(GraphElementType.VERTEX);
for (int vertexAttributePosition = 0; vertexAttributePosition < vertexAttributeCount; vertexAttributePosition++) {
final int vertexAttributeId = graph.getAttribute(GraphElementType.VERTEX, vertexAttributePosition);
final String sourceVertexAttributeName = graph.getAttributeName(vertexAttributeId);
if (Character.isUpperCase(sourceVertexAttributeName.charAt(0))) {
final Object sourceVertexAttributeValue = graph.getObjectValue(vertexAttributeId, sourceVertexId);
attributeMap.put(GraphRecordStoreUtilities.SOURCE + sourceVertexAttributeName, sourceVertexAttributeValue);
}
final String destinationVertexAttributeName = graph.getAttributeName(vertexAttributeId);
if (Character.isUpperCase(destinationVertexAttributeName.charAt(0))) {
final Object destinationVertexAttributeValue = graph.getObjectValue(vertexAttributeId, destinationVertexId);
attributeMap.put(GraphRecordStoreUtilities.DESTINATION + destinationVertexAttributeName, destinationVertexAttributeValue);
}
}
attributes.put(sourceVertexIdentifier, attributeMap);
}
// if the destination vertex represents a valid geospatial shape, record it
shapeFound = false;
if ((!selectedOnly || transactionSelected) && StringUtils.isNotBlank(destinationVertexShape) && Shape.isValidGeoJson(destinationVertexShape)) {
shapes.put(destinationVertexIdentifier, destinationVertexShape);
shapeFound = true;
} else if ((!selectedOnly || transactionSelected) && destinationVertexLatitude != null && destinationVertexLongitude != null) {
try {
final String vertexPoint = Shape.generateShape(destinationVertexIdentifier, GeometryType.POINT, Arrays.asList(Tuple.create((double) destinationVertexLongitude, (double) destinationVertexLatitude)));
shapes.put(destinationVertexIdentifier, vertexPoint);
shapeFound = true;
} catch (IOException ex) {
throw new PluginException(PluginNotificationLevel.ERROR, ex);
}
} else {
// Do nothing
}
// ... and record all its attributes
if (shapeFound) {
final Map<String, Object> attributeMap = new HashMap<>();
final int transactionAttributeCount = graph.getAttributeCount(GraphElementType.TRANSACTION);
for (int transactionAttributePosition = 0; transactionAttributePosition < transactionAttributeCount; transactionAttributePosition++) {
final int transactionAttributeId = graph.getAttribute(GraphElementType.TRANSACTION, transactionAttributePosition);
final String transactionAttributeName = graph.getAttributeName(transactionAttributeId);
if (Character.isUpperCase(transactionAttributeName.charAt(0))) {
final Object transactionAttributeValue = graph.getObjectValue(transactionAttributeId, transactionId);
attributeMap.put(GraphRecordStoreUtilities.TRANSACTION + transactionAttributeName, transactionAttributeValue);
}
}
final int vertexAttributeCount = graph.getAttributeCount(GraphElementType.VERTEX);
for (int vertexAttributePosition = 0; vertexAttributePosition < vertexAttributeCount; vertexAttributePosition++) {
final int vertexAttributeId = graph.getAttribute(GraphElementType.VERTEX, vertexAttributePosition);
final String sourceVertexAttributeName = graph.getAttributeName(vertexAttributeId);
if (Character.isUpperCase(sourceVertexAttributeName.charAt(0))) {
final Object sourceVertexAttributeValue = graph.getObjectValue(vertexAttributeId, sourceVertexId);
attributeMap.put(GraphRecordStoreUtilities.SOURCE + sourceVertexAttributeName, sourceVertexAttributeValue);
}
final String destinationVertexAttributeName = graph.getAttributeName(vertexAttributeId);
if (Character.isUpperCase(destinationVertexAttributeName.charAt(0))) {
final Object destinationVertexAttributeValue = graph.getObjectValue(vertexAttributeId, destinationVertexId);
attributeMap.put(GraphRecordStoreUtilities.DESTINATION + destinationVertexAttributeName, destinationVertexAttributeValue);
}
}
attributes.put(destinationVertexIdentifier, attributeMap);
}
}
break;
default:
throw new PluginException(PluginNotificationLevel.ERROR, "Invalid element type");
}
try {
exportGeo(parameters, GraphNode.getGraphNode(graph.getId()).getDisplayName(), shapes, attributes, output);
} catch (IOException ex) {
throw new PluginException(PluginNotificationLevel.ERROR, ex);
}
ConstellationLoggerHelper.exportPropertyBuilder(this, GraphRecordStoreUtilities.getVertices(graph, false, false, false).getAll(GraphRecordStoreUtilities.SOURCE + VisualConcept.VertexAttribute.LABEL), output, ConstellationLoggerHelper.SUCCESS);
}
use of au.gov.asd.tac.constellation.plugins.parameters.types.ElementTypeParameterValue 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.types.ElementTypeParameterValue in project constellation by constellation-app.
the class NotesViewPane method createNote.
/**
* Takes a NoteEntry object and creates the UI for it in the Notes View.
*
* @param newNote NoteEntry object used to create a the note UI in the Notes
* View.
*/
private void createNote(final NotesViewEntry newNote) {
final String noteColour = newNote.isUserCreated() ? USER_COLOUR : AUTO_COLOUR;
// Define dateTime label
final Label dateTimeLabel = new Label((new SimpleDateFormat(DATETIME_PATTERN).format(new Date(Long.parseLong(newNote.getDateTime())))));
dateTimeLabel.setWrapText(true);
dateTimeLabel.setStyle(BOLD_STYLE + fontStyle);
// Define title text box
final TextField titleText = new TextField(newNote.getNoteTitle());
titleText.setStyle(BOLD_STYLE);
// Define title label
final Label titleLabel = new Label(newNote.getNoteTitle());
titleLabel.setWrapText(true);
titleLabel.setStyle(BOLD_STYLE + fontStyle);
// Define content label
final Label contentLabel = new Label(newNote.getNoteContent());
contentLabel.setWrapText(true);
contentLabel.setMinWidth(50);
contentLabel.setAlignment(Pos.TOP_LEFT);
// Define content text area
final TextArea contentTextArea = new TextArea(newNote.getNoteContent());
contentTextArea.setWrapText(true);
contentTextArea.positionCaret(contentTextArea.getText() == null ? 0 : contentTextArea.getText().length());
final VBox noteInformation;
// Define selection label
String selectionLabelText = "";
final Label selectionLabel = new Label(selectionLabelText);
// If the note is user created add the selection details.
if (newNote.isUserCreated()) {
if (newNote.isGraphAttribute()) {
selectionLabelText = "Note linked to: the graph.";
} else {
selectionLabelText = "Note linked to: ";
if (newNote.getNodesSelected().size() == 1) {
selectionLabelText += newNote.getNodesSelected().size() + " node, ";
} else {
selectionLabelText += newNote.getNodesSelected().size() + " nodes, ";
}
if (newNote.getTransactionsSelected().size() == 1) {
selectionLabelText += newNote.getTransactionsSelected().size() + " transaction. ";
} else {
selectionLabelText += newNote.getTransactionsSelected().size() + " transactions. ";
}
}
selectionLabel.setText(selectionLabelText);
selectionLabel.setWrapText(true);
selectionLabel.setStyle("-fx-font-weight: bold; -fx-font-style: italic; " + fontStyle);
// If the note to be created is in edit mode, ensure it is created
// with the correct java fx elements
noteInformation = new VBox(DEFAULT_SPACING, dateTimeLabel, newNote.getEditMode() ? titleText : titleLabel, newNote.getEditMode() ? contentTextArea : contentLabel, selectionLabel);
HBox.setHgrow(noteInformation, Priority.ALWAYS);
} else {
// If the note to be created is in edit mode, ensure it is created
// with the correct java fx elements
noteInformation = new VBox(DEFAULT_SPACING, dateTimeLabel, newNote.getEditMode() ? titleText : titleLabel, newNote.getEditMode() ? contentTextArea : contentLabel, selectionLabel);
HBox.setHgrow(noteInformation, Priority.ALWAYS);
}
// Define buttons (edit, save, add, renove, delete)
final Button editTextButton = new Button("Edit");
editTextButton.setMinWidth(92);
editTextButton.setStyle(String.format("-fx-font-size:%d;", FontUtilities.getApplicationFontSize()));
final Button saveTextButton = new Button("Save");
saveTextButton.setMinWidth(92);
saveTextButton.setStyle(String.format("-fx-font-size:%d;", FontUtilities.getApplicationFontSize()));
final Button deleteButton = new Button("Delete Note");
deleteButton.setMinWidth(92);
deleteButton.setStyle(String.format("-fx-font-size:%d;", FontUtilities.getApplicationFontSize()));
final VBox noteButtons;
// If the note to be created is in edit mode, ensure it is created with
// the correct java fx elements
noteButtons = new VBox(DEFAULT_SPACING, newNote.getEditMode() ? saveTextButton : editTextButton, deleteButton);
noteButtons.setAlignment(Pos.CENTER);
final HBox noteBody = newNote.isUserCreated() ? new HBox(DEFAULT_SPACING, noteInformation, noteButtons) : new HBox(DEFAULT_SPACING, noteInformation);
noteBody.setStyle("-fx-padding: 5px; -fx-background-color: " + noteColour + "; -fx-background-radius: 10 10 10 10;");
notesListVBox.getChildren().add(noteBody);
if (newNote.isUserCreated()) {
// Add a right click context menu to user notes.
final MenuItem selectOnGraphMenuItem = new MenuItem("Select on Graph");
selectOnGraphMenuItem.setOnAction(event -> {
final BitSet elementIdsTx = new BitSet();
final BitSet elementIdsVx = new BitSet();
final Graph activeGraph = GraphManager.getDefault().getActiveGraph();
if (newNote.isGraphAttribute()) {
// Select all elements with right click menu if the user note is applied to the whole graph.
final ReadableGraph rg = activeGraph.getReadableGraph();
try {
final int vxCount = rg.getVertexCount();
for (int position = 0; position < vxCount; position++) {
final int vxId = rg.getVertex(position);
elementIdsVx.set(vxId);
}
final int txCount = rg.getTransactionCount();
for (int position = 0; position < txCount; position++) {
final int txId = rg.getTransaction(position);
elementIdsTx.set(txId);
}
} finally {
rg.release();
}
} else {
// Select the specific nodes and/or transactions applied to the note.
// Add nodes that are selected to the note.
final int nodesLength = newNote.getNodesSelected().size();
final List<Integer> nodesSelected = newNote.getNodesSelected();
for (int i = 0; i < nodesLength; i++) {
elementIdsVx.set(nodesSelected.get(i));
}
// Add transactions that are selected to the note.
final int transactionsLength = newNote.getTransactionsSelected().size();
final List<Integer> transactionsSelected = newNote.getTransactionsSelected();
for (int i = 0; i < transactionsLength; i++) {
elementIdsTx.set(transactionsSelected.get(i));
}
}
PluginExecution.withPlugin(VisualGraphPluginRegistry.CHANGE_SELECTION).withParameter(ChangeSelectionPlugin.ELEMENT_BIT_SET_PARAMETER_ID, elementIdsTx).withParameter(ChangeSelectionPlugin.ELEMENT_TYPE_PARAMETER_ID, new ElementTypeParameterValue(GraphElementType.TRANSACTION)).withParameter(ChangeSelectionPlugin.SELECTION_MODE_PARAMETER_ID, SelectionMode.REPLACE).executeLater(activeGraph);
PluginExecution.withPlugin(VisualGraphPluginRegistry.CHANGE_SELECTION).withParameter(ChangeSelectionPlugin.ELEMENT_BIT_SET_PARAMETER_ID, elementIdsVx).withParameter(ChangeSelectionPlugin.ELEMENT_TYPE_PARAMETER_ID, new ElementTypeParameterValue(GraphElementType.VERTEX)).withParameter(ChangeSelectionPlugin.SELECTION_MODE_PARAMETER_ID, SelectionMode.REPLACE).executeLater(activeGraph);
});
final MenuItem addOnGraphMenuItem = new MenuItem("Add Selected");
addOnGraphMenuItem.setOnAction(event -> {
// Save the current text in the text fields so they are not reset on
// updateNotesUI
newNote.setNoteTitle(titleText.getText());
newNote.setNoteContent(contentTextArea.getText());
addToSelectedElements(newNote);
final Graph activeGraph = GraphManager.getDefault().getActiveGraph();
if (activeGraph != null) {
updateNotesUI();
notesViewController.writeState(activeGraph);
}
});
final MenuItem removeOnGraphMenuItem = new MenuItem("Remove Selected");
removeOnGraphMenuItem.setOnAction(event -> {
// Save the current text in the text fields so they are not reset on
// updateNotesUI
newNote.setNoteTitle(titleText.getText());
newNote.setNoteContent(contentTextArea.getText());
removeFromSelectedElements(newNote);
final Graph activeGraph = GraphManager.getDefault().getActiveGraph();
if (activeGraph != null) {
updateNotesUI();
notesViewController.writeState(activeGraph);
}
});
// Context menu is only added to user created notes.
final ContextMenu contextMenu = new ContextMenu();
contextMenu.getItems().addAll(selectOnGraphMenuItem, addOnGraphMenuItem, removeOnGraphMenuItem);
noteBody.setOnContextMenuRequested(event -> contextMenu.show(this, event.getScreenX(), event.getScreenY()));
}
deleteButton.setOnAction(event -> {
final Alert deleteAlert = new Alert(Alert.AlertType.CONFIRMATION);
deleteAlert.setHeaderText("Delete Note");
deleteAlert.setContentText("Are you sure you want to delete \"" + titleLabel.getText() + "\"?");
deleteAlert.showAndWait();
if (deleteAlert.getResult() == ButtonType.OK) {
synchronized (LOCK) {
if (notesViewEntries.removeIf(note -> note.getDateTime().equals(newNote.getDateTime()))) {
notesDateTimeCache.remove(newNote.getDateTime());
final Graph activeGraph = GraphManager.getDefault().getActiveGraph();
if (activeGraph != null) {
updateNotesUI();
notesViewController.writeState(activeGraph);
}
}
}
event.consume();
}
deleteAlert.close();
});
// Edit button activates editable text boxs for title and label
editTextButton.setOnAction(event -> {
noteButtons.getChildren().removeAll(editTextButton, deleteButton);
noteButtons.getChildren().addAll(saveTextButton, deleteButton);
noteInformation.getChildren().removeAll(dateTimeLabel, titleLabel, contentLabel, selectionLabel);
noteInformation.getChildren().addAll(dateTimeLabel, titleText, contentTextArea, selectionLabel);
newNote.setEditMode(true);
});
// Save button deactivates editable text boxs for title and label
saveTextButton.setOnAction(event -> {
// Check if either the title or content text boxs are empty
if (StringUtils.isBlank(titleText.getText()) || StringUtils.isBlank(contentTextArea.getText())) {
JOptionPane.showMessageDialog(null, "Type in missing fields.", "Invalid Text", JOptionPane.WARNING_MESSAGE);
} else {
titleLabel.setText(titleText.getText());
contentLabel.setText(contentTextArea.getText());
newNote.setNoteTitle(titleText.getText());
newNote.setNoteContent(contentTextArea.getText());
noteButtons.getChildren().removeAll(saveTextButton, deleteButton);
noteButtons.getChildren().addAll(editTextButton, deleteButton);
noteInformation.getChildren().removeAll(dateTimeLabel, titleText, contentTextArea, selectionLabel);
noteInformation.getChildren().addAll(dateTimeLabel, titleLabel, contentLabel, selectionLabel);
newNote.setEditMode(false);
}
});
}
use of au.gov.asd.tac.constellation.plugins.parameters.types.ElementTypeParameterValue in project constellation by constellation-app.
the class ChangeSelectionPlugin method createParameters.
@Override
public PluginParameters createParameters() {
final PluginParameters parameters = new PluginParameters();
final PluginParameter<ObjectParameterValue> elementBitSet = ObjectParameterType.build(ELEMENT_BIT_SET_PARAMETER_ID);
elementBitSet.setName("Element Ids");
elementBitSet.setDescription("A set of the element id's, such as the vertex ids");
parameters.addParameter(elementBitSet);
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<ObjectParameterValue> selectionMode = ObjectParameterType.build(SELECTION_MODE_PARAMETER_ID);
selectionMode.setName("Selection Mode");
selectionMode.setDescription("The selection mode being ADD, REMOVE, REPLACE or INVERT");
parameters.addParameter(selectionMode);
return parameters;
}
Aggregations