cant get a new attribute from a node

Extensions and customization
Post Reply [phpBB Debug] PHP Warning: in file [ROOT]/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1275: count(): Parameter must be an array or an object that implements Countable
yxj0312
Posts:3
Joined:22 Mar 2013 18:42
[phpBB Debug] PHP Warning: in file [ROOT]/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1275: count(): Parameter must be an array or an object that implements Countable
cant get a new attribute from a node

Post by yxj0312 » 05 Apr 2013 14:23

hi, i am doing a plugin with some new features.

First i try to add a new Attribute, which names "Controller"(booleantypen) to the nodes.
here is my code:

Code: Select all

AttributeColumn controllerCol = nodeTable.getColumn("Controller");
            if(controllerCol == null){
                
                nodeTable.addColumn("Controller",AttributeType.BOOLEAN);
                for(Node n : nodes) {
                    n.getNodeData().getAttributes().setValue("Controller", Boolean.TRUE);
                   
                    
                } 
                }  else {
                nodeTable.getColumn("Controller");
                for(Node n : nodes) {
                    n.getNodeData().getAttributes().setValue("Controller", Boolean.TRUE);
                } 
it runs well.

but when i try to find those "Controller" node in another project. it will always return NullPointerException.

Code: Select all

n.getNodeData().getAttributes().getValue("Controller").equals(Boolean.TRUE)
it seems my plugin cant find the new customed attribute from a node.

can somebody help me .

User avatar
eduramiba
Gephi Code Manager
Posts:1064
Joined:22 Mar 2010 15:30
Location:Madrid, Spain
[phpBB Debug] PHP Warning: in file [ROOT]/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1275: count(): Parameter must be an array or an object that implements Countable

Re: cant get a new attribute from a node

Post by eduramiba » 05 Apr 2013 18:16

Hi,
You are probably some way not setting the "Controller" attribute for some of your nodes.
So these nodes will return null for the property.

This simple worked for me:

Code: Select all

        AttributeController ac = Lookup.getDefault().lookup(AttributeController.class);
        ac.getModel().getNodeTable().addColumn("Controller", AttributeType.BOOLEAN);
        
        for (Node node : graph.getNodes().toArray()) {
            node.getNodeData().getAttributes().setValue("Controller", Boolean.TRUE);
        }
        
        for (Node node : graph.getNodes().toArray()) {
            System.out.println(node.getNodeData().getAttributes().getValue("Controller").equals(Boolean.TRUE));
        }
Eduardo

Post Reply
[phpBB Debug] PHP Warning: in file [ROOT]/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1275: count(): Parameter must be an array or an object that implements Countable
[phpBB Debug] PHP Warning: in file [ROOT]/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1275: count(): Parameter must be an array or an object that implements Countable