ItemListener for Combo Box in Installation Node

Hello,

I am currently working on developing a urcap for my application. I have successfully created a drop down menu for selection in the Installation Node, but on the selection of certain parameter i am unable to send the data back. How do i do this?

In the program node, it is easy to do it with and there are several examples of it, but in the installation node, i am unable to find such example too which returns the data after selection. Anyone with an answer for this?

Thanks.

Hello vinneth1,

i’m not quite sure if I understood your problem to the full extend. As far as I know you can create such a combobox just the same way as in the ProgramNode. Just make sure to use the InstallationNodeContribution instead of a ProgramNodeContribution.

You could take a look at how it’s done in the ProgramNode in this tutorial.:
https://plus.universal-robots.com/getting-started/myfirsturcap-creating-the-view/

Hello Lutter,

I cannot do this way because i do not use the ContributionProvider class. If i have to do that way, then i have to redo everything. I could create the combobox in the installation node, and i could see the drop down menu also. But upon a certain selection of the combobox items, i need to update the combobox items.

For eg:

Box box = Box.createHorizontalBox();
box.setAlignmentX(Component.LEFT_ALIGNMENT);

	JLabel label = new JLabel(" digital_out ");

	combo.setPreferredSize(new Dimension(104, 30));
	combo.setMaximumSize(combo.getPreferredSize());

	combo.addItemListener(new ItemListener() {
		
		@Override
		public void itemStateChanged(ItemEvent e) {
			if(e.getStateChange() == ItemEvent.SELECTED) {
				//provider.get().onOutputSelection((Integer) e.getItem());///( How do i get this command with normal class and not using Contribution provider?)
			}
		}
	});

	box.add(label);
	box.add(combo);

	return box;

I could do all the commands except the provider.get() how do i do that? Thanks again

You don’t need to use a ContributionProvider in the InstallationNode. You can directly link your InstallationNodeContribution inside your InstallationNodeView.

Here is an example of a similar function inside the view:

   	private Box createFunctionalityEnabledBox(String text, final TCIInstallationNodeContribution contribution) {
	Box box = Box.createHorizontalBox();
	box.setAlignmentX(Component.LEFT_ALIGNMENT);
	
	CHECKBOX_FUNCTIONALITY_ENABLED.setText(text);
	CHECKBOX_FUNCTIONALITY_ENABLED.addActionListener(new ActionListener() {
		
		@Override
		public void actionPerformed(ActionEvent e) {
			contribution.userSelectedFunctonalityEnabled(CHECKBOX_FUNCTIONALITY_ENABLED.isSelected());
		}
	});
	
	box.add(CHECKBOX_FUNCTIONALITY_ENABLED);
	
	return box;
}

Also make sure to link your contribution in the BuildUI method.

	@Override
public void buildUI(JPanel panel, TCIInstallationNodeContribution contribution) {
	panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS));
	panel.add(createFunctionalityEnabledBox("Test", contribution));

I hope this helps you out.

Best Wishes,
Florian

Hello Florian,

I tried the code above, it does not work. May i know what is CHECKBOX_FUNCTIONALITY_ENABLED?

This code snippet doesn’t work as is. It’s from one of my projects. It’s supposed to give you a concept of how it’s done for your code, not to run it as is.

Your line:

Should be replaced with: contribution.onOutputSelection((Integer) e.getItem());

Also you need to change the Declaration where you define your combobox to accept a InstallationNodeContribution as argument instead of a ContributionProvider. Similar to:

private Box createFunctionalityEnabledBox(String text, final TCIInstallationNodeContribution contribution) {

Also in BuildUI you need to hand over the contribution instead of the provider.

I hope this helps.

Hello Florian,

It worked. Thank you so much for the help.