]> git.uio.no Git - ifi-stolz-refaktor.git/blame - case-study/jdt-before/ui refactoring/org/eclipse/jdt/internal/ui/refactoring/UserInterfaceManager.java
Case Study: adding data and statistics
[ifi-stolz-refaktor.git] / case-study / jdt-before / ui refactoring / org / eclipse / jdt / internal / ui / refactoring / UserInterfaceManager.java
CommitLineData
1b2798f6
EK
1/*******************************************************************************
2 * Copyright (c) 2000, 2011 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 *******************************************************************************/
11package org.eclipse.jdt.internal.ui.refactoring;
12
13import java.lang.reflect.Constructor;
14import java.lang.reflect.InvocationTargetException;
15import java.util.HashMap;
16import java.util.Map;
17
18import org.eclipse.ltk.core.refactoring.Refactoring;
19import org.eclipse.ltk.core.refactoring.participants.RefactoringProcessor;
20import org.eclipse.ltk.ui.refactoring.RefactoringWizard;
21
22public class UserInterfaceManager {
23
24 private Map<Class<? extends RefactoringProcessor>, Tuple> fMap= new HashMap<Class<? extends RefactoringProcessor>, Tuple>();
25
26 private static class Tuple {
27 private Class<? extends UserInterfaceStarter> starter;
28 private Class<? extends RefactoringWizard> wizard;
29 public Tuple(Class<? extends UserInterfaceStarter> s, Class<? extends RefactoringWizard> w) {
30 starter= s;
31 wizard= w;
32 }
33 }
34
35 protected void put(Class<? extends RefactoringProcessor> processor, Class<? extends UserInterfaceStarter> starter, Class<? extends RefactoringWizard> 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= fMap.get(processor.getClass());
45 if (tuple == null)
46 return null;
47 try {
48 UserInterfaceStarter starter= tuple.starter.newInstance();
49 Class<? extends RefactoringWizard> wizardClass= tuple.wizard;
50 Constructor<? extends RefactoringWizard> constructor= wizardClass.getConstructor(new Class[] {Refactoring.class});
51 RefactoringWizard wizard= constructor.newInstance(new Object[] {refactoring});
52 starter.initialize(wizard);
53 return starter;
54 } catch (NoSuchMethodException e) {
55 return null;
56 } catch (IllegalAccessException e) {
57 return null;
58 } catch (InstantiationException e) {
59 return null;
60 } catch (IllegalArgumentException e) {
61 return null;
62 } catch (InvocationTargetException e) {
63 return null;
64 }
65 }
66}