diff options
Diffstat (limited to 'bundles/org.eclipse.compare/compare/org/eclipse/compare/internal/BinaryCompareViewer.java')
-rw-r--r-- | bundles/org.eclipse.compare/compare/org/eclipse/compare/internal/BinaryCompareViewer.java | 58 |
1 files changed, 51 insertions, 7 deletions
diff --git a/bundles/org.eclipse.compare/compare/org/eclipse/compare/internal/BinaryCompareViewer.java b/bundles/org.eclipse.compare/compare/org/eclipse/compare/internal/BinaryCompareViewer.java index f9bd97342..01e54e12c 100644 --- a/bundles/org.eclipse.compare/compare/org/eclipse/compare/internal/BinaryCompareViewer.java +++ b/bundles/org.eclipse.compare/compare/org/eclipse/compare/internal/BinaryCompareViewer.java @@ -15,6 +15,10 @@ import java.util.ResourceBundle; import com.ibm.icu.text.MessageFormat; import org.eclipse.swt.SWT; +import org.eclipse.swt.custom.BusyIndicator; +import org.eclipse.swt.events.SelectionEvent; +import org.eclipse.swt.events.SelectionListener; +import org.eclipse.swt.layout.RowLayout; import org.eclipse.swt.widgets.*; import org.eclipse.ui.PlatformUI; import org.eclipse.core.runtime.CoreException; @@ -30,30 +34,67 @@ public class BinaryCompareViewer extends AbstractViewer { private static final String BUNDLE_NAME= "org.eclipse.compare.internal.BinaryCompareViewerResources"; //$NON-NLS-1$ private static final int EOF= -1; - private Label fControl; private ICompareInput fInput; private ResourceBundle fBundle; private boolean fLeftIsLocal; + + private Composite fComposite; + private Label fMessage; + private Button fTextButton; - public BinaryCompareViewer(Composite parent, CompareConfiguration cc) { + public BinaryCompareViewer(Composite parent, final CompareConfiguration cc) { PlatformUI.getWorkbench().getHelpSystem().setHelp(parent, ICompareContextIds.BINARY_COMPARE_VIEW); fBundle= ResourceBundle.getBundle(BUNDLE_NAME); + + fComposite= new Composite(parent, SWT.NONE); + RowLayout rowLayout = new RowLayout(); + rowLayout.type = SWT.VERTICAL; + fComposite.setLayout(rowLayout); - fControl= new Label(parent, SWT.WRAP); - fControl.setData(CompareUI.COMPARE_VIEWER_TITLE, Utilities.getString(fBundle, "title")); //$NON-NLS-1$ + fMessage= new Label(fComposite, SWT.WRAP); + fMessage.setData(CompareUI.COMPARE_VIEWER_TITLE, Utilities.getString(fBundle, "title")); //$NON-NLS-1$ fLeftIsLocal= Utilities.getBoolean(cc, "LEFT_IS_LOCAL", false); //$NON-NLS-1$ + + if (canShowAsText(cc)) { + fTextButton = new Button(fComposite, SWT.PUSH); + fTextButton.setText(Utilities.getString(fBundle, "compareAsText")); //$NON-NLS-1$ + fTextButton.addSelectionListener(new SelectionListener() { + public void widgetSelected(SelectionEvent e) { + BusyIndicator.showWhile(Display.getCurrent(), new Runnable() { + public void run() { + handleShowAsText(cc); + } + }); + } + public void widgetDefaultSelected(SelectionEvent e) { + // Do nothing + } + }); + fTextButton.setEnabled(false); + } + } + + private boolean canShowAsText(CompareConfiguration cc) { + if (cc == null) + return false; + return Utilities.getAdapter(cc.getContainer(), ICompareAsText.class) != null; + } + + protected void handleShowAsText(CompareConfiguration cc) { + ICompareAsText comparer = (ICompareAsText)Utilities.getAdapter(cc.getContainer(), ICompareAsText.class); + comparer.compareAsText(getInput()); } public Control getControl() { - return fControl; + return fComposite; } public void setInput(Object input) { - if (fControl != null && input instanceof ICompareInput) { + if (fComposite != null && input instanceof ICompareInput) { fInput= (ICompareInput) input; InputStream left= null; @@ -100,7 +141,10 @@ public class BinaryCompareViewer extends AbstractViewer { Utilities.close(right); } if (message != null) - fControl.setText(message); + fMessage.setText(message); + if (fTextButton != null) + fTextButton.setEnabled(true); + fComposite.layout(); } } |