use of org.gephi.datalab.api.AttributeColumnsController in project gephi by gephi.
the class CopyDataToOtherColumnUI method setup.
@Override
public void setup(AttributeColumnsManipulator m, GraphModel graphModel, Table table, Column column, DialogControls dialogControls) {
this.manipulator = (CopyDataToOtherColumn) m;
sourceColumnLabel.setText(NbBundle.getMessage(CopyDataToOtherColumnUI.class, "CopyDataToOtherColumnUI.sourceColumnLabel.text", column.getTitle()));
AttributeColumnsController ac = Lookup.getDefault().lookup(AttributeColumnsController.class);
ArrayList<Column> availableColumns = new ArrayList<>();
for (Column c : table) {
if (ac.canChangeColumnData(c) && c != column) {
availableColumns.add(c);
columnsComboBox.addItem(c.getTitle());
}
}
columns = availableColumns.toArray(new Column[0]);
}
use of org.gephi.datalab.api.AttributeColumnsController in project gephi by gephi.
the class NumberColumnStatisticsReport method getColumnNumbers.
public Number[] getColumnNumbers(final Table table, final Column column) {
AttributeColumnsController ac = Lookup.getDefault().lookup(AttributeColumnsController.class);
Number[] columnNumbers = ac.getColumnNumbers(table, column);
return columnNumbers;
}
use of org.gephi.datalab.api.AttributeColumnsController in project gephi by gephi.
the class AttributeTableCSVExporter method writeCSVFile.
/**
* <p>Export a AttributeTable to the specified file.</p>
*
* @param graph Graph containing the table and rows
* @param table Table to export. Cannot be null
* @param out Ouput stream to write. Cannot be null.
* @param separator Separator to use for separating values of a row in the CSV file. If null ',' will be used.
* @param charset Charset encoding for the file. If null, UTF-8 will be used
* @param columnIndexesToExport Indicates the indexes of the columns to export. All columns will be exported if null. For special columns in edges table, use {@code FAKE_COLUMN_EDGE_} values in this class.
* @param rows Elements (table rows: nodes/edges) to include in the exported file. Cannot be null. If null, all nodes/edges will be exported.
* @throws IOException When an error happens while writing the file
*/
public static void writeCSVFile(Graph graph, Table table, OutputStream out, Character separator, Charset charset, Integer[] columnIndexesToExport, Element[] rows) throws IOException {
if (out == null) {
throw new IllegalArgumentException("out cannot be null");
}
if (separator == null) {
separator = DEFAULT_SEPARATOR;
}
if (charset == null) {
charset = Charset.forName("UTF-8");
}
AttributeColumnsController ac = Lookup.getDefault().lookup(AttributeColumnsController.class);
boolean isEdgeTable = ac.isEdgeTable(table);
if (rows == null) {
if (isEdgeTable) {
rows = graph.getEdges().toArray();
} else {
rows = graph.getNodes().toArray();
}
}
TimeFormat timeFormat = graph.getModel().getTimeFormat();
DateTimeZone timeZone = graph.getModel().getTimeZone();
if (columnIndexesToExport == null) {
List<Integer> columnIndexesToExportList = new ArrayList<>();
//Add special columns for edges table:
if (isEdgeTable) {
columnIndexesToExportList.add(FAKE_COLUMN_EDGE_SOURCE);
columnIndexesToExportList.add(FAKE_COLUMN_EDGE_TARGET);
columnIndexesToExportList.add(FAKE_COLUMN_EDGE_TYPE);
}
for (Column column : table) {
columnIndexesToExportList.add(column.getIndex());
}
columnIndexesToExport = columnIndexesToExportList.toArray(new Integer[0]);
}
CsvWriter writer = new CsvWriter(out, separator, charset);
//Write column headers:
for (int column = 0; column < columnIndexesToExport.length; column++) {
int columnIndex = columnIndexesToExport[column];
if (columnIndex == FAKE_COLUMN_EDGE_SOURCE) {
writer.write("Source");
} else if (columnIndex == FAKE_COLUMN_EDGE_TARGET) {
writer.write("Target");
} else if (columnIndex == FAKE_COLUMN_EDGE_TYPE) {
writer.write("Type");
} else {
//Use the title only if it's the same as the id (case insensitive):
String columnId = table.getColumn(columnIndex).getId();
String columnTitle = table.getColumn(columnIndex).getId();
String columnHeader = columnId.equalsIgnoreCase(columnTitle) ? columnTitle : columnId;
writer.write(columnHeader, true);
}
}
writer.endRecord();
//Write rows:
Object value;
String text;
for (int row = 0; row < rows.length; row++) {
for (int i = 0; i < columnIndexesToExport.length; i++) {
int columnIndex = columnIndexesToExport[i];
if (columnIndex == FAKE_COLUMN_EDGE_SOURCE) {
value = ((Edge) rows[row]).getSource().getId();
} else if (columnIndex == FAKE_COLUMN_EDGE_TARGET) {
value = ((Edge) rows[row]).getTarget().getId();
} else if (columnIndex == FAKE_COLUMN_EDGE_TYPE) {
value = ((Edge) rows[row]).isDirected() ? "Directed" : "Undirected";
} else {
value = rows[row].getAttribute(table.getColumn(columnIndex));
}
if (value != null) {
text = AttributeUtils.print(value, timeFormat, timeZone);
} else {
text = "";
}
writer.write(text, true);
}
writer.endRecord();
}
writer.close();
}
use of org.gephi.datalab.api.AttributeColumnsController in project gephi by gephi.
the class CopyNodeDataToOtherNodes method execute.
@Override
public void execute() {
if (columnsToCopyData.length >= 0) {
AttributeColumnsController ac = Lookup.getDefault().lookup(AttributeColumnsController.class);
ac.copyNodeDataToOtherNodes(clickedNode, nodes, columnsToCopyData);
Lookup.getDefault().lookup(DataTablesController.class).refreshCurrentTable();
}
}
use of org.gephi.datalab.api.AttributeColumnsController in project gephi by gephi.
the class CopyNodeDataToOtherNodes method setup.
@Override
public void setup(Node[] nodes, Node clickedNode) {
this.clickedNode = clickedNode;
this.nodes = nodes;
AttributeColumnsController ac = Lookup.getDefault().lookup(AttributeColumnsController.class);
ArrayList<Column> columnsToCopyDataList = new ArrayList<>();
for (Column column : Lookup.getDefault().lookup(GraphController.class).getGraphModel().getNodeTable()) {
if (ac.canChangeColumnData(column)) {
columnsToCopyDataList.add(column);
}
}
columnsToCopyData = columnsToCopyDataList.toArray(new Column[0]);
}
Aggregations