use of org.gephi.graph.api.Table in project gephi by gephi.
the class ManageColumnEstimators method getColumns.
public List<Column> getColumns() {
GraphModel graphModel = Lookup.getDefault().lookup(GraphController.class).getGraphModel();
Table table;
if (Lookup.getDefault().lookup(DataTablesController.class).isNodeTableMode()) {
table = graphModel.getNodeTable();
} else {
table = graphModel.getEdgeTable();
}
List<Column> availableColumns = new ArrayList<>();
for (Column column : table) {
if (TimeMap.class.isAssignableFrom(column.getTypeClass())) {
availableColumns.add(column);
}
}
return availableColumns;
}
use of org.gephi.graph.api.Table in project gephi by gephi.
the class MergeNodeDuplicates method getUI.
@Override
public ManipulatorUI getUI() {
Table nodeTable = Lookup.getDefault().lookup(GraphController.class).getGraphModel().getNodeTable();
List<Column> columnsList = new ArrayList<>();
for (Column column : nodeTable) {
if (!column.isReadOnly()) {
columnsList.add(column);
}
}
columns = columnsList.toArray(new Column[0]);
mergeStrategies = new AttributeRowsMergeStrategy[columns.length];
deleteMergedNodes = NbPreferences.forModule(MergeNodeDuplicates.class).getBoolean(DELETE_MERGED_NODES_SAVED_PREFERENCES, true);
caseSensitive = NbPreferences.forModule(MergeNodeDuplicates.class).getBoolean(CASE_SENSITIVE_SAVED_PREFERENCES, true);
return new MergeNodeDuplicatesUI();
}
use of org.gephi.graph.api.Table in project gephi by gephi.
the class SearchReplaceControllerImpl method canReplace.
@Override
public boolean canReplace(SearchResult result) {
GraphController gc = Lookup.getDefault().lookup(GraphController.class);
Table table;
Column column;
if (result.getFoundNode() != null) {
table = gc.getGraphModel().getNodeTable();
column = table.getColumn(result.getFoundColumnIndex());
} else {
table = gc.getGraphModel().getEdgeTable();
column = table.getColumn(result.getFoundColumnIndex());
}
return Lookup.getDefault().lookup(AttributeColumnsController.class).canChangeColumnData(column);
}
use of org.gephi.graph.api.Table in project gephi by gephi.
the class GraphElementsControllerImpl method mergeNodes.
@Override
public Node mergeNodes(Graph graph, Node[] nodes, Node selectedNode, Column[] columns, AttributeRowsMergeStrategy[] mergeStrategies, boolean deleteMergedNodes) {
Table edgesTable = graph.getModel().getEdgeTable();
if (selectedNode == null) {
//Use first node as selected node if null
selectedNode = nodes[0];
}
//Create empty new node:
Node newNode = createNode("", null, graph);
//Set properties (position, size and color) using the selected node properties:
newNode.setX(selectedNode.x());
newNode.setY(selectedNode.y());
newNode.setZ(selectedNode.z());
newNode.setSize(selectedNode.size());
newNode.setR(selectedNode.r());
newNode.setG(selectedNode.g());
newNode.setB(selectedNode.b());
newNode.setAlpha(selectedNode.alpha());
//Merge attributes:
AttributeColumnsController ac = Lookup.getDefault().lookup(AttributeColumnsController.class);
ac.mergeRowsValues(columns, mergeStrategies, nodes, selectedNode, newNode);
Set<Node> nodesSet = new HashSet<>();
nodesSet.addAll(Arrays.asList(nodes));
//Assign edges to the new node:
Edge newEdge;
for (Node node : nodes) {
for (Edge edge : getNodeEdges(node)) {
Node newEdgeSource;
Node newEdgeTarget;
if (edge.getSource() == node) {
newEdgeSource = newNode;
if (nodesSet.contains(edge.getTarget())) {
//Self loop because of edge between merged nodes
newEdgeTarget = newNode;
} else {
newEdgeTarget = edge.getTarget();
}
} else {
newEdgeTarget = newNode;
if (nodesSet.contains(edge.getSource())) {
//Self loop because of edge between merged nodes
newEdgeSource = newNode;
} else {
newEdgeSource = edge.getSource();
}
}
if (graph.getEdge(newEdgeSource, newEdgeTarget) != null) {
//This edge already exists
continue;
}
newEdge = createEdge(newEdgeSource, newEdgeTarget, edge.isDirected(), edge.getTypeLabel(), graph);
if (newEdge != null) {
//Copy edge attributes:
for (Column column : edgesTable) {
if (!column.isReadOnly()) {
Object value = edge.getAttribute(column);
if (value == null) {
newEdge.removeAttribute(column);
} else {
newEdge.setAttribute(column, edge.getAttribute(column));
}
}
}
}
}
}
//Finally delete merged nodes:
if (deleteMergedNodes) {
deleteNodes(nodes);
}
return newNode;
}
use of org.gephi.graph.api.Table in project gephi by gephi.
the class AttributeColumnsControllerImpl method copyRowDataToOtherRows.
@Override
public void copyRowDataToOtherRows(Element row, Element[] otherRows, Column[] columnsToCopy) {
if (columnsToCopy != null) {
for (Column column : columnsToCopy) {
//Copy all except id and computed attributes:
if (canChangeColumnData(column)) {
for (Element otherRow : otherRows) {
Object value = row.getAttribute(column);
setAttributeValue(value, otherRow, column);
}
}
}
} else {
Table table;
if (row instanceof Node) {
table = Lookup.getDefault().lookup(GraphController.class).getGraphModel().getNodeTable();
} else {
table = Lookup.getDefault().lookup(GraphController.class).getGraphModel().getNodeTable();
}
for (Column column : table) {
if (canChangeColumnData(column)) {
for (Element otherRow : otherRows) {
otherRow.removeAttribute(column);
}
}
}
}
}
Aggregations