KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > ui > internal > presentations > util > LeftToRightTabOrder


1 /*******************************************************************************
2  * Copyright (c) 2004, 2005 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.presentations.util;
12
13 import java.util.Arrays JavaDoc;
14 import java.util.Iterator JavaDoc;
15 import java.util.List JavaDoc;
16
17 import org.eclipse.ui.IMemento;
18 import org.eclipse.ui.internal.IWorkbenchConstants;
19 import org.eclipse.ui.presentations.IPresentablePart;
20 import org.eclipse.ui.presentations.IPresentationSerializer;
21
22 /**
23  * @since 3.0
24  */

25 public class LeftToRightTabOrder extends TabOrder {
26
27     private IPresentablePartList list;
28     
29     public LeftToRightTabOrder(IPresentablePartList list) {
30         this.list = list;
31     }
32
33     /* (non-Javadoc)
34      * @see org.eclipse.ui.internal.presentations.util.TabOrder#add(org.eclipse.ui.presentations.IPresentablePart)
35      */

36     public void add(IPresentablePart newPart) {
37         list.insert(newPart, list.size());
38     }
39
40     /* (non-Javadoc)
41      * @see org.eclipse.ui.internal.presentations.util.TabOrder#addInitial(org.eclipse.ui.presentations.IPresentablePart)
42      */

43     public void addInitial(IPresentablePart newPart) {
44         add(newPart);
45     }
46
47     /* (non-Javadoc)
48      * @see org.eclipse.ui.internal.presentations.util.TabOrder#insert(org.eclipse.ui.presentations.IPresentablePart, int)
49      */

50     public void insert(IPresentablePart newPart, int index) {
51         list.insert(newPart, index);
52     }
53
54     /* (non-Javadoc)
55      * @see org.eclipse.ui.internal.presentations.util.TabOrder#remove(org.eclipse.ui.presentations.IPresentablePart)
56      */

57     public void remove(IPresentablePart removed) {
58         list.remove(removed);
59     }
60
61     /* (non-Javadoc)
62      * @see org.eclipse.ui.internal.presentations.util.TabOrder#select(org.eclipse.ui.presentations.IPresentablePart)
63      */

64     public void select(IPresentablePart selected) {
65         list.select(selected);
66     }
67
68     /* (non-Javadoc)
69      * @see org.eclipse.ui.internal.presentations.util.TabOrder#move(org.eclipse.ui.presentations.IPresentablePart, int)
70      */

71     public void move(IPresentablePart toMove, int newIndex) {
72         list.move(toMove, newIndex);
73     }
74     
75     
76     /* (non-Javadoc)
77      * @see org.eclipse.ui.internal.presentations.util.TabOrder#getPartList()
78      */

79     public IPresentablePart[] getPartList() {
80         return list.getPartList();
81     }
82     
83     /**
84      * Restores a presentation from a previously stored state
85      *
86      * @param serializer (not null)
87      * @param savedState (not null)
88      */

89     public void restoreState(IPresentationSerializer serializer,
90             IMemento savedState) {
91         IMemento[] parts = savedState.getChildren(IWorkbenchConstants.TAG_PART);
92
93         for (int idx = 0; idx < parts.length; idx++) {
94             String JavaDoc id = parts[idx].getString(IWorkbenchConstants.TAG_ID);
95
96             if (id != null) {
97                 IPresentablePart part = serializer.getPart(id);
98
99                 if (part != null) {
100                     addInitial(part);
101                 }
102             }
103         }
104     }
105
106     /* (non-Javadoc)
107      * @see org.eclipse.ui.presentations.StackPresentation#saveState(org.eclipse.ui.presentations.IPresentationSerializer, org.eclipse.ui.IMemento)
108      */

109     public void saveState(IPresentationSerializer context, IMemento memento) {
110
111         List JavaDoc parts = Arrays.asList(list.getPartList());
112
113         Iterator JavaDoc iter = parts.iterator();
114         while (iter.hasNext()) {
115             IPresentablePart next = (IPresentablePart) iter.next();
116
117             IMemento childMem = memento
118                     .createChild(IWorkbenchConstants.TAG_PART);
119             childMem.putString(IWorkbenchConstants.TAG_ID, context.getId(next));
120         }
121     }
122 }
123
Popular Tags