Loading different class depending on option


I'm new here, I'm developing new KNIME nods which implements different metaheuristic methods of optimalization (TS, SA, EA etc.).

For different problem type (TSP, Function optimization, SAT) node require some problem-specific class to be loaded (representation of Solution, EvaluationFunction etc.)

As for now user can change problem type through node's configuration Dialog:

        addDialogComponent(new DialogComponentStringSelection(
                new SettingsModelString(
                        "Problem type: ", "TSP","FunctionOptimization","SAT"));


in Model this option is specified by this:

    private final SettingsModelString m_problem_type = new SettingsModelString(

Then, in Model, in config() method I'm trying to load problem-specific classes depending on different option:


ProblemManager method is quite plain and simple:

public static EvaluationFunction getProblemSpecificEvaluationFunction(String problemName) throws InstantiationException, IllegalAccessException{
        Class creator = null;
            try {
                creator = Class.forName("pl.wroc.pwr.metaheuristic.evaluationfunction."+problemName+"EvalFunction");
            } catch (ClassNotFoundException e) {
                logger.error("ClassNotFoundException during loading problem-specific classes (implementation of EvaluationFunction)");
        return (EvaluationFunction) creator.newInstance();

But as You can see it's not that neat solution - options' name in Dialog doesn't look too user-friendly ("FunctionOptimization", "RandomInitialSolution") and few others things could be programmed better.


So my question is - is there any way to obtain information on chosen option,which is DialogComponentStringSelection,

than using it's getStringValue? Can I get access to index of chosen option in Model class? I looked up KNIME API but I couldn't find any help concerning this aspect.

Maybe there is more neat way to load  those classes? Should it be done in config() section of Model class as it is right now, or should it be done somewhere else?


Thank You in advance for any help



Have a look at the "Set Operator" node (classes SetOperatorNodeDialog and SetOperation)

It uses an "enum" class (SetOperation) to associate Strings (the choices in the node dialog) with set operators. You could bundle the "problem type name" with the solution class.

In the dialog you could use the "DialogComponentStringSelection" provide it with the list of enum#values(). You still get (from the SettingsModelString) the name of the selected enum class, but it is easy to get the corresponing enum instance from it. I suspect it to be a nicer implementation.

Hope that helps. Let me know if I didn't get it right...

 - Peter.