Note that there are some explanatory texts on larger screens.

plurals
  1. POGenerate view from a dynamic model
    text
    copied!<p>I have a model which can be modified at run time. Here's an example :</p> <pre><code>public class JavaMethod { private String name; private List&lt;Parameter&gt; parameters; private boolean isConstructor; // this is an example } </code></pre> <p>The parameters can have different type (<code>integer</code>, <code>boolean</code>, <code>string</code>, <code>float</code>...) and different valid values. For example, an integer parameter named <em>age</em> could only hold positive integers.</p> <p>The problem is that I would like to generate a view with Swing to configure that <code>JavaMethod</code>object, but I am not sure of the proper way to do it. </p> <p>For example, the <em>age</em> parameter which is a positive integer would be linked to a class extending <code>JTextField</code> that prevent entering negative any letters. Another integer parameter named <em>numberOfFingers</em> which can range from 8 to 12 would be linked to a class extending <code>JComboBox</code> that allows selection of an option in that range.</p> <p>I could do this with polymorphism by giving the task of generating the appropriate Swing component to the Parameter object, but then my model would know about how the view is generated.</p> <p>What is the proper way of generating a view for a model like this? All I can think of (without the model involved in the generation of the view) is a kind of giant switch in the controller that picks the good component by reading the Parameter's details.</p> <p>Thanks</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload