Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
View | Details | Raw Unified | Return to bug 98707 | Differences between
and this patch

Collapse All | Expand All

(-)plugin.xml (-1 / +1 lines)
Lines 195-201 Link Here
195
         <action
195
         <action
196
               label="%CompareWithPatchAction.label"
196
               label="%CompareWithPatchAction.label"
197
               tooltip="%CompareWithPatchAction.tooltip"
197
               tooltip="%CompareWithPatchAction.tooltip"
198
               class="org.eclipse.compare.internal.patch.CompareWithPatchAction"
198
               class="org.eclipse.compare.CompareWithPatchAction"
199
               menubarPath="team.main/group1"
199
               menubarPath="team.main/group1"
200
               enablesFor="1"
200
               enablesFor="1"
201
               id="compareWithPatch">
201
               id="compareWithPatch">
(-)compare/org/eclipse/compare/internal/CompareEditor.java (-56 / +1 lines)
Lines 17-23 Link Here
17
17
18
import org.eclipse.jface.dialogs.ErrorDialog;
18
import org.eclipse.jface.dialogs.ErrorDialog;
19
import org.eclipse.jface.dialogs.MessageDialog;
19
import org.eclipse.jface.dialogs.MessageDialog;
20
import org.eclipse.jface.resource.ImageDescriptor;
21
import org.eclipse.jface.util.*;
20
import org.eclipse.jface.util.*;
22
import org.eclipse.jface.util.Assert;
21
import org.eclipse.jface.util.Assert;
23
22
Lines 36-42 Link Here
36
 * A CompareEditor takes a ICompareEditorInput as input.
35
 * A CompareEditor takes a ICompareEditorInput as input.
37
 * Most functionality is delegated to the ICompareEditorInput.
36
 * Most functionality is delegated to the ICompareEditorInput.
38
 */
37
 */
39
public class CompareEditor extends EditorPart implements IReusableEditor, ISaveableModelSource, ISaveableModel {
38
public class CompareEditor extends EditorPart implements IReusableEditor {
40
	
39
	
41
	/**
40
	/**
42
	 * Internal property change listener for handling changes in the editor's input.
41
	 * Internal property change listener for handling changes in the editor's input.
Lines 258-272 Link Here
258
	 */
257
	 */
259
	public boolean isDirty() {
258
	public boolean isDirty() {
260
		IEditorInput input= getEditorInput();
259
		IEditorInput input= getEditorInput();
261
		if (input instanceof ISaveableModelSource) {
262
			ISaveableModelSource sms = (ISaveableModelSource) input;
263
			ISaveableModel[] models = sms.getModels();
264
			for (int i = 0; i < models.length; i++) {
265
				ISaveableModel model = models[i];
266
				if (model.isDirty())
267
					return true;
268
			}
269
		}
270
		if (input instanceof CompareEditorInput)
260
		if (input instanceof CompareEditorInput)
271
			return ((CompareEditorInput)input).isSaveNeeded();
261
			return ((CompareEditorInput)input).isSaveNeeded();
272
		return false;
262
		return false;
Lines 278-327 Link Here
278
		if (old_value == null || new_value == null || !old_value.equals(new_value))
268
		if (old_value == null || new_value == null || !old_value.equals(new_value))
279
			firePropertyChange(PROP_DIRTY);
269
			firePropertyChange(PROP_DIRTY);
280
	}
270
	}
281
282
	/* (non-Javadoc)
283
	 * @see org.eclipse.ui.ISaveableModelSource#getModels()
284
	 */
285
	public ISaveableModel[] getModels() {
286
		IEditorInput input= getEditorInput();
287
		if (input instanceof ISaveableModelSource) {
288
			ISaveableModelSource source = (ISaveableModelSource) input;
289
			return source.getModels();
290
		}
291
		return new ISaveableModel[] { this };
292
	}
293
294
	/* (non-Javadoc)
295
	 * @see org.eclipse.ui.ISaveableModelSource#getActiveModels()
296
	 */
297
	public ISaveableModel[] getActiveModels() {
298
		IEditorInput input= getEditorInput();
299
		if (input instanceof ISaveableModelSource) {
300
			ISaveableModelSource source = (ISaveableModelSource) input;
301
			return source.getActiveModels();
302
		}
303
		return new ISaveableModel[] { this };
304
	}
305
306
	/* (non-Javadoc)
307
	 * @see org.eclipse.ui.ISaveableModel#getName()
308
	 */
309
	public String getName() {
310
		return getPartName();
311
	}
312
313
	/* (non-Javadoc)
314
	 * @see org.eclipse.ui.ISaveableModel#getToolTipText()
315
	 */
316
	public String getToolTipText() {
317
		return getTitleToolTip();
318
	}
319
320
	/* (non-Javadoc)
321
	 * @see org.eclipse.ui.ISaveableModel#getImageDescriptor()
322
	 */
323
	public ImageDescriptor getImageDescriptor() {
324
		return ImageDescriptor.createFromImage(getTitleImage());
325
	}
326
}
271
}
327
272
(-)compare/org/eclipse/compare/internal/patch/PatchTargetPage.java (-3 / +4 lines)
Lines 12-17 Link Here
12
12
13
import java.text.MessageFormat;
13
import java.text.MessageFormat;
14
14
15
import org.eclipse.compare.PatchReader;
15
import org.eclipse.compare.internal.ICompareContextIds;
16
import org.eclipse.compare.internal.ICompareContextIds;
16
import org.eclipse.compare.internal.Utilities;
17
import org.eclipse.compare.internal.Utilities;
17
import org.eclipse.core.resources.IFile;
18
import org.eclipse.core.resources.IFile;
Lines 101-115 Link Here
101
			InputPatchPage inputPage = (InputPatchPage) fPatchWizard.getPage(InputPatchPage.INPUTPATCHPAGE_NAME);
102
			InputPatchPage inputPage = (InputPatchPage) fPatchWizard.getPage(InputPatchPage.INPUTPATCHPAGE_NAME);
102
			String source = ""; //$NON-NLS-1$
103
			String source = ""; //$NON-NLS-1$
