[jbosstools-commits] JBoss Tools SVN: r43723 - 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 19:23:24 EDT 2012
Author: adietish
Date: 2012-09-14 19:23:24 -0400 (Fri, 14 Sep 2012)
New Revision: 43723
Modified:
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/utils/StringUtils.java
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/wizard/ManageSSHKeysWizardPage.java
Log:
[JBIDE-11912] corrected various layout bugs, added refresh button
Modified: trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/utils/StringUtils.java
===================================================================
--- trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/utils/StringUtils.java 2012-09-14 23:08:35 UTC (rev 43722)
+++ trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/utils/StringUtils.java 2012-09-14 23:23:24 UTC (rev 43723)
@@ -18,7 +18,8 @@
public class StringUtils {
private static final String LINE_SEPARATOR_KEY = "line.separator";
-
+ private static final String SHORTENING_MARKER = "...";
+
public static String null2emptyString(String value) {
if (value != null) {
return value;
@@ -85,4 +86,15 @@
return value == null
|| value.isEmpty();
}
+
+ public static String shorten(String text, int maxLength) {
+ if (text.length() < maxLength) {
+ return text;
+ }
+
+ return new StringBuilder(text.substring(0, maxLength - SHORTENING_MARKER.length()))
+ .append(SHORTENING_MARKER)
+ .toString();
+ }
+
}
Modified: 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 2012-09-14 23:08:35 UTC (rev 43722)
+++ trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/utils/TableViewerBuilder.java 2012-09-14 23:23:24 UTC (rev 43723)
@@ -13,6 +13,7 @@
import org.eclipse.jface.layout.TableColumnLayout;
import org.eclipse.jface.viewers.CellLabelProvider;
import org.eclipse.jface.viewers.ColumnWeightData;
+import org.eclipse.jface.viewers.IElementComparer;
import org.eclipse.jface.viewers.IStructuredContentProvider;
import org.eclipse.jface.viewers.TableViewer;
import org.eclipse.jface.viewers.TableViewerColumn;
@@ -34,6 +35,7 @@
public TableViewerBuilder(TableViewer viewer, Composite tableContainer) {
this.viewer = viewer;
+ viewer.setComparer(new EqualityComparer());
this.tableLayout = new TableColumnLayout();
tableContainer.setLayout(tableLayout);
}
@@ -43,10 +45,19 @@
return this;
}
- public <V> ColumnBuilder<V> column(ICellValueProvider<V> valueProvider) {
- return new ColumnBuilder<V>(valueProvider);
+ public TableViewerBuilder comparer(IElementComparer sorter) {
+ viewer.setComparer(sorter);
+ return this;
}
+ public <E>ColumnBuilder<E> column(String name) {
+ return new ColumnBuilder<E>().name(name);
+ }
+
+ public <E>ColumnBuilder<E> column(IColumnLabelProvider<E> columnLabelProvider) {
+ return new ColumnBuilder<E>().labelProvider(columnLabelProvider);
+ }
+
public TableViewer buildViewer() {
return viewer;
}
@@ -54,13 +65,18 @@
public class ColumnBuilder<E> {
private int alignement;
- private ICellValueProvider<E> cellValueProvider;
+ private IColumnLabelProvider<E> columnLabelProvider;
private String name;
private int weight;
+ private int minWidth = ColumnWeightData.MINIMUM_WIDTH;
- private ColumnBuilder(ICellValueProvider<E> valueProvider) {
- this.cellValueProvider = valueProvider;
+ private ColumnBuilder() {
}
+
+ public ColumnBuilder<E> labelProvider(IColumnLabelProvider<E> labelProvider) {
+ this.columnLabelProvider = labelProvider;
+ return this;
+ }
public ColumnBuilder<E> align(int alignement) {
this.alignement = alignement;
@@ -77,6 +93,11 @@
return this;
}
+ public ColumnBuilder<E> minWidth(int minWidth) {
+ this.minWidth = minWidth;
+ return this;
+ }
+
public TableViewerBuilder buildColumn() {
TableViewerColumn column = new TableViewerColumn(viewer, alignement);
column.getColumn().setText(name);
@@ -85,17 +106,46 @@
@Override
public void update(ViewerCell cell) {
@SuppressWarnings("unchecked")
- String cellValue = cellValueProvider.getValue((E) cell.getElement());
+ String cellValue = columnLabelProvider.getValue((E) cell.getElement());
cell.setText(cellValue);
}
});
- tableLayout.setColumnData(column.getColumn(), new ColumnWeightData(weight, true));
+ tableLayout.setColumnData(column.getColumn(), new ColumnWeightData(weight, minWidth, true));
return TableViewerBuilder.this;
}
}
- public static interface ICellValueProvider<E> {
+ public static interface IColumnLabelProvider<E> {
public String getValue(E e);
}
-
+
+ /**
+ * Viewer element comparer based on #equals(). The default implementation in
+ * CheckboxTableViewer compares elements based on instance identity.
+ * <p>
+ * We need this since the available cartridges (item listed in the viewer)
+ * are not the same instance as the ones in the embedded application (items
+ * to check in the viewer).
+ */
+ public static class EqualityComparer implements IElementComparer {
+
+ @Override
+ public boolean equals(Object thisObject, Object thatObject) {
+ if (thisObject == null) {
+ return thatObject != null;
+ }
+
+ if (thatObject == null) {
+ return false;
+ }
+
+ return thisObject.equals(thatObject);
+ }
+
+ @Override
+ public int hashCode(Object element) {
+ return element.hashCode();
+ }
+ }
+
}
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 23:08:35 UTC (rev 43722)
+++ trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/ManageSSHKeysWizardPage.java 2012-09-14 23:23:24 UTC (rev 43723)
@@ -20,13 +20,9 @@
import org.eclipse.core.runtime.jobs.Job;
import org.eclipse.jface.layout.GridDataFactory;
import org.eclipse.jface.layout.GridLayoutFactory;
-import org.eclipse.jface.layout.TableColumnLayout;
import org.eclipse.jface.viewers.ArrayContentProvider;
-import org.eclipse.jface.viewers.CellLabelProvider;
-import org.eclipse.jface.viewers.ColumnWeightData;
import org.eclipse.jface.viewers.IElementComparer;
import org.eclipse.jface.viewers.TableViewer;
-import org.eclipse.jface.viewers.TableViewerColumn;
import org.eclipse.jface.wizard.IWizard;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Button;
@@ -36,8 +32,9 @@
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.StringUtils;
import org.jboss.tools.openshift.express.internal.ui.utils.TableViewerBuilder;
-import org.jboss.tools.openshift.express.internal.ui.utils.TableViewerBuilder.ICellValueProvider;
+import org.jboss.tools.openshift.express.internal.ui.utils.TableViewerBuilder.IColumnLabelProvider;
import com.openshift.client.IOpenShiftSSHKey;
@@ -62,15 +59,15 @@
Group sshKeysGroup = new Group(parent, SWT.NONE);
sshKeysGroup.setText("SSH Public Keys");
GridDataFactory.fillDefaults()
- .hint(200, 300).align(SWT.FILL, SWT.FILL).grab(true, true).applyTo(sshKeysGroup);
+ .align(SWT.FILL, SWT.FILL).grab(true, true).applyTo(sshKeysGroup);
GridLayoutFactory.fillDefaults()
.numColumns(2).margins(6, 6).applyTo(sshKeysGroup);
Composite tableContainer = new Composite(sshKeysGroup, SWT.NONE);
this.viewer = createTable(tableContainer);
GridDataFactory.fillDefaults()
- .span(1, 4).align(SWT.FILL, SWT.FILL).hint(500, 260).applyTo(tableContainer);
-
+ .span(1, 5).align(SWT.FILL, SWT.FILL).grab(true, true).applyTo(tableContainer);
+
Button addButton = new Button(sshKeysGroup, SWT.PUSH);
GridDataFactory.fillDefaults()
.align(SWT.FILL, SWT.FILL).applyTo(addButton);
@@ -85,50 +82,50 @@
GridDataFactory.fillDefaults()
.align(SWT.FILL, SWT.FILL).applyTo(removeButton);
removeButton.setText("Remove...");
- }
+ Composite filler = new Composite(sshKeysGroup, SWT.None);
+ GridDataFactory.fillDefaults()
+ .align(SWT.FILL, SWT.FILL).applyTo(filler);
+
+ Button refreshButton = new Button(sshKeysGroup, SWT.PUSH);
+ GridDataFactory.fillDefaults()
+ .align(SWT.FILL, SWT.END).applyTo(refreshButton);
+ refreshButton.setText("Refresh...");
+}
+
protected TableViewer createTable(Composite tableContainer) {
Table table =
new Table(tableContainer, SWT.BORDER | SWT.FULL_SELECTION | SWT.V_SCROLL | SWT.H_SCROLL);
table.setLinesVisible(true);
table.setHeaderVisible(true);
this.viewer = new TableViewerBuilder(table, tableContainer)
- .contentProvider(new ArrayContentProvider())
- .column(new ICellValueProvider<IOpenShiftSSHKey>() {
+ .contentProvider(new ArrayContentProvider())
+ .column(new IColumnLabelProvider<IOpenShiftSSHKey>() {
- @Override
- public String getValue(IOpenShiftSSHKey key) {
- return key.getName();
- }
- })
- .name("Name")
- .align(SWT.LEFT)
- .weight(2)
- .buildColumn()
- .column(new ICellValueProvider<IOpenShiftSSHKey>() {
+ @Override
+ public String getValue(IOpenShiftSSHKey key) {
+ return key.getName();
+ }
+ })
+ .name("Name").align(SWT.LEFT).weight(2).minWidth(200).buildColumn()
+ .column(new IColumnLabelProvider<IOpenShiftSSHKey>() {
- @Override
- public String getValue(IOpenShiftSSHKey key) {
- return key.getKeyType().getTypeId();
- }
- })
- .name("Type")
- .align(SWT.LEFT)
- .weight(1)
- .buildColumn()
- .column(new ICellValueProvider<IOpenShiftSSHKey>() {
+ @Override
+ public String getValue(IOpenShiftSSHKey key) {
+ return key.getKeyType().getTypeId();
+ }
+ })
+ .name("Type").align(SWT.LEFT).weight(1).minWidth(50).buildColumn()
+ .column(new IColumnLabelProvider<IOpenShiftSSHKey>() {
- @Override
- public String getValue(IOpenShiftSSHKey key) {
- return key.getPublicKey();
- }
- })
- .name("Type")
- .align(SWT.LEFT)
- .weight(4)
- .buildColumn()
- .buildViewer();
-
+ @Override
+ public String getValue(IOpenShiftSSHKey key) {
+ return StringUtils.shorten(key.getPublicKey(), 24);
+ }
+ })
+ .name("Type").align(SWT.LEFT).weight(4).minWidth(100).buildColumn()
+ .buildViewer();
+
return viewer;
}
@@ -168,33 +165,4 @@
}
});
}
-
- /**
- * Viewer element comparer based on #equals(). The default implementation in
- * CheckboxTableViewer compares elements based on instance identity.
- * <p>
- * We need this since the available cartridges (item listed in the viewer)
- * are not the same instance as the ones in the embedded application (items
- * to check in the viewer).
- */
- private static class EqualityComparer implements IElementComparer {
-
- @Override
- public boolean equals(Object thisObject, Object thatObject) {
- if (thisObject == null) {
- return thatObject != null;
- }
-
- if (thatObject == null) {
- return false;
- }
-
- return thisObject.equals(thatObject);
- }
-
- @Override
- public int hashCode(Object element) {
- return element.hashCode();
- }
- }
}
\ No newline at end of file
More information about the jbosstools-commits
mailing list