KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > ui > internal > presentations > PresentationSerializer


1 /*******************************************************************************
2  * Copyright (c) 2004, 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.presentations;
12
13 import java.util.Collections JavaDoc;
14 import java.util.List JavaDoc;
15
16 import org.eclipse.ui.presentations.IPresentablePart;
17 import org.eclipse.ui.presentations.IPresentationSerializer;
18
19 /**
20  * This class is used to map IPresentableParts onto string IDs
21  */

22 public class PresentationSerializer implements IPresentationSerializer {
23
24     private List JavaDoc parts = Collections.EMPTY_LIST;
25
26     public PresentationSerializer(List JavaDoc presentableParts) {
27         parts = presentableParts;
28     }
29
30     /* (non-Javadoc)
31      * @see org.eclipse.ui.presentations.IPresentationSerializer#getId(org.eclipse.ui.presentations.IPresentablePart)
32      */

33     public String JavaDoc getId(IPresentablePart part) {
34         int index = parts.indexOf(part);
35
36         return "" + index; //$NON-NLS-1$
37
}
38
39     /* (non-Javadoc)
40      * @see org.eclipse.ui.presentations.IPresentationSerializer#getPart(java.lang.String)
41      */

42     public IPresentablePart getPart(String JavaDoc id) {
43         try {
44             Integer JavaDoc integer = new Integer JavaDoc(id);
45             int index = integer.intValue();
46
47             IPresentablePart result = (IPresentablePart) parts.get(index);
48             return result;
49
50         } catch (NumberFormatException JavaDoc e) {
51         } catch (IndexOutOfBoundsException JavaDoc 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 }
67
Popular Tags