KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > team > internal > ui > mapping > DiffTreeChangesSection


1 /*******************************************************************************
2  * Copyright (c) 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.mapping;
12
13 import java.util.*;
14 import java.util.List JavaDoc;
15
16 import org.eclipse.core.resources.mapping.*;
17 import org.eclipse.core.runtime.*;
18 import org.eclipse.core.runtime.jobs.*;
19 import org.eclipse.jface.dialogs.ErrorDialog;
20 import org.eclipse.jface.preference.PreferenceStore;
21 import org.eclipse.jface.util.IPropertyChangeListener;
22 import org.eclipse.jface.util.PropertyChangeEvent;
23 import org.eclipse.jface.viewers.TreeViewer;
24 import org.eclipse.jface.viewers.Viewer;
25 import org.eclipse.osgi.util.NLS;
26 import org.eclipse.swt.SWT;
27 import org.eclipse.swt.events.SelectionEvent;
28 import org.eclipse.swt.events.SelectionListener;
29 import org.eclipse.swt.layout.GridData;
30 import org.eclipse.swt.layout.GridLayout;
31 import org.eclipse.swt.widgets.*;
32 import org.eclipse.team.core.diff.*;
33 import org.eclipse.team.core.mapping.ISynchronizationContext;
34 import org.eclipse.team.core.mapping.ISynchronizationScope;
35 import org.eclipse.team.internal.core.subscribers.SubscriberDiffTreeEventHandler;
36 import org.eclipse.team.internal.ui.*;
37 import org.eclipse.team.internal.ui.synchronize.*;
38 import org.eclipse.team.ui.ISharedImages;
39 import org.eclipse.team.ui.TeamUI;
40 import org.eclipse.team.ui.mapping.*;
41 import org.eclipse.team.ui.synchronize.*;
42 import org.eclipse.ui.forms.events.HyperlinkAdapter;
43 import org.eclipse.ui.forms.events.HyperlinkEvent;
44 import org.eclipse.ui.forms.widgets.Hyperlink;
45
46 public class DiffTreeChangesSection extends ForwardingChangesSection implements IDiffChangeListener, IPropertyChangeListener, IEmptyTreeListener {
47
48     private ISynchronizationContext context;
49     private IStatus[] errors;
50     private boolean showingError;
51     
52     public interface ITraversalFactory {
53         ResourceTraversal[] getTraversals(ISynchronizationScope scope);
54     }
55
56     public DiffTreeChangesSection(Composite parent, AbstractSynchronizePage page, ISynchronizePageConfiguration configuration) {
57         super(parent, page, configuration);
58         context = (ISynchronizationContext)configuration.getProperty(ITeamContentProviderManager.P_SYNCHRONIZATION_CONTEXT);
59         context.getDiffTree().addDiffChangeListener(this);
60         getConfiguration().addPropertyChangeListener(this);
61         Platform.getJobManager().addJobChangeListener(new JobChangeAdapter() {
62             public void running(IJobChangeEvent event) {
63                 if (isJobOfInterest(event.getJob())) {
64                     if (context.getDiffTree().isEmpty())
65                         calculateDescription();
66                 }
67             }
68             private boolean isJobOfInterest(Job job) {
69                 if (job.belongsTo(getConfiguration().getParticipant()))
70                     return true;
71                 SubscriberDiffTreeEventHandler handler = getHandler();
72                 if (handler != null && handler.getEventHandlerJob() == job)
73                     return true;
74                 return false;
75             }
76             public void done(IJobChangeEvent event) {
77                 if (isJobOfInterest(event.getJob())) {
78                     if (context.getDiffTree().isEmpty())
79                         calculateDescription();
80                 }
81             }
82         });
83     }
84
85     public void dispose() {
86         context.getDiffTree().removeDiffChangeListener(this);
87         getConfiguration().removePropertyChangeListener(this);
88         super.dispose();
89     }
90     
91     protected int getChangesCount() {
92         return context.getDiffTree().size();
93     }
94
95     protected long getChangesInMode(int candidateMode) {
96         long numChanges;
97         long numConflicts = context.getDiffTree().countFor(IThreeWayDiff.CONFLICTING, IThreeWayDiff.DIRECTION_MASK);
98         switch (candidateMode) {
99         case ISynchronizePageConfiguration.CONFLICTING_MODE:
100             numChanges = numConflicts;
101             break;
102         case ISynchronizePageConfiguration.OUTGOING_MODE:
103             numChanges = numConflicts + context.getDiffTree().countFor(IThreeWayDiff.OUTGOING, IThreeWayDiff.DIRECTION_MASK);
104             break;
105         case ISynchronizePageConfiguration.INCOMING_MODE:
106             numChanges = numConflicts + context.getDiffTree().countFor(IThreeWayDiff.INCOMING, IThreeWayDiff.DIRECTION_MASK);
107             break;
108         case ISynchronizePageConfiguration.BOTH_MODE:
109             numChanges = numConflicts + context.getDiffTree().countFor(IThreeWayDiff.INCOMING, IThreeWayDiff.DIRECTION_MASK)
110                 + context.getDiffTree().countFor(IThreeWayDiff.OUTGOING, IThreeWayDiff.DIRECTION_MASK);
111             break;
112         default:
113             numChanges = 0;
114             break;
115         }
116         return numChanges;
117     }
118     
119     protected boolean hasChangesInMode(String JavaDoc id, ISynchronizationCompareAdapter adapter, int candidateMode) {
120         switch (candidateMode) {
121         case ISynchronizePageConfiguration.CONFLICTING_MODE:
122             return hasChangesFor(id, adapter, context, new int[] { IThreeWayDiff.CONFLICTING }, IThreeWayDiff.DIRECTION_MASK);
123         case ISynchronizePageConfiguration.OUTGOING_MODE:
124             return hasChangesFor(id, adapter, context, new int[] { IThreeWayDiff.CONFLICTING, IThreeWayDiff.OUTGOING }, IThreeWayDiff.DIRECTION_MASK);
125         case ISynchronizePageConfiguration.INCOMING_MODE:
126             return hasChangesFor(id, adapter, context, new int[] { IThreeWayDiff.CONFLICTING, IThreeWayDiff.INCOMING }, IThreeWayDiff.DIRECTION_MASK);
127         case ISynchronizePageConfiguration.BOTH_MODE:
128             return hasChangesFor(id, adapter, context, new int[] { IThreeWayDiff.CONFLICTING, IThreeWayDiff.INCOMING, IThreeWayDiff.OUTGOING }, IThreeWayDiff.DIRECTION_MASK);
129         }
130         return false;
131     }
132
133     private boolean hasChangesFor(String JavaDoc id, ISynchronizationCompareAdapter adapter, ISynchronizationContext context, int[] states, int mask) {
134         ITraversalFactory factory = (ITraversalFactory)Utils.getAdapter(adapter, ITraversalFactory.class);
135         ResourceTraversal[] traversals;
136         if (factory == null) {
137             traversals = context.getScope().getTraversals(id);
138         } else {
139             traversals = factory.getTraversals(context.getScope());
140         }
141         return (context.getDiffTree().hasMatchingDiffs(traversals, FastDiffFilter.getStateFilter(states, mask)));
142     }
143
144     protected long getVisibleChangesCount() {
145         ISynchronizePageConfiguration configuration = getConfiguration();
146         if (configuration.getComparisonType() == ISynchronizePageConfiguration.TWO_WAY) {
147             return context.getDiffTree().size();
148         }
149         int currentMode = configuration.getMode();
150         String JavaDoc id = (String JavaDoc)configuration.getProperty(ModelSynchronizeParticipant.P_VISIBLE_MODEL_PROVIDER);
151         if (id != null && !id.equals(ModelSynchronizeParticipant.ALL_MODEL_PROVIDERS_VISIBLE)) {
152             try {
153                 IModelProviderDescriptor desc = ModelProvider.getModelProviderDescriptor(id);
154                 ISynchronizationCompareAdapter adapter = Utils.getCompareAdapter(desc.getModelProvider());
155                 if (adapter != null) {
156                     return hasChangesInMode(desc.getId(), adapter, getConfiguration().getMode()) ? -1 : 0;
157                 }
158             } catch (CoreException e) {
159                 TeamUIPlugin.log(e);
160             }
161             // Use the view state to indicate whether there are visible changes
162
return isViewerEmpty() ? 0 : -1;
163         }
164         return getChangesInMode(currentMode);
165     }
166
167     protected int getCandidateMode() {
168         SynchronizePageConfiguration configuration = (SynchronizePageConfiguration)getConfiguration();
169         long outgoingChanges = context.getDiffTree().countFor(IThreeWayDiff.OUTGOING, IThreeWayDiff.DIRECTION_MASK);
170         if (outgoingChanges > 0) {
171             if (configuration.isModeSupported(ISynchronizePageConfiguration.OUTGOING_MODE)) {
172                 return ISynchronizePageConfiguration.OUTGOING_MODE;
173             }
174             if (configuration.isModeSupported(ISynchronizePageConfiguration.BOTH_MODE)) {
175                 return ISynchronizePageConfiguration.BOTH_MODE;
176             }
177         }
178         long incomingChanges = context.getDiffTree().countFor(IThreeWayDiff.INCOMING, IThreeWayDiff.DIRECTION_MASK);
179         if (incomingChanges > 0) {
180             if (configuration.isModeSupported(ISynchronizePageConfiguration.INCOMING_MODE)) {
181                 return ISynchronizePageConfiguration.INCOMING_MODE;
182             }
183             if (configuration.isModeSupported(ISynchronizePageConfiguration.BOTH_MODE)) {
184                 return ISynchronizePageConfiguration.BOTH_MODE;
185             }
186         }
187         return configuration.getMode();
188     }
189
190     public void diffsChanged(IDiffChangeEvent event, IProgressMonitor monitor) {
191         IStatus[] errors = event.getErrors();
192         if (errors.length > 0) {
193             this.errors = errors;
194         }
195         calculateDescription();
196     }
197
198     /* (non-Javadoc)
199      * @see org.eclipse.team.core.diff.IDiffChangeListener#propertyChanged(int, org.eclipse.core.runtime.IPath[])
200      */

