Source Code Cross Referenced for SourceAttachmentPropertyPage.java in  » IDE-Eclipse » jdt » org » eclipse » jdt » internal » ui » preferences » 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 » jdt » org.eclipse.jdt.internal.ui.preferences 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*******************************************************************************
002:         * Copyright (c) 2000, 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.jdt.internal.ui.preferences;
011:
012:        import java.lang.reflect.InvocationTargetException;
013:
014:        import org.eclipse.core.runtime.Assert;
015:        import org.eclipse.core.runtime.CoreException;
016:        import org.eclipse.core.runtime.IAdaptable;
017:        import org.eclipse.core.runtime.IPath;
018:        import org.eclipse.core.runtime.IStatus;
019:
020:        import org.eclipse.core.resources.IFile;
021:        import org.eclipse.core.resources.IProject;
022:        import org.eclipse.core.resources.IResource;
023:
024:        import org.eclipse.swt.SWT;
025:        import org.eclipse.swt.layout.GridData;
026:        import org.eclipse.swt.layout.GridLayout;
027:        import org.eclipse.swt.widgets.Composite;
028:        import org.eclipse.swt.widgets.Control;
029:        import org.eclipse.swt.widgets.Label;
030:
031:        import org.eclipse.jface.dialogs.Dialog;
032:        import org.eclipse.jface.operation.IRunnableWithProgress;
033:
034:        import org.eclipse.ui.PlatformUI;
035:        import org.eclipse.ui.dialogs.PropertyPage;
036:
037:        import org.eclipse.jdt.core.ClasspathContainerInitializer;
038:        import org.eclipse.jdt.core.IClasspathContainer;
039:        import org.eclipse.jdt.core.IClasspathEntry;
040:        import org.eclipse.jdt.core.IJavaElement;
041:        import org.eclipse.jdt.core.IJavaProject;
042:        import org.eclipse.jdt.core.IPackageFragmentRoot;
043:        import org.eclipse.jdt.core.JavaCore;
044:
045:        import org.eclipse.jdt.internal.corext.util.JavaModelUtil;
046:        import org.eclipse.jdt.internal.corext.util.Messages;
047:
048:        import org.eclipse.jdt.internal.ui.IJavaHelpContextIds;
049:        import org.eclipse.jdt.internal.ui.JavaPlugin;
050:        import org.eclipse.jdt.internal.ui.dialogs.StatusUtil;
051:        import org.eclipse.jdt.internal.ui.util.ExceptionHandler;
052:        import org.eclipse.jdt.internal.ui.wizards.IStatusChangeListener;
053:        import org.eclipse.jdt.internal.ui.wizards.buildpaths.SourceAttachmentBlock;
054:
055:        /**
056:         * Property page to configure a archive's JARs source attachment
057:         */
058:        public class SourceAttachmentPropertyPage extends PropertyPage
059:                implements  IStatusChangeListener {
060:
061:            private SourceAttachmentBlock fSourceAttachmentBlock;
062:            private IPackageFragmentRoot fRoot;
063:            private IPath fContainerPath;
064:            private IClasspathEntry fEntry;
065:
066:            public SourceAttachmentPropertyPage() {
067:            }
068:
069:            /*
070:             * @see org.eclipse.jface.dialogs.IDialogPage#createControl(org.eclipse.swt.widgets.Composite)
071:             */
072:            public void createControl(Composite parent) {
073:                super .createControl(parent);
074:                PlatformUI.getWorkbench().getHelpSystem().setHelp(getControl(),
075:                        IJavaHelpContextIds.SOURCE_ATTACHMENT_PROPERTY_PAGE);
076:            }
077:
078:            /*
079:             * @see PreferencePage#createContents
080:             */
081:            protected Control createContents(Composite composite) {
082:                initializeDialogUnits(composite);
083:                Control result = createPageContent(composite);
084:                Dialog.applyDialogFont(result);
085:                return result;
086:            }
087:
088:            private Control createPageContent(Composite composite) {
089:                try {
090:                    fContainerPath = null;
091:                    fEntry = null;
092:                    fRoot = getJARPackageFragmentRoot();
093:                    if (fRoot == null
094:                            || fRoot.getKind() != IPackageFragmentRoot.K_BINARY) {
095:                        return createMessageContent(
096:                                composite,
097:                                PreferencesMessages.SourceAttachmentPropertyPage_noarchive_message);
098:                    }
099:
100:                    IPath containerPath = null;
101:                    IJavaProject jproject = fRoot.getJavaProject();
102:                    IClasspathEntry entry = fRoot.getRawClasspathEntry();
103:                    if (entry == null) {
104:                        // use a dummy entry to use for initialization
105:                        entry = JavaCore.newLibraryEntry(fRoot.getPath(), null,
106:                                null);
107:                    } else {
108:                        if (entry.getEntryKind() == IClasspathEntry.CPE_CONTAINER) {
109:                            containerPath = entry.getPath();
110:                            ClasspathContainerInitializer initializer = JavaCore
111:                                    .getClasspathContainerInitializer(containerPath
112:                                            .segment(0));
113:                            IClasspathContainer container = JavaCore
114:                                    .getClasspathContainer(containerPath,
115:                                            jproject);
116:                            if (initializer == null || container == null) {
117:                                return createMessageContent(
118:                                        composite,
119:                                        Messages
120:                                                .format(
121:                                                        PreferencesMessages.SourceAttachmentPropertyPage_invalid_container,
122:                                                        containerPath
123:                                                                .toString()));
124:                            }
125:                            String containerName = container.getDescription();
126:
127:                            IStatus status = initializer
128:                                    .getSourceAttachmentStatus(containerPath,
129:                                            jproject);
130:                            if (status.getCode() == ClasspathContainerInitializer.ATTRIBUTE_NOT_SUPPORTED) {
131:                                return createMessageContent(
132:                                        composite,
133:                                        Messages
134:                                                .format(
135:                                                        PreferencesMessages.SourceAttachmentPropertyPage_not_supported,
136:                                                        containerName));
137:                            }
138:                            if (status.getCode() == ClasspathContainerInitializer.ATTRIBUTE_READ_ONLY) {
139:                                return createMessageContent(
140:                                        composite,
141:                                        Messages
142:                                                .format(
143:                                                        PreferencesMessages.SourceAttachmentPropertyPage_read_only,
144:                                                        containerName));
145:                            }
146:                            entry = JavaModelUtil.findEntryInContainer(
147:                                    container, fRoot.getPath());
148:                            Assert.isNotNull(entry);
149:                        }
150:                    }
151:                    fContainerPath = containerPath;
152:                    fEntry = entry;
153:
154:                    fSourceAttachmentBlock = new SourceAttachmentBlock(this ,
155:                            entry);
156:                    return fSourceAttachmentBlock.createControl(composite);
157:                } catch (CoreException e) {
158:                    JavaPlugin.log(e);
159:                    return createMessageContent(
160:                            composite,
161:                            PreferencesMessages.SourceAttachmentPropertyPage_noarchive_message);
162:                }
163:            }
164:
165:            private Control createMessageContent(Composite composite,
166:                    String message) {
167:                Composite inner = new Composite(composite, SWT.NONE);
168:                GridLayout layout = new GridLayout();
169:                layout.marginHeight = 0;
170:                layout.marginWidth = 0;
171:                inner.setLayout(layout);
172:
173:                GridData gd = new GridData(GridData.HORIZONTAL_ALIGN_FILL);
174:                gd.widthHint = convertWidthInCharsToPixels(80);
175:
176:                Label label = new Label(inner, SWT.LEFT + SWT.WRAP);
177:                label.setText(message);
178:                label.setLayoutData(gd);
179:                return inner;
180:            }
181:
182:            /*
183:             * @see IPreferencePage#performOk
184:             */
185:            public boolean performOk() {
186:                if (fSourceAttachmentBlock != null) {
187:                    try {
188:                        IClasspathEntry entry = fSourceAttachmentBlock
189:                                .getNewEntry();
190:                        if (entry.equals(fEntry)) {
191:                            return true; // no change
192:                        }
193:
194:                        IRunnableWithProgress runnable = SourceAttachmentBlock
195:                                .getRunnable(getShell(), entry, fRoot
196:                                        .getJavaProject(), fContainerPath);
197:                        PlatformUI.getWorkbench().getProgressService().run(
198:                                true, true, runnable);
199:                    } catch (InvocationTargetException e) {
200:                        String title = PreferencesMessages.SourceAttachmentPropertyPage_error_title;
201:                        String message = PreferencesMessages.SourceAttachmentPropertyPage_error_message;
202:                        ExceptionHandler.handle(e, getShell(), title, message);
203:                        return false;
204:                    } catch (InterruptedException e) {
205:                        // cancelled
206:                        return false;
207:                    }
208:                }
209:                return true;
210:            }
211:
212:            /*
213:             * @see PreferencePage#performDefaults()
214:             */
215:            protected void performDefaults() {
216:                if (fSourceAttachmentBlock != null) {
217:                    fSourceAttachmentBlock.setDefaults();
218:                }
219:                super .performDefaults();
220:            }
221:
222:            private IPackageFragmentRoot getJARPackageFragmentRoot()
223:                    throws CoreException {
224:                // try to find it as Java element (needed for external jars)
225:                IAdaptable adaptable = getElement();
226:                IJavaElement elem = (IJavaElement) adaptable
227:                        .getAdapter(IJavaElement.class);
228:                if (elem instanceof  IPackageFragmentRoot) {
229:                    return (IPackageFragmentRoot) elem;
230:                }
231:                // not on classpath or not in a java project
232:                IResource resource = (IResource) adaptable
233:                        .getAdapter(IResource.class);
234:                if (resource instanceof  IFile) {
235:                    IProject proj = resource.getProject();
236:                    if (proj.hasNature(JavaCore.NATURE_ID)) {
237:                        IJavaProject jproject = JavaCore.create(proj);
238:                        return jproject.getPackageFragmentRoot(resource);
239:                    }
240:                }
241:                return null;
242:            }
243:
244:            /*
245:             * @see IStatusChangeListener#statusChanged
246:             */
247:            public void statusChanged(IStatus status) {
248:                setValid(!status.matches(IStatus.ERROR));
249:                StatusUtil.applyToStatusLine(this, status);
250:            }
251:
252:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.