129
|
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 * Port to the D programming language:
|
|
11 * Frank Benoit <benoit@tionex.de>
|
|
12 *******************************************************************************/
|
|
13 module dwtx.jface.text.AbstractReusableInformationControlCreator;
|
|
14
|
|
15 import dwt.dwthelper.utils;
|
|
16
|
|
17 import java.util.HashMap;
|
|
18 import java.util.Map;
|
|
19
|
|
20 import dwt.events.DisposeEvent;
|
|
21 import dwt.events.DisposeListener;
|
|
22 import dwt.widgets.Composite;
|
|
23 import dwt.widgets.Shell;
|
|
24
|
|
25
|
|
26 /**
|
|
27 * Abstract class for a reusable information control creators.
|
|
28 *
|
|
29 * @since 3.3
|
|
30 */
|
|
31 public abstract class AbstractReusableInformationControlCreator : IInformationControlCreator, IInformationControlCreatorExtension, DisposeListener {
|
|
32
|
|
33 private Map fInformationControls= new HashMap();
|
|
34
|
|
35 /**
|
|
36 * Creates the control.
|
|
37 *
|
|
38 * @param parent the parent shell
|
|
39 * @return the created information control
|
|
40 */
|
|
41 protected abstract IInformationControl doCreateInformationControl(Shell parent);
|
|
42
|
|
43 /*
|
|
44 * @see dwtx.jface.text.IInformationControlCreator#createInformationControl(dwt.widgets.Shell)
|
|
45 */
|
|
46 public IInformationControl createInformationControl(Shell parent) {
|
|
47 IInformationControl control= (IInformationControl)fInformationControls.get(parent);
|
|
48 if (control is null) {
|
|
49 control= doCreateInformationControl(parent);
|
|
50 control.addDisposeListener(this);
|
|
51 fInformationControls.put(parent, control);
|
|
52 }
|
|
53 return control;
|
|
54 }
|
|
55
|
|
56 /*
|
|
57 * @see dwt.events.DisposeListener#widgetDisposed(dwt.events.DisposeEvent)
|
|
58 */
|
|
59 public void widgetDisposed(DisposeEvent e) {
|
|
60 Composite parent= null;
|
|
61 if (e.widget instanceof Shell)
|
|
62 parent= ((Shell)e.widget).getParent();
|
|
63 if (parent instanceof Shell)
|
|
64 fInformationControls.remove(parent);
|
|
65 }
|
|
66
|
|
67
|
|
68 /*
|
|
69 * @see dwtx.jface.text.IInformationControlCreatorExtension#canReuse(dwtx.jface.text.IInformationControl)
|
|
70 */
|
|
71 public bool canReuse(IInformationControl control) {
|
|
72 return fInformationControls.containsValue(control);
|
|
73 }
|
|
74
|
|
75 /*
|
|
76 * @see dwtx.jface.text.IInformationControlCreatorExtension#canReplace(dwtx.jface.text.IInformationControlCreator)
|
|
77 */
|
|
78 public bool canReplace(IInformationControlCreator creator) {
|
|
79 return creator.getClass() is getClass();
|
|
80 }
|
|
81 }
|