KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jdt > internal > ui > text > java > hover > AbstractReusableInformationControlCreator


1 /*******************************************************************************
2  * Copyright (c) 2005, 2006 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  *******************************************************************************/

11 package org.eclipse.jdt.internal.ui.text.java.hover;
12
13 import java.util.HashMap JavaDoc;
14 import java.util.Map JavaDoc;
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 /**
26  * Abstract class for a reusable information control creators.
27  *
28  * @since 3.2
29  */

30 public abstract class AbstractReusableInformationControlCreator implements IInformationControlCreator, IInformationControlCreatorExtension, DisposeListener {
31
32     private Map JavaDoc fInformationControls= new HashMap JavaDoc();
33
34     /**
35      * Creates the control.
36      */

37     protected abstract IInformationControl doCreateInformationControl(Shell parent);
38
39     /*
40      * @see org.eclipse.jface.text.IInformationControlCreator#createInformationControl(org.eclipse.swt.widgets.Shell)
41      */

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     /*
53      * @see org.eclipse.swt.events.DisposeListener#widgetDisposed(org.eclipse.swt.events.DisposeEvent)
54      */

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     /*
65      * @see org.eclipse.jface.text.IInformationControlCreatorExtension#canReuse(org.eclipse.jface.text.IInformationControl)
66      */

67     public boolean canReuse(IInformationControl control) {
68         return fInformationControls.containsValue(control);
69     }
70
71     /*
72      * @see org.eclipse.jface.text.IInformationControlCreatorExtension#canReplace(org.eclipse.jface.text.IInformationControlCreator)
73      */

74     public boolean canReplace(IInformationControlCreator creator) {
75         return creator.getClass() == getClass();
76     }
77 }
78
Popular Tags