1 11 package org.eclipse.ui.internal; 12 13 import java.util.HashMap ; 14 import java.util.Map ; 15 16 import org.eclipse.core.runtime.IStatus; 17 import org.eclipse.core.runtime.MultiStatus; 18 import org.eclipse.swt.widgets.Composite; 19 import org.eclipse.swt.widgets.Control; 20 import org.eclipse.ui.IMemento; 21 import org.eclipse.ui.PlatformUI; 22 import org.eclipse.ui.internal.StartupThreading.StartupRunnable; 23 24 27 public class ViewSashContainer extends PartSashContainer { 28 public ViewSashContainer(WorkbenchPage page, Composite parent) { 29 super("root layout container", page, parent); } 31 32 35 public ViewSashContainer getRootContainer() { 36 return this; 37 } 38 39 44 protected Composite createParent(Composite parentWidget) { 45 return parentWidget; 46 } 47 48 52 protected void disposeParent() { 53 } 55 56 59 public Control getControl() { 60 return this.parent; 61 } 62 63 66 public IStatus restoreState(IMemento memento) { 67 MultiStatus result = new MultiStatus( 68 PlatformUI.PLUGIN_ID, 69 IStatus.OK, 70 WorkbenchMessages.RootLayoutContainer_problemsRestoringPerspective, null); 71 72 IMemento[] children = memento.getChildren(IWorkbenchConstants.TAG_INFO); 74 75 final Map mapIDtoPart = new HashMap (children.length); 77 78 for (int i = 0; i < children.length; i++) { 80 IMemento childMem = children[i]; 82 String partID = childMem.getString(IWorkbenchConstants.TAG_PART); 83 final String relativeID = childMem 84 .getString(IWorkbenchConstants.TAG_RELATIVE); 85 int relationship = 0; 86 float ratio = 0.0f; 87 int left = 0, right = 0; 88 if (relativeID != null) { 89 relationship = childMem.getInteger( 90 IWorkbenchConstants.TAG_RELATIONSHIP).intValue(); 91 92 Float ratioFloat = childMem 95 .getFloat(IWorkbenchConstants.TAG_RATIO); 96 Integer leftInt = childMem 97 .getInteger(IWorkbenchConstants.TAG_RATIO_LEFT); 98 Integer rightInt = childMem 99 .getInteger(IWorkbenchConstants.TAG_RATIO_RIGHT); 100 if (leftInt != null && rightInt != null) { 101 left = leftInt.intValue(); 102 right = rightInt.intValue(); 103 } else { 104 if (ratioFloat != null) { 105 ratio = ratioFloat.floatValue(); 106 } 107 } 108 } 109 String strFolder = childMem 110 .getString(IWorkbenchConstants.TAG_FOLDER); 111 112 LayoutPart part = null; 114 if (strFolder == null) { 115 part = new PartPlaceholder(partID); 116 } else { 117 ViewStack folder = new ViewStack(page); 118 folder.setID(partID); 119 result.add(folder.restoreState(childMem 120 .getChild(IWorkbenchConstants.TAG_FOLDER))); 121 ContainerPlaceholder placeholder = new ContainerPlaceholder( 122 partID); 123 placeholder.setRealContainer(folder); 124 part = placeholder; 125 } 126 part.setContainer(this); 128 129 final int myLeft = left, myRight= right, myRelationship = relationship; 130 final float myRatio = ratio; 131 final LayoutPart myPart = part; 132 133 StartupThreading.runWithoutExceptions(new StartupRunnable() { 134 135 public void runWithException() throws Throwable { 136 if (relativeID == null) { 138 add(myPart); 139 } else { 140 LayoutPart refPart = (LayoutPart) mapIDtoPart.get(relativeID); 141 if (refPart != null) { 142 if (myLeft != 0) { 143 add(myPart, myRelationship, myLeft, myRight, refPart); 144 } else { 145 add(myPart, myRelationship, myRatio, refPart); 146 } 147 } else { 148 WorkbenchPlugin 149 .log("Unable to find part for ID: " + relativeID); } 151 } 152 }}); 153 154 mapIDtoPart.put(partID, part); 155 } 156 return result; 157 } 158 159 162 public IStatus saveState(IMemento memento) { 163 RelationshipInfo[] relationships = computeRelation(); 164 165 MultiStatus result = new MultiStatus( 166 PlatformUI.PLUGIN_ID, 167 IStatus.OK, 168 WorkbenchMessages.RootLayoutContainer_problemsSavingPerspective, null); 169 170 for (int i = 0; i < relationships.length; i++) { 172 RelationshipInfo info = relationships[i]; 178 IMemento childMem = memento 179 .createChild(IWorkbenchConstants.TAG_INFO); 180 childMem.putString(IWorkbenchConstants.TAG_PART, info.part.getID()); 181 if (info.relative != null) { 182 childMem.putString(IWorkbenchConstants.TAG_RELATIVE, 183 info.relative.getID()); 184 childMem.putInteger(IWorkbenchConstants.TAG_RELATIONSHIP, 185 info.relationship); 186 childMem.putInteger(IWorkbenchConstants.TAG_RATIO_LEFT, 187 info.left); 188 childMem.putInteger(IWorkbenchConstants.TAG_RATIO_RIGHT, 189 info.right); 190 191 childMem.putFloat(IWorkbenchConstants.TAG_RATIO, info 195 .getRatio()); 196 } 197 198 ViewStack folder = null; 200 if (info.part instanceof ViewStack) { 201 folder = (ViewStack) info.part; 202 } else if (info.part instanceof ContainerPlaceholder) { 203 LayoutPart part = ((ContainerPlaceholder) info.part) 204 .getRealContainer(); 205 if (part instanceof ViewStack) { 206 folder = (ViewStack) part; 207 } 208 } 209 210 if (folder != null) { 212 childMem.putString(IWorkbenchConstants.TAG_FOLDER, "true"); 214 IMemento folderMem = childMem 215 .createChild(IWorkbenchConstants.TAG_FOLDER); 216 result.add(folder.saveState(folderMem)); 217 } 218 } 219 return result; 220 } 221 222 225 protected float getDockingRatio(LayoutPart dragged, LayoutPart target) { 226 if (isStackType(target)) { 227 return super.getDockingRatio(dragged, target); 228 } else { 229 return 0.25f; 230 } 231 } 232 233 236 public boolean isStackType(LayoutPart toTest) { 237 return (toTest instanceof ViewStack); 238 } 239 240 243 public boolean isPaneType(LayoutPart toTest) { 244 return (toTest instanceof ViewPane); 245 } 246 247 250 protected PartStack createStack() { 251 ViewStack result = new ViewStack(page); 252 return result; 253 } 254 255 258 protected void setVisiblePart(ILayoutContainer container, 259 LayoutPart visiblePart) { 260 if (container instanceof ViewStack) { 261 ViewStack tabFolder = (ViewStack) container; 262 263 tabFolder.setSelection(visiblePart); 264 } 265 } 266 267 270 protected LayoutPart getVisiblePart(ILayoutContainer container) { 271 return ((ViewStack) container).getSelection(); 272 } 273 274 277 protected void derefPart(LayoutPart sourcePart) { 278 page.getActivePerspective().getPresentation().derefPart(sourcePart); 279 } 280 281 284 protected void addChild(RelationshipInfo info) { 285 LayoutPart child = info.part; 286 287 if (child instanceof ViewPane) { 291 ViewStack folder = new ViewStack(page); 292 folder.add(child); 293 info.part = folder; 294 } 295 296 super.addChild(info); 297 } 298 299 302 public void replace(LayoutPart oldChild, LayoutPart newChild) { 303 if (!isChild(oldChild)) { 304 return; 305 } 306 307 if (newChild instanceof ViewPane) { 311 ViewStack folder = new ViewStack(page); 312 folder.add(newChild); 313 newChild = folder; 314 } 315 316 super.replace(oldChild, newChild); 317 } 318 } 319 | Popular Tags |