KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jface > text > AbstractReusableInformationControlCreator


1 /*******************************************************************************
2  * Copyright (c) 2007 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.text;
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
22 /**
23  * Abstract class for a reusable information control creators.
24  *
25  * @since 3.3
26  */

27 public abstract class AbstractReusableInformationControlCreator implements IInformationControlCreator, IInformationControlCreatorExtension, DisposeListener {
28
29     private Map JavaDoc fInformationControls= new HashMap JavaDoc();
30
31     /**
32      * Creates the control.
33      *
34      * @param parent the parent shell
35      * @return the created information 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