1 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 INCOMING_ID = TeamUIPlugin.ID + "org.eclipse.team.iu.statusline.incoming"; private static final String OUTGOING_ID = TeamUIPlugin.ID + "org.eclipse.team.iu.statusline.outgoing"; private static final String CONFLICTING_ID = TeamUIPlugin.ID + "org.eclipse.team.iu.statusline.conflicting"; private static final String TOTALS_ID = TeamUIPlugin.ID + "org.eclipse.team.iu.statusline.totals"; 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); this.outgoing = createStatusLineContribution(OUTGOING_ID, ISynchronizePageConfiguration.OUTGOING_MODE, "0", outgoingImage); this.conflicting = createStatusLineContribution(CONFLICTING_ID, ISynchronizePageConfiguration.CONFLICTING_MODE, "0", conflictingImage); } 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 id, final int mode, String 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 () { 86 public void run() { 87 if (isThreeWay()) { 88 conflicting.setText(new Integer (workspaceConflicting).toString()); 89 incoming.setText(new Integer (workspaceIncoming).toString()); 90 outgoing.setText(new Integer (workspaceOutgoing).toString()); 91 92 conflicting.setTooltip(NLS.bind(TeamUIMessages.StatisticsPanel_numbersTooltip, new String [] { TeamUIMessages.StatisticsPanel_conflicting })); outgoing.setTooltip(NLS.bind(TeamUIMessages.StatisticsPanel_numbersTooltip, new String [] { TeamUIMessages.StatisticsPanel_outgoing })); incoming.setTooltip(NLS.bind(TeamUIMessages.StatisticsPanel_numbersTooltip, new String [] { TeamUIMessages.StatisticsPanel_incoming })); } else { 96 if (total == 1) { 97 totalChanges.setText(NLS.bind(TeamUIMessages.StatisticsPanel_numberTotalSingular, new String [] { Integer.toString(total) })); 98 } else { 99 totalChanges.setText(NLS.bind(TeamUIMessages.StatisticsPanel_numberTotalPlural, new String [] { Integer.toString(total) })); 100 } 101 } 102 } 103 }); 104 } 105 106 protected abstract int getChangeCount(); 107 108 protected abstract int countFor(int state); 109 110 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 |