diff dwtx/jface/viewers/ArrayContentProvider.d @ 10:b6c35faf97c8

Viewers
author Frank Benoit <benoit@tionex.de>
date Mon, 31 Mar 2008 00:47:19 +0200
parents
children dad2e11b8ae4
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/dwtx/jface/viewers/ArrayContentProvider.d	Mon Mar 31 00:47:19 2008 +0200
@@ -0,0 +1,61 @@
+/*******************************************************************************
+ * Copyright (c) 2000, 2006 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.viewers.ArrayContentProvider;
+
+import dwtx.jface.viewers.IStructuredContentProvider;
+import dwtx.jface.viewers.Viewer;
+
+import tango.util.collection.model.View;
+
+import dwt.dwthelper.utils;
+
+/**
+ * This implementation of <code>IStructuredContentProvider</code> handles
+ * the case where the viewer input is an unchanging array or collection of elements.
+ * <p>
+ * This class is not intended to be subclassed outside the viewer framework.
+ * </p>
+ *
+ * @since 2.1
+ */
+public class ArrayContentProvider : IStructuredContentProvider {
+
+    /**
+     * Returns the elements in the input, which must be either an array or a
+     * <code>Collection</code>.
+     */
+    public Object[] getElements(Object inputElement) {
+        if ( auto aw = cast(ArrayWrapperObject) inputElement ) {
+            return aw.array;
+        }
+        if ( auto col = cast(View!(Object)) inputElement ) {
+            return col.toArray();
+        }
+        return null;
+    }
+
+    /**
+     * This implementation does nothing.
+     */
+    public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
+        // do nothing.
+    }
+
+    /**
+     * This implementation does nothing.
+     */
+    public void dispose() {
+        // do nothing.
+    }
+}