KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jdt > internal > ui > refactoring > UserInterfaceManager


1 /*******************************************************************************
2  * Copyright (c) 2000, 2005 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;
12
13 import java.lang.reflect.Constructor JavaDoc;
14 import java.lang.reflect.InvocationTargetException JavaDoc;
15 import java.util.HashMap JavaDoc;
16 import java.util.Map JavaDoc;
17
18 import org.eclipse.ltk.core.refactoring.Refactoring;
19 import org.eclipse.ltk.core.refactoring.participants.RefactoringProcessor;
20 import org.eclipse.ltk.ui.refactoring.RefactoringWizard;
21
22 public class UserInterfaceManager {
23     
24     private Map JavaDoc fMap= new HashMap JavaDoc();
25     
26     private static class Tuple {
27         private Class JavaDoc starter;
28         private Class JavaDoc wizard;
29         public Tuple(Class JavaDoc s, Class JavaDoc w) {
30             starter= s;
31             wizard= w;
32         }
33     }
34     
35     protected void put(Class JavaDoc processor, Class JavaDoc starter, Class JavaDoc wizard) {
36         fMap.put(processor, new Tuple(starter, wizard));
37     }
38
39     
40     public UserInterfaceStarter getStarter(Refactoring refactoring) {
41         RefactoringProcessor processor= (RefactoringProcessor)refactoring.getAdapter(RefactoringProcessor.class);
42         if (processor == null)
43             return null;
44         Tuple tuple= (Tuple)fMap.get(processor.getClass());
45         if (tuple == null)
46             return null;
47         try {
48             UserInterfaceStarter starter= (UserInterfaceStarter)tuple.starter.newInstance();
49             Class JavaDoc wizardClass= tuple.wizard;
50             Constructor JavaDoc constructor= wizardClass.getConstructor(new Class JavaDoc[] {Refactoring.class});
51             RefactoringWizard wizard= (RefactoringWizard)constructor.newInstance(new Object JavaDoc[] {refactoring});
52             starter.initialize(wizard);
53             return starter;
54         } catch (NoSuchMethodException JavaDoc e) {
55             return null;
56         } catch (IllegalAccessException JavaDoc e) {
57             return null;
58         } catch (InstantiationException JavaDoc e) {
59             return null;
60         } catch (IllegalArgumentException JavaDoc e) {
61             return null;
62         } catch (InvocationTargetException JavaDoc e) {
63             return null;
64         }
65     }
66 }
67
Popular Tags