[jbosstools-commits] JBoss Tools SVN: r43699 - in trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui: wizard and 1 other directory.
jbosstools-commits at lists.jboss.org
jbosstools-commits at lists.jboss.org
Fri Sep 14 12:30:16 EDT 2012
Author: adietish
Date: 2012-09-14 12:30:16 -0400 (Fri, 14 Sep 2012)
New Revision: 43699
Added:
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/utils/TableViewerBuilder.java
Modified:
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/ManageSSHKeysWizardPage.java
Log:
[JBIDE-11912] create TableviewerBuilder to reuse table viewer creation code
Added: trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/utils/TableViewerBuilder.java
===================================================================
--- trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/utils/TableViewerBuilder.java (rev 0)
+++ trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/utils/TableViewerBuilder.java 2012-09-14 16:30:16 UTC (rev 43699)
@@ -0,0 +1,101 @@
+/*******************************************************************************
+ * Copyright (c) 2011 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is 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:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.tools.openshift.express.internal.ui.utils;
+
+import org.eclipse.jface.layout.TableColumnLayout;
+import org.eclipse.jface.viewers.CellLabelProvider;
+import org.eclipse.jface.viewers.ColumnWeightData;
+import org.eclipse.jface.viewers.IStructuredContentProvider;
+import org.eclipse.jface.viewers.TableViewer;
+import org.eclipse.jface.viewers.TableViewerColumn;
+import org.eclipse.jface.viewers.ViewerCell;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Table;
+
+/**
+ * @author Andre Dietisheim
+ */
+public class TableViewerBuilder {
+
+ private TableViewer viewer;
+ private TableColumnLayout tableLayout;
+
+ public TableViewerBuilder(Table table, Composite tableContainer) {
+ this(new TableViewer(table), tableContainer);
+ }
+
+ public TableViewerBuilder(TableViewer viewer, Composite tableContainer) {
+ this.viewer = viewer;
+ this.tableLayout = new TableColumnLayout();
+ tableContainer.setLayout(tableLayout);
+ }
+
+ public TableViewerBuilder contentProvider(IStructuredContentProvider contentProvider) {
+ viewer.setContentProvider(contentProvider);
+ return this;
+ }
+
+ public <V> ColumnBuilder<V> column(ICellValueProvider<V> valueProvider) {
+ return new ColumnBuilder<V>(valueProvider);
+ }
+
+ public TableViewer buildViewer() {
+ return viewer;
+ }
+
+ public class ColumnBuilder<E> {
+
+ private int alignement;
+ private ICellValueProvider<E> cellValueProvider;
+ private String name;
+ private int weight;
+
+ private ColumnBuilder(ICellValueProvider<E> valueProvider) {
+ this.cellValueProvider = valueProvider;
+ }
+
+ public ColumnBuilder<E> align(int alignement) {
+ this.alignement = alignement;
+ return this;
+ }
+
+ public ColumnBuilder<E> name(String name) {
+ this.name = name;
+ return this;
+ }
+
+ public ColumnBuilder<E> weight(int weight) {
+ this.weight = weight;
+ return this;
+ }
+
+ public TableViewerBuilder buildColumn() {
+ TableViewerColumn column = new TableViewerColumn(viewer, alignement);
+ column.getColumn().setText(name);
+ column.setLabelProvider(new CellLabelProvider() {
+
+ @Override
+ public void update(ViewerCell cell) {
+ @SuppressWarnings("unchecked")
+ String cellValue = cellValueProvider.getValue((E) cell.getElement());
+ cell.setText(cellValue);
+ }
+ });
+ tableLayout.setColumnData(column.getColumn(), new ColumnWeightData(weight, true));
+ return TableViewerBuilder.this;
+ }
+ }
+
+ public static interface ICellValueProvider<E> {
+ public String getValue(E e);
+ }
+
+}
Property changes on: trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/utils/TableViewerBuilder.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Modified: trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/ManageSSHKeysWizardPage.java
===================================================================
--- trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/ManageSSHKeysWizardPage.java 2012-09-14 16:09:36 UTC (rev 43698)
+++ trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/ManageSSHKeysWizardPage.java 2012-09-14 16:30:16 UTC (rev 43699)
@@ -27,9 +27,6 @@
import org.eclipse.jface.viewers.IElementComparer;
import org.eclipse.jface.viewers.TableViewer;
import org.eclipse.jface.viewers.TableViewerColumn;
-import org.eclipse.jface.viewers.Viewer;
-import org.eclipse.jface.viewers.ViewerCell;
-import org.eclipse.jface.viewers.ViewerSorter;
import org.eclipse.jface.wizard.IWizard;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Button;
@@ -39,6 +36,8 @@
import org.jboss.tools.common.ui.WizardUtils;
import org.jboss.tools.openshift.express.internal.core.console.UserDelegate;
import org.jboss.tools.openshift.express.internal.ui.OpenShiftUIActivator;
+import org.jboss.tools.openshift.express.internal.ui.utils.TableViewerBuilder;
+import org.jboss.tools.openshift.express.internal.ui.utils.TableViewerBuilder.ICellValueProvider;
import com.openshift.client.IOpenShiftSSHKey;
@@ -70,7 +69,7 @@
Composite tableContainer = new Composite(sshKeysGroup, SWT.NONE);
this.viewer = createTable(tableContainer);
GridDataFactory.fillDefaults()
- .span(1, 4).align(SWT.FILL, SWT.FILL).grab(true, true).applyTo(tableContainer);
+ .span(1, 4).align(SWT.FILL, SWT.FILL).hint(500, 260).applyTo(tableContainer);
Button addButton = new Button(sshKeysGroup, SWT.PUSH);
GridDataFactory.fillDefaults()
@@ -92,60 +91,47 @@
Table table =
new Table(tableContainer, SWT.BORDER | SWT.FULL_SELECTION | SWT.V_SCROLL | SWT.H_SCROLL);
table.setLinesVisible(true);
- TableColumnLayout tableLayout = new TableColumnLayout();
- tableContainer.setLayout(tableLayout);
- TableViewer viewer = new TableViewer(table);
- viewer.setComparer(new EqualityComparer());
- viewer.setContentProvider(new ArrayContentProvider());
+ table.setHeaderVisible(true);
+ this.viewer = new TableViewerBuilder(table, tableContainer)
+ .contentProvider(new ArrayContentProvider())
+ .column(new ICellValueProvider<IOpenShiftSSHKey>() {
- viewer.setSorter(new ViewerSorter() {
+ @Override
+ public String getValue(IOpenShiftSSHKey key) {
+ return key.getName();
+ }
+ })
+ .name("Name")
+ .align(SWT.LEFT)
+ .weight(2)
+ .buildColumn()
+ .column(new ICellValueProvider<IOpenShiftSSHKey>() {
- @Override
- public int compare(Viewer viewer, Object thisKey, Object thatKey) {
- if (thisKey instanceof IOpenShiftSSHKey
- && thatKey instanceof IOpenShiftSSHKey) {
- return ((IOpenShiftSSHKey) thisKey).getName().compareTo(((IOpenShiftSSHKey) thatKey).getName());
+ @Override
+ public String getValue(IOpenShiftSSHKey key) {
+ return key.getKeyType().getTypeId();
}
- return super.compare(viewer, thisKey, thatKey);
- }
+ })
+ .name("Type")
+ .align(SWT.LEFT)
+ .weight(1)
+ .buildColumn()
+ .column(new ICellValueProvider<IOpenShiftSSHKey>() {
- });
-
- createTableColumn("Name", 1, new CellLabelProvider() {
-
- @Override
- public void update(ViewerCell cell) {
- IOpenShiftSSHKey key = (IOpenShiftSSHKey) cell.getElement();
- cell.setText(key.getName());
- }
- }, viewer, tableLayout);
- createTableColumn("Type", 1, new CellLabelProvider() {
-
- @Override
- public void update(ViewerCell cell) {
- IOpenShiftSSHKey key = (IOpenShiftSSHKey) cell.getElement();
- cell.setText(key.getKeyType().getTypeId());
- }
- }, viewer, tableLayout);
- createTableColumn("Public Key", 1, new CellLabelProvider() {
-
- @Override
- public void update(ViewerCell cell) {
- IOpenShiftSSHKey key = (IOpenShiftSSHKey) cell.getElement();
- cell.setText(key.getPublicKey());
- }
- }, viewer, tableLayout);
+ @Override
+ public String getValue(IOpenShiftSSHKey key) {
+ return key.getPublicKey();
+ }
+ })
+ .name("Type")
+ .align(SWT.LEFT)
+ .weight(4)
+ .buildColumn()
+ .buildViewer();
+
return viewer;
}
- private void createTableColumn(String name, int weight, CellLabelProvider cellLabelProvider, TableViewer viewer,
- TableColumnLayout layout) {
- TableViewerColumn column = new TableViewerColumn(viewer, SWT.LEFT);
- column.getColumn().setText(name);
- column.setLabelProvider(cellLabelProvider);
- layout.setColumnData(column.getColumn(), new ColumnWeightData(weight, true));
- }
-
@Override
protected void onPageActivated(DataBindingContext dbc) {
try {
More information about the jbosstools-commits
mailing list