KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > compare > internal > CompareAction


1 /*******************************************************************************
2  * Copyright (c) 2000, 2007 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  * Matt McCutchen (hashproduct+eclipse@gmail.com) - Bug 35390 Three-way compare cannot select (mis-selects) )ancestor resource
11  *******************************************************************************/

12 package org.eclipse.compare.internal;
13
14 import org.eclipse.jface.action.IAction;
15 import org.eclipse.jface.viewers.ISelection;
16
17 import org.eclipse.ui.IObjectActionDelegate;
18 import org.eclipse.ui.IWorkbenchPage;
19 import org.eclipse.ui.IWorkbenchPart;
20 import org.eclipse.compare.CompareConfiguration;
21 import org.eclipse.compare.CompareUI;
22
23
24 /*
25  * The "Compare with each other" action
26  */

27 public class CompareAction extends BaseCompareAction implements IObjectActionDelegate {
28
29     private ResourceCompareInput fInput;
30     private IWorkbenchPage fWorkbenchPage;
31
32
33     public void run(ISelection selection) {
34         if (fInput != null) {
35             // Pass the shell so setSelection can prompt the user for which
36
// resource should be the ancestor
37
boolean ok = fInput.setSelection(selection,
38                 fWorkbenchPage.getWorkbenchWindow().getShell());
39             if (!ok) return;
40             fInput.initializeCompareConfiguration();
41             CompareUI.openCompareEditorOnPage(fInput, fWorkbenchPage);
42             fInput= null; // don't reuse this input!
43
}
44     }
45
46     protected boolean isEnabled(ISelection selection) {
47         if (fInput == null) {
48             CompareConfiguration cc= new CompareConfiguration();
49             // buffered merge mode: don't ask for confirmation
50
// when switching between modified resources
51
cc.setProperty(CompareEditor.CONFIRM_SAVE_PROPERTY, new Boolean JavaDoc(false));
52             
53             // uncomment following line to have separate outline view
54
//cc.setProperty(CompareConfiguration.USE_OUTLINE_VIEW, new Boolean(true));
55

56             fInput= new ResourceCompareInput(cc);
57         }
58         return fInput.isEnabled(selection);
59     }
60
61     public void setActivePart(IAction action, IWorkbenchPart targetPart) {
62         fWorkbenchPage= targetPart.getSite().getPage();
63     }
64 }
65
Popular Tags