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 326393
Collapse All | Expand All

(-)src/org/eclipse/compare/internal/win32/WordMergeViewer.java (-4 / +19 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2008 IBM Corporation and others.
2
 * Copyright (c) 2008, 2010 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 305-312 Link Here
305
		try {
305
		try {
306
			if (isOneSided()) {
306
			if (isOneSided()) {
307
				File file = getFileForSingleSide();
307
				File file = getFileForSingleSide();
308
				if (file != null)
308
				if (file != null) {
309
					wordArea.openDocument(file.getAbsolutePath(), inplace);
309
					try {
310
						wordArea.openDocument(file.getAbsolutePath(), inplace);
311
					} catch (SWTException e) {
312
						throw new CoreException(new Status(IStatus.ERROR,
313
								Activator.PLUGIN_ID, NLS.bind(
314
										CompareWin32Messages.WordComparison_16,
315
										file.getAbsolutePath()), e));
316
					}
317
				}
310
			} else {
318
			} else {
311
				File left = getFileForLeft();
319
				File left = getFileForLeft();
312
				File right = getFileForRight();
320
				File right = getFileForRight();
Lines 327-333 Link Here
327
							resultFileTimestamp = result.lastModified();
335
							resultFileTimestamp = result.lastModified();
328
							description.setText(getTextDescription());
336
							description.setText(getTextDescription());
329
						}
337
						}
330
						wordArea.openDocument(result.getAbsolutePath(), inplace);
338
						try {
339
							wordArea.openDocument(result.getAbsolutePath(), inplace);
340
						} catch (SWTException e) {
341
							throw new CoreException(new Status(IStatus.ERROR,
342
									Activator.PLUGIN_ID, NLS.bind(
343
											CompareWin32Messages.WordComparison_16,
344
											result.getAbsolutePath()), e));
345
						}
331
					}
346
					}
332
				}
347
				}
333
			}
348
			}
(-)src/org/eclipse/compare/internal/win32/WordComparison.java (-7 / +45 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2008 IBM Corporation and others.
2
 * Copyright (c) 2008, 2010 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 48-53 Link Here
48
		return auto.invoke(property(auto, command), new Variant[0]);
48
		return auto.invoke(property(auto, command), new Variant[0]);
49
	}
49
	}
50
50
51
	private static Variant invoke(OleAutomation auto, OleAutomation reference, String command) {
52
		return auto.invoke(property(auto, reference, command), new Variant[0]);
53
	}
54
55
	private static Variant invoke(OleAutomation auto, OleAutomation reference, String command, String value) {
56
		return auto.invoke(property(auto, reference, command), new Variant[] { new Variant(value) });
57
	}
58
51
	private static Variant invoke(OleAutomation auto, String command, int value) {
59
	private static Variant invoke(OleAutomation auto, String command, int value) {
52
		return auto.invoke(property(auto, command), new Variant[] { new Variant(value) });
60
		return auto.invoke(property(auto, command), new Variant[] { new Variant(value) });
53
	}
61
	}
Lines 104-109 Link Here
104
		throw new SWTException(NLS.bind(CompareWin32Messages.WordComparison_3, command, value));
112
		throw new SWTException(NLS.bind(CompareWin32Messages.WordComparison_3, command, value));
105
	}
113
	}
106
114
115
116
	/**
117
	 * <p>This methods workarounds the feature in doc documents. Some properties are not accessible
118
	 * using names when a diff document is created. The workaround is to obtain the id of the
119
	 * method from an original document and use it in the newly created one.</p>
120
	 *
121
	 * <p>An exception is thrown if the id cannot be retrieved</p>
122
	 *
123
	 * Reference information for id assignment: <a href="
124
	 * http://msdn.microsoft.com/en-us/library/w7a36sdf%28VS.80%29.aspx">http://msdn.microsoft.com/en-us/library/w7a36sdf%28VS.80%29.aspx</a>
125
	 *
126
	 * @param auto - object from which we want to get the property, must not be <code>null</code>
127
	 * @param reference - an reference object from which the property will be obtained.
128
	 * @param name - the name of the property, must not be <code>null</code>
129
	 */
