001: /*******************************************************************************
002: * Copyright (c) 2004, 2005 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.presentations.util;
011:
012: import java.util.Arrays;
013: import java.util.Iterator;
014: import java.util.List;
015:
016: import org.eclipse.ui.IMemento;
017: import org.eclipse.ui.internal.IWorkbenchConstants;
018: import org.eclipse.ui.presentations.IPresentablePart;
019: import org.eclipse.ui.presentations.IPresentationSerializer;
020:
021: /**
022: * @since 3.0
023: */
024: public class LeftToRightTabOrder extends TabOrder {
025:
026: private IPresentablePartList list;
027:
028: public LeftToRightTabOrder(IPresentablePartList list) {
029: this .list = list;
030: }
031:
032: /* (non-Javadoc)
033: * @see org.eclipse.ui.internal.presentations.util.TabOrder#add(org.eclipse.ui.presentations.IPresentablePart)
034: */
035: public void add(IPresentablePart newPart) {
036: list.insert(newPart, list.size());
037: }
038:
039: /* (non-Javadoc)
040: * @see org.eclipse.ui.internal.presentations.util.TabOrder#addInitial(org.eclipse.ui.presentations.IPresentablePart)
041: */
042: public void addInitial(IPresentablePart newPart) {
043: add(newPart);
044: }
045:
046: /* (non-Javadoc)
047: * @see org.eclipse.ui.internal.presentations.util.TabOrder#insert(org.eclipse.ui.presentations.IPresentablePart, int)
048: */
049: public void insert(IPresentablePart newPart, int index) {
050: list.insert(newPart, index);
051: }
052:
053: /* (non-Javadoc)
054: * @see org.eclipse.ui.internal.presentations.util.TabOrder#remove(org.eclipse.ui.presentations.IPresentablePart)
055: */
056: public void remove(IPresentablePart removed) {
057: list.remove(removed);
058: }
059:
060: /* (non-Javadoc)
061: * @see org.eclipse.ui.internal.presentations.util.TabOrder#select(org.eclipse.ui.presentations.IPresentablePart)
062: */
063: public void select(IPresentablePart selected) {
064: list.select(selected);
065: }
066:
067: /* (non-Javadoc)
068: * @see org.eclipse.ui.internal.presentations.util.TabOrder#move(org.eclipse.ui.presentations.IPresentablePart, int)
069: */
070: public void move(IPresentablePart toMove, int newIndex) {
071: list.move(toMove, newIndex);
072: }
073:
074: /* (non-Javadoc)
075: * @see org.eclipse.ui.internal.presentations.util.TabOrder#getPartList()
076: */
077: public IPresentablePart[] getPartList() {
078: return list.getPartList();
079: }
080:
081: /**
082: * Restores a presentation from a previously stored state
083: *
084: * @param serializer (not null)
085: * @param savedState (not null)
086: */
087: public void restoreState(IPresentationSerializer serializer,
088: IMemento savedState) {
089: IMemento[] parts = savedState
090: .getChildren(IWorkbenchConstants.TAG_PART);
091:
092: for (int idx = 0; idx < parts.length; idx++) {
093: String id = parts[idx]
094: .getString(IWorkbenchConstants.TAG_ID);
095:
096: if (id != null) {
097: IPresentablePart part = serializer.getPart(id);
098:
099: 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,
110: IMemento memento) {
111:
112: List parts = Arrays.asList(list.getPartList());
113:
114: Iterator iter = parts.iterator();
115: while (iter.hasNext()) {
116: IPresentablePart next = (IPresentablePart) iter.next();
117:
118: IMemento childMem = memento
119: .createChild(IWorkbenchConstants.TAG_PART);
120: childMem.putString(IWorkbenchConstants.TAG_ID, context
121: .getId(next));
122: }
123: }
124: }
|