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;
24 * Groups the JDT folding actions.
28 public class FoldingActionGroup extends ActionGroup {
29 private ProjectionViewer fViewer;
31 private TextOperationAction fToggle;
32 private TextOperationAction fExpand;
33 private TextOperationAction fCollapse;
34 private TextOperationAction fExpandAll;
36 private IProjectionListener fProjectionListener;
39 * Creates a new projection action group for <code>editor</code>. If the
40 * supplied viewer is not an instance of <code>ProjectionViewer</code>, the
41 * action group is disabled.
43 * @param editor the text editor to operate on
44 * @param viewer the viewer of the editor
46 public FoldingActionGroup(ITextEditor editor, ITextViewer viewer) {
47 if (viewer instanceof ProjectionViewer) {
48 fViewer= (ProjectionViewer) viewer;
50 fProjectionListener= new IProjectionListener() {
52 public void projectionEnabled() {
56 public void projectionDisabled() {
61 fViewer.addProjectionListener(fProjectionListener);
63 fToggle= new TextOperationAction(ActionMessages.getResourceBundle(), "Projection.Toggle.", editor, ProjectionViewer.TOGGLE, true); //$NON-NLS-1$
64 fToggle.setChecked(true);
65 fToggle.setActionDefinitionId(IFoldingCommandIds.FOLDING_TOGGLE);
66 editor.setAction("FoldingToggle", fToggle); //$NON-NLS-1$
68 fExpandAll= new TextOperationAction(ActionMessages.getResourceBundle(), "Projection.ExpandAll.", editor, ProjectionViewer.EXPAND_ALL, true); //$NON-NLS-1$
69 fExpandAll.setActionDefinitionId(IFoldingCommandIds.FOLDING_EXPAND_ALL);
70 editor.setAction("FoldingExpandAll", fExpandAll); //$NON-NLS-1$
72 fExpand= new TextOperationAction(ActionMessages.getResourceBundle(), "Projection.Expand.", editor, ProjectionViewer.EXPAND, true); //$NON-NLS-1$
73 fExpand.setActionDefinitionId(IFoldingCommandIds.FOLDING_EXPAND);
74 editor.setAction("FoldingExpand", fExpand); //$NON-NLS-1$
76 fCollapse= new TextOperationAction(ActionMessages.getResourceBundle(), "Projection.Collapse.", editor, ProjectionViewer.COLLAPSE, true); //$NON-NLS-1$
77 fCollapse.setActionDefinitionId(IFoldingCommandIds.FOLDING_COLLAPSE);
78 editor.setAction("FoldingCollapse", fCollapse); //$NON-NLS-1$
83 * Returns <code>true</code> if the group is enabled.
85 * Invariant: isEnabled() <=> fViewer and all actions are != null.
88 * @return <code>true</code> if the group is enabled
90 protected boolean isEnabled() {
91 return fViewer != null;
95 * @see org.eclipse.ui.actions.ActionGroup#dispose()
97 public void dispose() {
99 fViewer.removeProjectionListener(fProjectionListener);
106 * Updates the actions.
108 protected void update() {
111 fToggle.setChecked(fViewer.getProjectionAnnotationModel() != null);
119 * Fills the menu with all folding actions.
121 * @param manager the menu manager for the folding submenu
123 public void fillMenu(IMenuManager manager) {
126 manager.add(fToggle);
127 manager.add(fExpandAll);
128 manager.add(fExpand);
129 manager.add(fCollapse);
134 * @see org.eclipse.ui.actions.ActionGroup#updateActionBars()
136 public void updateActionBars() {