1 11 package org.eclipse.ui.part; 12 13 import java.util.ArrayList ; 14 import java.util.Iterator ; 15 import java.util.List ; 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 60 public abstract class MultiPageEditor extends EditorPart { 61 private List syncVector; 62 63 private TabFolder tabFolder; 64 65 70 public MultiPageEditor() { 71 super(); 72 } 73 74 81 protected void addSyncroPageBook(PageBook pageBook) { 82 if (syncVector == null) { 84 syncVector = new ArrayList (1); 85 } 86 syncVector.add(pageBook); 87 88 syncPageBook(pageBook); 90 } 91 92 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 110 protected TabFolder getFolder() { 111 return tabFolder; 112 } 113 114 117 protected void onPageChange() { 118 if (syncVector != null) { 119 Iterator itr = syncVector.iterator(); 120 while (itr.hasNext()) { 121 PageBook pageBook = (PageBook) itr.next(); 122 syncPageBook(pageBook); 123 } 124 } 125 } 126 127 133 protected void removeSyncroPageBook(PageBook pageBook) { 134 if (syncVector != null) { 135 syncVector.remove(pageBook); 136 } 137 pageBook.dispose(); 138 } 139 140 143 protected void sync() { 144 if (syncVector != null) { 145 Iterator itr = syncVector.iterator(); 146 while (itr.hasNext()) { 147 PageBook pageBook = (PageBook) itr.next(); 148 syncPageBook(pageBook); 149 } 150 } 151 } 152 153 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 |