KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jdt > internal > ui > refactoring > reorg > ReorgCopyStarter


1 /*******************************************************************************
2  * Copyright (c) 2000, 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.jdt.internal.ui.refactoring.reorg;
12
13 import java.lang.reflect.InvocationTargetException JavaDoc;
14
15 import org.eclipse.core.runtime.Assert;
16
17 import org.eclipse.core.resources.IResource;
18
19 import org.eclipse.swt.widgets.Shell;
20
21 import org.eclipse.jface.dialogs.ProgressMonitorDialog;
22 import org.eclipse.jface.operation.IRunnableContext;
23
24 import org.eclipse.ltk.core.refactoring.RefactoringCore;
25
26 import org.eclipse.jdt.core.IJavaElement;
27 import org.eclipse.jdt.core.JavaModelException;
28
29 import org.eclipse.jdt.internal.corext.refactoring.reorg.JavaCopyProcessor;
30 import org.eclipse.jdt.internal.corext.refactoring.reorg.JavaCopyRefactoring;
31 import org.eclipse.jdt.internal.corext.refactoring.reorg.ReorgPolicyFactory;
32 import org.eclipse.jdt.internal.corext.refactoring.reorg.IReorgPolicy.ICopyPolicy;
33
34 import org.eclipse.jdt.internal.ui.refactoring.RefactoringExecutionHelper;
35 import org.eclipse.jdt.internal.ui.refactoring.RefactoringSaveHelper;
36
37 public class ReorgCopyStarter {
38
39     public static ReorgCopyStarter create(IJavaElement[] javaElements, IResource[] resources, IJavaElement destination) throws JavaModelException {
40         Assert.isNotNull(javaElements);
41         Assert.isNotNull(resources);
42         Assert.isNotNull(destination);
43         ICopyPolicy copyPolicy= ReorgPolicyFactory.createCopyPolicy(resources, javaElements);
44         if (!copyPolicy.canEnable())
45             return null;
46         JavaCopyProcessor copyProcessor= new JavaCopyProcessor(copyPolicy);
47         if (!copyProcessor.setDestination(destination).isOK())
48             return null;
49         return new ReorgCopyStarter(copyProcessor);
50     }
51
52     public static ReorgCopyStarter create(IJavaElement[] javaElements, IResource[] resources, IResource destination) throws JavaModelException {
53         Assert.isNotNull(javaElements);
54         Assert.isNotNull(resources);
55         Assert.isNotNull(destination);
56         ICopyPolicy copyPolicy= ReorgPolicyFactory.createCopyPolicy(resources, javaElements);
57         if (!copyPolicy.canEnable())
58             return null;
59         JavaCopyProcessor copyProcessor= new JavaCopyProcessor(copyPolicy);
60         if (!copyProcessor.setDestination(destination).isOK())
61             return null;
62         return new ReorgCopyStarter(copyProcessor);
63     }
64
65     private final JavaCopyProcessor fCopyProcessor;
66
67     private ReorgCopyStarter(JavaCopyProcessor copyProcessor) {
68         Assert.isNotNull(copyProcessor);
69         fCopyProcessor= copyProcessor;
70     }
71
72     public void run(Shell parent) throws InterruptedException JavaDoc, InvocationTargetException JavaDoc {
73         IRunnableContext context= new ProgressMonitorDialog(parent);
74         fCopyProcessor.setNewNameQueries(new NewNameQueries(parent));
75         fCopyProcessor.setReorgQueries(new ReorgQueries(parent));
76         new RefactoringExecutionHelper(new JavaCopyRefactoring(fCopyProcessor), RefactoringCore.getConditionCheckingFailedSeverity(), RefactoringSaveHelper.SAVE_NOTHING, parent, context).perform(false, false);
77     }
78 }
79
Popular Tags