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


001:        /*******************************************************************************
002:         * Copyright (c) 2005, 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.parts;
011:
012:        import org.eclipse.core.runtime.IStatus;
013:        import org.eclipse.core.runtime.Status;
014:        import org.eclipse.osgi.service.resolver.VersionRange;
015:        import org.eclipse.pde.internal.core.PDECoreMessages;
016:        import org.eclipse.pde.internal.core.util.VersionUtil;
017:        import org.eclipse.pde.internal.ui.PDEUIMessages;
018:        import org.eclipse.pde.internal.ui.util.PDELabelUtility;
019:        import org.eclipse.swt.SWT;
020:        import org.eclipse.swt.events.ModifyListener;
021:        import org.eclipse.swt.layout.GridData;
022:        import org.eclipse.swt.layout.GridLayout;
023:        import org.eclipse.swt.widgets.Combo;
024:        import org.eclipse.swt.widgets.Composite;
025:        import org.eclipse.swt.widgets.Group;
026:        import org.eclipse.swt.widgets.Label;
027:        import org.eclipse.swt.widgets.Text;
028:        import org.osgi.framework.Version;
029:
030:        public class PluginVersionPart {
031:
032:            private Text fMinVersionText;
033:            private Text fMaxVersionText;
034:            private Combo fMinVersionBound;
035:            private Combo fMaxVersionBound;
036:
037:            private VersionRange fVersionRange;
038:            private boolean fIsRanged;
039:            private boolean fRangeAllowed;
040:
041:            public PluginVersionPart(boolean rangeAllowed) {
042:                fRangeAllowed = rangeAllowed;
043:            }
044:
045:            public void setVersion(String version) {
046:                try {
047:                    if (version != null && !version.equals("")) { //$NON-NLS-1$
048:                        fVersionRange = new VersionRange(version);
049:                        Version max = fVersionRange.getMaximum();
050:                        if (max.getMajor() != Integer.MAX_VALUE
051:                                && fVersionRange.getMinimum().compareTo(
052:                                        fVersionRange.getMaximum()) < 0)
053:                            fIsRanged = true;
054:                    }
055:                } catch (IllegalArgumentException e) {
056:                    // illegal version string passed
057:                    fVersionRange = new VersionRange("[1.0.0,1.0.0]"); //$NON-NLS-1$
058:                }
059:            }
060:
061:            public void createVersionFields(Composite comp,
062:                    boolean createGroup, boolean editable) {
063:                if (fRangeAllowed)
064:                    createRangeField(comp, createGroup, editable);
065:                else
066:                    createSingleField(comp, createGroup, editable);
067:                preloadFields();
068:            }
069:
070:            private void createRangeField(Composite parent,
071:                    boolean createGroup, boolean editable) {
072:                if (createGroup) {
073:                    parent = new Group(parent, SWT.NONE);
074:                    ((Group) parent).setText(getGroupText());
075:                    parent
076:                            .setLayoutData(new GridData(
077:                                    GridData.FILL_HORIZONTAL));
078:                    parent.setLayout(new GridLayout(3, false));
079:                }
080:                String[] comboItems = new String[] {
081:                        PDEUIMessages.DependencyPropertiesDialog_comboInclusive,
082:                        PDEUIMessages.DependencyPropertiesDialog_comboExclusive };
083:                Label minlabel = new Label(parent, SWT.NONE);
084:                minlabel
085:                        .setText(PDEUIMessages.DependencyPropertiesDialog_minimumVersion);
086:                fMinVersionText = new Text(parent, SWT.SINGLE | SWT.BORDER);
087:                fMinVersionText.setLayoutData(new GridData(
088:                        GridData.FILL_HORIZONTAL));
089:                fMinVersionText.setEnabled(editable);
090:
091:                fMinVersionBound = new Combo(parent, SWT.SINGLE | SWT.BORDER
092:                        | SWT.READ_ONLY);
093:                fMinVersionBound.setEnabled(editable);
094:                fMinVersionBound.setItems(comboItems);
095:
096:                Label maxlabel = new Label(parent, SWT.NONE);
097:                maxlabel
098:                        .setText(PDEUIMessages.DependencyPropertiesDialog_maximumVersion);
099:                fMaxVersionText = new Text(parent, SWT.SINGLE | SWT.BORDER);
100:                fMaxVersionText.setLayoutData(new GridData(
101:                        GridData.FILL_HORIZONTAL));
102:                fMaxVersionText.setEnabled(editable);
103:
104:                fMaxVersionBound = new Combo(parent, SWT.SINGLE | SWT.BORDER
105:                        | SWT.READ_ONLY);
106:                fMaxVersionBound.setEnabled(editable);
107:                fMaxVersionBound.setItems(comboItems);
108:            }
109:
110:            private void createSingleField(Composite parent,
111:                    boolean createGroup, boolean editable) {
112:                if (createGroup) {
113:                    parent = new Group(parent, SWT.NONE);
114:                    ((Group) parent).setText(getGroupText());
115:                    parent.setLayoutData(new GridData(
116:                            GridData.VERTICAL_ALIGN_BEGINNING
117:                                    | GridData.FILL_HORIZONTAL));
118:                    parent.setLayout(new GridLayout(2, false));
119:                }
120:                Label label = new Label(parent, SWT.NONE);
121:                label.setText(PDEUIMessages.DependencyPropertiesDialog_version);
122:
123:                fMinVersionText = new Text(parent, SWT.SINGLE | SWT.BORDER);
124:                fMinVersionText.setLayoutData(new GridData(
125:                        GridData.FILL_HORIZONTAL));
126:                fMinVersionText.setEnabled(editable);
127:            }
128:
129:            public void preloadFields() {
130:                if (fRangeAllowed) {
131:                    fMinVersionText
132:                            .setText((fVersionRange != null) ? fVersionRange
133:                                    .getMinimum().toString() : ""); //$NON-NLS-1$
134:                    fMaxVersionText
135:                            .setText((fVersionRange != null && fVersionRange
136:                                    .getMaximum().getMajor() != Integer.MAX_VALUE) ? fVersionRange
137:                                    .getMaximum().toString()
138:                                    : ""); //$NON-NLS-1$
139:
140:                    if (fVersionRange != null)
141:                        fMinVersionBound.select((fVersionRange
142:                                .getIncludeMinimum()) ? 0 : 1);
143:                    else
144:                        fMinVersionBound.select(0);
145:
146:                    if (fVersionRange != null && getMaxVersion().length() > 0)
147:                        fMaxVersionBound.select((fVersionRange
148:                                .getIncludeMaximum()) ? 0 : 1);
149:                    else
150:                        fMaxVersionBound.select(1);
151:                }
152:                fMinVersionText.setText((fVersionRange != null) ? fVersionRange
153:                        .getMinimum().toString() : ""); //$NON-NLS-1$
154:            }
155:
156:            private IStatus validateVersion(String text, Text textWidget,
157:                    boolean shortErrorMessage) {
158:                if (text.length() == 0)
159:                    return Status.OK_STATUS;
160:                if (VersionUtil.validateVersion(text).getSeverity() != IStatus.OK) {
161:                    String errorMessage = null;
162:                    if (shortErrorMessage) {
163:                        // For dialogs
164:                        errorMessage = PDEUIMessages.DependencyPropertiesDialog_invalidFormat;
165:                    } else {
166:                        // For everything else:  Field assist, wizards
167:                        errorMessage = PDECoreMessages.BundleErrorReporter_InvalidFormatInBundleVersion;
168:                    }
169:                    return new Status(IStatus.ERROR, "org.eclipse.pde.ui", //$NON-NLS-1$
170:                            IStatus.ERROR, PDELabelUtility.qualifyMessage(
171:                                    PDELabelUtility.getFieldLabel(textWidget),
172:                                    errorMessage), null);
173:                }
174:
175:                return Status.OK_STATUS;
176:            }
177:
178:            private IStatus validateVersionRange(boolean shortErrorMessage) {
179:                if ((!fRangeAllowed && getMinVersion().length() == 0)
180:                        || (fRangeAllowed && (getMinVersion().length() == 0 || getMaxVersion()
181:                                .length() == 0))) {
182:                    fIsRanged = false;
183:                    return Status.OK_STATUS;
184:                }
185:
186:                String errorMessage = null;
187:                if (shortErrorMessage) {
188:                    // For dialogs
189:                    errorMessage = PDEUIMessages.DependencyPropertiesDialog_invalidFormat;
190:                } else {
191:                    // For everything else:  Field assist, wizards
192:                    errorMessage = PDECoreMessages.BundleErrorReporter_InvalidFormatInBundleVersion;
193:                }
194:
195:                Version v1;
196:                Version v2;
197:                try {
198:                    v1 = new Version(getMinVersion());
199:                } catch (IllegalArgumentException e) {
200:                    return new Status(IStatus.ERROR, "org.eclipse.pde.ui", //$NON-NLS-1$
201:                            IStatus.ERROR, PDELabelUtility.qualifyMessage(
202:                                    PDELabelUtility
203:                                            .getFieldLabel(fMinVersionText),
204:                                    errorMessage), null);
205:                }
206:                if (!fRangeAllowed) // version created fine
207:                    return Status.OK_STATUS;
208:
209:                try {
210:                    v2 = new Version(getMaxVersion());
211:                } catch (IllegalArgumentException e) {
212:                    return new Status(IStatus.ERROR, "org.eclipse.pde.ui", //$NON-NLS-1$
213:                            IStatus.ERROR, PDELabelUtility.qualifyMessage(
214:                                    PDELabelUtility
215:                                            .getFieldLabel(fMaxVersionText),
216:                                    errorMessage), null); //$NON-NLS-1$;
217:                }
218:                if (v1.compareTo(v2) == 0 || v1.compareTo(v2) < 0) {
219:                    fIsRanged = true;
220:                    return Status.OK_STATUS;
221:                }
222:                return new Status(
223:                        IStatus.ERROR,
224:                        "org.eclipse.pde.ui", //$NON-NLS-1$
225:                        IStatus.ERROR,
226:                        PDEUIMessages.DependencyPropertiesDialog_versionRangeError,
227:                        null);
228:            }
229:
230:            /**
231:             * Short error messages are required for dialog status lines.  Long error
232:             * messages are truncated and are not decorated with a status image.
233:             * @param shortErrorMessage if <code>true</code>, a brief error message
234:             * will be used.
235:             * @return
236:             */
237:            public IStatus validateFullVersionRangeText(
238:                    boolean shortErrorMessage) {
239:                IStatus status = validateVersion(getMinVersion(),
240:                        fMinVersionText, shortErrorMessage);
241:                if (status.isOK())
242:                    status = validateVersion(getMaxVersion(), fMaxVersionText,
243:                            shortErrorMessage);
244:                if (status.isOK())
245:                    status = validateVersionRange(shortErrorMessage);
246:                return status;
247:            }
248:
249:            private String getMinVersion() {
250:                return fMinVersionText.getText().trim();
251:            }
252:
253:            private String getMaxVersion() {
254:                if (fMaxVersionText != null)
255:                    return fMaxVersionText.getText().trim();
256:                return ""; //$NON-NLS-1$
257:            }
258:
259:            private boolean getMinInclusive() {
260:                if (fMinVersionBound != null)
261:                    return fMinVersionBound.getSelectionIndex() == 0;
262:                return false;
263:            }
264:
265:            private boolean getMaxInclusive() {
266:                if (fMaxVersionBound != null)
267:                    return fMaxVersionBound.getSelectionIndex() == 0;
268:                return true;
269:            }
270:
271:            private String extractSingleVersionFromText() {
272:                if (!fRangeAllowed)
273:                    return getMinVersion();
274:                if (getMinVersion().length() == 0)
275:                    return getMaxVersion();
276:                return getMinVersion();
277:            }
278:
279:            public String getVersion() {
280:                String version;
281:                if (fIsRanged) {
282:                    // if versions are equal they must be inclusive for a range to be valid
283:                    // blindly set for the user
284:                    String minV = getMinVersion();
285:                    String maxV = getMaxVersion();
286:                    boolean minI = getMinInclusive();
287:                    boolean maxI = getMaxInclusive();
288:                    if (minV.equals(maxV))
289:                        minI = maxI = true;
290:                    version = new VersionRange(new Version(minV), minI,
291:                            new Version(maxV), maxI).toString();
292:                } else {
293:                    String singleversion = extractSingleVersionFromText();
294:                    if (singleversion == null || singleversion.length() == 0)
295:                        version = ""; //$NON-NLS-1$
296:                    else
297:                        version = new Version(singleversion).toString();
298:                }
299:                return version;
300:            }
301:
302:            public void addListeners(ModifyListener minListener,
303:                    ModifyListener maxListener) {
304:                if (fMinVersionText != null && minListener != null)
305:                    fMinVersionText.addModifyListener(minListener);
306:                if (fRangeAllowed && fMaxVersionText != null
307:                        && maxListener != null)
308:                    fMaxVersionText.addModifyListener(maxListener);
309:            }
310:
311:            protected String getGroupText() {
312:                return PDEUIMessages.DependencyPropertiesDialog_groupText;
313:            }
314:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.