aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKristine Jetzke2014-01-06 10:15:44 (EST)
committerGerrit Code Review @ Eclipse.org2014-01-11 11:34:22 (EST)
commitaeb327460488be89e6e71edcce2cb9d0a1dc204b (patch)
tree5db6701071068bf305fead8cc637cbe8198d575b
parentf3de53cbf91d198005fd38a8b92de81bd90a7166 (diff)
downloadorg.eclipse.nebula-aeb327460488be89e6e71edcce2cb9d0a1dc204b.zip
org.eclipse.nebula-aeb327460488be89e6e71edcce2cb9d0a1dc204b.tar.gz
org.eclipse.nebula-aeb327460488be89e6e71edcce2cb9d0a1dc204b.tar.bz2
Bug 268497 - Added example for GridColumnLayoutrefs/changes/13/20313/2
Change-Id: Ie7557a92a12b1ab96cd94d2ac6a4662f3aec1cd5 Signed-off-by: Kristine Jetzke <kristine.jetzke@gmx.de>
-rw-r--r--examples/org.eclipse.nebula.snippets/src/org/eclipse/nebula/snippets/grid/viewer/GridViewerSnippetGridColumnLayout.java101
1 files changed, 101 insertions, 0 deletions
diff --git a/examples/org.eclipse.nebula.snippets/src/org/eclipse/nebula/snippets/grid/viewer/GridViewerSnippetGridColumnLayout.java b/examples/org.eclipse.nebula.snippets/src/org/eclipse/nebula/snippets/grid/viewer/GridViewerSnippetGridColumnLayout.java
new file mode 100644
index 0000000..d8ea84e
--- /dev/null
+++ b/examples/org.eclipse.nebula.snippets/src/org/eclipse/nebula/snippets/grid/viewer/GridViewerSnippetGridColumnLayout.java
@@ -0,0 +1,101 @@
+/*******************************************************************************
+ * Copyright (c) 2014 Kristine Jetzke 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:
+ * Kristine Jetzke - initial implementation
+ *******************************************************************************/
+package org.eclipse.nebula.snippets.grid.viewer;
+
+import org.eclipse.jface.viewers.ArrayContentProvider;
+import org.eclipse.jface.viewers.ColumnLabelProvider;
+import org.eclipse.jface.viewers.ColumnPixelData;
+import org.eclipse.jface.viewers.ColumnWeightData;
+import org.eclipse.nebula.jface.gridviewer.GridColumnLayout;
+import org.eclipse.nebula.jface.gridviewer.GridTableViewer;
+import org.eclipse.nebula.jface.gridviewer.GridViewerColumn;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.layout.FillLayout;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.Shell;
+
+/**
+ * Demonstrates usage of {@link GridColumnLayout}.
+ */
+public class GridViewerSnippetGridColumnLayout {
+
+ public static void main(String[] args) {
+
+ Display display = new Display();
+ Shell shell = new Shell(display);
+ shell.setLayout(new FillLayout(SWT.VERTICAL));
+
+ // 1st table: Columns with column weight
+
+ final Label labelWeight = new Label(shell, SWT.NONE);
+ labelWeight.setText("Grid Column Layout with weights from 1 to 10");
+ Composite compWeight = new Composite(shell, SWT.NONE);
+
+ GridColumnLayout layoutWeight = new GridColumnLayout();
+ compWeight.setLayout(layoutWeight);
+ final GridTableViewer viewerWeight = new GridTableViewer(compWeight,
+ SWT.BORDER | SWT.FULL_SELECTION);
+
+ viewerWeight.getGrid().setHeaderVisible(true);
+ viewerWeight.getGrid().setLinesVisible(true);
+
+ for (int i = 1; i < 11; i++) {
+ GridViewerColumn column = new GridViewerColumn(viewerWeight,
+ SWT.NONE);
+ // Set column data with column weight
+ layoutWeight.setColumnData(column.getColumn(),
+ new ColumnWeightData(i));
+ column.getColumn().setText("Weight: " + i);
+ column.setLabelProvider(new ColumnLabelProvider());
+ }
+
+ viewerWeight.setContentProvider(ArrayContentProvider.getInstance());
+ viewerWeight.setInput(new String[0]);
+
+ // 2nd table: Columns with fixed width in pixel
+
+ final Label labelFixedWidth = new Label(shell, SWT.NONE);
+ labelFixedWidth
+ .setText("Grid Column Layout with widths from 10px to 100 px");
+ Composite compFixedWidth = new Composite(shell, SWT.NONE);
+
+ GridColumnLayout layoutFixedWidth = new GridColumnLayout();
+ compFixedWidth.setLayout(layoutFixedWidth);
+ final GridTableViewer viewerFixedWidth = new GridTableViewer(
+ compFixedWidth, SWT.BORDER | SWT.FULL_SELECTION);
+
+ viewerFixedWidth.getGrid().setHeaderVisible(true);
+ viewerFixedWidth.getGrid().setLinesVisible(true);
+
+ for (int i = 1; i < 11; i++) {
+ GridViewerColumn column = new GridViewerColumn(viewerFixedWidth,
+ SWT.NONE);
+ // Set column data with fixed width in pixel
+ layoutWeight.setColumnData(column.getColumn(), new ColumnPixelData(
+ 10 * i));
+ column.getColumn().setText(10 * i + "px");
+ column.setLabelProvider(new ColumnLabelProvider());
+ }
+
+ viewerFixedWidth.setContentProvider(ArrayContentProvider.getInstance());
+ viewerFixedWidth.setInput(new String[0]);
+
+ shell.setSize(600, 200);
+ shell.open();
+ while (!shell.isDisposed()) {
+ if (!display.readAndDispatch())
+ display.sleep();
+ }
+ display.dispose();
+ }
+}