use of au.gov.asd.tac.constellation.graph.GraphAttribute in project constellation by constellation-app.
the class ImportController method updateAutoAddedAttributes.
/**
* Get the attributes that will automatically be added to the attribute
* list.
*
* @param elementType
* @param attributes
* @param rg
*/
private void updateAutoAddedAttributes(final GraphElementType elementType, final Map<String, Attribute> attributes, final GraphReadMethods rg, final boolean showSchemaAttributes) {
attributes.clear();
// Add attributes from the graph
int attributeCount = rg.getAttributeCount(elementType);
for (int i = 0; i < attributeCount; i++) {
int attributeId = rg.getAttribute(elementType, i);
Attribute attribute = new GraphAttribute(rg, attributeId);
attributes.put(attribute.getName(), attribute);
}
// Add attributes from the schema
if (showSchemaAttributes && rg.getSchema() != null) {
final SchemaFactory factory = rg.getSchema().getFactory();
for (final SchemaAttribute sattr : factory.getRegisteredAttributes(elementType).values()) {
final Attribute attribute = new GraphAttribute(elementType, sattr.getAttributeType(), sattr.getName(), sattr.getDescription());
if (!attributes.containsKey(attribute.getName())) {
attributes.put(attribute.getName(), attribute);
}
}
}
// Add pseudo-attributes
if (elementType == GraphElementType.TRANSACTION) {
final Attribute attribute = new GraphAttribute(elementType, BooleanAttributeDescription.ATTRIBUTE_NAME, DIRECTED, "Is this transaction directed?");
attributes.put(attribute.getName(), attribute);
}
// Add primary keys
for (int key : rg.getPrimaryKey(elementType)) {
keys.add(key);
}
}
use of au.gov.asd.tac.constellation.graph.GraphAttribute in project constellation by constellation-app.
the class ScatterOptionsPane method refreshOptions.
/**
* Refresh the state of the ScatterOptionsPane based on the given
* ScatterPlotState.
*
* @param state the ScatterPlotState.
*/
protected void refreshOptions(ScatterPlotState state) {
if (scatterPlot.getScatterPlot().getCurrentGraph() == null || state == null) {
return;
}
Platform.runLater(() -> {
isUpdating = true;
final ObservableList<Attribute> attributes = FXCollections.observableArrayList();
ReadableGraph readableGraph = scatterPlot.getScatterPlot().getCurrentGraph().getReadableGraph();
try {
final int attributeCount = readableGraph.getAttributeCount(state.getElementType());
for (int attributePosition = 0; attributePosition < attributeCount; attributePosition++) {
final int attributeId = readableGraph.getAttribute(state.getElementType(), attributePosition);
final Attribute attribute = new GraphAttribute(readableGraph, attributeId);
attributes.add(attribute);
}
} finally {
readableGraph.release();
}
FXCollections.sort(attributes, (attribute1, attribute2) -> attribute1.getName().compareTo(attribute2.getName()));
xAttributeComboBox.setItems(attributes);
yAttributeComboBox.setItems(attributes);
elementTypeComboBox.getSelectionModel().select(state.getElementType().getShortLabel());
xAttributeComboBox.getSelectionModel().select(state.getXAttribute());
yAttributeComboBox.getSelectionModel().select(state.getYAttribute());
selectedOnlyButton.setSelected(state.isSelectedOnly());
isUpdating = false;
});
}
use of au.gov.asd.tac.constellation.graph.GraphAttribute in project constellation by constellation-app.
the class ScatterPlotStateIoProvider method readObject.
@Override
public void readObject(int attributeId, int elementId, JsonNode jnode, GraphWriteMethods graph, Map<Integer, Integer> vertexMap, Map<Integer, Integer> transactionMap, GraphByteReader byteReader, ImmutableObjectCache cache) throws IOException {
if (!jnode.isNull()) {
final ScatterPlotState state = new ScatterPlotState();
GraphElementType elementType = GraphElementType.valueOf(jnode.get("elementType").asText());
final Attribute xAttribute = "null".equalsIgnoreCase(jnode.get(X_ATTRIBUTE).asText()) ? null : new GraphAttribute(graph, graph.getAttribute(elementType, jnode.get(X_ATTRIBUTE).asText()));
final Attribute yAttribute = "null".equalsIgnoreCase(jnode.get(Y_ATTRIBUTE).asText()) ? null : new GraphAttribute(graph, graph.getAttribute(elementType, jnode.get(Y_ATTRIBUTE).asText()));
state.setElementType(elementType);
state.setXAttribute(xAttribute);
state.setYAttribute(yAttribute);
state.setSelectedOnly(jnode.get("selectedOnly").asBoolean());
graph.setObjectValue(attributeId, elementId, state);
}
}
use of au.gov.asd.tac.constellation.graph.GraphAttribute in project constellation by constellation-app.
the class ColumnNGTest method init.
@Test
public void init() {
final Column column = new Column();
assertNull(column.getAttributeNamePrefix());
assertNull(column.getAttribute());
assertNull(column.getTableColumn());
final String prefix = "source.";
final GraphAttribute attribute = new GraphAttribute(GraphElementType.VERTEX, "string", "COLUMN_A", "Describes all things A's");
final TableColumn tableColumn = new TableColumn<>("source.COLUMN_A");
column.setAttributeNamePrefix(prefix);
column.setAttribute(attribute);
column.setTableColumn(tableColumn);
assertSame(prefix, column.getAttributeNamePrefix());
assertSame(attribute, column.getAttribute());
assertSame(tableColumn, column.getTableColumn());
}
use of au.gov.asd.tac.constellation.graph.GraphAttribute in project constellation by constellation-app.
the class TableNGTest method getRowDataForVertex.
@Test
public void getRowDataForVertex() {
final ReadableGraph readableGraph = mock(ReadableGraph.class);
final Map<Integer, ObservableList<String>> elementIdToRowIndex = new HashMap<>();
final Map<ObservableList<String>, Integer> rowToElementIdIndex = new HashMap<>();
doReturn(elementIdToRowIndex).when(activeTableReference).getElementIdToRowIndex();
doReturn(rowToElementIdIndex).when(activeTableReference).getRowToElementIdIndex();
final int vertexId = 42;
// Set up the attributes for each column
when(readableGraph.getAttribute(GraphElementType.VERTEX, "COLUMN_A")).thenReturn(101);
when(readableGraph.getAttributeName(101)).thenReturn("COLUMN_A");
when(readableGraph.getAttributeElementType(101)).thenReturn(GraphElementType.VERTEX);
when(readableGraph.getAttributeType(101)).thenReturn("string");
final Object objectValue1 = new Object();
when(readableGraph.getObjectValue(101, vertexId)).thenReturn(objectValue1);
final Attribute attribute1 = new GraphAttribute(readableGraph, 101);
final CopyOnWriteArrayList<Column> columnIndex = new CopyOnWriteArrayList<>();
columnIndex.add(new Column(null, attribute1, null));
when(table.getColumnIndex()).thenReturn(columnIndex);
try (final MockedStatic<AbstractAttributeInteraction> attrInteractionMockedStatic = Mockito.mockStatic(AbstractAttributeInteraction.class)) {
final AbstractAttributeInteraction interaction = mock(AbstractAttributeInteraction.class);
attrInteractionMockedStatic.when(() -> AbstractAttributeInteraction.getInteraction("string")).thenReturn(interaction);
when(interaction.getDisplayText(objectValue1)).thenReturn("column1Value");
assertEquals(FXCollections.observableArrayList("column1Value"), table.getRowDataForVertex(readableGraph, vertexId));
assertEquals(Map.of(vertexId, FXCollections.observableArrayList("column1Value")), elementIdToRowIndex);
assertEquals(Map.of(FXCollections.observableArrayList("column1Value"), vertexId), rowToElementIdIndex);
}
}
Aggregations