-
Notifications
You must be signed in to change notification settings - Fork 113
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Show number of differences in the Compare editor #504
Show number of differences (Ex: 6 Differences) in the toolbar of compare editor which matches "Change markers" next to the scroll bar in compare editor Fixes #504 Show number of differences in the Compare editor #504 Fixed Issues identified during review : 1. The label is not recomputed if the diff config changes (Ignore White Space). 2. The label is incorrect for zero changes - it says 0 Difference 3. Test case failure Fixes #504 Conflicts resolution
- Loading branch information
1 parent
508558d
commit 7125299
Showing
7 changed files
with
239 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
66 changes: 66 additions & 0 deletions
66
team/bundles/org.eclipse.compare/compare/org/eclipse/compare/LabelContributionItem.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
/******************************************************************************* | ||
* Copyright (c) ETAS GmbH 2023, all rights reserved. | ||
* | ||
* This program and the accompanying materials | ||
* are made available under the terms of the Eclipse Public License 2.0 | ||
* which accompanies this distribution, and is available at | ||
* https://www.eclipse.org/legal/epl-2.0/ | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
* | ||
* Contributors: | ||
* ETAS GmbH - initial API and implementation | ||
*******************************************************************************/ | ||
|
||
package org.eclipse.compare; | ||
|
||
import org.eclipse.jface.action.ControlContribution; | ||
import org.eclipse.swt.SWT; | ||
import org.eclipse.swt.layout.GridData; | ||
import org.eclipse.swt.layout.GridLayout; | ||
import org.eclipse.swt.widgets.Composite; | ||
import org.eclipse.swt.widgets.Control; | ||
import org.eclipse.swt.widgets.Label; | ||
|
||
|
||
/** | ||
* @since 3.10 | ||
* | ||
* A contribution item which delegates to a label on the tool bar. | ||
* | ||
*/ | ||
public class LabelContributionItem extends ControlContribution { | ||
|
||
private Label toolbarLabel; | ||
private String labelName; | ||
|
||
/** | ||
* @param id | ||
* @param name | ||
*/ | ||
public LabelContributionItem(String id, String name) { | ||
super(id); | ||
this.labelName = name; | ||
} | ||
|
||
@Override | ||
protected Control createControl(Composite parent) { | ||
Composite composite = new Composite(parent, SWT.LEFT); | ||
this.toolbarLabel = new Label(composite, SWT.LEFT); | ||
|
||
GridLayout compositeLayout = new GridLayout(1, false); | ||
compositeLayout.marginTop = -3; | ||
compositeLayout.marginBottom = -6; | ||
composite.setLayout(compositeLayout); | ||
GridData labelLayout = new GridData(SWT.LEFT, SWT.BOTTOM, true, true); | ||
|
||
this.toolbarLabel.setLayoutData(labelLayout); | ||
this.toolbarLabel.setText(this.labelName); | ||
|
||
return composite; | ||
} | ||
|
||
public Label getToolbarLabel() { | ||
return toolbarLabel; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2000, 2020 IBM Corporation and others. | ||
* Copyright (c) 2000, 2023 IBM Corporation and others. | ||
* | ||
* This program and the accompanying materials | ||
* are made available under the terms of the Eclipse Public License 2.0 | ||
|
@@ -13,6 +13,7 @@ | |
* Alex Blewitt <[email protected]> - replace new Boolean with Boolean.valueOf - https://bugs.eclipse.org/470344 | ||
* Stefan Xenos <[email protected]> (Google) - bug 448968 - Add diagnostic logging | ||
* Conrad Groth - Bug 213780 - Compare With direction should be configurable | ||
* Latha Patil (ETAS GmbH) - Issue #504 Show number of differences in the Compare editor | ||
*******************************************************************************/ | ||
|
||
package org.eclipse.compare.contentmergeviewer; | ||
|
@@ -795,7 +796,7 @@ private void internalRefresh(Object input) { | |
updateHeader(); | ||
if (Utilities.okToUse(fComposite) && Utilities.okToUse(fComposite.getParent())) { | ||
ToolBarManager tbm = (ToolBarManager) getToolBarManager(fComposite.getParent()); | ||
if (tbm != null ) { | ||
if (tbm != null) { | ||
updateToolItems(); | ||
tbm.update(true); | ||
tbm.getControl().getParent().layout(true); | ||
|
@@ -897,6 +898,7 @@ private void initializeToolbars(Composite parent) { | |
tbm.removeAll(); | ||
|
||
// Define groups. | ||
tbm.add(new Separator("diffLabel")); //$NON-NLS-1$ | ||
tbm.add(new Separator("modes")); //$NON-NLS-1$ | ||
tbm.add(new Separator("merge")); //$NON-NLS-1$ | ||
tbm.add(new Separator("navigation")); //$NON-NLS-1$ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2000, 2019 IBM Corporation and others. | ||
* Copyright (c) 2000, 2023 IBM Corporation and others. | ||
* | ||
* This program and the accompanying materials | ||
* are made available under the terms of the Eclipse Public License 2.0 | ||
|
@@ -21,6 +21,7 @@ | |
* Robin Stocker ([email protected]) - Bug 399960: [Edit] Make merge arrow buttons easier to hit | ||
* John Hendrikx ([email protected]) - Bug 541401 - [regression] Vertical scrollbar thumb size is wrong in compare view | ||
* Stefan Dirix ([email protected]) - Bug 473847: Minimum E4 Compatibility of Compare | ||
* Latha Patil (ETAS GmbH) - Issue #504 Show number of differences in the Compare editor | ||
*******************************************************************************/ | ||
package org.eclipse.compare.contentmergeviewer; | ||
|
||
|
@@ -45,6 +46,7 @@ | |
import org.eclipse.compare.ISharedDocumentAdapter; | ||
import org.eclipse.compare.IStreamContentAccessor; | ||
import org.eclipse.compare.ITypedElement; | ||
import org.eclipse.compare.LabelContributionItem; | ||
import org.eclipse.compare.SharedDocumentAdapter; | ||
import org.eclipse.compare.internal.ChangeCompareFilterPropertyAction; | ||
import org.eclipse.compare.internal.ChangePropertyAction; | ||
|
@@ -5408,6 +5410,32 @@ private boolean isIgnoreAncestor() { | |
|
||
updateVScrollBar(); | ||
updatePresentation(); | ||
updateToolbarLabel(); | ||
} | ||
|
||
private void updateToolbarLabel() { | ||
final String DIFF_COUNT_ID = "DiffCount"; //$NON-NLS-1$ | ||
ToolBarManager tbm = | ||
(ToolBarManager) getToolBarManager(fComposite.getParent()); | ||
int differenceCount = fMerger.changesCount(); | ||
if (tbm != null) { | ||
|
||
String label = differenceCount > 1 ? differenceCount + " Differences" //$NON-NLS-1$ | ||
: differenceCount == 1 ? differenceCount + " Difference" : "No Difference"; //$NON-NLS-1$ //$NON-NLS-2$ | ||
LabelContributionItem labelContributionItem = new LabelContributionItem(DIFF_COUNT_ID, | ||
label); | ||
|
||
if (tbm.find(DIFF_COUNT_ID) != null) { | ||
tbm.replaceItem(DIFF_COUNT_ID, labelContributionItem); | ||
} else { | ||
tbm.appendToGroup("diffLabel", labelContributionItem); //$NON-NLS-1$ | ||
} | ||
Display.getDefault().asyncExec(() -> { | ||
// relayout in next tick | ||
tbm.update(true); | ||
tbm.getControl().getParent().setRedraw(true); | ||
}); | ||
} | ||
} | ||
|
||
private void resetDiffs() { | ||
|
23 changes: 23 additions & 0 deletions
23
team/tests/org.eclipse.compare.tests/labelContributionData/file1.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package testPackage; | ||
import java.math.*; | ||
public class Javaclass1 { | ||
|
||
public static void main(String[] args) { | ||
// TODO Auto-generated method stub | ||
|
||
int a=0; | ||
|
||
System.out.println(""); | ||
|
||
call_me(); | ||
|
||
|
||
} | ||
|
||
private static void call_me() { | ||
// TODO Auto-generated method stub | ||
System.out.println(); | ||
|
||
} | ||
|
||
} |
31 changes: 31 additions & 0 deletions
31
team/tests/org.eclipse.compare.tests/labelContributionData/file2.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package testPackage; | ||
|
||
import java.io.File; | ||
|
||
public class Javaclass1 { | ||
|
||
public static void main(String[] args) { | ||
|
||
|
||
int a=0; | ||
|
||
System.out.println(""); | ||
|
||
call_me(); | ||
|
||
callMe(a); | ||
|
||
} | ||
|
||
private static void callMe(int a) { | ||
// TODO Auto-generated method stub | ||
System.out.println(); | ||
|
||
} | ||
|
||
private static void call_me() { | ||
File f= new File(""); | ||
System.out.println("I am calledJavaclass1.java"); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters