KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > ui > internal > views > properties > tabbed > view > TabbedPropertyRegistryFactory


1 /*******************************************************************************
2  * Copyright (c) 2001, 2007 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.views.properties.tabbed.view;
12
13 import java.util.ArrayList JavaDoc;
14 import java.util.HashMap JavaDoc;
15 import java.util.List JavaDoc;
16 import java.util.Map JavaDoc;
17
18 import org.eclipse.ui.views.properties.tabbed.ITabbedPropertySheetPageContributor;
19
20
21 /**
22  * tabbed property registry factory. Caches the tabbed property registry
23  * by tabbed property contributor ID.
24  *
25  * @author Anthony Hunter
26  */

27 public class TabbedPropertyRegistryFactory {
28
29     class CacheData {
30         TabbedPropertyRegistry registry;
31         List JavaDoc references;
32     }
33
34     /**
35      * singleton instance of this class
36      */

37     private static TabbedPropertyRegistryFactory INSTANCE =
38         new TabbedPropertyRegistryFactory();
39
40     /**
41      * get the singleton instance of this class
42      */

43     public static TabbedPropertyRegistryFactory getInstance() {
44         return INSTANCE;
45     }
46
47     /**
48      * private constructor.
49      */

50     private TabbedPropertyRegistryFactory() {
51         super();
52         idToCacheData = new HashMap JavaDoc();
53     }
54
55     protected Map JavaDoc idToCacheData; // cache
56

57     /**
58      * Creates a registry for the given contributor.
59      */

60     public TabbedPropertyRegistry createRegistry(ITabbedPropertySheetPageContributor target) {
61         /**
62          * Get the contributor id from the ITabbedPropertySheetPageContributor interface
63          */

64         String JavaDoc key = target.getContributorId();
65         CacheData data = (CacheData) idToCacheData.get(key);
66         if (data == null) {
67             data = new CacheData();
68             data.registry =
69                 new TabbedPropertyRegistry(key);
70             data.references = new ArrayList JavaDoc(5);
71             idToCacheData.put(key, data);
72         }
73         data.references.add(target);
74         // keeps track of contributor using the same registry
75
return data.registry;
76     }
77
78     /**
79      * Indicates that the given contributor no longer needs
80      * a registry. The registry will be disposed when
81      * no other contributor of the same type needs it.
82      */

83     public void disposeRegistry(ITabbedPropertySheetPageContributor target) {
84         /**
85          * Get the contributor id from the ITabbedPropertySheetPageContributor interface
86          */

87         String JavaDoc key = target.getContributorId();
88         CacheData data = (CacheData) idToCacheData.get(key);
89         if (data != null) {
90             data.references.remove(target);
91             if (data.references.isEmpty()) {
92                 idToCacheData.remove(key);
93             }
94         }
95     }
96 }
97
Popular Tags