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


001:        /*******************************************************************************
002:         * Copyright (c) 2006, 2007 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.internal.ui.editor.validation;
011:
012:        import org.eclipse.core.resources.IProject;
013:        import org.eclipse.core.runtime.IStatus;
014:        import org.eclipse.jface.dialogs.IMessageProvider;
015:        import org.eclipse.pde.internal.core.WorkspaceModelManager;
016:        import org.eclipse.pde.internal.core.builders.CompilerFlags;
017:        import org.eclipse.swt.widgets.Control;
018:        import org.eclipse.ui.forms.IManagedForm;
019:        import org.eclipse.ui.forms.IMessageManager;
020:
021:        /**
022:         * AbstractControlValidator
023:         *
024:         */
025:        public abstract class AbstractControlValidator implements 
026:                IControlValidator, IValidatorMessageHandler {
027:
028:            public static final Object F_DEFAULT_MESSAGE_KEY = "k"; //$NON-NLS-1$
029:
030:            private boolean fEnabled;
031:
032:            private IManagedForm fManagedForm;
033:
034:            private Control fControl;
035:
036:            private String fMessagePrefix;
037:
038:            private boolean fIsValid;
039:
040:            private IProject fProject;
041:
042:            /**
043:             * @param managedForm
044:             * @param control
045:             * @param project
046:             */
047:            public AbstractControlValidator(IManagedForm managedForm,
048:                    Control control, IProject project) {
049:                fProject = project;
050:                fManagedForm = managedForm;
051:                fControl = control;
052:                fMessagePrefix = null;
053:                fEnabled = autoEnable();
054:                reset();
055:            }
056:
057:            /**
058:             * @return
059:             */
060:            protected boolean autoEnable() {
061:                boolean isBinaryProject = WorkspaceModelManager
062:                        .isBinaryProject(fProject);
063:                // Enable validator if this is a source projec, the control is enabled 
064:                // and the control is not disposed  
065:                if ((isBinaryProject == false) && fControl.getEnabled()
066:                        && (fControl.isDisposed() == false)) {
067:                    return true;
068:                }
069:                return false;
070:            }
071:
072:            /* (non-Javadoc)
073:             * @see org.eclipse.pde.internal.ui.editor.IControlValdiator#getEnabled()
074:             */
075:            public boolean getEnabled() {
076:                return fEnabled;
077:            }
078:
079:            /* (non-Javadoc)
080:             * @see org.eclipse.pde.internal.ui.editor.IControlValdiator#setEnabled(boolean)
081:             */
082:            public void setEnabled(boolean enabled) {
083:                // Nothing to do here if enablement is not being changed
084:                if (enabled == fEnabled) {
085:                    return;
086:                }
087:                // Update enablement
088:                fEnabled = enabled;
089:                // Automatically perform actions depending on enablement
090:                if (fEnabled) {
091:                    // Re-validate control if validator is enabled
092:                    validate();
093:                } else {
094:                    // Reset validation state if validator is disabled
095:                    reset();
096:                }
097:            }
098:
099:            /* (non-Javadoc)
100:             * @see org.eclipse.pde.internal.ui.editor.IControlValdiator#validate()
101:             */
102:            public boolean validate() {
103:                // Skip validation if the validator is disabled
104:                if (fEnabled == false) {
105:                    return fIsValid;
106:                }
107:                // Validate the control
108:                fIsValid = validateControl();
109:                // If the control is valid, remove all the messages associated with 
110:                // the control (in case they were not individually removed by the
111:                // child class)
112:                if (fIsValid) {
113:                    fManagedForm.getMessageManager().removeMessages(fControl);
114:                }
115:                return fIsValid;
116:            }
117:
118:            /**
119:             * @return
120:             */
121:            protected abstract boolean validateControl();
122:
123:            /* (non-Javadoc)
124:             * @see org.eclipse.pde.internal.ui.editor.validation.IValidatorMessageHandler#addMessage(java.lang.Object, java.lang.String, int)
125:             */
126:            public void addMessage(Object key, String messageText,
127:                    int messageType) {
128:                // Add a prefix, if one was specified
129:                if (fMessagePrefix != null) {
130:                    messageText = fMessagePrefix + ' ' + messageText;
131:                }
132:                // Delegate to message manager
133:                fManagedForm.getMessageManager().addMessage(key, messageText,
134:                        null, messageType, fControl);
135:            }
136:
137:            /* (non-Javadoc)
138:             * @see org.eclipse.pde.internal.ui.editor.validation.IValidatorMessageHandler#addMessage(java.lang.String, int)
139:             */
140:            public void addMessage(String messageText, int messageType) {
141:                // Add a prefix, if one was specified
142:                if (fMessagePrefix != null) {
143:                    messageText = fMessagePrefix + ' ' + messageText;
144:                }
145:                // Delegate to message manager
146:                fManagedForm.getMessageManager().addMessage(
147:                        F_DEFAULT_MESSAGE_KEY, messageText, null, messageType,
148:                        fControl);
149:            }
150:
151:            /**
152:             * @param status
153:             * @return
154:             */
155:            public static int getMessageType(IStatus status) {
156:                int severity = status.getSeverity();
157:                // Translate severity to the equivalent message provider type
158:                if (severity == IStatus.OK) {
159:                    return IMessageProvider.NONE;
160:                } else if (severity == IStatus.ERROR) {
161:                    return IMessageProvider.ERROR;
162:                } else if (severity == IStatus.WARNING) {
163:                    return IMessageProvider.WARNING;
164:                } else if (severity == IStatus.INFO) {
165:                    return IMessageProvider.INFORMATION;
166:                }
167:                // IStatus.CANCEL
168:                return IMessageProvider.NONE;
169:            }
170:
171:            /**
172:             * @param project
173:             * @param compilerFlagId
174:             * @return
175:             */
176:            public static int getMessageType(IProject project,
177:                    String compilerFlagId) {
178:                int severity = CompilerFlags.getFlag(project, compilerFlagId);
179:                // Translate severity to the equivalent message provider type
180:                if (severity == CompilerFlags.IGNORE) {
181:                    return IMessageProvider.NONE;
182:                } else if (severity == CompilerFlags.ERROR) {
183:                    return IMessageProvider.ERROR;
184:                } else {
185:                    // CompilerFlags.WARNING
186:                    return IMessageProvider.WARNING;
187:                }
188:            }
189:
190:            /* (non-Javadoc)
191:             * @see org.eclipse.pde.internal.ui.editor.validation.IValidatorMessageHandler#removeMessage(java.lang.Object)
192:             */
193:            public void removeMessage(Object key) {
194:                fManagedForm.getMessageManager().removeMessage(key, fControl);
195:            }
196:
197:            /* (non-Javadoc)
198:             * @see org.eclipse.pde.internal.ui.editor.validation.IValidatorMessageHandler#setMessagePrefix(java.lang.String)
199:             */
200:            public void setMessagePrefix(String prefix) {
201:                fMessagePrefix = prefix;
202:            }
203:
204:            /* (non-Javadoc)
205:             * @see org.eclipse.pde.internal.ui.editor.validation.IValidatorMessageHandler#getMessagePrefix()
206:             */
207:            public String getMessagePrefix() {
208:                return fMessagePrefix;
209:            }
210:
211:            /* (non-Javadoc)
212:             * @see org.eclipse.pde.internal.ui.editor.validation.IValidatorMessageHandler#getManagedForm()
213:             */
214:            public IManagedForm getManagedForm() {
215:                return fManagedForm;
216:            }
217:
218:            /* (non-Javadoc)
219:             * @see org.eclipse.pde.internal.ui.editor.validation.IValidatorMessageHandler#getMessageManager()
220:             */
221:            public IMessageManager getMessageManager() {
222:                return fManagedForm.getMessageManager();
223:            }
224:
225:            /* (non-Javadoc)
226:             * @see org.eclipse.pde.internal.ui.editor.validation.IControlValidator#setRefresh(boolean)
227:             */
228:            public void setRefresh(boolean refresh) {
229:                getMessageManager().setAutoUpdate(refresh);
230:            }
231:
232:            /* (non-Javadoc)
233:             * @see org.eclipse.pde.internal.ui.editor.validation.IControlValdiator#getControl()
234:             */
235:            public Control getControl() {
236:                return fControl;
237:            }
238:
239:            /* (non-Javadoc)
240:             * @see org.eclipse.pde.internal.ui.editor.validation.IControlValidator#isValid()
241:             */
242:            public boolean isValid() {
243:                return fIsValid;
244:            }
245:
246:            /* (non-Javadoc)
247:             * @see org.eclipse.pde.internal.ui.editor.validation.IControlValidator#reset()
248:             */
249:            public void reset() {
250:                fIsValid = true;
251:                fManagedForm.getMessageManager().removeMessages(fControl);
252:            }
253:        }
w___ww___.__j___a_v___a___2__s__.__c___om__ | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.