changeset 179:89de7ff0752c default tip

Add JFace snippet Snippet054NativeControlsInViewers, thanks to WasserDragoon
author Frank Benoit <benoit@tionex.de>
date Wed, 29 Apr 2009 11:01:41 +0200
parents 61dd51f8d45f
children
files jface/dsss.conf jface/snippets/viewers/Snippet054NativeControlsInViewers.d
diffstat 2 files changed, 206 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/jface/dsss.conf	Sun Feb 01 19:43:48 2009 +0100
+++ b/jface/dsss.conf	Wed Apr 29 11:01:41 2009 +0200
@@ -24,11 +24,13 @@
 }
 
 #[sqleditor/jfacetext/sqleditor/SQLEditor.d]
+#[test2.d]
 [FileTreeViewer.d]
 [Librarian.d]
 [ActionAndStatusbar.d]
 [ShowFieldPrefs.d]
 [ShowPrefs.d]
+#[SWTCompletionEditor.d]
 [user/Decoration.d]
 [user/PopUp.d]
 [snippets/viewers/Snippet001TableViewer.d]
@@ -38,6 +40,7 @@
 [snippets/viewers/Snippet006TableMultiLineCells.d]
 [snippets/viewers/Snippet007FullSelection.d]
 [snippets/viewers/Snippet010OwnerDraw.d]
+[snippets/viewers/Snippet011CustomTooltips.d]
 [snippets/viewers/Snippet014TreeViewerNoMandatoryLabelProvider.d]
 [snippets/viewers/Snippet016TableLayout.d]
 [snippets/viewers/Snippet019TableViewerAddRemoveColumnsWithEditingNewAPI.d]
@@ -46,8 +49,10 @@
 [snippets/viewers/Snippet040TableViewerSorting.d]
 [snippets/viewers/Snippet043NoColumnTreeViewerKeyboardEditing.d]
 [snippets/viewers/Snippet047VirtualLazyTreeViewer.d]
