View | Details | Raw Unified | Return to bug 110481
Collapse All | Expand All

(-)compare/org/eclipse/compare/internal/patch/Hunk.java (+4 lines)
Lines 165-168 Link Here
165
			return this;
165
			return this;
166
		return null;
166
		return null;
167
	}
167
	}
168
	
169
	protected boolean getHunkProblem() {
170
		return fHunkProblem;
171
	}
168
}
172
}
(-)compare/org/eclipse/compare/internal/patch/PreviewPatchPage.java (+20 lines)
Lines 338-348 Link Here
338
				DiffProject proj = null;
338
				DiffProject proj = null;
339
				if (obj instanceof DiffProject){
339
				if (obj instanceof DiffProject){
340
					proj = (DiffProject) obj;
340
					proj = (DiffProject) obj;
341
					//Check to see if any of the Diffs contained by the DiffProject
342
					//have their diff problems set
343
					Object[] diffs = proj.getChildren(null);
344
					for (int i= 0; i<diffs.length; i++) {
345
					if (((Diff) diffs[i]).containsProblems()){
346
						checked.setChecked(obj, false);
347
							break;
348
						}
349
					}
341
				} else if (obj instanceof Diff){
350
				} else if (obj instanceof Diff){
342
					proj = ((Diff) obj).getProject();
351
					proj = ((Diff) obj).getProject();
352
					//If Diff has any diff problems set, at least one hunk underneath 
353
					//does not match - so don't allow entire tree to be checked
354
					if (((Diff) obj).containsProblems()){
355
						checked.setChecked(obj, false);
356
					}
343
				} else if (obj instanceof Hunk){
357
				} else if (obj instanceof Hunk){
344
					Diff diff = (Diff) ((Hunk) obj).getParent(null);
358
					Diff diff = (Diff) ((Hunk) obj).getParent(null);
345
					proj = diff.getProject();
359
					proj = diff.getProject();
360
					//Check to see if this hunk has any problems OR
361
					//if its parent has any problems
362
					if( diff.getDiffProblem() ||
363
						((Hunk) obj).getHunkProblem()){
364
						checked.setChecked(obj, false);
365
					}
346
				}
366
				}
347
				if (proj!= null &&
367
				if (proj!= null &&
348
				   !proj.getProject().exists()){
368
				   !proj.getProject().exists()){
(-)compare/org/eclipse/compare/internal/patch/PatchTargetPage.java (-3 / +3 lines)
Lines 38-44 Link Here
38
import org.eclipse.ui.PlatformUI;
38
import org.eclipse.ui.PlatformUI;
39
import org.eclipse.ui.model.WorkbenchContentProvider;
39
import org.eclipse.ui.model.WorkbenchContentProvider;
40
import org.eclipse.ui.model.WorkbenchLabelProvider;
40
import org.eclipse.ui.model.WorkbenchLabelProvider;
41
import org.eclipse.ui.model.WorkbenchViewerSorter;
41
import org.eclipse.ui.views.navigator.ResourceSorter;
42
42
43
/***
43
/***
44
 * This page only shows up if the user is trying to apply
44
 * This page only shows up if the user is trying to apply
Lines 141-147 Link Here
141
		fPatchTargets = new CheckboxTreeViewer(tree);
141
		fPatchTargets = new CheckboxTreeViewer(tree);
142
		fPatchTargets.setLabelProvider(new WorkbenchLabelProvider());
142
		fPatchTargets.setLabelProvider(new WorkbenchLabelProvider());
143
		fPatchTargets.setContentProvider(new WorkbenchContentProvider());
143
		fPatchTargets.setContentProvider(new WorkbenchContentProvider());
144
		fPatchTargets.setSorter(new WorkbenchViewerSorter());
144
		fPatchTargets.setSorter(new ResourceSorter(ResourceSorter.NAME));
145
		fPatchTargets.setInput(ResourcesPlugin.getWorkspace().getRoot());
145
		fPatchTargets.setInput(ResourcesPlugin.getWorkspace().getRoot());
146
		
146
		
147
		PatchWizard pw = (PatchWizard) getWizard();
147
		PatchWizard pw = (PatchWizard) getWizard();
Lines 154-160 Link Here
154
		// register listeners
154
		// register listeners
155
		fPatchTargets.addSelectionChangedListener(new ISelectionChangedListener() {
155
		fPatchTargets.addSelectionChangedListener(new ISelectionChangedListener() {
156
			public void selectionChanged(SelectionChangedEvent event) {
156
			public void selectionChanged(SelectionChangedEvent event) {
157
				fPatchWizard.setTarget(Utilities.getResource(event.getSelection()));
157
				fPatchWizard.setTarget(Utilities.getFirstResource(event.getSelection()));
158
				updateWidgetEnablements();
158
				updateWidgetEnablements();
159
			}
159
			}
160
		});
160
		});
(-)compare/org/eclipse/compare/internal/patch/Diff.java (-1 / +25 lines)
Lines 159-165 Link Here
159
			if (hunkFailed)
159
			if (hunkFailed)
160
				this.fMatches= false;
160
				this.fMatches= false;
161
			hunk.reset(hunkFailed);
161
			hunk.reset(hunkFailed);
162
			if (!hunkFailed && projectExistsInWorkspace)
162
			//If the hunk can be applied and the project exists in the workspace and
163
			//there are no problems with the hunk's containing diff, then check the hunk
164
			if (!hunkFailed && projectExistsInWorkspace && !fDiffProblem)
163
				hunksToCheck.add(hunk);
165
				hunksToCheck.add(hunk);
164
		}
166
		}
165
		return hunksToCheck;
167
		return hunksToCheck;
Lines 252-257 Link Here
252
			return this;
254
			return this;
253
		return null;
255
		return null;
254
	}
256
	}
257
	
258
	protected boolean getDiffProblem() {
259
		return fDiffProblem;
260
	}
261
262
	/**
263
	 * Returns whether this Diff has any problems
264
	 * @return true if this Diff or any of its children Hunks have a problem, false if it doesn't
265
	 */
266
	protected boolean containsProblems() {
267
268
		if (fDiffProblem)
269
			return true;
270
271
		for (Iterator iter = fHunks.iterator(); iter.hasNext();) {
272
			Hunk element = (Hunk) iter.next();
273
			if (element.getHunkProblem()) {
274
				return true;
275
			}
276
		}
277
		return false;
278
	}
255
279
256
}
280
}
257
281
(-)compare/org/eclipse/compare/internal/patch/PatchWizard.java (-1 / +1 lines)
Lines 45-51 Link Here
45
		setWindowTitle(PatchMessages.PatchWizard_title);
