diff dwtx/jface/text/source/ContentAssistantFacade.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/source/ContentAssistantFacade.d	Sat Aug 23 19:10:48 2008 +0200
@@ -0,0 +1,94 @@
+/*******************************************************************************
+ * 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.source.ContentAssistantFacade;
+
+import dwt.dwthelper.utils;
+
+
+
+import dwtx.core.commands.IHandler;
+import dwtx.core.runtime.Assert;
+import dwtx.jface.text.contentassist.ICompletionListener;
+import dwtx.jface.text.contentassist.IContentAssistant;
+import dwtx.jface.text.contentassist.IContentAssistantExtension2;
+import dwtx.jface.text.contentassist.IContentAssistantExtension4;
+
+
+/**
+ * Facade to allow minimal access to the given content assistant.
+ * <p>
+ * The offered API access can grow over time.
+ * </p>
+ * 
+ * @since 3.4
+ */
+public final class ContentAssistantFacade {
+
+    private IContentAssistant fContentAssistant;
+
+    /**
+     * Creates a new facade.
+     * 
+     * @param contentAssistant the content assistant which implements {@link IContentAssistantExtension2} and {@link IContentAssistantExtension4}
+     */
+    public ContentAssistantFacade(IContentAssistant contentAssistant) {
+        Assert.isLegal(contentAssistant instanceof IContentAssistantExtension4 && contentAssistant instanceof IContentAssistantExtension4);
+        fContentAssistant= contentAssistant;
+    }
+
+    /**
+     * Returns the handler for the given command identifier.
+     * <p>
+     * The same handler instance will be returned when called a more than once
+     * with the same command identifier.
+     * </p>
+     * 
+     * @param commandId the command identifier
+     * @return the handler for the given command identifier
+     * @throws IllegalArgumentException if the command is not supported by this
+     *             content assistant
+     * @throws IllegalStateException if called when the content assistant is
+     *             uninstalled
+     */
+    public IHandler getHandler(String commandId) {
+        if (fContentAssistant is null)
+            throw new IllegalStateException();
+        return ((IContentAssistantExtension4)fContentAssistant).getHandler(commandId);
+    }
+
+    /**
+     * Adds a completion listener that will be informed before proposals are
+     * computed.
+     * 
+     * @param listener the listener
+     * @throws IllegalStateException if called when the content assistant is
+     *             uninstalled
+     */
+    public void addCompletionListener(ICompletionListener listener) {
+        if (fContentAssistant is null)
+            throw new IllegalStateException();
+        ((IContentAssistantExtension2)fContentAssistant).addCompletionListener(listener);
+    }
+
+    /**
+     * Removes a completion listener.
+     * 
+     * @param listener the listener to remove
+     * @throws IllegalStateException if called when the content assistant is
+     *             uninstalled
+     */
+    public void removeCompletionListener(ICompletionListener listener) {
+        ((IContentAssistantExtension2)fContentAssistant).removeCompletionListener(listener);
+    }
+
+}