1 /*******************************************************************************
2  * Copyright (c) 2009 Avaloq Evolution AG, 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  *     Tom Eicher (Avaloq Evolution AG) - initial API and implementation
13  *******************************************************************************/
14 package org.eclipse.ui.texteditor;
15 
16 import java.util.ResourceBundle;
17 
18 import org.eclipse.jface.action.IAction;
19 
20 
21 /**
22  * This action toggles the block (aka column) selection mode.
23  *
24  * @since 3.5
25  */
26 final class BlockSelectionModeToggleAction extends TextEditorAction {
27 
28 	/**
29 	 * Construct the action and initialize its state.
30 	 *
31 	 * @param resourceBundle  the resource bundle to construct label and tooltip from
32 	 * @param prefix  the prefix to use for constructing resource bundle keys
33 	 * @param editor  the editor this action is associated with
34 	 */
BlockSelectionModeToggleAction(ResourceBundle resourceBundle, String prefix, ITextEditor editor)35 	public BlockSelectionModeToggleAction(ResourceBundle resourceBundle, String prefix, ITextEditor editor) {
36 		super(resourceBundle, prefix, editor, IAction.AS_CHECK_BOX);
37 	}
38 
39 	@Override
run()40 	public void run() {
41 		ITextEditor editor= getTextEditor();
42 		if (editor instanceof ITextEditorExtension5) {
43 			ITextEditorExtension5 ext5= (ITextEditorExtension5) editor;
44 			ext5.setBlockSelectionMode(!ext5.isBlockSelectionModeEnabled());
45 		}
46 		update(); // update in case anyone else has directly accessed the widget
47 	}
48 
49 	@Override
update()50 	public void update() {
51 		ITextEditor editor= getTextEditor();
52 		if (editor instanceof ITextEditorExtension5) {
53 			ITextEditorExtension5 ext5= (ITextEditorExtension5) editor;
54 			setEnabled(true);
55 			setChecked(ext5.isBlockSelectionModeEnabled());
56 			return;
57 		}
58 		setEnabled(false);
59 		setChecked(false);
60 	}
61 }
62