01: /*******************************************************************************
02: * Copyright (c) 2004, 2006 IBM Corporation and others.
03: * All rights reserved. This program and the accompanying materials
04: * are made available under the terms of the Eclipse Public License v1.0
05: * which accompanies this distribution, and is available at
06: * http://www.eclipse.org/legal/epl-v10.html
07: *
08: * Contributors:
09: * IBM Corporation - initial API and implementation
10: *******************************************************************************/package org.eclipse.ui.internal.presentations;
11:
12: import java.util.Collections;
13: import java.util.List;
14:
15: import org.eclipse.ui.presentations.IPresentablePart;
16: import org.eclipse.ui.presentations.IPresentationSerializer;
17:
18: /**
19: * This class is used to map IPresentableParts onto string IDs
20: */
21: public class PresentationSerializer implements IPresentationSerializer {
22:
23: private List parts = Collections.EMPTY_LIST;
24:
25: public PresentationSerializer(List presentableParts) {
26: parts = presentableParts;
27: }
28:
29: /* (non-Javadoc)
30: * @see org.eclipse.ui.presentations.IPresentationSerializer#getId(org.eclipse.ui.presentations.IPresentablePart)
31: */
32: public String getId(IPresentablePart part) {
33: int index = parts.indexOf(part);
34:
35: return "" + index; //$NON-NLS-1$
36: }
37:
38: /* (non-Javadoc)
39: * @see org.eclipse.ui.presentations.IPresentationSerializer#getPart(java.lang.String)
40: */
41: public IPresentablePart getPart(String id) {
42: try {
43: Integer integer = new Integer(id);
44: int index = integer.intValue();
45:
46: IPresentablePart result = (IPresentablePart) parts
47: .get(index);
48: return result;
49:
50: } catch (NumberFormatException e) {
51: } catch (IndexOutOfBoundsException e) {
52: }
53:
54: return null;
55: }
56:
57: /**
58: * Prevent this object from being used further. Ensure that none
59: * of the methods return anything useful in order to discourage clients
60: * from hanging onto references to this object.
61: */
62: public void dispose() {
63: parts = Collections.EMPTY_LIST;
64: }
65:
66: }
|