1 11 package org.eclipse.team.internal.ui.synchronize; 12 13 import org.eclipse.core.runtime.IProgressMonitor; 14 import org.eclipse.core.runtime.MultiStatus; 15 import org.eclipse.jface.dialogs.ErrorDialog; 16 import org.eclipse.osgi.util.NLS; 17 import org.eclipse.swt.SWT; 18 import org.eclipse.swt.layout.GridData; 19 import org.eclipse.swt.layout.GridLayout; 20 import org.eclipse.swt.widgets.*; 21 import org.eclipse.team.core.ITeamStatus; 22 import org.eclipse.team.core.synchronize.*; 23 import org.eclipse.team.internal.ui.*; 24 import org.eclipse.team.ui.synchronize.*; 25 import org.eclipse.ui.forms.events.HyperlinkAdapter; 26 import org.eclipse.ui.forms.events.HyperlinkEvent; 27 import org.eclipse.ui.forms.widgets.Hyperlink; 28 29 35 public class SyncInfoSetChangesSection extends ForwardingChangesSection { 36 37 41 private boolean showingError; 42 43 47 private SynchronizePageActionGroup changedListener = new SynchronizePageActionGroup() { 48 public void modelChanged(ISynchronizeModelElement root) { 49 calculateDescription(); 50 } 51 }; 52 53 57 private ISyncInfoSetChangeListener subscriberListener = new ISyncInfoSetChangeListener() { 58 public void syncInfoSetReset(SyncInfoSet set, IProgressMonitor monitor) { 59 } 61 public void syncInfoChanged(ISyncInfoSetChangeEvent event, IProgressMonitor monitor) { 62 calculateDescription(); 63 } 64 public void syncInfoSetErrors(SyncInfoSet set, ITeamStatus[] errors, IProgressMonitor monitor) { 65 } 67 }; 68 69 73 private ISyncInfoSetChangeListener outputSetListener = new ISyncInfoSetChangeListener() { 74 public void syncInfoSetReset(SyncInfoSet set, IProgressMonitor monitor) { 75 calculateDescription(); 76 } 77 public void syncInfoChanged(ISyncInfoSetChangeEvent event, IProgressMonitor monitor) { 78 } 81 public void syncInfoSetErrors(SyncInfoSet set, ITeamStatus[] errors, IProgressMonitor monitor) { 82 calculateDescription(); 83 } 84 }; 85 86 92 public SyncInfoSetChangesSection(Composite parent, AbstractSynchronizePage page, ISynchronizePageConfiguration configuration) { 93 super(parent, page, configuration); 94 } 95 96 99 protected void initializeChangesViewer() { 100 super.initializeChangesViewer(); 101 getConfiguration().addActionContribution(changedListener); 102 getParticipantSyncInfoSet().addSyncSetChangedListener(subscriberListener); 103 getVisibleSyncInfoSet().addSyncSetChangedListener(outputSetListener); 104 } 105 106 protected void calculateDescription() { 107 SyncInfoTree syncInfoTree = getVisibleSyncInfoSet(); 108 if (syncInfoTree.getErrors().length > 0) { 109 if (!showingError) { 110 TeamUIPlugin.getStandardDisplay().asyncExec(new Runnable () { 111 public void run() { 112 updatePage(getErrorComposite(getContainer())); 113 showingError = true; 114 } 115 }); 116 } 117 return; 118 } 119 120 showingError = false; 121 super.calculateDescription(); 122 } 123 124 protected long getChangesInMode(int candidateMode) { 125 SyncInfoSet participantSet = getParticipantSyncInfoSet(); 126 long numChanges; 127 switch (candidateMode) { 128 case ISynchronizePageConfiguration.OUTGOING_MODE: 129 numChanges = participantSet.countFor(SyncInfo.OUTGOING, SyncInfo.DIRECTION_MASK); 130 break; 131 case ISynchronizePageConfiguration.INCOMING_MODE: 132 numChanges = participantSet.countFor(SyncInfo.INCOMING, SyncInfo.DIRECTION_MASK); 133 break; 134 case ISynchronizePageConfiguration.BOTH_MODE: 135 numChanges = participantSet.countFor(SyncInfo.INCOMING, SyncInfo.DIRECTION_MASK) 136 + participantSet.countFor(SyncInfo.OUTGOING, SyncInfo.DIRECTION_MASK); 137 break; 138 default: 139 numChanges = 0; 140 break; 141 } 142 return numChanges; 143 } 144 145 149 protected int getCandidateMode() { 150 SyncInfoSet participantSet = getParticipantSyncInfoSet(); 151 SynchronizePageConfiguration configuration = (SynchronizePageConfiguration)getConfiguration(); 152 long outgoingChanges = participantSet.countFor(SyncInfo.OUTGOING, SyncInfo.DIRECTION_MASK); 153 if (outgoingChanges > 0) { 154 if (configuration.isModeSupported(ISynchronizePageConfiguration.OUTGOING_MODE)) { 155 return ISynchronizePageConfiguration.OUTGOING_MODE; 156 } 157 if (configuration.isModeSupported(ISynchronizePageConfiguration.BOTH_MODE)) { 158 return ISynchronizePageConfiguration.BOTH_MODE; 159 } 160 } 161 long incomingChanges = participantSet.countFor(SyncInfo.INCOMING, SyncInfo.DIRECTION_MASK); 162 if (incomingChanges > 0) { 163 if (configuration.isModeSupported(ISynchronizePageConfiguration.INCOMING_MODE)) { 164 return ISynchronizePageConfiguration.INCOMING_MODE; 165 } 166 if (configuration.isModeSupported(ISynchronizePageConfiguration.BOTH_MODE)) { 167 return ISynchronizePageConfiguration.BOTH_MODE; 168 } 169 } 170 return configuration.getMode(); 171 } 172 173 public void dispose() { 174 super.dispose(); 175 getConfiguration().removeActionContribution(changedListener); 176 getParticipantSyncInfoSet().removeSyncSetChangedListener(subscriberListener); 177 getVisibleSyncInfoSet().removeSyncSetChangedListener(outputSetListener); 178 } 179 180 private Composite getErrorComposite(Composite parent) { 181 Composite composite = new Composite(parent, SWT.NONE); 182 composite.setBackground(getBackgroundColor()); 183 GridLayout layout = new GridLayout(); 184 layout.numColumns = 2; 185 composite.setLayout(layout); 186 GridData data = new GridData(GridData.FILL_BOTH); 187 data.grabExcessVerticalSpace = true; 188 composite.setLayoutData(data); 189 190 Hyperlink link = new Hyperlink(composite, SWT.WRAP); 191 link.setText(TeamUIMessages.ChangesSection_8); 192 link.addHyperlinkListener(new HyperlinkAdapter() { 193 public void linkActivated(HyperlinkEvent e) { 194 showErrors(); 195 } 196 }); 197 link.setBackground(getBackgroundColor()); 198 link.setUnderlined(true); 199 200 link = new Hyperlink(composite, SWT.WRAP); 201 link.setText(TeamUIMessages.ChangesSection_9); 202 link.addHyperlinkListener(new HyperlinkAdapter() { 203 public void linkActivated(HyperlinkEvent e) { 204 getPage().reset(); 205 } 206 }); 207 link.setBackground(getBackgroundColor()); 208 link.setUnderlined(true); 209 210 createDescriptionLabel(composite, NLS.bind(TeamUIMessages.ChangesSection_10, new String [] { Utils.shortenText(SynchronizeView.MAX_NAME_LENGTH, getConfiguration().getParticipant().getName()) })); 211 212 return composite; 213 } 214 215 void showErrors() { 216 ITeamStatus[] status = getVisibleSyncInfoSet().getErrors(); 217 String title = TeamUIMessages.ChangesSection_11; 218 if (status.length == 1) { 219 ErrorDialog.openError(getShell(), title, status[0].getMessage(), status[0]); 220 } else { 221 MultiStatus multi = new MultiStatus(TeamUIPlugin.ID, 0, status, TeamUIMessages.ChangesSection_12, null); 222 ErrorDialog.openError(getShell(), title, null, multi); 223 } 224 } 225 226 protected int getChangesCount() { 227 return getParticipantSyncInfoSet().size(); 228 } 229 230 protected long getVisibleChangesCount() { 231 return getVisibleSyncInfoSet().size(); 232 } 233 234 237 private SyncInfoTree getVisibleSyncInfoSet() { 238 return (SyncInfoTree)getConfiguration().getProperty(ISynchronizePageConfiguration.P_SYNC_INFO_SET); 239 } 240 241 245 private SyncInfoSet getParticipantSyncInfoSet() { 246 return (SyncInfoSet)getConfiguration().getProperty(SynchronizePageConfiguration.P_WORKING_SET_SYNC_INFO_SET); 247 } 248 } 249 | Popular Tags |