PojoUi

I am just starting using Annotations, however I am trying to involve them in my coding as much as I can. One way I found is to develop a simple framework (which I hope to put it on-line an open-source project once I develop the first simple rules about it).
My idea is to generate automatically the visual aspect of an application using the MVC concept. This I thought that could be done by using annotations both in the Controller and the Model classes.
I thought that the class declaration could be as follows:
@UIContainer(id="onePanel")
public class MyModel{
}and for example in the Model class the code could be something like this:
@UIObject(type="JTextField", id="oneTextField",
     x=20, y=20, width=100, height=20
     controler="package.ClassName.methodName");
     value="this")
public String getName(){
     return this.name;
public void setName(String name){
     this.name = name;
}Now as you can see the above code is not a very good implementation. Now a big issue I am facing is that I want the framework the generate the UI
interface at run time rather then at compile time.
But my 'What if's never stop! I imagine when the user will want a button on his User Interface which will update a JTextField value (which would have also been generated by the framework). In that case I thought that some of the controller code could be as follows:
@UIObject(type="JButton", id="OneButton",
     x=20, y=20, width=100, height=100
     controler="null");
     value="Reset")
public void resetUserNameTextFieldValue(){
     // Here id my problem.
     onePanel.txtOne.setText("");
}I know perfectly that the code above will never run. First of all the generated objects (onePanel, txtOne) are no were created then in run time, and thus at compile time they do not exists!
I know that the framework I would like to develop could be stupid and unrealistic (in which case please tell me). I also do understand that i=even if possible, the way I am planning it would leave out much of the items provided by swing (Layouts, Borders, etc.).
However do you think something like the above is possible? Do you think that the compiler could be avoided from raising such errors? and also do you know if something like this already exists? so hopefully I could stop hearting my little brain ;) :)
Thanks in advance for any suggestions (even insulting one at the above idea, since that is one way of learning stuff after all :).

So you want to add Annotations to your business object that describe a UI for editing it? The idea itself isn't to bad, IMHO, but it got some flaws:
- What if any object has more than one UIs?
- How do you define more complex UIs?
I'd move the UI definition into an external file (take a look at Glade for C(++)/GTK or XUL from Mozilla for real-world examples). That way you can change the UI without the need to change the business objects.
And sending those files would probably be easier than sending the classes + Annotations in a sensible/compatible manner.
And an implementation-specific sidenode: Why is type a String and not a Class?

Similar Messages

Maybe you are looking for