103
			switch (inputPage.getInputMethod()) {
104
			switch (inputPage.getInputMethod()) {
104
				case InputPatchPage.CLIPBOARD :
105
				case PatchReader.CLIPBOARD :
105
					source = PatchMessages.InputPatchPage_Clipboard_title;
106
					source = PatchMessages.InputPatchPage_Clipboard_title;
106
					break;
107
					break;
107
108
108
				case InputPatchPage.FILE :
109
				case PatchReader.FILE :
109
					source = PatchMessages.InputPatchPage_PatchFile_title;
110
					source = PatchMessages.InputPatchPage_PatchFile_title;
110
					break;
111
					break;
111
112
112
				case InputPatchPage.WORKSPACE :
113
				case PatchReader.WORKSPACE :
113
					source = PatchMessages.InputPatchPage_WorkspacePatch_title;
114
					source = PatchMessages.InputPatchPage_WorkspacePatch_title;
114
					break;
115
					break;
115
			}
116
			}
(-)compare/org/eclipse/compare/internal/patch/PatchWizard.java (-17 / +75 lines)
Lines 10-17 Link Here
10
 *******************************************************************************/
10
 *******************************************************************************/
11
package org.eclipse.compare.internal.patch;
11
package org.eclipse.compare.internal.patch;
12
12
13
import java.io.IOException;
13
import java.lang.reflect.InvocationTargetException;
14
import java.lang.reflect.InvocationTargetException;
14
15
16
import org.eclipse.compare.PatchReader;
15
import org.eclipse.compare.internal.CompareUIPlugin;
17
import org.eclipse.compare.internal.CompareUIPlugin;
16
import org.eclipse.compare.internal.ExceptionHandler;
18
import org.eclipse.compare.internal.ExceptionHandler;
17
import org.eclipse.compare.internal.Utilities;
19
import org.eclipse.compare.internal.Utilities;
Lines 23-36 Link Here
23
import org.eclipse.jface.dialogs.IDialogSettings;
25
import org.eclipse.jface.dialogs.IDialogSettings;
24
import org.eclipse.jface.viewers.ISelection;
26
import org.eclipse.jface.viewers.ISelection;
25
import org.eclipse.jface.wizard.Wizard;
27
import org.eclipse.jface.wizard.Wizard;
28
import org.eclipse.swt.dnd.Clipboard;
29
import org.eclipse.swt.widgets.Display;
26
import org.eclipse.ui.actions.WorkspaceModifyOperation;
30
import org.eclipse.ui.actions.WorkspaceModifyOperation;
27
31
28
/* package */class PatchWizard extends Wizard {
32
/* package */public class PatchWizard extends Wizard {
29
33
30
	// dialog store id constants
34
	// dialog store id constants
31
	private final static String DIALOG_SETTINGS_KEY= "PatchWizard"; //$NON-NLS-1$
35
	public final static String DIALOG_SETTINGS_KEY= "PatchWizard"; //$NON-NLS-1$
32
36
33
	private boolean fHasNewDialogSettings;
37
	private boolean fHasNewDialogSettings;
38
	private int fPatchSource;
39
	private String fPatchFilePath;
34
	
40
	
35
	private InputPatchPage fPatchWizardPage;
41
	private InputPatchPage fPatchWizardPage;
36
42
Lines 39-62 Link Here
39
	/*
45
	/*
40
	 * Creates a wizard for applying a patch file to the workspace.
46
	 * Creates a wizard for applying a patch file to the workspace.
41
	 */
47
	 */
42
	/* package */PatchWizard(ISelection selection) {
48
	/* package */public PatchWizard(ISelection selection) {
43
49
		init(selection, PatchReader.UNKNOWN);
50
	}
51
	
52
	/*
53
	 * Creates a wizard for applying a patch file to the workspace with the option of skipping the
54
	 * patch input step.
55
	 */
56
	public PatchWizard(ISelection selection, int patchSource) {
57
		init(selection, patchSource);
58
	}
59
	
60
	private void init(ISelection selection, int patchSource) {
44
		setDefaultPageImageDescriptor(CompareUIPlugin.getImageDescriptor("wizban/applypatch_wizban.gif")); //$NON-NLS-1$
61
		setDefaultPageImageDescriptor(CompareUIPlugin.getImageDescriptor("wizban/applypatch_wizban.gif")); //$NON-NLS-1$
45
		setWindowTitle(PatchMessages.PatchWizard_title);
62
		setWindowTitle(PatchMessages.PatchWizard_title);
46
63
64
		fPatchSource = patchSource;
65
		
47
		fPatcher= new WorkspacePatcher();
66
		fPatcher= new WorkspacePatcher();
48
		setTarget(Utilities.getFirstResource(selection));
67
		setTarget(Utilities.getFirstResource(selection));
49
68
		
50
		IDialogSettings workbenchSettings= CompareUIPlugin.getDefault().getDialogSettings();
69
		if (patchSource == PatchReader.UNKNOWN) {
51
		IDialogSettings section= workbenchSettings.getSection(DIALOG_SETTINGS_KEY);
70
			IDialogSettings workbenchSettings= CompareUIPlugin.getDefault().getDialogSettings();
52
		if (section==null)
71
			IDialogSettings section= workbenchSettings.getSection(DIALOG_SETTINGS_KEY);
53
			fHasNewDialogSettings= true;
72
			if (section==null)
54
		else {
73
				fHasNewDialogSettings= true;
55
			fHasNewDialogSettings= false;
74
			else {
56
			setDialogSettings(section);
75
				fHasNewDialogSettings= false;
76
				setDialogSettings(section);
77
			}
57
		}
78
		}
58
	}
79
	}
59
80
	
60
	WorkspacePatcher getPatcher() {
81
	WorkspacePatcher getPatcher() {
61
		return fPatcher;
82
		return fPatcher;
62
	}
83
	}
Lines 74-81 Link Here
74
	 */
95
	 */
75
	public void addPages() {
96
	public void addPages() {
76
		super.addPages();
97
		super.addPages();
77
		
98
		fPatchWizardPage = new InputPatchPage(this);
78
		addPage(fPatchWizardPage= new InputPatchPage(this));
99
100
		try {
101
			switch (fPatchSource) {
102
			case PatchReader.UNKNOWN:
103
				addPage(fPatchWizardPage);
104
				break;
105
	
106
			case PatchReader.CLIPBOARD:
107
				Display display = this.getShell().getDisplay();
108
				if (display != null) {
109
					Clipboard clipboard = new Clipboard(display);
110
					PatchReader.readPatchFromClipboard(clipboard, fPatcher);
111
					clipboard.dispose();
112
				}
113
				break;
114
				
115
			case PatchReader.FILE:
116
				PatchReader.readPatchFromFile(fPatchFilePath, fPatcher);
117
				break;
118
				
119
			case PatchReader.WORKSPACE:
120
				PatchReader.readPatchFromFile(fPatchFilePath, fPatcher);
121
				break;
122
			}
123
		}
124
		catch (IOException e) {
125
			/* If we encounter an error reading a patch, add the input patch page */
126
			addPage(fPatchWizardPage);
127
		}
79
		addPage(new PatchTargetPage(this));
128
		addPage(new PatchTargetPage(this));
80
		addPage(new PreviewPatchPage(this));
129
		addPage(new PreviewPatchPage(this));
81
	}
130
	}
Lines 92-98 Link Here
92
	 */
141
	 */
93
	public boolean performFinish() {
142
	public boolean performFinish() {
94
		
143
		
95
		fPatcher.setName(fPatchWizardPage.getPatchName());
144
		if (fPatchSource == PatchReader.UNKNOWN) {
145
			fPatcher.setName(fPatchWizardPage.getPatchName());
146
		}
96
147
97
		try {
148
		try {
98
			//Create scheduling rule based on the type of patch - single or workspace
149
			//Create scheduling rule based on the type of patch - single or workspace
Lines 133-142 Link Here
133
			setDialogSettings(section);
184
			setDialogSettings(section);
134
		}
185
		}
135
		
186
		
136
		fPatchWizardPage.saveWidgetValues();
187
		if (fPatchSource == PatchReader.UNKNOWN) {
188
			fPatchWizardPage.saveWidgetValues();
189
		}
190
		
137
		//fPreviewPatchPage.saveWidgetValues();
191
		//fPreviewPatchPage.saveWidgetValues();
138
		
192
		
139
		return true;
193
		return true;
140
	}
194
	}
195
196
	public void setPatchFilePath(String filePath) {
197
		fPatchFilePath = filePath;
198
	}
141
}
199
}
142
200
(-)compare/org/eclipse/compare/internal/patch/CompareWithPatchAction.java (-174 lines)
Removed Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2004 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.compare.internal.patch;
12
13
import java.lang.reflect.InvocationTargetException;
14
import java.util.Arrays;
15
16
import org.eclipse.compare.internal.BaseCompareAction;
17
import org.eclipse.compare.internal.ComparePreferencePage;
18
import org.eclipse.compare.internal.CompareUIPlugin;
19
import org.eclipse.compare.internal.ExceptionHandler;
20
import org.eclipse.compare.internal.ListContentProvider;
21
import org.eclipse.compare.internal.ListDialog;
22
import org.eclipse.compare.internal.Utilities;
23
import org.eclipse.core.resources.IWorkspace;
24
import org.eclipse.core.resources.IWorkspaceDescription;
25
import org.eclipse.core.resources.ResourcesPlugin;
26
import org.eclipse.core.runtime.CoreException;
27
import org.eclipse.core.runtime.IProgressMonitor;
28
import org.eclipse.core.runtime.SubProgressMonitor;
29
import org.eclipse.jface.dialogs.IDialogSettings;
30
import org.eclipse.jface.dialogs.ProgressMonitorDialog;
31
import org.eclipse.jface.operation.IRunnableWithProgress;
32
import org.eclipse.jface.util.Assert;
33
import org.eclipse.jface.viewers.ILabelProvider;
34
import org.eclipse.jface.viewers.ISelection;
35
import org.eclipse.jface.viewers.LabelProvider;
36
import org.eclipse.jface.window.Window;
37
import org.eclipse.jface.wizard.IWizard;
38
import org.eclipse.jface.wizard.WizardDialog;
39
import org.eclipse.swt.SWT;
40
import org.eclipse.swt.events.SelectionAdapter;
41
import org.eclipse.swt.events.SelectionEvent;
42
import org.eclipse.swt.graphics.Image;
43
import org.eclipse.swt.widgets.Button;
44
import org.eclipse.swt.widgets.Composite;
45
import org.eclipse.swt.widgets.Control;
46
import org.eclipse.swt.widgets.Shell;
47
import org.eclipse.ui.IEditorPart;
48
49
50
public class CompareWithPatchAction extends BaseCompareAction {
51
52
	static class PatchWizardDialog extends WizardDialog {
53
	
54
		private static final String PATCH_WIZARD_SETTINGS_SECTION = "PatchWizard"; //$NON-NLS-1$
55
56
		PatchWizardDialog(Shell parent, IWizard wizard) {
57
			super(parent, wizard);
58
			
59
			setShellStyle(getShellStyle() | SWT.RESIZE);
60
			setMinimumPageSize(700, 500);
61
		}
62
		
63
		protected IDialogSettings getDialogBoundsSettings() {
64
	        IDialogSettings settings = CompareUIPlugin.getDefault().getDialogSettings();
65
	        IDialogSettings section = settings.getSection(PATCH_WIZARD_SETTINGS_SECTION);
66
	        if (section == null) {
67
	            section = settings.addNewSection(PATCH_WIZARD_SETTINGS_SECTION);
68
	        } 
69
	        return section;
70
		}
71
	}
72
	
73
	protected boolean isEnabled(ISelection selection) {
74
		return Utilities.getResources(selection).length == 1;
75
	}
76
		
77
	/* (non-Javadoc)
78
	 * @see org.eclipse.compare.internal.BaseCompareAction#run(org.eclipse.jface.viewers.ISelection)
79
	 */
80
	protected void run(ISelection selection) {
81
		PatchWizard wizard= new PatchWizard(selection);
82
		
83
		if (areAllEditorsSaved()) {
84
			PatchWizardDialog dialog= new PatchWizardDialog(CompareUIPlugin.getShell(), wizard);
85
			dialog.open();
86
		}
87
	}
88
89
	private boolean areAllEditorsSaved(){
90
		if (CompareUIPlugin.getDirtyEditors().length == 0)
91
			return true;
92
		if (! saveAllDirtyEditors())
93
			return false;
94
		Shell shell= CompareUIPlugin.getShell();
95
		try {
96
			// Save isn't cancelable.
97
			IWorkspace workspace= ResourcesPlugin.getWorkspace();
98
			IWorkspaceDescription description= workspace.getDescription();
99
			boolean autoBuild= description.isAutoBuilding();
100
			description.setAutoBuilding(false);
101
			workspace.setDescription(description);
102
			try {
103
				new ProgressMonitorDialog(shell).run(false, false, createRunnable());
104
			} finally {
105
				description.setAutoBuilding(autoBuild);
106
				workspace.setDescription(description);
107
			}
108
			return true;
109
		} catch (InvocationTargetException e) {
110
			ExceptionHandler.handle(e, shell, PatchMessages.PatchAction_ExceptionTitle, PatchMessages.PatchAction_Exception);  
111
			return false;
112
		} catch (CoreException e) {
113
			ExceptionHandler.handle(e, shell, PatchMessages.PatchAction_ExceptionTitle, PatchMessages.PatchAction_Exception);  
114
			return false;			
115
		} catch (InterruptedException e) {
116
			Assert.isTrue(false); // Can't happen. Operation isn't cancelable.
117
			return false;
118
		}
119
	}
120
121
	private IRunnableWithProgress createRunnable() {
122
		return new IRunnableWithProgress() {
123
			public void run(IProgressMonitor pm) {
124
				IEditorPart[] editorsToSave= CompareUIPlugin.getDirtyEditors();
125
				pm.beginTask(PatchMessages.PatchAction_SavingDirtyEditorsTask, editorsToSave.length); 
126
				for (int i= 0; i < editorsToSave.length; i++) {
127
					editorsToSave[i].doSave(new SubProgressMonitor(pm, 1));
128
					pm.worked(1);
129
				}
130
				pm.done();
131
			}
132
		};
133
	}
134
135
	private boolean saveAllDirtyEditors() {
136
		if (ComparePreferencePage.getSaveAllEditors()) //must save everything
137
			return true;
138
		ListDialog dialog= new ListDialog(CompareUIPlugin.getShell()) {
139
			protected Control createDialogArea(Composite parent) {
140
				Composite result= (Composite) super.createDialogArea(parent);
141
				final Button check= new Button(result, SWT.CHECK);
142
				check.setText(PatchMessages.PatchAction_AlwaysSaveQuestion); 
143
				check.setSelection(ComparePreferencePage.getSaveAllEditors());
144
				check.addSelectionListener(
145
					new SelectionAdapter() {
146
						public void widgetSelected(SelectionEvent e) {
147
							ComparePreferencePage.setSaveAllEditors(check.getSelection());
148
						}
149
					}
150
				);
151
				applyDialogFont(result);
152
				return result;
153
			}
154
		};
155
		dialog.setTitle(PatchMessages.PatchAction_SaveAllQuestion); 
156
		dialog.setAddCancelButton(true);
157
		dialog.setLabelProvider(createDialogLabelProvider());
158
		dialog.setMessage(PatchMessages.PatchAction_SaveAllDescription); 
159
		dialog.setContentProvider(new ListContentProvider());
160
		dialog.setInput(Arrays.asList(CompareUIPlugin.getDirtyEditors()));
161
		return dialog.open() == Window.OK;
162
	}
163
164
	private ILabelProvider createDialogLabelProvider() {
165
		return new LabelProvider() {
166
			public Image getImage(Object element) {
167
				return ((IEditorPart) element).getTitleImage();
168
			}
169
			public String getText(Object element) {
170
				return ((IEditorPart) element).getTitle();
171
			}
172
		};
173
	}
174
}
(-)compare/org/eclipse/compare/internal/patch/InputPatchPage.java (-60 / +37 lines)
Lines 19-24 Link Here
19
import java.io.StringReader;
19
import java.io.StringReader;
20
import java.text.MessageFormat;
20
import java.text.MessageFormat;
21
21
22
import org.eclipse.compare.PatchReader;
22
import org.eclipse.compare.internal.ICompareContextIds;
23
import org.eclipse.compare.internal.ICompareContextIds;
23
import org.eclipse.compare.internal.Utilities;
24
import org.eclipse.compare.internal.Utilities;
24
import org.eclipse.core.resources.IFile;
25
import org.eclipse.core.resources.IFile;
Lines 72-82 Link Here
72
	private final static String STORE_PATCH_FILES_ID= PAGE_NAME+".PATCH_FILES"; //$NON-NLS-1$
