diff options
7 files changed, 290 insertions, 117 deletions
diff --git a/bundles/org.eclipse.team.core/src/org/eclipse/team/core/diff/IDiffTree.java b/bundles/org.eclipse.team.core/src/org/eclipse/team/core/diff/IDiffTree.java index 2766a90d4..e9698234e 100644 --- a/bundles/org.eclipse.team.core/src/org/eclipse/team/core/diff/IDiffTree.java +++ b/bundles/org.eclipse.team.core/src/org/eclipse/team/core/diff/IDiffTree.java @@ -94,6 +94,12 @@ public interface IDiffTree { public IPath[] getChildren(IPath parent); /** + * Return the number of diffs contained in the tree. + * @return the number of diffs contained in the tree + */ + public int size(); + + /** * Return whether the set is empty. * @return whether the set is empty */ diff --git a/bundles/org.eclipse.team.core/src/org/eclipse/team/core/diff/provider/DiffTree.java b/bundles/org.eclipse.team.core/src/org/eclipse/team/core/diff/provider/DiffTree.java index 2b552d838..d1870a106 100644 --- a/bundles/org.eclipse.team.core/src/org/eclipse/team/core/diff/provider/DiffTree.java +++ b/bundles/org.eclipse.team.core/src/org/eclipse/team/core/diff/provider/DiffTree.java @@ -275,7 +275,7 @@ public class DiffTree implements IDiffTree { private void internalRemove(IDiffNode delta) { Assert.isTrue(!lockedForModification); IDiffNode oldDiff = (IDiffNode)pathTree.get(delta.getPath()); - if(oldDiff == null) { + if(oldDiff != null) { statistics.remove(oldDiff); } pathTree.remove(delta.getPath()); @@ -319,4 +319,11 @@ public class DiffTree implements IDiffTree { return statistics.countFor(state, mask); } + /* (non-Javadoc) + * @see org.eclipse.team.core.diff.IDiffTree#size() + */ + public int size() { + return pathTree.size(); + } + } diff --git a/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/mapping/ModelSynchronizePage.java b/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/mapping/ModelSynchronizePage.java index 023d62d7f..f4ba3cf83 100644 --- a/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/mapping/ModelSynchronizePage.java +++ b/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/mapping/ModelSynchronizePage.java @@ -90,7 +90,7 @@ public class ModelSynchronizePage extends AbstractSynchronizePage { * @see org.eclipse.team.internal.ui.synchronize.AbstractSynchronizePage#createChangesSection() */ protected ChangesSection createChangesSection(Composite parent) { - return new ChangesSection(parent, this, getConfiguration()); + return new DiffTreeChangesSection(parent, this, getConfiguration()); } } diff --git a/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/synchronize/ChangesSection.java b/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/synchronize/ChangesSection.java index deadcbf1a..a49128866 100644 --- a/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/synchronize/ChangesSection.java +++ b/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/synchronize/ChangesSection.java @@ -126,4 +126,8 @@ public class ChangesSection extends Composite { public Viewer getChangesViewer() { return changesViewer; } + + protected boolean isThreeWay() { + return ISynchronizePageConfiguration.THREE_WAY.equals(getConfiguration().getComparisonType()); + } } diff --git a/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/synchronize/DiffTreeChangesSection.java b/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/synchronize/DiffTreeChangesSection.java new file mode 100644 index 000000000..386e7da99 --- /dev/null +++ b/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/synchronize/DiffTreeChangesSection.java @@ -0,0 +1,101 @@ +/******************************************************************************* + * Copyright (c) 2006 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.team.internal.ui.synchronize; + +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.jface.util.IPropertyChangeListener; +import org.eclipse.jface.util.PropertyChangeEvent; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.team.core.diff.*; +import org.eclipse.team.core.mapping.ISynchronizationContext; +import org.eclipse.team.ui.mapping.ISynchronizationConstants; +import org.eclipse.team.ui.synchronize.ISynchronizePageConfiguration; + +public class DiffTreeChangesSection extends ForwardingChangesSection implements IDiffChangeListener, IPropertyChangeListener { + + private ISynchronizationContext context; + + public DiffTreeChangesSection(Composite parent, AbstractSynchronizePage page, ISynchronizePageConfiguration configuration) { + super(parent, page, configuration); + context = (ISynchronizationContext)configuration.getProperty(ISynchronizationConstants.P_SYNCHRONIZATION_CONTEXT); + context.getDiffTree().addDiffChangeListener(this); + getConfiguration().addPropertyChangeListener(this); + } + + public void dispose() { + context.getDiffTree().removeDiffChangeListener(this); + getConfiguration().removePropertyChangeListener(this); + super.dispose(); + } + + protected int getChangesCount() { + return context.getDiffTree().size(); + } + + protected long getChangesInMode(int candidateMode) { + long numChanges; + switch (candidateMode) { + case ISynchronizePageConfiguration.OUTGOING_MODE: + numChanges = context.getDiffTree().countFor(IThreeWayDiff.OUTGOING, IThreeWayDiff.DIRECTION_MASK); + break; + case ISynchronizePageConfiguration.INCOMING_MODE: + numChanges = context.getDiffTree().countFor(IThreeWayDiff.INCOMING, IThreeWayDiff.DIRECTION_MASK); + break; + case ISynchronizePageConfiguration.BOTH_MODE: + numChanges = context.getDiffTree().countFor(IThreeWayDiff.INCOMING, IThreeWayDiff.DIRECTION_MASK) + + context.getDiffTree().countFor(IThreeWayDiff.OUTGOING, IThreeWayDiff.DIRECTION_MASK); + break; + default: + numChanges = 0; + break; + } + return numChanges; + } + + protected long getVisibleChangesCount() { + int currentMode = getConfiguration().getMode(); + return getChangesInMode(currentMode); + } + + protected int getCandidateMode() { + SynchronizePageConfiguration configuration = (SynchronizePageConfiguration)getConfiguration(); + long outgoingChanges = context.getDiffTree().countFor(IThreeWayDiff.OUTGOING, IThreeWayDiff.DIRECTION_MASK); + if (outgoingChanges > 0) { + if (configuration.isModeSupported(ISynchronizePageConfiguration.OUTGOING_MODE)) { + return ISynchronizePageConfiguration.OUTGOING_MODE; + } + if (configuration.isModeSupported(ISynchronizePageConfiguration.BOTH_MODE)) { + return ISynchronizePageConfiguration.BOTH_MODE; + } + } + long incomingChanges = context.getDiffTree().countFor(IThreeWayDiff.INCOMING, IThreeWayDiff.DIRECTION_MASK); + if (incomingChanges > 0) { + if (configuration.isModeSupported(ISynchronizePageConfiguration.INCOMING_MODE)) { + return ISynchronizePageConfiguration.INCOMING_MODE; + } + if (configuration.isModeSupported(ISynchronizePageConfiguration.BOTH_MODE)) { + return ISynchronizePageConfiguration.BOTH_MODE; + } + } + return configuration.getMode(); + } + + public void diffChanged(IDiffChangeEvent event, IProgressMonitor monitor) { + calculateDescription(); + } + + public void propertyChange(PropertyChangeEvent event) { + if (event.getProperty().equals(ISynchronizePageConfiguration.P_MODE)) { + calculateDescription(); + } + } + +} diff --git a/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/synchronize/ForwardingChangesSection.java b/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/synchronize/ForwardingChangesSection.java new file mode 100644 index 000000000..3ad1a20ae --- /dev/null +++ b/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/synchronize/ForwardingChangesSection.java @@ -0,0 +1,151 @@ +/******************************************************************************* + * Copyright (c) 2006 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.team.internal.ui.synchronize; + +import org.eclipse.osgi.util.NLS; +import org.eclipse.swt.SWT; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.widgets.*; +import org.eclipse.team.internal.ui.*; +import org.eclipse.team.ui.ISharedImages; +import org.eclipse.team.ui.synchronize.ISynchronizePageConfiguration; +import org.eclipse.ui.forms.events.HyperlinkAdapter; +import org.eclipse.ui.forms.events.HyperlinkEvent; +import org.eclipse.ui.forms.widgets.Hyperlink; + +/** + * A changes section that points the user to a mode that has changes when the current mode + * is empty. + */ +public abstract class ForwardingChangesSection extends ChangesSection { + + /** + * Shows message to user is no changes are to be shown in the diff + * tree viewer. + */ + private Composite messageArea; + + public ForwardingChangesSection(Composite parent, AbstractSynchronizePage page, ISynchronizePageConfiguration configuration) { + super(parent, page, configuration); + } + + /* (non-Javadoc) + * @see org.eclipse.team.internal.ui.synchronize.ChangesSection#initializeChangesViewer() + */ + protected void initializeChangesViewer() { + calculateDescription(); + } + + protected void calculateDescription() { + if(getVisibleChangesCount() == 0) { + TeamUIPlugin.getStandardDisplay().asyncExec(new Runnable() { + public void run() { + updatePage(getEmptyChangesComposite(getContainer())); + } + }); + } else { + TeamUIPlugin.getStandardDisplay().asyncExec(new Runnable() { + public void run() { + updatePage(null); + } + }); + } + } + + protected void updatePage(Composite message) { + if (getContainer().isDisposed()) return; + if(messageArea != null) { + messageArea.dispose(); + messageArea = null; + } + messageArea = message; + if (message == null) { + Control control = getChangesViewer().getControl(); + if (!getContainer().isDisposed() && !control.isDisposed()) { + getContainer().showPage(control); + } + } else { + getContainer().showPage(messageArea); + } + } + + protected Composite getEmptyChangesComposite(Composite parent) { + Composite composite = new Composite(parent, SWT.NONE); + composite.setBackground(getBackgroundColor()); + GridLayout layout = new GridLayout(); + layout.numColumns = 2; + composite.setLayout(layout); + GridData data = new GridData(GridData.FILL_BOTH); + data.grabExcessVerticalSpace = true; + composite.setLayoutData(data); + + if(! isThreeWay()) { + createDescriptionLabel(composite,NLS.bind(TeamUIMessages.ChangesSection_noChanges, new String[] { getConfiguration().getParticipant().getName() })); + return composite; + } + + int allChanges = getChangesCount(); + long visibleChanges = getVisibleChangesCount(); + + if(visibleChanges == 0 && allChanges != 0) { + final int candidateMode = getCandidateMode(); + int currentMode = getConfiguration().getMode(); + if (candidateMode != currentMode) { + long numChanges = getChangesInMode(candidateMode); + if (numChanges > 0) { + String message; + if(numChanges > 1) { + message = NLS.bind(TeamUIMessages.ChangesSection_filterHidesPlural, new String[] { Long.toString(numChanges), Utils.modeToString(candidateMode) }); + } else { + message = NLS.bind(TeamUIMessages.ChangesSection_filterHidesSingular, new String[] { Long.toString(numChanges), Utils.modeToString(candidateMode) }); + } + message = NLS.bind(TeamUIMessages.ChangesSection_filterHides, new String[] { Utils.modeToString(getConfiguration().getMode()), message }); + + Label warning = new Label(composite, SWT.NONE); + warning.setImage(TeamUIPlugin.getPlugin().getImage(ISharedImages.IMG_WARNING_OVR)); + + Hyperlink link = getForms().createHyperlink(composite, NLS.bind(TeamUIMessages.ChangesSection_filterChange, new String[] { Utils.modeToString(candidateMode) }), SWT.WRAP); + link.addHyperlinkListener(new HyperlinkAdapter() { + public void linkActivated(HyperlinkEvent e) { + getConfiguration().setMode(candidateMode); + } + }); + getForms().getHyperlinkGroup().add(link); + createDescriptionLabel(composite, message); + return composite; + } + } + } + // There is no other mode that can be shown so just indicate that there are no changes + createDescriptionLabel(composite,NLS.bind(TeamUIMessages.ChangesSection_noChanges, new String[] { getConfiguration().getParticipant().getName() })); // + return composite; + } + + protected Label createDescriptionLabel(Composite parent, String text) { + Label description = new Label(parent, SWT.WRAP); + GridData data = new GridData(GridData.FILL_HORIZONTAL); + data.horizontalSpan = 2; + data.widthHint = 100; + description.setLayoutData(data); + description.setText(text); + description.setBackground(getBackgroundColor()); + return description; + } + + protected abstract int getChangesCount(); + + protected abstract long getChangesInMode(int candidateMode); + + protected abstract long getVisibleChangesCount(); + + protected abstract int getCandidateMode(); +} diff --git a/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/synchronize/SyncInfoSetChangesSection.java b/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/synchronize/SyncInfoSetChangesSection.java index 3c737a84a..321b897ce 100644 --- a/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/synchronize/SyncInfoSetChangesSection.java +++ b/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/synchronize/SyncInfoSetChangesSection.java @@ -20,8 +20,8 @@ import org.eclipse.swt.layout.GridLayout; import org.eclipse.swt.widgets.*; import org.eclipse.team.core.ITeamStatus; import org.eclipse.team.core.synchronize.*; -import org.eclipse.team.internal.ui.*; -import org.eclipse.team.ui.ISharedImages; +import org.eclipse.team.internal.ui.TeamUIMessages; +import org.eclipse.team.internal.ui.TeamUIPlugin; import org.eclipse.team.ui.synchronize.*; import org.eclipse.ui.forms.events.HyperlinkAdapter; import org.eclipse.ui.forms.events.HyperlinkEvent; @@ -33,13 +33,7 @@ import org.eclipse.ui.forms.widgets.Hyperlink; * * @since 3.0 */ -public class SyncInfoSetChangesSection extends ChangesSection { - - /** - * Shows message to user is no changes are to be shown in the diff - * tree viewer. - */ - private Composite filteredContainer; +public class SyncInfoSetChangesSection extends ForwardingChangesSection { /** * Boolean that indicates whether the error page is being shown. @@ -104,25 +98,19 @@ public class SyncInfoSetChangesSection extends ChangesSection { * @see org.eclipse.team.internal.ui.synchronize.ChangesSection#initializeChangesViewer() */ protected void initializeChangesViewer() { - calculateDescription(); + super.initializeChangesViewer(); getConfiguration().addActionContribution(changedListener); getParticipantSyncInfoSet().addSyncSetChangedListener(subscriberListener); getVisibleSyncInfoSet().addSyncSetChangedListener(outputSetListener); } - private void calculateDescription() { + protected void calculateDescription() { SyncInfoTree syncInfoTree = getVisibleSyncInfoSet(); if (syncInfoTree.getErrors().length > 0) { if (!showingError) { TeamUIPlugin.getStandardDisplay().asyncExec(new Runnable() { public void run() { - if (getContainer().isDisposed()) return; - if(filteredContainer != null) { - filteredContainer.dispose(); - filteredContainer = null; - } - filteredContainer = getErrorComposite(getContainer()); - getContainer().showPage(filteredContainer); + updatePage(getErrorComposite(getContainer())); showingError = true; } }); @@ -131,93 +119,11 @@ public class SyncInfoSetChangesSection extends ChangesSection { } showingError = false; - if(syncInfoTree.size() == 0) { - TeamUIPlugin.getStandardDisplay().asyncExec(new Runnable() { - public void run() { - if (getContainer().isDisposed()) return; - if(filteredContainer != null) { - filteredContainer.dispose(); - filteredContainer = null; - } - filteredContainer = getEmptyChangesComposite(getContainer()); - getContainer().showPage(filteredContainer); - } - }); - } else { - TeamUIPlugin.getStandardDisplay().asyncExec(new Runnable() { - public void run() { - if(filteredContainer != null) { - filteredContainer.dispose(); - filteredContainer = null; - } - Control control = SyncInfoSetChangesSection.this.getChangesViewer().getControl(); - if (!getContainer().isDisposed() && !control.isDisposed()) { - getContainer().showPage(control); - } - } - }); - } - } - - private boolean isThreeWay() { - return ISynchronizePageConfiguration.THREE_WAY.equals(getConfiguration().getComparisonType()); - } - - private Composite getEmptyChangesComposite(Composite parent) { - Composite composite = new Composite(parent, SWT.NONE); - composite.setBackground(getBackgroundColor()); - GridLayout layout = new GridLayout(); - layout.numColumns = 2; - composite.setLayout(layout); - GridData data = new GridData(GridData.FILL_BOTH); - data.grabExcessVerticalSpace = true; - composite.setLayoutData(data); - - if(! isThreeWay()) { - createDescriptionLabel(composite,NLS.bind(TeamUIMessages.ChangesSection_noChanges, new String[] { getConfiguration().getParticipant().getName() })); - return composite; - } - - SyncInfoSet participantSet = getParticipantSyncInfoSet(); - - int allChanges = participantSet.size(); - int visibleChanges = getVisibleSyncInfoSet().size(); - - if(visibleChanges == 0 && allChanges != 0) { - final int candidateMode = getCandidateMode(participantSet); - int currentMode = getConfiguration().getMode(); - if (candidateMode != currentMode) { - long numChanges = getChangesInMode(participantSet, candidateMode); - if (numChanges > 0) { - String message; - if(numChanges > 1) { - message = NLS.bind(TeamUIMessages.ChangesSection_filterHidesPlural, new String[] { Long.toString(numChanges), Utils.modeToString(candidateMode) }); - } else { - message = NLS.bind(TeamUIMessages.ChangesSection_filterHidesSingular, new String[] { Long.toString(numChanges), Utils.modeToString(candidateMode) }); - } - message = NLS.bind(TeamUIMessages.ChangesSection_filterHides, new String[] { Utils.modeToString(getConfiguration().getMode()), message }); - - Label warning = new Label(composite, SWT.NONE); - warning.setImage(TeamUIPlugin.getPlugin().getImage(ISharedImages.IMG_WARNING_OVR)); - - Hyperlink link = getForms().createHyperlink(composite, NLS.bind(TeamUIMessages.ChangesSection_filterChange, new String[] { Utils.modeToString(candidateMode) }), SWT.WRAP); - link.addHyperlinkListener(new HyperlinkAdapter() { - public void linkActivated(HyperlinkEvent e) { - getConfiguration().setMode(candidateMode); - } - }); - getForms().getHyperlinkGroup().add(link); - createDescriptionLabel(composite, message); - return composite; - } - } - } - // There is no other mode that can be shown so just indicate that there are no changes - createDescriptionLabel(composite,NLS.bind(TeamUIMessages.ChangesSection_noChanges, new String[] { getConfiguration().getParticipant().getName() })); // - return composite; + super.calculateDescription(); } - private long getChangesInMode(SyncInfoSet participantSet, final int candidateMode) { + protected long getChangesInMode(int candidateMode) { + SyncInfoSet participantSet = getParticipantSyncInfoSet(); long numChanges; switch (candidateMode) { case ISynchronizePageConfiguration.OUTGOING_MODE: @@ -241,7 +147,8 @@ public class SyncInfoSetChangesSection extends ChangesSection { * Return the candidate mode based on the presence of unfiltered changes * and the modes supported by the page. */ - private int getCandidateMode(SyncInfoSet participantSet) { + protected int getCandidateMode() { + SyncInfoSet participantSet = getParticipantSyncInfoSet(); SynchronizePageConfiguration configuration = (SynchronizePageConfiguration)getConfiguration(); long outgoingChanges = participantSet.countFor(SyncInfo.OUTGOING, SyncInfo.DIRECTION_MASK); if (outgoingChanges > 0) { @@ -264,17 +171,6 @@ public class SyncInfoSetChangesSection extends ChangesSection { return configuration.getMode(); } - private Label createDescriptionLabel(Composite parent, String text) { - Label description = new Label(parent, SWT.WRAP); - GridData data = new GridData(GridData.FILL_HORIZONTAL); - data.horizontalSpan = 2; - data.widthHint = 100; - description.setLayoutData(data); - description.setText(text); - description.setBackground(getBackgroundColor()); - return description; - } - public void dispose() { super.dispose(); getConfiguration().removeActionContribution(changedListener); @@ -328,6 +224,14 @@ public class SyncInfoSetChangesSection extends ChangesSection { } } + protected int getChangesCount() { + return getParticipantSyncInfoSet().size(); + } + + protected long getVisibleChangesCount() { + return getVisibleSyncInfoSet().size(); + } + /* * Return the sync info set that contains the visible resources */ |