KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > team > internal > ui > synchronize > SubscriberParticipantPage


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.ui.synchronize;
12
13 import org.eclipse.core.runtime.IAdaptable;
14 import org.eclipse.swt.widgets.Composite;
15 import org.eclipse.team.core.synchronize.FastSyncInfoFilter;
16 import org.eclipse.team.core.synchronize.SyncInfo;
17 import org.eclipse.team.internal.core.subscribers.SubscriberSyncInfoCollector;
18 import org.eclipse.team.internal.core.subscribers.WorkingSetFilteredSyncInfoCollector;
19 import org.eclipse.team.internal.ui.synchronize.actions.DefaultSynchronizePageActions;
20 import org.eclipse.team.internal.ui.synchronize.actions.SubscriberActionContribution;
21 import org.eclipse.team.ui.synchronize.ISynchronizePageConfiguration;
22 import org.eclipse.team.ui.synchronize.SubscriberParticipant;
23
24 /**
25  * A synchronize view page that works with participants that are subclasses of
26  * {@link SubscriberParticipant}. It shows changes in the tree or table view
27  * and supports navigation, opening, and filtering changes.
28  * <p>
29  * Clients can subclass to extend the label decoration or add action bar
30  * contributions. For more extensive modifications, clients should create
31  * their own custom page.
32  * </p>
33  * @since 3.0
34  */

35 public final class SubscriberParticipantPage extends AbstractSynchronizePage implements IAdaptable {
36         
37     private SubscriberParticipant participant;
38     
39     private final static int[] INCOMING_MODE_FILTER = new int[] {SyncInfo.CONFLICTING, SyncInfo.INCOMING};
40     private final static int[] OUTGOING_MODE_FILTER = new int[] {SyncInfo.CONFLICTING, SyncInfo.OUTGOING};
41     private final static int[] BOTH_MODE_FILTER = new int[] {SyncInfo.CONFLICTING, SyncInfo.INCOMING, SyncInfo.OUTGOING};
42     private final static int[] CONFLICTING_MODE_FILTER = new int[] {SyncInfo.CONFLICTING};
43
44     /**
45      * Filters out-of-sync resources by working set and mode
46      */

47     private WorkingSetFilteredSyncInfoCollector collector;
48     
49     /**
50      * Constructs a new SynchronizeView.
51      */

52     public SubscriberParticipantPage(ISynchronizePageConfiguration configuration, SubscriberSyncInfoCollector subscriberCollector) {
53         super(configuration);
54         this.participant = (SubscriberParticipant)configuration.getParticipant();
55         configuration.setComparisonType(isThreeWay()
56                         ? ISynchronizePageConfiguration.THREE_WAY
57                         : ISynchronizePageConfiguration.TWO_WAY);
58         configuration.addActionContribution(new DefaultSynchronizePageActions());
59         configuration.addActionContribution(new SubscriberActionContribution());
60         initializeCollector(configuration, subscriberCollector);
61     }
62     
63     /**
64      * @return Returns the participant.
65      */

66     public SubscriberParticipant getParticipant() {
67         return participant;
68     }
69
70     protected AbstractViewerAdvisor createViewerAdvisor(Composite parent) {
71         return new TreeViewerAdvisor(parent, getConfiguration());
72     }
73     
74     /*
75      * This method is invoked from <code>setMode</code> when the mode has changed.
76      * It sets the filter on the collector to show the <code>SyncInfo</code>
77      * appropriate for the mode.
78      * @param mode the new mode (one of <code>INCOMING_MODE_FILTER</code>,
79      * <code>OUTGOING_MODE_FILTER</code>, <code>CONFLICTING_MODE_FILTER</code>
80      * or <code>BOTH_MODE_FILTER</code>)
81      */

82     protected void updateMode(int mode) {
83         if(collector != null && isThreeWay()) {
84         
85             int[] modeFilter = BOTH_MODE_FILTER;
86             switch(mode) {
87             case ISynchronizePageConfiguration.INCOMING_MODE:
88                 modeFilter = INCOMING_MODE_FILTER; break;
89             case ISynchronizePageConfiguration.OUTGOING_MODE:
90                 modeFilter = OUTGOING_MODE_FILTER; break;
91             case ISynchronizePageConfiguration.BOTH_MODE:
92                 modeFilter = BOTH_MODE_FILTER; break;
93             case ISynchronizePageConfiguration.CONFLICTING_MODE:
94                 modeFilter = CONFLICTING_MODE_FILTER; break;
95             }
96
97             collector.setFilter(
98                     new FastSyncInfoFilter.AndSyncInfoFilter(
99                             new FastSyncInfoFilter[] {
100                                     new FastSyncInfoFilter.SyncInfoDirectionFilter(modeFilter)
101                             }));
102         }
103     }
104     
105     private void initializeCollector(ISynchronizePageConfiguration configuration, SubscriberSyncInfoCollector subscriberCollector) {
106         SubscriberParticipant participant = getParticipant();
107         collector = new WorkingSetFilteredSyncInfoCollector(subscriberCollector, participant.getSubscriber().roots());
108         updateMode(configuration.getMode());
109         collector.reset();
110         configuration.setProperty(ISynchronizePageConfiguration.P_SYNC_INFO_SET, collector.getSyncInfoTree());
111         configuration.setProperty(SynchronizePageConfiguration.P_WORKING_SET_SYNC_INFO_SET, collector.getWorkingSetSyncInfoSet());
112     }
113     
114     /* (non-Javadoc)
115      * @see org.eclipse.team.ui.synchronize.SyncInfoSetSynchronizePage#isThreeWay()
116      */

117     protected boolean isThreeWay() {
118         return getParticipant().getSubscriber().getResourceComparator().isThreeWay();
119     }
120
121     /* (non-Javadoc)
122      * @see org.eclipse.team.internal.ui.synchronize.SyncInfoSetSynchronizePage#reset()
123      */

124     public void reset() {
125         getParticipant().reset();
126     }
127     
128     /*
129      * Provide internal access to the collector
130      * @return Returns the collector.
131      */

132     public WorkingSetFilteredSyncInfoCollector getCollector() {
133         return collector;
134     }
135     
136     public void dispose() {
137         super.dispose();
138         collector.dispose();
139     }
140     
141     /* (non-Javadoc)
142      * @see org.eclipse.team.internal.ui.synchronize.AbstractSynchronizePage#createChangesSection(org.eclipse.swt.widgets.Composite)
143      */

144     protected ChangesSection createChangesSection(Composite parent) {
145         return new SyncInfoSetChangesSection(parent, this, getConfiguration());
146     }
147 }
148
Popular Tags