+[snippets/viewers/Snippet054NativeControlsInViewers.d]
 [snippets/window/Snippet020CustomizedControlTooltips.d]
 [snippets/window/Snippet023TreeViewerCustomTooltips.d]
 [snippets/window/Snippet031TableStaticTooltip.d]
 [snippets/wizard/Snippet047WizardWithLongRunningOperation.d]
 
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/jface/snippets/viewers/Snippet054NativeControlsInViewers.d	Wed Apr 29 11:01:41 2009 +0200
@@ -0,0 +1,201 @@
+/*******************************************************************************
+ * Copyright (c) 2006 Tom Schindl 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:
+ *     Tom Schindl - initial API and implementation
+ *******************************************************************************/
+
+module jface.snippets.viewers.Snippet054NativeControlsInViewers;
+
+import dwtx.jface.viewers.CellLabelProvider;
+import dwtx.jface.viewers.ColumnLabelProvider;
+import dwtx.jface.viewers.IStructuredContentProvider;
+import dwtx.jface.viewers.TableViewer;
+import dwtx.jface.viewers.TableViewerColumn;
+import dwtx.jface.viewers.Viewer;
+import dwtx.jface.viewers.ViewerCell;
+import dwt.DWT;
+import dwt.custom.TableEditor;
+import dwt.dwthelper.utils;
+import dwt.events.DisposeEvent;
+import dwt.events.DisposeListener;
+import dwt.events.SelectionAdapter;
+import dwt.events.SelectionEvent;
+import dwt.events.SelectionListener;
+import dwt.layout.FillLayout;
+import dwt.layout.RowLayout;
+import dwt.widgets.Button;
+import dwt.widgets.Composite;
+import dwt.widgets.Display;
+import dwt.widgets.Shell;
+import dwt.widgets.TableItem;
+
+import tango.util.Convert;
+import tango.util.collection.ArraySeq;
+
+/**
+ * Example how to place native controls into a viewer with the new JFace-API
+ * because has the potential to eat up all your handles you should think about
+ * alternate approaches e.g. takeing a screenshot of the control
+ *
+ * @author Tom Schindl <tom.schindl@bestsolution.at>
+ *
+ */
+public class Snippet054NativeControlsInViewers {
+
+    private class MyContentProvider: IStructuredContentProvider {
+
+        /*
+         * (non-Javadoc)
+         *
+         * @see org.eclipse.jface.viewers.IStructuredContentProvider#getElements(java.lang.Object)
+         */
+        public Object[] getElements(Object inputElement) {
+            return (cast(ArraySeq!(MyModel))inputElement).toArray;
+        }
+
+        /*
+         * (non-Javadoc)
+         *
+         * @see org.eclipse.jface.viewers.IContentProvider#dispose()
+         */
+        public void dispose() {
+
+        }
+
+        /*
+         * (non-Javadoc)
+         *
+         * @see org.eclipse.jface.viewers.IContentProvider#inputChanged(org.eclipse.jface.viewers.Viewer,
+         *      java.lang.Object, java.lang.Object)
+         */
+        public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
+
+        }
+
+    }
+
+    public class MyModel {
+        public int counter;
+
+        public this(int counter) {
+            this.counter = counter;
+        }
+
+        public String toString() {
+            return "Item " ~ to!(char[])(this.counter);
+        }
+    }
+
+    public this(Shell shell) {
+        final TableViewer v = new TableViewer(shell, DWT.BORDER
+                | DWT.FULL_SELECTION);
+        v.setContentProvider(new MyContentProvider());
+
+        TableViewerColumn column = new TableViewerColumn(v, DWT.NONE);
+        column.getColumn().setWidth(200);
+        column.getColumn().setText("Column 1");
+        column.setLabelProvider(new class() ColumnLabelProvider {
+
+            public String getText(Object element) {
+                return element.toString();
+            }
+
+        });
+
+        column = new TableViewerColumn(v, DWT.NONE);
+        column.getColumn().setWidth(200);
+        column.getColumn().setText("Column 2");
+        column.setLabelProvider(new class() CellLabelProvider {
+
+            public void update(ViewerCell cell) {
+                final TableItem item = cast(TableItem) cell.getItem();
+                DisposeListener listener = new class(item) DisposeListener {
+
+                    private TableItem item;
+
+                    public this(TableItem item) {
+                        this.item = item;
+                    }
+
+                    public void widgetDisposed(DisposeEvent e) {
+                        if( item.getData("EDITOR") !is null ) {
+                            TableEditor editor = cast(TableEditor) item.getData("EDITOR");
+                            editor.getEditor().dispose();
+                            editor.dispose();
+                        }
+                    }
+
+                };
+
+                if (item.getData("EDITOR") !is null) {
+                    TableEditor editor = cast(TableEditor) item.getData("EDITOR");
+                    editor.getEditor().dispose();
+                    editor.dispose();
+                }
+
+                if( item.getData("DISPOSELISTNER") !is null ) {
+                    item.removeDisposeListener(cast(DisposeListener) item.getData("DISPOSELISTNER"));
+                }
+
+                TableEditor editor = new TableEditor(item.getParent());
+                item.setData("EDITOR", editor);
+                Composite comp = new Composite(item.getParent(), DWT.NONE);
+                comp.setBackground(item.getParent().getBackground());
+                comp.setBackgroundMode(DWT.INHERIT_DEFAULT);
+                RowLayout l = new RowLayout();
+                l.marginHeight = 0;
+                l.marginWidth = 0;
+                l.marginTop = 0;
+                l.marginBottom = 0;
+                comp.setLayout(l);
+                Button rad = new Button(comp, DWT.RADIO);
+                Button rad1 = new Button(comp, DWT.RADIO);
+                Button rad2 = new Button(comp, DWT.RADIO);
+
+                editor.grabHorizontal = true;
+                editor.setEditor(comp, item, 1);
+
+                item.addDisposeListener(listener);
+                item.setData("DISPOSELISTNER",cast(Object)listener);
+            }
+
+        });
+
+        ArraySeq!(MyModel) model = createModel(10);
+        v.setInput(model);
+        v.getTable().setLinesVisible(true);
+        v.getTable().setHeaderVisible(true);
+    }
+
+    private ArraySeq!(MyModel) createModel(int amount) {
+        ArraySeq!(MyModel) elements = new ArraySeq!(MyModel);
+        elements.capacity  = amount;
+
+        for (int i = 0; i < amount; i++) {
+            elements ~= new MyModel(i);
+        }
+
+        return elements;
+    }
+}
+
+void main() {
+    Display display = new Display();
+    Shell shell = new Shell(display);
+    shell.setLayout(new FillLayout());
+    new Snippet054NativeControlsInViewers(shell);
+    shell.open();
+
+    while (!shell.isDisposed()) {
+        if (!display.readAndDispatch())
+            display.sleep();
+    }
+
+    display.dispose();
+
+}