Source Code Cross Referenced for ControlValidationUtility.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) 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.CoreException;
014:        import org.eclipse.core.runtime.IStatus;
015:        import org.eclipse.jdt.core.IJavaProject;
016:        import org.eclipse.jdt.core.JavaCore;
017:        import org.eclipse.jface.dialogs.IMessageProvider;
018:        import org.eclipse.pde.core.plugin.IFragmentModel;
019:        import org.eclipse.pde.core.plugin.IPluginModelBase;
020:        import org.eclipse.pde.core.plugin.PluginRegistry;
021:        import org.eclipse.pde.internal.core.AbstractNLModel;
022:        import org.eclipse.pde.internal.core.NLResourceHelper;
023:        import org.eclipse.pde.internal.core.PDECore;
024:        import org.eclipse.pde.internal.core.builders.CompilerFlags;
025:        import org.eclipse.pde.internal.core.util.PDEJavaHelper;
026:        import org.eclipse.pde.internal.core.util.VersionUtil;
027:        import org.eclipse.pde.internal.ui.PDEUIMessages;
028:        import org.osgi.framework.InvalidSyntaxException;
029:
030:        /**
031:         * ControlValidationUtility
032:         *
033:         */
034:        public class ControlValidationUtility {
035:
036:            /**
037:             * @param text
038:             * @param validator
039:             * @return
040:             */
041:            public static boolean validateRequiredField(String value,
042:                    IValidatorMessageHandler validator, int messageType) {
043:                // Check to see if a value was specified
044:                if (value.length() == 0) {
045:                    validator
046:                            .addMessage(
047:                                    PDEUIMessages.ControlValidationUtility_errorMsgValueMustBeSpecified,
048:                                    messageType);
049:                    return false;
050:                }
051:                return true;
052:            }
053:
054:            /**
055:             * @param text
056:             * @param validator
057:             * @param required
058:             * @param model
059:             * @param project
060:             * @return
061:             */
062:            public static boolean validateTranslatableField(String value,
063:                    IValidatorMessageHandler validator, IPluginModelBase model,
064:                    IProject project) {
065:
066:                // Check the compiler flag and translate it into a message type
067:                int messageType = AbstractControlValidator.getMessageType(
068:                        project, CompilerFlags.P_NOT_EXTERNALIZED);
069:                // If the message type is none, no validation is required
070:                // Same as IGNORE
071:                if (messageType == IMessageProvider.NONE) {
072:                    return true;
073:                }
074:
075:                // Check to see if the name has been externalized
076:                if (value.startsWith("%") == false) { //$NON-NLS-1$
077:                    validator
078:                            .addMessage(
079:                                    PDEUIMessages.ControlValidationUtility_errorMsgValueNotExternalized,
080:                                    messageType);
081:                    return false;
082:                }
083:
084:                // Check to see if the key is in the plugin's property file
085:                if (model instanceof  AbstractNLModel) {
086:                    NLResourceHelper helper = ((AbstractNLModel) model)
087:                            .getNLResourceHelper();
088:                    if ((helper == null)
089:                            || (helper.resourceExists(value) == false)) {
090:                        validator
091:                                .addMessage(
092:                                        PDEUIMessages.ControlValidationUtility_errorMsgKeyNotFound,
093:                                        messageType);
094:                        return false;
095:                    }
096:                }
097:                return true;
098:            }
099:
100:            /**
101:             * @param text
102:             * @param validator
103:             * @param required
104:             * @return
105:             */
106:            public static boolean validateVersionField(String value,
107:                    IValidatorMessageHandler validator) {
108:                // Check for invalid version
109:                IStatus status = VersionUtil.validateVersion(value);
110:                if (status.isOK() == false) {
111:                    validator.addMessage(status.getMessage(),
112:                            AbstractControlValidator.getMessageType(status));
113:                    return false;
114:                }
115:                return true;
116:            }
117:
118:            /**
119:             * @param text
120:             * @param validator
121:             * @param model
122:             * @param project
123:             */
124:            public static boolean validatePlatformFilterField(String value,
125:                    IValidatorMessageHandler validator) {
126:                // Check to see if the platform filter syntax is valid
127:                try {
128:                    PDECore.getDefault().getBundleContext().createFilter(value);
129:                } catch (InvalidSyntaxException ise) {
130:                    validator
131:                            .addMessage(
132:                                    PDEUIMessages.ControlValidationUtility_errorMsgFilterInvalidSyntax,
133:                                    IMessageProvider.ERROR);
134:                    return false;
135:                }
136:
137:                return true;
138:            }
139:
140:            /**
141:             * @param text
142:             * @param validator
143:             * @param project
144:             * @return
145:             */
146:            public static boolean validateActivatorField(String value,
147:                    IValidatorMessageHandler validator, IProject project) {
148:
149:                // Check the compiler flag and translate it into a message type
150:                int messageType = AbstractControlValidator.getMessageType(
151:                        project, CompilerFlags.P_UNKNOWN_CLASS);
152:                // If the message type is none, no validation is required
153:                // Same as IGNORE
154:                if (messageType == IMessageProvider.NONE) {
155:                    return true;
156:                }
157:
158:                // Check to see if the class is on the plug-in classpath
159:                try {
160:                    if (project.hasNature(JavaCore.NATURE_ID)) {
161:                        IJavaProject javaProject = JavaCore.create(project);
162:                        // Look for this activator in the project's classpath
163:                        if (!PDEJavaHelper.isOnClasspath(value, javaProject)) {
164:                            validator
165:                                    .addMessage(
166:                                            PDEUIMessages.ControlValidationUtility_errorMsgNotOnClasspath,
167:                                            messageType);
168:                            return false;
169:                        }
170:                    }
171:                } catch (CoreException ce) {
172:                    // Ignore
173:                }
174:
175:                return true;
176:            }
177:
178:            /**
179:             * @param value
180:             * @param validator
181:             * @param model
182:             * @param project
183:             * @return
184:             */
185:            public static boolean validateFragmentHostPluginField(String value,
186:                    IValidatorMessageHandler validator, IProject project) {
187:
188:                // Check the compiler flag and translate it into a message type
189:                // If the message type is none, it is the same as IGNORE
190:                int reqAttMessageType = AbstractControlValidator
191:                        .getMessageType(project,
192:                                CompilerFlags.P_NO_REQUIRED_ATT);
193:                // Check to see if the host plug-in was defined
194:                if ((reqAttMessageType != IMessageProvider.NONE)
195:                        && validateRequiredField(value, validator,
196:                                reqAttMessageType) == false) {
197:                    return false;
198:                }
199:                // Check the compiler flag and translate it into a message type
200:                int unresImpMessageType = AbstractControlValidator
201:                        .getMessageType(project,
202:                                CompilerFlags.P_UNRESOLVED_IMPORTS);
203:                // If the message type is none, no validation is required
204:                // Same as IGNORE		
205:                if (unresImpMessageType == IMessageProvider.NONE) {
206:                    return true;
207:                }
208:                // Check to see if the host plugin is defined, enabled and not a 
209:                // fragment itself
210:                IPluginModelBase hostModel = PluginRegistry.findModel(value);
211:                if ((hostModel == null)
212:                        || (hostModel instanceof  IFragmentModel)
213:                        || (hostModel.isEnabled() == false)) {
214:                    validator
215:                            .addMessage(
216:                                    PDEUIMessages.ControlValidationUtility_errorMsgPluginUnresolved,
217:                                    unresImpMessageType);
218:                    return false;
219:                }
220:
221:                return true;
222:            }
223:
224:        }
ww_w_._j___av___a__2__s__.___c__o___m___ | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.