73
	private final static String STORE_PATCH_FILES_ID= PAGE_NAME+".PATCH_FILES"; //$NON-NLS-1$
73
	private final static String STORE_INPUT_METHOD_ID= PAGE_NAME+".INPUT_METHOD"; //$NON-NLS-1$
74
	private final static String STORE_INPUT_METHOD_ID= PAGE_NAME+".INPUT_METHOD"; //$NON-NLS-1$
74
	private final static String STORE_WORKSPACE_PATH_ID= PAGE_NAME+".WORKSPACE_PATH"; //$NON-NLS-1$
75
	private final static String STORE_WORKSPACE_PATH_ID= PAGE_NAME+".WORKSPACE_PATH"; //$NON-NLS-1$
75
	//patch input constants
76
	
76
	protected final static int CLIPBOARD= 1;
77
	protected final static int FILE= 2;
78
	protected final static int WORKSPACE= 3;
79
80
	static final char SEPARATOR= System.getProperty("file.separator").charAt(0); //$NON-NLS-1$
77
	static final char SEPARATOR= System.getProperty("file.separator").charAt(0); //$NON-NLS-1$
81
78
82
	private boolean fShowError= false;
79
	private boolean fShowError= false;
Lines 102-112 Link Here
102
			//Allow error messages if the selected input actually has something selected in it
