KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > ui > part > MultiPageEditor


1 /*******************************************************************************
2  * Copyright (c) 2000, 2006 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.part;
12
13 import java.util.ArrayList JavaDoc;
14 import java.util.Iterator JavaDoc;
15 import java.util.List JavaDoc;
16
17 import org.eclipse.swt.SWT;
18 import org.eclipse.swt.events.SelectionAdapter;
19 import org.eclipse.swt.events.SelectionEvent;
20 import org.eclipse.swt.widgets.Composite;
21 import org.eclipse.swt.widgets.Control;
22 import org.eclipse.swt.widgets.TabFolder;
23
24 /**
25  * Abstract superclass of all multi-page workbench editors.
26  * <p>
27  * This class should be subclassed by clients wishing to define new
28  * multi-page editor.
29  * </p>
30  * <p>
31  * Subclasses must implement the following methods:
32  * <ul>
33  * <li><code>createPartControl</code> - to create the view's controls </li>
34  * <li><code>setFocus</code> - to accept focus</li>
35  * <li><code>isDirty</code> - to decide whether a significant change has
36  * occurred</li>
37  * <li><code>doSave</code> - to save contents of editor</li>
38  * <li><code>doSaveAs</code> - to save contents of editor</li>
39  * </ul>
40  * </p>
41  * <p>
42  * Subclasses may extend or reimplement the following methods as required:
43  * <ul>
44  * <li><code>setInitializationData</code> - extend to provide additional
45  * initialization when editor extension is instantiated</li>
46  * <li><code>init(IEditorSite,IEditorInput)</code> - extend to provide
47  * additional initialization when editor is assigned its site</li>
48  * <li><code>isSaveOnCloseNeeded</code> - override to control saving</li>
49  * <li><code>isSaveAsAllowed</code> - override to control saving</li>
50  * <li><code>gotoMarker</code> - reimplement to make selections based on
51  * markers</li>
52  * <li><code>dispose</code> - extend to provide additional cleanup</li>
53  * <li><code>getAdapter</code> - reimplement to make their editor
54  * adaptable</li>
55  * </ul>
56  * </p>
57  *
58  * @deprecated Use the class <code>MultiPageEditorPart</code> instead
59  */

60 public abstract class MultiPageEditor extends EditorPart {
61     private List JavaDoc syncVector;
62
63     private TabFolder tabFolder;
64
65     /**
66      * Creates a new multi-page editor.
67      *
68      * @deprecated Use the class <code>MultiPageEditorPart</code> instead
69      */

70     public MultiPageEditor() {
71         super();
72     }
73
74     /**
75      * Adds a synchronized pagebook to this editor. Once added, the
76      * visible page of the pagebook and the visible page of the editor
77      * will be synchronized.
78      *
79      * @param pageBook the pagebook to add
80      */

81     protected void addSyncroPageBook(PageBook pageBook) {
82         // Add the page.
83
if (syncVector == null) {
84             syncVector = new ArrayList JavaDoc(1);
85         }
86         syncVector.add(pageBook);
87
88         // Set the visible page.
89
syncPageBook(pageBook);
90     }
91
92     /**
93      * The <code>MultiPageEditor</code> implementation of this <code>IWorkbenchPart</code>
94      * method creates a <code>TabFolder</code> control.
95      */

96     public void createPartControl(Composite parent) {
97         tabFolder = new TabFolder(parent, SWT.NONE);
98         tabFolder.addSelectionListener(new SelectionAdapter() {
99             public void widgetSelected(SelectionEvent e) {
100                 sync();
101             }
102         });
103     }
104
105     /**
106      * Returns this editor's workbook.
107      *
108      * @return the editor workbook
109      */

110     protected TabFolder getFolder() {
111         return tabFolder;
112     }
113
114     /**
115      * Indicates that a page change has occurred. Updates the sync vector.
116      */

117     protected void onPageChange() {
118         if (syncVector != null) {
119             Iterator JavaDoc itr = syncVector.iterator();
120             while (itr.hasNext()) {
121                 PageBook pageBook = (PageBook) itr.next();
122                 syncPageBook(pageBook);
123             }
124         }
125     }
126
127     /**
128      * Removes a synchronized pagebook from this editor.
129      *
130      * @param pageBook the pagebook to remove
131      * @see #addSyncroPageBook(PageBook)
132      */

133     protected void removeSyncroPageBook(PageBook pageBook) {
134         if (syncVector != null) {
135             syncVector.remove(pageBook);
136         }
137         pageBook.dispose();
138     }
139
140     /**
141      * Synchronizes each registered pagebook with the editor page.
142      */

143     protected void sync() {
144         if (syncVector != null) {
145             Iterator JavaDoc itr = syncVector.iterator();
146             while (itr.hasNext()) {
147                 PageBook pageBook = (PageBook) itr.next();
148                 syncPageBook(pageBook);
149             }
150         }
151     }
152
153     /**
154      * Sets the visible page of the given pagebook to be the same as
155      * the visible page of this editor.
156      *
157      * @param pageBook a pagebook to synchronize
158      */

159     protected void syncPageBook(PageBook pageBook) {
160         int pos = tabFolder.getSelectionIndex();
161         Control children[] = pageBook.getChildren();
162         int size = children.length;
163         if (pos < size) {
164             pageBook.showPage(children[pos]);
165         }
166     }
167 }
168
Popular Tags