Question to WidgetGroup and Effects

Hi,
let me first explain what I would like to do (though I have no clue whether I’ve chosen the right approach…)
I would like to have a checkbox. If it’s checked several different widgets should be enabled. I’ve made a little testcase which partially does what it should:

@Widget(title = "Use Settings", description = "...")
@ValueReference(UseSettingsReference.class)
boolean m_useSettings = false;
	
static final class UseSettingsReference implements BooleanReference {
}

@Persistor(TestPersistor.class)
TestGroup tg = new TestGroup();
	
@Effect(predicate = UseSettingsPredicate.class, type = EffectType.ENABLE)
static class TestGroup implements WidgetGroup {
	@Widget(title = "w1", description = "")
	@TextInputWidget()
	String m_teststring = "test";
		
	@Widget(title = "w2", description = "")
	@NumberInputWidget()
	int m_testnumber = 5;
}
	
public static final class UseSettingsPredicate implements EffectPredicateProvider {

	@Override
	public EffectPredicate init(PredicateInitializer i) {
		// TODO Auto-generated method stub
		return i.getBoolean(UseSettingsReference.class).isTrue();
	}
		
}
	
private static final class TestPersistor implements NodeParametersPersistor<TestGroup> {

	@Override
	public TestGroup load(NodeSettingsRO settings) throws InvalidSettingsException {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public void save(TestGroup param, NodeSettingsWO settings) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public String[][] getConfigPaths() {
		// TODO Auto-generated method stub
		return null;
	}
		
}

As a result widget w2 can be enabled/disabled via the checkbox while it’s not possible for w1. If I change w1 to a number input widget it works.

First question: Is this the right approach? Finally, I want to have a dropdown box, a number input widget and another checkbox in that group.
Second question: Do I have to implement this Persistor class? If I try to run it without, KNIME complains at runtime about a missing default persistor class for TestGroup

Thanks a lot in advance!
Antje

Hi Antje,

the solution here would be to use NodeParameters instead of WidgetGroup. With that, no custom @Persistor is required and I get the expected result:

I cannot reproduce the issue that only the number input is disabled. Do you still get that with this code:

    static final class UseSettingsReference implements BooleanReference {
    }

    TestGroup tg = new TestGroup();

    @Effect(predicate = UseSettingsPredicate.class, type = EffectType.ENABLE)
    static class TestGroup implements NodeParameters {
        @Widget(title = "w1", description = "")
        @TextInputWidget()
        String m_teststring = "test";

        @Widget(title = "w2", description = "")
        @NumberInputWidget()
        int m_testnumber = 5;
    }

    public static final class UseSettingsPredicate implements EffectPredicateProvider {

        @Override
        public EffectPredicate init(final PredicateInitializer i) {
            return i.getBoolean(UseSettingsReference.class).isTrue();
        }

    }

Best Regards,
Paul

PS: In case of a BooleanReference one can even use the reference directly as an EffectPredicateProvider, i.e. @Effect(predicate = UseSettingsReference.class, …

1 Like

Thank you very much for the quick reply. Actually, I was wrong with my assumption that text input is not disabled. In my first test, I had an empty string as default content. With that a disabled text input widget basically looks the same as an enabled one (though it is actually disabled…)
Sorry for the confusion!

Thanks a lot for the help! Good to know that I should use NodeParameters in that case. And also good to know that I can use a boolean reference directly as predicate.

Best,
Antje

@Paul_Brnrthr

May I add a related question?
I tried to use additional effects within the group but it seem that it overwrites the effect for the whole group. Probably it’s not a good idea to nest effects?

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.