1 /* 2 * Created on Jan 19, 2004 3 * 4 * Copyright (C) 2004 Sean Ruff 5 * 6 * This program is free software; you can redistribute it and/or 7 * modify it under the terms of the GNU General Public License 8 * as published by the Free Software Foundation; either version 2 9 * of the License, or (at your option) any later version. 10 * 11 * This program is distributed in the hope that it will be useful, 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 * GNU General Public License for more details. 15 * 16 * You should have received a copy of the GNU General Public License 17 * along with this program; if not, write to the Free Software 18 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 19 */ 20 package org.un4gvn.editorviewer.internal.action; 21 22 import org.eclipse.jface.action.Action; 23 import org.eclipse.ui.IEditorPart; 24 import org.eclipse.ui.IWorkbenchPage; 25 import org.eclipse.ui.IWorkbenchWindow; 26 import org.un4gvn.editorviewer.internal.EditorViewerPlugin; 27 import org.un4gvn.editorviewer.internal.Messages; 28 import org.un4gvn.editorviewer.internal.element.IViewerElement; 29 import org.un4gvn.editorviewer.internal.ui.EditorViewer; 30 31 /*** 32 * Action to link/unlink the view selection with the Active Editor 33 * <p> 34 * @author Sean Ruff 35 */ 36 37 public class LinkEditorAction extends Action { 38 39 /*** 40 * EditorViewer for callbacks 41 */ 42 private EditorViewer _viewer = null; 43 44 /*** 45 * Linked/Unlinked mode 46 */ 47 private int _linkMode = EditorViewerPlugin.NON_LINKED_MODE; 48 49 /*** 50 * Constructor with the default specified linkMode 51 * @param viewer 52 * @param linkMode 53 */ 54 public LinkEditorAction(EditorViewer viewer, int linkMode){ 55 _linkMode = linkMode; 56 _viewer = viewer; 57 EditorViewerPlugin plugin = EditorViewerPlugin.getInstance(); 58 setImageDescriptor(plugin.getImageDescriptor(Messages.getString("LinkEditorAction.0"))); //$NON-NLS-1$ 59 setText(Messages.getString("LinkEditorAction.1")); //$NON-NLS-1$ 60 setToolTipText(Messages.getString("LinkEditorAction.2")); //$NON-NLS-1$ 61 setDescription(Messages.getString("LinkEditorAction.3")); //$NON-NLS-1$ 62 setChecked(_linkMode == EditorViewerPlugin.LINKED_MODE ? true : false); 63 } 64 65 /*** 66 * Link/unlink the View selection depending on the previous mode 67 */ 68 public void run(){ 69 setText(Messages.getString("LinkEditorAction.4")); //$NON-NLS-1$ 70 setToolTipText(Messages.getString("LinkEditorAction.5")); //$NON-NLS-1$ 71 setDescription(Messages.getString("LinkEditorAction.6")); //$NON-NLS-1$ 72 if ( isChecked() ){ 73 IWorkbenchWindow win = EditorViewerPlugin.getInstance().getActiveWindow(); 74 if ( win == null ) 75 return; 76 IWorkbenchPage page = win.getActivePage(); 77 if ( page == null ) 78 return; 79 IEditorPart part = page.getActiveEditor(); 80 if ( part == null ) 81 return; 82 IViewerElement element = _viewer.getElement(part); 83 _viewer.setSelection(new IViewerElement[]{element}); 84 } 85 } 86 87 }

This page was automatically generated by Maven