summaryrefslogtreecommitdiffstatsabout
diff options
context:
space:
mode:
authorHendrik Still2013-06-29 20:58:17 (EDT)
committer Hendrik Still2013-07-23 14:26:20 (EDT)
commit38d75bb81e0b502c0c311f814ce9bafc5983e946 (patch)
tree6e124c471013908ec8206cdb77067b07c56517fd
parent819e6ff448f57dc4ee61c75ad1d8f68e4bc560e6 (diff)
downloadeclipse.platform.ui-38d75bb81e0b502c0c311f814ce9bafc5983e946.zip
eclipse.platform.ui-38d75bb81e0b502c0c311f814ce9bafc5983e946.tar.gz
eclipse.platform.ui-38d75bb81e0b502c0c311f814ce9bafc5983e946.tar.bz2
Bug 411967 New snippet to demonstrate the usage of ComboViewersrefs/changes/44/14744/5
Change-Id: I01a2e88699f5d1f70a58e592fb48bc45dd0c6f7d Signed-off-by: Hendrik Still <hendrik.still@gammas.de>
-rw-r--r--examples/org.eclipse.jface.snippets/Eclipse JFace Snippets/org/eclipse/jface/snippets/viewers/Snippet063ComboViewer.java132
1 files changed, 132 insertions, 0 deletions
diff --git a/examples/org.eclipse.jface.snippets/Eclipse JFace Snippets/org/eclipse/jface/snippets/viewers/Snippet063ComboViewer.java b/examples/org.eclipse.jface.snippets/Eclipse JFace Snippets/org/eclipse/jface/snippets/viewers/Snippet063ComboViewer.java
new file mode 100644
index 0000000..0f26c0a
--- /dev/null
+++ b/examples/org.eclipse.jface.snippets/Eclipse JFace Snippets/org/eclipse/jface/snippets/viewers/Snippet063ComboViewer.java
@@ -0,0 +1,132 @@
+/*******************************************************************************
+ * Copyright (c) 2013 Hendrik Still 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:
+ * Hendrik Still<hendrik.still@gammas.de> - initial implementation
+ *******************************************************************************/
+
+package org.eclipse.jface.snippets.viewers;
+
+import org.eclipse.jface.layout.GridLayoutFactory;
+import org.eclipse.jface.layout.LayoutConstants;
+import org.eclipse.jface.viewers.ComboViewer;
+import org.eclipse.jface.viewers.IStructuredContentProvider;
+import org.eclipse.jface.viewers.LabelProvider;
+import org.eclipse.jface.viewers.StructuredSelection;
+import org.eclipse.jface.viewers.Viewer;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.Shell;
+
+/**
+ * A simple ComboViewer to demonstrate usage
+ *
+ * @author Hendrik Still <hendrik.still@gammas.de>
+ *
+ */
+public class Snippet063ComboViewer {
+ private class MyContentProvider implements IStructuredContentProvider {
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * org.eclipse.jface.viewers.IStructuredContentProvider#getElements(
+ * java.lang.Object)
+ */
+ public Object[] getElements(Object inputElement) {
+ return (MyModel[]) inputElement;
+ }
+
+ /*
+ * (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 MyModel(int counter) {
+ this.counter = counter;
+ }
+
+ public String toString() {
+ return "Item " + this.counter;
+ }
+ }
+
+ public Snippet063ComboViewer(Shell shell) {
+
+ GridLayoutFactory.fillDefaults().numColumns(2)
+ .margins(LayoutConstants.getMargins()).generateLayout(shell);
+
+ final Label l = new Label(shell, SWT.None);
+ l.setText("Choose Item:");
+ final ComboViewer v = new ComboViewer(shell);
+ v.setLabelProvider(new LabelProvider());
+ v.setContentProvider(new MyContentProvider());
+
+ MyModel[] model = createModel();
+ v.setInput(model);
+
+ // Select the initial Element
+ if (model.length > 0) {
+ v.setSelection(new StructuredSelection(model[0]));
+ }
+ }
+
+ private MyModel[] createModel() {
+ MyModel[] elements = new MyModel[11];
+
+ for (int i = 0; i < 10; i++) {
+ elements[i] = new MyModel(i);
+ }
+ elements[10] = new MyModel(42);
+
+ return elements;
+ }
+
+ /**
+ * @param args
+ */
+ public static void main(String[] args) {
+ Display display = new Display();
+ Shell shell = new Shell(display);
+ new Snippet063ComboViewer(shell);
+
+ shell.pack();
+ shell.open();
+
+ while (!shell.isDisposed()) {
+ if (!display.readAndDispatch()) {
+ display.sleep();
+ }
+ }
+
+ display.dispose();
+
+ }
+
+}