Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndre Weinand2002-02-12 15:52:48 +0000
committerAndre Weinand2002-02-12 15:52:48 +0000
commitb2d6176ab678441fcc129445dab739bf7f441979 (patch)
treeb603cb45f7550ae720820e99f053603115909ebc /bundles/org.eclipse.compare/compare/org/eclipse/compare
parenta3f2d90990a619c5d692f4c798a9f3299a7a85bd (diff)
downloadeclipse.platform.team-b2d6176ab678441fcc129445dab739bf7f441979.tar.gz
eclipse.platform.team-b2d6176ab678441fcc129445dab739bf7f441979.tar.xz
eclipse.platform.team-b2d6176ab678441fcc129445dab739bf7f441979.zip
NLS work, patch: #6346v20020212-tmp1
Diffstat (limited to 'bundles/org.eclipse.compare/compare/org/eclipse/compare')
-rw-r--r--bundles/org.eclipse.compare/compare/org/eclipse/compare/internal/CompareMessages.properties3
-rw-r--r--bundles/org.eclipse.compare/compare/org/eclipse/compare/internal/ComparePreferencePage.java12
-rw-r--r--bundles/org.eclipse.compare/compare/org/eclipse/compare/internal/CompareUIPlugin.java77
-rw-r--r--bundles/org.eclipse.compare/compare/org/eclipse/compare/internal/ExceptionHandler.java127
-rw-r--r--bundles/org.eclipse.compare/compare/org/eclipse/compare/internal/ListContentProvider.java41
-rw-r--r--bundles/org.eclipse.compare/compare/org/eclipse/compare/internal/ListDialog.java83
-rw-r--r--bundles/org.eclipse.compare/compare/org/eclipse/compare/internal/Utilities.java2
-rw-r--r--bundles/org.eclipse.compare/compare/org/eclipse/compare/internal/patch/CompareWithPatchAction.java166
-rw-r--r--bundles/org.eclipse.compare/compare/org/eclipse/compare/internal/patch/Diff.java (renamed from bundles/org.eclipse.compare/compare/org/eclipse/compare/patch/Diff.java)2
-rw-r--r--bundles/org.eclipse.compare/compare/org/eclipse/compare/internal/patch/Hunk.java (renamed from bundles/org.eclipse.compare/compare/org/eclipse/compare/patch/Hunk.java)16
-rw-r--r--bundles/org.eclipse.compare/compare/org/eclipse/compare/internal/patch/InputPatchPage.java (renamed from bundles/org.eclipse.compare/compare/org/eclipse/compare/patch/InputPatchPage.java)49
-rw-r--r--bundles/org.eclipse.compare/compare/org/eclipse/compare/internal/patch/LineReader.java (renamed from bundles/org.eclipse.compare/compare/org/eclipse/compare/patch/LineReader.java)2
-rw-r--r--bundles/org.eclipse.compare/compare/org/eclipse/compare/internal/patch/PatchCompareInput.java (renamed from bundles/org.eclipse.compare/compare/org/eclipse/compare/patch/PatchCompareInput.java)13
-rw-r--r--bundles/org.eclipse.compare/compare/org/eclipse/compare/internal/patch/PatchErrorDialog.java17
-rw-r--r--bundles/org.eclipse.compare/compare/org/eclipse/compare/internal/patch/PatchMessages.java26
-rw-r--r--bundles/org.eclipse.compare/compare/org/eclipse/compare/internal/patch/PatchMessages.properties73
-rw-r--r--bundles/org.eclipse.compare/compare/org/eclipse/compare/internal/patch/PatchWizard.java (renamed from bundles/org.eclipse.compare/compare/org/eclipse/compare/patch/PatchWizard.java)25
-rw-r--r--bundles/org.eclipse.compare/compare/org/eclipse/compare/internal/patch/PatchedResource.java (renamed from bundles/org.eclipse.compare/compare/org/eclipse/compare/patch/PatchedResource.java)2
-rw-r--r--bundles/org.eclipse.compare/compare/org/eclipse/compare/internal/patch/Patcher.java (renamed from bundles/org.eclipse.compare/compare/org/eclipse/compare/patch/Patcher.java)166
-rw-r--r--bundles/org.eclipse.compare/compare/org/eclipse/compare/internal/patch/PreviewPatchPage.java (renamed from bundles/org.eclipse.compare/compare/org/eclipse/compare/patch/PreviewPatchPage.java)59
-rw-r--r--bundles/org.eclipse.compare/compare/org/eclipse/compare/patch/CompareWithPatchAction.java44
21 files changed, 809 insertions, 196 deletions
diff --git a/bundles/org.eclipse.compare/compare/org/eclipse/compare/internal/CompareMessages.properties b/bundles/org.eclipse.compare/compare/org/eclipse/compare/internal/CompareMessages.properties
index cf31617aa..44538cec9 100644
--- a/bundles/org.eclipse.compare/compare/org/eclipse/compare/internal/CompareMessages.properties
+++ b/bundles/org.eclipse.compare/compare/org/eclipse/compare/internal/CompareMessages.properties
@@ -3,6 +3,9 @@
# All Rights Reserved.
# =====================================
+ComparePlugin.internal_error= Internal Error
+ExceptionDialog.seeErrorLogMessage= See error log for more details.
+
#
# Title format for CompareViewerSwitchingPane
#
diff --git a/bundles/org.eclipse.compare/compare/org/eclipse/compare/internal/ComparePreferencePage.java b/bundles/org.eclipse.compare/compare/org/eclipse/compare/internal/ComparePreferencePage.java
index c9ac102fd..f8a64840f 100644
--- a/bundles/org.eclipse.compare/compare/org/eclipse/compare/internal/ComparePreferencePage.java
+++ b/bundles/org.eclipse.compare/compare/org/eclipse/compare/internal/ComparePreferencePage.java
@@ -19,9 +19,9 @@ public class ComparePreferencePage extends FieldEditorPreferencePage implements
public static final String SYNCHRONIZE_SCROLLING= PREFIX + "SynchronizeScrolling"; //$NON-NLS-1$
public static final String SHOW_PSEUDO_CONFLICTS= PREFIX + "ShowPseudoConflicts"; //$NON-NLS-1$
public static final String INITIALLY_SHOW_ANCESTOR_PANE= PREFIX + "InitiallyShowAncestorPane"; //$NON-NLS-1$
+ public static final String PREF_SAVE_ALL_EDITORS= PREFIX + "SaveAllEditors"; //$NON-NLS-1$
public static final String TEXT_FONT= PREFIX + "TextFont"; //$NON-NLS-1$
-
public ComparePreferencePage() {
super(GRID);
}
@@ -34,6 +34,16 @@ public class ComparePreferencePage extends FieldEditorPreferencePage implements
WorkbenchChainedTextFontFieldEditor.startPropagate(store, TEXT_FONT);
}
+ static public boolean getSaveAllEditors() {
+ IPreferenceStore store= CompareUIPlugin.getDefault().getPreferenceStore();
+ return store.getBoolean(PREF_SAVE_ALL_EDITORS);
+ }
+
+ static public void setSaveAllEditors(boolean value) {
+ IPreferenceStore store= CompareUIPlugin.getDefault().getPreferenceStore();
+ store.setValue(PREF_SAVE_ALL_EDITORS, value);
+ }
+
public void init(IWorkbench workbench) {
}
diff --git a/bundles/org.eclipse.compare/compare/org/eclipse/compare/internal/CompareUIPlugin.java b/bundles/org.eclipse.compare/compare/org/eclipse/compare/internal/CompareUIPlugin.java
index 4c56ee5e5..1ed9d6397 100644
--- a/bundles/org.eclipse.compare/compare/org/eclipse/compare/internal/CompareUIPlugin.java
+++ b/bundles/org.eclipse.compare/compare/org/eclipse/compare/internal/CompareUIPlugin.java
@@ -57,6 +57,9 @@ public final class CompareUIPlugin extends AbstractUIPlugin {
public static final String CTOOL_PREV= "clcl16/prev_nav.gif"; //$NON-NLS-1$
public static final String ETOOL_PREV= "elcl16/prev_nav.gif"; //$NON-NLS-1$
+ /** Status code describing an internal error */
+ public static final int INTERNAL_ERROR= 1;
+
private static boolean NORMALIZE_CASE= true;
private final static String CLASS_ATTRIBUTE= "class"; //$NON-NLS-1$
@@ -195,6 +198,20 @@ public final class CompareUIPlugin extends AbstractUIPlugin {
return fgResourceBundle;
}
+ public static IWorkbench getActiveWorkbench() {
+ CompareUIPlugin plugin= getDefault();
+ if (plugin == null)
+ return null;
+ return plugin.getWorkbench();
+ }
+
+ public static IWorkbenchWindow getActiveWorkbenchWindow() {
+ IWorkbench workbench= getActiveWorkbench();
+ if (workbench == null)
+ return null;
+ return workbench.getActiveWorkbenchWindow();
+ }
+
/**
* Returns the active workkbench page or <code>null</code> if
* no active workkbench page can be determined.
@@ -203,13 +220,7 @@ public final class CompareUIPlugin extends AbstractUIPlugin {
* no active workkbench page can be determined
*/
private static IWorkbenchPage getActivePage() {
- CompareUIPlugin plugin= getDefault();
- if (plugin == null)
- return null;
- IWorkbench workbench= plugin.getWorkbench();
- if (workbench == null)
- return null;
- IWorkbenchWindow window= workbench.getActiveWorkbenchWindow();
+ IWorkbenchWindow window= getActiveWorkbenchWindow();
if (window == null)
return null;
return window.getActivePage();
@@ -223,16 +234,10 @@ public final class CompareUIPlugin extends AbstractUIPlugin {
* no workbench window is active
*/
public static Shell getShell() {
- CompareUIPlugin p= getDefault();
- if (p == null)
- return null;
- IWorkbench wb= p.getWorkbench();
- if (wb == null)
- return null;
- IWorkbenchWindow ww= wb.getActiveWorkbenchWindow();
- if (ww == null)
+ IWorkbenchWindow window= getActiveWorkbenchWindow();
+ if (window == null)
return null;
- return ww.getShell();
+ return window.getShell();
}
/**
@@ -810,4 +815,44 @@ public final class CompareUIPlugin extends AbstractUIPlugin {
iter.remove();
}
}
+
+ /**
+ * Returns an array of all editors that have an unsaved content. If the identical content is
+ * presented in more than one editor, only one of those editor parts is part of the result.
+ *
+ * @return an array of all dirty editor parts.
+ */
+ public static IEditorPart[] getDirtyEditors() {
+ Set inputs= new HashSet(7);
+ ArrayList result= new ArrayList(0);
+ IWorkbench workbench= CompareUIPlugin.getDefault().getWorkbench();
+ IWorkbenchWindow[] windows= workbench.getWorkbenchWindows();
+ for (int i= 0; i < windows.length; i++) {
+ IWorkbenchPage[] pages= windows[i].getPages();
+ for (int x= 0; x < pages.length; x++) {
+ IEditorPart[] editors= pages[x].getEditors();
+ for (int z= 0; z < editors.length; z++) {
+ IEditorPart editor= editors[z];
+ IEditorInput input= editor.getEditorInput();
+ if (editor.isDirty() && !inputs.contains(input)) {
+ inputs.add(input);
+ result.add(editor);
+ }
+ }
+ }
+ }
+ return (IEditorPart[])result.toArray(new IEditorPart[result.size()]);
+ }
+
+ public static void log(Throwable e) {
+ log(new Status(IStatus.ERROR, getPluginId(), INTERNAL_ERROR, CompareMessages.getString("JavaPlugin.internal_error"), e)); //$NON-NLS-1$
+ }
+
+ public static void log(IStatus status) {
+ getDefault().getLog().log(status);
+ }
+
+ public static String getPluginId() {
+ return getDefault().getDescriptor().getUniqueIdentifier();
+ }
}
diff --git a/bundles/org.eclipse.compare/compare/org/eclipse/compare/internal/ExceptionHandler.java b/bundles/org.eclipse.compare/compare/org/eclipse/compare/internal/ExceptionHandler.java
new file mode 100644
index 000000000..773b0499c
--- /dev/null
+++ b/bundles/org.eclipse.compare/compare/org/eclipse/compare/internal/ExceptionHandler.java
@@ -0,0 +1,127 @@
+/*
+ * (c) Copyright IBM Corp. 2000, 2001.
+ * All Rights Reserved.
+ */
+package org.eclipse.compare.internal;
+
+import java.io.StringWriter;
+import java.lang.reflect.InvocationTargetException;
+
+import org.eclipse.swt.widgets.Shell;
+
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Status;
+
+import org.eclipse.jface.dialogs.ErrorDialog;
+import org.eclipse.jface.dialogs.MessageDialog;
+
+/**
+ * The default exception handler shows an error dialog when one of its handle methods
+ * is called. If the passed exception is a <code>CoreException</code> an error dialog
+ * pops up showing the exception's status information. For a <code>InvocationTargetException</code>
+ * a normal message dialog pops up showing the exception's message. Additionally the exception
+ * is written to the platform log.
+ */
+public class ExceptionHandler {
+
+ private static ExceptionHandler fgInstance= new ExceptionHandler();
+
+ /**
+ * Logs the given exception using the platform's logging mechanism. The exception is
+ * logged as an error with the error code <code>JavaStatusConstants.INTERNAL_ERROR</code>.
+ */
+ public static void log(Throwable t, String message) {
+ CompareUIPlugin.log(new Status(IStatus.ERROR, CompareUIPlugin.getPluginId(),
+ CompareUIPlugin.INTERNAL_ERROR, message, t));
+ }
+
+ /**
+ * Handles the given <code>CoreException</code>. The workbench shell is used as a parent
+ * for the dialog window.
+ *
+ * @param e the <code>CoreException</code> to be handled
+ * @param title the dialog window's window title
+ * @param message message to be displayed by the dialog window
+ */
+ public static void handle(CoreException e, String title, String message) {
+ handle(e, CompareUIPlugin.getShell(), title, message);
+ }
+
+ /**
+ * Handles the given <code>CoreException</code>.
+ *
+ * @param e the <code>CoreException</code> to be handled
+ * @param parent the dialog window's parent shell
+ * @param title the dialog window's window title
+ * @param message message to be displayed by the dialog window
+ */
+ public static void handle(CoreException e, Shell parent, String title, String message) {
+ fgInstance.perform(e, parent, title, message);
+ }
+
+ /**
+ * Handles the given <code>InvocationTargetException</code>. The workbench shell is used
+ * as a parent for the dialog window.
+ *
+ * @param e the <code>InvocationTargetException</code> to be handled
+ * @param title the dialog window's window title
+ * @param message message to be displayed by the dialog window
+ */
+ public static void handle(InvocationTargetException e, String title, String message) {
+ handle(e, CompareUIPlugin.getShell(), title, message);
+ }
+
+ /**
+ * Handles the given <code>InvocationTargetException</code>.
+ *
+ * @param e the <code>InvocationTargetException</code> to be handled
+ * @param parent the dialog window's parent shell
+ * @param title the dialog window's window title
+ * @param message message to be displayed by the dialog window
+ */
+ public static void handle(InvocationTargetException e, Shell parent, String title, String message) {
+ fgInstance.perform(e, parent, title, message);
+ }
+
+ //---- Hooks for subclasses to control exception handling ------------------------------------
+
+ protected void perform(CoreException e, Shell shell, String title, String message) {
+ CompareUIPlugin.log(e);
+ IStatus status= e.getStatus();
+ if (status != null) {
+ ErrorDialog.openError(shell, title, message, status);
+ } else {
+ displayMessageDialog(e, e.getMessage(), shell, title, message);
+ }
+ }
+
+ protected void perform(InvocationTargetException e, Shell shell, String title, String message) {
+ Throwable target= e.getTargetException();
+ if (target instanceof CoreException) {
+ perform((CoreException)target, shell, title, message);
+ } else {
+ CompareUIPlugin.log(e);
+ if (e.getMessage() != null && e.getMessage().length() > 0) {
+ displayMessageDialog(e, e.getMessage(), shell, title, message);
+ } else {
+ displayMessageDialog(e, target.getMessage(), shell, title, message);
+ }
+ }
+ }
+
+ //---- Helper methods -----------------------------------------------------------------------
+
+ private void displayMessageDialog(Throwable t, String exceptionMessage, Shell shell, String title, String message) {
+ StringWriter msg= new StringWriter();
+ if (message != null) {
+ msg.write(message);
+ msg.write("\n\n"); //$NON-NLS-1$
+ }
+ if (exceptionMessage == null || exceptionMessage.length() == 0)
+ msg.write(CompareMessages.getString("ExceptionDialog.seeErrorLogMessage")); //$NON-NLS-1$
+ else
+ msg.write(exceptionMessage);
+ MessageDialog.openError(shell, title, msg.toString());
+ }
+}
diff --git a/bundles/org.eclipse.compare/compare/org/eclipse/compare/internal/ListContentProvider.java b/bundles/org.eclipse.compare/compare/org/eclipse/compare/internal/ListContentProvider.java
new file mode 100644
index 000000000..9170edeca
--- /dev/null
+++ b/bundles/org.eclipse.compare/compare/org/eclipse/compare/internal/ListContentProvider.java
@@ -0,0 +1,41 @@
+/*
+ * (c) Copyright IBM Corp. 2000, 2001.
+ * All Rights Reserved.
+ */
+package org.eclipse.compare.internal;
+
+import java.util.List;
+
+import org.eclipse.jface.viewers.IStructuredContentProvider;
+import org.eclipse.jface.viewers.Viewer;
+
+/**
+ * A specialized content provider to show a list of editor parts.
+ */
+public class ListContentProvider implements IStructuredContentProvider {
+ List fContents;
+
+ public ListContentProvider() {
+ }
+
+ public Object[] getElements(Object input) {
+ if (fContents != null && fContents == input)
+ return fContents.toArray();
+ return new Object[0];
+ }
+
+ public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
+ if (newInput instanceof List)
+ fContents= (List)newInput;
+ else
+ fContents= null;
+ // we use a fixed set.
+ }
+
+ public void dispose() {
+ }
+
+ public boolean isDeleted(Object o) {
+ return fContents != null && !fContents.contains(o);
+ }
+} \ No newline at end of file
diff --git a/bundles/org.eclipse.compare/compare/org/eclipse/compare/internal/ListDialog.java b/bundles/org.eclipse.compare/compare/org/eclipse/compare/internal/ListDialog.java
new file mode 100644
index 000000000..7cd262479
--- /dev/null
+++ b/bundles/org.eclipse.compare/compare/org/eclipse/compare/internal/ListDialog.java
@@ -0,0 +1,83 @@
+/*
+ * (c) Copyright IBM Corp. 2000, 2001.
+ * All Rights Reserved.
+ */
+package org.eclipse.compare.internal;
+
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.widgets.*;
+
+import org.eclipse.jface.dialogs.IDialogConstants;
+import org.eclipse.jface.viewers.*;
+
+import org.eclipse.ui.dialogs.SelectionDialog;
+
+public class ListDialog extends SelectionDialog {
+
+ private IStructuredContentProvider fContentProvider;
+ private ILabelProvider fLabelProvider;
+ private Object fInput;
+ private TableViewer fTableViewer;
+ private boolean fAddCancelButton;
+
+ public ListDialog(Shell parent) {
+ super(parent);
+ fAddCancelButton= false;
+ }
+
+ public void setInput(Object input) {
+ fInput= input;
+ }
+
+ public void setContentProvider(IStructuredContentProvider sp){
+ fContentProvider= sp;
+ }
+
+ public void setLabelProvider(ILabelProvider lp){
+ fLabelProvider= lp;
+ }
+
+ public void setAddCancelButton(boolean addCancelButton) {
+ fAddCancelButton= addCancelButton;
+ }
+
+ public TableViewer getTableViewer(){
+ return fTableViewer;
+ }
+
+ public boolean hasFilters(){
+ return fTableViewer.getFilters() != null && fTableViewer.getFilters().length != 0;
+ }
+
+ public void create() {
+ setShellStyle(SWT.DIALOG_TRIM | SWT.RESIZE);
+ super.create();
+ }
+
+ protected void createButtonsForButtonBar(Composite parent) {
+ if (! fAddCancelButton)
+ createButton(parent, IDialogConstants.OK_ID, IDialogConstants.OK_LABEL, true);
+ else
+ super.createButtonsForButtonBar(parent);
+ }
+
+ protected Control createDialogArea(Composite container) {
+ Composite parent= (Composite) super.createDialogArea(container);
+ createMessageArea(parent);
+ fTableViewer= new TableViewer(parent, getTableStyle());
+ fTableViewer.setContentProvider(fContentProvider);
+ Table table= fTableViewer.getTable();
+ fTableViewer.setLabelProvider(fLabelProvider);
+ fTableViewer.setInput(fInput);
+ GridData gd= new GridData(GridData.FILL_BOTH);
+ gd.heightHint= convertHeightInCharsToPixels(15);
+ gd.widthHint= convertWidthInCharsToPixels(55);
+ table.setLayoutData(gd);
+ return parent;
+ }
+
+ protected int getTableStyle() {
+ return SWT.SINGLE | SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER;
+ }
+}
diff --git a/bundles/org.eclipse.compare/compare/org/eclipse/compare/internal/Utilities.java b/bundles/org.eclipse.compare/compare/org/eclipse/compare/internal/Utilities.java
index 01f63aab0..0a81cc115 100644
--- a/bundles/org.eclipse.compare/compare/org/eclipse/compare/internal/Utilities.java
+++ b/bundles/org.eclipse.compare/compare/org/eclipse/compare/internal/Utilities.java
@@ -204,7 +204,7 @@ public class Utilities {
}
public static String getIconPath(Display display) {
- return "icons/full/";
+ return "icons/full/"; //$NON-NLS-1$
}
/**
diff --git a/bundles/org.eclipse.compare/compare/org/eclipse/compare/internal/patch/CompareWithPatchAction.java b/bundles/org.eclipse.compare/compare/org/eclipse/compare/internal/patch/CompareWithPatchAction.java
new file mode 100644
index 000000000..28dff2473
--- /dev/null
+++ b/bundles/org.eclipse.compare/compare/org/eclipse/compare/internal/patch/CompareWithPatchAction.java
@@ -0,0 +1,166 @@
+/*
+ * (c) Copyright IBM Corp. 2000, 2001.
+ * All Rights Reserved.
+ */
+package org.eclipse.compare.internal.patch;
+
+import java.lang.reflect.InvocationTargetException;
+import java.text.MessageFormat;
+import java.util.Arrays;
+
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.*;
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Button;
+
+import org.eclipse.jface.dialogs.*;
+import org.eclipse.jface.operation.IRunnableWithProgress;
+import org.eclipse.jface.util.Assert;
+import org.eclipse.jface.viewers.*;
+import org.eclipse.jface.window.Window;
+import org.eclipse.jface.wizard.*;
+import org.eclipse.jface.action.IAction;
+
+import org.eclipse.ui.IEditorPart;
+import org.eclipse.ui.internal.*;
+import org.eclipse.ui.IActionDelegate;
+
+import org.eclipse.core.resources.*;
+import org.eclipse.core.runtime.*;
+
+import org.eclipse.compare.internal.*;
+
+public class CompareWithPatchAction implements IActionDelegate {
+
+ static class PatchWizardDialog extends WizardDialog {
+
+ PatchWizardDialog(Shell parent, IWizard wizard) {
+ super(parent, wizard);
+
+ setShellStyle(getShellStyle() | SWT.RESIZE);
+ setMinimumPageSize(700, 500);
+ }
+ }
+
+ private ISelection fSelection;
+ private boolean fSavedFiles;
+ private boolean fAutobuildState;
+
+
+ public void selectionChanged(IAction action, ISelection selection) {
+ fSelection= selection;
+ action.setEnabled(fSelection != null && !fSelection.isEmpty());
+ }
+
+ public void run(IAction action) {
+ PatchWizard wizard= new PatchWizard(fSelection);
+
+ if (areAllEditorsSaved()) {
+ //RefactoringStatus activationStatus= refactoring.checkActivation(new NullProgressMonitor());
+ //if (! activationStatus.hasFatalError()){
+ // wizard.setActivationStatus(activationStatus);
+ PatchWizardDialog dialog= new PatchWizardDialog(CompareUIPlugin.getShell(), wizard);
+ if (dialog.open() == Dialog.CANCEL)
+ triggerBuild();
+
+ //} else{
+ //RefactoringErrorDialog.open(dialogTitle, activationStatus);
+ //}
+ }
+ }
+
+ private boolean areAllEditorsSaved(){
+ if (CompareUIPlugin.getDirtyEditors().length == 0)
+ return true;
+ if (! saveAllDirtyEditors())
+ return false;
+ Shell shell= CompareUIPlugin.getShell();
+ try {
+ // Save isn't cancelable.
+ IWorkspace workspace= ResourcesPlugin.getWorkspace();
+ IWorkspaceDescription description= workspace.getDescription();
+ boolean autoBuild= description.isAutoBuilding();
+ description.setAutoBuilding(false);
+ workspace.setDescription(description);
+ try {
+ new ProgressMonitorDialog(shell).run(false, false, createRunnable());
+ fSavedFiles= true;
+ } finally {
+ description.setAutoBuilding(autoBuild);
+ workspace.setDescription(description);
+ }
+ return true;
+ } catch (InvocationTargetException e) {
+ ExceptionHandler.handle(e, shell, PatchMessages.getString("PatchAction.ExceptionTitle"), PatchMessages.getString("Exception")); //$NON-NLS-1$ //$NON-NLS-2$
+ return false;
+ } catch (CoreException e) {
+ ExceptionHandler.handle(e, shell, PatchMessages.getString("PatchAction.ExceptionTitle"), PatchMessages.getString("Exception")); //$NON-NLS-1$ //$NON-NLS-2$
+ return false;
+ } catch (InterruptedException e) {
+ Assert.isTrue(false); // Can't happen. Operation isn't cancelable.
+ return false;
+ }
+ }
+
+ private IRunnableWithProgress createRunnable() {
+ return new IRunnableWithProgress() {
+ public void run(IProgressMonitor pm) {
+ IEditorPart[] editorsToSave= CompareUIPlugin.getDirtyEditors();
+ pm.beginTask(PatchMessages.getString("PatchAction.SavingDirtyEditorsTask"), editorsToSave.length); //$NON-NLS-1$
+ for (int i= 0; i < editorsToSave.length; i++) {
+ editorsToSave[i].doSave(new SubProgressMonitor(pm, 1));
+ pm.worked(1);
+ }
+ pm.done();
+ }
+ };
+ }
+
+ private boolean saveAllDirtyEditors() {
+ if (ComparePreferencePage.getSaveAllEditors()) //must save everything
+ return true;
+ ListDialog dialog= new ListDialog(CompareUIPlugin.getShell()) {
+ protected Control createDialogArea(Composite parent) {
+ Composite result= (Composite) super.createDialogArea(parent);
+ final Button check= new Button(result, SWT.CHECK);
+ check.setText(PatchMessages.getString("PatchAction.AlwaysSaveQuestion")); //$NON-NLS-1$
+ check.setSelection(ComparePreferencePage.getSaveAllEditors());
+ check.addSelectionListener(
+ new SelectionAdapter() {
+ public void widgetSelected(SelectionEvent e) {
+ ComparePreferencePage.setSaveAllEditors(check.getSelection());
+ }
+ }
+ );
+ return result;
+ }
+ };
+ dialog.setTitle(PatchMessages.getString("PatchAction.SaveAllQuestion")); //$NON-NLS-1$
+ dialog.setAddCancelButton(true);
+ dialog.setLabelProvider(createDialogLabelProvider());
+ dialog.setMessage(PatchMessages.getString("PatchAction.SaveAllDescription")); //$NON-NLS-1$
+ dialog.setContentProvider(new ListContentProvider());
+ dialog.setInput(Arrays.asList(CompareUIPlugin.getDirtyEditors()));
+ return dialog.open() == Dialog.OK;
+ }
+
+ private ILabelProvider createDialogLabelProvider() {
+ return new LabelProvider() {
+ public Image getImage(Object element) {
+ return ((IEditorPart) element).getTitleImage();
+ }
+ public String getText(Object element) {
+ return ((IEditorPart) element).getTitle();
+ }
+ };
+ }
+
+ private void triggerBuild() {
+ if (fSavedFiles && ResourcesPlugin.getWorkspace().getDescription().isAutoBuilding()) {
+ new GlobalBuildAction(CompareUIPlugin.getActiveWorkbench(), IncrementalProjectBuilder.INCREMENTAL_BUILD).run();
+ }
+ }
+}
diff --git a/bundles/org.eclipse.compare/compare/org/eclipse/compare/patch/Diff.java b/bundles/org.eclipse.compare/compare/org/eclipse/compare/internal/patch/Diff.java
index 77dc42e28..9682d5cfe 100644
--- a/bundles/org.eclipse.compare/compare/org/eclipse/compare/patch/Diff.java
+++ b/bundles/org.eclipse.compare/compare/org/eclipse/compare/internal/patch/Diff.java
@@ -2,7 +2,7 @@
* (c) Copyright IBM Corp. 2000, 2001.
* All Rights Reserved.
*/
-package org.eclipse.compare.patch;
+package org.eclipse.compare.internal.patch;
import java.util.*;
diff --git a/bundles/org.eclipse.compare/compare/org/eclipse/compare/patch/Hunk.java b/bundles/org.eclipse.compare/compare/org/eclipse/compare/internal/patch/Hunk.java
index 6620af3a5..28dc90b55 100644
--- a/bundles/org.eclipse.compare/compare/org/eclipse/compare/patch/Hunk.java
+++ b/bundles/org.eclipse.compare/compare/org/eclipse/compare/internal/patch/Hunk.java
@@ -2,7 +2,7 @@
* (c) Copyright IBM Corp. 2000, 2001.
* All Rights Reserved.
*/
-package org.eclipse.compare.patch;
+package org.eclipse.compare.internal.patch;
import java.util.List;
@@ -103,4 +103,18 @@ import org.eclipse.jface.util.Assert;
sb.append(Integer.toString(fNewLength));
return sb.toString();
}
+
+ String getRejectedDescription() {
+ StringBuffer sb= new StringBuffer();
+ sb.append("@@ -"); //$NON-NLS-1$
+ sb.append(Integer.toString(fOldStart));
+ sb.append(',');
+ sb.append(Integer.toString(fOldLength));
+ sb.append(" +"); //$NON-NLS-1$
+ sb.append(Integer.toString(fNewStart));
+ sb.append(',');
+ sb.append(Integer.toString(fNewLength));
+ sb.append(" @@"); //$NON-NLS-1$
+ return sb.toString();
+ }
}
diff --git a/bundles/org.eclipse.compare/compare/org/eclipse/compare/patch/InputPatchPage.java b/bundles/org.eclipse.compare/compare/org/eclipse/compare/internal/patch/InputPatchPage.java
index c0535baf3..988036dc1 100644
--- a/bundles/org.eclipse.compare/compare/org/eclipse/compare/patch/InputPatchPage.java
+++ b/bundles/org.eclipse.compare/compare/org/eclipse/compare/internal/patch/InputPatchPage.java
@@ -2,7 +2,7 @@
* (c) Copyright IBM Corp. 2000, 2001.
* All Rights Reserved.
*/
-package org.eclipse.compare.patch;
+package org.eclipse.compare.internal.patch;
import java.io.*;
import java.util.*;
@@ -55,9 +55,9 @@ import org.eclipse.compare.internal.Utilities;
InputPatchPage(PatchWizard pw) {
- super("InputPatchPage", "Patch Input Specification", null);
+ super("InputPatchPage", PatchMessages.getString("InputPatchPage.title"), null); //$NON-NLS-1$ //$NON-NLS-2$
fPatchWizard= pw;
- setMessage("Define what resource to patch with which patch.");
+ setMessage(PatchMessages.getString("InputPatchPage.message")); //$NON-NLS-1$
}
/**
@@ -70,7 +70,7 @@ import org.eclipse.compare.internal.Utilities;
/* package */ String getPatchName() {
if (getUseClipboard())
- return "Clipboard";
+ return PatchMessages.getString("InputPatchPage.Clipboard"); //$NON-NLS-1$
return getPatchFilePath();
}
@@ -82,7 +82,7 @@ import org.eclipse.compare.internal.Utilities;
setControl(composite);
Label l= new Label(composite, SWT.NONE); // a spacer
- l.setText("Select a single file or folder to patch:");
+ l.setText(PatchMessages.getString("InputPatchPage.SelectInput")); //$NON-NLS-1$
buildInputGroup(composite);
new Label(composite, SWT.NONE); // a spacer
@@ -121,7 +121,9 @@ import org.eclipse.compare.internal.Utilities;
try {
reader= new FileReader(patchFilePath);
} catch (FileNotFoundException ex) {
- MessageDialog.openError(null, "Error", "Patch file not found: " + patchFilePath);
+ MessageDialog.openError(null,
+ PatchMessages.getString("InputPatchPage.PatchErrorDialog.title"), //$NON-NLS-1$
+ PatchMessages.getString("InputPatchPage.PatchFileNotFound.message")); //$NON-NLS-1$
}
}
}
@@ -131,7 +133,9 @@ import org.eclipse.compare.internal.Utilities;
try {
patcher.parse(new BufferedReader(reader));
} catch (IOException ex) {
- MessageDialog.openError(null, "Error", "Error while parsing patch");
+ MessageDialog.openError(null,
+ PatchMessages.getString("InputPatchPage.PatchErrorDialog.title_2"), //$NON-NLS-1$
+ PatchMessages.getString("InputPatchPage.ParseError.message")); //$NON-NLS-1$
}
try {
@@ -142,7 +146,9 @@ import org.eclipse.compare.internal.Utilities;
Diff[] diffs= patcher.getDiffs();
if (diffs == null || diffs.length == 0) {
- MessageDialog.openError(null, "Error", "No diffs found in " + getPatchName());
+ MessageDialog.openError(null,
+ PatchMessages.getString("InputPatchPage.PatchErrorDialog.title_4"), //$NON-NLS-1$
+ PatchMessages.getString("InputPatchPage.NoDiffsFound.message")); //$NON-NLS-1$
return this;
}
@@ -243,7 +249,7 @@ import org.eclipse.compare.internal.Utilities;
private void buildPatchFileGroup(Composite parent) {
fPatchFileGroup= new Group(parent, SWT.NONE);
- fPatchFileGroup.setText("Select Patch");
+ fPatchFileGroup.setText(PatchMessages.getString("InputPatchPage.SelectPatch.title")); //$NON-NLS-1$
GridLayout layout= new GridLayout();
layout.numColumns= 3;
fPatchFileGroup.setLayout(layout);
@@ -251,7 +257,7 @@ import org.eclipse.compare.internal.Utilities;
// 1st row
fUsePatchFileButton= new Button(fPatchFileGroup, SWT.RADIO);
- fUsePatchFileButton.setText("File ");
+ fUsePatchFileButton.setText(PatchMessages.getString("InputPatchPage.FileButton.text")); //$NON-NLS-1$
fPatchFileNameField= new Combo(fPatchFileGroup, SWT.BORDER);
GridData gd= new GridData(GridData.FILL_HORIZONTAL);
@@ -260,12 +266,12 @@ import org.eclipse.compare.internal.Utilities;
fPatchFileNameField.setLayoutData(gd);
fPatchFileBrowseButton= new Button(fPatchFileGroup, SWT.PUSH);
- fPatchFileBrowseButton.setText("Choose...");
+ fPatchFileBrowseButton.setText(PatchMessages.getString("InputPatchPage.ChooseFileButton.text")); //$NON-NLS-1$
fPatchFileBrowseButton.setLayoutData(new GridData());
// 2nd row
fUseClipboardButton= new Button(fPatchFileGroup, SWT.RADIO);
- fUseClipboardButton.setText("Clipboard");
+ fUseClipboardButton.setText(PatchMessages.getString("InputPatchPage.UseClipboardButton.text")); //$NON-NLS-1$
gd= new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING);
gd.horizontalSpan= 2;
fUseClipboardButton.setLayoutData(gd);
@@ -376,7 +382,7 @@ import org.eclipse.compare.internal.Utilities;
ISelection selection= fPatchTargets.getSelection();
boolean anySelected= selection != null && !selection.isEmpty();
if (!anySelected)
- error= "Nothing selected to apply patch to.";
+ error= PatchMessages.getString("InputPatchPage.NothingSelected.message"); //$NON-NLS-1$
boolean gotPatch= false;
if (getUseClipboard()) {
@@ -389,20 +395,20 @@ import org.eclipse.compare.internal.Utilities;
if (s.length() > 0)
gotPatch= true;
else
- error= "Clipboard is empty.";
+ error= PatchMessages.getString("InputPatchPage.ClipboardIsEmpty.message"); //$NON-NLS-1$
} else
- error= "Clipboard does not contain text.";
+ error= PatchMessages.getString("InputPatchPage.NoTextInClipboard.message"); //$NON-NLS-1$
} else
- error= "Couldn't retrieve clipboard contents.";
+ error= PatchMessages.getString("InputPatchPage.CouldNotReadClipboard.message"); //$NON-NLS-1$
} else {
String path= fPatchFileNameField.getText();
if (path != null && path.length() > 0) {
File file= new File(path);
gotPatch= file.exists() && file.isFile() && file.length() > 0;
if (!gotPatch)
- error= "Can't locate patch file: " + path;
+ error= PatchMessages.getString("InputPatchPage.CannotLocatePatch.message") + path; //$NON-NLS-1$
} else {
- error= "No file name.";
+ error= PatchMessages.getString("InputPatchPage.NoFileName.message"); //$NON-NLS-1$
}
}
@@ -412,7 +418,7 @@ import org.eclipse.compare.internal.Utilities;
protected void handlePatchFileBrowseButtonPressed() {
FileDialog dialog= new FileDialog(getShell(), SWT.NONE);
- dialog.setText("Select Patch File");
+ dialog.setText(PatchMessages.getString("InputPatchPage.SelectPatchFileDialog.title")); //$NON-NLS-1$
dialog.setFilterPath(getPatchFilePath());
String res= dialog.open();
if (res == null)
@@ -515,8 +521,7 @@ import org.eclipse.compare.internal.Utilities;
String patchFilePath= settings.get(STORE_PATCH_FILES_ID);
if (patchFilePath != null)
setSourceName(patchFilePath);
- } else
- System.out.println("restoreWidgetValues: no dialog settings");
+ }
}
/**
@@ -559,7 +564,7 @@ import org.eclipse.compare.internal.Utilities;
private String getPatchFilePath() {
if (fPatchFileNameField != null)
return fPatchFileNameField.getText();
- return "";
+ return ""; //$NON-NLS-1$
}
/**
diff --git a/bundles/org.eclipse.compare/compare/org/eclipse/compare/patch/LineReader.java b/bundles/org.eclipse.compare/compare/org/eclipse/compare/internal/patch/LineReader.java
index 4306e63ea..98026451e 100644
--- a/bundles/org.eclipse.compare/compare/org/eclipse/compare/patch/LineReader.java
+++ b/bundles/org.eclipse.compare/compare/org/eclipse/compare/internal/patch/LineReader.java
@@ -2,7 +2,7 @@
* (c) Copyright IBM Corp. 2000, 2001.
* All Rights Reserved.
*/
-package org.eclipse.compare.patch;
+package org.eclipse.compare.internal.patch;
import java.io.*;
import java.util.*;
diff --git a/bundles/org.eclipse.compare/compare/org/eclipse/compare/patch/PatchCompareInput.java b/bundles/org.eclipse.compare/compare/org/eclipse/compare/internal/patch/PatchCompareInput.java
index 47f73dc24..1f26392b3 100644
--- a/bundles/org.eclipse.compare/compare/org/eclipse/compare/patch/PatchCompareInput.java
+++ b/bundles/org.eclipse.compare/compare/org/eclipse/compare/internal/patch/PatchCompareInput.java
@@ -2,7 +2,7 @@
* (c) Copyright IBM Corp. 2000, 2001.
* All Rights Reserved.
*/
-package org.eclipse.compare.patch;
+package org.eclipse.compare.internal.patch;
import java.io.*;
import java.io.ByteArrayInputStream;
@@ -37,13 +37,13 @@ import org.eclipse.compare.internal.*;
fDiff= diff;
}
public String getName() {
- return fName + " *";
+ return fName + " *"; //$NON-NLS-1$
}
public String getType() {
- return "txt";
+ return "txt"; //$NON-NLS-1$
}
public Image getImage() {
- return CompareUI.getImage("file");
+ return CompareUI.getImage("file"); //$NON-NLS-1$
}
public InputStream getContents() {
return new ByteArrayInputStream(fDiff.fRejected.getBytes());
@@ -91,7 +91,7 @@ import org.eclipse.compare.internal.*;
String rej= diff.fRejected;
if (rej != null) {
IPath pp= path.removeLastSegments(1);
- pp= pp.append(path.lastSegment() + ".rej");
+ pp= pp.append(path.lastSegment() + ".rej"); //$NON-NLS-1$
createPath(fRoot, rootFolder, pp, diff, true);
}
}
@@ -104,7 +104,8 @@ import org.eclipse.compare.internal.*;
cc.setLeftLabel(leftLabel);
cc.setLeftImage(CompareUIPlugin.getImage(fTarget));
- String rightLabel= "Patch: " + fPatcher.getName();
+ String rformat= PatchMessages.getString("PatchCompareInput.RightTitle.format"); //$NON-NLS-1$
+ String rightLabel= MessageFormat.format(rformat, new String[] { fPatcher.getName() } );
cc.setRightLabel(rightLabel);
//cc.setRightImage(CompareUIPlugin.getImage(fRightResource));
diff --git a/bundles/org.eclipse.compare/compare/org/eclipse/compare/internal/patch/PatchErrorDialog.java b/bundles/org.eclipse.compare/compare/org/eclipse/compare/internal/patch/PatchErrorDialog.java
new file mode 100644
index 000000000..cd4cb28a6
--- /dev/null
+++ b/bundles/org.eclipse.compare/compare/org/eclipse/compare/internal/patch/PatchErrorDialog.java
@@ -0,0 +1,17 @@
+/*
+ * (c) Copyright IBM Corp. 2000, 2001.
+ * All Rights Reserved.
+ */
+package org.eclipse.compare.internal.patch;
+
+import org.eclipse.jface.dialogs.MessageDialog;
+
+import org.eclipse.compare.internal.ListDialog;
+
+public class PatchErrorDialog {
+
+ private PatchErrorDialog() {
+ // no instance.
+ }
+
+}
diff --git a/bundles/org.eclipse.compare/compare/org/eclipse/compare/internal/patch/PatchMessages.java b/bundles/org.eclipse.compare/compare/org/eclipse/compare/internal/patch/PatchMessages.java
new file mode 100644
index 000000000..8dce380cc
--- /dev/null
+++ b/bundles/org.eclipse.compare/compare/org/eclipse/compare/internal/patch/PatchMessages.java
@@ -0,0 +1,26 @@
+/*
+ * (c) Copyright IBM Corp. 2002.
+ * All Rights Reserved.
+ */
+package org.eclipse.compare.internal.patch;
+
+import java.util.MissingResourceException;
+import java.util.ResourceBundle;
+
+public class PatchMessages {
+
+ private static final String RESOURCE_BUNDLE= "org.eclipse.compare.internal.patch.PatchMessages";//$NON-NLS-1$
+
+ private static ResourceBundle fgResourceBundle= ResourceBundle.getBundle(RESOURCE_BUNDLE);
+
+ private PatchMessages() {
+ }
+
+ 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/compare/org/eclipse/compare/internal/patch/PatchMessages.properties b/bundles/org.eclipse.compare/compare/org/eclipse/compare/internal/patch/PatchMessages.properties
new file mode 100644
index 000000000..e9aed4f47
--- /dev/null
+++ b/bundles/org.eclipse.compare/compare/org/eclipse/compare/internal/patch/PatchMessages.properties
@@ -0,0 +1,73 @@
+# =====================================
+# (c) Copyright IBM Corp. 2002.
+# All Rights Reserved.
+# =====================================
+
+#
+# 'Compare with Patch' Action
+#
+PatchAction.ExceptionTitle=Saving Resources
+PatchAction.Exception=Unexpected exception. See log for details
+PatchAction.SavingDirtyEditorsTask=Saving dirty editors
+PatchAction.AlwaysSaveQuestion=&Always save all modified resources automatically prior to patching
+PatchAction.SaveAllQuestion=Save all modified resources
+PatchAction.SaveAllDescription=All modified resources must be saved before this operation.\nPress OK to confirm or Cancel otherwise
+
+#
+# PatchWizard
+#
+PatchWizard.title=Resource Patcher
+
+#
+# InputPatchPage
+#
+InputPatchPage.title= Patch Input Specification
+InputPatchPage.message= Define what resource to patch with which patch
+InputPatchPage.Clipboard=Clipboard
+InputPatchPage.SelectInput=Select a single file or folder to patch:
+InputPatchPage.PatchErrorDialog=Patch Error
+InputPatchPage.SelectPatch.title=Select Patch
+InputPatchPage.FileButton.text=File
+InputPatchPage.ChooseFileButton.text=Choose
+InputPatchPage.UseClipboardButton.text=Clipboard
+InputPatchPage.NothingSelected.message=Nothing selected to apply patch to
+InputPatchPage.ClipboardIsEmpty.message=Clipboard is empty
+InputPatchPage.NoTextInClipboard.message=Clipboard does not contain text
+InputPatchPage.CouldNotReadClipboard.message=Couldn\'t retrieve clipboard contents
+InputPatchPage.CannotLocatePatch.message=Can\'t locate patch file:
+InputPatchPage.NoFileName.message=No file name
+InputPatchPage.SelectPatchFileDialog.title=Select Patch File
+InputPatchPage.PatchFileNotFound.message=Patch file not found.
+InputPatchPage.ParseError.message=Error while parsing patch
+InputPatchPage.NoDiffsFound.message=No diffs found in
+
+#
+# PreviewPatchPage
+#
+PreviewPatchPage.title= Verify Patch
+PreviewPatchPage.message= The tree shows the contents of the patch.\nA checked item indicates that a patch could be applied succesfully. Uncheck an item if you want to exclude it.
+PreviewPatchPage.Left.title= Original
+PreviewPatchPage.Right.title= Result
+PreviewPatchPage.PatchOptions.title=Patch Options
+PreviewPatchPage.IgnoreSegments.text=Ignore leading path name segments:
+PreviewPatchPage.ReversePatch.text=Reverse Patch
+PreviewPatchPage.FuzzFactor.text=Maximum fuzz factor:
+PreviewPatchPage.FuzzFactor.tooltip=Allow context to shift this number of lines from the original place
+PreviewPatchPage.IgnoreWhitespace.text=Ignore Whitespace
+PreviewPatchPage.NoName.text=no name
+PreviewPatchPage.FileExists.error=(file already exists)
+PreviewPatchPage.FileDoesNotExist.error=(file doesn\'t exist)
+PreviewPatchPage.NoMatch.error=(no match)
+
+#
+# Patcher
+#
+Patcher.ErrorDialog.title=title
+Patcher.DeleteError.message=Error while deleting resource
+Patcher.UpdateError.message=Error while updating resource
+Patcher.RefreshError.message=Error while refreshing from local
+
+#
+# PatchCompareInput
+#
+PatchCompareInput.RightTitle.format= Patch: {0}
diff --git a/bundles/org.eclipse.compare/compare/org/eclipse/compare/patch/PatchWizard.java b/bundles/org.eclipse.compare/compare/org/eclipse/compare/internal/patch/PatchWizard.java
index 8fc93f312..466b59a42 100644
--- a/bundles/org.eclipse.compare/compare/org/eclipse/compare/patch/PatchWizard.java
+++ b/bundles/org.eclipse.compare/compare/org/eclipse/compare/internal/patch/PatchWizard.java
@@ -2,16 +2,21 @@
* (c) Copyright IBM Corp. 2000, 2001.
* All Rights Reserved.
*/
-package org.eclipse.compare.patch;
+package org.eclipse.compare.internal.patch;
+
+import java.lang.reflect.InvocationTargetException;
import org.eclipse.swt.graphics.Image;
-import org.eclipse.jface.dialogs.IDialogSettings;
+import org.eclipse.jface.operation.IRunnableWithProgress;
import org.eclipse.jface.viewers.*;
import org.eclipse.jface.wizard.Wizard;
+import org.eclipse.jface.dialogs.IDialogSettings;
+import org.eclipse.jface.dialogs.ProgressMonitorDialog;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.NullProgressMonitor;
+import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.compare.*;
import org.eclipse.compare.internal.*;
@@ -41,7 +46,7 @@ import org.eclipse.compare.structuremergeviewer.Differencer;
fPatcher= new Patcher();
- setWindowTitle("Resource Patcher");
+ setWindowTitle(PatchMessages.getString("PatchWizard.title")); //$NON-NLS-1$
IDialogSettings workbenchSettings= CompareUIPlugin.getDefault().getDialogSettings();
IDialogSettings section= workbenchSettings.getSection(DIALOG_SETTINGS_KEY); //$NON-NLS-1$
@@ -111,7 +116,19 @@ import org.eclipse.compare.structuremergeviewer.Differencer;
CompareUI.openCompareEditor(new PatchCompareInput(cc, fPatcher, new StructuredSelection(fTarget)));
} else {
fPatcher.setName(fPatchWizardPage.getPatchName());
- fPatcher.applyAll(getTarget(), new NullProgressMonitor());
+
+ try {
+ IRunnableWithProgress op= new IRunnableWithProgress() {
+ public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
+ fPatcher.applyAll(getTarget(), monitor);
+ }
+ };
+ new ProgressMonitorDialog(CompareUIPlugin.getShell()).run(true, true, op);
+ } catch (InvocationTargetException e) {
+ // handle exception
+ } catch (InterruptedException e) {
+ // handle cancelation
+ }
}
// Save the dialog settings
diff --git a/bundles/org.eclipse.compare/compare/org/eclipse/compare/patch/PatchedResource.java b/bundles/org.eclipse.compare/compare/org/eclipse/compare/internal/patch/PatchedResource.java
index 9e8a36156..5236f80e0 100644
--- a/bundles/org.eclipse.compare/compare/org/eclipse/compare/patch/PatchedResource.java
+++ b/bundles/org.eclipse.compare/compare/org/eclipse/compare/internal/patch/PatchedResource.java
@@ -2,7 +2,7 @@
* (c) Copyright IBM Corp. 2000, 2001.
* All Rights Reserved.
*/
-package org.eclipse.compare.patch;
+package org.eclipse.compare.internal.patch;
import java.io.*;
diff --git a/bundles/org.eclipse.compare/compare/org/eclipse/compare/patch/Patcher.java b/bundles/org.eclipse.compare/compare/org/eclipse/compare/internal/patch/Patcher.java
index 36f8ac677..c2d5264b3 100644
--- a/bundles/org.eclipse.compare/compare/org/eclipse/compare/patch/Patcher.java
+++ b/bundles/org.eclipse.compare/compare/org/eclipse/compare/internal/patch/Patcher.java
@@ -1,4 +1,4 @@
-package org.eclipse.compare.patch;
+package org.eclipse.compare.internal.patch;
import java.io.*;
import java.text.*;
@@ -10,6 +10,7 @@ import org.eclipse.core.runtime.*;
import org.eclipse.core.resources.*;
import org.eclipse.compare.structuremergeviewer.Differencer;
+import org.eclipse.compare.internal.ExceptionHandler;
/**
@@ -250,10 +251,12 @@ public class Patcher {
}
break;
default:
- int a1= c, a2= 0;
- if (line.length() > 1)
- a2= line.charAt(1);
- if (DEBUG) System.out.println("char: " + a1 + " " + a2);
+ if (DEBUG) {
+ int a1= c, a2= 0;
+ if (line.length() > 1)
+ a2= line.charAt(1);
+ System.out.println("char: " + a1 + " " + a2); //$NON-NLS-1$ //$NON-NLS-2$
+ }
break;
}
return line;
@@ -523,7 +526,7 @@ public class Patcher {
if (pos >= 0)
path= path.substring(0, pos);
if (path2 != null && !path2.equals(path)) {
- if (DEBUG) System.out.println("path mismatch: " + path2);
+ if (DEBUG) System.out.println("path mismatch: " + path2); //$NON-NLS-1$
path= path2;
}
return new Path(path);
@@ -544,13 +547,13 @@ public class Patcher {
pair[0]= pair[1]= -1;
int startPos= line.indexOf(start);
if (startPos < 0) {
- if (DEBUG) System.out.println("parsing error in extractPair: couldn't find \'" + start + "\'");
+ if (DEBUG) System.out.println("parsing error in extractPair: couldn't find \'" + start + "\'"); //$NON-NLS-1$ //$NON-NLS-2$
return;
}
line= line.substring(startPos+1);
int endPos= line.indexOf(' ');
if (endPos < 0) {
- if (DEBUG) System.out.println("parsing error in extractPair: couldn't find end blank");
+ if (DEBUG) System.out.println("parsing error in extractPair: couldn't find end blank"); //$NON-NLS-1$
return;
}
line= line.substring(0, endPos);
@@ -592,11 +595,7 @@ public class Patcher {
patch(diff, lines, failedHunks);
- StringBuffer sb= new StringBuffer();
- Iterator iter= lines.iterator();
- while (iter.hasNext())
- sb.append((String)iter.next());
- return sb.toString();
+ return createString(lines);
}
/**
@@ -631,14 +630,15 @@ public class Patcher {
}
if (found) {
- if (DEBUG) System.out.println("patched hunk at offset: " + (shift-oldShift));
+ if (DEBUG) System.out.println("patched hunk at offset: " + (shift-oldShift)); //$NON-NLS-1$
shift+= doPatch(hunk, lines, shift);
} else {
if (failedHunks != null) {
- if (DEBUG) System.out.println("failed hunk");
+ if (DEBUG) System.out.println("failed hunk"); //$NON-NLS-1$
failedHunks.add(hunk);
}
}
+ oldShift= oldShift; // prevent compiler warning about unused local variable
}
return shift;
}
@@ -726,76 +726,109 @@ public class Patcher {
public void applyAll(IResource target, IProgressMonitor pm) {
- if (DEBUG) System.out.println("applyAll: start");
+ final int WORK_UNIT= 10;
+
+ if (DEBUG) System.out.println("applyAll: start"); //$NON-NLS-1$
+ IFile file= null; // file to be patched
IContainer container= null;
if (target instanceof IContainer)
container= (IContainer) target;
- else {
- if (DEBUG) System.out.println("applyAll: not yet implemented");
+ else if (target instanceof IFile) {
+ file= (IFile) target;
+ container= file.getParent();
+ } else {
+ System.out.println("applyAll: not yet implemented"); //$NON-NLS-1$
return;
}
+ if (pm != null)
+ pm.beginTask("Patching", fDiffs.length*WORK_UNIT);
+
for (int i= 0; i < fDiffs.length; i++) {
+
+ int workTicks= WORK_UNIT;
+
Diff diff= fDiffs[i];
if (diff.fIsEnabled) {
IPath path= getPath(diff);
- IFile file= createPath(container, path);
+ if (pm != null)
+ pm.subTask(path.toString());
+
+ if (container != null)
+ file= createPath(container, path);
+ List failed= new ArrayList();
+ List result= null;
int type= diff.getType();
switch (type) {
case Differencer.ADDITION:
- if (DEBUG) System.out.println(" add: " + path);
- updateFile(diff, file, true, pm);
+ // patch it and collect rejected hunks
+ result= apply(diff, file, true, failed);
+ updateFile(createString(result), file, new SubProgressMonitor(pm, workTicks));
+ workTicks-= WORK_UNIT;
break;
case Differencer.DELETION:
- if (DEBUG) System.out.println(" del: " + path);
- deleteFile(file, pm);
+ deleteFile(file, new SubProgressMonitor(pm, workTicks));
+ workTicks-= WORK_UNIT;
break;
case Differencer.CHANGE:
- if (DEBUG) System.out.println(" chg: " + path);
- updateFile(diff, file, false, pm);
+ // patch it and collect rejected hunks
+ result= apply(diff, file, false, failed);
+ updateFile(createString(result), file, new SubProgressMonitor(pm, workTicks));
+ workTicks-= WORK_UNIT;
break;
}
-
- /*
- String rej= diff.fRejected;
- if (rej != null) {
- IPath pp= path.removeLastSegments(1);
- pp= pp.append(path.lastSegment() + ".rej");
- createPath(fRoot, rootFolder, pp, diff, true);
+
+ if (failed.size() > 0) {
+ IPath pp= null;
+ if (path.segmentCount() > 1) {
+ pp= path.removeLastSegments(1);
+ pp= pp.append(path.lastSegment() + ".rej"); //$NON-NLS-1$
+ } else
+ pp= new Path(path.lastSegment() + ".rej"); //$NON-NLS-1$
+ file= createPath(container, pp);
+ updateFile(getRejected(failed), file, pm);
}
- */
}
- if (pm != null)
- pm.worked(1);
+
+ if (pm != null) {
+ if (pm.isCanceled())
+ break;
+ if (workTicks > 0)
+ pm.worked(workTicks);
+ }
}
+ /*
+ if (pm != null)
+ pm.subTask("Refreshing");
try {
target.refreshLocal(IResource.DEPTH_INFINITE, pm);
} catch (CoreException ex) {
- if (DEBUG) System.out.println("refreshLocal: exception " + ex);
+ ExceptionHandler.handle(ex,
+ PatchMessages.getString("Patcher.ErrorDialog.title"), //$NON-NLS-1$
+ PatchMessages.getString("Patcher.RefreshError.message")); //$NON-NLS-1$
}
- if (DEBUG) System.out.println("applyAll: end");
+ */
+
+ // IWorkspace.validateEdit(IFile[], Object context);
}
List apply(Diff diff, IFile file, boolean create, List failedHunks) {
- if (file == null)
- if (DEBUG) System.out.println(" file == null");
-
List lines= null;
- if (!create) {
+ if (!create && file != null) {
// read current contents
InputStream is= null;
try {
is= file.getContents();
BufferedReader reader= new BufferedReader(new InputStreamReader(is));
lines= new LineReader(reader).readLines();
- if (DEBUG) System.out.println(" creating reader successful");
+ if (DEBUG) System.out.println(" creating reader successful"); //$NON-NLS-1$
} catch(CoreException ex) {
- if (DEBUG) System.out.println(" reading contents: " + ex);
+ if (DEBUG) System.out.println(" reading contents: " + ex); //$NON-NLS-1$
} finally {
if (is != null)
try {
@@ -809,48 +842,58 @@ public class Patcher {
lines= new ArrayList();
patch(diff, lines, failedHunks);
-
+
return lines;
}
+ String getRejected(List failedHunks) {
+ if (failedHunks.size() <= 0)
+ return null;
+
+ StringBuffer sb= new StringBuffer();
+ Iterator iter= failedHunks.iterator();
+ while (iter.hasNext()) {
+ Hunk hunk= (Hunk) iter.next();
+ sb.append(hunk.getRejectedDescription());
+ sb.append('\n');
+ sb.append(hunk.getContent());
+ }
+ return sb.toString();
+ }
+
private void deleteFile(IFile file, IProgressMonitor pm) {
try {
file.delete(true, true, pm);
} catch (CoreException ex) {
- System.out.println("deleteFile: exception: " + ex);
+ ExceptionHandler.handle(ex,
+ PatchMessages.getString("Patcher.ErrorDialog.title"), //$NON-NLS-1$
+ PatchMessages.getString("Patcher.DeleteError.message")); //$NON-NLS-1$
}
}
-
- private void updateFile(Diff diff, IFile file, boolean create, IProgressMonitor pm) {
-
- if (DEBUG) System.out.println(" updateFile: start");
-
- // patch it and collect rejected hunks
- List failed= new ArrayList();
-
- if (DEBUG) System.out.println(" patching: start");
- List lines= apply(diff, file, create, failed);
- if (DEBUG) System.out.println(" patching: end");
-
+
+ private String createString(List lines) {
// convert the result into a String
StringBuffer sb= new StringBuffer();
Iterator iter= lines.iterator();
while (iter.hasNext())
sb.append((String)iter.next());
- String contents= sb.toString();
+ return sb.toString();
+ }
+
+ private void updateFile(String contents, IFile file, IProgressMonitor pm) {
// and save it
InputStream is= new ByteArrayInputStream(contents.getBytes());
try {
if (file.exists()) {
file.setContents(is, false, true, pm);
- if (DEBUG) System.out.println(" setContents: successfull");
} else {
file.create(is, false, pm);
- if (DEBUG) System.out.println(" create: successfull");
}
} catch (CoreException ex) {
- if (DEBUG) System.out.println(" exception: " + ex);
+ ExceptionHandler.handle(ex,
+ PatchMessages.getString("Patcher.ErrorDialog.title"), //$NON-NLS-1$
+ PatchMessages.getString("Patcher.UpdateError.message")); //$NON-NLS-1$
} finally {
if (is != null)
try {
@@ -858,7 +901,6 @@ public class Patcher {
} catch(IOException ex) {
}
}
- if (DEBUG) System.out.println(" updateFile: end");
}
private IFile createPath(IContainer folder, IPath path) {
diff --git a/bundles/org.eclipse.compare/compare/org/eclipse/compare/patch/PreviewPatchPage.java b/bundles/org.eclipse.compare/compare/org/eclipse/compare/internal/patch/PreviewPatchPage.java
index 952c5615f..99e82b5f6 100644
--- a/bundles/org.eclipse.compare/compare/org/eclipse/compare/patch/PreviewPatchPage.java
+++ b/bundles/org.eclipse.compare/compare/org/eclipse/compare/internal/patch/PreviewPatchPage.java
@@ -2,7 +2,7 @@
* (c) Copyright IBM Corp. 2000, 2001.
* All Rights Reserved.
*/
-package org.eclipse.compare.patch;
+package org.eclipse.compare.internal.patch;
import java.io.*;
import java.util.*;
@@ -46,7 +46,7 @@ import org.eclipse.compare.structuremergeviewer.*;
return null;
}
public String getName() {
- return "no name";
+ return PatchMessages.getString("PreviewPatchPage.NoName.text"); //$NON-NLS-1$
}
public String getType() {
return fType;
@@ -73,28 +73,25 @@ import org.eclipse.compare.structuremergeviewer.*;
/* package */ PreviewPatchPage(PatchWizard pw) {
- super("PreviewPatchPage", "Verify Patch", null);
+ super("PreviewPatchPage", PatchMessages.getString("PreviewPatchPage.title"), null); //$NON-NLS-1$ //$NON-NLS-2$
- setMessage(
- "The tree shows the contents of the patch. " +
- "A checked item indicates that a patch could be applied succesfully.\n" +
- "Uncheck an item if you want to exclude it.");
+ setMessage(PatchMessages.getString("PreviewPatchPage.message")); //$NON-NLS-1$
fPatchWizard= pw;
//setPageComplete(false);
int w= 16;
fNullImage= new DiffImage(null, null, w).createImage();
- fAddImage= new DiffImage(null, CompareUIPlugin.getImageDescriptor("ovr16/add_ov.gif"), w).createImage();
- fDelImage= new DiffImage(null, CompareUIPlugin.getImageDescriptor("ovr16/del_ov.gif"), w).createImage();
+ fAddImage= new DiffImage(null, CompareUIPlugin.getImageDescriptor("ovr16/add_ov.gif"), w).createImage(); //$NON-NLS-1$
+ fDelImage= new DiffImage(null, CompareUIPlugin.getImageDescriptor("ovr16/del_ov.gif"), w).createImage(); //$NON-NLS-1$
fCompareConfiguration= new CompareConfiguration();
fCompareConfiguration.setLeftEditable(false);
- fCompareConfiguration.setLeftLabel("Original");
+ fCompareConfiguration.setLeftLabel(PatchMessages.getString("PreviewPatchPage.Left.title")); //$NON-NLS-1$
fCompareConfiguration.setRightEditable(false);
- fCompareConfiguration.setRightLabel("Result");
+ fCompareConfiguration.setRightLabel(PatchMessages.getString("PreviewPatchPage.Right.title")); //$NON-NLS-1$
}
/* (non-Javadoc)
@@ -187,7 +184,7 @@ import org.eclipse.compare.structuremergeviewer.*;
final Patcher patcher= fPatchWizard.getPatcher();
Group group= new Group(parent, SWT.NONE);
- group.setText("Patch Options");
+ group.setText(PatchMessages.getString("PreviewPatchPage.PatchOptions.title")); //$NON-NLS-1$
GridLayout layout= new GridLayout();
layout.numColumns= 5;
group.setLayout(layout);
@@ -195,7 +192,7 @@ import org.eclipse.compare.structuremergeviewer.*;
//fPatchFileGroup.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
// 1st row
- new Label(group, SWT.NONE).setText("Ignore leading path name segments:");
+ new Label(group, SWT.NONE).setText(PatchMessages.getString("PreviewPatchPage.IgnoreSegments.text")); //$NON-NLS-1$
fStripPrefixSegments= new Combo(group, SWT.DROP_DOWN | SWT.READ_ONLY | SWT.SIMPLE);
int prefixCnt= patcher.getStripPrefixSegments();
@@ -206,16 +203,16 @@ import org.eclipse.compare.structuremergeviewer.*;
addSpacer(group);
fReversePatchButton= new Button(group, SWT.CHECK);
- fReversePatchButton.setText("Reverse Patch");
+ fReversePatchButton.setText(PatchMessages.getString("PreviewPatchPage.ReversePatch.text")); //$NON-NLS-1$
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");
+ l.setText(PatchMessages.getString("PreviewPatchPage.FuzzFactor.text")); //$NON-NLS-1$
+ l.setToolTipText(PatchMessages.getString("PreviewPatchPage.FuzzFactor.tooltip")); //$NON-NLS-1$
fFuzzField= new Text(group, SWT.BORDER);
- fFuzzField.setText("2");
+ fFuzzField.setText("2"); //$NON-NLS-1$
GridData gd2= new GridData(GridData.HORIZONTAL_ALIGN_CENTER);
gd2.widthHint= 30;
fFuzzField.setLayoutData(gd2);
@@ -223,7 +220,7 @@ import org.eclipse.compare.structuremergeviewer.*;
addSpacer(group);
fIgnoreWhitespaceButton= new Button(group, SWT.CHECK);
- fIgnoreWhitespaceButton.setText("Ignore Whitespace");
+ fIgnoreWhitespaceButton.setText(PatchMessages.getString("PreviewPatchPage.IgnoreWhitespace.text")); //$NON-NLS-1$
addSpacer(group);
@@ -384,7 +381,7 @@ import org.eclipse.compare.structuremergeviewer.*;
} else {
// file already exists
diff.fIsEnabled= false;
- error= "(file already exists)";
+ error= PatchMessages.getString("PreviewPatchPage.FileExists.error"); //$NON-NLS-1$
}
create= true;
} else {
@@ -398,27 +395,17 @@ import org.eclipse.compare.structuremergeviewer.*;
} else {
// file doesn't exist
diff.fIsEnabled= false;
- error= "(file doesn't exist)";
+ error= PatchMessages.getString("PreviewPatchPage.FileDoesNotExist.error"); //$NON-NLS-1$
}
}
boolean checked= false;
- ArrayList failedHunks= new ArrayList(); // collect rejected hunks here
-
+ ArrayList failedHunks= new ArrayList();
fPatchWizard.getPatcher().apply(diff, file, create, failedHunks);
- if (! failedHunks.isEmpty()) {
- StringBuffer sb= new StringBuffer();
- Iterator iter= failedHunks.iterator();
- while (iter.hasNext()) {
- Hunk hunk= (Hunk) iter.next();
- sb.append(hunk.getDescription());
- sb.append('\n');
- sb.append(hunk.getContent());
- }
- diff.fRejected= sb.toString();
- }
+ if (failedHunks.size() > 0)
+ diff.fRejected= fPatchWizard.getPatcher().getRejected(failedHunks);
int checkedSubs= 0; // counts checked hunk items
TreeItem[] hunkItems= item.getItems();
@@ -427,7 +414,7 @@ import org.eclipse.compare.structuremergeviewer.*;
boolean failed= failedHunks.contains(hunk);
String hunkError= null;
if (failed)
- hunkError= "(no match)";
+ hunkError= PatchMessages.getString("PreviewPatchPage.NoMatch.error"); //$NON-NLS-1$
hunk.fIsEnabled= diff.fIsEnabled && !failed;
hunkItems[h].setChecked(hunk.fIsEnabled);
if (hunk.fIsEnabled) {
@@ -436,13 +423,13 @@ import org.eclipse.compare.structuremergeviewer.*;
}
String hunkLabel= hunk.getDescription();
if (hunkError != null)
- hunkLabel+= " " + hunkError;
+ hunkLabel+= " " + hunkError; //$NON-NLS-1$
hunkItems[h].setText(hunkLabel);
}
String label= diff.getDescription(strip);
if (error != null)
- label+= " " + error;
+ label+= " " + error; //$NON-NLS-1$
item.setText(label);
item.setImage(getImage(diff));
item.setChecked(checked);
diff --git a/bundles/org.eclipse.compare/compare/org/eclipse/compare/patch/CompareWithPatchAction.java b/bundles/org.eclipse.compare/compare/org/eclipse/compare/patch/CompareWithPatchAction.java
deleted file mode 100644
index 73c2021c1..000000000
--- a/bundles/org.eclipse.compare/compare/org/eclipse/compare/patch/CompareWithPatchAction.java
+++ /dev/null
@@ -1,44 +0,0 @@
-/*
- * (c) Copyright IBM Corp. 2000, 2001.
- * All Rights Reserved.
- */
-package org.eclipse.compare.patch;
-
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.widgets.Shell;
-
-import org.eclipse.jface.action.IAction;
-import org.eclipse.jface.viewers.ISelection;
-import org.eclipse.jface.wizard.*;
-
-import org.eclipse.ui.IActionDelegate;
-
-import org.eclipse.compare.internal.CompareUIPlugin;
-
-
-public class CompareWithPatchAction implements IActionDelegate {
-
- static class PatchWizardDialog extends WizardDialog {
-
- PatchWizardDialog(Shell parent, IWizard wizard) {
- super(parent, wizard);
-
- setShellStyle(getShellStyle() | SWT.RESIZE);
- setMinimumPageSize(700, 500);
- }
- }
-
- private ISelection fSelection;
-
- public void run(IAction action) {
-
- PatchWizard wizard= new PatchWizard(fSelection);
- PatchWizardDialog wd= new PatchWizardDialog(CompareUIPlugin.getShell(), wizard);
- wd.open();
- }
-
- public void selectionChanged(IAction action, ISelection selection) {
- fSelection= selection;
- action.setEnabled(fSelection != null && !fSelection.isEmpty());
- }
-}

Back to the top