99
			//Allow error messages if the selected input actually has something selected in it
103
			fShowError=true;
100
			fShowError=true;
104
			switch(getInputMethod()){
101
			switch(getInputMethod()){
105
				case FILE:
102
				case PatchReader.FILE:
106
				fShowError = (fPatchFileNameField.getText() != "");  //$NON-NLS-1$
103
				fShowError = (fPatchFileNameField.getText() != "");  //$NON-NLS-1$
107
				break;
104
				break;
108
			    
105
			    
109
				case WORKSPACE:
106
				case PatchReader.WORKSPACE:
110
				fShowError = (!fTreeViewer.getSelection().isEmpty());
107
				fShowError = (!fTreeViewer.getSelection().isEmpty());
111
				break;
108
				break;
112
				
109
				
Lines 131-137 Link Here
131
	}
128
	}
132
129
133
	/* package */ String getPatchName() {
130
	/* package */ String getPatchName() {
134
		if (getInputMethod()==CLIPBOARD)
131
		if (getInputMethod()==PatchReader.CLIPBOARD)
135
			return PatchMessages.InputPatchPage_Clipboard;
132
			return PatchMessages.InputPatchPage_Clipboard;
136
		return getPatchFilePath();
133
		return getPatchFilePath();
137
	}
134
	}
