1 11 package org.eclipse.jdt.internal.ui.text.java.hover; 12 13 import java.util.HashMap ; 14 import java.util.Map ; 15 16 import org.eclipse.swt.events.DisposeEvent; 17 import org.eclipse.swt.events.DisposeListener; 18 import org.eclipse.swt.widgets.Composite; 19 import org.eclipse.swt.widgets.Shell; 20 21 import org.eclipse.jface.text.IInformationControl; 22 import org.eclipse.jface.text.IInformationControlCreator; 23 import org.eclipse.jface.text.IInformationControlCreatorExtension; 24 25 30 public abstract class AbstractReusableInformationControlCreator implements IInformationControlCreator, IInformationControlCreatorExtension, DisposeListener { 31 32 private Map fInformationControls= new HashMap (); 33 34 37 protected abstract IInformationControl doCreateInformationControl(Shell parent); 38 39 42 public IInformationControl createInformationControl(Shell parent) { 43 IInformationControl control= (IInformationControl)fInformationControls.get(parent); 44 if (control == null) { 45 control= doCreateInformationControl(parent); 46 control.addDisposeListener(this); 47 fInformationControls.put(parent, control); 48 } 49 return control; 50 } 51 52 55 public void widgetDisposed(DisposeEvent e) { 56 Composite parent= null; 57 if (e.widget instanceof Shell) 58 parent= ((Shell)e.widget).getParent(); 59 if (parent instanceof Shell) 60 fInformationControls.remove(parent); 61 } 62 63 64 67 public boolean canReuse(IInformationControl control) { 68 return fInformationControls.containsValue(control); 69 } 70 71 74 public boolean canReplace(IInformationControlCreator creator) { 75 return creator.getClass() == getClass(); 76 } 77 } 78 | Popular Tags |