View Javadoc

1   /*
2    * EL4J, the Extension Library for the J2EE, adds incremental enhancements to
3    * the spring framework, http://el4j.sf.net
4    * Copyright (C) 2005 by ELCA Informatique SA, Av. de la Harpe 22-24,
5    * 1000 Lausanne, Switzerland, http://www.elca.ch
6    *
7    * EL4J is published under the GNU Lesser General Public License (LGPL)
8    * Version 2.1. See http://www.gnu.org/licenses/
9    *
10   * This program is distributed in the hope that it will be useful,
11   * but WITHOUT ANY WARRANTY; without even the implied warranty of
12   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13   * GNU Lesser General Public License for more details.
14   *
15   * For alternative licensing, please contact info@elca.ch
16   */
17  package ch.elca.el4j.services.gui.swing.cookswing;
18  
19  import javax.swing.JDesktopPane;
20  import javax.swing.event.MenuEvent;
21  import javax.swing.event.MenuListener;
22  
23  import org.w3c.dom.Element;
24  
25  import ch.elca.el4j.services.gui.swing.mdi.WindowManager;
26  import ch.elca.el4j.services.gui.swing.mdi.WindowMenu;
27  
28  import cookxml.core.DecodeEngine;
29  import cookxml.core.exception.CookXmlException;
30  import cookxml.core.exception.CreatorException;
31  import cookxml.core.interfaces.Creator;
32  
33  /**
34   * The cookSwing creator for <windowmenu>s, which list all opened forms
35   * inside the desktop pane and some operations on them.
36   *
37   * @svnLink $Revision: 3884 $;$Date: 2009-08-04 15:48:31 +0200 (Di, 04. Aug 2009) $;$Author: swismer $;$URL: https://el4j.svn.sourceforge.net/svnroot/el4j/branches/el4j_3_1/el4j/framework/modules/swing/src/main/java/ch/elca/el4j/services/gui/swing/cookswing/WindowMenuCreator.java $
38   *
39   * @author Stefan Wismer (SWI)
40   */
41  public class WindowMenuCreator implements Creator {
42  
43  	/**
44  	 * This {@link MenuListener} lazily initialized the window menu. This
45  	 * is necessary because generally the desktop pane XML element is declared
46  	 * after the menu and therefore the cannot be resolved.
47  	 */
48  	private class LazyWindowMenuCreator implements MenuListener {
49  		/**
50  		 * The cookXML decoder engine.
51  		 */
52  		private DecodeEngine m_decodeEngine;
53  		
54  		/**
55  		 * The window menu.
56  		 */
57  		private WindowMenu m_menu;
58  		
59  		/**
60  		 * The id of the desktop pane XML element.
61  		 */
62  		private String m_desktopPaneId;
63  		
64  		/**
65  		 * @param decodeEngine     the cookXML decoder engine
66  		 * @param menu             the window menu
67  		 * @param desktopPaneId    the id of the desktop pane XML element
68  		 */
69  		public LazyWindowMenuCreator(DecodeEngine decodeEngine,
70  			WindowMenu menu, String desktopPaneId) {
71  			
72  			m_decodeEngine = decodeEngine;
73  			m_menu = menu;
74  			m_desktopPaneId = desktopPaneId;
75  		}
76  		
77  		/** {@inheritDoc} */
78  		public void menuSelected(MenuEvent e) {
79  			if (m_menu.getWindowManager() == null && m_decodeEngine != null) {
80  				JDesktopPane desktopPane = (JDesktopPane) m_decodeEngine
81  				.getCookXml().getId(m_desktopPaneId).object;
82  				WindowManager windowManager = new WindowManager(
83  					desktopPane, m_menu);
84  				m_menu.setWindowManager(windowManager);
85  				
86  				m_decodeEngine = null;
87  				
88  			}
89  		}
90  		
91  		/** {@inheritDoc} */
92  		public void menuDeselected(MenuEvent e) { }
93  		
94  		/** {@inheritDoc} */
95  		public void menuCanceled(MenuEvent e) { }
96  	}
97  	
98  	/** {@inheritDoc} */
99  	public Object create(String parentNS, String parentTag, Element elm,
100 		Object parentObj, DecodeEngine decodeEngine) throws CreatorException {
101 
102 		WindowMenu windowMenu = new WindowMenu();
103 		windowMenu.addMenuListener(new LazyWindowMenuCreator(
104 			decodeEngine, windowMenu, elm.getAttribute("desktopPaneId")));
105 		
106 		return windowMenu;
107 	}
108 
109 	/** {@inheritDoc} */
110 	public Object editFinished(String parentNS, String parentTag, Element elm,
111 		Object parentObj, Object obj, DecodeEngine decodeEngine)
112 		throws CookXmlException {
113 		
114 		return obj;
115 	}
116 }