KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > team > internal > ui > synchronize > actions > StatusLineContributionGroup


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.actions;
12
13 import org.eclipse.jface.action.IStatusLineManager;
14 import org.eclipse.osgi.util.NLS;
15 import org.eclipse.swt.SWT;
16 import org.eclipse.swt.graphics.Image;
17 import org.eclipse.swt.widgets.*;
18 import org.eclipse.team.core.synchronize.SyncInfo;
19 import org.eclipse.team.internal.ui.*;
20 import org.eclipse.team.ui.synchronize.*;
21 import org.eclipse.ui.IActionBars;
22 import org.eclipse.ui.actions.ActionGroup;
23
24 public abstract class StatusLineContributionGroup extends ActionGroup {
25
26     private static final String JavaDoc INCOMING_ID = TeamUIPlugin.ID + "org.eclipse.team.iu.statusline.incoming"; //$NON-NLS-1$
27
private static final String JavaDoc OUTGOING_ID = TeamUIPlugin.ID + "org.eclipse.team.iu.statusline.outgoing"; //$NON-NLS-1$
28
private static final String JavaDoc CONFLICTING_ID = TeamUIPlugin.ID + "org.eclipse.team.iu.statusline.conflicting"; //$NON-NLS-1$
29
private static final String JavaDoc TOTALS_ID = TeamUIPlugin.ID + "org.eclipse.team.iu.statusline.totals"; //$NON-NLS-1$
30
private final static int TEXT_FIELD_MAX_SIZE = 25;
31
32     private StatusLineCLabelContribution incoming;
33     private StatusLineCLabelContribution outgoing;
34     private StatusLineCLabelContribution conflicting;
35     private StatusLineCLabelContribution totalChanges;
36     
37     private Image incomingImage = TeamUIPlugin.getImageDescriptor(ITeamUIImages.IMG_DLG_SYNC_INCOMING).createImage();
38     private Image outgoingImage = TeamUIPlugin.getImageDescriptor(ITeamUIImages.IMG_DLG_SYNC_OUTGOING).createImage();
39     private Image conflictingImage = TeamUIPlugin.getImageDescriptor(ITeamUIImages.IMG_DLG_SYNC_CONFLICTING).createImage();
40     
41     private ISynchronizePageConfiguration configuration;
42
43     public StatusLineContributionGroup(final Shell shell, ISynchronizePageConfiguration configuration) {
44         this.configuration = configuration;
45         if (isThreeWay()) {
46             this.incoming = createStatusLineContribution(INCOMING_ID, ISynchronizePageConfiguration.INCOMING_MODE, "0", incomingImage); //$NON-NLS-1$
47
this.outgoing = createStatusLineContribution(OUTGOING_ID, ISynchronizePageConfiguration.OUTGOING_MODE, "0", outgoingImage); //$NON-NLS-1$
48
this.conflicting = createStatusLineContribution(CONFLICTING_ID, ISynchronizePageConfiguration.CONFLICTING_MODE, "0", conflictingImage); //$NON-NLS-1$
49
} else {
50             this.totalChanges = new StatusLineCLabelContribution(TOTALS_ID, TEXT_FIELD_MAX_SIZE);
51         }
52         updateCounts();
53     }
54
55     private boolean isThreeWay() {
56         return configuration.getComparisonType() == ISynchronizePageConfiguration.THREE_WAY;
57     }
58
59     private StatusLineCLabelContribution createStatusLineContribution(String JavaDoc id, final int mode, String JavaDoc label, Image image) {
60         StatusLineCLabelContribution item = new StatusLineCLabelContribution(id, 15);
61         item.addListener(SWT.MouseDown, new Listener() {
62             public void handleEvent(Event event) {
63                 configuration.setMode(mode);
64             }
65         });
66         item.setText(label);
67         item.setImage(image);
68         return item;
69     }
70
71     public void dispose() {
72         if (isThreeWay()) {
73             incomingImage.dispose();
74             outgoingImage.dispose();
75             conflictingImage.dispose();
76         }
77     }
78
79     protected void updateCounts() {
80         final int total = getChangeCount();
81         final int workspaceConflicting = countFor(SyncInfo.CONFLICTING);
82         final int workspaceOutgoing = countFor(SyncInfo.OUTGOING);
83         final int workspaceIncoming = countFor(SyncInfo.INCOMING);
84
85         TeamUIPlugin.getStandardDisplay().asyncExec(new Runnable JavaDoc() {
86             public void run() {
87                 if (isThreeWay()) {
88                     conflicting.setText(new Integer JavaDoc(workspaceConflicting).toString());
89                     incoming.setText(new Integer JavaDoc(workspaceIncoming).toString());
90                     outgoing.setText(new Integer JavaDoc(workspaceOutgoing).toString());
91
92                     conflicting.setTooltip(NLS.bind(TeamUIMessages.StatisticsPanel_numbersTooltip, new String JavaDoc[] { TeamUIMessages.StatisticsPanel_conflicting })); //
93
outgoing.setTooltip(NLS.bind(TeamUIMessages.StatisticsPanel_numbersTooltip, new String JavaDoc[] { TeamUIMessages.StatisticsPanel_outgoing })); //
94
incoming.setTooltip(NLS.bind(TeamUIMessages.StatisticsPanel_numbersTooltip, new String JavaDoc[] { TeamUIMessages.StatisticsPanel_incoming })); //
95
} else {
96                     if (total == 1) {
97                         totalChanges.setText(NLS.bind(TeamUIMessages.StatisticsPanel_numberTotalSingular, new String JavaDoc[] { Integer.toString(total) }));
98                     } else {
99                         totalChanges.setText(NLS.bind(TeamUIMessages.StatisticsPanel_numberTotalPlural, new String JavaDoc[] { Integer.toString(total) }));
100                     }
101                 }
102             }
103         });
104     }
105
106     protected abstract int getChangeCount();
107
108     protected abstract int countFor(int state);
109     
110     /*
111      * (non-Javadoc)
112      *
113      * @see org.eclipse.ui.actions.ActionGroup#fillActionBars(org.eclipse.ui.IActionBars)
114      */

115     public void fillActionBars(IActionBars actionBars) {
116         IStatusLineManager mgr = actionBars.getStatusLineManager();
117         if (isThreeWay()) {
118             mgr.add(incoming);
119             mgr.add(outgoing);
120             mgr.add(conflicting);
121         } else {
122             mgr.add(totalChanges);
123         }
124     }
125
126     public ISynchronizePageConfiguration getConfiguration() {
127         return configuration;
128     }
129 }
130
Popular Tags