01: /*******************************************************************************
02: * Copyright (c) 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.navigator;
11:
12: import java.util.LinkedHashSet;
13:
14: import org.eclipse.ui.internal.navigator.extensions.NavigatorContentDescriptor;
15:
16: /**
17: * @since 3.2
18: *
19: */
20: public class ContributorTrackingSet extends LinkedHashSet {
21:
22: private static final long serialVersionUID = 2516241537206281972L;
23:
24: private NavigatorContentDescriptor contributor;
25: private NavigatorContentService contentService;
26:
27: /**
28: * Construct a tracking set.
29: *
30: * @param aContentService
31: */
32: public ContributorTrackingSet(
33: NavigatorContentService aContentService) {
34: contentService = aContentService;
35: }
36:
37: /**
38: * Construct a tracking set.
39: *
40: * @param aContentService
41: * @param elements
42: */
43: public ContributorTrackingSet(
44: NavigatorContentService aContentService, Object[] elements) {
45:
46: for (int i = 0; i < elements.length; i++)
47: super .add(elements[i]);
48:
49: contentService = aContentService;
50: }
51:
52: /* (non-Javadoc)
53: * @see java.util.HashSet#add(java.lang.Object)
54: */
55: public boolean add(Object o) {
56: if (contributor != null)
57: contentService.rememberContribution(contributor, o);
58: return super .add(o);
59: }
60:
61: /* (non-Javadoc)
62: * @see java.util.HashSet#remove(java.lang.Object)
63: */
64: public boolean remove(Object o) {
65: contentService.rememberContribution(null, o);
66: return super .remove(o);
67: }
68:
69: /**
70: *
71: * @return The current contributor.
72: */
73: public NavigatorContentDescriptor getContributor() {
74: return contributor;
75: }
76:
77: /**
78: *
79: * @param newContributor The contributor to record for the next series of adds.
80: */
81: public void setContributor(NavigatorContentDescriptor newContributor) {
82: contributor = newContributor;
83: }
84:
85: /**
86: * @param contents
87: */
88: public void setContents(Object[] contents) {
89: super .clear();
90: if (contents != null)
91: for (int i = 0; i < contents.length; i++)
92: super.add(contents[i]);
93:
94: }
95: }
|