Source Code Cross Referenced for JARFileSelectionDialog.java in  » IDE-Eclipse » jdt » org » eclipse » jdt » internal » ui » wizards » buildpaths » 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.wizards.buildpaths 
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.wizards.buildpaths;
011:
012:        import java.io.File;
013:
014:        import org.eclipse.core.runtime.IStatus;
015:
016:        import org.eclipse.swt.graphics.Image;
017:        import org.eclipse.swt.widgets.Shell;
018:
019:        import org.eclipse.jface.viewers.ITreeContentProvider;
020:        import org.eclipse.jface.viewers.LabelProvider;
021:        import org.eclipse.jface.viewers.Viewer;
022:        import org.eclipse.jface.viewers.ViewerComparator;
023:        import org.eclipse.jface.viewers.ViewerFilter;
024:
025:        import org.eclipse.ui.ISharedImages;
026:        import org.eclipse.ui.PlatformUI;
027:        import org.eclipse.ui.dialogs.ElementTreeSelectionDialog;
028:        import org.eclipse.ui.dialogs.ISelectionStatusValidator;
029:
030:        import org.eclipse.jdt.internal.ui.JavaPlugin;
031:        import org.eclipse.jdt.internal.ui.JavaPluginImages;
032:        import org.eclipse.jdt.internal.ui.dialogs.StatusInfo;
033:
034:        /**
035:         * Selection dialog to select a JAR on the file system.
036:         * Set input to a java.io.File that point to folder.
037:         */
038:        public class JARFileSelectionDialog extends ElementTreeSelectionDialog {
039:
040:            /**
041:             * Constructor for JARFileSelectionDialog.
042:             * @param parent parent shell
043:             * @param multiSelect specifies if selecting multiple elements is allowed
044:             * @param acceptFolders specifies if folders can be selected as well
045:             */
046:            public JARFileSelectionDialog(Shell parent, boolean multiSelect,
047:                    boolean acceptFolders) {
048:                super (parent, new FileLabelProvider(),
049:                        new FileContentProvider());
050:                setComparator(new FileViewerComparator());
051:                addFilter(new FileArchiveFileFilter(acceptFolders));
052:                setValidator(new FileSelectionValidator(multiSelect,
053:                        acceptFolders));
054:                setHelpAvailable(false);
055:            }
056:
057:            private static boolean isArchive(File file) {
058:                String name = file.getName();
059:                int detIndex = name.lastIndexOf('.');
060:                return (detIndex != -1 && ArchiveFileFilter
061:                        .isArchiveFileExtension(name.substring(detIndex + 1)));
062:            }
063:
064:            private static class FileLabelProvider extends LabelProvider {
065:                private final Image IMG_FOLDER = PlatformUI.getWorkbench()
066:                        .getSharedImages().getImage(
067:                                ISharedImages.IMG_OBJ_FOLDER);
068:                private final Image IMG_JAR = JavaPlugin.getDefault()
069:                        .getImageRegistry().get(
070:                                JavaPluginImages.IMG_OBJS_EXTJAR);
071:
072:                public Image getImage(Object element) {
073:                    if (element instanceof  File) {
074:                        File curr = (File) element;
075:                        if (curr.isDirectory()) {
076:                            return IMG_FOLDER;
077:                        } else {
078:                            return IMG_JAR;
079:                        }
080:                    }
081:                    return null;
082:                }
083:
084:                public String getText(Object element) {
085:                    if (element instanceof  File) {
086:                        return ((File) element).getName();
087:                    }
088:                    return super .getText(element);
089:                }
090:            }
091:
092:            private static class FileContentProvider implements 
093:                    ITreeContentProvider {
094:
095:                private final Object[] EMPTY = new Object[0];
096:
097:                public Object[] getChildren(Object parentElement) {
098:                    if (parentElement instanceof  File) {
099:                        File[] children = ((File) parentElement).listFiles();
100:                        if (children != null) {
101:                            return children;
102:                        }
103:                    }
104:                    return EMPTY;
105:                }
106:
107:                public Object getParent(Object element) {
108:                    if (element instanceof  File) {
109:                        return ((File) element).getParentFile();
110:                    }
111:                    return null;
112:                }
113:
114:                public boolean hasChildren(Object element) {
115:                    return getChildren(element).length > 0;
116:                }
117:
118:                public Object[] getElements(Object element) {
119:                    return getChildren(element);
120:                }
121:
122:                public void dispose() {
123:                }
124:
125:                public void inputChanged(Viewer viewer, Object oldInput,
126:                        Object newInput) {
127:                }
128:
129:            }
130:
131:            private static class FileArchiveFileFilter extends ViewerFilter {
132:                private final boolean fAcceptFolders;
133:
134:                public FileArchiveFileFilter(boolean acceptFolders) {
135:                    fAcceptFolders = acceptFolders;
136:                }
137:
138:                public boolean select(Viewer viewer, Object parent,
139:                        Object element) {
140:                    if (element instanceof  File) {
141:                        File file = (File) element;
142:                        if (file.isFile()) {
143:                            return isArchive(file);
144:                        } else if (fAcceptFolders) {
145:                            return true;
146:                        } else {
147:                            File[] listFiles = file.listFiles();
148:                            if (listFiles != null) {
149:                                for (int i = 0; i < listFiles.length; i++) {
150:                                    if (select(viewer, file, listFiles[i])) {
151:                                        return true;
152:                                    }
153:                                }
154:                            }
155:                        }
156:                    }
157:                    return false;
158:                }
159:            }
160:
161:            private static class FileViewerComparator extends ViewerComparator {
162:                public int category(Object element) {
163:                    if (element instanceof  File) {
164:                        if (((File) element).isFile()) {
165:                            return 1;
166:                        }
167:                    }
168:                    return 0;
169:                }
170:            }
171:
172:            private static class FileSelectionValidator implements 
173:                    ISelectionStatusValidator {
174:                private boolean fMultiSelect;
175:                private boolean fAcceptFolders;
176:
177:                public FileSelectionValidator(boolean multiSelect,
178:                        boolean acceptFolders) {
179:                    fMultiSelect = multiSelect;
180:                    fAcceptFolders = acceptFolders;
181:                }
182:
183:                public IStatus validate(Object[] selection) {
184:                    int nSelected = selection.length;
185:                    if (nSelected == 0 || (nSelected > 1 && !fMultiSelect)) {
186:                        return new StatusInfo(IStatus.ERROR, ""); //$NON-NLS-1$
187:                    }
188:                    for (int i = 0; i < selection.length; i++) {
189:                        Object curr = selection[i];
190:                        if (curr instanceof  File) {
191:                            File file = (File) curr;
192:                            if (!fAcceptFolders && !file.isFile()) {
193:                                return new StatusInfo(IStatus.ERROR, ""); //$NON-NLS-1$
194:                            }
195:                        }
196:                    }
197:                    return new StatusInfo();
198:                }
199:            }
200:
201:        }
w__w_w__.__jav__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.