Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndre Weinand2002-01-22 11:43:54 +0000
committerAndre Weinand2002-01-22 11:43:54 +0000
commitceff15f67ba20d197a909e5693bfb469e57a6e54 (patch)
tree2083b0d221b78b0098c50a3cceef070ddeae10ee /bundles/org.eclipse.compare/plugins/org.eclipse.compare/compare/org
parentdbbe719613d610b7701c57d2011dee78bfda16a9 (diff)
downloadeclipse.platform.team-ceff15f67ba20d197a909e5693bfb469e57a6e54.tar.gz
eclipse.platform.team-ceff15f67ba20d197a909e5693bfb469e57a6e54.tar.xz
eclipse.platform.team-ceff15f67ba20d197a909e5693bfb469e57a6e54.zip
2773: Java structure compare should give better indication when no changes (1GJ6ENE)
Diffstat (limited to 'bundles/org.eclipse.compare/plugins/org.eclipse.compare/compare/org')
-rw-r--r--bundles/org.eclipse.compare/plugins/org.eclipse.compare/compare/org/eclipse/compare/CompareViewerSwitchingPane.java25
-rw-r--r--bundles/org.eclipse.compare/plugins/org.eclipse.compare/compare/org/eclipse/compare/internal/CompareMessages.java26
-rw-r--r--bundles/org.eclipse.compare/plugins/org.eclipse.compare/compare/org/eclipse/compare/internal/CompareMessages.properties15
-rw-r--r--bundles/org.eclipse.compare/plugins/org.eclipse.compare/compare/org/eclipse/compare/patch/Patcher.java57
-rw-r--r--bundles/org.eclipse.compare/plugins/org.eclipse.compare/compare/org/eclipse/compare/patch/PreviewPatchPage.java21
-rw-r--r--bundles/org.eclipse.compare/plugins/org.eclipse.compare/compare/org/eclipse/compare/structuremergeviewer/StructureDiffViewer.java29
6 files changed, 141 insertions, 32 deletions
diff --git a/bundles/org.eclipse.compare/plugins/org.eclipse.compare/compare/org/eclipse/compare/CompareViewerSwitchingPane.java b/bundles/org.eclipse.compare/plugins/org.eclipse.compare/compare/org/eclipse/compare/CompareViewerSwitchingPane.java
index 2a668150d..42717db56 100644
--- a/bundles/org.eclipse.compare/plugins/org.eclipse.compare/compare/org/eclipse/compare/CompareViewerSwitchingPane.java
+++ b/bundles/org.eclipse.compare/plugins/org.eclipse.compare/compare/org/eclipse/compare/CompareViewerSwitchingPane.java
@@ -4,6 +4,8 @@
*/
package org.eclipse.compare;
+import java.text.MessageFormat;
+
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.*;
import org.eclipse.swt.graphics.Image;
@@ -34,6 +36,8 @@ public abstract class CompareViewerSwitchingPane extends CompareViewerPane
private ListenerList fSelectionListeners= new ListenerList();
private ListenerList fOpenListeners= new ListenerList();
private boolean fControlVisibility= false;
+ private String fTitle;
+ private String fTitleArgument;
/**
@@ -245,7 +249,26 @@ public abstract class CompareViewerSwitchingPane extends CompareViewerPane
}
}
- setText(title != null ? title : ""); //$NON-NLS-1$
+ fTitle= title;
+ updateTitle();
+ }
+
+ public void setTitleArgument(String argument) {
+ fTitleArgument= argument;
+ updateTitle();
+ }
+
+ private void updateTitle() {
+ if (fTitle != null) {
+ if (fTitleArgument != null) {
+ String format= CompareMessages.getString("CompareViewerSwitchingPane.Titleformat"); //$NON-NLS-1$
+ String t= MessageFormat.format(format, new String[] { fTitle, fTitleArgument } );
+ setText(t);
+ } else
+ setText(fTitle);
+ } else {
+ setText(""); //$NON-NLS-1$
+ }
}
public Object getInput() {
diff --git a/bundles/org.eclipse.compare/plugins/org.eclipse.compare/compare/org/eclipse/compare/internal/CompareMessages.java b/bundles/org.eclipse.compare/plugins/org.eclipse.compare/compare/org/eclipse/compare/internal/CompareMessages.java
new file mode 100644
index 000000000..96b7c0407
--- /dev/null
+++ b/bundles/org.eclipse.compare/plugins/org.eclipse.compare/compare/org/eclipse/compare/internal/CompareMessages.java
@@ -0,0 +1,26 @@
+/*
+ * (c) Copyright IBM Corp. 2002.
+ * All Rights Reserved.
+ */
+package org.eclipse.compare.internal;
+
+import java.util.MissingResourceException;
+import java.util.ResourceBundle;
+
+public class CompareMessages {
+
+ private static final String RESOURCE_BUNDLE= "org.eclipse.compare.internal.CompareMessages";//$NON-NLS-1$
+
+ private static ResourceBundle fgResourceBundle= ResourceBundle.getBundle(RESOURCE_BUNDLE);
+
+ private CompareMessages() {
+ }
+
+ public static String getString(String key) {
+ try {
+ return fgResourceBundle.getString(key);
+ } catch (MissingResourceException e) {
+ return "!" + key + "!";//$NON-NLS-2$ //$NON-NLS-1$
+ }
+ }
+}
diff --git a/bundles/org.eclipse.compare/plugins/org.eclipse.compare/compare/org/eclipse/compare/internal/CompareMessages.properties b/bundles/org.eclipse.compare/plugins/org.eclipse.compare/compare/org/eclipse/compare/internal/CompareMessages.properties
new file mode 100644
index 000000000..cf31617aa
--- /dev/null
+++ b/bundles/org.eclipse.compare/plugins/org.eclipse.compare/compare/org/eclipse/compare/internal/CompareMessages.properties
@@ -0,0 +1,15 @@
+# =====================================
+# (c) Copyright IBM Corp. 2002.
+# All Rights Reserved.
+# =====================================
+
+#
+# Title format for CompareViewerSwitchingPane
+#
+CompareViewerSwitchingPane.Titleformat= {0} ({1})
+
+#
+# Title message for StructureDiffViewer if no structural differences could be found
+#
+StructureDiffViewer.NoStructuralDifferences= No Structural Differences
+StructureDiffViewer.StructureError= Couldn't Compare Structures \ No newline at end of file
diff --git a/bundles/org.eclipse.compare/plugins/org.eclipse.compare/compare/org/eclipse/compare/patch/Patcher.java b/bundles/org.eclipse.compare/plugins/org.eclipse.compare/compare/org/eclipse/compare/patch/Patcher.java
index e96e7d374..81bf4f276 100644
--- a/bundles/org.eclipse.compare/plugins/org.eclipse.compare/compare/org/eclipse/compare/patch/Patcher.java
+++ b/bundles/org.eclipse.compare/plugins/org.eclipse.compare/compare/org/eclipse/compare/patch/Patcher.java
@@ -37,6 +37,7 @@ public class Patcher {
private int fStripPrefixSegments;
private int fFuzz;
private boolean fIgnoreWhitespace;
+ private boolean fReverse= false;
Patcher() {
@@ -96,6 +97,17 @@ public class Patcher {
/**
* Returns <code>true</code> if new value differs from old.
*/
+ boolean setReversed(boolean reverse) {
+ if (fReverse != reverse) {
+ fReverse= reverse;
+ return true;
+ }
+ return false;
+ }
+
+ /**
+ * Returns <code>true</code> if new value differs from old.
+ */
boolean setIgnoreWhitespace(boolean ignoreWhitespace) {
if (ignoreWhitespace != fIgnoreWhitespace) {
fIgnoreWhitespace= ignoreWhitespace;
@@ -609,12 +621,13 @@ public class Patcher {
}
if (found) {
- //System.out.println("patched hunk at offset: " + (shift-oldShift));
+ System.out.println("patched hunk at offset: " + (shift-oldShift));
shift+= doPatch(hunk, lines, shift);
} else {
- if (failedHunks != null)
+ if (failedHunks != null) {
+ System.out.println("failed hunk");
failedHunks.add(hunk);
- // System.out.println("hunk ignored");
+ }
}
}
return shift;
@@ -628,8 +641,8 @@ public class Patcher {
String s= hunk.fLines[i];
Assert.isTrue(s.length() > 0);
String line= s.substring(1);
- switch (s.charAt(0)) {
- case ' ': // context lines
+ char controlChar= s.charAt(0);
+ if (controlChar == ' ') { // context lines
while (true) {
if (pos < 0 || pos >= lines.size())
return false;
@@ -642,8 +655,8 @@ public class Patcher {
return false;
pos++;
}
- break;
- case '-': // deleted lines
+ } else if ((!fReverse && controlChar == '-') || (fReverse && controlChar == '+')) {
+ // deleted lines
while (true) {
if (pos < 0 || pos >= lines.size())
return false;
@@ -656,10 +669,11 @@ public class Patcher {
return false;
pos++;
}
- break;
- case '+': // added lines
- break;
- }
+ } else if ((!fReverse && controlChar == '+') || (fReverse && controlChar == '-')) {
+ // added lines
+ // we don't have to do anything for a 'try'
+ } else
+ Assert.isTrue(false, "tryPatch: unknown control charcter: " + controlChar); //$NON-NLS-1$
}
return true;
}
@@ -670,33 +684,32 @@ public class Patcher {
String s= hunk.fLines[i];
Assert.isTrue(s.length() > 0);
String line= s.substring(1);
- char type= s.charAt(0);
- switch (type) {
- case ' ': // context lines
+ char controlChar= s.charAt(0);
+ if (controlChar == ' ') { // context lines
while (true) {
- Assert.isTrue(pos < lines.size(), "3"); //$NON-NLS-1$
+ Assert.isTrue(pos < lines.size(), "doPatch: inconsistency in context"); //$NON-NLS-1$
if (linesMatch(line, (String) lines.get(pos))) {
pos++;
break;
}
pos++;
}
- break;
- case '-': // deleted lines
+ } else if ((!fReverse && controlChar == '-') || (fReverse && controlChar == '+')) {
+ // deleted lines
while (true) {
- Assert.isTrue(pos < lines.size(), "3"); //$NON-NLS-1$
+ Assert.isTrue(pos < lines.size(), "doPatch: inconsistency in deleted lines"); //$NON-NLS-1$
if (linesMatch(line, (String) lines.get(pos))) {
break;
}
pos++;
}
lines.remove(pos);
- break;
- case '+': // added lines
+ } else if ((!fReverse && controlChar == '+') || (fReverse && controlChar == '-')) {
+ // added lines
lines.add(pos, line);
pos++;
- break;
- }
+ } else
+ Assert.isTrue(false, "doPatch: unknown control charcter: " + controlChar); //$NON-NLS-1$
}
return hunk.fNewLength - hunk.fOldLength;
}
diff --git a/bundles/org.eclipse.compare/plugins/org.eclipse.compare/compare/org/eclipse/compare/patch/PreviewPatchPage.java b/bundles/org.eclipse.compare/plugins/org.eclipse.compare/compare/org/eclipse/compare/patch/PreviewPatchPage.java
index 006f3534e..83977bd17 100644
--- a/bundles/org.eclipse.compare/plugins/org.eclipse.compare/compare/org/eclipse/compare/patch/PreviewPatchPage.java
+++ b/bundles/org.eclipse.compare/plugins/org.eclipse.compare/compare/org/eclipse/compare/patch/PreviewPatchPage.java
@@ -62,6 +62,7 @@ import org.eclipse.compare.structuremergeviewer.*;
private Combo fStripPrefixSegments;
private CompareViewerSwitchingPane fHunkViewer;
private Button fIgnoreWhitespaceButton;
+ private Button fReversePatchButton;
private Text fFuzzField;
private Image fNullImage;
@@ -188,11 +189,12 @@ import org.eclipse.compare.structuremergeviewer.*;
Group group= new Group(parent, SWT.NONE);
group.setText("Patch Options");
GridLayout layout= new GridLayout();
- layout.numColumns= 7;
+ layout.numColumns= 5;
group.setLayout(layout);
group.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_FILL | GridData.GRAB_HORIZONTAL));
//fPatchFileGroup.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
+ // 1st row
new Label(group, SWT.NONE).setText("Ignore leading path name segments:");
fStripPrefixSegments= new Combo(group, SWT.DROP_DOWN | SWT.READ_ONLY | SWT.SIMPLE);
@@ -203,6 +205,12 @@ import org.eclipse.compare.structuremergeviewer.*;
addSpacer(group);
+ fReversePatchButton= new Button(group, SWT.CHECK);
+ fReversePatchButton.setText("Reverse Patch");
+
+ addSpacer(group);
+
+ // 2nd row
Label l= new Label(group, SWT.NONE);
l.setText("Maximum fuzz factor:");
l.setToolTipText("Allow context to shift this number of lines from the original place");
@@ -218,9 +226,8 @@ import org.eclipse.compare.structuremergeviewer.*;
fIgnoreWhitespaceButton.setText("Ignore Whitespace");
addSpacer(group);
-
+
// register listeners
-
if (fStripPrefixSegments != null)
fStripPrefixSegments.addSelectionListener(
@@ -231,6 +238,14 @@ import org.eclipse.compare.structuremergeviewer.*;
}
}
);
+ fReversePatchButton.addSelectionListener(
+ new SelectionAdapter() {
+ public void widgetSelected(SelectionEvent e) {
+ if (patcher.setReversed(fReversePatchButton.getSelection()))
+ updateTree();
+ }
+ }
+ );
fIgnoreWhitespaceButton.addSelectionListener(
new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
diff --git a/bundles/org.eclipse.compare/plugins/org.eclipse.compare/compare/org/eclipse/compare/structuremergeviewer/StructureDiffViewer.java b/bundles/org.eclipse.compare/plugins/org.eclipse.compare/compare/org/eclipse/compare/structuremergeviewer/StructureDiffViewer.java
index 5aec6901a..71489efa6 100644
--- a/bundles/org.eclipse.compare/plugins/org.eclipse.compare/compare/org/eclipse/compare/structuremergeviewer/StructureDiffViewer.java
+++ b/bundles/org.eclipse.compare/plugins/org.eclipse.compare/compare/org/eclipse/compare/structuremergeviewer/StructureDiffViewer.java
@@ -52,6 +52,7 @@ public class StructureDiffViewer extends DiffTreeViewer {
private ChangePropertyAction fSmartAction;
private IContentChangeListener fContentChangedListener;
private ICompareInputChangeListener fThreeWayInputChangedListener;
+ private CompareViewerSwitchingPane fParent;
/**
* Creates a new viewer for the given SWT tree control with the specified configuration.
@@ -61,6 +62,9 @@ public class StructureDiffViewer extends DiffTreeViewer {
*/
public StructureDiffViewer(Tree tree, CompareConfiguration configuration) {
super(tree, configuration);
+ Composite c= tree.getParent();
+ if (c instanceof CompareViewerSwitchingPane)
+ fParent= (CompareViewerSwitchingPane) c;
initialize();
}
@@ -72,6 +76,8 @@ public class StructureDiffViewer extends DiffTreeViewer {
*/
public StructureDiffViewer(Composite parent, CompareConfiguration configuration) {
super(parent, configuration);
+ if (parent instanceof CompareViewerSwitchingPane)
+ fParent= (CompareViewerSwitchingPane) parent;
initialize();
}
@@ -266,9 +272,12 @@ public class StructureDiffViewer extends DiffTreeViewer {
preDiffHook(fAncestorStructure, fLeftStructure, fRightStructure);
+ String message= null;
+
if ((fThreeWay && fAncestorStructure == null) || fLeftStructure == null || fRightStructure == null) {
// could not get structure of one (or more) of the legs
fRoot= null;
+ message= CompareMessages.getString("StructureDiffViewer.StructureError"); //$NON-NLS-1$
} else { // calculate difference of the two (or three) structures
@@ -287,13 +296,21 @@ public class StructureDiffViewer extends DiffTreeViewer {
fRoot= (IDiffContainer) fDifferencer.findDifferences(fThreeWay, null, null,
fAncestorStructure, fLeftStructure, fRightStructure);
-
- if (fStructureCreator.canRewriteTree()) {
- boolean smart= Utilities.getBoolean(getCompareConfiguration(), SMART, false);
- if (smart && fRoot != null)
- fStructureCreator.rewriteTree(fDifferencer, fRoot);
+
+ if (fRoot == null || fRoot.getChildren().length == 0) {
+ message= CompareMessages.getString("StructureDiffViewer.NoStructuralDifferences"); //$NON-NLS-1$
+ } else {
+ if (fStructureCreator.canRewriteTree()) {
+ boolean smart= Utilities.getBoolean(getCompareConfiguration(), SMART, false);
+ if (smart && fRoot != null)
+ fStructureCreator.rewriteTree(fDifferencer, fRoot);
+ }
}
- }
+
+ }
+ if (fParent != null)
+ fParent.setTitleArgument(message);
+
refresh(getRoot());
}

Back to the top