diff dwtx/jface/text/AbstractReusableInformationControlCreator.d @ 129:eb30df5ca28b

Added JFace Text sources
author Frank Benoit <benoit@tionex.de>
date Sat, 23 Aug 2008 19:10:48 +0200
parents
children c4fb132a086c
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/dwtx/jface/text/AbstractReusableInformationControlCreator.d	Sat Aug 23 19:10:48 2008 +0200
@@ -0,0 +1,81 @@
+/*******************************************************************************
+ * Copyright (c) 2007 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ *     IBM Corporation - initial API and implementation
+ * Port to the D programming language:
+ *     Frank Benoit <benoit@tionex.de>
+ *******************************************************************************/
+module dwtx.jface.text.AbstractReusableInformationControlCreator;
+
+import dwt.dwthelper.utils;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import dwt.events.DisposeEvent;
+import dwt.events.DisposeListener;
+import dwt.widgets.Composite;
+import dwt.widgets.Shell;
+
+
+/**
+ * Abstract class for a reusable information control creators.
+ * 
+ * @since 3.3
+ */
+public abstract class AbstractReusableInformationControlCreator : IInformationControlCreator, IInformationControlCreatorExtension, DisposeListener {
+
+    private Map fInformationControls= new HashMap();
+
+    /**
+     * Creates the control.
+     * 
+     * @param parent the parent shell
+     * @return the created information control
+     */
+    protected abstract IInformationControl doCreateInformationControl(Shell parent);
+
+    /*
+     * @see dwtx.jface.text.IInformationControlCreator#createInformationControl(dwt.widgets.Shell)
+     */
+    public IInformationControl createInformationControl(Shell parent) {
+        IInformationControl control= (IInformationControl)fInformationControls.get(parent);
+        if (control is null) {
+            control= doCreateInformationControl(parent);
+            control.addDisposeListener(this);
+            fInformationControls.put(parent, control);
+        }           
+        return control;
+    }
+    
+    /*
+     * @see dwt.events.DisposeListener#widgetDisposed(dwt.events.DisposeEvent)
+     */
+    public void widgetDisposed(DisposeEvent e) {
+        Composite parent= null;
+        if (e.widget instanceof Shell)
+            parent= ((Shell)e.widget).getParent();
+        if (parent instanceof Shell)
+            fInformationControls.remove(parent);
+    }
+
+
+    /*
+     * @see dwtx.jface.text.IInformationControlCreatorExtension#canReuse(dwtx.jface.text.IInformationControl)
+     */
+    public bool canReuse(IInformationControl control) {
+        return fInformationControls.containsValue(control);
+    }
+
+    /*
+     * @see dwtx.jface.text.IInformationControlCreatorExtension#canReplace(dwtx.jface.text.IInformationControlCreator)
+     */
+    public bool canReplace(IInformationControlCreator creator) {
+        return creator.getClass() is getClass();
+    }
+}