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;
15 import org.eclipse.jface.text.ITextViewer;
16 import org.eclipse.jface.text.source.projection.IProjectionListener;
17 import org.eclipse.jface.text.source.projection.ProjectionViewer;
19 import org.eclipse.ui.actions.ActionGroup;
20 import org.eclipse.ui.editors.text.IFoldingCommandIds;
21 import org.eclipse.ui.texteditor.ITextEditor;
22 import org.eclipse.ui.texteditor.TextOperationAction;
26 * Groups the JDT folding actions.
30 public class FoldingActionGroup extends ActionGroup {
31 private ProjectionViewer fViewer;
33 private TextOperationAction fToggle;
34 private TextOperationAction fExpand;
35 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>, the
43 * action group is disabled.
45 * @param editor the text editor to operate on
46 * @param viewer the viewer of the editor
48 public FoldingActionGroup(ITextEditor editor, ITextViewer viewer) {
49 if (viewer instanceof ProjectionViewer) {
50 fViewer= (ProjectionViewer) viewer;
52 fProjectionListener= new IProjectionListener() {
54 public void projectionEnabled() {
58 public void projectionDisabled() {
63 fViewer.addProjectionListener(fProjectionListener);
65 fToggle= new TextOperationAction(ActionMessages.getResourceBundle(), "Projection.Toggle.", editor, ProjectionViewer.TOGGLE, true); //$NON-NLS-1$
66 fToggle.setChecked(true);
67 fToggle.setActionDefinitionId(IFoldingCommandIds.FOLDING_TOGGLE);
68 editor.setAction("FoldingToggle", fToggle); //$NON-NLS-1$
70 fExpandAll= new TextOperationAction(ActionMessages.getResourceBundle(), "Projection.ExpandAll.", editor, ProjectionViewer.EXPAND_ALL, true); //$NON-NLS-1$
71 fExpandAll.setActionDefinitionId(IFoldingCommandIds.FOLDING_EXPAND_ALL);
72 editor.setAction("FoldingExpandAll", fExpandAll); //$NON-NLS-1$
74 fExpand= new TextOperationAction(ActionMessages.getResourceBundle(), "Projection.Expand.", editor, ProjectionViewer.EXPAND, true); //$NON-NLS-1$
75 fExpand.setActionDefinitionId(IFoldingCommandIds.FOLDING_EXPAND);
76 editor.setAction("FoldingExpand", fExpand); //$NON-NLS-1$
78 fCollapse= new TextOperationAction(ActionMessages.getResourceBundle(), "Projection.Collapse.", editor, ProjectionViewer.COLLAPSE, true); //$NON-NLS-1$
79 fCollapse.setActionDefinitionId(IFoldingCommandIds.FOLDING_COLLAPSE);
80 editor.setAction("FoldingCollapse", fCollapse); //$NON-NLS-1$
85 * Returns <code>true</code> if the group is enabled.
87 * Invariant: isEnabled() <=> fViewer and all actions are != null.
90 * @return <code>true</code> if the group is enabled
92 protected boolean isEnabled() {
93 return fViewer != null;
97 * @see org.eclipse.ui.actions.ActionGroup#dispose()
99 public void dispose() {
101 fViewer.removeProjectionListener(fProjectionListener);
108 * Updates the actions.
110 protected void update() {
113 fToggle.setChecked(fViewer.getProjectionAnnotationModel() != null);
121 * Fills the menu with all folding actions.
123 * @param manager the menu manager for the folding submenu
125 public void fillMenu(IMenuManager manager) {
128 manager.add(fToggle);
129 manager.add(fExpandAll);
130 manager.add(fExpand);
131 manager.add(fCollapse);
136 * @see org.eclipse.ui.actions.ActionGroup#updateActionBars()
138 public void updateActionBars() {