I have a URCap which has multiple ComboBoxes. The ComboBoxes are defined as private.
I add a few objects to the ComboBoxes when pushed a button.
But after removing the URCap from TreeNode and re-deploying them, the ComboBoxes have the objects I have added before deleting.
The values of the components I altered stayed with the URCap after removing them. Or when I add another one of the same URCap, the values stay the same.
I don’t know if I was able to explain the issue but the values of the components stay the same for different instances of the same URCap.
Where are the combo boxes you are referring to? Are they in program nodes or in the installation node? If you are loading the same saved program before and aftrer reinstallation of the URCap, then you should expect the program to remember the values in the combo box, assuming you use a program nodes DataModel to repopulate the combo boxes… Likewise if you have saved an installation file, if you remove the URCap and reinstall, the installation file will keep the data from the uninstalled URCap saved so that it can be re applied upon reinstallation, and again if these combo boxes are populated using data you save to the installation’s DataModel, this is the expected behaviour.
The other possibility assumes that your problem is with the UI not changing when clicking between different instances of different program noes of the same type. This is because whilst each program node has its own DataModel that is unique to a given program node instance, there is only a single instance of the view class that is used by each instance of that program node. This means that in order to update the UI for each program node, you should save information to a program nodes DataModel and then in `openView(), use the information saved in the data model to change any required UI components,
We would need more inforamtion about the circumstances under which this is happening in order to help confirm the cause of the problem you are seeing, hopefully 1 of the 2 above solutions above helps.
The error occurs since as I stated, there is only ever 1 instance of the programNodeView, and so the view can be given a specific instance of a DataModel. Think of the view class as “static”, for want of a better word.
You will need to fetch the specific contribution instance in the view class in order to save to the currently active DataModel. This will be performed in a listener of some sort which I assume you already have implemented (if not have a look at this post) to perform actions when changes to the comboBox occur. You need to use the ContributionProvider that is passed to the view class in buildUI(). The contribution provider has a pethod called get() which returns the current contribution instance. From there, make a public method in your contribution class that passed and can save any necessayry data to the data model.
I have created 2 arrays of String in ProgramNodeView.
Then I have created a function in ProgramNodeContribution:
private static final String COMBO = "comboBox";
private static final String COMBO1 = "comboBox1";
private static final String[] DEF_COMBO = {"default_value"};
public void setComboBoxesC(final String[] combo1, final String[] combo) {
undoRedoManager.recordChanges(new UndoableChanges() {
@Override
public void executeChanges() {
model.set(COMBO1, combo1);
model.set(COMBO, combo);
}
});
view.setComboBoxes(model.get(COMBO1, DEF_COMBO), model.get(COMBO, DEF_COMBO));
}
There is another function called setComboBoxes in ProgramNodeView that sets the String arrays to the comboBoxes:
I believe I used the DataModel as you have instructed but the same issue still persists. When I add another instance of this same Node the comboBoxes have values which were set in the instance before this.
You will need to call view.setComboBoxes() in openView() of your contribution class to update them when adding/flicking between nodes. The UI objects stored in the view class will only ever change when they are told to do so (usually by the contribution) so you have to make sure to change them in openView() as well as in your listeners.
The same issue still persists. The items of Combo Boxes in a Node exist in another instance as well.
Also, the items in ComboBoxes are not updated automatically. They are updated after clicking another Node and clicking back to our Node which has ComboBoxes.
Instead of using global variable, I have used it an instance variable. There is no problem right now except for not auto-updating the items in comboBoxes.