Search in sources :

Example 1 with AttributeColumnsController

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]);
}
Also used : CopyDataToOtherColumn(org.gephi.datalab.plugin.manipulators.columns.CopyDataToOtherColumn) Column(org.gephi.graph.api.Column) AttributeColumnsController(org.gephi.datalab.api.AttributeColumnsController) ArrayList(java.util.ArrayList)

Example 2 with AttributeColumnsController

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;
}
Also used : AttributeColumnsController(org.gephi.datalab.api.AttributeColumnsController)

Example 3 with AttributeColumnsController

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();
}
Also used : TimeFormat(org.gephi.graph.api.TimeFormat) CsvWriter(com.csvreader.CsvWriter) ArrayList(java.util.ArrayList) DateTimeZone(org.joda.time.DateTimeZone) Column(org.gephi.graph.api.Column) AttributeColumnsController(org.gephi.datalab.api.AttributeColumnsController) Edge(org.gephi.graph.api.Edge)

Example 4 with AttributeColumnsController

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();
    }
}
Also used : AttributeColumnsController(org.gephi.datalab.api.AttributeColumnsController) DataTablesController(org.gephi.datalab.api.datatables.DataTablesController)

Example 5 with AttributeColumnsController

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]);
}
Also used : Column(org.gephi.graph.api.Column) AttributeColumnsController(org.gephi.datalab.api.AttributeColumnsController) ArrayList(java.util.ArrayList)

Aggregations

AttributeColumnsController (org.gephi.datalab.api.AttributeColumnsController)31 Column (org.gephi.graph.api.Column)23 Element (org.gephi.graph.api.Element)14 BigDecimal (java.math.BigDecimal)8 ArrayList (java.util.ArrayList)7 DataTablesController (org.gephi.datalab.api.datatables.DataTablesController)5 Edge (org.gephi.graph.api.Edge)3 PropertyEditor (java.beans.PropertyEditor)2 Node (org.gephi.graph.api.Node)2 TimeFormat (org.gephi.graph.api.TimeFormat)2 IntervalSet (org.gephi.graph.api.types.IntervalSet)2 AttributeValueWrapper (org.gephi.ui.tools.plugin.edit.EditWindowUtils.AttributeValueWrapper)2 DateTimeZone (org.joda.time.DateTimeZone)2 PropertySupport (org.openide.nodes.PropertySupport)2 Sheet (org.openide.nodes.Sheet)2 CsvWriter (com.csvreader.CsvWriter)1 Dialog (java.awt.Dialog)1 File (java.io.File)1 IOException (java.io.IOException)1 Charset (java.nio.charset.Charset)1