001: /*******************************************************************************
002: * Copyright (c) 2000, 2007 IBM Corporation and others.
003: * All rights reserved. This program and the accompanying materials
004: * are made available under the terms of the Eclipse Public License v1.0
005: * which accompanies this distribution, and is available at
006: * http://www.eclipse.org/legal/epl-v10.html
007: *
008: * Contributors:
009: * IBM Corporation - initial API and implementation
010: *******************************************************************************/package org.eclipse.ui.internal;
011:
012: import org.eclipse.core.runtime.Assert;
013: import org.eclipse.jface.preference.IPreferenceStore;
014: import org.eclipse.swt.SWT;
015: import org.eclipse.swt.events.SelectionAdapter;
016: import org.eclipse.swt.events.SelectionEvent;
017: import org.eclipse.swt.widgets.Control;
018: import org.eclipse.swt.widgets.Menu;
019: import org.eclipse.swt.widgets.MenuItem;
020: import org.eclipse.ui.IEditorReference;
021: import org.eclipse.ui.IWorkbenchPart;
022: import org.eclipse.ui.internal.tweaklets.TabBehaviour;
023: import org.eclipse.ui.internal.tweaklets.Tweaklets;
024: import org.eclipse.ui.presentations.StackPresentation;
025:
026: /**
027: * An EditorPane is a subclass of PartPane offering extended
028: * behavior for workbench editors.
029: */
030: public class EditorPane extends PartPane {
031: private EditorStack workbook;
032:
033: /**
034: * Constructs an editor pane for an editor part.
035: * @param ref
036: * @param page
037: * @param workbook
038: */
039: public EditorPane(IEditorReference ref, WorkbenchPage page,
040: EditorStack workbook) {
041: super (ref, page);
042: this .workbook = workbook;
043: }
044:
045: /**
046: * Editor panes do not need a title bar. The editor
047: * title and close icon are part of the tab containing
048: * the editor. Tools and menus are added directly into
049: * the workbench toolbar and menu bar.
050: */
051: protected void createTitleBar() {
052: // do nothing
053: }
054:
055: /**
056: * @see PartPane#doHide()
057: */
058: public void doHide() {
059: getPage().closeEditor(getEditorReference(), true);
060: }
061:
062: /**
063: * Answer the editor part child.
064: * @return {@link IEditorReference}
065: */
066: public IEditorReference getEditorReference() {
067: return (IEditorReference) getPartReference();
068: }
069:
070: /**
071: * Answer the SWT widget style.
072: */
073: int getStyle() {
074: return SWT.NONE;
075: }
076:
077: /**
078: * Answer the editor workbook container
079: * @return {@link EditorStack}
080: */
081: public EditorStack getWorkbook() {
082: return workbook;
083: }
084:
085: /**
086: * Notify the workbook page that the part pane has
087: * been activated by the user.
088: */
089: public void requestActivation() {
090: // By clearing the active workbook if its not the one
091: // associated with the editor, we reduce draw flicker
092: if (!workbook.isActiveWorkbook()) {
093: workbook.getEditorArea().setActiveWorkbook(null, false);
094: }
095:
096: super .requestActivation();
097: }
098:
099: /**
100: * Set the editor workbook container
101: * @param editorWorkbook
102: */
103: public void setWorkbook(EditorStack editorWorkbook) {
104: workbook = editorWorkbook;
105: }
106:
107: /* (non-Javadoc)
108: * Method declared on PartPane.
109: */
110: /* package */void shellActivated() {
111: //this.workbook.drawGradient();
112: }
113:
114: /* (non-Javadoc)
115: * Method declared on PartPane.
116: */
117: /* package */void shellDeactivated() {
118: //this.workbook.drawGradient();
119: }
120:
121: /* (non-Javadoc)
122: * @see org.eclipse.ui.internal.LayoutPart#setFocus()
123: */
124: public void setFocus() {
125: super .setFocus();
126:
127: workbook.becomeActiveWorkbook(true);
128: }
129:
130: /**
131: * Indicate focus in part.
132: */
133: public void showFocus(boolean inFocus) {
134: if (inFocus) {
135: this .workbook.becomeActiveWorkbook(true);
136: } else {
137: this .workbook
138: .setActive(this .workbook.isActiveWorkbook() ? StackPresentation.AS_ACTIVE_NOFOCUS
139: : StackPresentation.AS_INACTIVE);
140: }
141: }
142:
143: /**
144: * Add the pin menu item on the editor system menu.
145: * @param parent
146: */
147: protected void addPinEditorItem(Menu parent) {
148: IPreferenceStore store = WorkbenchPlugin.getDefault()
149: .getPreferenceStore();
150: boolean reuseEditor = store
151: .getBoolean(IPreferenceConstants.REUSE_EDITORS_BOOLEAN)
152: || ((TabBehaviour) Tweaklets.get(TabBehaviour.KEY))
153: .alwaysShowPinAction();
154: if (!reuseEditor) {
155: return;
156: }
157:
158: final WorkbenchPartReference ref = (WorkbenchPartReference) getPartReference();
159:
160: final MenuItem item = new MenuItem(parent, SWT.CHECK);
161: item.setText(WorkbenchMessages.EditorPane_pinEditor);
162: item.addSelectionListener(new SelectionAdapter() {
163: public void widgetSelected(SelectionEvent e) {
164: IWorkbenchPart part = getPartReference().getPart(true);
165: if (part == null) {
166: // this should never happen
167: item.setSelection(false);
168: item.setEnabled(false);
169: } else {
170: ref.setPinned(item.getSelection());
171: }
172: }
173: });
174: item.setEnabled(true);
175: item.setSelection(ref.isPinned());
176: }
177:
178: /**
179: * Update the title attributes for the pane.
180: */
181: public void updateTitles() {
182: // TODO commented during presentation refactor workbook.updateEditorTab(getEditorReference());
183: }
184:
185: /* (non-Javadoc)
186: * @see org.eclipse.ui.internal.LayoutPart#testInvariants()
187: */
188: public void testInvariants() {
189: super .testInvariants();
190:
191: if (getContainer() != null) {
192: Assert.isTrue(getContainer() == workbook);
193: }
194: }
195:
196: /**
197: * Get the name of editor.
198: * @return String
199: */
200: public String getName() {
201: return null;
202: }
203:
204: /* (non-Javadoc)
205: * @see org.eclipse.ui.internal.PartPane#getToolBar()
206: */
207: public Control getToolBar() {
208: return null;
209: }
210:
211: /* (non-Javadoc)
212: * @see org.eclipse.ui.internal.PartPane#isCloseable()
213: */
214: public boolean isCloseable() {
215: return true;
216: }
217:
218: }
|