130
	private static int property(OleAutomation auto, OleAutomation reference, String name) {
131
		int[] ids = auto.getIDsOfNames(new String[] { name });
132
		if (ids != null) {
133
			return ids[0];
134
		}
135
		if(reference == null) throw new SWTException(NLS.bind(CompareWin32Messages.WordComparison_4, name)) ;
136
137
		// the property was not retrieved at that point, try to get it from the reference object
138
		ids = reference.getIDsOfNames(new String[] { name });
139
		if (ids == null) {
140
			throw new SWTException(NLS.bind(CompareWin32Messages.WordComparison_4, name));
141
		}
142
		return ids[0];
143
	}
144
107
	private static int property(OleAutomation auto, String name) {
145
	private static int property(OleAutomation auto, String name) {
108
		int[] ids = auto.getIDsOfNames(new String[] { name });
146
		int[] ids = auto.getIDsOfNames(new String[] { name });
109
		if (ids == null) throw new SWTException(NLS.bind(CompareWin32Messages.WordComparison_4, name));
147
		if (ids == null) throw new SWTException(NLS.bind(CompareWin32Messages.WordComparison_4, name));
Lines 154-166 Link Here
154
				compareDocument(document, baseDocument, revisedDocument);
192
				compareDocument(document, baseDocument, revisedDocument);
155
				OleAutomation activeDocument = getActiveDocument(application);
193
				OleAutomation activeDocument = getActiveDocument(application);
156
				try {
194
				try {
157
					Variant varResult = invoke(activeDocument, "SaveAs", workingCopy); //$NON-NLS-1$
195
					Variant varResult = invoke(activeDocument, document, "SaveAs", workingCopy); //$NON-NLS-1$
158
					if (varResult == null)
196
					if (varResult == null)
159
						throw new SWTException(NLS.bind(CompareWin32Messages.WordComparison_6, workingCopy));
197
						throw new SWTException(NLS.bind(CompareWin32Messages.WordComparison_6, workingCopy));
160
					varResult.dispose();
198
					varResult.dispose();
161
				} finally {
199
				} finally {
162
					try {
200
					try {
163
						closeDocument(activeDocument);
201
						closeDocument(activeDocument, document);
164
					} catch (SWTException e) {
202
					} catch (SWTException e) {
165
						// We don't want to throw the exception as we may mask another exception
203
						// We don't want to throw the exception as we may mask another exception
166
						Activator.log(e);
204
						Activator.log(e);
Lines 170-176 Link Here
170
				}
208
				}
171
			} finally {
209
			} finally {
172
				try {
210
				try {
173
					closeDocument(document);
211
					closeDocument(document, null);
174
				} catch (SWTException e) {
212
				} catch (SWTException e) {
175
					// We don't want to throw the exception as we may mask another exception
213
					// We don't want to throw the exception as we may mask another exception
176
					Activator.log(e);
214
					Activator.log(e);
Lines 183-191 Link Here
183
		}
221
		}
184
	}
222
	}
185
	
223
	
186
	private void closeDocument(OleAutomation document) {
224
	private void closeDocument(OleAutomation document, OleAutomation reference) {
187
		// Close the first document: destination.Close()
225
		// Close the first document: destination.Close()
188
		Variant varResult = invoke(document, "Close"); //$NON-NLS-1$
226
		Variant varResult = invoke(document, reference, "Close"); //$NON-NLS-1$
189
		if (varResult != null) {
227
		if (varResult != null) {
190
			varResult.dispose();
228
			varResult.dispose();
191
		}
229
		}
Lines 273-279 Link Here
273
	private void disposeSite() {
311
	private void disposeSite() {
274
		if (document != null) {
312
		if (document != null) {
275
			try {
313
			try {
276
				closeDocument(document);
314
				closeDocument(document, null);
277
			} catch (SWTException e) {
315
			} catch (SWTException e) {
278
				Activator.log(e);
316
				Activator.log(e);
279
			}
317
			}

Return to bug 326393