Package org.gephi.datalab.api

Examples of org.gephi.datalab.api.GraphElementsController


                    columnsList.add(addAttributeColumn(edges, columnNames[i], columnTypes[i]));
                }
            }

            //Create edges:
            GraphElementsController gec = Lookup.getDefault().lookup(GraphElementsController.class);
            Graph graph = Lookup.getDefault().lookup(GraphController.class).getModel().getGraph();
            String id = null;
            Edge edge;
            String sourceId, targetId;
            Node source, target;
            String type;
            boolean directed;
            Attributes edgeAttributes;
            reader = new CsvReader(new FileInputStream(file), separator, charset);
            reader.readHeaders();
            while (reader.readRecord()) {
                sourceId = reader.get(sourceColumn);
                targetId = reader.get(targetColumn);

                if (sourceId == null || sourceId.isEmpty() || targetId == null || targetId.isEmpty()) {
                    continue;//No correct source and target ids were provided, ignore row
                }

                graph.readLock();
                source = graph.getNode(sourceId);
                graph.readUnlock();

                if (source == null) {
                    if (createNewNodes) {//Create new nodes when they don't exist already and option is enabled
                        if (source == null) {
                            source = gec.createNode(null, sourceId);
                        }
                    } else {
                        continue;//Ignore this edge row, since no new nodes should be created.
                    }
                }

                graph.readLock();
                target = graph.getNode(targetId);
                graph.readUnlock();

                if (target == null) {
                    if (createNewNodes) {//Create new nodes when they don't exist already and option is enabled
                        if (target == null) {
                            target = gec.createNode(null, targetId);
                        }
                    } else {
                        continue;//Ignore this edge row, since no new nodes should be created.
                    }
                }

                if (typeColumn != null) {
                    type = reader.get(typeColumn);
                    //Undirected if indicated correctly, otherwise always directed:
                    if (type != null) {
                        directed = !type.equalsIgnoreCase("undirected");
                    } else {
                        directed = true;
                    }
                } else {
                    directed = true;//Directed by default when not indicated
                }

                //Prepare the correct edge to assign the attributes:
                if (idColumn != null) {
                    id = reader.get(idColumn);
                    if (id == null || id.isEmpty()) {
                        edge = gec.createEdge(source, target, directed);//id null or empty, assign one
                    } else {
                        edge = gec.createEdge(id, source, target, directed);
                        if (edge == null) {//Edge with that id already in graph
                            edge = gec.createEdge(source, target, directed);
                        }
                    }
                } else {
                    edge = gec.createEdge(source, target, directed);
                }

                if (edge != null) {//Edge could be created because it does not already exist:
                    //Assign attributes to the current edge:
                    edgeAttributes = edge.getEdgeData().getAttributes();
View Full Code Here


        searchOptions.setLoopToBeginning(true);//Restore loop behaviour
        return replacementsCount;
    }

    private SearchResult findOnNodes(SearchOptions searchOptions, int rowIndex, int columnIndex) {
        GraphElementsController gec = Lookup.getDefault().lookup(GraphElementsController.class);
        SearchResult result = null;
        Set<Integer> columnsToSearch = searchOptions.getColumnsToSearch();
        boolean searchAllColumns = columnsToSearch.isEmpty();
        Node[] nodes = searchOptions.getNodesToSearch();
        AttributeRow row;
        Object value;
        for (; rowIndex < nodes.length; rowIndex++) {
            if (!gec.isNodeInGraph(nodes[rowIndex])) {
                continue;//Make sure node is still in graph when continuing a search
            }
            row = (AttributeRow) nodes[rowIndex].getNodeData().getAttributes();
            for (; columnIndex < row.countValues(); columnIndex++) {
                if (searchAllColumns || columnsToSearch.contains(columnIndex)) {
View Full Code Here

        }
        return result;
    }

    private SearchResult findOnEdges(SearchOptions searchOptions, int rowIndex, int columnIndex) {
        GraphElementsController gec = Lookup.getDefault().lookup(GraphElementsController.class);
        SearchResult result = null;
        Set<Integer> columnsToSearch = searchOptions.getColumnsToSearch();
        boolean searchAllColumns = columnsToSearch.isEmpty();
        Edge[] edges = searchOptions.getEdgesToSearch();
        AttributeRow row;
        Object value;
        for (; rowIndex < edges.length; rowIndex++) {
            if (!gec.isEdgeInGraph(edges[rowIndex])) {
                continue;//Make sure edge is still in graph when continuing a search
            }
            row = (AttributeRow) edges[rowIndex].getEdgeData().getAttributes();
            for (; columnIndex < row.countValues(); columnIndex++) {
                if (searchAllColumns || columnsToSearch.contains(columnIndex)) {
View Full Code Here

        this.nodes = nodes;
        this.clickedNode=clickedNode;
    }

    public void execute() {
        GraphElementsController gec = Lookup.getDefault().lookup(GraphElementsController.class);
        gec.setNodesFixed(nodes, true);
        Lookup.getDefault().lookup(DataTablesController.class).refreshCurrentTable();
    }
View Full Code Here

    public String getDescription() {
        return "";
    }

    public boolean canExecute() {
        GraphElementsController gec = Lookup.getDefault().lookup(GraphElementsController.class);
        return !gec.isNodeFixed(clickedNode);
    }
View Full Code Here

*/
@ServiceProvider(service=GraphContextMenuItem.class)
public class Group extends BasicItem {

    public void execute() {
        GraphElementsController gec=Lookup.getDefault().lookup(GraphElementsController.class);
        gec.groupNodes(nodes);
    }
View Full Code Here

    public void execute() {
        NotifyDescriptor.Confirmation notifyDescriptor = new NotifyDescriptor.Confirmation(
                NbBundle.getMessage(Delete.class, "GraphContextMenu.Delete.message"),
                NbBundle.getMessage(Delete.class, "GraphContextMenu.Delete.message.title"), NotifyDescriptor.YES_NO_OPTION);
        if (DialogDisplayer.getDefault().notify(notifyDescriptor).equals(NotifyDescriptor.YES_OPTION)) {
            GraphElementsController gec = Lookup.getDefault().lookup(GraphElementsController.class);
            gec.deleteNodes(nodes);
        }
    }
View Full Code Here

*/
@ServiceProvider(service = GraphContextMenuItem.class)
public class Settle extends BasicItem{

    public void execute() {
        GraphElementsController gec = Lookup.getDefault().lookup(GraphElementsController.class);
        gec.setNodesFixed(nodes, true);
    }
View Full Code Here

*/
@ServiceProvider(service = GraphContextMenuItem.class)
public class Ungroup extends BasicItem {

    public void execute() {
        GraphElementsController gec = Lookup.getDefault().lookup(GraphElementsController.class);
        gec.ungroupNodes(nodes);
    }
View Full Code Here

                    }
                }
            }

            //Create nodes:
            GraphElementsController gec = Lookup.getDefault().lookup(GraphElementsController.class);
            Graph graph = Lookup.getDefault().lookup(GraphController.class).getModel().getGraph();
            String id = null;
            Node node;
            Attributes nodeAttributes;
            reader = new CsvReader(new FileInputStream(file), separator, charset);
            reader.setTrimWhitespace(false);
            reader.readHeaders();
            while (reader.readRecord()) {
                //Prepare the correct node to assign the attributes:
                if (idColumn != null) {
                    id = reader.get(idColumn);
                    if (id == null || id.isEmpty()) {
                        node = gec.createNode(null);//id null or empty, assign one
                    } else {
                        graph.readLock();
                        node = graph.getNode(id);
                        graph.readUnlock();
                        if (node != null) {//Node with that id already in graph
                            if (assignNewNodeIds) {
                                node = gec.createNode(null);
                            }
                        } else {
                            node = gec.createNode(null, id);//New id in the graph
                        }
                    }
                } else {
                    node = gec.createNode(null);
                }
                //Assign attributes to the current node:
                nodeAttributes = node.getNodeData().getAttributes();
                for (AttributeColumn column : columnsList) {
                    setAttributeValue(reader.get(columnHeaders.get(column)), nodeAttributes, column);
View Full Code Here

TOP

Related Classes of org.gephi.datalab.api.GraphElementsController

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.