01: /*******************************************************************************
02: * Copyright (c) 2000, 2005 IBM Corporation and others.
03: * All rights reserved. This program and the accompanying materials
04: * are made available under the terms of the Eclipse Public License v1.0
05: * which accompanies this distribution, and is available at
06: * http://www.eclipse.org/legal/epl-v10.html
07: *
08: * Contributors:
09: * IBM Corporation - initial API and implementation
10: *******************************************************************************/package org.eclipse.jdt.internal.ui.refactoring;
11:
12: import java.lang.reflect.Constructor;
13: import java.lang.reflect.InvocationTargetException;
14: import java.util.HashMap;
15: import java.util.Map;
16:
17: import org.eclipse.ltk.core.refactoring.Refactoring;
18: import org.eclipse.ltk.core.refactoring.participants.RefactoringProcessor;
19: import org.eclipse.ltk.ui.refactoring.RefactoringWizard;
20:
21: public class UserInterfaceManager {
22:
23: private Map fMap = new HashMap();
24:
25: private static class Tuple {
26: private Class starter;
27: private Class wizard;
28:
29: public Tuple(Class s, Class w) {
30: starter = s;
31: wizard = w;
32: }
33: }
34:
35: protected void put(Class processor, Class starter, Class wizard) {
36: fMap.put(processor, new Tuple(starter, wizard));
37: }
38:
39: public UserInterfaceStarter getStarter(Refactoring refactoring) {
40: RefactoringProcessor processor = (RefactoringProcessor) refactoring
41: .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
49: .newInstance();
50: Class wizardClass = tuple.wizard;
51: Constructor constructor = wizardClass
52: .getConstructor(new Class[] { Refactoring.class });
53: RefactoringWizard wizard = (RefactoringWizard) constructor
54: .newInstance(new Object[] { refactoring });
55: starter.initialize(wizard);
56: return starter;
57: } catch (NoSuchMethodException e) {
58: return null;
59: } catch (IllegalAccessException e) {
60: return null;
61: } catch (InstantiationException e) {
62: return null;
63: } catch (IllegalArgumentException e) {
64: return null;
65: } catch (InvocationTargetException e) {
66: return null;
67: }
68: }
69: }
|