Lines 176-200 Link Here
176
173
177
		String source= ""; //$NON-NLS-1$
174
		String source= ""; //$NON-NLS-1$
178
175
179
		// Create a reader for the input
180
		Reader reader= null;
181
		try {
176
		try {
182
			int inputMethod= getInputMethod();
177
			int inputMethod= getInputMethod();
183
			if (inputMethod==CLIPBOARD) {
178
			if (inputMethod==PatchReader.CLIPBOARD) {
184
				Control c= getControl();
179
				Control c= getControl();
185
				if (c != null) {
180
				if (c != null) {
186
					Clipboard clipboard= new Clipboard(c.getDisplay());
181
					Clipboard clipboard= new Clipboard(c.getDisplay());
187
					Object o= clipboard.getContents(TextTransfer.getInstance());
182
					PatchReader.readPatchFromClipboard(clipboard, patcher);
188
					clipboard.dispose();
189
					if (o instanceof String)
190
						reader= new StringReader((String)o);
191
				}
183
				}
192
				source= PatchMessages.InputPatchPage_Clipboard_title;
184
				source= PatchMessages.InputPatchPage_Clipboard_title;
193
			} else if (inputMethod==FILE) {
185
			} else if (inputMethod==PatchReader.FILE) {
194
				String patchFilePath= getPatchFilePath();
186
				String patchFilePath= getPatchFilePath();
195
				if (patchFilePath != null) {
187
				if (patchFilePath != null) {
196
					try {
188
					try {
197
						reader= new FileReader(patchFilePath);
189
						PatchReader.readPatchFromFile(patchFilePath, patcher);
198
					} catch (FileNotFoundException ex) {
190
					} catch (FileNotFoundException ex) {
199
						MessageDialog.openError(null,
191
						MessageDialog.openError(null,
200
							PatchMessages.InputPatchPage_PatchErrorDialog_title,	
192
							PatchMessages.InputPatchPage_PatchErrorDialog_title,	
Lines 202-214 Link Here
202
					}
194
					}
203
				}
195
				}
204
				source= PatchMessages.InputPatchPage_PatchFile_title;
196
				source= PatchMessages.InputPatchPage_PatchFile_title;
205
			} else if (inputMethod==WORKSPACE) {
197
			} else if (inputMethod==PatchReader.WORKSPACE) {
206
				//Get the selected patch file (tree will only allow for one selection)
198
				//Get the selected patch file (tree will only allow for one selection)
207
				IResource[] resources= Utilities.getResources(fTreeViewer.getSelection());
199
				IResource[] resources= Utilities.getResources(fTreeViewer.getSelection());
208
				IResource patchFile= resources[0];
200
				IResource patchFile= resources[0];
209
				if (patchFile!=null) {
201
				if (patchFile!=null) {
210
					try {
202
					try {
211
						reader= new FileReader(patchFile.getRawLocation().toFile());
203
						PatchReader.readPatchFromFile(patchFile.getRawLocation(), patcher);
212
					} catch (FileNotFoundException ex) {
204
					} catch (FileNotFoundException ex) {
213
						MessageDialog.openError(null, PatchMessages.InputPatchPage_PatchErrorDialog_title, PatchMessages.InputPatchPage_PatchFileNotFound_message);
205
						MessageDialog.openError(null, PatchMessages.InputPatchPage_PatchErrorDialog_title, PatchMessages.InputPatchPage_PatchFileNotFound_message);
214
					} catch (NullPointerException nex) {
206
					} catch (NullPointerException nex) {
Lines 218-242 Link Here
218
				}
210
				}
219
				source= PatchMessages.InputPatchPage_WorkspacePatch_title;
211
				source= PatchMessages.InputPatchPage_WorkspacePatch_title;
220
			}
212
			}
221
			
213
		} catch (IOException e) {
222
			// parse the input
214
			MessageDialog.openError(null,
223
			if (reader != null) {
215
					PatchMessages.InputPatchPage_PatchErrorDialog_title, 
224
				try {
216
					PatchMessages.InputPatchPage_ParseError_message); 
225
					patcher.parse(new BufferedReader(reader));
226
				} catch (IOException ex) {
227
					MessageDialog.openError(null,
228
						PatchMessages.InputPatchPage_PatchErrorDialog_title, 
229
						PatchMessages.InputPatchPage_ParseError_message); 
230
				}
231
			}
232
		} finally {
233
			if (reader != null) {
234
				try {
235
					reader.close();
236
				} catch (IOException x) {
237
					// silently ignored
238
				}
239
			}
240
		}
217
		}
241
		
218
		
242
		Diff[] diffs= patcher.getDiffs();
219
		Diff[] diffs= patcher.getDiffs();
Lines 340-347 Link Here
340
				clearErrorMessage();
317
				clearErrorMessage();
341
				fShowError = (fPatchFileNameField.getText() != ""); //$NON-NLS-1$
318
				fShowError = (fPatchFileNameField.getText() != ""); //$NON-NLS-1$
342
				int state= getInputMethod();
319
				int state= getInputMethod();
343
				setEnablePatchFile(state==FILE);
320
				setEnablePatchFile(state==PatchReader.FILE);
344
				setEnableWorkspacePatch(state==WORKSPACE);
321
				setEnableWorkspacePatch(state==PatchReader.WORKSPACE);
345
				updateWidgetEnablements();
322
				updateWidgetEnablements();
346
			}
323
			}
347
		});
324
		});
Lines 374-381 Link Here
374
				//If there is anything typed in at all
351
				//If there is anything typed in at all
375
				fShowError = (!fTreeViewer.getSelection().isEmpty());
352
				fShowError = (!fTreeViewer.getSelection().isEmpty());
376
				int state= getInputMethod();
353
				int state= getInputMethod();
377
				setEnablePatchFile(state==FILE);
354
				setEnablePatchFile(state==PatchReader.FILE);
378
				setEnableWorkspacePatch(state==WORKSPACE);
355
				setEnableWorkspacePatch(state==PatchReader.WORKSPACE);
379
				updateWidgetEnablements();
356
				updateWidgetEnablements();
380
			}
357
			}
381
		});
358
		});
Lines 423-429 Link Here
423
400
424
		boolean gotPatch= false;
401
		boolean gotPatch= false;
