Source Code Cross Referenced for DefaultWindowManager.java in  » Web-Framework » webonswing » net » ar » webonswing » managers » windows » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Web Framework » webonswing » net.ar.webonswing.managers.windows 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        // WebOnSwing - Web Application Framework
002:        //Copyright (C) 2003 Fernando Damian Petrola
003:        //	
004:        //This library is free software; you can redistribute it and/or
005:        //modify it under the terms of the GNU Lesser General Public
006:        //License as published by the Free Software Foundation; either
007:        //version 2.1 of the License, or (at your option) any later version.
008:        //	
009:        //This library is distributed in the hope that it will be useful,
010:        //but WITHOUT ANY WARRANTY; without even the implied warranty of
011:        //MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
012:        //Lesser General Public License for more details.
013:        //	
014:        //You should have received a copy of the GNU Lesser General Public
015:        //License along with this library; if not, write to the Free Software
016:        //Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
017:
018:        package net.ar.webonswing.managers.windows;
019:
020:        import java.lang.reflect.*;
021:        import java.util.*;
022:
023:        import net.ar.webonswing.helpers.*;
024:        import net.ar.webonswing.wrapping.*;
025:
026:        /**
027:         * Implementacion simple de un administrador de ventanas; tiene la capacidad de
028:         * apilar las ventanas que se van abriendo para poder trabajar con ventanas de
029:         * tipo "modal".
030:         * 
031:         * @author Fernando Damian Petrola
032:         */
033:        public class DefaultWindowManager implements  WindowManager {
034:            public static final String AFTER_HIDE_METHOD_NAME = "theAfterHideMethodName";
035:            public static final String OPENER_WINDOW = "theOpenerWindow";
036:            public static final String WINDOW_MANAGER_PROPERTY = "theWindowManager";
037:
038:            protected Stack theStack;
039:            protected Hashtable theOpenersTable;
040:            private VisualWindow currentWindow;
041:
042:            protected void showNormal(Object aWindowToShow) {
043:            }
044:
045:            protected void hideNormal(Object aWindow) {
046:            }
047:
048:            protected WindowManager getWindowManager(Object anOpenerWindow) {
049:                VisualComponent theComponent = (VisualComponent) anOpenerWindow;
050:                return (WindowManager) theComponent
051:                        .getClientProperty(WINDOW_MANAGER_PROPERTY);
052:            }
053:
054:            protected void setWindowManager(Object aWindow,
055:                    WindowManager aWindowManager) {
056:                VisualComponent theComponent = (VisualComponent) aWindow;
057:                theComponent.putClientProperty(WINDOW_MANAGER_PROPERTY,
058:                        aWindowManager);
059:            }
060:
061:            protected VisualWindow getNewVisualWindowFor(Object aWindowToShow) {
062:                return (VisualWindow) aWindowToShow;
063:            }
064:
065:            protected boolean isWindowModal(Object aWindowToShow) {
066:                return false;
067:            }
068:
069:            protected boolean isWindowEquals(Object aComponent,
070:                    VisualWindow theWindowWrapper) {
071:                return aComponent.equals(theWindowWrapper);
072:            }
073:
074:            protected Object getRealWindow(Object aWindow) {
075:                return aWindow;
076:            }
077:
078:            public DefaultWindowManager() {
079:                theStack = new Stack();
080:                theOpenersTable = new Hashtable();
081:            }
082:
083:            public void show(VisualWindow aWindow, boolean isModal) {
084:                if (!isModal)
085:                    theStack.clear();
086:                else
087:                    addModalWindowExecuteMethod(aWindow);
088:
089:                setCurrentWindow(aWindow);
090:            }
091:
092:            protected void addModalWindowExecuteMethod(VisualWindow aWindow) {
093:                Object theMethod = aWindow
094:                        .getClientProperty(AFTER_HIDE_METHOD_NAME);
095:                if (theMethod != null)
096:                    theOpenersTable.put(aWindow.getName(), theMethod);
097:            }
098:
099:            public void hide(VisualWindow aWindow) {
100:                VisualWindow foundWindow = findWindowWithId(aWindow.getName());
101:                if (existOpennedWindows() && foundWindow != null) {
102:                    int indexOfWindow = theStack.indexOf(foundWindow);
103:
104:                    if (indexOfWindow > 0) {
105:                        VisualWindow parentWindow = (VisualWindow) theStack
106:                                .get(indexOfWindow - 1);
107:                        executeMethodForModalClosing(aWindow, parentWindow);
108:                        setCurrentWindow(parentWindow);
109:                    } else
110:                        setCurrentWindow((VisualWindow) theStack.peek());
111:
112:                    theStack.remove(foundWindow);
113:                }
114:
115:                if (!existOpennedWindows()) {
116:                    theStack.push(aWindow);
117:                    setCurrentWindow(aWindow);
118:                }
119:            }
120:
121:            protected void executeMethodForModalClosing(VisualWindow aWindow,
122:                    VisualWindow aParentWindow) {
123:                String theMethodName = (String) theOpenersTable.get(aWindow
124:                        .getName());
125:                if (theMethodName != null)
126:                    callReturnMethod(aParentWindow, aWindow, theMethodName);
127:            }
128:
129:            public VisualWindow getCurrentWindow() {
130:                if (!existOpennedWindows())
131:                    return null;
132:                else
133:                    return currentWindow;
134:            }
135:
136:            public void setCurrentWindow(VisualWindow aWindow) {
137:                setWindowManager(aWindow, this );
138:
139:                currentWindow = findWindowWithId(aWindow.getName());
140:
141:                if (currentWindow == null) {
142:                    currentWindow = aWindow;
143:                    theStack.push(aWindow);
144:                }
145:            }
146:
147:            public VisualWindow findWindowWithId(Object aName) {
148:                for (Iterator i = theStack.iterator(); i.hasNext();) {
149:                    VisualWindow theWindow = (VisualWindow) i.next();
150:                    if (theWindow.getName().equals(aName))
151:                        return theWindow;
152:                }
153:
154:                return null;
155:            }
156:
157:            public void replaceCurrentWindow(VisualWindow aReplaceWindow) {
158:                theStack.set(theStack.indexOf(currentWindow), aReplaceWindow);
159:                setCurrentWindow(aReplaceWindow);
160:            }
161:
162:            public void showChildWindow(Object anOpenerWindow,
163:                    Object aWindowToShow) {
164:                showAndExecute(anOpenerWindow, aWindowToShow, null);
165:            }
166:
167:            protected void callReturnMethod(VisualWindow aParentWindow,
168:                    VisualWindow aWindow, String theMethodName) {
169:                Object theWindow = getRealWindow(aWindow);
170:                Object theOpenerWindow = getRealWindow(aParentWindow);
171:
172:                callMethod(theMethodName, theWindow, theOpenerWindow);
173:            }
174:
175:            protected void callMethod(String theMethodName, Object theWindow,
176:                    Object theOpenerWindow) {
177:                try {
178:                    Method theMethod = theOpenerWindow.getClass()
179:                            .getMethod(theMethodName,
180:                                    new Class[] { theWindow.getClass() });
181:                    if (theMethod != null)
182:                        theMethod.invoke(theOpenerWindow,
183:                                new Object[] { theWindow });
184:                } catch (Exception e) {
185:                    throw new WebOnSwingException(
186:                            "Cannot invoke the method after window hide", e);
187:                }
188:            }
189:
190:            public void showAndExecute(Object anOpenerWindow,
191:                    Object aWindowToShow, String aMethodName) {
192:                WindowManager theWindowManager = getWindowManager(anOpenerWindow);
193:                setWindowManager(aWindowToShow, theWindowManager);
194:
195:                if (theWindowManager != null) {
196:                    VisualWindow theWindowToShowWrapper = getNewVisualWindowFor(aWindowToShow);
197:                    if (aMethodName != null)
198:                        theWindowToShowWrapper.putClientProperty(
199:                                AFTER_HIDE_METHOD_NAME, aMethodName);
200:
201:                    theWindowToShowWrapper.putClientProperty(OPENER_WINDOW,
202:                            anOpenerWindow);
203:                    theWindowManager.show(theWindowToShowWrapper,
204:                            isWindowModal(aWindowToShow));
205:                } else {
206:                    showNormal(aWindowToShow);
207:
208:                    if (aMethodName != null)
209:                        callMethod(aMethodName, aWindowToShow, anOpenerWindow);
210:                }
211:            }
212:
213:            public void hide(Object aWindow) {
214:                WindowManager theWindowManager = getWindowManager(aWindow);
215:
216:                if (theWindowManager != null) {
217:                    VisualWindow theFoundWindow = theWindowManager
218:                            .findWindow(aWindow);
219:                    if (theFoundWindow != null)
220:                        theWindowManager.hide(theFoundWindow);
221:                } else
222:                    hideNormal(aWindow);
223:            }
224:
225:            public VisualWindow findWindow(Object aComponent) {
226:                for (Iterator i = theStack.iterator(); i.hasNext();) {
227:                    VisualWindow theWindowWrapper = (VisualWindow) i.next();
228:                    if (isWindowEquals(aComponent, theWindowWrapper))
229:                        return theWindowWrapper;
230:                }
231:
232:                return null;
233:            }
234:
235:            public VisualWindow getWindow(String aWindowId) {
236:                VisualWindow foundWindow = null;
237:
238:                if (existOpennedWindows())
239:                    if (aWindowId != null)
240:                        foundWindow = findWindowWithId(aWindowId);
241:
242:                return foundWindow;
243:            }
244:
245:            private boolean existOpennedWindows() {
246:                return !theStack.isEmpty();
247:            }
248:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.