Source Code Cross Referenced for ChoiceOption.java in  » IDE-Eclipse » Eclipse-plug-in-development » org » eclipse » pde » ui » templates » 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 » Eclipse plug in development » org.eclipse.pde.ui.templates 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*******************************************************************************
002:         * Copyright (c) 2000, 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.pde.ui.templates;
011:
012:        import org.eclipse.swt.SWT;
013:        import org.eclipse.swt.events.SelectionAdapter;
014:        import org.eclipse.swt.events.SelectionEvent;
015:        import org.eclipse.swt.events.SelectionListener;
016:        import org.eclipse.swt.layout.GridData;
017:        import org.eclipse.swt.layout.GridLayout;
018:        import org.eclipse.swt.widgets.Button;
019:        import org.eclipse.swt.widgets.Composite;
020:        import org.eclipse.swt.widgets.Control;
021:
022:        /**
023:         * Implementation of the TemplateOption that allows users to choose a value from
024:         * the fixed set of options.
025:         * 
026:         * @since 2.0
027:         * @deprecated see {@link RadioChoiceOption} and {@link ComboChoiceOption}
028:         */
029:        public class ChoiceOption extends TemplateOption {
030:            private String[][] choices;
031:            private Control labelControl;
032:            private Button[] buttons;
033:            private boolean blockListener;
034:
035:            /**
036:             * Constructor for ChoiceOption.
037:             * 
038:             * @param section
039:             *            the parent section.
040:             * @param name
041:             *            the unique name
042:             * @param label
043:             *            the presentable label
044:             * @param choices
045:             *            the list of choices from which the value can be chosen. Each
046:             *            array entry should be an array of size 2, where position 0
047:             *            will be interpeted as the choice unique name, and position 1
048:             *            as the choice presentable label.
049:             */
050:            public ChoiceOption(BaseOptionTemplateSection section, String name,
051:                    String label, String[][] choices) {
052:                super (section, name, label);
053:                this .choices = choices;
054:            }
055:
056:            /* (non-Javadoc)
057:             * @see org.eclipse.pde.ui.templates.TemplateField#createControl(org.eclipse.swt.widgets.Composite, int)
058:             */
059:            public void createControl(Composite parent, int span) {
060:                Composite container = createComposite(parent, span);
061:                fill(container, span);
062:                GridLayout layout = new GridLayout();
063:                layout.marginWidth = layout.marginHeight = 0;
064:                container.setLayout(layout);
065:                labelControl = createLabel(container, span);
066:                labelControl.setEnabled(isEnabled());
067:                fill(labelControl, span);
068:
069:                buttons = new Button[choices.length];
070:
071:                SelectionListener listener = new SelectionAdapter() {
072:                    public void widgetSelected(SelectionEvent e) {
073:                        Button b = (Button) e.widget;
074:                        if (blockListener)
075:                            return;
076:                        if (b.getSelection()) {
077:                            ChoiceOption.super .setValue(b.getData().toString());
078:                            getSection().validateOptions(ChoiceOption.this );
079:                        }
080:                    }
081:                };
082:
083:                for (int i = 0; i < choices.length; i++) {
084:                    String[] choice = choices[i];
085:                    Button button = createRadioButton(parent, span, choice);
086:                    buttons[i] = button;
087:                    button.addSelectionListener(listener);
088:                    button.setEnabled(isEnabled());
089:                }
090:                if (getChoice() != null)
091:                    selectChoice(getChoice());
092:            }
093:
094:            /**
095:             * Returns the string value of the current choice.
096:             * 
097:             * @return the current choice or <samp>null </samp> if not initialized.
098:             */
099:            public String getChoice() {
100:                return getValue() != null ? getValue().toString() : null;
101:            }
102:
103:            /**
104:             * Implements the superclass method by passing the new value to the option's
105:             * widget.
106:             * 
107:             * @param value
108:             *            the new value.
109:             */
110:            public void setValue(Object value) {
111:                super .setValue(value);
112:                if (buttons != null && value != null) {
113:                    selectChoice(value.toString());
114:                }
115:            }
116:
117:            /**
118:             * Implements the superclass method by updating the enable state of the
119:             * option's widget.
120:             */
121:            public void setEnabled(boolean enabled) {
122:                super .setEnabled(enabled);
123:                if (labelControl != null) {
124:                    labelControl.setEnabled(enabled);
125:                    for (int i = 0; i < buttons.length; i++) {
126:                        buttons[i].setEnabled(isEnabled());
127:                    }
128:                }
129:            }
130:
131:            private GridData fill(Control control, int span) {
132:                GridData gd = new GridData(GridData.HORIZONTAL_ALIGN_FILL);
133:                gd.horizontalSpan = span;
134:                control.setLayoutData(gd);
135:                return gd;
136:            }
137:
138:            private Composite createComposite(Composite parent, int span) {
139:                Composite composite = new Composite(parent, SWT.NULL);
140:                fill(composite, span);
141:                return composite;
142:            }
143:
144:            private Button createRadioButton(Composite parent, int span,
145:                    String[] choice) {
146:                Button button = new Button(parent, SWT.RADIO);
147:                button.setData(choice[0]);
148:                button.setText(choice[1]);
149:                GridData gd = fill(button, span);
150:                gd.horizontalIndent = 10;
151:                return button;
152:            }
153:
154:            private void selectChoice(String choice) {
155:                blockListener = true;
156:                for (int i = 0; i < buttons.length; i++) {
157:                    Button button = buttons[i];
158:                    String bname = button.getData().toString();
159:                    if (bname.equals(choice)) {
160:                        button.setSelection(true);
161:                    } else {
162:                        button.setSelection(false);
163:                    }
164:                }
165:                blockListener = false;
166:            }
167:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.