KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > ltk > internal > ui > refactoring > actions > RejectRefactoringsAction


1 /*******************************************************************************
2  * Copyright (c) 2006 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.ltk.internal.ui.refactoring.actions;
12
13 import java.lang.reflect.InvocationTargetException JavaDoc;
14
15 import org.eclipse.team.core.diff.IThreeWayDiff;
16 import org.eclipse.team.core.mapping.IMergeContext;
17 import org.eclipse.team.core.mapping.ISynchronizationContext;
18
19 import org.eclipse.core.runtime.Assert;
20 import org.eclipse.core.runtime.IProgressMonitor;
21 import org.eclipse.core.runtime.SubProgressMonitor;
22
23 import org.eclipse.ltk.core.refactoring.RefactoringDescriptorProxy;
24
25 import org.eclipse.ltk.internal.core.refactoring.history.RefactoringHistoryService;
26 import org.eclipse.ltk.internal.ui.refactoring.RefactoringUIPlugin;
27 import org.eclipse.ltk.internal.ui.refactoring.model.ModelMessages;
28 import org.eclipse.ltk.internal.ui.refactoring.model.RefactoringDescriptorSynchronizationProxy;
29
30 import org.eclipse.jface.action.Action;
31 import org.eclipse.jface.operation.IRunnableWithProgress;
32
33 import org.eclipse.ui.PlatformUI;
34
35 /**
36  * Action to reject a pending refactoring and to just store it in the history.
37  *
38  * @since 3.2
39  */

40 public final class RejectRefactoringsAction extends Action {
41
42     /** The synchronization context to use */
43     private final ISynchronizationContext fContext;
44
45     /** The refactoring descriptor proxies, or <code>null</code> */
46     private RefactoringDescriptorProxy[] fProxies= null;
47
48     /**
49      * Creates a new reject refactorings action.
50      *
51      * @param context
52      * the synchronization context
53      */

54     public RejectRefactoringsAction(final ISynchronizationContext context) {
55         Assert.isNotNull(context);
56         fContext= context;
57         setText(ModelMessages.RejectRefactoringsAction_title);
58         setToolTipText(ModelMessages.RejectRefactoringsAction_tool_tip);
59         setDescription(ModelMessages.RejectRefactoringsAction_description);
60     }
61
62     /**
63      * {@inheritDoc}
64      */

65     public boolean isEnabled() {
66         if (fProxies != null && fProxies.length > 0 && fContext instanceof IMergeContext) {
67             for (int index= 0; index < fProxies.length; index++) {
68                 if (fProxies[index] instanceof RefactoringDescriptorSynchronizationProxy) {
69                     final RefactoringDescriptorSynchronizationProxy proxy= (RefactoringDescriptorSynchronizationProxy) fProxies[index];
70                     if (proxy.getDirection() == IThreeWayDiff.INCOMING)
71                         return true;
72                 }
73             }
74         }
75         return false;
76     }
77
78     /**
79      * {@inheritDoc}
80      */

81     public void run() {
82         if (fProxies != null) {
83             try {
84                 PlatformUI.getWorkbench().getProgressService().run(true, true, new IRunnableWithProgress() {
85
86                     public final void run(final IProgressMonitor monitor) throws InvocationTargetException JavaDoc, InterruptedException JavaDoc {
87                         try {
88                             monitor.beginTask("", fProxies.length + 100); //$NON-NLS-1$
89
final RefactoringHistoryService service= RefactoringHistoryService.getInstance();
90                             for (int index= 0; index < fProxies.length; index++)
91                                 service.addRefactoringDescriptor(fProxies[index], new SubProgressMonitor(monitor, 1));
92                         } finally {
93                             monitor.done();
94                         }
95                     }
96                 });
97             } catch (InvocationTargetException JavaDoc exception) {
98                 RefactoringUIPlugin.log(exception);
99             } catch (InterruptedException JavaDoc exception) {
100                 // Do nothing
101
}
102         }
103     }
104
105     /**
106      * Sets the refactoring descriptor proxies to accept.
107      *
108      * @param proxies
109      * the refactoring descriptor proxies
110      */

111     public void setRefactoringDescriptors(final RefactoringDescriptorProxy[] proxies) {
112         Assert.isNotNull(proxies);
113         fProxies= proxies;
114     }
115 }
Popular Tags