KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jface > internal > text > revisions > 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.jface.internal.text.revisions;
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  * <p>
28  * XXX copy of org.eclipse.jdt.internal.ui.text.java.hover.AbstractReusableInformationControlCreator.
29  * </p>
30  *
31  * @since 3.2
32  */

33 abstract class AbstractReusableInformationControlCreator implements IInformationControlCreator, IInformationControlCreatorExtension, DisposeListener {
34
35     private Map JavaDoc fInformationControls= new HashMap JavaDoc();
36
37     /**
38      * Creates the control.
39      *
40      * @param parent the parent shell
41      * @return the created information control
42      */

43     protected abstract IInformationControl doCreateInformationControl(Shell parent);
44
45     /*
46      * @see org.eclipse.jface.text.IInformationControlCreator#createInformationControl(org.eclipse.swt.widgets.Shell)
47      */

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

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

73     public boolean canReuse(IInformationControl control) {
74         return fInformationControls.containsValue(control);
75     }
76
77     /*
78      * @see org.eclipse.jface.text.IInformationControlCreatorExtension#canReplace(org.eclipse.jface.text.IInformationControlCreator)
79      */

80     public boolean canReplace(IInformationControlCreator creator) {
81         return creator.getClass() == getClass();
82     }
83 }
84
Popular Tags