45
		setWindowTitle(PatchMessages.PatchWizard_title);
46
46
47
		fPatcher= new WorkspacePatcher();
47
		fPatcher= new WorkspacePatcher();
48
		setTarget(Utilities.getResource(selection));
48
		setTarget(Utilities.getFirstResource(selection));
49
49
50
		IDialogSettings workbenchSettings= CompareUIPlugin.getDefault().getDialogSettings();
50
		IDialogSettings workbenchSettings= CompareUIPlugin.getDefault().getDialogSettings();
51
		IDialogSettings section= workbenchSettings.getSection(DIALOG_SETTINGS_KEY);
51
		IDialogSettings section= workbenchSettings.getSection(DIALOG_SETTINGS_KEY);
(-)compare/org/eclipse/compare/internal/patch/CompareWithPatchAction.java (-14 / +34 lines)
Lines 13-18 Link Here
13
import java.lang.reflect.InvocationTargetException;
13
import java.lang.reflect.InvocationTargetException;
14
import java.util.Arrays;
14
import java.util.Arrays;
15
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;
16
import org.eclipse.swt.SWT;
39
import org.eclipse.swt.SWT;
17
import org.eclipse.swt.events.SelectionAdapter;
40
import org.eclipse.swt.events.SelectionAdapter;
18
import org.eclipse.swt.events.SelectionEvent;
41
import org.eclipse.swt.events.SelectionEvent;
Lines 21-53 Link Here
21
import org.eclipse.swt.widgets.Composite;
44
import org.eclipse.swt.widgets.Composite;
22
import org.eclipse.swt.widgets.Control;
45
import org.eclipse.swt.widgets.Control;
23
import org.eclipse.swt.widgets.Shell;
46
import org.eclipse.swt.widgets.Shell;
24
25
import org.eclipse.jface.dialogs.ProgressMonitorDialog;
26
import org.eclipse.jface.operation.IRunnableWithProgress;
27
import org.eclipse.jface.util.Assert;
28
import org.eclipse.jface.viewers.*;
29
import org.eclipse.jface.window.Window;
30
import org.eclipse.jface.wizard.IWizard;
31
import org.eclipse.jface.wizard.WizardDialog;
32
33
import org.eclipse.core.resources.*;
34
import org.eclipse.core.runtime.*;
35
36
import org.eclipse.ui.IEditorPart;
47
import org.eclipse.ui.IEditorPart;
37
48
38
import org.eclipse.compare.internal.*;
39
40
49
41
public class CompareWithPatchAction extends BaseCompareAction {
50
public class CompareWithPatchAction extends BaseCompareAction {
42
51
43
	static class PatchWizardDialog extends WizardDialog {
52
	static class PatchWizardDialog extends WizardDialog {
44
	
53
	
54
		private static final String PATCH_WIZARD_SETTINGS_SECTION = "PatchWizard"; //$NON-NLS-1$
55
45
		PatchWizardDialog(Shell parent, IWizard wizard) {
56
		PatchWizardDialog(Shell parent, IWizard wizard) {
46
			super(parent, wizard);
57
			super(parent, wizard);
47
			
58
			
48
			setShellStyle(getShellStyle() | SWT.RESIZE);
59
			setShellStyle(getShellStyle() | SWT.RESIZE);
49
			setMinimumPageSize(700, 500);
60
			setMinimumPageSize(700, 500);
50
		}
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
		}
51
	}
71
	}
52
	
72
	
53
	protected boolean isEnabled(ISelection selection) {
73
	protected boolean isEnabled(ISelection selection) {
(-)compare/org/eclipse/compare/internal/patch/PatchMessages.properties (-3 / +3 lines)
Lines 29-44 Link Here
29
# InputPatchPage
29
# InputPatchPage
30
#
30
#
31
InputPatchPage_title= Patch Input Specification
31
InputPatchPage_title= Patch Input Specification
32
InputPatchPage_message= Define the resource to patch and the patch to apply
32
InputPatchPage_message= Select the patch location.
33
InputPatchPage_Clipboard=Clipboard
33
InputPatchPage_Clipboard=Clipboard
34
InputPatchPage_SelectInput=Select a single file or folder to patch:
34
InputPatchPage_SelectInput=&Select a single file or folder to patch:
35
InputPatchPage_PatchErrorDialog_title=Patch Error
35
InputPatchPage_PatchErrorDialog_title=Patch Error
36
InputPatchPage_SelectPatch_title=Select Patch
36
InputPatchPage_SelectPatch_title=Select Patch
37
InputPatchPage_FileButton_text=Fil&e
37
InputPatchPage_FileButton_text=Fil&e
38
InputPatchPage_ChooseFileButton_text=&Browse...
38
InputPatchPage_ChooseFileButton_text=&Browse...
39
InputPatchPage_UseClipboardButton_text=&Clipboard
39
InputPatchPage_UseClipboardButton_text=&Clipboard
40
InputPatchPage_UseWorkspaceButton_text=&Workspace
40
InputPatchPage_UseWorkspaceButton_text=&Workspace
41
InputPatchPage_WorkspaceSelectPatch_text=Select the location of the patch
41
InputPatchPage_WorkspaceSelectPatch_text=&Select the location of the patch
42
InputPatchPage_NothingSelected_message=Select a file or folder to be patched
42
InputPatchPage_NothingSelected_message=Select a file or folder to be patched
43
InputPatchPage_ClipboardIsEmpty_message=Clipboard is empty
43
InputPatchPage_ClipboardIsEmpty_message=Clipboard is empty
44
InputPatchPage_NoTextInClipboard_message=Clipboard does not contain text
44
InputPatchPage_NoTextInClipboard_message=Clipboard does not contain text
(-)compare/org/eclipse/compare/internal/patch/InputPatchPage.java (-14 / +224 lines)
Lines 21-26 Link Here
21
21
22
import org.eclipse.compare.internal.ICompareContextIds;
22
import org.eclipse.compare.internal.ICompareContextIds;
23
import org.eclipse.compare.internal.Utilities;
23
import org.eclipse.compare.internal.Utilities;
24
import org.eclipse.core.resources.IFile;
24
import org.eclipse.core.resources.IResource;
25
import org.eclipse.core.resources.IResource;
25
import org.eclipse.core.resources.ResourcesPlugin;
26
import org.eclipse.core.resources.ResourcesPlugin;
26
import org.eclipse.core.runtime.IPath;
27
import org.eclipse.core.runtime.IPath;
Lines 30-35 Link Here
30
import org.eclipse.jface.dialogs.MessageDialog;
31
import org.eclipse.jface.dialogs.MessageDialog;
31
import org.eclipse.jface.viewers.ISelectionChangedListener;
32
import org.eclipse.jface.viewers.ISelectionChangedListener;
32
import org.eclipse.jface.viewers.SelectionChangedEvent;
33
import org.eclipse.jface.viewers.SelectionChangedEvent;
34
import org.eclipse.jface.viewers.StructuredSelection;
33
import org.eclipse.jface.viewers.TreeViewer;
35
import org.eclipse.jface.viewers.TreeViewer;
34
import org.eclipse.jface.wizard.IWizardPage;
36
import org.eclipse.jface.wizard.IWizardPage;
35
import org.eclipse.jface.wizard.WizardPage;
37
import org.eclipse.jface.wizard.WizardPage;
Lines 40-45 Link Here
40
import org.eclipse.swt.events.ModifyListener;
42
import org.eclipse.swt.events.ModifyListener;
41
import org.eclipse.swt.events.SelectionAdapter;
43
import org.eclipse.swt.events.SelectionAdapter;
42
import org.eclipse.swt.events.SelectionEvent;
44
import org.eclipse.swt.events.SelectionEvent;
45
import org.eclipse.swt.events.ShellAdapter;
46
import org.eclipse.swt.events.ShellEvent;
43
import org.eclipse.swt.layout.GridData;
47
import org.eclipse.swt.layout.GridData;
44
import org.eclipse.swt.layout.GridLayout;
48
import org.eclipse.swt.layout.GridLayout;
45
import org.eclipse.swt.widgets.Button;
49
import org.eclipse.swt.widgets.Button;
Lines 48-58 Link Here
48
import org.eclipse.swt.widgets.Control;
52
import org.eclipse.swt.widgets.Control;
49
import org.eclipse.swt.widgets.FileDialog;
53
import org.eclipse.swt.widgets.FileDialog;
50
import org.eclipse.swt.widgets.Label;
54
import org.eclipse.swt.widgets.Label;
55
import org.eclipse.swt.widgets.Shell;
51
import org.eclipse.swt.widgets.Text;
56
import org.eclipse.swt.widgets.Text;
52
import org.eclipse.ui.PlatformUI;
57
import org.eclipse.ui.PlatformUI;
53
import org.eclipse.ui.model.WorkbenchContentProvider;
58
import org.eclipse.ui.model.WorkbenchContentProvider;
54
import org.eclipse.ui.model.WorkbenchLabelProvider;
59
import org.eclipse.ui.model.WorkbenchLabelProvider;
55
import org.eclipse.ui.model.WorkbenchViewerSorter;
60
import org.eclipse.ui.views.navigator.ResourceSorter;
61
62
56
63
57
/* package */ class InputPatchPage extends WizardPage {
64
/* package */ class InputPatchPage extends WizardPage {
58
65
Lines 64-69 Link Here
64
	private final static String PAGE_NAME= "PatchWizardPage1"; //$NON-NLS-1$  
71
	private final static String PAGE_NAME= "PatchWizardPage1"; //$NON-NLS-1$  
65
	private final static String STORE_PATCH_FILES_ID= PAGE_NAME+".PATCH_FILES"; //$NON-NLS-1$
72
	private final static String STORE_PATCH_FILES_ID= PAGE_NAME+".PATCH_FILES"; //$NON-NLS-1$
66
	private final static String STORE_INPUT_METHOD_ID= PAGE_NAME+".INPUT_METHOD"; //$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_WORKSPACE_PATH_ID= PAGE_NAME+".WORKSPACE_PATH"; //$NON-NLS-1$
67
	//patch input constants
75
	//patch input constants
68
	protected final static int CLIPBOARD= 1;
76
	protected final static int CLIPBOARD= 1;
69
	protected final static int FILE= 2;
77
	protected final static int FILE= 2;
Lines 85-96 Link Here
85
93
86
	private PatchWizard fPatchWizard;
94
	private PatchWizard fPatchWizard;
87
95
96
	private ActivationListener fActivationListener = new ActivationListener();
97
	
88
	protected final static String INPUTPATCHPAGE_NAME= "InputPatchPage"; //$NON-NLS-1$
98
	protected final static String INPUTPATCHPAGE_NAME= "InputPatchPage"; //$NON-NLS-1$
89
99
	
100
	class ActivationListener extends ShellAdapter {
101
		public void shellActivated(ShellEvent e) {
102
			//Allow error messages if the selected input actually has something selected in it
103
			fShowError=true;
104
			switch(getInputMethod()){
105
				case FILE:
106
				fShowError = (fPatchFileNameField.getText() != "");  //$NON-NLS-1$
107
				break;
108
			    
109
				case WORKSPACE:
110
				fShowError = (!fTreeViewer.getSelection().isEmpty());
111
				break;
112
				
113
			}
114
			updateWidgetEnablements();
115
		}
116
	}
117
	
118
	
90
	InputPatchPage(PatchWizard pw) {
119
	InputPatchPage(PatchWizard pw) {
91
		super(INPUTPATCHPAGE_NAME, PatchMessages.InputPatchPage_title, null);
120
		super(INPUTPATCHPAGE_NAME, PatchMessages.InputPatchPage_title, null);
92
		fPatchWizard= pw;
121
		fPatchWizard= pw;
93
		setMessage(PatchMessages.InputPatchPage_message); 
122
		setMessage(PatchMessages.InputPatchPage_message);
94
	}
123
	}
95
	
124
	
96
	/*
125
	/*
Lines 115-125 Link Here
115
		setControl(composite);
144
		setControl(composite);
116
145
117
		buildPatchFileGroup(composite);
146
		buildPatchFileGroup(composite);
118
147
		
119
		restoreWidgetValues();
148
		//see if there are any better options presently selected
120
149
		if(!adjustToCurrentTarget()){
150
			//get the persisted values
151
			restoreWidgetValues();
152
		}
153
		
154
		//No error for dialog opening
155
		fShowError=false;
156
		clearErrorMessage();
121
		updateWidgetEnablements();
157
		updateWidgetEnablements();
122
		
158
		
159
		Shell shell= getShell();
160
		shell.addShellListener(fActivationListener);
161
		
123
		Dialog.applyDialogFont(composite);
162
		Dialog.applyDialogFont(composite);
124
		PlatformUI.getWorkbench().getHelpSystem().setHelp(composite, ICompareContextIds.PATCH_INPUT_WIZARD_PAGE);
163
		PlatformUI.getWorkbench().getHelpSystem().setHelp(composite, ICompareContextIds.PATCH_INPUT_WIZARD_PAGE);
125
	}
164
	}
Lines 282-290 Link Here
282
		addWorkspaceControls(parent);
321
		addWorkspaceControls(parent);
283
322
284
		// Add listeners
323
		// Add listeners
285
		fUsePatchFileButton.addSelectionListener(new SelectionAdapter() {
324
		fUseClipboardButton.addSelectionListener(new SelectionAdapter() {
286
			public void widgetSelected(SelectionEvent e) {
325
			public void widgetSelected(SelectionEvent e) {
326
				if (!fUseClipboardButton.getSelection())
327
					return;
328
				
329
				clearErrorMessage();
287
				fShowError= true;
330
				fShowError= true;
331
				updateWidgetEnablements();
332
			}
333
		});
334
		
335
		fUsePatchFileButton.addSelectionListener(new SelectionAdapter() {
336
			public void widgetSelected(SelectionEvent e) {
337
				if (!fUsePatchFileButton.getSelection())
338
					return;
339
				//If there is anything typed in at all
340
				clearErrorMessage();
341
				fShowError = (fPatchFileNameField.getText() != ""); //$NON-NLS-1$
288
				int state= getInputMethod();
342
				int state= getInputMethod();
289
				setEnablePatchFile(state==FILE);
343
				setEnablePatchFile(state==FILE);
290
				setEnableWorkspacePatch(state==WORKSPACE);
344
				setEnableWorkspacePatch(state==WORKSPACE);
Lines 299-317 Link Here
299
		});
353
		});
300
		fPatchFileNameField.addModifyListener(new ModifyListener() {
354
		fPatchFileNameField.addModifyListener(new ModifyListener() {
301
			public void modifyText(ModifyEvent e) {
355
			public void modifyText(ModifyEvent e) {
356
				clearErrorMessage();
302
				fShowError= true;
357
				fShowError= true;
303
				updateWidgetEnablements();
358
				updateWidgetEnablements();
304
			}
359
			}
305
		});
360
		});
306
		fPatchFileBrowseButton.addSelectionListener(new SelectionAdapter() {
361
		fPatchFileBrowseButton.addSelectionListener(new SelectionAdapter() {
307
			public void widgetSelected(SelectionEvent e) {
362
			public void widgetSelected(SelectionEvent e) {
363
				clearErrorMessage();
364
				fShowError= true;
308
				handlePatchFileBrowseButtonPressed();
365
				handlePatchFileBrowseButtonPressed();
309
				updateWidgetEnablements();
366
				updateWidgetEnablements();
310
			}
367
			}
311
		});
368
		});
312
		fUseWorkspaceButton.addSelectionListener(new SelectionAdapter() {
369
		fUseWorkspaceButton.addSelectionListener(new SelectionAdapter() {
313
			public void widgetSelected(SelectionEvent e) {
370
			public void widgetSelected(SelectionEvent e) {
314
				fShowError= true;
371
				if (!fUseWorkspaceButton.getSelection())
372
					return;
373
				clearErrorMessage();
374
				//If there is anything typed in at all
375
				fShowError = (!fTreeViewer.getSelection().isEmpty());
315
				int state= getInputMethod();
376
				int state= getInputMethod();
316
				setEnablePatchFile(state==FILE);
377
				setEnablePatchFile(state==FILE);
317
				setEnableWorkspacePatch(state==WORKSPACE);
378
				setEnableWorkspacePatch(state==WORKSPACE);
Lines 321-326 Link Here
321
382
322
		fTreeViewer.addSelectionChangedListener(new ISelectionChangedListener() {
383
		fTreeViewer.addSelectionChangedListener(new ISelectionChangedListener() {
323
			public void selectionChanged(SelectionChangedEvent event) {
384
			public void selectionChanged(SelectionChangedEvent event) {
385
				clearErrorMessage();
324
				updateWidgetEnablements();
386
				updateWidgetEnablements();
325
			}
387
			}
326
		});
388
		});
Lines 328-336 Link Here
328
390
329
	private void addWorkspaceControls(Composite composite) {
391
	private void addWorkspaceControls(Composite composite) {
330
392
331
		new Label(composite, SWT.LEFT).setText(PatchMessages.InputPatchPage_WorkspaceSelectPatch_text);
393
	
332
394
		Composite newComp = new Composite(composite, SWT.NONE);
333
		fTreeViewer= new TreeViewer(composite, SWT.BORDER);
395
		GridLayout layout= new GridLayout(1, false);
396
		layout.marginWidth = 15;
397
		layout.marginHeight = 0;
398
		layout.marginLeft = 5;
399
		newComp.setLayout(layout);
400
		newComp.setLayoutData(new GridData(GridData.FILL_BOTH));
401
			
402
		new Label(newComp, SWT.LEFT).setText(PatchMessages.InputPatchPage_WorkspaceSelectPatch_text);
403
		
404
		fTreeViewer= new TreeViewer(newComp, SWT.BORDER);
334
		final GridData gd= new GridData(SWT.FILL, SWT.FILL, true, true);
405
		final GridData gd= new GridData(SWT.FILL, SWT.FILL, true, true);
335
		gd.widthHint= 0;
406
		gd.widthHint= 0;
336
		gd.heightHint= 0;
407
		gd.heightHint= 0;
Lines 338-347 Link Here
338
409
339
		fTreeViewer.setLabelProvider(new WorkbenchLabelProvider());
410
		fTreeViewer.setLabelProvider(new WorkbenchLabelProvider());
340
		fTreeViewer.setContentProvider(new WorkbenchContentProvider());
411
		fTreeViewer.setContentProvider(new WorkbenchContentProvider());
341
		fTreeViewer.setSorter(new WorkbenchViewerSorter());
412
		fTreeViewer.setSorter(new ResourceSorter(ResourceSorter.NAME));
342
		fTreeViewer.setInput(ResourcesPlugin.getWorkspace().getRoot());
413
		fTreeViewer.setInput(ResourcesPlugin.getWorkspace().getRoot());
343
	}
414
	}
344
415
416
345
	/**
417
	/**
346
	 * Updates the enable state of this page's controls.
418
	 * Updates the enable state of this page's controls.
347
	 */
419
	 */
Lines 495-501 Link Here
495
	 */
567
	 */
496
	private void restoreWidgetValues() {
568
	private void restoreWidgetValues() {
497
569
498
		int inputMethod= CLIPBOARD;
570
		int inputMethod= FILE;
499
571
500
		IDialogSettings settings= getDialogSettings();
572
		IDialogSettings settings= getDialogSettings();
501
		if (settings != null) {
573
		if (settings != null) {
Lines 517-522 Link Here
517
			String patchFilePath= settings.get(STORE_PATCH_FILES_ID);
589
			String patchFilePath= settings.get(STORE_PATCH_FILES_ID);
518
			if (patchFilePath != null)
590
			if (patchFilePath != null)
519
				setSourceName(patchFilePath);
591
				setSourceName(patchFilePath);
592
			
593
			//If the previous apply patch was used with a clipboard, we need to check
594
			//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
596
			//will be selected automatically
597
			if (inputMethod == CLIPBOARD){
598
				inputMethod=FILE;
599
				fPatchFileNameField.deselectAll();
600
			}
601
			
602
			//set the workspace patch selection
603
			String workspaceSetting = settings.get(STORE_WORKSPACE_PATH_ID);
604
			if (workspaceSetting != null && !workspaceSetting.equals("")){ //$NON-NLS-1$
605
				//See if this resource still exists in the workspace
606
				IPath path = new Path(workspaceSetting);
607
				IFile targetFile = ResourcesPlugin.getWorkspace().getRoot().getFile(path);
608
				if (fTreeViewer != null && targetFile.exists()){
609
					fTreeViewer.expandToLevel(targetFile, 0);
610
					fTreeViewer.setSelection(new StructuredSelection(targetFile));
611
				} 
612
			} else {
613
				//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 
615
				//the tree viewer
616
				if (inputMethod == WORKSPACE)
617
					inputMethod=FILE;
618
			}
520
		}
619
		}
521
620
522
		// set radio buttons state
621
		// set radio buttons state
Lines 541-564 Link Here
541
	
640
	
542
			sourceNames= addToHistory(sourceNames, getPatchFilePath());
641
			sourceNames= addToHistory(sourceNames, getPatchFilePath());
543
			settings.put(STORE_PATCH_FILES_ID, sourceNames);
642
			settings.put(STORE_PATCH_FILES_ID, sourceNames);
643
			
644
			//save the workspace selection
645
			settings.put(STORE_WORKSPACE_PATH_ID, getWorkspacePath());
646
			
544
		}
647
		}
545
	}
648
	}
546
	
649
	
650
	private String getWorkspacePath() {
651
		if (fTreeViewer != null){
652
			IResource[] resources= Utilities.getResources(fTreeViewer.getSelection());
653
			if (resources.length > 0){
654
				IResource patchFile= resources[0];
655
				return patchFile.getFullPath().toString();
656
			}
657
			
658
		}
659
		return ""; //$NON-NLS-1$
660
	}
661
547
	// static helpers
662
	// static helpers
663
	
664
	/**
665
	 * Checks to see if the file that has been selected for Apply Patch
666
	 * is actually a patch
667
	 * @return true if the file selected to run Apply Patch on in the workspace is a patch file
668
	 * or if the clipboard contains a patch
669
	 */
670
	private boolean adjustToCurrentTarget() {
671
		//Readjust selection if there is a patch selected in the workspace or on the clipboard
672
		//Check workspace first
673
		IResource patchTarget = fPatchWizard.getTarget();
674
		if (patchTarget instanceof IFile) {
675
			Reader reader = null;
676
			try {
677
				try {
678
					reader = new FileReader(patchTarget.getRawLocation().toFile());
679
				} catch (FileNotFoundException ex) {/*silently ignored*/
680
				} catch (NullPointerException nex) {/*silently ignored*/
681
				}
548
682
683
				if (isPatchFile(reader)) {
684
					//Set choice to workspace
685
					setInputButtonState(WORKSPACE);
686
					if (fTreeViewer != null && patchTarget.exists()) {
687
						fTreeViewer.expandToLevel(patchTarget, 0);
688
						fTreeViewer.setSelection(new StructuredSelection(patchTarget));
689
					}
690
					return true;
691
				}
692
			} finally {
693
				if (reader != null) {
694
					try {
695
						reader.close();
696
					} catch (IOException x) {/*silently ignored*/
697
					}
698
				}
699
			}
700
		} else {
701
			//check out clipboard contents
702
			Reader reader = null;
703
			Control c = getControl();
704
			if (c != null) {
705
				Clipboard clipboard = new Clipboard(c.getDisplay());
706
				Object o = clipboard.getContents(TextTransfer.getInstance());
707
				clipboard.dispose();
708
				try {
709
					if (o instanceof String) {
710
						reader = new StringReader((String) o);
711
						if (isPatchFile(reader)) {
712
							setInputButtonState(CLIPBOARD);
713
							return true;
714
						}
715
					}
716
				} finally {
717
					if (reader != null) {
718
						try {
719
							reader.close();
720
						} catch (IOException x) {/*silently ignored*/
721
						}
722
					}
723
				}
724
			}
725
		}
726
		return false;
727
	} 
728
	
729
	
730
731
	private boolean isPatchFile(Reader reader){
732
		  WorkspacePatcher patcher= ((PatchWizard) getWizard()).getPatcher();
733
			
734
			try {
735
				patcher.parse(new BufferedReader(reader));
736
			} catch (IOException ex) {return false;}
737
			
738
			Diff[] diffs= patcher.getDiffs();
739
			if (diffs == null || diffs.length == 0) {
740
				return false;
741
			}
742
			
743
		return true;
744
	}
745
	
746
	/*
747
	 * Clears the dialog message box
748
	 */
749
	private void  clearErrorMessage(){
750
		setErrorMessage(null);
751
	}
752
	
549
	private void setInputButtonState(int state) {
753
	private void setInputButtonState(int state) {
550
754
551
		switch (state) {
755
		switch (state) {
552
			case CLIPBOARD :
756
			case CLIPBOARD :
553
				fUseClipboardButton.setSelection(true);
757
				fUseClipboardButton.setSelection(true);
758
				fUsePatchFileButton.setSelection(false);
759
				fUseWorkspaceButton.setSelection(false);
554
				break;
760
				break;
555
761
556
			case FILE :
762
			case FILE :
763
				fUseClipboardButton.setSelection(false);
557
				fUsePatchFileButton.setSelection(true);
764
				fUsePatchFileButton.setSelection(true);
765
				fUseWorkspaceButton.setSelection(false);
558
				break;
766
				break;
559
767
560
			case WORKSPACE :
768
			case WORKSPACE :
561
				fUsePatchFileButton.setSelection(true);
769
				fUseClipboardButton.setSelection(false);
770
				fUsePatchFileButton.setSelection(false);
771
				fUseWorkspaceButton.setSelection(true);
562
				break;
772
				break;
563
		}
773
		}
564
774
(-)compare/org/eclipse/compare/internal/Utilities.java (-1 / +1 lines)
Lines 594-600 Link Here
594
		}
594
		}
595
	}
595
	}
596
596
597
	public static IResource getResource(ISelection selection) {
597
	public static IResource getFirstResource(ISelection selection) {
598
		IResource[] resources = getResources(selection);
598
		IResource[] resources = getResources(selection);
599
		if (resources.length > 0)
599
		if (resources.length > 0)
600
			return resources[0];
600
			return resources[0];
(-)compare/org/eclipse/compare/CompareUI.java (-36 lines)
Lines 14-22 Link Here
14
14
15
import org.eclipse.compare.internal.CompareUIPlugin;
15
import org.eclipse.compare.internal.CompareUIPlugin;
16
import org.eclipse.compare.internal.DocumentManager;
16
import org.eclipse.compare.internal.DocumentManager;
17
import org.eclipse.compare.internal.patch.WorkspacePatcher;
18
import org.eclipse.compare.structuremergeviewer.ICompareInput;
17
import org.eclipse.compare.structuremergeviewer.ICompareInput;
19
import org.eclipse.core.resources.IProject;
20
import org.eclipse.core.runtime.IAdaptable;
18
import org.eclipse.core.runtime.IAdaptable;
21
import org.eclipse.core.runtime.content.IContentType;
19
import org.eclipse.core.runtime.content.IContentType;
22
import org.eclipse.jface.resource.ImageDescriptor;
20
import org.eclipse.jface.resource.ImageDescriptor;
Lines 358-396 Link Here
358
		DocumentManager.remove(document);
356
		DocumentManager.remove(document);
359
	}
357
	}
360
	
358
	
361
	/**
362
	 * Returns a string that must be the first line of a workspace patch (a multi-project patch 
363
	 * that is understood by the Apply Patch wizard). Each project to be included in the patch
364
	 * must be prefixed by the line obtained from the <code>getWorkspacePatchProjectHeader()</code>.
365
	 * This snippet outlines how the a workspace patch is to be created:
366
	 * <pre>
367
	 *  //Write out workspace patch header
368
	 *  stream.println(CompareUI.getWorkspacePatchHeader());
369
	 *  for (int i=0; i<projects.length; i++){
370
	 *    //Write out project header
371
	 *    stream.println(CompareUI.getWorkspacePatchProjectHeader(projects[i]);
372
	 *    //Write out patches in Unified Diff format
373
	 *  }
374
	 *  </pre>
375
	 * @return String
376
	 * @see CompareUI#getWorkspacePatchProjectHeader(IProject)
377
	 * @since 3.2
378
	 */
379
	public static String getWorkspacePatchHeader() {
380
		return WorkspacePatcher.MULTIPROJECTPATCH_HEADER+" "+WorkspacePatcher.MULTIPROJECTPATCH_VERSION; //$NON-NLS-1$
381
	}
382
383
	/**
384
	 * Returns the project header that must appear before any patches that apply to that
385
	 * project. All patches that are encountered after this header and before the next header
386
	 * are understood to belong the the project.
387
	 * @param project project to be patched
388
	 * @return String
389
	 * @see CompareUI#getWorkspacePatchHeader()
390
	 * @since 3.2
391
	 */
392
	public static String getWorkspacePatchProjectHeader(IProject project) {
393
		return WorkspacePatcher.MULTIPROJECTPATCH_PROJECT+" "+ project.getName(); //$NON-NLS-1$
394
	}
395
}
359
}
396
360
(-)compare/org/eclipse/compare/patch/WorkspacePatcherUI.java (+41 lines)
Added Link Here
1
package org.eclipse.compare.patch;
2
3
import org.eclipse.compare.internal.patch.WorkspacePatcher;
4
import org.eclipse.core.resources.IProject;
5
6
public class WorkspacePatcherUI {
7
	/**
8
	 * Returns a string that must be the first line of a workspace patch (a multi-project patch 
9
	 * that is understood by the Apply Patch wizard). Each project to be included in the patch
10
	 * must be prefixed by the line obtained from the <code>getWorkspacePatchProjectHeader()</code>.
11
	 * This snippet outlines how the a workspace patch is to be created:
12
	 * <pre>
13
	 *  //Write out workspace patch header
14
	 *  stream.println(CompareUI.getWorkspacePatchHeader());
15
	 *  for (int i=0; i<projects.length; i++){
16
	 *    //Write out project header
17
	 *    stream.println(CompareUI.getWorkspacePatchProjectHeader(projects[i]);
18
	 *    //Write out patches in Unified Diff format
19
	 *  }
20
	 *  </pre>
21
	 * @return String
22
	 * @see WorkspacePatcherUI#getWorkspacePatchProjectHeader(IProject)
23
	 * @since 3.2
24
	 */
25
	public static String getWorkspacePatchHeader() {
26
		return WorkspacePatcher.MULTIPROJECTPATCH_HEADER+" "+WorkspacePatcher.MULTIPROJECTPATCH_VERSION; //$NON-NLS-1$
27
	}
28
29
	/**
30
	 * Returns the project header that must appear before any patches that apply to that
31
	 * project. All patches that are encountered after this header and before the next header
32
	 * are understood to belong the the project.
33
	 * @param project project to be patched
34
	 * @return String
35
	 * @see WorkspacePatcherUI#getWorkspacePatchHeader()
36
	 * @since 3.2
37
	 */
38
	public static String getWorkspacePatchProjectHeader(IProject project) {
39
		return WorkspacePatcher.MULTIPROJECTPATCH_PROJECT+" "+ project.getName(); //$NON-NLS-1$
40
	}
41
}

Return to bug 110481