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


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