KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > ui > internal > navigator > ContributorTrackingSet


1 /*******************************************************************************
2  * Copyright (c) 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
12 package org.eclipse.ui.internal.navigator;
13
14 import java.util.LinkedHashSet JavaDoc;
15
16 import org.eclipse.ui.internal.navigator.extensions.NavigatorContentDescriptor;
17
18 /**
19  * @since 3.2
20  *
21  */

22 public class ContributorTrackingSet extends LinkedHashSet JavaDoc {
23
24     
25     private static final long serialVersionUID = 2516241537206281972L;
26     
27     private NavigatorContentDescriptor contributor;
28     private NavigatorContentService contentService;
29     
30     /**
31      * Construct a tracking set.
32      *
33      * @param aContentService
34      */

35     public ContributorTrackingSet(NavigatorContentService aContentService) {
36         contentService = aContentService;
37     }
38     
39     /**
40      * Construct a tracking set.
41      *
42      * @param aContentService
43      * @param elements
44      */

45     public ContributorTrackingSet(NavigatorContentService aContentService, Object JavaDoc[] elements) {
46         
47         for (int i = 0; i < elements.length; i++)
48             super.add(elements[i]);
49         
50         contentService = aContentService;
51     }
52     
53     /* (non-Javadoc)
54      * @see java.util.HashSet#add(java.lang.Object)
55      */

56     public boolean add(Object JavaDoc o) {
57         if(contributor != null)
58             contentService.rememberContribution(contributor, o);
59         return super.add(o);
60     }
61     
62     /* (non-Javadoc)
63      * @see java.util.HashSet#remove(java.lang.Object)
64      */

65     public boolean remove(Object JavaDoc o) {
66         contentService.rememberContribution(null, o);
67         return super.remove(o);
68     }
69
70     /**
71      *
72      * @return The current contributor.
73      */

74     public NavigatorContentDescriptor getContributor() {
75         return contributor;
76     }
77
78     /**
79      *
80      * @param newContributor The contributor to record for the next series of adds.
81      */

82     public void setContributor(NavigatorContentDescriptor newContributor) {
83         contributor = newContributor;
84     }
85
86     /**
87      * @param contents
88      */

89     public void setContents(Object JavaDoc[] contents) {
90         super.clear();
91         if(contents != null)
92             for (int i = 0; i < contents.length; i++)
93                 super.add(contents[i]);
94         
95     }
96 }
97
Popular Tags