1 13 14 package org.eclipse.ui.internal; 15 16 import org.eclipse.core.runtime.Assert; 17 import org.eclipse.core.runtime.IStatus; 18 import org.eclipse.core.runtime.Status; 19 import org.eclipse.jface.action.IMenuManager; 20 import org.eclipse.swt.widgets.Control; 21 import org.eclipse.ui.IEditorReference; 22 import org.eclipse.ui.IMemento; 23 import org.eclipse.ui.PlatformUI; 24 import org.eclipse.ui.internal.presentations.PresentablePart; 25 import org.eclipse.ui.internal.presentations.PresentationFactoryUtil; 26 import org.eclipse.ui.internal.presentations.SystemMenuPinEditor; 27 import org.eclipse.ui.internal.presentations.SystemMenuSize; 28 import org.eclipse.ui.internal.presentations.UpdatingActionContributionItem; 29 import org.eclipse.ui.internal.presentations.util.TabbedStackPresentation; 30 import org.eclipse.ui.internal.util.Util; 31 import org.eclipse.ui.presentations.IPresentablePart; 32 import org.eclipse.ui.presentations.IStackPresentationSite; 33 import org.eclipse.ui.presentations.StackPresentation; 34 35 42 public class EditorStack extends PartStack { 43 44 private EditorSashContainer editorArea; 45 46 private WorkbenchPage page; 47 48 private SystemMenuSize sizeItem = new SystemMenuSize(null); 49 50 private SystemMenuPinEditor pinEditorItem = new SystemMenuPinEditor(null); 51 52 public EditorStack(EditorSashContainer editorArea, WorkbenchPage page) { 53 super(PresentationFactoryUtil.ROLE_EDITOR); 54 this.editorArea = editorArea; 55 setID(this.toString()); 56 this.page = page; 62 } 63 64 67 protected WorkbenchPage getPage() { 68 return page; 69 } 70 71 public void addSystemActions(IMenuManager menuManager) { 72 pinEditorItem = new SystemMenuPinEditor((EditorPane) getSelection()); 73 appendToGroupIfPossible(menuManager, 74 "misc", new UpdatingActionContributionItem(pinEditorItem)); sizeItem = new SystemMenuSize(getSelection()); 76 appendToGroupIfPossible(menuManager, "size", sizeItem); } 78 79 public boolean isMoveable(IPresentablePart part) { 80 return true; 81 } 82 83 86 public boolean supportsState(int state) { 87 if (page.isFixedLayout()) { 88 return false; 89 } 90 91 return true; 92 } 93 94 97 public static EditorStack newEditorWorkbook(EditorSashContainer editorArea, 98 WorkbenchPage page) { 99 return new EditorStack(editorArea, page); 100 } 101 102 protected void add(LayoutPart newChild, Object cookie) { 103 super.add(newChild, cookie); 104 105 ((EditorPane) newChild).setWorkbook(this); 106 } 107 108 111 public void add(LayoutPart child) { 112 super.add(child); 113 114 if (child instanceof EditorPane) { 115 ((EditorPane) child).setWorkbook(this); 116 } 117 } 118 119 protected void updateActions(PresentablePart current) { 120 EditorPane pane = null; 121 if (current != null && current.getPane() instanceof EditorPane) { 122 pane = (EditorPane) current.getPane(); 123 } 124 125 sizeItem.setPane(pane); 126 pinEditorItem.setPane(pane); 127 } 128 129 public Control[] getTabList() { 130 return getTabList(getSelection()); 131 } 132 133 public void removeAll() { 134 LayoutPart[] children = getChildren(); 135 136 for (int i = 0; i < children.length; i++) { 137 remove(children[i]); 138 } 139 } 140 141 public boolean isActiveWorkbook() { 142 EditorSashContainer area = getEditorArea(); 143 144 if (area != null) { 145 return area.isActiveWorkbook(this); 146 } else { 147 return false; 148 } 149 } 150 151 public void becomeActiveWorkbook(boolean hasFocus) { 152 EditorSashContainer area = getEditorArea(); 153 154 if (area != null) { 155 area.setActiveWorkbook(this, hasFocus); 156 } 157 } 158 159 public EditorPane[] getEditors() { 160 LayoutPart[] children = getChildren(); 161 162 EditorPane[] panes = new EditorPane[children.length]; 163 for (int idx = 0; idx < children.length; idx++) { 164 panes[idx] = (EditorPane) children[idx]; 165 } 166 167 return panes; 168 } 169 170 public EditorSashContainer getEditorArea() { 171 return editorArea; 172 } 173 174 177 protected boolean canMoveFolder() { 178 return true; 179 } 180 181 184 protected void derefPart(LayoutPart toDeref) { 185 EditorAreaHelper.derefPart(toDeref); 186 } 187 188 191 protected boolean allowsDrop(PartPane part) { 192 return part instanceof EditorPane; 193 } 194 195 public void setFocus() { 196 super.setFocus(); 197 becomeActiveWorkbook(true); 198 } 199 200 203 protected void close(IPresentablePart[] parts) { 204 205 if (parts.length == 1) { 206 close(parts[0]); 207 return; 208 } 209 210 IEditorReference[] toClose = new IEditorReference[parts.length]; 211 for (int idx = 0; idx < parts.length; idx++) { 212 EditorPane part = (EditorPane) getPaneFor(parts[idx]); 213 toClose[idx] = part.getEditorReference(); 214 } 215 216 WorkbenchPage page = getPage(); 217 218 if (page != null) { 219 page.closeEditors(toClose, true); 220 } 221 } 222 223 226 public void testInvariants() { 227 super.testInvariants(); 228 229 int active = getActive(); 230 231 if (active == StackPresentation.AS_ACTIVE_FOCUS) { 232 Assert.isTrue(isActiveWorkbook()); 233 } else if (active == StackPresentation.AS_ACTIVE_NOFOCUS) { 234 Assert.isTrue(isActiveWorkbook()); 235 } else if (active == StackPresentation.AS_INACTIVE) { 236 Assert.isTrue(!isActiveWorkbook()); 237 } 238 } 239 240 243 public IStatus restoreState(IMemento memento) { 244 Integer expanded = memento.getInteger(IWorkbenchConstants.TAG_EXPANDED); 245 setState((expanded == null || expanded.intValue() != IStackPresentationSite.STATE_MINIMIZED) ? IStackPresentationSite.STATE_RESTORED 246 : IStackPresentationSite.STATE_MINIMIZED); 247 248 Integer appearance = memento 249 .getInteger(IWorkbenchConstants.TAG_APPEARANCE); 250 if (appearance != null) { 251 this.appearance = appearance.intValue(); 252 } 253 254 savedPresentationState = null; 256 IMemento[] presentationMementos = memento 257 .getChildren(IWorkbenchConstants.TAG_PRESENTATION); 258 259 for (int idx = 0; idx < presentationMementos.length; idx++) { 260 IMemento child = presentationMementos[idx]; 261 262 String id = child.getString(IWorkbenchConstants.TAG_ID); 263 264 if (Util.equals(id, getFactory().getId())) { 265 savedPresentationState = child; 266 break; 267 } 268 } 269 270 return new Status(IStatus.OK, PlatformUI.PLUGIN_ID, 0, "", null); } 272 273 276 public IStatus saveState(IMemento memento) { 277 memento 278 .putInteger( 279 IWorkbenchConstants.TAG_EXPANDED, 280 (getPresentationSite().getState() == IStackPresentationSite.STATE_MINIMIZED) ? IStackPresentationSite.STATE_MINIMIZED 281 : IStackPresentationSite.STATE_RESTORED); 282 283 memento.putInteger(IWorkbenchConstants.TAG_APPEARANCE, appearance); 284 285 savePresentationState(); 286 287 if (savedPresentationState != null) { 288 IMemento presentationState = memento 289 .createChild(IWorkbenchConstants.TAG_PRESENTATION); 290 presentationState.putMemento(savedPresentationState); 291 } 292 293 return new Status(IStatus.OK, PlatformUI.PLUGIN_ID, 0, "", null); } 295 296 299 public void setMinimized(boolean minimized) { 300 Perspective persp = getPage().getActivePerspective(); 302 if (Perspective.useNewMinMax(persp)) { 303 if (minimized) { 304 persp.setEditorAreaState(IStackPresentationSite.STATE_MINIMIZED); 305 } 306 else { 307 if (persp.getPresentation().getMaximizedStack() != null) { 309 PartStack maxStack = persp.getPresentation().getMaximizedStack(); 310 if (maxStack instanceof ViewStack) { 311 maxStack.setState(IStackPresentationSite.STATE_RESTORED); 312 } 313 else if (maxStack instanceof EditorStack) { 314 persp.setEditorAreaState(IStackPresentationSite.STATE_RESTORED); 317 } 318 } 319 320 int curState = persp.getEditorAreaState(); 321 if (curState == IStackPresentationSite.STATE_MINIMIZED) 322 curState = IStackPresentationSite.STATE_RESTORED; 323 324 persp.setEditorAreaState(curState); 325 } 326 327 refreshPresentationState(); 328 } 330 331 super.setMinimized(minimized); 332 } 333 334 342 public void setStateLocal(int newState) { 343 if (newState == getState()) 344 return; 345 346 super.setMinimized(newState == IStackPresentationSite.STATE_MINIMIZED); 348 presentationSite.setPresentationState(newState); 349 } 350 351 359 public void showMinMax(boolean show) { 360 StackPresentation pres = getPresentation(); 361 if (pres == null) 362 return; 363 364 if (pres instanceof TabbedStackPresentation) 365 ((TabbedStackPresentation)pres).showMinMax(show); 366 } 367 } 368 | Popular Tags |