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


001:        /*******************************************************************************
002:         * Copyright (c) 2004, 2006 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 - Initial API and implementation
010:         *******************************************************************************/package org.eclipse.ui.internal.ide.actions;
011:
012:        import java.util.Collection;
013:        import java.util.HashSet;
014:
015:        import org.eclipse.core.resources.ICommand;
016:        import org.eclipse.core.resources.IFile;
017:        import org.eclipse.core.resources.IProject;
018:        import org.eclipse.core.resources.IProjectDescription;
019:        import org.eclipse.core.resources.IResource;
020:        import org.eclipse.core.resources.IncrementalProjectBuilder;
021:        import org.eclipse.core.resources.ResourcesPlugin;
022:        import org.eclipse.core.resources.mapping.ResourceMapping;
023:        import org.eclipse.core.runtime.CoreException;
024:        import org.eclipse.jface.viewers.ISelection;
025:        import org.eclipse.jface.viewers.IStructuredSelection;
026:        import org.eclipse.ui.IEditorPart;
027:        import org.eclipse.ui.IWorkbenchPage;
028:        import org.eclipse.ui.IWorkbenchPart;
029:        import org.eclipse.ui.IWorkbenchWindow;
030:        import org.eclipse.ui.PlatformUI;
031:        import org.eclipse.ui.actions.BuildAction;
032:        import org.eclipse.ui.ide.ResourceUtil;
033:
034:        /**
035:         * This class contains convenience methods used by the various build commands
036:         * to determine enablement.  These utilities cannot be factored into a common
037:         * class because some build actions are API and some are not.
038:         * 
039:         * @since 3.1
040:         */
041:        public class BuildUtilities {
042:            /**
043:             * Extracts the selected projects from a selection.
044:             * 
045:             * @param selection The selection to analyze
046:             * @return The selected projects
047:             */
048:            public static IProject[] extractProjects(Object[] selection) {
049:                HashSet projects = new HashSet();
050:                for (int i = 0; i < selection.length; i++) {
051:                    IResource resource = ResourceUtil.getResource(selection[i]);
052:                    if (resource != null) {
053:                        projects.add(resource.getProject());
054:                    } else {
055:                        ResourceMapping mapping = ResourceUtil
056:                                .getResourceMapping(selection[i]);
057:                        if (mapping != null) {
058:                            IProject[] theProjects = mapping.getProjects();
059:                            for (int j = 0; j < theProjects.length; j++) {
060:                                projects.add(theProjects[j]);
061:                            }
062:                        }
063:                    }
064:                }
065:                return (IProject[]) projects.toArray(new IProject[projects
066:                        .size()]);
067:            }
068:
069:            /**
070:             * Finds and returns the selected projects in the given window
071:             * 
072:             * @param window The window to find the selection in
073:             * @return The selected projects, or an empty array if no selection could be found.
074:             */
075:            public static IProject[] findSelectedProjects(
076:                    IWorkbenchWindow window) {
077:                if (window == null) {
078:                    return new IProject[0];
079:                }
080:                ISelection selection = window.getSelectionService()
081:                        .getSelection();
082:                IProject[] selected = null;
083:                if (selection != null && !selection.isEmpty()
084:                        && selection instanceof  IStructuredSelection) {
085:                    selected = extractProjects(((IStructuredSelection) selection)
086:                            .toArray());
087:                } else {
088:                    //see if we can extract a selected project from the active editor
089:                    IWorkbenchPart part = window.getPartService()
090:                            .getActivePart();
091:                    if (part instanceof  IEditorPart) {
092:                        IEditorPart editor = (IEditorPart) part;
093:                        IFile file = ResourceUtil.getFile(editor
094:                                .getEditorInput());
095:                        if (file != null) {
096:                            selected = new IProject[] { file.getProject() };
097:                        }
098:                    }
099:                }
100:                if (selected == null) {
101:                    selected = new IProject[0];
102:                }
103:                return selected;
104:            }
105:
106:            /**
107:             * Returns whether a build command with the given trigger should
108:             * be enabled for the given selection.
109:             * @param projects The projects to use to determine enablement
110:             * @param trigger The build trigger (<code>IncrementalProjectBuilder.*_BUILD</code> constants).
111:             * @return <code>true</code> if the action should be enabled, and
112:             * <code>false</code> otherwise.
113:             */
114:            public static boolean isEnabled(IProject[] projects, int trigger) {
115:                //incremental build is only enabled if all projects are not autobuilding
116:                if (trigger == IncrementalProjectBuilder.INCREMENTAL_BUILD
117:                        && ResourcesPlugin.getWorkspace().isAutoBuilding()) {
118:                    if (!matchingTrigger(projects,
119:                            IncrementalProjectBuilder.AUTO_BUILD, false)) {
120:                        return false;
121:                    }
122:                }
123:                //finally we are building only if there is a builder that accepts the trigger
124:                return matchingTrigger(projects, trigger, true);
125:            }
126:
127:            /**
128:             * Returns whether one of the projects has a builder whose trigger setting
129:             * for the given trigger matches the given value.
130:             * 
131:             * @param projects The projects to check
132:             * @param trigger The trigger to look for
133:             * @param value The trigger value to look for
134:             * @return <code>true</code> if one of the projects has a builder whose
135:             * trigger activation matches the provided value, and <code>false</code> otherwise.
136:             */
137:            private static boolean matchingTrigger(IProject[] projects,
138:                    int trigger, boolean value) {
139:                for (int i = 0; i < projects.length; i++) {
140:                    if (!projects[i].isAccessible()) {
141:                        continue;
142:                    }
143:                    try {
144:                        IProjectDescription description = projects[i]
145:                                .getDescription();
146:                        ICommand[] buildSpec = description.getBuildSpec();
147:                        for (int j = 0; j < buildSpec.length; j++) {
148:                            if (buildSpec[j].isBuilding(trigger) == value) {
149:                                return true;
150:                            }
151:                        }
152:                    } catch (CoreException e) {
153:                        //ignore projects that are not available
154:                    }
155:                }
156:                return false;
157:            }
158:
159:            /**
160:             * Causes all editors to save any modified resources in the provided collection
161:             * of projects depending on the user's preference.
162:             * @param projects The projects in which to save editors, or <code>null</code>
163:             * to save editors in all projects.
164:             */
165:            public static void saveEditors(Collection projects) {
166:                if (!BuildAction.isSaveAllSet()) {
167:                    return;
168:                }
169:                IWorkbenchWindow[] windows = PlatformUI.getWorkbench()
170:                        .getWorkbenchWindows();
171:                for (int i = 0; i < windows.length; i++) {
172:                    IWorkbenchPage[] pages = windows[i].getPages();
173:                    for (int j = 0; j < pages.length; j++) {
174:                        IWorkbenchPage page = pages[j];
175:                        if (projects == null) {
176:                            page.saveAllEditors(false);
177:                        } else {
178:                            IEditorPart[] editors = page.getDirtyEditors();
179:                            for (int k = 0; k < editors.length; k++) {
180:                                IEditorPart editor = editors[k];
181:                                IFile inputFile = ResourceUtil.getFile(editor
182:                                        .getEditorInput());
183:                                if (inputFile != null) {
184:                                    if (projects.contains(inputFile
185:                                            .getProject())) {
186:                                        page.saveEditor(editor, false);
187:                                    }
188:                                }
189:                            }
190:                        }
191:                    }
192:                }
193:            }
194:
195:            /**
196:             * Doesn't need to be instantiated
197:             */
198:            private BuildUtilities() {
199:            }
200:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.