1 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 29 public abstract class ForwardingChangesSection extends ChangesSection { 30 31 35 private Composite messageArea; 36 37 public ForwardingChangesSection(Composite parent, AbstractSynchronizePage page, ISynchronizePageConfiguration configuration) { 38 super(parent, page, configuration); 39 } 40 41 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 () { 53 public void run() { 54 if (!getContainer().isDisposed()) 55 updatePage(getEmptyChangesComposite(getContainer())); 56 } 57 }); 58 } else { 59 TeamUIPlugin.getStandardDisplay().asyncExec(new Runnable () { 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 [] { 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 message; 109 if(numChanges > 1) { 110 message = NLS.bind(TeamUIMessages.ChangesSection_filterHidesPlural, new String [] { Long.toString(numChanges), Utils.modeToString(candidateMode) }); 111 } else { 112 message = NLS.bind(TeamUIMessages.ChangesSection_filterHidesSingular, new String [] { Long.toString(numChanges), Utils.modeToString(candidateMode) }); 113 } 114 message = NLS.bind(TeamUIMessages.ChangesSection_filterHides, new String [] { 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 [] { 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 createDescriptionLabel(composite,NLS.bind(TeamUIMessages.ChangesSection_noChanges, new String [] { Utils.shortenText(SynchronizeView.MAX_NAME_LENGTH, getConfiguration().getParticipant().getName()) })); return composite; 134 } 135 136 protected Label createDescriptionLabel(Composite parent, String 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 |