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.internal;
011:
012: import java.util.ArrayList;
013:
014: import org.eclipse.swt.graphics.Rectangle;
015: import org.eclipse.ui.IMemento;
016:
017: /**
018: * DetachedPlaceHolder is the placeholder for detached views.
019: *
020: */
021: public class DetachedPlaceHolder extends PartPlaceholder implements
022: ILayoutContainer {
023: ArrayList children = new ArrayList();
024:
025: Rectangle bounds;
026:
027: /**
028: * DetachedPlaceHolder constructor comment.
029: * @param id java.lang.String
030: * @param bounds the size of the placeholder
031: */
032: public DetachedPlaceHolder(String id, Rectangle bounds) {
033: super (id);
034: this .bounds = bounds;
035: }
036:
037: /**
038: * Add a child to the container.
039: */
040: public void add(LayoutPart newPart) {
041: if (!(newPart instanceof PartPlaceholder)) {
042: return;
043: }
044: children.add(newPart);
045: }
046:
047: /**
048: * Return true if the container allows its
049: * parts to show a border if they choose to,
050: * else false if the container does not want
051: * its parts to show a border.
052: * @return boolean
053: */
054: public boolean allowsBorder() {
055: return false;
056: }
057:
058: public Rectangle getBounds() {
059: return bounds;
060: }
061:
062: /**
063: * Returns a list of layout children.
064: */
065: public LayoutPart[] getChildren() {
066: LayoutPart result[] = new LayoutPart[children.size()];
067: children.toArray(result);
068: return result;
069: }
070:
071: /**
072: * Remove a child from the container.
073: */
074: public void remove(LayoutPart part) {
075: children.remove(part);
076: }
077:
078: /**
079: * Replace one child with another
080: */
081: public void replace(LayoutPart oldPart, LayoutPart newPart) {
082: remove(oldPart);
083: add(newPart);
084: }
085:
086: /**
087: * Restore the state from the memento.
088: * @param memento
089: */
090: public void restoreState(IMemento memento) {
091: // Read the bounds.
092: Integer bigInt;
093: bigInt = memento.getInteger(IWorkbenchConstants.TAG_X);
094: int x = bigInt.intValue();
095: bigInt = memento.getInteger(IWorkbenchConstants.TAG_Y);
096: int y = bigInt.intValue();
097: bigInt = memento.getInteger(IWorkbenchConstants.TAG_WIDTH);
098: int width = bigInt.intValue();
099: bigInt = memento.getInteger(IWorkbenchConstants.TAG_HEIGHT);
100: int height = bigInt.intValue();
101:
102: bounds = new Rectangle(x, y, width, height);
103:
104: // Restore the placeholders.
105: IMemento childrenMem[] = memento
106: .getChildren(IWorkbenchConstants.TAG_VIEW);
107: for (int i = 0; i < childrenMem.length; i++) {
108: PartPlaceholder holder = new PartPlaceholder(childrenMem[i]
109: .getString(IWorkbenchConstants.TAG_ID));
110: holder.setContainer(this );
111: children.add(holder);
112: }
113: }
114:
115: /**
116: * Save state to the memento.
117: * @param memento
118: */
119: public void saveState(IMemento memento) {
120: // Save the bounds.
121: memento.putInteger(IWorkbenchConstants.TAG_X, bounds.x);
122: memento.putInteger(IWorkbenchConstants.TAG_Y, bounds.y);
123: memento.putInteger(IWorkbenchConstants.TAG_WIDTH, bounds.width);
124: memento.putInteger(IWorkbenchConstants.TAG_HEIGHT,
125: bounds.height);
126:
127: // Save the views.
128: for (int i = 0; i < children.size(); i++) {
129: IMemento childMem = memento
130: .createChild(IWorkbenchConstants.TAG_VIEW);
131: LayoutPart child = (LayoutPart) children.get(i);
132: childMem.putString(IWorkbenchConstants.TAG_ID, child
133: .getID());
134: }
135: }
136:
137: public void findSashes(LayoutPart part, PartPane.Sashes sashes) {
138: ILayoutContainer container = getContainer();
139:
140: if (container != null) {
141: container.findSashes(this , sashes);
142: }
143: }
144:
145: /* (non-Javadoc)
146: * @see org.eclipse.ui.internal.ILayoutContainer#allowsAutoFocus()
147: */
148: public boolean allowsAutoFocus() {
149: return false;
150: }
151: }
|