Checkbox inside checkbox

Hi!

i am developing a custom URCap having the following structure for the first case:

  • Inside the installation tab i have two independent checkboxed making visible two checkboxes in the program page that we will call checkboxA and checkboxB
  • checknoxA is a checkbox independent from B
  • checkboxB is a checkbox independent from A

By pressing on checkbox A, a custom Node is added to the program Node,
By pressing on checkbox B , a second custom node is nested correcly inside the custom programNode (if i remove this checkbox, then the custom nested node is removed)

EDIT: As you can see from the second picture, (the blue and yellow), each time i add the yellow custom instruction inside the blue instruction, an extra instruction is added

Can some one figure this out?

case b:

  • Inside the installation tab i have two independent checkboxed making visible two checkboxes in the program page that we will call checkboxA and checkboxB
  • checknoxA is the mastercheckbox
    *checkboxB is a checkbox nested in checkbox A

By pressing on checkbox A, a custom Node is added to the program Node,
By pressing on checkbox B , a second custom node is nested for TWO times indie the custom Porgram node. if i press the checkbox to eliminate the check, only one customInstruction is removed. If i retry to add this custom instruction, this time THREE instructions are add (it is like a counter always increasing by one).

Has this to someone else?
The main instruction is the one added by CheckboxA, checkboxB adds the green instructions and as you can see here it has added two instructions instead of one.

Probably going to have to see some code to help you on this one. I’ve experienced some weird accumulation like this before when I was misusing the “Static” modifier, and when using certain kinds of listeners on the UI components. Make sure whatever listener you have on your checkbox is not being fired by, say, the creation of the component itself, or an openView() method setting the state and triggering it to fire again. Putting a lot of “System.out.println()” statements will help you debug what’s actually going on.

the listener

Check.addItemListener(new ItemListener() {    
            public void itemStateChanged(ItemEvent e) {   
	            if (e.getStateChange()==1){
	            	System.out.println(e);
	            	System.out.println("add");
	            	if (locprovider.get().childNodeAlreadyExists())
	            	{
	            	System.out.println("esiste di gia");
	            	}
	            	else {
	            		locprovider.get().createNode();
	            	}
	            }
	            else {
	          
	            	System.out.println("remove");
					locprovider.get().removeNodes();
					}}});

the ChildNodeMethod

	public boolean childNodeAlreadyExists() {
		final boolean[] foundChild = new boolean[1];
		foundChild[0] = false;
		System.out.println("ciaone133333333333");
		TreeNode root = apiProvider.getProgramAPI().getProgramModel().getRootTreeNode(this);
		System.out.println("ciaone111222222222");
		root.traverse(new ProgramNodeVisitor() {
			@Override
			public void visit(URCapProgramNode programNode, int index, int depth) {
//				if (index >1) {
//					index = 1;
//				}
				System.out.println(index);
				System.out.println(depth);
				System.out.println("ciaone1111");
				if(programNode.canGetAs(Stitch_Weld_Service.class)) {
					System.out.println("ciaone");
					foundChild[0] = true;
				}
				super.visit(programNode, index, depth);
			}
		});
		System.out.println(foundChild[0]);
		return foundChild[0];
	}

the createNode

public void createStitchNode() {
		this.Node = Node;
		ProgramAPI programAPI = apiProvider.getProgramAPI();
		ProgramModel programModel = programAPI.getProgramModel();
		final ProgramNodeFactory progNodeFactory = programModel.getProgramNodeFactory();
		final TreeNode treeNode = programModel.getRootTreeNode(this);
		final TreeNode rootTreeNode = programModel.getRootTreeNode(this);
		undoRedoManager.recordChanges(new UndoableChanges() {
			@Override

			public void executeChanges() {
				try {
					
					Node = programNodeFactory.createURCapProgramNode(Custom_Service.class);
		
					treeNode.insertChildAfter(TreeNode, Node);
					

				} catch (TreeStructureException e) {
					e.printStackTrace();
				}

			}
		});

	}

I did not use any static

while compiling the code, this is what i get the corresponding printOut for the program that you can see in the yellow and blue pciture. As you can see the index increases each time (1…2…3…4)
Senza nome2

Even if i try to add my customInstruction connected to checkbox 2 when i already have this instruction implemented, the checkChild still gives out a false

So yeah the listener on your checkbox is probably triggering more times than you think. That’s because if you have some method in your openView() that sets its value, it’s going to trigger. Basically, the stateChange listener can fire programmatically, when you probably want it to fire only as a result of actually tapping on it. Try the onClick() or onRelease() methods of a MouseListener. You would then just check if(Check.isSelected()) to determine if you should add or delete the node. (This all might be a non-issue, as I think the real problem here is that your “already exists” code is not functioning properly, so the checkbox listener is always thinking there’s no child of that type, so it inserts another.

As for failing to find the node (I’m assuming that’s what the “false” printout at the bottom means) that could be a couple things, but it looks like it might just be that you’re checking if the node can be gotten as the service. I don’t think it works that way. I’m pretty sure its typed as a StitchWeldProgramNodeContribution or whatever you named your contribution class file.

Alternatively, you can create a custom interface, implement that in your stitch node, and getAs() your interface. That would look like this:

At the top of the contribution, when declaring the class

public class StitchWeldContribution implements ProgramNodeContribution, myCustomInterface {
root.traverse(new ProgramNodeVisitor() {
			@Override
			public void visit(URCapProgramNode programNode, int index, int depth) {
//				if (index >1) {
//					index = 1;
//				}
				System.out.println(index);
				System.out.println(depth);
				System.out.println("ciaone1111");
				if(programNode.canGetAs(myCustomInterface.class)) {  //<------ here's the edited line
					System.out.println("ciaone");
					foundChild[0] = true;
				}
				super.visit(programNode, index, depth);
			}
		});