KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > ui > internal > presentations > SystemMenuPinEditor


1 /*******************************************************************************
2  * Copyright (c) 2004, 2007 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.ui.internal.presentations;
12
13 import org.eclipse.jface.action.Action;
14 import org.eclipse.jface.preference.IPreferenceStore;
15 import org.eclipse.ui.internal.EditorPane;
16 import org.eclipse.ui.internal.IPreferenceConstants;
17 import org.eclipse.ui.internal.WorkbenchMessages;
18 import org.eclipse.ui.internal.WorkbenchPartReference;
19 import org.eclipse.ui.internal.WorkbenchPlugin;
20 import org.eclipse.ui.internal.tweaklets.TabBehaviour;
21 import org.eclipse.ui.internal.tweaklets.Tweaklets;
22
23 public class SystemMenuPinEditor extends Action implements ISelfUpdatingAction {
24
25     private EditorPane editorPane;
26
27     public SystemMenuPinEditor(EditorPane pane) {
28         setText(WorkbenchMessages.EditorPane_pinEditor);
29         setPane(pane);
30     }
31
32     public void dispose() {
33         editorPane = null;
34     }
35
36     public void setPane(EditorPane pane) {
37         editorPane = pane;
38         update();
39     }
40
41     public void run() {
42         WorkbenchPartReference ref = (WorkbenchPartReference)editorPane.getPartReference();
43
44         ref.setPinned(!isChecked());
45     }
46
47     public void update() {
48         if (editorPane == null) {
49             setEnabled(false);
50             return;
51         }
52
53         WorkbenchPartReference ref = (WorkbenchPartReference)editorPane.getPartReference();
54         setEnabled(true);
55         setChecked(ref.isPinned());
56     }
57
58     public boolean shouldBeVisible() {
59         if (editorPane == null) {
60             return false;
61         }
62
63         IPreferenceStore store = WorkbenchPlugin.getDefault().getPreferenceStore();
64         boolean reuseEditor = store
65                 .getBoolean(IPreferenceConstants.REUSE_EDITORS_BOOLEAN)
66                 | ((TabBehaviour)Tweaklets.get(TabBehaviour.KEY)).alwaysShowPinAction();
67         return reuseEditor;
68     }
69
70 }
71
Popular Tags