Controller map??

1 view
Skip to first unread message

Raul_Arabaolaza

unread,
Jul 27, 2010, 6:23:29 AM7/27/10
to SDL/Swing
Hi,

Is there any option to get one controller from other without using any
reference to a component under the first controller??

My situation is that i have a master window which uses one controller,
and then i show a secondary window with details of one record and
buttons for delete and edit the record, this secondary window uses it
´s own controller diferent from the controller of the main window.

After the edit or remove operations i want to refresh the main window,
that is call one of it´s controller methods but i´m not able to get
the reference properly initialized... not to mention i don´t want a
lot of controller instances in my space memory :)

I´ve various alternatives to solve this, isolate all GUI stuff to a
presenter and make the controllers simply do nothing but call it, but
that way i need to inject swing components in the presenters and i
suspect sometimes i will not be able to do that properly... probably
the best option is to maintain a map of controllers and use the shown
method to atach controllers to it.

I´m a little stuck. Do you guys sometime faced this problem?? if so,
how did you solve it??

For the moment i´m going to use the controller map and post the code
here later.

regards, Raúl

raul.ar...@gmail.com

unread,
Jul 27, 2010, 8:02:50 AM7/27/10
to SDL/Swing
Forget the last message it was my fault, the controller map seems a simple solution, simply a map variable and one call in my shown method like:

Application.addController("scaffold", this);

In my case i use an application class like this to initialize the event namespace, the look and feel and so.... it will have to be changed when the next version of sdlswing is released but for the moment it works.

public class Application {

private static Map<String,FormController> map=new HashMap<String, FormController>();

public void start(String frameTitle, String sdlFileName) {
try {
UIManager
.setLookAndFeel("com.sun.java.swing.plaf.nimbus.NimbusLookAndFeel");
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
initializeDeclarativeListeners();
UI.startApplication(frameTitle, sdlFileName);
}

protected void initializeDeclarativeListeners() {
UI.registerPropertyHandler("event", new ComponentPropertyHandler() {
@Override
public void set(final Component component, String key, final Object value)
throws UIBindingException {
if (key.equalsIgnoreCase("doubleClicked")) {
addDoubleClickListener(component, value);
}
}
});
}
private void addDoubleClickListener(final Component component,
final Object value) {
component.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
if (e.getClickCount() == 2) {
FormController controller = UI
.getFormForComponent(component)
.getController();
try {
Method m = controller.getClass()
.getDeclaredMethod(value.toString(),
new Class[] {});
m.invoke(controller, new Object[] {});
} catch (Exception e1) {
throw new UIBindingException("Problem trying to execute method "+value+"as double click listener for "+component.getName(), e1);
}

}
}
});
}

public static FormController getControllerByID(String id){
return Application.map.get(id);
}

public static synchronized void addController(String id, FormController controller){
Application.map.put(id, controller);
}

}

El 27/07/2010 13:25, Raúl Arabaolaza <raul.ar...@gmail.com> escribió:
> After taking a good look at the source code i think i can use the Ui.showInDialog method instead of creating a new jFrame for the details and hopefu
>
> 2010/7/27 Raul_Arabaolaza raul.ar...@gmail.com>

Dan Leuck

unread,
Jul 27, 2010, 9:03:19 PM7/27/10
to sdls...@googlegroups.com
That is what I was going to suggest as a short term solution. We
should probably set things up so forms and/or controllers are
automatically registered and accessible from the UI or Application
class.
Reply all
Reply to author
Forward
0 new messages