Source Code Cross Referenced for TextOperationAction.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, 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.texteditor;
011:
012:        import java.util.ResourceBundle;
013:
014:        import org.eclipse.swt.custom.BusyIndicator;
015:        import org.eclipse.swt.widgets.Display;
016:        import org.eclipse.swt.widgets.Shell;
017:
018:        import org.eclipse.jface.text.ITextOperationTarget;
019:
020:        import org.eclipse.ui.IWorkbenchPartSite;
021:
022:        /**
023:         * An action which gets a text operation target from its text editor.
024:         * <p>
025:         * The action is initially associated with a text editor via the constructor,
026:         * but can subsequently be changed using <code>setEditor</code>.</p>
027:         * <p>
028:         * If this class is used as is, it works by asking the text editor for its
029:         * text operation target adapter (using <code>getAdapter(ITextOperationTarget.class)</code>.
030:         * The action runs this operation with the pre-configured opcode.</p>
031:         */
032:        public final class TextOperationAction extends TextEditorAction {
033:
034:            /** The text operation code */
035:            private int fOperationCode = -1;
036:            /** The text operation target */
037:            private ITextOperationTarget fOperationTarget;
038:            /**
039:             * Indicates whether this action can be executed on read only editors
040:             * @since 2.0
041:             */
042:            private boolean fRunsOnReadOnly = false;
043:
044:            /**
045:             * Flag to prevent running twice trough {@link #update()}
046:             * when creating this action.
047:             * @since 3.2
048:             */
049:            private boolean fAllowUpdate = false;
050:
051:            /**
052:             * Creates and initializes the action for the given text editor and operation
053:             * code. The action configures its visual representation from the given resource
054:             * bundle. The action works by asking the text editor at the time for its
055:             * text operation target adapter (using
056:             * <code>getAdapter(ITextOperationTarget.class)</code>. The action runs that
057:             * operation with the given opcode.
058:             *
059:             * @param bundle the resource bundle
060:             * @param prefix a prefix to be prepended to the various resource keys
061:             *   (described in <code>ResourceAction</code> constructor), or
062:             *   <code>null</code> if none
063:             * @param editor the text editor
064:             * @param operationCode the operation code
065:             * @see TextEditorAction#TextEditorAction(ResourceBundle, String, ITextEditor)
066:             */
067:            public TextOperationAction(ResourceBundle bundle, String prefix,
068:                    ITextEditor editor, int operationCode) {
069:                super (bundle, prefix, editor);
070:                fOperationCode = operationCode;
071:                fAllowUpdate = true;
072:                update();
073:            }
074:
075:            /**
076:             * Creates and initializes the action for the given text editor and operation
077:             * code. The action configures its visual representation from the given resource
078:             * bundle. The action works by asking the text editor at the time for its
079:             * text operation target adapter (using
080:             * <code>getAdapter(ITextOperationTarget.class)</code>. The action runs that
081:             * operation with the given opcode.
082:             *
083:             * @param bundle the resource bundle
084:             * @param prefix a prefix to be prepended to the various resource keys
085:             *   (described in <code>ResourceAction</code> constructor), or
086:             *   <code>null</code> if none
087:             * @param editor the text editor
088:             * @param operationCode the operation code
089:             * @param runsOnReadOnly <code>true</code> if action can be executed on read-only files
090:             *
091:             * @see TextEditorAction#TextEditorAction(ResourceBundle, String, ITextEditor)
092:             * @since 2.0
093:             */
094:            public TextOperationAction(ResourceBundle bundle, String prefix,
095:                    ITextEditor editor, int operationCode,
096:                    boolean runsOnReadOnly) {
097:                super (bundle, prefix, editor);
098:                fOperationCode = operationCode;
099:                fRunsOnReadOnly = runsOnReadOnly;
100:                fAllowUpdate = true;
101:                update();
102:            }
103:
104:            /**
105:             * The <code>TextOperationAction</code> implementation of this
106:             * <code>IAction</code> method runs the operation with the current
107:             * operation code.
108:             */
109:            public void run() {
110:                if (fOperationCode == -1 || fOperationTarget == null)
111:                    return;
112:
113:                ITextEditor editor = getTextEditor();
114:                if (editor == null)
115:                    return;
116:
117:                if (!fRunsOnReadOnly && !validateEditorInputState())
118:                    return;
119:
120:                Display display = null;
121:
122:                IWorkbenchPartSite site = editor.getSite();
123:                Shell shell = site.getShell();
124:                if (shell != null && !shell.isDisposed())
125:                    display = shell.getDisplay();
126:
127:                BusyIndicator.showWhile(display, new Runnable() {
128:                    public void run() {
129:                        fOperationTarget.doOperation(fOperationCode);
130:                    }
131:                });
132:            }
133:
134:            /**
135:             * The <code>TextOperationAction</code> implementation of this
136:             * <code>IUpdate</code> method discovers the operation through the current
137:             * editor's <code>ITextOperationTarget</code> adapter, and sets the
138:             * enabled state accordingly.
139:             */
140:            public void update() {
141:                if (!fAllowUpdate)
142:                    return;
143:
144:                super .update();
145:
146:                if (!fRunsOnReadOnly && !canModifyEditor()) {
147:                    setEnabled(false);
148:                    return;
149:                }
150:
151:                ITextEditor editor = getTextEditor();
152:                if (fOperationTarget == null && editor != null
153:                        && fOperationCode != -1)
154:                    fOperationTarget = (ITextOperationTarget) editor
155:                            .getAdapter(ITextOperationTarget.class);
156:
157:                boolean isEnabled = (fOperationTarget != null && fOperationTarget
158:                        .canDoOperation(fOperationCode));
159:                setEnabled(isEnabled);
160:            }
161:
162:            /*
163:             * @see TextEditorAction#setEditor(ITextEditor)
164:             */
165:            public void setEditor(ITextEditor editor) {
166:                super.setEditor(editor);
167:                fOperationTarget = null;
168:            }
169:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.