KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > ui > internal > EditorPane


1 /*******************************************************************************
2  * Copyright (c) 2000, 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;
12
13 import org.eclipse.core.runtime.Assert;
14 import org.eclipse.jface.preference.IPreferenceStore;
15 import org.eclipse.swt.SWT;
16 import org.eclipse.swt.events.SelectionAdapter;
17 import org.eclipse.swt.events.SelectionEvent;
18 import org.eclipse.swt.widgets.Control;
19 import org.eclipse.swt.widgets.Menu;
20 import org.eclipse.swt.widgets.MenuItem;
21 import org.eclipse.ui.IEditorReference;
22 import org.eclipse.ui.IWorkbenchPart;
23 import org.eclipse.ui.internal.tweaklets.TabBehaviour;
24 import org.eclipse.ui.internal.tweaklets.Tweaklets;
25 import org.eclipse.ui.presentations.StackPresentation;
26
27 /**
28  * An EditorPane is a subclass of PartPane offering extended
29  * behavior for workbench editors.
30  */

31 public class EditorPane extends PartPane {
32     private EditorStack workbook;
33
34    
35     /**
36      * Constructs an editor pane for an editor part.
37      * @param ref
38      * @param page
39      * @param workbook
40      */

41     public EditorPane(IEditorReference ref, WorkbenchPage page,
42             EditorStack workbook) {
43         super(ref, page);
44         this.workbook = workbook;
45     }
46
47     /**
48      * Editor panes do not need a title bar. The editor
49      * title and close icon are part of the tab containing
50      * the editor. Tools and menus are added directly into
51      * the workbench toolbar and menu bar.
52      */

53     protected void createTitleBar() {
54         // do nothing
55
}
56
57     /**
58      * @see PartPane#doHide()
59      */

60     public void doHide() {
61         getPage().closeEditor(getEditorReference(), true);
62     }
63
64     /**
65      * Answer the editor part child.
66      * @return {@link IEditorReference}
67      */

68     public IEditorReference getEditorReference() {
69         return (IEditorReference) getPartReference();
70     }
71
72     /**
73      * Answer the SWT widget style.
74      */

75     int getStyle() {
76         return SWT.NONE;
77     }
78
79     /**
80      * Answer the editor workbook container
81      * @return {@link EditorStack}
82      */

83     public EditorStack getWorkbook() {
84         return workbook;
85     }
86
87     /**
88      * Notify the workbook page that the part pane has
89      * been activated by the user.
90      */

91     public void requestActivation() {
92         // By clearing the active workbook if its not the one
93
// associated with the editor, we reduce draw flicker
94
if (!workbook.isActiveWorkbook()) {
95             workbook.getEditorArea().setActiveWorkbook(null, false);
96         }
97
98         super.requestActivation();
99     }
100
101     /**
102      * Set the editor workbook container
103      * @param editorWorkbook
104      */

105     public void setWorkbook(EditorStack editorWorkbook) {
106         workbook = editorWorkbook;
107     }
108
109     /* (non-Javadoc)
110      * Method declared on PartPane.
111      */

112     /* package */void shellActivated() {
113         //this.workbook.drawGradient();
114
}
115
116     /* (non-Javadoc)
117      * Method declared on PartPane.
118      */

119     /* package */void shellDeactivated() {
120         //this.workbook.drawGradient();
121
}
122
123     /* (non-Javadoc)
124      * @see org.eclipse.ui.internal.LayoutPart#setFocus()
125      */

126     public void setFocus() {
127         super.setFocus();
128
129         workbook.becomeActiveWorkbook(true);
130     }
131
132     /**
133      * Indicate focus in part.
134      */

135     public void showFocus(boolean inFocus) {
136         if (inFocus) {
137             this.workbook.becomeActiveWorkbook(true);
138         } else {
139             this.workbook
140                     .setActive(this.workbook.isActiveWorkbook() ? StackPresentation.AS_ACTIVE_NOFOCUS
141                             : StackPresentation.AS_INACTIVE);
142         }
143     }
144
145     /**
146      * Add the pin menu item on the editor system menu.
147      * @param parent
148      */

149     protected void addPinEditorItem(Menu parent) {
150         IPreferenceStore store = WorkbenchPlugin.getDefault().getPreferenceStore();
151         boolean reuseEditor = store
152                 .getBoolean(IPreferenceConstants.REUSE_EDITORS_BOOLEAN)
153                 || ((TabBehaviour)Tweaklets.get(TabBehaviour.KEY)).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     /**
198      * Get the name of editor.
199      * @return String
200      */

201     public String JavaDoc getName() {
202         return null;
203     }
204
205     /* (non-Javadoc)
206      * @see org.eclipse.ui.internal.PartPane#getToolBar()
207      */

208     public Control getToolBar() {
209         return null;
210     }
211
212     /* (non-Javadoc)
213      * @see org.eclipse.ui.internal.PartPane#isCloseable()
214      */

215     public boolean isCloseable() {
216         return true;
217     }
218
219 }
220
Popular Tags