aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/com/itmill/toolkit/terminal/gwt/client/Util.java15
-rw-r--r--src/com/itmill/toolkit/terminal/gwt/client/ui/IFilterSelect.java38
-rw-r--r--src/com/itmill/toolkit/tests/tickets/Ticket2157.java107
3 files changed, 153 insertions, 7 deletions
diff --git a/src/com/itmill/toolkit/terminal/gwt/client/Util.java b/src/com/itmill/toolkit/terminal/gwt/client/Util.java
index edfae1e55e..d924593964 100644
--- a/src/com/itmill/toolkit/terminal/gwt/client/Util.java
+++ b/src/com/itmill/toolkit/terminal/gwt/client/Util.java
@@ -46,8 +46,8 @@ public class Util {
Map<Container, Set<Paintable>> childWidgets = new HashMap<Container, Set<Paintable>>();
for (Widget widget : widgets) {
-// ApplicationConnection.getConsole().log(
-// "Widget " + Util.getSimpleName(widget) + " size updated");
+ // ApplicationConnection.getConsole().log(
+ // "Widget " + Util.getSimpleName(widget) + " size updated");
Widget parent = widget.getParent();
while (parent != null && !(parent instanceof Container)) {
parent = parent.getParent();
@@ -199,6 +199,9 @@ public class Util {
String originalWidth = DOM.getStyleAttribute(element, "width");
int originalOffsetWidth = element.getOffsetWidth();
int widthGuess = (originalOffsetWidth - paddingGuess);
+ if (widthGuess < 1) {
+ widthGuess = 1;
+ }
DOM.setStyleAttribute(element, "width", widthGuess + "px");
int padding = element.getOffsetWidth() - widthGuess;
@@ -211,9 +214,13 @@ public class Util {
if (BrowserInfo.get().isIE6()) {
String originalWidth = DOM.getStyleAttribute(element, "width");
int originalOffsetWidth = element.getOffsetWidth();
+ if (originalOffsetWidth < 1) {
+ originalOffsetWidth = 10;
+ }
+
DOM.setStyleAttribute(element, "width", originalOffsetWidth + "px");
- borders = element.getOffsetWidth()
- - element.getPropertyInt("clientWidth");
+ int cw = element.getPropertyInt("clientWidth");
+ borders = element.getOffsetWidth() - cw;
DOM.setStyleAttribute(element, "width", originalWidth);
} else {
diff --git a/src/com/itmill/toolkit/terminal/gwt/client/ui/IFilterSelect.java b/src/com/itmill/toolkit/terminal/gwt/client/ui/IFilterSelect.java
index 8e565212ae..8ef567413e 100644
--- a/src/com/itmill/toolkit/terminal/gwt/client/ui/IFilterSelect.java
+++ b/src/com/itmill/toolkit/terminal/gwt/client/ui/IFilterSelect.java
@@ -482,6 +482,8 @@ public class IFilterSelect extends Composite implements Paintable, Field,
// This handles the special case where are not filtering yet and the
// selected value has changed on the server-side. See #2119
private boolean popupOpenerClicked;
+ private String width = null;
+ private int elementPadding = -1;
private static final String CLASSNAME_EMPTY = "empty";
private static final String ATTR_EMPTYTEXT = "emptytext";
@@ -635,6 +637,15 @@ public class IFilterSelect extends Composite implements Paintable, Field,
popupOpenerClicked = false;
+ if (width == null) {
+ /*
+ * When the width is not specified we must specify width for root
+ * div so the popupopener won't wrap to the next line and also so
+ * the size of the combobox won't change over time.
+ */
+ int w = tb.getOffsetWidth() + popupOpener.getOffsetWidth();
+ super.setWidth(w + "px");
+ }
}
public void onSuggestionSelected(FilterSelectSuggestion suggestion) {
@@ -815,11 +826,32 @@ public class IFilterSelect extends Composite implements Paintable, Field,
@Override
public void setWidth(String width) {
+ if (width == null || width.equals("")) {
+ this.width = null;
+ } else {
+ this.width = width;
+ }
+
super.setWidth(width);
- int padding = Util.measureHorizontalPadding(tb.getElement(), 4);
- tb.setWidth((getOffsetWidth() - padding - popupOpener.getOffsetWidth())
- + "px");
+ if (this.width != null) {
+ /*
+ * When the width is specified we also want to explicitly specify
+ * widths for textbox and popupopener
+ */
+ int textboxWidth = getOffsetWidth() - getElementPadding()
+ - popupOpener.getOffsetWidth();
+ if (textboxWidth < 0) {
+ textboxWidth = 0;
+ }
+ tb.setWidth(textboxWidth + "px");
+ }
+ }
+ public int getElementPadding() {
+ if (elementPadding < 0) {
+ elementPadding = Util.measureHorizontalPadding(tb.getElement(), 4);
+ }
+ return elementPadding;
}
}
diff --git a/src/com/itmill/toolkit/tests/tickets/Ticket2157.java b/src/com/itmill/toolkit/tests/tickets/Ticket2157.java
new file mode 100644
index 0000000000..2fd4aef8a2
--- /dev/null
+++ b/src/com/itmill/toolkit/tests/tickets/Ticket2157.java
@@ -0,0 +1,107 @@
+package com.itmill.toolkit.tests.tickets;
+
+import com.itmill.toolkit.Application;
+import com.itmill.toolkit.ui.ComboBox;
+import com.itmill.toolkit.ui.OrderedLayout;
+import com.itmill.toolkit.ui.Panel;
+import com.itmill.toolkit.ui.Window;
+
+public class Ticket2157 extends Application {
+
+ public void init() {
+ Window w = new Window(getClass().getSimpleName());
+ setMainWindow(w);
+ // setTheme("tests-tickets");
+ createUI((OrderedLayout) w.getLayout());
+ }
+
+ private void createUI(OrderedLayout layout) {
+ OrderedLayout ol;
+ Panel p;
+ ComboBox cb;
+
+ ol = new OrderedLayout();
+ p = new Panel(ol);
+ p.setCaption("Combobox without width");
+ // p.setWidth("100px");
+ cb = new ComboBox();
+ // cb.setCaption("A combobox");
+ // cb.setWidth("100%");
+ p.addComponent(cb);
+ layout.addComponent(p);
+
+ ol = new OrderedLayout();
+ p = new Panel(ol);
+ p.setCaption("Combobox without width with caption");
+ // p.setWidth("100px");
+ cb = new ComboBox();
+ cb.setCaption("A combobox");
+ // cb.setWidth("100px");
+ p.addComponent(cb);
+ layout.addComponent(p);
+
+ //
+ ol = new OrderedLayout();
+ p = new Panel(ol);
+ p.setCaption("Combobox 100px wide");
+ // p.setWidth("100px");
+ cb = new ComboBox();
+ // cb.setCaption("A combobox");
+ cb.setWidth("100px");
+ p.addComponent(cb);
+ layout.addComponent(p);
+
+ ol = new OrderedLayout();
+ p = new Panel(ol);
+ p.setCaption("Combobox 100px wide with caption");
+ // p.setWidth("100px");
+ cb = new ComboBox();
+ cb.setCaption("A combobox");
+ cb.setWidth("100px");
+ p.addComponent(cb);
+ layout.addComponent(p);
+
+ ol = new OrderedLayout();
+ p = new Panel(ol);
+ p.setCaption("Combobox 500px wide");
+ // p.setWidth("500px");
+ cb = new ComboBox();
+ // cb.setCaption("A combobox");
+ cb.setWidth("500px");
+ p.addComponent(cb);
+ layout.addComponent(p);
+
+ ol = new OrderedLayout();
+ p = new Panel(ol);
+ p.setCaption("Combobox 500px wide with caption");
+ // p.setWidth("500px");
+ cb = new ComboBox();
+ cb.setCaption("A combobox");
+ cb.setWidth("500px");
+ p.addComponent(cb);
+ layout.addComponent(p);
+
+ ol = new OrderedLayout();
+ p = new Panel(ol);
+ p.setCaption("Combobox 100% wide");
+ p.setWidth("200px");
+ ol.setWidth("100%");
+ cb = new ComboBox();
+ // cb.setCaption("A combobox");
+ cb.setWidth("100%");
+ p.addComponent(cb);
+ layout.addComponent(p);
+
+ ol = new OrderedLayout();
+ p = new Panel(ol);
+ p.setCaption("Combobox 100% wide with caption");
+ p.setWidth("200px");
+ ol.setWidth("100%");
+ cb = new ComboBox();
+ cb.setCaption("A combobox");
+ cb.setWidth("100%");
+ p.addComponent(cb);
+ layout.addComponent(p);
+
+ }
+}