Source Code Cross Referenced for TextEditorAction.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:        /**
015:         * Skeleton of a standard text editor action. The action is
016:         * initially associated with a text editor via the constructor,
017:         * but can subsequently be changed using <code>setEditor</code>.
018:         * Subclasses must implement the <code>run</code> method and if
019:         * required override the <code>update</code> method.
020:         * <p>
021:         * Subclasses that may modify the editor content should use {@link #canModifyEditor()}
022:         * in their <code>update</code> code to check whether updating the editor is most
023:         * likely possible (even if it is read-only - this may change for editor contents
024:         * that are under version control) and {@link #validateEditorInputState()} before
025:         * actually modifying the editor contents.
026:         * </p>
027:         */
028:        public abstract class TextEditorAction extends ResourceAction implements 
029:                IUpdate {
030:
031:            /** The action's editor */
032:            private ITextEditor fTextEditor;
033:
034:            /**
035:             * Creates and initializes the action for the given text editor. The action
036:             * configures its visual representation from the given resource bundle.
037:             *
038:             * @param bundle the resource bundle
039:             * @param prefix a prefix to be prepended to the various resource keys
040:             *   (described in <code>ResourceAction</code> constructor), or
041:             *   <code>null</code> if none
042:             * @param editor the text editor
043:             * @see ResourceAction#ResourceAction(ResourceBundle, String)
044:             */
045:            protected TextEditorAction(ResourceBundle bundle, String prefix,
046:                    ITextEditor editor) {
047:                super (bundle, prefix);
048:                setEditor(editor);
049:                update();
050:            }
051:
052:            /**
053:             * Creates and initializes the action for the given text editor. The action
054:             * configures its visual representation from the given resource bundle.
055:             *
056:             * @param bundle the resource bundle
057:             * @param prefix a prefix to be prepended to the various resource keys
058:             *   (described in <code>ResourceAction</code> constructor), or
059:             *   <code>null</code> if none
060:             * @param editor the text editor
061:             * @param style the style of this action
062:             * @see ResourceAction#ResourceAction(ResourceBundle, String, int)
063:             * @since 3.0
064:             */
065:            protected TextEditorAction(ResourceBundle bundle, String prefix,
066:                    ITextEditor editor, int style) {
067:                super (bundle, prefix, style);
068:                setEditor(editor);
069:                update();
070:            }
071:
072:            /**
073:             * Returns the action's text editor.
074:             *
075:             * @return the action's text editor
076:             */
077:            protected ITextEditor getTextEditor() {
078:                return fTextEditor;
079:            }
080:
081:            /**
082:             * Retargets this action to the given editor.
083:             *
084:             * @param editor the new editor, or <code>null</code> if none
085:             */
086:            public void setEditor(ITextEditor editor) {
087:                fTextEditor = editor;
088:            }
089:
090:            /**
091:             * Always enables this action if it is connected to a text editor.
092:             * If the associated editor is <code>null</code>, the action is disabled.
093:             * Subclasses may override.
094:             */
095:            public void update() {
096:                setEnabled(getTextEditor() != null);
097:            }
098:
099:            /**
100:             * Checks the editor's modifiable state. Returns <code>true</code> if the editor can be modified,
101:             * taking in account the possible editor extensions.
102:             *
103:             * <p>If the editor implements <code>ITextEditorExtension2</code>,
104:             * this method returns {@link ITextEditorExtension2#isEditorInputModifiable()};<br> else if the editor
105:             * implements <code>ITextEditorExtension</code>, it returns {@link ITextEditorExtension#isEditorInputReadOnly()};<br>
106:             * else, {@link ITextEditor#isEditable()} is returned, or <code>false</code> if the editor is <code>null</code>.</p>
107:             *
108:             * <p>There is only a difference to {@link #validateEditorInputState()} if the editor implements
109:             * <code>ITextEditorExtension2</code>.</p>
110:             *
111:             * @return <code>true</code> if a modifying action should be enabled, <code>false</code> otherwise
112:             * @since 3.0
113:             */
114:            protected boolean canModifyEditor() {
115:                ITextEditor editor = getTextEditor();
116:                if (editor instanceof  ITextEditorExtension2)
117:                    return ((ITextEditorExtension2) editor)
118:                            .isEditorInputModifiable();
119:                else if (editor instanceof  ITextEditorExtension)
120:                    return !((ITextEditorExtension) editor)
121:                            .isEditorInputReadOnly();
122:                else if (editor != null)
123:                    return editor.isEditable();
124:                else
125:                    return false;
126:            }
127:
128:            /**
129:             * Checks and validates the editor's modifiable state. Returns <code>true</code> if an action
130:             * can proceed modifying the editor's input, <code>false</code> if it should not.
131:             *
132:             * <p>If the editor implements <code>ITextEditorExtension2</code>,
133:             * this method returns {@link ITextEditorExtension2#validateEditorInputState()};<br> else if the editor
134:             * implements <code>ITextEditorExtension</code>, it returns {@link ITextEditorExtension#isEditorInputReadOnly()};<br>
135:             * else, {@link ITextEditor#isEditable()} is returned, or <code>false</code> if the editor is <code>null</code>.</p>
136:             *
137:             * <p>There is only a difference to {@link #canModifyEditor()} if the editor implements
138:             * <code>ITextEditorExtension2</code>.</p>
139:             *
140:             * @return <code>true</code> if a modifying action can proceed to modify the underlying document, <code>false</code> otherwise
141:             * @since 3.0
142:             */
143:            protected boolean validateEditorInputState() {
144:                ITextEditor editor = getTextEditor();
145:                if (editor instanceof  ITextEditorExtension2)
146:                    return ((ITextEditorExtension2) editor)
147:                            .validateEditorInputState();
148:                else if (editor instanceof  ITextEditorExtension)
149:                    return !((ITextEditorExtension) editor)
150:                            .isEditorInputReadOnly();
151:                else if (editor != null)
152:                    return editor.isEditable();
153:                else
154:                    return false;
155:            }
156:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.