1 /*******************************************************************************
2 * Copyright (c) 2000, 2003 IBM Corporation and others.
3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the Common Public License v1.0
5 * which accompanies this distribution, and is available at
6 * http://www.eclipse.org/legal/cpl-v10.html
9 * IBM Corporation - initial API and implementation
10 *******************************************************************************/
11 package net.sourceforge.phpdt.internal.ui.actions;
13 import org.eclipse.jface.action.IMenuManager;
14 import org.eclipse.jface.text.ITextViewer;
15 import org.eclipse.jface.text.source.projection.IProjectionListener;
16 import org.eclipse.jface.text.source.projection.ProjectionViewer;
17 import org.eclipse.ui.actions.ActionGroup;
18 import org.eclipse.ui.editors.text.IFoldingCommandIds;
19 import org.eclipse.ui.texteditor.ITextEditor;
20 import org.eclipse.ui.texteditor.TextOperationAction;
23 * Groups the JDT folding actions.
27 public class FoldingActionGroup extends ActionGroup {
28 private ProjectionViewer fViewer;
30 private TextOperationAction fToggle;
32 private TextOperationAction fExpand;
34 private TextOperationAction fCollapse;
36 private TextOperationAction fExpandAll;
38 private IProjectionListener fProjectionListener;
41 * Creates a new projection action group for <code>editor</code>. If the
42 * supplied viewer is not an instance of <code>ProjectionViewer</code>,
43 * the action group is disabled.
46 * the text editor to operate on
48 * the viewer of the editor
50 public FoldingActionGroup(ITextEditor editor, ITextViewer viewer) {
51 if (viewer instanceof ProjectionViewer) {
52 fViewer = (ProjectionViewer) viewer;
54 fProjectionListener = new IProjectionListener() {
56 public void projectionEnabled() {
60 public void projectionDisabled() {
65 fViewer.addProjectionListener(fProjectionListener);
67 fToggle = new TextOperationAction(ActionMessages
69 "Projection.Toggle.", editor, ProjectionViewer.TOGGLE, true); //$NON-NLS-1$
70 fToggle.setChecked(true);
71 fToggle.setActionDefinitionId(IFoldingCommandIds.FOLDING_TOGGLE);
72 editor.setAction("FoldingToggle", fToggle); //$NON-NLS-1$
74 fExpandAll = new TextOperationAction(
75 ActionMessages.getResourceBundle(),
76 "Projection.ExpandAll.", editor, ProjectionViewer.EXPAND_ALL, true); //$NON-NLS-1$
78 .setActionDefinitionId(IFoldingCommandIds.FOLDING_EXPAND_ALL);
79 editor.setAction("FoldingExpandAll", fExpandAll); //$NON-NLS-1$
81 fExpand = new TextOperationAction(ActionMessages
83 "Projection.Expand.", editor, ProjectionViewer.EXPAND, true); //$NON-NLS-1$
84 fExpand.setActionDefinitionId(IFoldingCommandIds.FOLDING_EXPAND);
85 editor.setAction("FoldingExpand", fExpand); //$NON-NLS-1$
87 fCollapse = new TextOperationAction(
88 ActionMessages.getResourceBundle(),
89 "Projection.Collapse.", editor, ProjectionViewer.COLLAPSE, true); //$NON-NLS-1$
91 .setActionDefinitionId(IFoldingCommandIds.FOLDING_COLLAPSE);
92 editor.setAction("FoldingCollapse", fCollapse); //$NON-NLS-1$
97 * Returns <code>true</code> if the group is enabled.
100 * Invariant: isEnabled() <=> fViewer and all actions are != null.
103 * @return <code>true</code> if the group is enabled
105 private boolean isEnabled() {
106 return fViewer != null;
110 * @see org.eclipse.ui.actions.ActionGroup#dispose()
112 public void dispose() {
114 fViewer.removeProjectionListener(fProjectionListener);
121 * Updates the actions.
123 protected void update() {
126 fToggle.setChecked(fViewer.getProjectionAnnotationModel() != null);
134 * Fills the menu with all folding actions.
137 * the menu manager for the folding submenu
139 public void fillMenu(IMenuManager manager) {
142 manager.add(fToggle);
143 manager.add(fExpandAll);
144 manager.add(fExpand);
145 manager.add(fCollapse);
150 * @see org.eclipse.ui.actions.ActionGroup#updateActionBars()
152 public void updateActionBars() {