KickJava   Java API By Example, From Geeks To Geeks.

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


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.synchronize;
12
13 import org.eclipse.osgi.util.NLS;
14 import org.eclipse.swt.SWT;
15 import org.eclipse.swt.layout.GridData;
16 import org.eclipse.swt.layout.GridLayout;
17 import org.eclipse.swt.widgets.*;
18 import org.eclipse.team.internal.ui.*;
19 import org.eclipse.team.ui.ISharedImages;
20 import org.eclipse.team.ui.synchronize.ISynchronizePageConfiguration;
21 import org.eclipse.ui.forms.events.HyperlinkAdapter;
22 import org.eclipse.ui.forms.events.HyperlinkEvent;
23 import org.eclipse.ui.forms.widgets.Hyperlink;
24
25 /**
26  * A changes section that points the user to a mode that has changes when the current mode
27  * is empty.
28  */

29 public abstract class ForwardingChangesSection extends ChangesSection {
30
31     /**
32      * Shows message to user is no changes are to be shown in the diff
33      * tree viewer.
34      */

35     private Composite messageArea;
36     
37     public ForwardingChangesSection(Composite parent, AbstractSynchronizePage page, ISynchronizePageConfiguration configuration) {
38         super(parent, page, configuration);
39     }
40
41     /* (non-Javadoc)
42      * @see org.eclipse.team.internal.ui.synchronize.ChangesSection#initializeChangesViewer()
43      */

44     protected void initializeChangesViewer() {
45         calculateDescription();
46     }
47     
48     protected void calculateDescription() {
49         if (getContainer().isDisposed())
50             return;
51         if(getVisibleChangesCount() == 0) {
52             TeamUIPlugin.getStandardDisplay().asyncExec(new Runnable JavaDoc() {
53                 public void run() {
54                     if (!getContainer().isDisposed())
55                         updatePage(getEmptyChangesComposite(getContainer()));
56                 }
57             });
58         } else {
59             TeamUIPlugin.getStandardDisplay().asyncExec(new Runnable JavaDoc() {
60                 public void run() {
61                     updatePage(null);
62                 }
63             });
64         }
65     }
66     
67     protected void updatePage(Composite message) {
68         if (getContainer().isDisposed()) return;
69         if(messageArea != null) {
70             messageArea.dispose();
71             messageArea = null;
72         }
73         messageArea = message;
74         if (message == null) {
75             Control control = getChangesViewer().getControl();
76             if (!getContainer().isDisposed() && !control.isDisposed()) {
77                 getContainer().showPage(control);
78             }
79         } else {
80             getContainer().showPage(messageArea);
81         }
82     }
83     
84     protected Composite getEmptyChangesComposite(Composite parent) {
85         Composite composite = new Composite(parent, SWT.NONE);
86         composite.setBackground(getBackgroundColor());
87         GridLayout layout = new GridLayout();
88         layout.numColumns = 2;
89         composite.setLayout(layout);
90         GridData data = new GridData(GridData.FILL_BOTH);
91         data.grabExcessVerticalSpace = true;
92         composite.setLayoutData(data);
93         
94         if(! isThreeWay()) {
95             createDescriptionLabel(composite,NLS.bind(TeamUIMessages.ChangesSection_noChanges, new String JavaDoc[] { Utils.shortenText(SynchronizeView.MAX_NAME_LENGTH, getConfiguration().getParticipant().getName()) }));
96             return composite;
97         }
98         
99         int allChanges = getChangesCount();
100         long visibleChanges = getVisibleChangesCount();
101         
102         if(visibleChanges == 0 && allChanges != 0) {
103             final int candidateMode = getCandidateMode();
104             int currentMode = getConfiguration().getMode();
105             if (candidateMode != currentMode) {
106                 long numChanges = getChangesInMode(candidateMode);
107                 if (numChanges > 0) {
108                     String JavaDoc message;
109                     if(numChanges > 1) {
110                         message = NLS.bind(TeamUIMessages.ChangesSection_filterHidesPlural, new String JavaDoc[] { Long.toString(numChanges), Utils.modeToString(candidateMode) });
111                     } else {
112                         message = NLS.bind(TeamUIMessages.ChangesSection_filterHidesSingular, new String JavaDoc[] { Long.toString(numChanges), Utils.modeToString(candidateMode) });
113                     }
114                     message = NLS.bind(TeamUIMessages.ChangesSection_filterHides, new String JavaDoc[] { Utils.modeToString(getConfiguration().getMode()), message });
115                     
116                     Label warning = new Label(composite, SWT.NONE);
117                     warning.setImage(TeamUIPlugin.getPlugin().getImage(ISharedImages.IMG_WARNING_OVR));
118                     
119                     Hyperlink link = getForms().createHyperlink(composite, NLS.bind(TeamUIMessages.ChangesSection_filterChange, new String JavaDoc[] { Utils.modeToString(candidateMode) }), SWT.WRAP);
120                     link.addHyperlinkListener(new HyperlinkAdapter() {
121                         public void linkActivated(HyperlinkEvent e) {
122                             getConfiguration().setMode(candidateMode);
123                         }
124                     });
125                     getForms().getHyperlinkGroup().add(link);
126                     createDescriptionLabel(composite, message);
127                     return composite;
128                 }
129             }
130         }
131         // There is no other mode that can be shown so just indicate that there are no changes
132
createDescriptionLabel(composite,NLS.bind(TeamUIMessages.ChangesSection_noChanges, new String JavaDoc[] { Utils.shortenText(SynchronizeView.MAX_NAME_LENGTH, getConfiguration().getParticipant().getName()) })); //
133
return composite;
134     }
135     
136     protected Label createDescriptionLabel(Composite parent, String JavaDoc text) {
137         Label description = new Label(parent, SWT.WRAP);
138         GridData data = new GridData(GridData.FILL_HORIZONTAL);
139         data.horizontalSpan = 2;
140         data.widthHint = 100;
141         description.setLayoutData(data);
142         description.setText(text);
143         description.setBackground(getBackgroundColor());
144         return description;
145     }
146     
147     protected abstract int getChangesCount();
148
149     protected abstract long getChangesInMode(int candidateMode);
150
151     protected abstract long getVisibleChangesCount();
152     
153     protected abstract int getCandidateMode();
154 }
155
Popular Tags