KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jdt > internal > ui > 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.jdt.internal.ui.actions;
12
13 import org.eclipse.jface.action.IAction;
14 import org.eclipse.jface.action.IMenuManager;
15
16 import org.eclipse.jface.text.source.IVerticalRulerInfo;
17 import org.eclipse.jface.text.source.projection.ProjectionAnnotationModel;
18 import org.eclipse.jface.text.source.projection.ProjectionViewer;
19
20 import org.eclipse.ui.IEditorPart;
21 import org.eclipse.ui.editors.text.IFoldingCommandIds;
22 import org.eclipse.ui.texteditor.AbstractRulerActionDelegate;
23 import org.eclipse.ui.texteditor.ITextEditor;
24 import org.eclipse.ui.texteditor.TextOperationAction;
25
26
27 /**
28  * Groups the folding actions.
29  *
30  * @since 3.0
31  */

32 public class FoldingToggleRulerAction extends AbstractRulerActionDelegate {
33
34     private IAction fUIAction;
35     private TextOperationAction fAction;
36     private ITextEditor fTextEditor;
37
38     /*
39      * @see org.eclipse.ui.texteditor.AbstractRulerActionDelegate#createAction(org.eclipse.ui.texteditor.ITextEditor, org.eclipse.jface.text.source.IVerticalRulerInfo)
40      */

41     protected IAction createAction(ITextEditor editor, IVerticalRulerInfo rulerInfo) {
42         fTextEditor= editor;
43         fAction= new TextOperationAction(FoldingMessages.getResourceBundle(), "Projection.Toggle.", editor, ProjectionViewer.TOGGLE, true); //$NON-NLS-1$
44
fAction.setActionDefinitionId(IFoldingCommandIds.FOLDING_TOGGLE);
45
46         return fAction;
47     }
48     
49     /*
50      * @see org.eclipse.ui.texteditor.AbstractRulerActionDelegate#setActiveEditor(org.eclipse.jface.action.IAction, org.eclipse.ui.IEditorPart)
51      */

52     public void setActiveEditor(IAction callerAction, IEditorPart targetEditor) {
53         fUIAction= callerAction;
54         super.setActiveEditor(callerAction, targetEditor);
55     }
56     
57     /*
58      * @see org.eclipse.ui.texteditor.AbstractRulerActionDelegate#menuAboutToShow(org.eclipse.jface.action.IMenuManager)
59      */

60     public void menuAboutToShow(IMenuManager manager) {
61         update();
62         super.menuAboutToShow(manager);
63     }
64     
65     private void update() {
66         if (fTextEditor != null) {
67             boolean enabled= fTextEditor.getAdapter(ProjectionAnnotationModel.class) != null;
68             fUIAction.setChecked(enabled);
69         }
70     }
71 }
72
Popular Tags