01: /*
02: *
03: * (c) Copyright 2004 - 2007 osbl development team.
04: *
05: * This file is part of the osbl (http://osbl.wilken.de).
06: *
07: * the osbl is free software; you can redistribute it and/or modify
08: * it under the terms of the GNU General Public License
09: * as published by the Free Software Foundation; either version 2.1
10: * of the License, or (at your option) any later version.
11: *
12: * Please see COPYING for the complete licence.
13: */
14: package org.osbl.client.wings.action;
15:
16: import java.awt.event.ActionEvent;
17: import java.util.Map;
18: import java.util.HashMap;
19:
20: import org.wings.SIcon;
21: import org.wings.util.SessionLocal;
22: import org.osbl.client.wings.shell.*;
23:
24: /**
25: * @author hengels
26: * @version $Revision: 1.2 $
27: */
28: public class ShowApplicationAction extends NavigationAction {
29: protected Class<? extends Application> type;
30:
31: static final SessionLocal windows = new SessionLocal() {
32: protected Object initialValue() {
33: return new HashMap();
34: }
35: };
36:
37: public ShowApplicationAction(Class<? extends Application> type,
38: String command, SIcon icon) {
39: super (command, icon);
40: this .type = type;
41: }
42:
43: public ShowApplicationAction(Class<? extends Application> type,
44: String command) {
45: super (command);
46: this .type = type;
47: }
48:
49: public void actionPerformed(ActionEvent event) {
50: ApplicationWindow applicationWindow = getApplication();
51: Client.getInstance().pushWindow(applicationWindow);
52: }
53:
54: public void navigate(Object object) {
55: actionPerformed(new ActionEvent(this , -1, toString()));
56: }
57:
58: public void navigate(Map<String, String> query) {
59: actionPerformed(new ActionEvent(this , -1, toString()));
60: }
61:
62: protected Application createApplicationInstance() {
63: try {
64: return type.newInstance();
65: } catch (Exception e) {
66: throw new RuntimeException(e);
67: }
68: }
69:
70: private ApplicationWindow getApplication() {
71: Map<Class, ApplicationWindow> map = (Map<Class, ApplicationWindow>) windows
72: .get();
73: ApplicationWindow applicationWindow = map.get(type);
74: if (applicationWindow == null) {
75: Application application = createApplicationInstance();
76: applicationWindow = new ApplicationWindow(application);
77: map.put(type, applicationWindow);
78: }
79: return applicationWindow;
80: }
81:
82: static class ApplicationWindow extends Window {
83: Application application;
84:
85: public ApplicationWindow(Application application) {
86: this .application = application;
87: application.getEnvironment().setDelegate(this );
88: }
89:
90: public Application getApplication() {
91: return application;
92: }
93: }
94: }
|