1 11 package org.eclipse.jface.internal.text.revisions; 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 33 abstract class AbstractReusableInformationControlCreator implements IInformationControlCreator, IInformationControlCreatorExtension, DisposeListener { 34 35 private Map fInformationControls= new HashMap (); 36 37 43 protected abstract IInformationControl doCreateInformationControl(Shell parent); 44 45 48 public IInformationControl createInformationControl(Shell parent) { 49 IInformationControl control= (IInformationControl)fInformationControls.get(parent); 50 if (control == null) { 51 control= doCreateInformationControl(parent); 52 control.addDisposeListener(this); 53 fInformationControls.put(parent, control); 54 } 55 return control; 56 } 57 58 61 public void widgetDisposed(DisposeEvent e) { 62 Composite parent= null; 63 if (e.widget instanceof Shell) 64 parent= ((Shell)e.widget).getParent(); 65 if (parent instanceof Shell) 66 fInformationControls.remove(parent); 67 } 68 69 70 73 public boolean canReuse(IInformationControl control) { 74 return fInformationControls.containsValue(control); 75 } 76 77 80 public boolean canReplace(IInformationControlCreator creator) { 81 return creator.getClass() == getClass(); 82 } 83 } 84 | Popular Tags |