01: /*******************************************************************************
02: * Copyright (c) 2004, 2007 IBM Corporation and others.
03: * All rights reserved. This program and the accompanying materials
04: * are made available under the terms of the Eclipse Public License v1.0
05: * which accompanies this distribution, and is available at
06: * http://www.eclipse.org/legal/epl-v10.html
07: *
08: * Contributors:
09: * IBM Corporation - initial API and implementation
10: *******************************************************************************/package org.eclipse.ui.internal.presentations;
11:
12: import org.eclipse.jface.action.Action;
13: import org.eclipse.jface.preference.IPreferenceStore;
14: import org.eclipse.ui.internal.EditorPane;
15: import org.eclipse.ui.internal.IPreferenceConstants;
16: import org.eclipse.ui.internal.WorkbenchMessages;
17: import org.eclipse.ui.internal.WorkbenchPartReference;
18: import org.eclipse.ui.internal.WorkbenchPlugin;
19: import org.eclipse.ui.internal.tweaklets.TabBehaviour;
20: import org.eclipse.ui.internal.tweaklets.Tweaklets;
21:
22: public class SystemMenuPinEditor extends Action implements
23: 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
43: .getPartReference();
44:
45: ref.setPinned(!isChecked());
46: }
47:
48: public void update() {
49: if (editorPane == null) {
50: setEnabled(false);
51: return;
52: }
53:
54: WorkbenchPartReference ref = (WorkbenchPartReference) editorPane
55: .getPartReference();
56: setEnabled(true);
57: setChecked(ref.isPinned());
58: }
59:
60: public boolean shouldBeVisible() {
61: if (editorPane == null) {
62: return false;
63: }
64:
65: IPreferenceStore store = WorkbenchPlugin.getDefault()
66: .getPreferenceStore();
67: boolean reuseEditor = store
68: .getBoolean(IPreferenceConstants.REUSE_EDITORS_BOOLEAN)
69: | ((TabBehaviour) Tweaklets.get(TabBehaviour.KEY))
70: .alwaysShowPinAction();
71: return reuseEditor;
72: }
73:
74: }
|