KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > ui > internal > DetachedPlaceHolder


1 /*******************************************************************************
2  * Copyright (c) 2000, 2006 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.ui.internal;
12
13 import java.util.ArrayList JavaDoc;
14
15 import org.eclipse.swt.graphics.Rectangle;
16 import org.eclipse.ui.IMemento;
17
18 /**
19  * DetachedPlaceHolder is the placeholder for detached views.
20  *
21  */

22 public class DetachedPlaceHolder extends PartPlaceholder implements
23         ILayoutContainer {
24     ArrayList JavaDoc children = new ArrayList JavaDoc();
25
26     Rectangle bounds;
27
28     /**
29      * DetachedPlaceHolder constructor comment.
30      * @param id java.lang.String
31      * @param bounds the size of the placeholder
32      */

33     public DetachedPlaceHolder(String JavaDoc id, Rectangle bounds) {
34         super(id);
35         this.bounds = bounds;
36     }
37
38     /**
39      * Add a child to the container.
40      */

41     public void add(LayoutPart newPart) {
42         if (!(newPart instanceof PartPlaceholder)) {
43             return;
44         }
45         children.add(newPart);
46     }
47
48     /**
49      * Return true if the container allows its
50      * parts to show a border if they choose to,
51      * else false if the container does not want
52      * its parts to show a border.
53      * @return boolean
54      */

55     public boolean allowsBorder() {
56         return false;
57     }
58
59     public Rectangle getBounds() {
60         return bounds;
61     }
62
63     /**
64      * Returns a list of layout children.
65      */

66     public LayoutPart[] getChildren() {
67         LayoutPart result[] = new LayoutPart[children.size()];
68         children.toArray(result);
69         return result;
70     }
71
72     /**
73      * Remove a child from the container.
74      */

75     public void remove(LayoutPart part) {
76         children.remove(part);
77     }
78
79     /**
80      * Replace one child with another
81      */

82     public void replace(LayoutPart oldPart, LayoutPart newPart) {
83         remove(oldPart);
84         add(newPart);
85     }
86
87    
88     /**
89      * Restore the state from the memento.
90      * @param memento
91      */

92     public void restoreState(IMemento memento) {
93         // Read the bounds.
94
Integer JavaDoc bigInt;
95         bigInt = memento.getInteger(IWorkbenchConstants.TAG_X);
96         int x = bigInt.intValue();
97         bigInt = memento.getInteger(IWorkbenchConstants.TAG_Y);
98         int y = bigInt.intValue();
99         bigInt = memento.getInteger(IWorkbenchConstants.TAG_WIDTH);
100         int width = bigInt.intValue();
101         bigInt = memento.getInteger(IWorkbenchConstants.TAG_HEIGHT);
102         int height = bigInt.intValue();
103
104         bounds = new Rectangle(x, y, width, height);
105
106         // Restore the placeholders.
107
IMemento childrenMem[] = memento
108                 .getChildren(IWorkbenchConstants.TAG_VIEW);
109         for (int i = 0; i < childrenMem.length; i++) {
110             PartPlaceholder holder = new PartPlaceholder(childrenMem[i]
111                     .getString(IWorkbenchConstants.TAG_ID));
112             holder.setContainer(this);
113             children.add(holder);
114         }
115     }
116
117     /**
118      * Save state to the memento.
119      * @param memento
120      */

121     public void saveState(IMemento memento) {
122         // Save the bounds.
123
memento.putInteger(IWorkbenchConstants.TAG_X, bounds.x);
124         memento.putInteger(IWorkbenchConstants.TAG_Y, bounds.y);
125         memento.putInteger(IWorkbenchConstants.TAG_WIDTH, bounds.width);
126         memento.putInteger(IWorkbenchConstants.TAG_HEIGHT, bounds.height);
127
128         // Save the views.
129
for (int i = 0; i < children.size(); i++) {
130             IMemento childMem = memento
131                     .createChild(IWorkbenchConstants.TAG_VIEW);
132             LayoutPart child = (LayoutPart) children.get(i);
133             childMem.putString(IWorkbenchConstants.TAG_ID, child.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 }
152
Popular Tags