Search in sources :

Example 1 with DataTablesModel

use of org.gephi.desktop.datalab.DataTablesModel in project gephi by gephi.

the class DataLaboratoryPersistenceProvider method readDataTablesModel.

private void readDataTablesModel(XMLStreamReader reader, Workspace workspace) throws XMLStreamException {
    GraphModel graphModel = workspace.getLookup().lookup(GraphModel.class);
    Table nodesTable = graphModel.getNodeTable();
    Table edgesTable = graphModel.getEdgeTable();
    DataTablesModel dataTablesModel = workspace.getLookup().lookup(DataTablesModel.class);
    if (dataTablesModel == null) {
        workspace.add(dataTablesModel = new DataTablesModel(workspace));
    }
    AvailableColumnsModel nodeColumns = dataTablesModel.getNodeAvailableColumnsModel();
    nodeColumns.removeAllColumns();
    AvailableColumnsModel edgeColumns = dataTablesModel.getEdgeAvailableColumnsModel();
    edgeColumns.removeAllColumns();
    boolean end = false;
    while (reader.hasNext() && !end) {
        Integer eventType = reader.next();
        if (eventType.equals(XMLEvent.START_ELEMENT)) {
            String name = reader.getLocalName();
            if (NODE_COLUMN.equalsIgnoreCase(name)) {
                Integer id = Integer.parseInt(reader.getAttributeValue(null, "id"));
                Column column = nodesTable.getColumn(id);
                if (column != null) {
                    nodeColumns.addAvailableColumn(column);
                }
            } else if (EDGE_COLUMN.equalsIgnoreCase(name)) {
                Integer id = Integer.parseInt(reader.getAttributeValue(null, "id"));
                Column column = edgesTable.getColumn(id);
                if (column != null) {
                    edgeColumns.addAvailableColumn(column);
                }
            }
        } else if (eventType.equals(XMLStreamReader.END_ELEMENT)) {
            if (AVAILABLE_COLUMNS.equalsIgnoreCase(reader.getLocalName())) {
                end = true;
            }
        }
    }
}
Also used : Table(org.gephi.graph.api.Table) Column(org.gephi.graph.api.Column) GraphModel(org.gephi.graph.api.GraphModel) DataTablesModel(org.gephi.desktop.datalab.DataTablesModel) AvailableColumnsModel(org.gephi.desktop.datalab.AvailableColumnsModel)

Aggregations

AvailableColumnsModel (org.gephi.desktop.datalab.AvailableColumnsModel)1 DataTablesModel (org.gephi.desktop.datalab.DataTablesModel)1 Column (org.gephi.graph.api.Column)1 GraphModel (org.gephi.graph.api.GraphModel)1 Table (org.gephi.graph.api.Table)1