Source Code Cross Referenced for RadioMenu.java in  » IDE-Eclipse » ui-workbench » org » eclipse » ui » internal » 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 » IDE Eclipse » ui workbench » org.eclipse.ui.internal 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*******************************************************************************
002:         * Copyright (c) 2004, 2006 IBM Corporation and others.
003:         * All rights reserved. This program and the accompanying materials
004:         * are made available under the terms of the Eclipse Public License v1.0
005:         * which accompanies this distribution, and is available at
006:         * http://www.eclipse.org/legal/epl-v10.html
007:         *
008:         * Contributors:
009:         *     IBM Corporation - initial API and implementation
010:         *******************************************************************************/package org.eclipse.ui.internal;
011:
012:        import java.util.ArrayList;
013:        import java.util.Iterator;
014:        import java.util.List;
015:
016:        import org.eclipse.swt.SWT;
017:        import org.eclipse.swt.events.SelectionAdapter;
018:        import org.eclipse.swt.events.SelectionEvent;
019:        import org.eclipse.swt.widgets.Menu;
020:        import org.eclipse.swt.widgets.MenuItem;
021:
022:        /**
023:         * Represents a group of radio buttons in a menu. Each menu item
024:         * is mapped onto a particular value. The RadioMenu reports its state
025:         * using the attached Model object. That is, Model.getState() will
026:         * return the value of the currently selected radio button and Model.setState(value)
027:         * will select the radio button associated with the given value.
028:         */
029:        public class RadioMenu implements  IChangeListener {
030:
031:            private Model data;
032:
033:            private Menu parent;
034:
035:            private List items = new ArrayList();
036:
037:            SelectionAdapter selectionAdapter = new SelectionAdapter() {
038:                public void widgetSelected(SelectionEvent e) {
039:                    Object newState = e.widget.getData();
040:
041:                    data.setState(newState, RadioMenu.this );
042:                }
043:            };
044:
045:            /**
046:             * Creates a set of radio menu items on the given menu. 
047:             * 
048:             * @param parent menu that will contain the menu items
049:             * @param newData the model that will store the value of the currently selected item
050:             */
051:            public RadioMenu(Menu parent, Model newData) {
052:                this .parent = parent;
053:                this .data = newData;
054:
055:                newData.addChangeListener(this );
056:            }
057:
058:            /**
059:             * Returns true iff the given values are considered equal.
060:             * 
061:             * @param value1
062:             * @param value2
063:             * @return
064:             */
065:            private static boolean isEqual(Object value1, Object value2) {
066:                if (value1 == null) {
067:                    return value2 == null;
068:                } else if (value2 == null) {
069:                    return false;
070:                }
071:
072:                return value1.equals(value2);
073:            }
074:
075:            /**
076:             * Creates a new menu item with the given text and value. When 
077:             * the item is selected, the state of the model will change to
078:             * match the given value.
079:             * 
080:             * @param text
081:             * @param value
082:             */
083:            public void addMenuItem(String text, Object value) {
084:                MenuItem newItem = new MenuItem(parent, SWT.RADIO);
085:
086:                newItem.setSelection(isEqual(data.getState(), value));
087:                newItem.setText(text);
088:                newItem.setData(value);
089:                items.add(newItem);
090:
091:                newItem.addSelectionListener(selectionAdapter);
092:            }
093:
094:            /**
095:             * Disposes all menu items
096:             */
097:            public void dispose() {
098:                Iterator iter = items.iterator();
099:                while (iter.hasNext()) {
100:                    MenuItem next = (MenuItem) iter.next();
101:
102:                    if (!next.isDisposed()) {
103:                        next.removeSelectionListener(selectionAdapter);
104:                        next.dispose();
105:                    }
106:                }
107:
108:                items.clear();
109:            }
110:
111:            /**
112:             * Refreshes the selected menu items to match the current state of the model.
113:             */
114:            private void refreshSelection() {
115:                Iterator iter = items.iterator();
116:                while (iter.hasNext()) {
117:                    MenuItem next = (MenuItem) iter.next();
118:
119:                    if (!next.isDisposed()) {
120:                        next.setSelection(isEqual(data.getState(), next
121:                                .getData()));
122:                    }
123:                }
124:            }
125:
126:            /* (non-Javadoc)
127:             * @see org.eclipse.ui.internal.controls.IView#changed()
128:             */
129:            public void update(boolean changed) {
130:                refreshSelection();
131:            }
132:
133:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.