Source Code Cross Referenced for MessageRegion.java in  » IDE-Eclipse » ui » org » eclipse » ui » texteditor » 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 » org.eclipse.ui.texteditor 
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.ui.texteditor;
011:
012:        import org.eclipse.swt.SWT;
013:        import org.eclipse.swt.graphics.Color;
014:        import org.eclipse.swt.graphics.Image;
015:        import org.eclipse.swt.graphics.Rectangle;
016:        import org.eclipse.swt.layout.GridData;
017:        import org.eclipse.swt.layout.GridLayout;
018:        import org.eclipse.swt.widgets.Composite;
019:        import org.eclipse.swt.widgets.Label;
020:        import org.eclipse.swt.widgets.Text;
021:
022:        import org.eclipse.jface.dialogs.Dialog;
023:        import org.eclipse.jface.dialogs.IDialogConstants;
024:        import org.eclipse.jface.dialogs.IMessageProvider;
025:        import org.eclipse.jface.resource.JFaceColors;
026:        import org.eclipse.jface.resource.JFaceResources;
027:
028:        /**
029:         * The MessageRegion is the optional area to
030:         * show messages in the page.
031:         * <p>
032:         * XXX: Copied from org.eclipse.jface.preference.PreferencePage.MessageRegion
033:         * 		see: https://bugs.eclipse.org/bugs/show_bug.cgi?id=84061
034:         * </p>
035:         *
036:         * @since 3.1
037:         */
038:        class MessageRegion {
039:
040:            private Text messageText;
041:
042:            private Label messageImageLabel;
043:
044:            private Composite messageComposite;
045:
046:            private String lastMessageText = "";//$NON-NLS-1$
047:
048:            private int lastMessageType;
049:
050:            /**
051:             * Create a new instance of the receiver.
052:             */
053:            public MessageRegion() {
054:                //No initial behavior
055:            }
056:
057:            /**
058:             * Create the contents for the receiver.
059:             *
060:             * @param parent
061:             *            the Composite that the children will be created in
062:             */
063:            public void createContents(Composite parent) {
064:                messageComposite = new Composite(parent, SWT.NONE);
065:                GridLayout messageLayout = new GridLayout();
066:                messageLayout.numColumns = 2;
067:                messageLayout.marginWidth = 0;
068:                messageLayout.marginHeight = 0;
069:                messageLayout.makeColumnsEqualWidth = false;
070:                messageComposite.setLayout(messageLayout);
071:                messageImageLabel = new Label(messageComposite, SWT.NONE);
072:
073:                GridData imageData = new GridData(
074:                        GridData.VERTICAL_ALIGN_CENTER);
075:                Image sizingImage = JFaceResources
076:                        .getImage(Dialog.DLG_IMG_MESSAGE_ERROR);
077:                Rectangle imageBounds;
078:                if (sizingImage == null)
079:                    imageBounds = new Rectangle(0, 0,
080:                            IDialogConstants.VERTICAL_MARGIN * 2,
081:                            IDialogConstants.VERTICAL_MARGIN * 2);
082:                else
083:                    imageBounds = sizingImage.getBounds();
084:                imageData.heightHint = imageBounds.height
085:                        + IDialogConstants.VERTICAL_SPACING;
086:                imageData.widthHint = imageBounds.width
087:                        + IDialogConstants.HORIZONTAL_SPACING;
088:                messageImageLabel.setLayoutData(imageData);
089:
090:                messageText = new Text(messageComposite, SWT.NONE);
091:                messageText.setEditable(false);
092:                messageText.setBackground(parent.getDisplay().getSystemColor(
093:                        SWT.COLOR_WIDGET_BACKGROUND));
094:
095:                GridData textData = new GridData(GridData.GRAB_HORIZONTAL
096:                        | GridData.FILL_HORIZONTAL
097:                        | GridData.VERTICAL_ALIGN_CENTER);
098:                messageText.setLayoutData(textData);
099:                hideRegion();
100:
101:            }
102:
103:            /**
104:             * Set the layoutData for the messageArea. In most cases this will be a copy
105:             * of the layoutData used in setTitleLayoutData.
106:             *
107:             * @param layoutData
108:             *            the layoutData for the message area composite.
109:             */
110:            public void setMessageLayoutData(Object layoutData) {
111:                messageComposite.setLayoutData(layoutData);
112:            }
113:
114:            /**
115:             * Show the new message in the message text and update the image. Base the
116:             * background color on whether or not there are errors.
117:             *
118:             * @param newMessage
119:             *            The new value for the message
120:             * @param newType
121:             *            One of the IMessageProvider constants. If newType is
122:             *            IMessageProvider.NONE show the title.
123:             * @see IMessageProvider
124:             */
125:            public void updateText(String newMessage, int newType) {
126:                Image newImage = null;
127:                boolean showingError = false;
128:                switch (newType) {
129:                case IMessageProvider.NONE:
130:                    hideRegion();
131:                    return;
132:                case IMessageProvider.INFORMATION:
133:                    newImage = JFaceResources
134:                            .getImage(Dialog.DLG_IMG_MESSAGE_INFO);
135:                    break;
136:                case IMessageProvider.WARNING:
137:                    newImage = JFaceResources
138:                            .getImage(Dialog.DLG_IMG_MESSAGE_WARNING);
139:                    break;
140:                case IMessageProvider.ERROR:
141:                    newImage = JFaceResources
142:                            .getImage(Dialog.DLG_IMG_MESSAGE_ERROR);
143:                    showingError = true;
144:                    break;
145:                }
146:
147:                if (newMessage == null) {//No message so clear the area
148:                    hideRegion();
149:                    return;
150:                }
151:                showRegion();
152:                // Any more updates required
153:                if (newMessage.equals(messageText.getText())
154:                        && newImage == messageImageLabel.getImage())
155:                    return;
156:                messageImageLabel.setImage(newImage);
157:                messageText.setText(newMessage);
158:                if (showingError)
159:                    setMessageColors(JFaceColors
160:                            .getErrorBackground(messageComposite.getDisplay()));
161:                else {
162:                    lastMessageText = newMessage;
163:                    setMessageColors(JFaceColors
164:                            .getBannerBackground(messageComposite.getDisplay()));
165:                }
166:
167:            }
168:
169:            /**
170:             * Show and enable the widgets in the message region
171:             */
172:            private void showRegion() {
173:                messageComposite.setVisible(true);
174:            }
175:
176:            /**
177:             * Hide the message region and clear out the caches.
178:             */
179:            private void hideRegion() {
180:                messageComposite.setVisible(false);
181:                lastMessageText = null;
182:                lastMessageType = IMessageProvider.NONE;
183:            }
184:
185:            /**
186:             * Set the colors of the message area.
187:             *
188:             * @param color
189:             *            The color to be use in the message area.
190:             */
191:            private void setMessageColors(Color color) {
192:                messageText.setBackground(color);
193:                messageComposite.setBackground(color);
194:                messageImageLabel.setBackground(color);
195:            }
196:
197:            /**
198:             * Clear the error message. Restore the previously displayed message if
199:             * there is one, if not restore the title label.
200:             *
201:             */
202:            public void clearErrorMessage() {
203:                updateText(lastMessageText, lastMessageType);
204:            }
205:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.