Reset textfield using multiple identicalprogramnodes

Hello all,

I would like to be able to use a programNode multiple times in my program tree. In this programnode there is a textfield that may be given a value each time.

Unfortunately, the value entered in the textfield is always passed to all programnodes.

I have the textfields set up this way
view

contribution

and I have already tried the following solutions in another topic ( Bug when trying to store string with # - #2 by hch ):

  • a white space before the hashtags
  • instead of #.# : &hashmark

I have also tried the following:

  • textfield.setText(“”);

But these syntaxes unfortunately do not work. So I already have a hunch that it’s because of the dataModel and that I need to reset it, but I don’t know how. Anyone who can tell me this or knows another solution?

Greetings Zoe

Are the actual values saved in the respective DataModels wrong or just the view is wrong?
Are you calling the view.set… functions in the OpenView of the contribution as well?
You should call the view.set… functions where you are setting the text of the textfields in the openView of the contribution.

That is indeed a good question
I have checked it and it is only the representation that is not correct, the value in the data model is correct.

it might be a stupid question, but how do I get this value into the OpenView without the “value” parameter?
And then how do I process it in the programView?

i have tried the following:

view:
textfield method:
instellenField.setText(setTextTextFieldStopVertraging.getText());

public void setTextTextFieldStopVertraging(String txt) {
TextTextFieldStopVertraging.setText(txt);
}

contribution
openview:
view.setTextTextFieldStopVertraging(INSTELLEN_STOPVERTRAGING);

But it didn’t work…

yours sincerely,

Zoë

In your view when you are creating the textfield you can leave it as you originally had it for setting the Initial value of “standaardInstellenFieldText” assuming that it is a String variable.
Also for setting the text you could do;

public void setInstellenField(Double value){
    instellenField.setText(String.valueOf(value));
}

The String.valueOf will take the Double value provided and turn it into a String.

As for the contribution; when you need data saved in the DataModel you should use the model.get() function to retrieve it like you do in “getInstellenField()” or you could just use that function you created.
For example in your case it would be

view.setTextTextFieldStopVertraging(getInstellenField());
//or
//view.setTextTextFieldStopVertraging(model.get(INSTELLEN_STARTVERTRAGING, DEFAULT_STARTVERTRAGING));

Thank you for your quick reply and the example
I have tried both solutions, but unfortunately it doesn’t seem to help… Every new programNode still shows the same value in the textfields. Also if I adjust them

Are there any other ways to solve this?

Sincerely,
Zoë

If you downloaded the Starter pack you can compare your setup to one of the URCap examples provided by UR. For Example the HelloWorldSwing shows an example of what you are doing, although they are using a String but it functions the same way. I would compare the two to see what may be wrong. They also use the UndoRedoManager, which I would also recommend using when setting your datamodel.

I believe you can also find these examples on Github.

Quick question: Do the textfields all update to display the last thing you typed into one, or do they all say the same thing (like some initial value) and never change regardless of what you type? If it’s the later, then I think I see what’s happening.

Take a look at the order in which your functions are being called. When we click on the TextField, we call the getKeyboardForInstellenField() function. In here, we set its initial value to the result of getInstellenField(). This function returns the result of the model.get(). However, we have never set this value yet, so it will return the default value, DEFAULT_STARTVERTRAGING.

You can double check this quickly by changing this default value to something else, and seeing if all the textfields now display this new value.

This may be coupling with another issue, which as @nrivas mentions, you are not using UnderRedo manager to wrap your model.set() commands. It should look something like this:

public void onOK(Double value) {
	undoRedoManager.recordChanges(() -> {
		model.set(INSTELLEN_STARTVERTRAGING, value);
        view.setInstellenField(value);
	});
}

It’s possible that Polyscope is actually failing to set the model, so you always get the default return value. (Though I thought it threw an error saying it’s failed.)

Another completely different thing you could try is actually passing the contents of the textfield into the callback and use that to set your initial value. So in your view you would have:

KeyboardNumberInput<Double> keyboardInput = provider.get.getKeyboardForInstellenField(instellenField.getText());

You’ll have to add a String parameter to your function in the contribution, and do keyboard.setInitialValue(new_parameter)
This would ensure that what’s displayed when you click the box is always whatever was in the box last. To tie that into openView(), you’d have to use the datamodel with a model.get()

Something like:

view.setinstellenField(model.get(TEXTFIELD_VALUE, DEFAULT_VALUE); //If you have a function in view to access the textfield

Or

view.instellenField.setText(model.get(TEXTFIELD_VALUE, DEFAULT_VALUE)) //If you've declared the textfield as "Public"

Hello @nrivas & @eric.feldmann,

Comparing it to the helloWorldSwing program fixed the problem. Something was missing in the openview (like @nrivas said)

Thank you so much for all your help guys, without you I wouldn’t have gotten this far with coding and creating a URCap.

1 Like