Lines 10-47
Link Here
|
10 |
*******************************************************************************/ |
10 |
*******************************************************************************/ |
11 |
package org.eclipse.compare.internal; |
11 |
package org.eclipse.compare.internal; |
12 |
|
12 |
|
13 |
import java.io.*; |
13 |
import java.io.IOException; |
|
|
14 |
import java.io.InputStream; |
15 |
import java.util.HashSet; |
14 |
import java.util.ResourceBundle; |
16 |
import java.util.ResourceBundle; |
15 |
import com.ibm.icu.text.MessageFormat; |
17 |
import java.util.Set; |
16 |
|
18 |
|
|
|
19 |
import org.eclipse.compare.CompareConfiguration; |
20 |
import org.eclipse.compare.CompareEditorInput; |
21 |
import org.eclipse.compare.CompareUI; |
22 |
import org.eclipse.compare.IStreamContentAccessor; |
23 |
import org.eclipse.compare.ITypedElement; |
24 |
import org.eclipse.compare.structuremergeviewer.ICompareInput; |
25 |
import org.eclipse.core.runtime.CoreException; |
17 |
import org.eclipse.swt.SWT; |
26 |
import org.eclipse.swt.SWT; |
18 |
import org.eclipse.swt.custom.BusyIndicator; |
|
|
19 |
import org.eclipse.swt.events.SelectionEvent; |
20 |
import org.eclipse.swt.events.SelectionListener; |
21 |
import org.eclipse.swt.layout.RowLayout; |
27 |
import org.eclipse.swt.layout.RowLayout; |
22 |
import org.eclipse.swt.widgets.*; |
28 |
import org.eclipse.swt.widgets.Composite; |
|
|
29 |
import org.eclipse.swt.widgets.Control; |
30 |
import org.eclipse.swt.widgets.Label; |
23 |
import org.eclipse.ui.PlatformUI; |
31 |
import org.eclipse.ui.PlatformUI; |
24 |
import org.eclipse.core.runtime.CoreException; |
32 |
|
25 |
import org.eclipse.compare.*; |
33 |
import com.ibm.icu.text.MessageFormat; |
26 |
import org.eclipse.compare.structuremergeviewer.ICompareInput; |
|
|
27 |
|
34 |
|
28 |
/** |
35 |
/** |
29 |
* A simple compare viewer for binary files. |
36 |
* A simple compare viewer for binary files. |
30 |
* Shows the position of the first non-matching byte. |
37 |
* Shows the position of the first non-matching byte. |
31 |
*/ |
38 |
*/ |
32 |
public class BinaryCompareViewer extends AbstractViewer { |
39 |
public class BinaryCompareViewer extends AbstractViewer { |
|
|
40 |
|
41 |
/** |
42 |
* Property key for the set of test inputs (instance of Set) |
43 |
*/ |
44 |
public static final String PROP_TEXT_INPUTS = "org.eclipse.compare.TextInputs"; //$NON-NLS-1$ |
33 |
|
45 |
|
34 |
private static final String BUNDLE_NAME= "org.eclipse.compare.internal.BinaryCompareViewerResources"; //$NON-NLS-1$ |
46 |
private static final String BUNDLE_NAME = "org.eclipse.compare.internal.BinaryCompareViewerResources"; //$NON-NLS-1$ |
35 |
|
47 |
|
36 |
private static final int EOF= -1; |
48 |
private static final int EOF = -1; |
37 |
private ICompareInput fInput; |
49 |
private ICompareInput fInput; |
38 |
private ResourceBundle fBundle; |
50 |
private ResourceBundle fBundle; |
39 |
private boolean fLeftIsLocal; |
51 |
private boolean fLeftIsLocal; |
40 |
|
52 |
|
41 |
private Composite fComposite; |
53 |
private Composite fComposite; |
42 |
private Label fMessage; |
54 |
private Label fMessage; |
43 |
private Button fTextButton; |
55 |
|
44 |
|
56 |
private CompareConfiguration cc; |
45 |
|
57 |
|
46 |
public BinaryCompareViewer(Composite parent, final CompareConfiguration cc) { |
58 |
public BinaryCompareViewer(Composite parent, final CompareConfiguration cc) { |
47 |
|
59 |
|
Lines 59-94
Link Here
|
59 |
|
71 |
|
60 |
fLeftIsLocal= Utilities.getBoolean(cc, "LEFT_IS_LOCAL", false); //$NON-NLS-1$ |
72 |
fLeftIsLocal= Utilities.getBoolean(cc, "LEFT_IS_LOCAL", false); //$NON-NLS-1$ |
61 |
|
73 |
|
62 |
if (canShowAsText(cc)) { |
74 |
if (cc != null && cc.getContainer() instanceof CompareEditorInput) { |
63 |
fTextButton = new Button(fComposite, SWT.PUSH); |
75 |
this.cc = cc; |
64 |
fTextButton.setText(Utilities.getString(fBundle, "compareAsText")); //$NON-NLS-1$ |
76 |
Label compareAsTextLabel = new Label(fComposite, SWT.WRAP); |
65 |
fTextButton.addSelectionListener(new SelectionListener() { |
77 |
compareAsTextLabel |
66 |
public void widgetSelected(SelectionEvent e) { |
78 |
.setText(Utilities.getString(fBundle, "compareAsText")); //$NON-NLS-1$ |
67 |
BusyIndicator.showWhile(Display.getCurrent(), new Runnable() { |
|
|
68 |
public void run() { |
69 |
handleShowAsText(cc); |
70 |
} |
71 |
}); |
72 |
} |
73 |
public void widgetDefaultSelected(SelectionEvent e) { |
74 |
// Do nothing |
75 |
} |
76 |
}); |
77 |
fTextButton.setEnabled(false); |
78 |
} |
79 |
} |
79 |
} |
80 |
} |
80 |
|
81 |
|
81 |
private boolean canShowAsText(CompareConfiguration cc) { |
|
|
82 |
if (cc == null) |
83 |
return false; |
84 |
return Utilities.getAdapter(cc.getContainer(), ICompareAsText.class) != null; |
85 |
} |
86 |
|
87 |
protected void handleShowAsText(CompareConfiguration cc) { |
88 |
ICompareAsText comparer = (ICompareAsText)Utilities.getAdapter(cc.getContainer(), ICompareAsText.class); |
89 |
comparer.compareAsText(getInput()); |
90 |
} |
91 |
|
92 |
public Control getControl() { |
82 |
public Control getControl() { |
93 |
return fComposite; |
83 |
return fComposite; |
94 |
} |
84 |
} |
Lines 97-102
Link Here
|
97 |
if (fComposite != null && input instanceof ICompareInput) { |
87 |
if (fComposite != null && input instanceof ICompareInput) { |
98 |
fInput= (ICompareInput) input; |
88 |
fInput= (ICompareInput) input; |
99 |
|
89 |
|
|
|
90 |
if (cc != null){ |
91 |
Set set = (Set)cc.getProperty(PROP_TEXT_INPUTS); |
92 |
if (set == null) { |
93 |
set = new HashSet(); |
94 |
cc.setProperty(PROP_TEXT_INPUTS, set); |
95 |
} |
96 |
set.add(input); |
97 |
} |
98 |
|
100 |
InputStream left= null; |
99 |
InputStream left= null; |
101 |
InputStream right= null; |
100 |
InputStream right= null; |
102 |
|
101 |
|
Lines 142-149
Link Here
|
142 |
} |
141 |
} |
143 |
if (message != null) |
142 |
if (message != null) |
144 |
fMessage.setText(message); |
143 |
fMessage.setText(message); |
145 |
if (fTextButton != null) |
|
|
146 |
fTextButton.setEnabled(true); |
147 |
fComposite.layout(); |
144 |
fComposite.layout(); |
148 |
} |
145 |
} |
149 |
} |
146 |
} |