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


001:        /*******************************************************************************
002:         * Copyright (c) 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.ui.internal.actions;
011:
012:        import java.util.ArrayList;
013:        import java.util.Iterator;
014:        import java.util.Map;
015:
016:        import org.eclipse.core.commands.Command;
017:        import org.eclipse.core.commands.CommandEvent;
018:        import org.eclipse.core.commands.ICommandListener;
019:        import org.eclipse.core.commands.IParameter;
020:        import org.eclipse.core.commands.Parameterization;
021:        import org.eclipse.core.commands.ParameterizedCommand;
022:        import org.eclipse.core.commands.common.NotDefinedException;
023:        import org.eclipse.jface.action.Action;
024:        import org.eclipse.swt.widgets.Event;
025:        import org.eclipse.ui.commands.ICommandService;
026:        import org.eclipse.ui.handlers.IHandlerService;
027:        import org.eclipse.ui.internal.WorkbenchPlugin;
028:        import org.eclipse.ui.services.IServiceLocator;
029:
030:        /**
031:         * Instantiate an action that will execute the command.
032:         * <p>
033:         * This is a legacy bridge class, and should not be used outside of the
034:         * framework. Please use menu contributions to display a command in a menu or
035:         * toolbar.
036:         * </p>
037:         * <p>
038:         * <b>Note:</b> Clients my instantiate, but they must not subclass.
039:         * </p>
040:         * 
041:         * @since 3.3
042:         */
043:        public class CommandAction extends Action {
044:
045:            private IHandlerService handlerService = null;
046:
047:            private ParameterizedCommand parameterizedCommand = null;
048:
049:            private ICommandListener commandListener;
050:
051:            protected CommandAction() {
052:
053:            }
054:
055:            /**
056:             * Creates the action backed by a command. For commands that don't take
057:             * parameters.
058:             * 
059:             * @param serviceLocator
060:             *            The service locator that is closest in lifecycle to this
061:             *            action.
062:             * @param commandIdIn
063:             *            the command id. Must not be <code>null</code>.
064:             */
065:            public CommandAction(IServiceLocator serviceLocator,
066:                    String commandIdIn) {
067:                this (serviceLocator, commandIdIn, null);
068:            }
069:
070:            /**
071:             * Creates the action backed by a parameterized command. The parameterMap
072:             * must contain only all required parameters, and may contain the optional
073:             * parameters.
074:             * 
075:             * @param serviceLocator
076:             *            The service locator that is closest in lifecycle to this
077:             *            action.
078:             * @param commandIdIn
079:             *            the command id. Must not be <code>null</code>.
080:             * @param parameterMap
081:             *            the parameter map. May be <code>null</code>.
082:             */
083:            public CommandAction(IServiceLocator serviceLocator,
084:                    String commandIdIn, Map parameterMap) {
085:                if (commandIdIn == null) {
086:                    throw new NullPointerException(
087:                            "commandIdIn must not be null"); //$NON-NLS-1$
088:                }
089:                init(serviceLocator, commandIdIn, parameterMap);
090:            }
091:
092:            protected ICommandListener getCommandListener() {
093:                if (commandListener == null) {
094:                    commandListener = new ICommandListener() {
095:                        public void commandChanged(CommandEvent commandEvent) {
096:                            if (commandEvent.isHandledChanged()
097:                                    || commandEvent.isEnabledChanged()) {
098:                                if (commandEvent.getCommand().isDefined()) {
099:                                    setEnabled(commandEvent.getCommand()
100:                                            .isEnabled());
101:                                }
102:                            }
103:                        }
104:                    };
105:                }
106:                return commandListener;
107:            }
108:
109:            /**
110:             * Build a command from the executable extension information.
111:             * 
112:             * @param commandService
113:             *            to get the Command object
114:             * @param commandId
115:             *            the command id for this action
116:             * @param parameterMap
117:             */
118:            private void createCommand(ICommandService commandService,
119:                    String commandId, Map parameterMap) {
120:                try {
121:                    Command cmd = commandService.getCommand(commandId);
122:                    if (!cmd.isDefined()) {
123:                        WorkbenchPlugin
124:                                .log("Command " + commandId + " is undefined"); //$NON-NLS-1$//$NON-NLS-2$
125:                        return;
126:                    }
127:
128:                    if (parameterMap == null) {
129:                        parameterizedCommand = new ParameterizedCommand(cmd,
130:                                null);
131:                        return;
132:                    }
133:
134:                    ArrayList parameters = new ArrayList();
135:                    Iterator i = parameterMap.keySet().iterator();
136:                    while (i.hasNext()) {
137:                        String parmName = (String) i.next();
138:                        IParameter parm = cmd.getParameter(parmName);
139:                        if (parm == null) {
140:                            WorkbenchPlugin
141:                                    .log("Invalid parameter \'" + parmName //$NON-NLS-1$
142:                                            + "\' for command " + commandId); //$NON-NLS-1$
143:                            return;
144:                        }
145:                        parameters.add(new Parameterization(parm,
146:                                (String) parameterMap.get(parmName)));
147:                    }
148:                    parameterizedCommand = new ParameterizedCommand(cmd,
149:                            (Parameterization[]) parameters
150:                                    .toArray(new Parameterization[parameters
151:                                            .size()]));
152:                } catch (NotDefinedException e) {
153:                    WorkbenchPlugin.log(e);
154:                }
155:            }
156:
157:            public void dispose() {
158:                // not important for command ID, maybe for command though.
159:                handlerService = null;
160:                if (commandListener != null) {
161:                    parameterizedCommand.getCommand().removeCommandListener(
162:                            commandListener);
163:                    commandListener = null;
164:                }
165:                parameterizedCommand = null;
166:            }
167:
168:            /*
169:             * (non-Javadoc)
170:             * 
171:             * @see org.eclipse.jface.action.Action#runWithEvent(org.eclipse.swt.widgets.Event)
172:             */
173:            public void runWithEvent(Event event) {
174:                if (handlerService == null) {
175:                    String commandId = (parameterizedCommand == null ? "unknownCommand" //$NON-NLS-1$
176:                            : parameterizedCommand.getId());
177:                    WorkbenchPlugin.log("Cannot run " + commandId //$NON-NLS-1$
178:                            + " before command action has been initialized"); //$NON-NLS-1$
179:                    return;
180:                }
181:                try {
182:                    if (parameterizedCommand != null) {
183:                        handlerService.executeCommand(parameterizedCommand,
184:                                event);
185:                    }
186:                } catch (Exception e) {
187:                    WorkbenchPlugin.log(e);
188:                }
189:            }
190:
191:            /*
192:             * (non-Javadoc)
193:             * 
194:             * @see org.eclipse.jface.action.Action#run()
195:             */
196:            public void run() {
197:                // hopefully this is never called
198:                runWithEvent(null);
199:            }
200:
201:            protected void init(IServiceLocator serviceLocator,
202:                    String commandIdIn, Map parameterMap) {
203:                if (handlerService != null) {
204:                    // already initialized
205:                    return;
206:                }
207:                handlerService = (IHandlerService) serviceLocator
208:                        .getService(IHandlerService.class);
209:                ICommandService commandService = (ICommandService) serviceLocator
210:                        .getService(ICommandService.class);
211:                createCommand(commandService, commandIdIn, parameterMap);
212:                if (parameterizedCommand != null) {
213:                    setId(parameterizedCommand.getId());
214:                    try {
215:                        setText(parameterizedCommand.getName());
216:                    } catch (NotDefinedException e) {
217:                        // if we get this far it shouldn't be a problem
218:                    }
219:                    parameterizedCommand.getCommand().addCommandListener(
220:                            getCommandListener());
221:                    setEnabled(parameterizedCommand.getCommand().isEnabled());
222:                }
223:            }
224:
225:            protected ParameterizedCommand getParameterizedCommand() {
226:                return parameterizedCommand;
227:            }
228:
229:            public String getActionDefinitionId() {
230:                if (parameterizedCommand != null) {
231:                    return parameterizedCommand.getId();
232:                }
233:                return null;
234:            }
235:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.