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


001:        /*******************************************************************************
002:         * Copyright (c) 2004, 2005 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.examples.components.views;
011:
012:        import java.net.MalformedURLException;
013:        import java.net.URL;
014:
015:        import org.eclipse.core.runtime.IStatus;
016:        import org.eclipse.jface.dialogs.ErrorDialog;
017:        import org.eclipse.jface.resource.ImageDescriptor;
018:        import org.eclipse.swt.SWT;
019:        import org.eclipse.swt.events.ModifyListener;
020:        import org.eclipse.swt.events.SelectionAdapter;
021:        import org.eclipse.swt.events.SelectionEvent;
022:        import org.eclipse.swt.events.SelectionListener;
023:        import org.eclipse.swt.layout.GridData;
024:        import org.eclipse.swt.layout.GridLayout;
025:        import org.eclipse.swt.widgets.Button;
026:        import org.eclipse.swt.widgets.Composite;
027:        import org.eclipse.swt.widgets.FileDialog;
028:        import org.eclipse.swt.widgets.Label;
029:        import org.eclipse.swt.widgets.Text;
030:        import org.eclipse.ui.internal.components.framework.ComponentException;
031:        import org.eclipse.ui.internal.part.components.services.INameable;
032:        import org.eclipse.ui.internal.part.components.services.IStatusFactory;
033:
034:        /**
035:         * Example view that contains text fields allowing the user to change the view's
036:         * title, icon, tooltip, and content description
037:         * 
038:         * @since 3.1
039:         */
040:        public class NameTestView {
041:            // Dependencies
042:            private INameable name;
043:            private IStatusFactory error;
044:
045:            // Widgets
046:            private Composite mainControl;
047:            private Text nameField;
048:            private Text contentField;
049:            private Text tooltip;
050:            private Button selectImage;
051:
052:            // Listeners
053:            private ModifyListener modifyListener = new ModifyListener() {
054:                public void modifyText(org.eclipse.swt.events.ModifyEvent e) {
055:                    textChanged((Text) e.widget);
056:                }
057:            };
058:
059:            private SelectionListener buttonListener = new SelectionAdapter() {
060:                /* (non-Javadoc)
061:                 * @see org.eclipse.swt.events.SelectionAdapter#widgetSelected(org.eclipse.swt.events.SelectionEvent)
062:                 */
063:                public void widgetSelected(SelectionEvent e) {
064:                    buttonPressed((Button) e.widget);
065:                }
066:            };
067:
068:            /**
069:             * Creates a new NameTestView that takes the parent composite, 
070:             */
071:            public NameTestView(Composite parent, INameable name,
072:                    IStatusFactory error) throws ComponentException {
073:
074:                // Remember our dependencies
075:                this .name = name;
076:                this .mainControl = parent;
077:                this .error = error;
078:
079:                // Construct the widgets and the layout
080:                GridLayout layout = new GridLayout();
081:                layout.numColumns = 2;
082:                parent.setLayout(layout);
083:
084:                // Create text fields for editing the view name, description, and tooltip
085:                createLabel(parent, "Name");
086:                nameField = createTextField(parent);
087:                createLabel(parent, "Description");
088:                contentField = createTextField(parent);
089:                createLabel(parent, "Tooltip");
090:                tooltip = createTextField(parent);
091:
092:                // Add a button that allows a new image to be selected
093:                createLabel(parent, "Image");
094:                selectImage = createButton(parent, "Select Image");
095:            }
096:
097:            /**
098:             * Called whenever a Button is pressed
099:             * 
100:             * @param button that was pressed
101:             */
102:            protected void buttonPressed(Button button) {
103:                if (button == selectImage) {
104:                    FileDialog dialog = new FileDialog(mainControl.getShell(),
105:                            SWT.OPEN);
106:
107:                    String filename = dialog.open();
108:                    if (filename != null) {
109:                        try {
110:                            // Create an image descriptor for the selected file
111:                            ImageDescriptor image = ImageDescriptor
112:                                    .createFromURL(new URL("file:/" + filename));
113:
114:                            // Change the title image
115:                            name.setImage(image);
116:                        } catch (MalformedURLException e) {
117:                            IStatus status = error.newError(
118:                                    "Unable to open image", e);
119:                            ErrorDialog.openError(mainControl.getShell(),
120:                                    "Error opening file", null, status);
121:                            return;
122:                        }
123:                    }
124:                }
125:            }
126:
127:            /**
128:             * Called whenever a Text field changes
129:             * 
130:             * @param changed Text field that changed
131:             */
132:            private void textChanged(Text changed) {
133:                if (changed == nameField) {
134:                    name.setName(nameField.getText());
135:                } else if (changed == contentField) {
136:                    name.setContentDescription(contentField.getText());
137:                } else if (changed == tooltip) {
138:                    name.setTooltip(tooltip.getText());
139:                }
140:            }
141:
142:            // Widget factory methods ///////////////////////////////////////////
143:
144:            private Text createTextField(Composite parent) {
145:                Text result = new Text(parent, SWT.BORDER);
146:                result.setLayoutData(new GridData(GridData.FILL_HORIZONTAL
147:                        | GridData.VERTICAL_ALIGN_CENTER));
148:                result.addModifyListener(modifyListener);
149:                return result;
150:            }
151:
152:            private Button createButton(Composite parent, String buttonText) {
153:                Button newButton = new Button(parent, SWT.PUSH);
154:                newButton.setText(buttonText);
155:                newButton.addSelectionListener(buttonListener);
156:                newButton.setLayoutData(new GridData(
157:                        GridData.HORIZONTAL_ALIGN_BEGINNING
158:                                | GridData.VERTICAL_ALIGN_CENTER));
159:                return newButton;
160:            }
161:
162:            private Label createLabel(Composite parent, String labelText) {
163:                Label label = new Label(parent, SWT.NONE);
164:                label.setText(labelText);
165:                label.setLayoutData(new GridData(
166:                        GridData.HORIZONTAL_ALIGN_BEGINNING
167:                                | GridData.VERTICAL_ALIGN_CENTER));
168:                return label;
169:            }
170:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.