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/patch/CompareWithPatchAction.java (-154 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.swt.SWT;
17
import org.eclipse.swt.events.SelectionAdapter;
18
import org.eclipse.swt.events.SelectionEvent;
19
import org.eclipse.swt.graphics.Image;
20
import org.eclipse.swt.widgets.Button;
21
import org.eclipse.swt.widgets.Composite;
22
import org.eclipse.swt.widgets.Control;
23
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;
37
38
import org.eclipse.compare.internal.*;
39
40
41
public class CompareWithPatchAction extends BaseCompareAction {
42
43
	static class PatchWizardDialog extends WizardDialog {
44
	
45
		PatchWizardDialog(Shell parent, IWizard wizard) {
46
			super(parent, wizard);
47
			
48
			setShellStyle(getShellStyle() | SWT.RESIZE);
49
			setMinimumPageSize(700, 500);
50
		}
51
	}
52
	
53
	protected boolean isEnabled(ISelection selection) {
54
		return Utilities.getResources(selection).length == 1;
55
	}
56
		
57
	/* (non-Javadoc)
58
	 * @see org.eclipse.compare.internal.BaseCompareAction#run(org.eclipse.jface.viewers.ISelection)
59
	 */
60
	protected void run(ISelection selection) {
61
		PatchWizard wizard= new PatchWizard(selection);
62
		
63
		if (areAllEditorsSaved()) {
64
			PatchWizardDialog dialog= new PatchWizardDialog(CompareUIPlugin.getShell(), wizard);
65
			dialog.open();
66
		}
67
	}
68
69
	private boolean areAllEditorsSaved(){
70
		if (CompareUIPlugin.getDirtyEditors().length == 0)
71
			return true;
72
		if (! saveAllDirtyEditors())
73
			return false;
74
		Shell shell= CompareUIPlugin.getShell();
75
		try {
76
			// Save isn't cancelable.
77
			IWorkspace workspace= ResourcesPlugin.getWorkspace();
78
			IWorkspaceDescription description= workspace.getDescription();
79
			boolean autoBuild= description.isAutoBuilding();
80
			description.setAutoBuilding(false);
81
			workspace.setDescription(description);
82
			try {
83
				new ProgressMonitorDialog(shell).run(false, false, createRunnable());
84
			} finally {
85
				description.setAutoBuilding(autoBuild);
86
				workspace.setDescription(description);
87
			}
88
			return true;
89
		} catch (InvocationTargetException e) {
90
			ExceptionHandler.handle(e, shell, PatchMessages.PatchAction_ExceptionTitle, PatchMessages.PatchAction_Exception);  
91
			return false;
92
		} catch (CoreException e) {
93
			ExceptionHandler.handle(e, shell, PatchMessages.PatchAction_ExceptionTitle, PatchMessages.PatchAction_Exception);  
94
			return false;			
95
		} catch (InterruptedException e) {
96
			Assert.isTrue(false); // Can't happen. Operation isn't cancelable.
97
			return false;
98
		}
99
	}
100
101
	private IRunnableWithProgress createRunnable() {
102
		return new IRunnableWithProgress() {
103
			public void run(IProgressMonitor pm) {
104
				IEditorPart[] editorsToSave= CompareUIPlugin.getDirtyEditors();
105
				pm.beginTask(PatchMessages.PatchAction_SavingDirtyEditorsTask, editorsToSave.length); 
106
				for (int i= 0; i < editorsToSave.length; i++) {
107
					editorsToSave[i].doSave(new SubProgressMonitor(pm, 1));
108
					pm.worked(1);
109
				}
110
				pm.done();
111
			}
112
		};
113
	}
114
115
	private boolean saveAllDirtyEditors() {
116
		if (ComparePreferencePage.getSaveAllEditors()) //must save everything
117
			return true;
118
		ListDialog dialog= new ListDialog(CompareUIPlugin.getShell()) {
119
			protected Control createDialogArea(Composite parent) {
120
				Composite result= (Composite) super.createDialogArea(parent);
121
				final Button check= new Button(result, SWT.CHECK);
122
				check.setText(PatchMessages.PatchAction_AlwaysSaveQuestion); 
123
				check.setSelection(ComparePreferencePage.getSaveAllEditors());
124
				check.addSelectionListener(
125
					new SelectionAdapter() {
126
						public void widgetSelected(SelectionEvent e) {
127
							ComparePreferencePage.setSaveAllEditors(check.getSelection());
128
						}
129
					}
130
				);
131
				applyDialogFont(result);
132
				return result;
133
			}
134
		};
135
		dialog.setTitle(PatchMessages.PatchAction_SaveAllQuestion); 
136
		dialog.setAddCancelButton(true);
137
		dialog.setLabelProvider(createDialogLabelProvider());
138
		dialog.setMessage(PatchMessages.PatchAction_SaveAllDescription); 
139
		dialog.setContentProvider(new ListContentProvider());
140
		dialog.setInput(Arrays.asList(CompareUIPlugin.getDirtyEditors()));
141
		return dialog.open() == Window.OK;
142
	}
143
144
	private ILabelProvider createDialogLabelProvider() {
145
		return new LabelProvider() {
146
			public Image getImage(Object element) {
147
				return ((IEditorPart) element).getTitleImage();
148
			}
149
			public String getText(Object element) {
150
				return ((IEditorPart) element).getTitle();
151
			}
152
		};
153
	}
154
}
(-)compare/org/eclipse/compare/internal/patch/InputPatchPage.java (-2 / +6 lines)
Lines 214-219 Link Here
214
		//gd.horizontalIndent= 8;
214
		//gd.horizontalIndent= 8;
215
		gd.widthHint= SIZING_TEXT_FIELD_WIDTH;
215
		gd.widthHint= SIZING_TEXT_FIELD_WIDTH;
216
		fPatchFileNameField.setLayoutData(gd);
216
		fPatchFileNameField.setLayoutData(gd);
217
		fPatchFileNameField.setText(fPatchWizard.getPatchPath());
217
		
218
		
218
		fPatchFileBrowseButton= new Button(fPatchFileGroup, SWT.PUSH);
219
		fPatchFileBrowseButton= new Button(fPatchFileGroup, SWT.PUSH);
219
		fPatchFileBrowseButton.setText(PatchMessages.InputPatchPage_ChooseFileButton_text); 
220
		fPatchFileBrowseButton.setText(PatchMessages.InputPatchPage_ChooseFileButton_text); 
Lines 269-276 Link Here
269
		
270
		
270
		PatchWizard pw= (PatchWizard) getWizard();
271
		PatchWizard pw= (PatchWizard) getWizard();
271
		IResource target= pw.getTarget();
272
		IResource target= pw.getTarget();
272
		IWorkspace workspace= target.getWorkspace();
273
		IWorkspaceRoot root = null;
273
		IWorkspaceRoot root= workspace.getRoot();
274
		if (target != null) {
275
			IWorkspace workspace= target.getWorkspace();
276
			root= workspace.getRoot();
277
		}
274
		
278
		
275
		Tree tree= new Tree(parent, SWT.BORDER);
279
		Tree tree= new Tree(parent, SWT.BORDER);
276
		GridData gd= new GridData(GridData.FILL_BOTH);
280
		GridData gd= new GridData(GridData.FILL_BOTH);
(-)compare/org/eclipse/compare/internal/patch/PatchWizard.java (-3 / +11 lines)
Lines 25-31 Link Here
25
import org.eclipse.compare.internal.*;
25
import org.eclipse.compare.internal.*;
26
26
27
27
28
/* package */ class PatchWizard extends Wizard {
28
/* package */ public class PatchWizard extends Wizard {
29
	
29
	
30
	// dialog store id constants
30
	// dialog store id constants
31
	private final static String DIALOG_SETTINGS_KEY= "PatchWizard"; //$NON-NLS-1$
31
	private final static String DIALOG_SETTINGS_KEY= "PatchWizard"; //$NON-NLS-1$
Lines 36-47 Link Here
36
	
36
	
37
	private Patcher fPatcher;
37
	private Patcher fPatcher;
38
	private IResource fTarget;
38
	private IResource fTarget;
39
39
	private String fPatchPath;
40
		
40
		
41
	/*
41
	/*
42
	 * Creates a wizard for applying a patch file to the workspace.
42
	 * Creates a wizard for applying a patch file to the workspace.
43
	 */
43
	 */
44
	/* package */ PatchWizard(ISelection selection) {
44
	/* package */ public PatchWizard(ISelection selection) {
45
		
45
		
46
		setDefaultPageImageDescriptor(CompareUIPlugin.getImageDescriptor("wizban/applypatch_wizban.gif"));	//$NON-NLS-1$
46
		setDefaultPageImageDescriptor(CompareUIPlugin.getImageDescriptor("wizban/applypatch_wizban.gif"));	//$NON-NLS-1$
47
		setWindowTitle(PatchMessages.PatchWizard_title); 
47
		setWindowTitle(PatchMessages.PatchWizard_title); 
Lines 131-135 Link Here
131
		
131
		
132
		return true;
132
		return true;
133
	}
133
	}
134
135
	public String getPatchPath() {
136
		return fPatchPath;
137
	}
138
139
	public void setPatchPath(String patchPath) {
140
		fPatchPath = patchPath;
141
	}
134
}
142
}
135
143
(-)compare/org/eclipse/compare/CompareWithPatchAction.java (+162 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.swt.SWT;
17
import org.eclipse.swt.events.SelectionAdapter;
18
import org.eclipse.swt.events.SelectionEvent;
19
import org.eclipse.swt.graphics.Image;
20
import org.eclipse.swt.widgets.Button;
21
import org.eclipse.swt.widgets.Composite;
22
import org.eclipse.swt.widgets.Control;
23
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;
37
38
import org.eclipse.compare.internal.*;
39
import org.eclipse.compare.internal.patch.PatchMessages;
40
import org.eclipse.compare.internal.patch.PatchWizard;
41
42
43
public class CompareWithPatchAction extends BaseCompareAction {
44
45
	private String patchPath = ""; //$NON-NLS-1$
46
	
47
	static class PatchWizardDialog extends WizardDialog {
48
	
49
		PatchWizardDialog(Shell parent, IWizard wizard) {
50
			super(parent, wizard);
51
			
52
			setShellStyle(getShellStyle() | SWT.RESIZE);
53
			setMinimumPageSize(700, 500);
54
		}
55
	}
56
	
57
	protected boolean isEnabled(ISelection selection) {
58
		return Utilities.getResources(selection).length == 1;
59
	}
60
		
61
	/* (non-Javadoc)
62
	 * @see org.eclipse.compare.internal.BaseCompareAction#run(org.eclipse.jface.viewers.ISelection)
63
	 */
64
	protected void run(ISelection selection) {
65
		PatchWizard wizard= new PatchWizard(selection);
66
		wizard.setPatchPath(patchPath);
67
		if (areAllEditorsSaved()) {
68
			PatchWizardDialog dialog= new PatchWizardDialog(CompareUIPlugin.getShell(), wizard);
69
			dialog.open();
70
		}
71
	}
72
73
	private boolean areAllEditorsSaved(){
74
		if (CompareUIPlugin.getDirtyEditors().length == 0)
75
			return true;
76
		if (! saveAllDirtyEditors())
77
			return false;
78
		Shell shell= CompareUIPlugin.getShell();
79
		try {
80
			// Save isn't cancelable.
81
			IWorkspace workspace= ResourcesPlugin.getWorkspace();
82
			IWorkspaceDescription description= workspace.getDescription();
83
			boolean autoBuild= description.isAutoBuilding();
84
			description.setAutoBuilding(false);
85
			workspace.setDescription(description);
86
			try {
87
				new ProgressMonitorDialog(shell).run(false, false, createRunnable());
88
			} finally {
89
				description.setAutoBuilding(autoBuild);
90
				workspace.setDescription(description);
91
			}
92
			return true;
93
		} catch (InvocationTargetException e) {
94
			ExceptionHandler.handle(e, shell, PatchMessages.PatchAction_ExceptionTitle, PatchMessages.PatchAction_Exception);  
95
			return false;
96
		} catch (CoreException e) {
97
			ExceptionHandler.handle(e, shell, PatchMessages.PatchAction_ExceptionTitle, PatchMessages.PatchAction_Exception);  
98
			return false;			
99
		} catch (InterruptedException e) {
100
			Assert.isTrue(false); // Can't happen. Operation isn't cancelable.
101
			return false;
102
		}
103
	}
104
105
	private IRunnableWithProgress createRunnable() {
106
		return new IRunnableWithProgress() {
107
			public void run(IProgressMonitor pm) {
108
				IEditorPart[] editorsToSave= CompareUIPlugin.getDirtyEditors();
109
				pm.beginTask(PatchMessages.PatchAction_SavingDirtyEditorsTask, editorsToSave.length); 
110
				for (int i= 0; i < editorsToSave.length; i++) {
111
					editorsToSave[i].doSave(new SubProgressMonitor(pm, 1));
112
					pm.worked(1);
113
				}
114
				pm.done();
115
			}
116
		};
117
	}
118
119
	private boolean saveAllDirtyEditors() {
120
		if (ComparePreferencePage.getSaveAllEditors()) //must save everything
121
			return true;
122
		ListDialog dialog= new ListDialog(CompareUIPlugin.getShell()) {
123
			protected Control createDialogArea(Composite parent) {
124
				Composite result= (Composite) super.createDialogArea(parent);
125
				final Button check= new Button(result, SWT.CHECK);
126
				check.setText(PatchMessages.PatchAction_AlwaysSaveQuestion); 
127
				check.setSelection(ComparePreferencePage.getSaveAllEditors());
128
				check.addSelectionListener(
129
					new SelectionAdapter() {
130
						public void widgetSelected(SelectionEvent e) {
131
							ComparePreferencePage.setSaveAllEditors(check.getSelection());
132
						}
133
					}
134
				);
135
				applyDialogFont(result);
136
				return result;
137
			}
138
		};
139
		dialog.setTitle(PatchMessages.PatchAction_SaveAllQuestion); 
140
		dialog.setAddCancelButton(true);
141
		dialog.setLabelProvider(createDialogLabelProvider());
142
		dialog.setMessage(PatchMessages.PatchAction_SaveAllDescription); 
143
		dialog.setContentProvider(new ListContentProvider());
144
		dialog.setInput(Arrays.asList(CompareUIPlugin.getDirtyEditors()));
145
		return dialog.open() == Window.OK;
146
	}
147
148
	private ILabelProvider createDialogLabelProvider() {
149
		return new LabelProvider() {
150
			public Image getImage(Object element) {
151
				return ((IEditorPart) element).getTitleImage();
152
			}
153
			public String getText(Object element) {
154
				return ((IEditorPart) element).getTitle();
155
			}
156
		};
157
	}
158
159
	public void setPatchPath(String patchPath) {
160
		this.patchPath = patchPath;
161
	}
162
}

Return to bug 98707