201     public void propertyChanged(IDiffTree tree, int property, IPath[] paths) {
202         // Do nothing
203
}
204     
205     public void propertyChange(PropertyChangeEvent event) {
206         if (event.getProperty().equals(ISynchronizePageConfiguration.P_MODE)
207                 || event.getProperty().equals(ModelSynchronizeParticipant.P_VISIBLE_MODEL_PROVIDER)) {
208             calculateDescription();
209         }
210     }
211     
212     protected Composite getEmptyChangesComposite(Composite parent) {
213         if (context.getDiffTree().isEmpty()) {
214             SubscriberDiffTreeEventHandler handler = getHandler();
215             if (handler != null && handler.getState() == SubscriberDiffTreeEventHandler.STATE_STARTED) {
216                 // The context has not been initialized yet
217
return getInitializationPane(parent);
218             }
219             if (isRefreshRunning() || (handler != null && handler.getEventHandlerJob().getState() != Job.NONE)) {
220                 return getInitializingMessagePane(parent);
221             }
222         } else {
223             ISynchronizePageConfiguration configuration = getConfiguration();
224             String JavaDoc id = (String JavaDoc)configuration.getProperty(ModelSynchronizeParticipant.P_VISIBLE_MODEL_PROVIDER);
225             if (id == null)
226                 id = ModelSynchronizeParticipant.P_VISIBLE_MODEL_PROVIDER;
227             if (id.equals(ModelSynchronizeParticipant.ALL_MODEL_PROVIDERS_VISIBLE)) {
228                 if (getChangesInMode(getConfiguration().getMode()) > 0 && isAtLeastOneProviderDisabled()) {
229                     // There are changes in this mode but they are not visible so enable
230
// all providers
231
return createEnableParticipantModelProvidersPane(parent);
232                 }
233             } else {
234                 // A particular model is active so we need to look for a model that has changes in this
235
// same mode before offering to change modes.
236
ModelProvider[] providers =findModelsWithChangesInMode(getConfiguration().getMode());
237                 ModelProvider currentProvider = null;
238                 for (int i = 0; i < providers.length; i++) {
239                     ModelProvider provider = providers[i];
240                     if (isEnabled(provider)) {
241                         if (provider.getDescriptor().getId().equals(id)) {
242                             currentProvider = provider;
243                         } else {
244                             return getPointerToModel(parent, provider, id);
245                         }
246                     }
247                 }
248                 if (currentProvider != null || providers.length > 0) {
249                     // The current provider has changes but the view is empty
250
// or there is a disabled provider with changes
251
// This is an error so offer to enable and show all models
252
return createEnableParticipantModelProvidersPane(parent);
253                 }
254             }
255         }
256         return super.getEmptyChangesComposite(parent);
257     }
258     
259     private boolean isAtLeastOneProviderDisabled() {
260         ModelProvider[] providers =findModelsWithChangesInMode(getConfiguration().getMode());
261         for (int i = 0; i < providers.length; i++) {
262             ModelProvider provider = providers[i];
263             if (!isEnabled(provider)) {
264                 return true;
265             }
266         }
267         return false;
268     }
269
270     private ModelProvider[] findModelsWithChangesInMode(int mode) {
271         ModelProvider[] providers =context.getScope().getModelProviders();
272         providers = ModelOperation.sortByExtension(providers);
273         List JavaDoc result = new ArrayList();
274         for (int i = 0; i < providers.length; i++) {
275             ModelProvider provider = providers[i];
276             ISynchronizationCompareAdapter adapter = Utils.getCompareAdapter(provider);
277             if (adapter != null) {
278                 boolean hasChanges = hasChangesInMode(provider.getId(), adapter, getConfiguration().getMode());
279                 if (hasChanges) {
280                     result.add(provider);
281                 }
282             }
283         }
284         return (ModelProvider[]) result.toArray(new ModelProvider[result.size()]);
285     }
286
287     private boolean isEnabled(ModelProvider provider) {
288         ITeamContentProviderDescriptor desc = TeamUI.getTeamContentProviderManager().getDescriptor(provider.getId());
289         return (desc != null && desc.isEnabled());
290     }
291
292     private Composite createEnableParticipantModelProvidersPane(Composite parent) {
293         Composite composite = new Composite(parent, SWT.NONE);
294         composite.setBackground(getBackgroundColor());
295         GridLayout layout = new GridLayout();
296         layout.numColumns = 2;
297         composite.setLayout(layout);
298         GridData data = new GridData(GridData.FILL_BOTH);
299         data.grabExcessVerticalSpace = true;
300         composite.setLayoutData(data);
301
302         String JavaDoc message;
303         int changesCount = getChangesCount();
304         if (changesCount == 1) {
305             message = TeamUIMessages.DiffTreeChangesSection_8;
306         } else {
307             message = NLS.bind(TeamUIMessages.DiffTreeChangesSection_9, new Integer JavaDoc(changesCount));
308         }
309         final ITeamContentProviderDescriptor[] descriptors = getEnabledContentDescriptors();
310         if (descriptors.length == 0)
311             message = NLS.bind(TeamUIMessages.DiffTreeChangesSection_10, message);
312         else
313             message = NLS.bind(TeamUIMessages.DiffTreeChangesSection_11, message);
314         
315         createDescriptionLabel(composite, message);
316         
317         Label warning = new Label(composite, SWT.NONE);
318         warning.setImage(TeamUIPlugin.getPlugin().getImage(ISharedImages.IMG_WARNING_OVR));
319         
320         Hyperlink link = getForms().createHyperlink(composite, TeamUIMessages.DiffTreeChangesSection_12, SWT.WRAP);
321         link.addHyperlinkListener(new HyperlinkAdapter() {
322             public void linkActivated(HyperlinkEvent e) {
323                 ModelSynchronizeParticipant participant = (ModelSynchronizeParticipant)getConfiguration().getParticipant();
324                 ModelProvider[] providers = participant.getEnabledModelProviders();
325                 Set toEnable = new HashSet();
326                 toEnable.addAll(Arrays.asList(descriptors));
327                 for (int i = 0; i < providers.length; i++) {
328                     ModelProvider provider = providers[i];
329                     ITeamContentProviderDescriptor desc = TeamUI.getTeamContentProviderManager().getDescriptor(provider.getId());
330                     if (desc != null && !desc.isEnabled()) {
331                         toEnable.add(desc);
332                     }
333                 }
334                 TeamUI.getTeamContentProviderManager().setEnabledDescriptors(
335                         (ITeamContentProviderDescriptor[]) toEnable
336                                 .toArray(new ITeamContentProviderDescriptor[toEnable.size()]));
337                 getConfiguration().setProperty(ModelSynchronizeParticipant.P_VISIBLE_MODEL_PROVIDER, ModelSynchronizeParticipant.ALL_MODEL_PROVIDERS_VISIBLE );
338
339             }
340         });
341         getForms().getHyperlinkGroup().add(link);
342         
343         return composite;
344     }
345
346     private ITeamContentProviderDescriptor[] getEnabledContentDescriptors() {
347         ModelSynchronizeParticipant participant = (ModelSynchronizeParticipant)getConfiguration().getParticipant();
348         ModelProvider[] providers = participant.getEnabledModelProviders();
349         Set result = new HashSet();
350         for (int i = 0; i < providers.length; i++) {
351             ModelProvider provider = providers[i];
352             ITeamContentProviderDescriptor desc = TeamUI.getTeamContentProviderManager().getDescriptor(provider.getId());
353             if (desc != null && desc.isEnabled())
354                 result.add(desc);
355         }
356         return (ITeamContentProviderDescriptor[]) result.toArray(new ITeamContentProviderDescriptor[result.size()]);
357     }
358
359     private Composite getInitializationPane(Composite parent) {
360         Composite composite = new Composite(parent, SWT.NONE);
361         composite.setBackground(getBackgroundColor());
362         GridLayout layout = new GridLayout();
363         layout.numColumns = 2;
364         composite.setLayout(layout);
365         GridData data = new GridData(GridData.FILL_BOTH);
366         data.grabExcessVerticalSpace = true;
367         composite.setLayoutData(data);
368
369         createDescriptionLabel(composite, NLS.bind(TeamUIMessages.DiffTreeChangesSection_3, new String JavaDoc[] { Utils.shortenText(SynchronizeView.MAX_NAME_LENGTH, getConfiguration().getParticipant().getName()) }));
370
371         final boolean[] remember = new boolean[] { false };
372         final PreferenceStore store = (PreferenceStore) getConfiguration()
373             .getProperty(StartupPreferencePage.STARTUP_PREFERENCES);
374         Hyperlink link = getForms().createHyperlink(composite, TeamUIMessages.DiffTreeChangesSection_4, SWT.WRAP);
375         link.addHyperlinkListener(new HyperlinkAdapter() {
376             public void linkActivated(HyperlinkEvent e) {
377                 if (remember[0] && store != null) {
378                     store.putValue(StartupPreferencePage.PROP_STARTUP_ACTION, StartupPreferencePage.STARTUP_ACTION_POPULATE);
379                 }
380                 getHandler().initializeIfNeeded();
381             }
382         });
383         getForms().getHyperlinkGroup().add(link);
384         
385         link = getForms().createHyperlink(composite, TeamUIMessages.DiffTreeChangesSection_5, SWT.WRAP);
386         link.addHyperlinkListener(new HyperlinkAdapter() {
387             public void linkActivated(HyperlinkEvent e) {
388                 if (remember[0] && store != null) {
389                     store.putValue(StartupPreferencePage.PROP_STARTUP_ACTION, StartupPreferencePage.STARTUP_ACTION_SYNCHRONIZE);
390                 }
391                 getConfiguration().getParticipant().run(getConfiguration().getSite().getPart());
392             }
393         });
394         getForms().getHyperlinkGroup().add(link);
395         
396         if (store != null) {
397             final Button rememberButton = getForms().createButton(composite, TeamUIMessages.DiffTreeChangesSection_14, SWT.CHECK);
398             rememberButton.setToolTipText(TeamUIMessages.DiffTreeChangesSection_14);
399             data = new GridData(GridData.FILL_HORIZONTAL);
400             data.horizontalSpan = 2;
401             data.horizontalIndent=5;
402             data.verticalIndent=5;
403             data.widthHint = 100;
404             rememberButton.setLayoutData(data);
405             rememberButton.addSelectionListener(new SelectionListener() {
406                 public void widgetSelected(SelectionEvent e) {
407                     remember[0] = rememberButton.getSelection();
408                 }
409                 public void widgetDefaultSelected(SelectionEvent e) {
410                     // Do nothing
411
}
412             });
413         }
414         
415         return composite;
416     }
417
418     private Composite getInitializingMessagePane(Composite parent) {
419         Composite composite = new Composite(parent, SWT.NONE);
420         composite.setBackground(getBackgroundColor());
421         GridLayout layout = new GridLayout();
422         layout.numColumns = 2;
423         composite.setLayout(layout);
424         GridData data = new GridData(GridData.FILL_BOTH);
425         data.grabExcessVerticalSpace = true;
426         composite.setLayoutData(data);
427         if (isRefreshRunning()) {
428             createDescriptionLabel(composite,NLS.bind(TeamUIMessages.DiffTreeChangesSection_6, new String JavaDoc[] { Utils.shortenText(SynchronizeView.MAX_NAME_LENGTH, getConfiguration().getParticipant().getName()) }));
429         } else {
430             createDescriptionLabel(composite,NLS.bind(TeamUIMessages.DiffTreeChangesSection_7, new String JavaDoc[] { Utils.shortenText(SynchronizeView.MAX_NAME_LENGTH, getConfiguration().getParticipant().getName()) }));
431         }
432         return composite;
433     }
434
435     private boolean isRefreshRunning() {
436         return Platform.getJobManager().find(getConfiguration().getParticipant()).length > 0;
437     }
438
439     private SubscriberDiffTreeEventHandler getHandler() {
440         return (SubscriberDiffTreeEventHandler)Utils.getAdapter(context, SubscriberDiffTreeEventHandler.class);
441     }
442
443     private Composite getPointerToModel(Composite parent, final ModelProvider provider, String JavaDoc oldId) {
444         Composite composite = new Composite(parent, SWT.NONE);
445         composite.setBackground(getBackgroundColor());
446         GridLayout layout = new GridLayout();
447         layout.numColumns = 2;
448         composite.setLayout(layout);
449         GridData data = new GridData(GridData.FILL_BOTH);
450         data.grabExcessVerticalSpace = true;
451         composite.setLayoutData(data);
452
453         IModelProviderDescriptor oldDesc = ModelProvider.getModelProviderDescriptor(oldId);
454         String JavaDoc message;
455         String JavaDoc modeToString = Utils.modeToString(getConfiguration().getMode());
456         message = NLS.bind(TeamUIMessages.DiffTreeChangesSection_0, new String JavaDoc[] {
457                     provider.getDescriptor().getLabel(),
458                     modeToString });
459         message = NLS.bind(TeamUIMessages.DiffTreeChangesSection_1, new String JavaDoc[] { modeToString, oldDesc.getLabel(), message });
460         
461         createDescriptionLabel(composite, message);
462         
463         Label warning = new Label(composite, SWT.NONE);
464         warning.setImage(TeamUIPlugin.getPlugin().getImage(ISharedImages.IMG_WARNING_OVR));
465         
466         Hyperlink link = getForms().createHyperlink(composite, NLS.bind(TeamUIMessages.DiffTreeChangesSection_2, new String JavaDoc[] { provider.getDescriptor().getLabel() }), SWT.WRAP);
467         link.addHyperlinkListener(new HyperlinkAdapter() {
468             public void linkActivated(HyperlinkEvent e) {
469                 getConfiguration().setProperty(ModelSynchronizeParticipant.P_VISIBLE_MODEL_PROVIDER, provider.getDescriptor().getId() );
470             }
471         });
472         getForms().getHyperlinkGroup().add(link);
473         
474         new Label(composite, SWT.NONE);
475         Hyperlink link2 = getForms().createHyperlink(composite, TeamUIMessages.DiffTreeChangesSection_13, SWT.WRAP);
476         link2.addHyperlinkListener(new HyperlinkAdapter() {
477             public void linkActivated(HyperlinkEvent e) {
478                 getConfiguration().setProperty(ModelSynchronizeParticipant.P_VISIBLE_MODEL_PROVIDER, ModelSynchronizeParticipant.ALL_MODEL_PROVIDERS_VISIBLE );
479             }
480         });
481         getForms().getHyperlinkGroup().add(link2);
482         
483         return composite;
484     }
485
486     public void treeEmpty(TreeViewer viewer) {
487         handleEmptyViewer();
488     }
489
490     private void handleEmptyViewer() {
491         // Override stand behavior to do our best to show something
492
TeamUIPlugin.getStandardDisplay().asyncExec(new Runnable JavaDoc() {
493             public void run() {
494                 if (!getContainer().isDisposed())
495                     updatePage(getEmptyChangesComposite(getContainer()));
496             }
497         });
498     }
499     
500     protected void calculateDescription() {
501         if (errors != null && errors.length > 0) {
502             if (!showingError) {
503                 TeamUIPlugin.getStandardDisplay().asyncExec(new Runnable JavaDoc() {
504                     public void run() {
505                         updatePage(getErrorComposite(getContainer()));
506                         showingError = true;
507                     }
508                 });
509             }
510             return;
511         }
512         showingError = false;
513         if (isViewerEmpty()) {
514             handleEmptyViewer();
515         } else {
516             super.calculateDescription();
517         }
518     }
519
520     private boolean isViewerEmpty() {
521         Viewer v = getPage().getViewer();
522         if (v instanceof CommonViewerAdvisor.NavigableCommonViewer) {
523             CommonViewerAdvisor.NavigableCommonViewer cv = (CommonViewerAdvisor.NavigableCommonViewer) v;
524             return cv.isEmpty();
525         }
526         return false;
527     }
528
529     public void notEmpty(TreeViewer viewer) {
530         calculateDescription();
531     }
532     
533     private Composite getErrorComposite(Composite parent) {
534         Composite composite = new Composite(parent, SWT.NONE);
535         composite.setBackground(getBackgroundColor());
536         GridLayout layout = new GridLayout();
537         layout.numColumns = 2;
538         composite.setLayout(layout);
539         GridData data = new GridData(GridData.FILL_BOTH);
540         data.grabExcessVerticalSpace = true;
541         composite.setLayoutData(data);
542
543         createDescriptionLabel(composite, NLS.bind(TeamUIMessages.ChangesSection_10, new String JavaDoc[] { Utils.shortenText(SynchronizeView.MAX_NAME_LENGTH, getConfiguration().getParticipant().getName()) }));
544
545         Hyperlink link = getForms().createHyperlink(composite, TeamUIMessages.ChangesSection_8, SWT.WRAP);
546         link.addHyperlinkListener(new HyperlinkAdapter() {
547             public void linkActivated(HyperlinkEvent e) {
548                 showErrors();
549             }
550         });
551         getForms().getHyperlinkGroup().add(link);
552         
553         link = getForms().createHyperlink(composite, TeamUIMessages.ChangesSection_9, SWT.WRAP);
554         link.addHyperlinkListener(new HyperlinkAdapter() {
555             public void linkActivated(HyperlinkEvent e) {
556                 errors = null;
557                 calculateDescription();
558                 SubscriberDiffTreeEventHandler handler = getHandler();
559                 if (handler != null)
560                     handler.initializeIfNeeded();
561                 else
562                     getConfiguration().getParticipant().run(getConfiguration().getSite().getPart());
563             }
564         });
565         getForms().getHyperlinkGroup().add(link);
566         
567         return composite;
568     }
569
570     /* private */ void showErrors() {
571         if (errors != null) {
572             IStatus[] status = errors;
573             String JavaDoc title = TeamUIMessages.ChangesSection_11;
574             if (status.length == 1) {
575                 ErrorDialog.openError(getShell(), title, status[0].getMessage(), status[0]);
576             } else {
577                 MultiStatus multi = new MultiStatus(TeamUIPlugin.ID, 0, status, TeamUIMessages.ChangesSection_12, null);
578                 ErrorDialog.openError(getShell(), title, null, multi);
579             }
580         }
581     }
582 }
583
Popular Tags