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


001:        /*******************************************************************************
002:         * Copyright (c) 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 Corporation - initial API and implementation
010:         ******************************************************************************/package org.eclipse.ui.internal.navigator.resources.actions;
011:
012:        import java.util.Iterator;
013:
014:        import org.eclipse.core.resources.ICommand;
015:        import org.eclipse.core.resources.IProject;
016:        import org.eclipse.core.resources.IncrementalProjectBuilder;
017:        import org.eclipse.core.resources.ResourcesPlugin;
018:        import org.eclipse.core.runtime.CoreException;
019:        import org.eclipse.core.runtime.IAdaptable;
020:        import org.eclipse.jface.action.IMenuManager;
021:        import org.eclipse.jface.resource.ImageDescriptor;
022:        import org.eclipse.jface.viewers.IStructuredSelection;
023:        import org.eclipse.swt.widgets.Shell;
024:        import org.eclipse.ui.IActionBars;
025:        import org.eclipse.ui.actions.ActionFactory;
026:        import org.eclipse.ui.actions.BuildAction;
027:        import org.eclipse.ui.actions.CloseResourceAction;
028:        import org.eclipse.ui.actions.CloseUnrelatedProjectsAction;
029:        import org.eclipse.ui.actions.OpenResourceAction;
030:        import org.eclipse.ui.actions.RefreshAction;
031:        import org.eclipse.ui.ide.IDEActionFactory;
032:        import org.eclipse.ui.internal.ide.IDEWorkbenchPlugin;
033:        import org.eclipse.ui.navigator.CommonActionProvider;
034:        import org.eclipse.ui.navigator.ICommonActionExtensionSite;
035:        import org.eclipse.ui.navigator.ICommonMenuConstants;
036:
037:        /**
038:         * @since 3.2
039:         *
040:         */
041:        public class ResourceMgmtActionProvider extends CommonActionProvider {
042:
043:            private BuildAction buildAction;
044:
045:            private OpenResourceAction openProjectAction;
046:
047:            private CloseResourceAction closeProjectAction;
048:
049:            private CloseUnrelatedProjectsAction closeUnrelatedProjectsAction;
050:
051:            private RefreshAction refreshAction;
052:
053:            private Shell shell;
054:
055:            /* (non-Javadoc)
056:             * @see org.eclipse.ui.navigator.CommonActionProvider#init(org.eclipse.ui.navigator.ICommonActionExtensionSite)
057:             */
058:            public void init(ICommonActionExtensionSite aSite) {
059:                super .init(aSite);
060:                shell = aSite.getViewSite().getShell();
061:                makeActions();
062:            }
063:
064:            public void fillActionBars(IActionBars actionBars) {
065:                actionBars.setGlobalActionHandler(
066:                        ActionFactory.REFRESH.getId(), refreshAction);
067:                actionBars.setGlobalActionHandler(
068:                        IDEActionFactory.BUILD_PROJECT.getId(), buildAction);
069:                actionBars.setGlobalActionHandler(IDEActionFactory.OPEN_PROJECT
070:                        .getId(), openProjectAction);
071:                actionBars.setGlobalActionHandler(
072:                        IDEActionFactory.CLOSE_PROJECT.getId(),
073:                        closeProjectAction);
074:                actionBars.setGlobalActionHandler(
075:                        IDEActionFactory.CLOSE_UNRELATED_PROJECTS.getId(),
076:                        closeUnrelatedProjectsAction);
077:                updateActionBars();
078:            }
079:
080:            /**
081:             * Adds the build, open project, close project and refresh resource
082:             * actions to the context menu.
083:             * <p>
084:             * The following conditions apply: 
085:             * 	build-only projects selected, auto build disabled, at least one 
086:             * 		builder present
087:             * 	open project-only projects selected, at least one closed project
088:             * 	close project-only projects selected, at least one open project
089:             * 	refresh-no closed project selected
090:             * </p>
091:             * <p>
092:             * Both the open project and close project action may be on the menu
093:             * at the same time.
094:             * </p>
095:             * <p>
096:             * No disabled action should be on the context menu.
097:             * </p>
098:             * 
099:             * @param menu context menu to add actions to
100:             */
101:            public void fillContextMenu(IMenuManager menu) {
102:                IStructuredSelection selection = (IStructuredSelection) getContext()
103:                        .getSelection();
104:                boolean isProjectSelection = true;
105:                boolean hasOpenProjects = false;
106:                boolean hasClosedProjects = false;
107:                boolean hasBuilder = true; // false if any project is closed or does not have builder 
108:                Iterator resources = selection.iterator();
109:
110:                while (resources.hasNext()
111:                        && (!hasOpenProjects || !hasClosedProjects
112:                                || hasBuilder || isProjectSelection)) {
113:                    Object next = resources.next();
114:                    IProject project = null;
115:
116:                    if (next instanceof  IProject) {
117:                        project = (IProject) next;
118:                    } else if (next instanceof  IAdaptable) {
119:                        project = (IProject) ((IAdaptable) next)
120:                                .getAdapter(IProject.class);
121:                    }
122:
123:                    if (project == null) {
124:                        isProjectSelection = false;
125:                        continue;
126:                    }
127:                    if (project.isOpen()) {
128:                        hasOpenProjects = true;
129:                        if (hasBuilder && !hasBuilder(project)) {
130:                            hasBuilder = false;
131:                        }
132:                    } else {
133:                        hasClosedProjects = true;
134:                        hasBuilder = false;
135:                    }
136:                }
137:                if (!selection.isEmpty() && isProjectSelection
138:                        && !ResourcesPlugin.getWorkspace().isAutoBuilding()
139:                        && hasBuilder) {
140:                    // Allow manual incremental build only if auto build is off.
141:                    buildAction.selectionChanged(selection);
142:                    menu.appendToGroup(ICommonMenuConstants.GROUP_BUILD,
143:                            buildAction);
144:                }
145:                if (!hasClosedProjects) {
146:                    refreshAction.selectionChanged(selection);
147:                    menu.appendToGroup(ICommonMenuConstants.GROUP_BUILD,
148:                            refreshAction);
149:                }
150:                if (isProjectSelection) {
151:                    if (hasClosedProjects) {
152:                        openProjectAction.selectionChanged(selection);
153:                        menu.appendToGroup(ICommonMenuConstants.GROUP_BUILD,
154:                                openProjectAction);
155:                    }
156:                    if (hasOpenProjects) {
157:                        closeProjectAction.selectionChanged(selection);
158:                        menu.appendToGroup(ICommonMenuConstants.GROUP_BUILD,
159:                                closeProjectAction);
160:                        closeUnrelatedProjectsAction
161:                                .selectionChanged(selection);
162:                        menu.appendToGroup(ICommonMenuConstants.GROUP_BUILD,
163:                                closeUnrelatedProjectsAction);
164:                    }
165:                }
166:            }
167:
168:            /**
169:             * Returns whether there are builders configured on the given project.
170:             *
171:             * @return <code>true</code> if it has builders,
172:             *   <code>false</code> if not, or if this could not be determined
173:             */
174:            boolean hasBuilder(IProject project) {
175:                try {
176:                    ICommand[] commands = project.getDescription()
177:                            .getBuildSpec();
178:                    if (commands.length > 0) {
179:                        return true;
180:                    }
181:                } catch (CoreException e) {
182:                    // Cannot determine if project has builders. Project is closed 
183:                    // or does not exist. Fall through to return false.
184:                }
185:                return false;
186:            }
187:
188:            protected void makeActions() {
189:                //Shell shell = navigator.getSite().getShell();
190:                openProjectAction = new OpenResourceAction(shell);
191:
192:                closeProjectAction = new CloseResourceAction(shell);
193:
194:                closeUnrelatedProjectsAction = new CloseUnrelatedProjectsAction(
195:                        shell);
196:
197:                refreshAction = new RefreshAction(shell);
198:                refreshAction
199:                        .setDisabledImageDescriptor(getImageDescriptor("dlcl16/refresh_nav.gif"));//$NON-NLS-1$
200:                refreshAction
201:                        .setImageDescriptor(getImageDescriptor("elcl16/refresh_nav.gif"));//$NON-NLS-1$       
202:                refreshAction
203:                        .setActionDefinitionId("org.eclipse.ui.file.refresh"); //$NON-NLS-1$
204:
205:                buildAction = new BuildAction(shell,
206:                        IncrementalProjectBuilder.INCREMENTAL_BUILD);
207:                buildAction
208:                        .setActionDefinitionId("org.eclipse.ui.project.buildProject"); //$NON-NLS-1$
209:            }
210:
211:            /**
212:             * Returns the image descriptor with the given relative path.
213:             */
214:            protected ImageDescriptor getImageDescriptor(String relativePath) {
215:                return IDEWorkbenchPlugin.getIDEImageDescriptor(relativePath);
216:
217:            }
218:
219:            public void updateActionBars() {
220:                IStructuredSelection selection = (IStructuredSelection) getContext()
221:                        .getSelection();
222:                refreshAction.selectionChanged(selection);
223:                buildAction.selectionChanged(selection);
224:                openProjectAction.selectionChanged(selection);
225:                closeUnrelatedProjectsAction.selectionChanged(selection);
226:                closeProjectAction.selectionChanged(selection);
227:            }
228:
229:        }
ww__w___.j__a_v__a2__s__._co__m__ | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.