KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > team > internal > core > subscribers > SubscriberSyncInfoSet


1 /*******************************************************************************
2  * Copyright (c) 2000, 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.team.internal.core.subscribers;
12
13 import org.eclipse.core.resources.IWorkspaceRunnable;
14 import org.eclipse.core.runtime.IProgressMonitor;
15 import org.eclipse.team.core.synchronize.ISyncInfoSetChangeListener;
16 import org.eclipse.team.core.synchronize.SyncInfoTree;
17 import org.eclipse.team.internal.core.Policy;
18
19 /**
20  * The <code>SubscriberSyncInfoSet</code> is a <code>SyncInfoSet</code> that provides the ability to add,
21  * remove and change <code>SyncInfo</code> and fires change event notifications to registered listeners.
22  * It also provides the ability
23  * to batch changes in a single change notification as well as optimizations for sync info retrieval.
24  *
25  * This class uses synchronized methods and synchronized blocks to protect internal data structures during both access
26  * and modify operations and uses an <code>ILock</code> to make modification operations thread-safe. The events
27  * are fired while this lock is held so clients responding to these events should not obtain their own internal locks
28  * while processing change events.
29  *
30  * TODO: Override modification methods to enforce use with handler
31  *
32  */

33 public class SubscriberSyncInfoSet extends SyncInfoTree {
34     
35     protected SubscriberEventHandler handler;
36     
37     public SubscriberSyncInfoSet(SubscriberEventHandler handler) {
38         this.handler = handler;
39     }
40
41     /* (non-Javadoc)
42      * @see org.eclipse.team.core.synchronize.SyncInfoSet#connect(org.eclipse.team.core.synchronize.ISyncInfoSetChangeListener, org.eclipse.core.runtime.IProgressMonitor)
43      */

44     public void connect(ISyncInfoSetChangeListener listener, IProgressMonitor monitor) {
45         if (handler == null) {
46             super.connect(listener, monitor);
47         } else {
48             connect(listener);
49         }
50     }
51
52     /**
53      * Variation of connect that does not need progress and does not throw an exception.
54      * Progress is provided by the background event handler and errors are passed through
55      * the chain to the view.
56      * @param listener
57      */

58     public void connect(final ISyncInfoSetChangeListener listener) {
59         if (handler == null) {
60             // Should only use this connect if the set has a handler
61
throw new UnsupportedOperationException JavaDoc();
62         } else {
63             handler.run(new IWorkspaceRunnable() {
64                 public void run(IProgressMonitor monitor) {
65                     try {
66                         beginInput();
67                         monitor.beginTask(null, 100);
68                         removeSyncSetChangedListener(listener);
69                         addSyncSetChangedListener(listener);
70                         listener.syncInfoSetReset(SubscriberSyncInfoSet.this, Policy.subMonitorFor(monitor, 95));
71                     } finally {
72                         endInput(Policy.subMonitorFor(monitor, 5));
73                         monitor.done();
74                     }
75                 }
76             }, true /* high priority */);
77         }
78     }
79 }
80
Popular Tags