Source Code Cross Referenced for ShiftAction.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.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:         * Action for shifting code to the right or left by one indentation level.
024:         * @since 2.0
025:         */
026:        public class ShiftAction extends TextEditorAction implements 
027:                IReadOnlyDependent {
028:
029:            /** The text operation code */
030:            private int fOperationCode = -1;
031:            /** The text operation target */
032:            private ITextOperationTarget fOperationTarget;
033:
034:            /**
035:             * Creates and initializes the action for the given text editor and operation
036:             * code. The action configures its visual representation from the given resource
037:             * bundle. The action works by asking the text editor at the time for its
038:             * text operation target adapter (using
039:             * <code>getAdapter(ITextOperationTarget.class)</code>. The action runs that
040:             * operation with the given opcode.
041:             *
042:             * @param bundle the resource bundle
043:             * @param prefix a prefix to be prepended to the various resource keys
044:             *   (described in <code>ResourceAction</code> constructor), or  <code>null</code> if none
045:             * @param editor the text editor
046:             * @param operationCode the operation code
047:             * @see TextEditorAction#TextEditorAction(ResourceBundle, String, ITextEditor)
048:             */
049:            public ShiftAction(ResourceBundle bundle, String prefix,
050:                    ITextEditor editor, int operationCode) {
051:                super (bundle, prefix, editor);
052:                fOperationCode = operationCode;
053:                update();
054:            }
055:
056:            /**
057:             * The <code>TextOperationAction</code> implementation of this
058:             * <code>IAction</code> method runs the operation with the current
059:             * operation code.
060:             */
061:            public void run() {
062:                if (fOperationCode == -1 || fOperationTarget == null)
063:                    return;
064:
065:                ITextEditor editor = getTextEditor();
066:                if (editor == null)
067:                    return;
068:
069:                if (!validateEditorInputState())
070:                    return;
071:
072:                Display display = null;
073:
074:                IWorkbenchPartSite site = editor.getSite();
075:                Shell shell = site.getShell();
076:                if (shell != null && !shell.isDisposed())
077:                    display = shell.getDisplay();
078:
079:                BusyIndicator.showWhile(display, new Runnable() {
080:                    public void run() {
081:                        fOperationTarget.doOperation(fOperationCode);
082:                    }
083:                });
084:            }
085:
086:            /*
087:             * @see IUpdate#update()
088:             */
089:            public void update() {
090:                super .update();
091:                if (!isEnabled())
092:                    return;
093:
094:                if (!canModifyEditor()) {
095:                    setEnabled(false);
096:                    return;
097:                }
098:
099:                ITextEditor editor = getTextEditor();
100:                if (fOperationTarget == null && editor != null
101:                        && fOperationCode != -1)
102:                    fOperationTarget = (ITextOperationTarget) editor
103:                            .getAdapter(ITextOperationTarget.class);
104:
105:            }
106:
107:            /**
108:             * Enablement when tab key is pressed - the current selection has to be cover multiple lines.
109:             *
110:             * @since 3.0
111:             */
112:            protected void updateForTab() {
113:                super .update();
114:
115:                if (isEnabled()) {
116:                    if (!canModifyEditor()) {
117:                        setEnabled(false);
118:                        return;
119:                    }
120:
121:                    ITextEditor editor = getTextEditor();
122:                    if (fOperationTarget == null && editor != null
123:                            && fOperationCode != -1)
124:                        fOperationTarget = (ITextOperationTarget) editor
125:                                .getAdapter(ITextOperationTarget.class);
126:
127:                    boolean isEnabled = (fOperationTarget != null && fOperationTarget
128:                            .canDoOperation(fOperationCode));
129:                    setEnabled(isEnabled);
130:                }
131:
132:            }
133:
134:            /*
135:             * @see TextEditorAction#setEditor(ITextEditor)
136:             */
137:            public void setEditor(ITextEditor editor) {
138:                super .setEditor(editor);
139:                fOperationTarget = null;
140:            }
141:
142:            /*
143:             * @see IReadOnlyDependent#isEnabled(boolean)
144:             */
145:            public boolean isEnabled(boolean isWritable) {
146:
147:                if (!isWritable)
148:                    return false;
149:
150:                /*
151:                 * Note that this implementation still honors the result returned by canDoOperation.
152:                 * I.e. if the viewer is set to read-only, this method still returns false.
153:                 * It covers the case in which the viewer is also writable.
154:                 *
155:                 */
156:                ITextEditor editor = getTextEditor();
157:                if (fOperationTarget == null && editor != null
158:                        && fOperationCode != -1)
159:                    fOperationTarget = (ITextOperationTarget) editor
160:                            .getAdapter(ITextOperationTarget.class);
161:
162:                return (fOperationTarget != null && fOperationTarget
163:                        .canDoOperation(fOperationCode));
164:            }
165:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.