1 11 package org.eclipse.jdt.internal.ui.refactoring; 12 13 import java.lang.reflect.Constructor ; 14 import java.lang.reflect.InvocationTargetException ; 15 import java.util.HashMap ; 16 import java.util.Map ; 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 fMap= new HashMap (); 25 26 private static class Tuple { 27 private Class starter; 28 private Class wizard; 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 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 wizardClass= tuple.wizard; 50 Constructor constructor= wizardClass.getConstructor(new Class [] {Refactoring.class}); 51 RefactoringWizard wizard= (RefactoringWizard)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 } 67 | Popular Tags |