001: /*******************************************************************************
002: * Copyright (c) 2000, 2006 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.part;
011:
012: import java.util.ArrayList;
013: import java.util.Iterator;
014: import java.util.List;
015:
016: import org.eclipse.swt.SWT;
017: import org.eclipse.swt.events.SelectionAdapter;
018: import org.eclipse.swt.events.SelectionEvent;
019: import org.eclipse.swt.widgets.Composite;
020: import org.eclipse.swt.widgets.Control;
021: import org.eclipse.swt.widgets.TabFolder;
022:
023: /**
024: * Abstract superclass of all multi-page workbench editors.
025: * <p>
026: * This class should be subclassed by clients wishing to define new
027: * multi-page editor.
028: * </p>
029: * <p>
030: * Subclasses must implement the following methods:
031: * <ul>
032: * <li><code>createPartControl</code> - to create the view's controls </li>
033: * <li><code>setFocus</code> - to accept focus</li>
034: * <li><code>isDirty</code> - to decide whether a significant change has
035: * occurred</li>
036: * <li><code>doSave</code> - to save contents of editor</li>
037: * <li><code>doSaveAs</code> - to save contents of editor</li>
038: * </ul>
039: * </p>
040: * <p>
041: * Subclasses may extend or reimplement the following methods as required:
042: * <ul>
043: * <li><code>setInitializationData</code> - extend to provide additional
044: * initialization when editor extension is instantiated</li>
045: * <li><code>init(IEditorSite,IEditorInput)</code> - extend to provide
046: * additional initialization when editor is assigned its site</li>
047: * <li><code>isSaveOnCloseNeeded</code> - override to control saving</li>
048: * <li><code>isSaveAsAllowed</code> - override to control saving</li>
049: * <li><code>gotoMarker</code> - reimplement to make selections based on
050: * markers</li>
051: * <li><code>dispose</code> - extend to provide additional cleanup</li>
052: * <li><code>getAdapter</code> - reimplement to make their editor
053: * adaptable</li>
054: * </ul>
055: * </p>
056: *
057: * @deprecated Use the class <code>MultiPageEditorPart</code> instead
058: */
059: public abstract class MultiPageEditor extends EditorPart {
060: private List syncVector;
061:
062: private TabFolder tabFolder;
063:
064: /**
065: * Creates a new multi-page editor.
066: *
067: * @deprecated Use the class <code>MultiPageEditorPart</code> instead
068: */
069: public MultiPageEditor() {
070: super ();
071: }
072:
073: /**
074: * Adds a synchronized pagebook to this editor. Once added, the
075: * visible page of the pagebook and the visible page of the editor
076: * will be synchronized.
077: *
078: * @param pageBook the pagebook to add
079: */
080: protected void addSyncroPageBook(PageBook pageBook) {
081: // Add the page.
082: if (syncVector == null) {
083: syncVector = new ArrayList(1);
084: }
085: syncVector.add(pageBook);
086:
087: // Set the visible page.
088: syncPageBook(pageBook);
089: }
090:
091: /**
092: * The <code>MultiPageEditor</code> implementation of this <code>IWorkbenchPart</code>
093: * method creates a <code>TabFolder</code> control.
094: */
095: public void createPartControl(Composite parent) {
096: tabFolder = new TabFolder(parent, SWT.NONE);
097: tabFolder.addSelectionListener(new SelectionAdapter() {
098: public void widgetSelected(SelectionEvent e) {
099: sync();
100: }
101: });
102: }
103:
104: /**
105: * Returns this editor's workbook.
106: *
107: * @return the editor workbook
108: */
109: protected TabFolder getFolder() {
110: return tabFolder;
111: }
112:
113: /**
114: * Indicates that a page change has occurred. Updates the sync vector.
115: */
116: protected void onPageChange() {
117: if (syncVector != null) {
118: Iterator itr = syncVector.iterator();
119: while (itr.hasNext()) {
120: PageBook pageBook = (PageBook) itr.next();
121: syncPageBook(pageBook);
122: }
123: }
124: }
125:
126: /**
127: * Removes a synchronized pagebook from this editor.
128: *
129: * @param pageBook the pagebook to remove
130: * @see #addSyncroPageBook(PageBook)
131: */
132: protected void removeSyncroPageBook(PageBook pageBook) {
133: if (syncVector != null) {
134: syncVector.remove(pageBook);
135: }
136: pageBook.dispose();
137: }
138:
139: /**
140: * Synchronizes each registered pagebook with the editor page.
141: */
142: protected void sync() {
143: if (syncVector != null) {
144: Iterator itr = syncVector.iterator();
145: while (itr.hasNext()) {
146: PageBook pageBook = (PageBook) itr.next();
147: syncPageBook(pageBook);
148: }
149: }
150: }
151:
152: /**
153: * Sets the visible page of the given pagebook to be the same as
154: * the visible page of this editor.
155: *
156: * @param pageBook a pagebook to synchronize
157: */
158: protected void syncPageBook(PageBook pageBook) {
159: int pos = tabFolder.getSelectionIndex();
160: Control children[] = pageBook.getChildren();
161: int size = children.length;
162: if (pos < size) {
163: pageBook.showPage(children[pos]);
164: }
165: }
166: }
|