1 /******************************************************************************* 2 * Copyright (c) 2000, 2008 IBM Corporation and others. 3 * 4 * This program and the accompanying materials 5 * are made available under the terms of the Eclipse Public License 2.0 6 * which accompanies this distribution, and is available at 7 * https://www.eclipse.org/legal/epl-2.0/ 8 * 9 * SPDX-License-Identifier: EPL-2.0 10 * 11 * Contributors: 12 * IBM Corporation - initial API and implementation 13 *******************************************************************************/ 14 package org.eclipse.ui.examples.javaeditor; 15 16 17 import org.eclipse.ui.texteditor.ITextEditor; 18 import org.eclipse.ui.texteditor.TextEditorAction; 19 20 /** 21 * A toolbar action which toggles the presentation model of the 22 * connected text editor. The editor shows either the highlight range 23 * only or always the whole document. 24 */ 25 public class PresentationAction extends TextEditorAction { 26 27 /** 28 * Constructs and updates the action. 29 */ PresentationAction()30 public PresentationAction() { 31 super(JavaEditorMessages.getResourceBundle(), "TogglePresentation.", null); //$NON-NLS-1$ 32 update(); 33 } 34 35 @Override run()36 public void run() { 37 38 ITextEditor editor= getTextEditor(); 39 40 editor.resetHighlightRange(); 41 boolean show= editor.showsHighlightRangeOnly(); 42 setChecked(!show); 43 editor.showHighlightRangeOnly(!show); 44 } 45 46 @Override update()47 public void update() { 48 setChecked(getTextEditor() != null && getTextEditor().showsHighlightRangeOnly()); 49 setEnabled(true); 50 } 51 } 52