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


001:        /*******************************************************************************
002:         * Copyright (c) 2000, 2005 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.texteditor;
011:
012:        import java.util.ResourceBundle;
013:
014:        import org.eclipse.swt.events.HelpEvent;
015:        import org.eclipse.swt.events.HelpListener;
016:
017:        import org.eclipse.jface.action.IAction;
018:        import org.eclipse.jface.util.IPropertyChangeListener;
019:        import org.eclipse.jface.util.PropertyChangeEvent;
020:
021:        /**
022:         * Action used by an editor action bar contributor to establish placeholders in
023:         * menus or action bars which can be retargeted to dynamically changing actions,
024:         * for example, those which come from the active editor. This action assumes that
025:         * the "wrapped" action sends out property change events in response to state
026:         * changes. It uses these change notifications to adapt its enabling state and
027:         * its visual presentation.
028:         */
029:        public final class RetargetTextEditorAction extends ResourceAction {
030:
031:            /** The target action. */
032:            private IAction fAction;
033:            /** The default label if there is no target action. */
034:            private String fDefaultText;
035:            /**
036:             * The local help listener
037:             * @since 2.1
038:             */
039:            private HelpListener fLocalHelpListener;
040:            /** The listener to pick up changes of the target action. */
041:            private IPropertyChangeListener fListener = new IPropertyChangeListener() {
042:                public void propertyChange(PropertyChangeEvent event) {
043:                    update(event);
044:                }
045:            };
046:
047:            /**
048:             * Creates a new action. The action configures its initial visual
049:             * representation from the given resource bundle. If this action's
050:             * wrapped action is set to <code>null</code> it also uses the
051:             * information in the resource bundle.
052:             *
053:             * @param bundle the resource bundle
054:             * @param prefix a prefix to be prepended to the various resource keys
055:             *   (described in <code>ResourceAction</code> constructor), or
056:             *   <code>null</code> if none
057:             * @param	style one of <code>IAction.AS_PUSH_BUTTON</code>, <code>IAction.AS_CHECK_BOX</code>,
058:             *			and <code>IAction.AS_RADIO_BUTTON</code>.
059:             *
060:             * @see ResourceAction#ResourceAction(ResourceBundle, String, int)
061:             * @see IAction#AS_CHECK_BOX
062:             * @see IAction#AS_DROP_DOWN_MENU
063:             * @see IAction#AS_PUSH_BUTTON
064:             * @see IAction#AS_RADIO_BUTTON
065:             * @since 2.1
066:             */
067:            public RetargetTextEditorAction(ResourceBundle bundle,
068:                    String prefix, int style) {
069:                super (bundle, prefix, style);
070:                fDefaultText = getText();
071:                installHelpListener();
072:            }
073:
074:            /**
075:             * Creates a new action. The action configures its initial visual
076:             * representation from the given resource bundle. If this action's
077:             * wrapped action is set to <code>null</code> it also uses the
078:             * information in the resource bundle.
079:             *
080:             * @param bundle the resource bundle
081:             * @param prefix a prefix to be prepended to the various resource keys
082:             *   (described in <code>ResourceAction</code> constructor), or
083:             *   <code>null</code> if none
084:             * @see ResourceAction#ResourceAction(ResourceBundle, String)
085:             */
086:            public RetargetTextEditorAction(ResourceBundle bundle, String prefix) {
087:                super (bundle, prefix);
088:                fDefaultText = getText();
089:                installHelpListener();
090:            }
091:
092:            /**
093:             * Creates a new action. The action configures its initial visual
094:             * representation from the given resource bundle. If this action's
095:             * wrapped action is set to <code>null</code> it also uses the
096:             * information in the resource bundle. The action gets the given
097:             * action id.
098:             *
099:             * @param bundle the resource bundle
100:             * @param prefix a prefix to be prepended to the various resource keys
101:             *   (described in <code>ResourceAction</code> constructor), or <code>null</code> if none
102:             * @param actionId the action id
103:             * @param	style one of <code>IAction.AS_PUSH_BUTTON</code>, <code>IAction.AS_CHECK_BOX</code>,
104:             *			and <code>IAction.AS_RADIO_BUTTON</code>.
105:             *
106:             * @see ResourceAction#ResourceAction(ResourceBundle, String, int)
107:             * @see IAction#AS_CHECK_BOX
108:             * @see IAction#AS_DROP_DOWN_MENU
109:             * @see IAction#AS_PUSH_BUTTON
110:             * @see IAction#AS_RADIO_BUTTON
111:             * @since 2.1
112:             */
113:            public RetargetTextEditorAction(ResourceBundle bundle,
114:                    String prefix, String actionId, int style) {
115:                super (bundle, prefix, style);
116:                fDefaultText = getText();
117:                setId(actionId);
118:                installHelpListener();
119:            }
120:
121:            /**
122:             * Creates a new action. The action configures its initial visual
123:             * representation from the given resource bundle. If this action's
124:             * wrapped action is set to <code>null</code> it also uses the
125:             * information in the resource bundle. The action gets the given
126:             * action id.
127:             *
128:             * @param bundle the resource bundle
129:             * @param prefix a prefix to be prepended to the various resource keys
130:             *   (described in <code>ResourceAction</code> constructor), or <code>null</code> if none
131:             * @param actionId the action id
132:             * @see ResourceAction#ResourceAction(ResourceBundle, String)
133:             * @since 2.0
134:             */
135:            public RetargetTextEditorAction(ResourceBundle bundle,
136:                    String prefix, String actionId) {
137:                super (bundle, prefix);
138:                fDefaultText = getText();
139:                setId(actionId);
140:                installHelpListener();
141:            }
142:
143:            /**
144:             * Updates to the changes of the underlying action.
145:             *
146:             * @param event the change event describing the state change
147:             */
148:            private void update(PropertyChangeEvent event) {
149:                if (ENABLED.equals(event.getProperty())) {
150:                    Boolean bool = (Boolean) event.getNewValue();
151:                    setEnabled(bool.booleanValue());
152:                } else if (TEXT.equals(event.getProperty()))
153:                    setText((String) event.getNewValue());
154:                else if (TOOL_TIP_TEXT.equals(event.getProperty()))
155:                    setToolTipText((String) event.getNewValue());
156:                else if (CHECKED.equals(event.getProperty())) {
157:                    Boolean bool = (Boolean) event.getNewValue();
158:                    setChecked(bool.booleanValue());
159:                }
160:            }
161:
162:            /**
163:             * Sets the underlying action.
164:             *
165:             * @param action the underlying action
166:             */
167:            public void setAction(IAction action) {
168:
169:                if (fAction != null) {
170:                    fAction.removePropertyChangeListener(fListener);
171:                    fAction = null;
172:                }
173:
174:                fAction = action;
175:
176:                if (fAction == null) {
177:
178:                    setEnabled(false);
179:                    if (getStyle() == AS_CHECK_BOX
180:                            || getStyle() == AS_RADIO_BUTTON)
181:                        setChecked(false);
182:                    setText(fDefaultText);
183:                    setToolTipText(""); //$NON-NLS-1$
184:
185:                } else {
186:
187:                    setEnabled(fAction.isEnabled());
188:                    if (fAction.getStyle() == AS_CHECK_BOX
189:                            || fAction.getStyle() == AS_RADIO_BUTTON)
190:                        super .setChecked(fAction.isChecked());
191:                    setText(fAction.getText());
192:                    setToolTipText(fAction.getToolTipText());
193:                    fAction.addPropertyChangeListener(fListener);
194:                }
195:            }
196:
197:            /**
198:             * Installs the help listener.
199:             *
200:             * @since 2.1
201:             */
202:            private void installHelpListener() {
203:                super .setHelpListener(new HelpListener() {
204:                    public void helpRequested(HelpEvent e) {
205:                        HelpListener listener = null;
206:                        if (fAction != null) {
207:                            // if we have a handler, see if it has a help listener
208:                            listener = fAction.getHelpListener();
209:                            if (listener == null)
210:                                // use our own help listener
211:                                listener = fLocalHelpListener;
212:                        }
213:                        if (listener != null)
214:                            // pass on the event
215:                            listener.helpRequested(e);
216:                    }
217:                });
218:            }
219:
220:            /**
221:             * The <code>RetargetTextEditorAction</code> implementation of this method declared on
222:             * <code>IAction</code> stores the help listener in a local field. The
223:             * supplied listener is only used if there is no handler.
224:             *
225:             * @param listener the help listener
226:             * @since 2.1
227:             */
228:            public void setHelpListener(HelpListener listener) {
229:                fLocalHelpListener = listener;
230:            }
231:
232:            /*
233:             * @see IAction#run()
234:             */
235:            public void run() {
236:                if (fAction != null)
237:                    fAction.run();
238:            }
239:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.