425
		int inputMethod= getInputMethod();
402
		int inputMethod= getInputMethod();
426
		if (inputMethod==CLIPBOARD) {
403
		if (inputMethod==PatchReader.CLIPBOARD) {
427
			Control c= getControl();
404
			Control c= getControl();
428
			if (c != null) {
405
			if (c != null) {
429
				Clipboard clipboard= new Clipboard(c.getDisplay());
406
				Clipboard clipboard= new Clipboard(c.getDisplay());
Lines 439-445 Link Here
439
					error= PatchMessages.InputPatchPage_NoTextInClipboard_message;					 
416
					error= PatchMessages.InputPatchPage_NoTextInClipboard_message;					 
440
			} else
417
			} else
441
				error= PatchMessages.InputPatchPage_CouldNotReadClipboard_message;
418
				error= PatchMessages.InputPatchPage_CouldNotReadClipboard_message;
442
		} else if (inputMethod==FILE) {
419
		} else if (inputMethod==PatchReader.FILE) {
443
			String path= fPatchFileNameField.getText();
420
			String path= fPatchFileNameField.getText();
444
			if (path != null && path.length() > 0) {
421
			if (path != null && path.length() > 0) {
445
				File file= new File(path);
422
				File file= new File(path);
Lines 449-455 Link Here
449
			} else {
426
			} else {
450
				error= PatchMessages.InputPatchPage_NoFileName_message; 
427
				error= PatchMessages.InputPatchPage_NoFileName_message; 
451
			}
428
			}
452
		} else if (inputMethod==WORKSPACE) {
429
		} else if (inputMethod==PatchReader.WORKSPACE) {
453
			//Get the selected patch file (tree will only allow for one selection)
430
			//Get the selected patch file (tree will only allow for one selection)
454
			IResource[] resources= Utilities.getResources(fTreeViewer.getSelection());
431
			IResource[] resources= Utilities.getResources(fTreeViewer.getSelection());
455
			if (resources!=null&&resources.length>0) {
432
			if (resources!=null&&resources.length>0) {
Lines 567-573 Link Here
567
	 */
544
	 */
568
	private void restoreWidgetValues() {
545
	private void restoreWidgetValues() {
569
546
570
		int inputMethod= FILE;
547
		int inputMethod= PatchReader.FILE;
571
548
572
		IDialogSettings settings= getDialogSettings();
549
		IDialogSettings settings= getDialogSettings();
573
		if (settings != null) {
550
		if (settings != null) {
Lines 594-601 Link Here
594
			//if there is a valid patch on the clipboard. This will be done in adjustToCurrentTarget()
571
			//if there is a valid patch on the clipboard. This will be done in adjustToCurrentTarget()
595
			//so just set it to FILE now and, if there exists a patch on the clipboard, then clipboard
572
			//so just set it to FILE now and, if there exists a patch on the clipboard, then clipboard
596
			//will be selected automatically
573
			//will be selected automatically
597
			if (inputMethod == CLIPBOARD){
574
			if (inputMethod == PatchReader.CLIPBOARD){
598
				inputMethod=FILE;
575
				inputMethod=PatchReader.FILE;
599
				fPatchFileNameField.deselectAll();
576
				fPatchFileNameField.deselectAll();
600
			}
577
			}
601
			
578
			
Lines 613-620 Link Here
613
				//check to see if the current input is set to workspace - if it is switch it
590
				//check to see if the current input is set to workspace - if it is switch it
614
				//back to clipboard since there is no corresponding element to go along with 
591
				//back to clipboard since there is no corresponding element to go along with 
615
				//the tree viewer
592
				//the tree viewer
616
				if (inputMethod == WORKSPACE)
593
				if (inputMethod == PatchReader.WORKSPACE)
617
					inputMethod=FILE;
594
					inputMethod=PatchReader.FILE;
618
			}
595
			}
619
		}
596
		}
620
597
Lines 682-688 Link Here
682
659
683
				if (isPatchFile(reader)) {
660
				if (isPatchFile(reader)) {
684
					//Set choice to workspace
661
					//Set choice to workspace
685
					setInputButtonState(WORKSPACE);
662
					setInputButtonState(PatchReader.WORKSPACE);
686
					if (fTreeViewer != null && patchTarget.exists()) {
663
					if (fTreeViewer != null && patchTarget.exists()) {
687
						fTreeViewer.expandToLevel(patchTarget, 0);
664
						fTreeViewer.expandToLevel(patchTarget, 0);
688
						fTreeViewer.setSelection(new StructuredSelection(patchTarget));
665
						fTreeViewer.setSelection(new StructuredSelection(patchTarget));
Lines 709-715 Link Here
709
					if (o instanceof String) {
686
					if (o instanceof String) {
710
						reader = new StringReader((String) o);
687
						reader = new StringReader((String) o);
711
						if (isPatchFile(reader)) {
688
						if (isPatchFile(reader)) {
712
							setInputButtonState(CLIPBOARD);
689
							setInputButtonState(PatchReader.CLIPBOARD);
713
							return true;
690
							return true;
714
						}
691
						}
715
					}
692
					}
Lines 753-788 Link Here
753
	private void setInputButtonState(int state) {
730
	private void setInputButtonState(int state) {
754
731
755
		switch (state) {
732
		switch (state) {
756
			case CLIPBOARD :
733
			case PatchReader.CLIPBOARD :
757
				fUseClipboardButton.setSelection(true);
734
				fUseClipboardButton.setSelection(true);
758
				fUsePatchFileButton.setSelection(false);
735
				fUsePatchFileButton.setSelection(false);
759
				fUseWorkspaceButton.setSelection(false);
736
				fUseWorkspaceButton.setSelection(false);
760
				break;
737
				break;
761
738
762
			case FILE :
739
			case PatchReader.FILE :
763
				fUseClipboardButton.setSelection(false);
740
				fUseClipboardButton.setSelection(false);
764
				fUsePatchFileButton.setSelection(true);
741
				fUsePatchFileButton.setSelection(true);
765
				fUseWorkspaceButton.setSelection(false);
742
				fUseWorkspaceButton.setSelection(false);
766
				break;
743
				break;
767
744
768
			case WORKSPACE :
745
			case PatchReader.WORKSPACE :
769
				fUseClipboardButton.setSelection(false);
746
				fUseClipboardButton.setSelection(false);
770
				fUsePatchFileButton.setSelection(false);
747
				fUsePatchFileButton.setSelection(false);
771
				fUseWorkspaceButton.setSelection(true);
748
				fUseWorkspaceButton.setSelection(true);
772
				break;
749
				break;
773
		}
750
		}
774
751
775
		setEnablePatchFile(state==FILE);
752
		setEnablePatchFile(state==PatchReader.FILE);
776
		setEnableWorkspacePatch(state==WORKSPACE);
753
		setEnableWorkspacePatch(state==PatchReader.WORKSPACE);
777
	}
754
	}
778
755
779
	protected int getInputMethod() {
756
	protected int getInputMethod() {
780
		if (fUseClipboardButton.getSelection())
757
		if (fUseClipboardButton.getSelection())
781
			return CLIPBOARD;
758
			return PatchReader.CLIPBOARD;
782
		else if (fUsePatchFileButton.getSelection())
759
		else if (fUsePatchFileButton.getSelection())
783
			return FILE;
760
			return PatchReader.FILE;
784
		else
761
		else
785
			return WORKSPACE;
762
			return PatchReader.WORKSPACE;
786
	}
763
	}
787
764
788
	private String getPatchFilePath() {
765
	private String getPatchFilePath() {
(-)compare/org/eclipse/compare/PatchReader.java (+109 lines)
Added Link Here
1
package org.eclipse.compare;
2
3
import java.io.BufferedReader;
4
import java.io.FileNotFoundException;
5
import java.io.FileReader;
6
import java.io.IOException;
7
import java.io.Reader;
8
import java.io.StringReader;
9
10
import org.eclipse.compare.internal.patch.WorkspacePatcher;
11
import org.eclipse.core.runtime.IPath;
12
import org.eclipse.swt.dnd.Clipboard;
13
import org.eclipse.swt.dnd.TextTransfer;
14
15
16
public class PatchReader {
17
18
	//patch input constants
19
	public final static int UNKNOWN = -1;
20
	public final static int CLIPBOARD = 1;
21
	public final static int FILE = 2;
22
	public final static int WORKSPACE = 3;	
23
	
24
	/**
25
	 * Populate the given patcher by reading a patch from the clipboard.
26
	 * 
27
	 * @param clipboard
28
	 * @param patcher
29
	 * @throws IOException 
30
	 */
31
	public static void readPatchFromClipboard(Clipboard clipboard, WorkspacePatcher patcher) 
32
	throws IOException { 
33
		
34
		Reader reader = null;
35
		try {		
36
			if (clipboard != null) {
37
				Object o= clipboard.getContents(TextTransfer.getInstance());
38
				clipboard.dispose();
39
				if (o instanceof String)
40
					reader= new StringReader((String)o);
41
			}
42
			
43
			// parse the input
44
			if (reader != null) {
45
				patcher.parse(new BufferedReader(reader));
46
			}
47
		} 
48
		finally {
49
			if (reader != null) {
50
				reader.close();
51
			}
52
		}
53
	}
54
	
55
	/**
56
	 * Populate the given patcher by reading a patch from the file path.
57
	 * 
58
	 * @param filePath
59
	 * @param patcher
60
	 * @throws IOException 
61
	 * @throws FileNotFoundException 
62
	 */
63
64
	public static void readPatchFromFile(String filePath, WorkspacePatcher patcher) 
65
	throws IOException, FileNotFoundException {
66
		Reader reader = null;
67
		try {
68
			reader = new FileReader(filePath);
69
			
70
			// parse the input
71
			if (reader != null) {
72
				patcher.parse(new BufferedReader(reader));
73
			}
74
		}
75
		finally {
76
			if (reader != null) {
77
				reader.close();
78
			}
79
		}
80
	}
81
82
	/**
83
	 * Populate the given patcher by reading a patch from the IPath.
84
	 * 
85
	 * @param path
86
	 * @param patcher
87
	 * @throws IOException 
88
	 * @throws FileNotFoundException 
89
	 * @throws NullPointerException 
90
	 */
91
	public static void readPatchFromFile(IPath path, WorkspacePatcher patcher) 
92
	throws IOException, FileNotFoundException, NullPointerException {
93
94
		Reader reader = null;
95
		try {
96
			reader = new FileReader(path.toFile());
97
			
98
			// parse the input
99
			if (reader != null) {
100
				patcher.parse(new BufferedReader(reader));
101
			}
102
		}
103
		finally {
104
			if (reader != null) {
105
				reader.close();
106
			}
107
		}
108
	}
109
}
(-)compare/org/eclipse/compare/CompareWithPatchAction.java (+199 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2004 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.compare;
12
13
import java.lang.reflect.InvocationTargetException;
14
import java.util.Arrays;
15
16
import org.eclipse.compare.internal.BaseCompareAction;
17
import org.eclipse.compare.internal.ComparePreferencePage;
18
import org.eclipse.compare.internal.CompareUIPlugin;
19
import org.eclipse.compare.internal.ExceptionHandler;
20
import org.eclipse.compare.internal.ListContentProvider;
21
import org.eclipse.compare.internal.ListDialog;
22
import org.eclipse.compare.internal.Utilities;
23
import org.eclipse.compare.internal.patch.PatchMessages;
24
import org.eclipse.compare.internal.patch.PatchWizard;
25
import org.eclipse.core.resources.IWorkspace;
26
import org.eclipse.core.resources.IWorkspaceDescription;
27
import org.eclipse.core.resources.ResourcesPlugin;
28
import org.eclipse.core.runtime.CoreException;
29
import org.eclipse.core.runtime.IProgressMonitor;
30
import org.eclipse.core.runtime.SubProgressMonitor;
31
import org.eclipse.jface.dialogs.IDialogSettings;
32
import org.eclipse.jface.dialogs.ProgressMonitorDialog;
33
import org.eclipse.jface.operation.IRunnableWithProgress;
34
import org.eclipse.jface.util.Assert;
35
import org.eclipse.jface.viewers.ILabelProvider;
36
import org.eclipse.jface.viewers.ISelection;
37
import org.eclipse.jface.viewers.LabelProvider;
38
import org.eclipse.jface.window.Window;
39
import org.eclipse.jface.wizard.IWizard;
40
import org.eclipse.jface.wizard.WizardDialog;
41
import org.eclipse.swt.SWT;
42
import org.eclipse.swt.events.SelectionAdapter;
43
import org.eclipse.swt.events.SelectionEvent;
44
import org.eclipse.swt.graphics.Image;
45
import org.eclipse.swt.widgets.Button;
46
import org.eclipse.swt.widgets.Composite;
47
import org.eclipse.swt.widgets.Control;
48
import org.eclipse.swt.widgets.Shell;
49
import org.eclipse.ui.IEditorPart;
50
51
52
public class CompareWithPatchAction extends BaseCompareAction {
53
54
	private int patchSource = PatchReader.UNKNOWN;
55
	private String filePath;
56
	
57
	static class PatchWizardDialog extends WizardDialog {
58
	
59
		private static final String PATCH_WIZARD_SETTINGS_SECTION = "PatchWizard"; //$NON-NLS-1$
60
61
		PatchWizardDialog(Shell parent, IWizard wizard) {
62
			super(parent, wizard);
63
			
64
			setShellStyle(getShellStyle() | SWT.RESIZE);
65
			setMinimumPageSize(700, 500);
66
		}
67
		
68
		protected IDialogSettings getDialogBoundsSettings() {
69
	        IDialogSettings settings = CompareUIPlugin.getDefault().getDialogSettings();
70
	        IDialogSettings section = settings.getSection(PATCH_WIZARD_SETTINGS_SECTION);
71
	        if (section == null) {
72
	            section = settings.addNewSection(PATCH_WIZARD_SETTINGS_SECTION);
73
	        } 
74
	        return section;
75
		}
76
	}
77
	
78
	protected boolean isEnabled(ISelection selection) {
79
		return Utilities.getResources(selection).length == 1;
80
	}
81
		
82
	/* (non-Javadoc)
83
	 * @see org.eclipse.compare.internal.BaseCompareAction#run(org.eclipse.jface.viewers.ISelection)
84
	 */
85
	protected void run(ISelection selection) {
86
		PatchWizard wizard = null;
87
		wizard= new PatchWizard(selection, patchSource);
88
		wizard.setPatchFilePath(filePath);
89
		
90
		if (areAllEditorsSaved()) {
91
			PatchWizardDialog dialog= new PatchWizardDialog(CompareUIPlugin.getShell(), wizard);
92
			dialog.open();
93
		}
94
	}
95
96
	private boolean areAllEditorsSaved(){
97
		if (CompareUIPlugin.getDirtyEditors().length == 0)
98
			return true;
99
		if (! saveAllDirtyEditors())
100
			return false;
101
		Shell shell= CompareUIPlugin.getShell();
102
		try {
103
			// Save isn't cancelable.
104
			IWorkspace workspace= ResourcesPlugin.getWorkspace();
105
			IWorkspaceDescription description= workspace.getDescription();
106
			boolean autoBuild= description.isAutoBuilding();
107
			description.setAutoBuilding(false);
108
			workspace.setDescription(description);
109
			try {
110
				new ProgressMonitorDialog(shell).run(false, false, createRunnable());
111
			} finally {
112
				description.setAutoBuilding(autoBuild);
113
				workspace.setDescription(description);
114
			}
115
			return true;
116
		} catch (InvocationTargetException e) {
117
			ExceptionHandler.handle(e, shell, PatchMessages.PatchAction_ExceptionTitle, PatchMessages.PatchAction_Exception);  
118
			return false;
119
		} catch (CoreException e) {
120
			ExceptionHandler.handle(e, shell, PatchMessages.PatchAction_ExceptionTitle, PatchMessages.PatchAction_Exception);  
121
			return false;			
122
		} catch (InterruptedException e) {
123
			Assert.isTrue(false); // Can't happen. Operation isn't cancelable.
124
			return false;
125
		}
126
	}
127
128
	private IRunnableWithProgress createRunnable() {
129
		return new IRunnableWithProgress() {
130
			public void run(IProgressMonitor pm) {
131
				IEditorPart[] editorsToSave= CompareUIPlugin.getDirtyEditors();
132
				pm.beginTask(PatchMessages.PatchAction_SavingDirtyEditorsTask, editorsToSave.length); 
133
				for (int i= 0; i < editorsToSave.length; i++) {
134
					editorsToSave[i].doSave(new SubProgressMonitor(pm, 1));
135
					pm.worked(1);
136
				}
137
				pm.done();
138
			}
139
		};
140
	}
141
142
	private boolean saveAllDirtyEditors() {
143
		if (ComparePreferencePage.getSaveAllEditors()) //must save everything
144
			return true;
145
		ListDialog dialog= new ListDialog(CompareUIPlugin.getShell()) {
146
			protected Control createDialogArea(Composite parent) {
147
				Composite result= (Composite) super.createDialogArea(parent);
148
				final Button check= new Button(result, SWT.CHECK);
149
				check.setText(PatchMessages.PatchAction_AlwaysSaveQuestion); 
150
				check.setSelection(ComparePreferencePage.getSaveAllEditors());
151
				check.addSelectionListener(
152
					new SelectionAdapter() {
153
						public void widgetSelected(SelectionEvent e) {
154
							ComparePreferencePage.setSaveAllEditors(check.getSelection());
155
						}
156
					}
157
				);
158
				applyDialogFont(result);
159
				return result;
160
			}
161
		};
162
		dialog.setTitle(PatchMessages.PatchAction_SaveAllQuestion); 
163
		dialog.setAddCancelButton(true);
164
		dialog.setLabelProvider(createDialogLabelProvider());
165
		dialog.setMessage(PatchMessages.PatchAction_SaveAllDescription); 
166
		dialog.setContentProvider(new ListContentProvider());
167
		dialog.setInput(Arrays.asList(CompareUIPlugin.getDirtyEditors()));
168
		return dialog.open() == Window.OK;
169
	}
170
171
	private ILabelProvider createDialogLabelProvider() {
172
		return new LabelProvider() {
173
			public Image getImage(Object element) {
174
				return ((IEditorPart) element).getTitleImage();
175
			}
176
			public String getText(Object element) {
177
				return ((IEditorPart) element).getTitle();
178
			}
179
		};
180
	}
181
	
182
	/**
183
	 * Set the patch dialog settings to be used in the apply patch dialog.
184
     *
185
	 * @param source
186
	 */
187
	public void setPatchSource(int source) {
188
		this.patchSource = source;
189
	}
190
	
191
	/**
192
	 * Set the file path to the patch.
193
	 * 
194
	 * @param filePath
195
	 */
196
	public void setPatchFilePath(String filePath) {
197
		this.filePath = filePath;
198
	}
199
}

Return to bug 98707