Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
Copyright (c) 2010 Michael Clay and others. All rights reserved. This program and the accompanying materials are made available under the terms of the Eclipse Public License v1.0 which accompanies this distribution, and is available at http://www.eclipse.org/legal/epl-v10.html /
  
  package org.eclipse.xtext.ui.editor.folding;
 
 
 import  org.eclipse.jface.action.IAction;
 import  org.eclipse.jface.action.IMenuManager;
 import  org.eclipse.jface.text.ITextViewer;
 import  org.eclipse.jface.text.source.projection.IProjectionListener;
 import  org.eclipse.jface.text.source.projection.ProjectionViewer;
 import  org.eclipse.ui.actions.ActionGroup;
 import  org.eclipse.ui.editors.text.IFoldingCommandIds;
 import  org.eclipse.ui.texteditor.ITextEditor;
 import  org.eclipse.ui.texteditor.IUpdate;
 import  org.eclipse.ui.texteditor.ResourceAction;
 import  org.eclipse.ui.texteditor.TextEditorAction;
 import  org.eclipse.ui.texteditor.TextOperationAction;
Groups the Xtext folding actions. Initially copied from org.eclipse.jdt.internal.ui.actions.FoldingActionGroup

Author(s):
Michael Clay - Initial contribution and API
 
 public class FoldingActionGroup extends ActionGroup {
 
 	private static abstract class PreferenceAction extends ResourceAction implements IUpdate {
 		PreferenceAction(ResourceBundle bundleString prefixint style) {
 			super(bundleprefixstyle);
 		}
 	}
 
 	private class FoldingAction extends PreferenceAction {
 
 		FoldingAction(ResourceBundle bundleString prefix) {
 			super(bundleprefix, IAction.AS_PUSH_BUTTON);
 		}
 
 		public void update() {
 			setEnabled(FoldingActionGroup.this.isEnabled() && .isProjectionMode());
 		}
 
 	}
 
 	private ProjectionViewer viewer;
 	private final TextEditorAction toggle;
 	private final TextOperationAction expand;
 	private final TextOperationAction collapse;
 	private final TextOperationAction expandAll;
 	private final TextOperationAction collapseAll;
 	private final IProjectionListener projectionListener;
 
 	private final PreferenceAction restoreDefaults;

Creates a new projection action group for editor. If the supplied viewer is not an instance of ProjectionViewer, the action group is disabled.

Parameters:
editor the text editor to operate on
viewer the viewer of the editor
 
 	public FoldingActionGroup(final ITextEditor editor, ITextViewer viewer) {
 		if (!(viewer instanceof ProjectionViewer)) {
 			 = null;
 			 = null;
 			 = null;
 			 = null;
 			 = null;
 			 = null;
 			return;
 		}
 
 		this. = (ProjectionViewer) viewer;
 
 		 = new IProjectionListener() {
 
 			public void projectionEnabled() {
 				update();
 			}
 
 			public void projectionDisabled() {
 				update();
 			}
 		};
 
 		this..addProjectionListener();
		.setChecked(this..isProjectionMode());
		.setActionDefinitionId(IFoldingCommandIds.FOLDING_TOGGLE);
		editor.setAction("FoldingToggle"); //$NON-NLS-1$
		 = new TextOperationAction(FoldingMessages.getResourceBundle(),
				"Projection.ExpandAll."editor, ProjectionViewer.EXPAND_ALL, true); //$NON-NLS-1$
		.setActionDefinitionId(IFoldingCommandIds.FOLDING_EXPAND_ALL);
		editor.setAction("FoldingExpandAll"); //$NON-NLS-1$
		 = new TextOperationAction(FoldingMessages.getResourceBundle(),
				"Projection.CollapseAll."editor, ProjectionViewer.COLLAPSE_ALL, true); //$NON-NLS-1$
		.setActionDefinitionId(IFoldingCommandIds.FOLDING_COLLAPSE_ALL);
		editor.setAction("FoldingCollapseAll"); //$NON-NLS-1$
		 = new TextOperationAction(FoldingMessages.getResourceBundle(),
				"Projection.Expand."editor, ProjectionViewer.EXPAND, true); //$NON-NLS-1$
		.setActionDefinitionId(IFoldingCommandIds.FOLDING_EXPAND);
		editor.setAction("FoldingExpand"); //$NON-NLS-1$
		 = new TextOperationAction(FoldingMessages.getResourceBundle(),
				"Projection.Collapse."editor, ProjectionViewer.COLLAPSE, true); //$NON-NLS-1$
		.setActionDefinitionId(IFoldingCommandIds.FOLDING_COLLAPSE);
		editor.setAction("FoldingCollapse"); //$NON-NLS-1$
		 = new FoldingAction(FoldingMessages.getResourceBundle(), "Projection.Restore.") { //$NON-NLS-1$
			public void run() {
				if (editor instanceof XtextEditor) {
					XtextEditor xtextEditor = (XtextEditoreditor;
					xtextEditor.resetProjection();
				}
			}
		};
		.setActionDefinitionId(IFoldingCommandIds.FOLDING_RESTORE);
		editor.setAction("FoldingRestore"); //$NON-NLS-1$
	}

Since:
2.8
	protected TextEditorAction createToggleFoldingAction(ITextEditor editor) {
		return new TextOperationAction(FoldingMessages.getResourceBundle(), "Projection.Toggle."editor,
				ProjectionViewer.TOGGLE, true);
	}

Returns true if the group is enabled.
 Invariant: isEnabled() <=> fViewer and all actions are != null.
 

Returns:
true if the group is enabled
	protected boolean isEnabled() {
		return  != null;
	}
	/*
	 * @see org.eclipse.ui.actions.ActionGroup#dispose()
	 */
	public void dispose() {
		if (isEnabled()) {
			.removeProjectionListener();
			 = null;
		}
		super.dispose();
	}

Updates the actions.
	protected void update() {
		if (isEnabled()) {
			.update();
			.setChecked(.isProjectionMode());
			.update();
			.update();
			.update();
			.update();
		}
	}

Fills the menu with all folding actions.

Parameters:
manager the menu manager for the folding submenu
	public void fillMenu(IMenuManager manager) {
		if (isEnabled()) {
			manager.add();
			manager.add();
			manager.add();
			manager.add();
			manager.add();
			manager.add();
		}
	}
	/*
	 * @see org.eclipse.ui.actions.ActionGroup#updateActionBars()
	 */
	public void updateActionBars() {
	}
New to GrepCode? Check out our FAQ X