KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > ant > internal > ui > editor > actions > FoldingToggleRulerAction


1 /*******************************************************************************
2  * Copyright (c) 2000, 2005 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.ant.internal.ui.editor.actions;
12
13 import org.eclipse.ant.internal.ui.editor.AntEditor;
14 import org.eclipse.jface.action.IAction;
15 import org.eclipse.jface.action.IMenuManager;
16
17 import org.eclipse.jface.text.source.ISourceViewer;
18 import org.eclipse.jface.text.source.IVerticalRulerInfo;
19 import org.eclipse.jface.text.source.projection.ProjectionViewer;
20
21 import org.eclipse.ui.IEditorPart;
22 import org.eclipse.ui.editors.text.IFoldingCommandIds;
23 import org.eclipse.ui.texteditor.AbstractRulerActionDelegate;
24 import org.eclipse.ui.texteditor.ITextEditor;
25 import org.eclipse.ui.texteditor.TextOperationAction;
26
27 public class FoldingToggleRulerAction extends AbstractRulerActionDelegate {
28
29     private IAction fUIAction;
30     private TextOperationAction fAction;
31     private ITextEditor fTextEditor;
32
33     /* (non-Javadoc)
34      * @see org.eclipse.ui.texteditor.AbstractRulerActionDelegate#createAction(org.eclipse.ui.texteditor.ITextEditor, org.eclipse.jface.text.source.IVerticalRulerInfo)
35      */

36     protected IAction createAction(ITextEditor editor, IVerticalRulerInfo rulerInfo) {
37         fTextEditor= editor;
38         fAction= new TextOperationAction(AntEditorActionMessages.getResourceBundle(), "Projection.Toggle.", editor, ProjectionViewer.TOGGLE, true); //$NON-NLS-1$
39
fAction.setActionDefinitionId(IFoldingCommandIds.FOLDING_TOGGLE);
40
41         return fAction;
42     }
43     
44     /* (non-Javadoc)
45      * @see org.eclipse.ui.IEditorActionDelegate#setActiveEditor(org.eclipse.jface.action.IAction, org.eclipse.ui.IEditorPart)
46      */

47     public void setActiveEditor(IAction callerAction, IEditorPart targetEditor) {
48         fUIAction= callerAction;
49         super.setActiveEditor(callerAction, targetEditor);
50     }
51     
52     /* (non-Javadoc)
53      * @see org.eclipse.jface.action.IMenuListener#menuAboutToShow(org.eclipse.jface.action.IMenuManager)
54      */

55     public void menuAboutToShow(IMenuManager manager) {
56         update();
57         super.menuAboutToShow(manager);
58     }
59     
60     private void update() {
61         if (fTextEditor instanceof AntEditor) {
62             ISourceViewer viewer= ((AntEditor) fTextEditor).getViewer();
63             if (viewer instanceof ProjectionViewer) {
64                 boolean enabled= ((ProjectionViewer) viewer).getProjectionAnnotationModel() != null;
65                 fUIAction.setChecked(enabled);
66             }
67         }
68     }
69 }
70
Popular Tags