Added
Link Here
|
1 |
/******************************************************************************* |
2 |
* Copyright (c) 2009 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; |
12 |
import org.eclipse.compare.CompareConfiguration; |
13 |
import org.eclipse.compare.CompareUI; |
14 |
import org.eclipse.core.commands.AbstractHandler; |
15 |
import org.eclipse.core.commands.ExecutionEvent; |
16 |
import org.eclipse.core.commands.ExecutionException; |
17 |
import org.eclipse.jface.viewers.ISelection; |
18 |
import org.eclipse.jface.viewers.IStructuredSelection; |
19 |
import org.eclipse.ui.IWorkbenchPage; |
20 |
import org.eclipse.ui.handlers.HandlerUtil; |
21 |
|
22 |
/** |
23 |
* This is a temporarily replacement for CompareWithOtherResourceAction which |
24 |
* was available from "Compare With > Other Resource...". See bug 264498. |
25 |
*/ |
26 |
public class CompareWithOtherResourceHandler extends AbstractHandler { |
27 |
|
28 |
public Object execute(ExecutionEvent event) throws ExecutionException { |
29 |
ISelection selection = HandlerUtil.getCurrentSelection(event); |
30 |
IWorkbenchPage workbenchPage = HandlerUtil.getActiveWorkbenchWindow(event).getActivePage(); |
31 |
|
32 |
// CompareAction#isEnabled(ISelection) |
33 |
CompareConfiguration cc= new CompareConfiguration(); |
34 |
cc.setProperty(CompareEditor.CONFIRM_SAVE_PROPERTY, new Boolean(false)); |
35 |
ResourceCompareInput input= new ResourceCompareInput(cc); |
36 |
|
37 |
int selectionSize = 0; |
38 |
if (selection instanceof IStructuredSelection) { |
39 |
selectionSize = ((IStructuredSelection) selection).toArray().length; |
40 |
} |
41 |
if (input.isEnabled(selection) || selectionSize == 1) { |
42 |
|
43 |
// CompareAction#run(ISelection) |
44 |
if (!input.setSelection(selection, workbenchPage.getWorkbenchWindow().getShell(), false)) |
45 |
return null; |
46 |
input.initializeCompareConfiguration(); |
47 |
CompareUI.openCompareEditorOnPage(input, workbenchPage); |
48 |
} |
49 |
return null; |
50 |
} |
51 |
|
52 |
} |