Search in sources :

Example 1 with DataTablesController

use of org.gephi.datalab.api.datatables.DataTablesController in project gephi-plugins-bootcamp by gephi.

the class InvertRowSelection method execute.

@Override
public void execute() {
    //Note that a function to inverse selection directly in the table with DataTablesController
    //would be more efficient than calculating it here, but this example demonstrates some table selection features.
    DataTablesController dtc = Lookup.getDefault().lookup(DataTablesController.class);
    Graph graph = Lookup.getDefault().lookup(GraphController.class).getGraphModel().getGraph();
    if (dtc.isNodeTableMode()) {
        //Get currently selected nodes and calculate inverse set.
        Node[] selected = dtc.getNodeTableSelection();
        ArrayList<Node> nodes = new ArrayList<Node>();
        nodes.addAll(Arrays.asList(graph.getNodes().toArray()));
        for (Node node : selected) {
            nodes.remove(node);
        }
        dtc.setNodeTableSelection(nodes.toArray(new Node[0]));
    } else if (dtc.isEdgeTableMode()) {
        //Get currently selected edges and calculate inverse set.
        Edge[] selected = dtc.getEdgeTableSelection();
        ArrayList<Edge> edges = new ArrayList<Edge>();
        edges.addAll(Arrays.asList(graph.getEdges().toArray()));
        for (Edge edge : selected) {
            edges.remove(edge);
        }
        dtc.setEdgeTableSelection(edges.toArray(new Edge[0]));
    }
}
Also used : Graph(org.gephi.graph.api.Graph) Node(org.gephi.graph.api.Node) ArrayList(java.util.ArrayList) Edge(org.gephi.graph.api.Edge) DataTablesController(org.gephi.datalab.api.datatables.DataTablesController)

Example 2 with DataTablesController

use of org.gephi.datalab.api.datatables.DataTablesController in project gephi by gephi.

the class SelectEdgesOnTable method execute.

@Override
public void execute() {
    DataTablesController dtc = Lookup.getDefault().lookup(DataTablesController.class);
    dtc.setEdgeTableSelection(edges);
    dtc.selectEdgesTable();
}
Also used : DataTablesController(org.gephi.datalab.api.datatables.DataTablesController)

Example 3 with DataTablesController

use of org.gephi.datalab.api.datatables.DataTablesController in project gephi by gephi.

the class ImportCSVUIWizardAction method performAction.

@Override
public void performAction() {
    wizardDescriptor = new WizardDescriptor(getPanels());
    step1.setWizardDescriptor(wizardDescriptor);
    step2.setWizardDescriptor(wizardDescriptor);
    // {0} will be replaced by WizardDesriptor.Panel.getComponent().getName()
    wizardDescriptor.setTitleFormat(new MessageFormat("{0}"));
    wizardDescriptor.setTitle(getName());
    Dialog dialog = DialogDisplayer.getDefault().createDialog(wizardDescriptor);
    dialog.setVisible(true);
    dialog.toFront();
    boolean cancelled = wizardDescriptor.getValue() != WizardDescriptor.FINISH_OPTION;
    if (!cancelled) {
        //General parameters:
        File file = (File) wizardDescriptor.getProperty("file");
        Character separator = (Character) wizardDescriptor.getProperty("separator");
        Charset charset = (Charset) wizardDescriptor.getProperty("charset");
        String[] columnNames = (String[]) wizardDescriptor.getProperty("columns-names");
        Class[] columnTypes = (Class[]) wizardDescriptor.getProperty("columns-types");
        //Nodes import parameters:
        Boolean assignNewNodeIds = (Boolean) wizardDescriptor.getProperty("assign-new-node-ids");
        //Edges import parameters:
        Boolean createNewNodes = (Boolean) wizardDescriptor.getProperty("create-new-nodes");
        Graph graph = Lookup.getDefault().lookup(GraphController.class).getGraphModel().getGraph();
        AttributeColumnsController ac = Lookup.getDefault().lookup(AttributeColumnsController.class);
        DataTablesController dtc = Lookup.getDefault().lookup(DataTablesController.class);
        dtc.setAutoRefreshEnabled(false);
        try {
            switch((Mode) wizardDescriptor.getProperty("mode")) {
                case NODES_TABLE:
                    ac.importCSVToNodesTable(graph, file, separator, charset, columnNames, columnTypes, assignNewNodeIds);
                    break;
                case EDGES_TABLE:
                    ac.importCSVToEdgesTable(graph, file, separator, charset, columnNames, columnTypes, createNewNodes);
                    break;
            }
            dtc.refreshCurrentTable();
        } catch (Exception e) {
            Logger.getLogger("").log(Level.SEVERE, null, e);
        } finally {
            dtc.setAutoRefreshEnabled(true);
        }
    }
    step1.unSetup();
    step2.unSetup();
}
Also used : MessageFormat(java.text.MessageFormat) Charset(java.nio.charset.Charset) WizardDescriptor(org.openide.WizardDescriptor) Graph(org.gephi.graph.api.Graph) Dialog(java.awt.Dialog) AttributeColumnsController(org.gephi.datalab.api.AttributeColumnsController) File(java.io.File) DataTablesController(org.gephi.datalab.api.datatables.DataTablesController)

Example 4 with DataTablesController

use of org.gephi.datalab.api.datatables.DataTablesController in project gephi by gephi.

the class ExportTable method execute.

@Override
public void execute() {
    DataTablesController dtc = Lookup.getDefault().lookup(DataTablesController.class);
    dtc.exportCurrentTable(DataTablesController.ExportMode.CSV);
}
Also used : DataTablesController(org.gephi.datalab.api.datatables.DataTablesController)

Example 5 with DataTablesController

use of org.gephi.datalab.api.datatables.DataTablesController in project gephi by gephi.

the class SelectNodesOnTable method execute.

@Override
public void execute() {
    Node[] nodes = new Node[] { clickedEdge.getSource(), clickedEdge.getTarget() };
    DataTablesController dtc = Lookup.getDefault().lookup(DataTablesController.class);
    dtc.setNodeTableSelection(nodes);
    dtc.selectNodesTable();
}
Also used : Node(org.gephi.graph.api.Node) DataTablesController(org.gephi.datalab.api.datatables.DataTablesController)

Aggregations

DataTablesController (org.gephi.datalab.api.datatables.DataTablesController)5 Graph (org.gephi.graph.api.Graph)2 Node (org.gephi.graph.api.Node)2 Dialog (java.awt.Dialog)1 File (java.io.File)1 Charset (java.nio.charset.Charset)1 MessageFormat (java.text.MessageFormat)1 ArrayList (java.util.ArrayList)1 AttributeColumnsController (org.gephi.datalab.api.AttributeColumnsController)1 Edge (org.gephi.graph.api.Edge)1 WizardDescriptor (org.openide.WizardDescriptor)1