From 36a201f22f66989bf7a78ce8afce1ee64aaa0a22 Mon Sep 17 00:00:00 2001 From: Artur Signell Date: Wed, 6 Mar 2013 14:55:15 +0200 Subject: Fixed focus and tab index handling for UI (#11129) Change-Id: I80377792ade11946337e2900a7ea84209ae1d060 --- .../com/vaadin/tests/components/ui/UITabIndex.html | 57 ++++++++++++++++++++++ .../com/vaadin/tests/components/ui/UITabIndex.java | 51 +++++++++++++++++++ 2 files changed, 108 insertions(+) create mode 100644 uitest/src/com/vaadin/tests/components/ui/UITabIndex.html create mode 100644 uitest/src/com/vaadin/tests/components/ui/UITabIndex.java (limited to 'uitest/src/com/vaadin/tests') diff --git a/uitest/src/com/vaadin/tests/components/ui/UITabIndex.html b/uitest/src/com/vaadin/tests/components/ui/UITabIndex.html new file mode 100644 index 0000000000..fa083f1489 --- /dev/null +++ b/uitest/src/com/vaadin/tests/components/ui/UITabIndex.html @@ -0,0 +1,57 @@ + + + + + + +New Test + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
New Test
open/run/com.vaadin.tests.components.ui.UITabIndex?restartApplication
assertAttributevaadin=runcomvaadintestscomponentsuiUITabIndex::@tabIndex1
clickvaadin=runcomvaadintestscomponentsuiUITabIndex::/VVerticalLayout[0]/Slot[1]/VVerticalLayout[0]/Slot[0]/VButton[0]/domChild[0]/domChild[0]
assertAttributevaadin=runcomvaadintestscomponentsuiUITabIndex::@tabIndex-1
clickvaadin=runcomvaadintestscomponentsuiUITabIndex::/VVerticalLayout[0]/Slot[1]/VVerticalLayout[0]/Slot[1]/VButton[0]/domChild[0]/domChild[0]
assertAttributevaadin=runcomvaadintestscomponentsuiUITabIndex::@tabIndex0
clickvaadin=runcomvaadintestscomponentsuiUITabIndex::/VVerticalLayout[0]/Slot[1]/VVerticalLayout[0]/Slot[2]/VButton[0]/domChild[0]/domChild[0]
assertAttributevaadin=runcomvaadintestscomponentsuiUITabIndex::@tabIndex1
+ + diff --git a/uitest/src/com/vaadin/tests/components/ui/UITabIndex.java b/uitest/src/com/vaadin/tests/components/ui/UITabIndex.java new file mode 100644 index 0000000000..083eaf3f7d --- /dev/null +++ b/uitest/src/com/vaadin/tests/components/ui/UITabIndex.java @@ -0,0 +1,51 @@ +package com.vaadin.tests.components.ui; + +import com.vaadin.server.VaadinRequest; +import com.vaadin.tests.components.AbstractTestUI; +import com.vaadin.ui.Button; +import com.vaadin.ui.Button.ClickEvent; +import com.vaadin.ui.Button.ClickListener; + +public class UITabIndex extends AbstractTestUI { + + @Override + protected void setup(VaadinRequest request) { + Button b; + + b = new Button("Set tabIndex to -1"); + b.addClickListener(new ClickListener() { + @Override + public void buttonClick(ClickEvent event) { + setTabIndex(-1); + } + }); + addComponent(b); + b = new Button("Set tabIndex to 0"); + b.addClickListener(new ClickListener() { + @Override + public void buttonClick(ClickEvent event) { + setTabIndex(0); + } + }); + addComponent(b); + b = new Button("Set tabIndex to 1"); + b.addClickListener(new ClickListener() { + @Override + public void buttonClick(ClickEvent event) { + setTabIndex(1); + } + }); + addComponent(b); + } + + @Override + protected String getTestDescription() { + return "Tests tab index handling for UI"; + } + + @Override + protected Integer getTicketNumber() { + return 11129; + } + +} -- cgit v1.2.3 From 5cba827316eed64508ffb254edb95f303f44eab9 Mon Sep 17 00:00:00 2001 From: Artur Signell Date: Wed, 13 Mar 2013 11:14:24 +0200 Subject: Fixed client-server value sync problem in CheckBox (#11028) Change-Id: I1bac8e8a746bcc97b3ce929e76cf3476ad793bf6 --- server/src/com/vaadin/ui/CheckBox.java | 17 +++++ .../tests/components/AbstractTestUIWithLog.java | 36 ++++++++++ .../checkbox/CheckBoxRevertValueChange.html | 82 ++++++++++++++++++++++ .../checkbox/CheckBoxRevertValueChange.java | 65 +++++++++++++++++ 4 files changed, 200 insertions(+) create mode 100644 uitest/src/com/vaadin/tests/components/AbstractTestUIWithLog.java create mode 100644 uitest/src/com/vaadin/tests/components/checkbox/CheckBoxRevertValueChange.html create mode 100644 uitest/src/com/vaadin/tests/components/checkbox/CheckBoxRevertValueChange.java (limited to 'uitest/src/com/vaadin/tests') diff --git a/server/src/com/vaadin/ui/CheckBox.java b/server/src/com/vaadin/ui/CheckBox.java index 0ace0a4f26..ac33f5e410 100644 --- a/server/src/com/vaadin/ui/CheckBox.java +++ b/server/src/com/vaadin/ui/CheckBox.java @@ -16,6 +16,8 @@ package com.vaadin.ui; +import org.json.JSONException; + import com.vaadin.data.Property; import com.vaadin.event.FieldEvents.BlurEvent; import com.vaadin.event.FieldEvents.BlurListener; @@ -37,6 +39,21 @@ public class CheckBox extends AbstractField { return; } + /* + * Client side updates the state before sending the event so we need + * to make sure the cached state is updated to match the client. If + * we do not do this, a reverting setValue() call in a listener will + * not cause the new state to be sent to the client. + * + * See #11028, #10030. + */ + try { + getUI().getConnectorTracker().getDiffState(CheckBox.this) + .put("checked", checked); + } catch (JSONException e) { + throw new RuntimeException(e); + } + final Boolean oldValue = getValue(); final Boolean newValue = checked; diff --git a/uitest/src/com/vaadin/tests/components/AbstractTestUIWithLog.java b/uitest/src/com/vaadin/tests/components/AbstractTestUIWithLog.java new file mode 100644 index 0000000000..cace7c3404 --- /dev/null +++ b/uitest/src/com/vaadin/tests/components/AbstractTestUIWithLog.java @@ -0,0 +1,36 @@ +/* + * Copyright 2000-2013 Vaadin Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ +package com.vaadin.tests.components; + +import com.vaadin.server.VaadinRequest; +import com.vaadin.tests.util.Log; +import com.vaadin.ui.VerticalLayout; + +public abstract class AbstractTestUIWithLog extends AbstractTestUI { + + protected Log log = new Log(5); + + @Override + public void init(VaadinRequest request) { + super.init(request); + ((VerticalLayout) getContent()).addComponent(log, 0); + } + + protected void log(String message) { + log.log(message); + } + +} diff --git a/uitest/src/com/vaadin/tests/components/checkbox/CheckBoxRevertValueChange.html b/uitest/src/com/vaadin/tests/components/checkbox/CheckBoxRevertValueChange.html new file mode 100644 index 0000000000..ea5849f99f --- /dev/null +++ b/uitest/src/com/vaadin/tests/components/checkbox/CheckBoxRevertValueChange.html @@ -0,0 +1,82 @@ + + + + + + +New Test + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
New Test
open/run/com.vaadin.tests.components.checkbox.CheckBoxRevertValueChange?restartApplication
mouseClickvaadin=runcomvaadintestscomponentscheckboxCheckBoxRevertValueChange::/VVerticalLayout[0]/Slot[2]/VVerticalLayout[0]/Slot[0]/VCheckBox[0]/domChild[0]10,5
assertTextvaadin=runcomvaadintestscomponentscheckboxCheckBoxRevertValueChange::PID_SLog_row_01. I said no checking!
assertValuevaadin=runcomvaadintestscomponentscheckboxCheckBoxRevertValueChange::/VVerticalLayout[0]/Slot[2]/VVerticalLayout[0]/Slot[0]/VCheckBox[0]/domChild[0]off
mouseClickvaadin=runcomvaadintestscomponentscheckboxCheckBoxRevertValueChange::/VVerticalLayout[0]/Slot[2]/VVerticalLayout[0]/Slot[0]/VCheckBox[0]/domChild[1]93,10
assertTextvaadin=runcomvaadintestscomponentscheckboxCheckBoxRevertValueChange::PID_SLog_row_02. I said no checking!
assertValuevaadin=runcomvaadintestscomponentscheckboxCheckBoxRevertValueChange::/VVerticalLayout[0]/Slot[2]/VVerticalLayout[0]/Slot[0]/VCheckBox[0]/domChild[0]off
mouseClickvaadin=runcomvaadintestscomponentscheckboxCheckBoxRevertValueChange::/VVerticalLayout[0]/Slot[2]/VVerticalLayout[0]/Slot[1]/VCheckBox[0]/domChild[0]5,8
assertTextvaadin=runcomvaadintestscomponentscheckboxCheckBoxRevertValueChange::PID_SLog_row_03. I said no unchecking!
assertValuevaadin=runcomvaadintestscomponentscheckboxCheckBoxRevertValueChange::/VVerticalLayout[0]/Slot[2]/VVerticalLayout[0]/Slot[1]/VCheckBox[0]/domChild[0]on
mouseClickvaadin=runcomvaadintestscomponentscheckboxCheckBoxRevertValueChange::/VVerticalLayout[0]/Slot[2]/VVerticalLayout[0]/Slot[1]/VCheckBox[0]/domChild[1]78,12
assertTextvaadin=runcomvaadintestscomponentscheckboxCheckBoxRevertValueChange::PID_SLog_row_04. I said no unchecking!
assertValuevaadin=runcomvaadintestscomponentscheckboxCheckBoxRevertValueChange::/VVerticalLayout[0]/Slot[2]/VVerticalLayout[0]/Slot[1]/VCheckBox[0]/domChild[0]on
+ + diff --git a/uitest/src/com/vaadin/tests/components/checkbox/CheckBoxRevertValueChange.java b/uitest/src/com/vaadin/tests/components/checkbox/CheckBoxRevertValueChange.java new file mode 100644 index 0000000000..5b086fb935 --- /dev/null +++ b/uitest/src/com/vaadin/tests/components/checkbox/CheckBoxRevertValueChange.java @@ -0,0 +1,65 @@ +/* + * Copyright 2000-2013 Vaadin Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ +package com.vaadin.tests.components.checkbox; + +import com.vaadin.annotations.PreserveOnRefresh; +import com.vaadin.data.Property; +import com.vaadin.server.VaadinRequest; +import com.vaadin.tests.components.AbstractTestUIWithLog; +import com.vaadin.ui.CheckBox; + +@PreserveOnRefresh +public class CheckBoxRevertValueChange extends AbstractTestUIWithLog { + + @Override + protected void setup(VaadinRequest request) { + final CheckBox alwaysUnchecked = new CheckBox("You may not check me"); + alwaysUnchecked + .addValueChangeListener(new Property.ValueChangeListener() { + public void valueChange(Property.ValueChangeEvent event) { + if (alwaysUnchecked.getValue()) { + log("I said no checking!"); + alwaysUnchecked.setValue(false); + } + } + }); + final CheckBox alwaysChecked = new CheckBox("You may not uncheck me"); + alwaysChecked.setValue(true); + alwaysChecked + .addValueChangeListener(new Property.ValueChangeListener() { + public void valueChange(Property.ValueChangeEvent event) { + if (!alwaysChecked.getValue()) { + log("I said no unchecking!"); + alwaysChecked.setValue(true); + } + } + }); + + addComponent(alwaysUnchecked); + addComponent(alwaysChecked); + } + + @Override + protected String getTestDescription() { + return "Ensure checking of a checkbox can be reverted on the server side without making the client go out of sync"; + } + + @Override + protected Integer getTicketNumber() { + return 11028; + } + +} -- cgit v1.2.3 From d2d4279e9946f9b193c0b706ecad9e01a5bf77c3 Mon Sep 17 00:00:00 2001 From: Leif Åstrand Date: Wed, 13 Mar 2013 09:50:41 +0200 Subject: Fixed setting column width back to undefined by setting it to -1. #7922 svn changeset:25591/svn branch:6.8 Conflicts: server/src/com/vaadin/ui/Table.java Reverted change included by mistake in changeset [25591] for #7922 svn changeset:25606/svn branch:6.8 Change-Id: I6765a52ab213c131cca053227ee72b0007552f7f --- client/src/com/vaadin/client/ui/VScrollTable.java | 24 +++++-- server/src/com/vaadin/ui/Table.java | 71 ++++++++++++------ .../table/TableColumnWidthsAndExpandRatios.html | 83 ++++++++++++++++++++++ .../table/TableColumnWidthsAndExpandRatios.java | 57 +++++++++++++++ 4 files changed, 208 insertions(+), 27 deletions(-) create mode 100644 uitest/src/com/vaadin/tests/components/table/TableColumnWidthsAndExpandRatios.html create mode 100644 uitest/src/com/vaadin/tests/components/table/TableColumnWidthsAndExpandRatios.java (limited to 'uitest/src/com/vaadin/tests') diff --git a/client/src/com/vaadin/client/ui/VScrollTable.java b/client/src/com/vaadin/client/ui/VScrollTable.java index 6f9fd6da88..4d61fba429 100644 --- a/client/src/com/vaadin/client/ui/VScrollTable.java +++ b/client/src/com/vaadin/client/ui/VScrollTable.java @@ -3056,7 +3056,7 @@ public class VScrollTable extends FlowPanel implements HasWidgets, .hasNext(); columnIndex++) { if (it.next() == this) { break; - } + } } } final int cw = scrollBody.getColWidth(columnIndex); @@ -3266,10 +3266,9 @@ public class VScrollTable extends FlowPanel implements HasWidgets, } if (col.hasAttribute("width")) { - final String widthStr = col.getStringAttribute("width"); // Make sure to accomodate for the sort indicator if // necessary. - int width = Integer.parseInt(widthStr); + int width = col.getIntAttribute("width"); int widthWithoutAddedIndent = width; // get min width with indent, no padding @@ -3301,12 +3300,25 @@ public class VScrollTable extends FlowPanel implements HasWidgets, // save min width without indent c.setWidth(widthWithoutAddedIndent, true); } + } else if (col.hasAttribute("er")) { + c.setExpandRatio(col.getFloatAttribute("er")); + } else if (recalcWidths) { c.setUndefinedWidth(); + + } else { + boolean hadExpandRatio = c.getExpandRatio() > 0; + boolean hadDefinedWidth = c.isDefinedWidth(); + if (hadExpandRatio || hadDefinedWidth) { + // Someone has removed a expand width or the defined + // width on the server side (setting it to -1), make the + // column undefined again and measure columns again. + c.setUndefinedWidth(); + c.setExpandRatio(0); + refreshContentWidths = true; + } } - if (col.hasAttribute("er")) { - c.setExpandRatio(col.getFloatAttribute("er")); - } + if (col.hasAttribute("collapsed")) { // ensure header is properly removed from parent (case when // collapsing happens via servers side api) diff --git a/server/src/com/vaadin/ui/Table.java b/server/src/com/vaadin/ui/Table.java index 641c0ff1f6..3d7cb42050 100644 --- a/server/src/com/vaadin/ui/Table.java +++ b/server/src/com/vaadin/ui/Table.java @@ -396,10 +396,14 @@ public class Table extends AbstractSelect implements Action.Container, private HashMap columnAlignments = new HashMap(); /** - * Holds column widths in pixels (Integer) or expand ratios (Float) for - * visible columns (by propertyId). + * Holds column widths in pixels for visible columns (by propertyId). */ - private final HashMap columnWidths = new HashMap(); + private final HashMap columnWidths = new HashMap(); + + /** + * Holds column expand rations for visible columns (by propertyId). + */ + private final HashMap columnExpandRatios = new HashMap(); /** * Holds column generators @@ -886,10 +890,14 @@ public class Table extends AbstractSelect implements Action.Container, // id to store the width of the row header. propertyId = ROW_HEADER_FAKE_PROPERTY_ID; } + + // Setting column width should remove any expand ratios as well + columnExpandRatios.remove(propertyId); + if (width < 0) { columnWidths.remove(propertyId); } else { - columnWidths.put(propertyId, Integer.valueOf(width)); + columnWidths.put(propertyId, width); } markAsDirty(); } @@ -930,21 +938,39 @@ public class Table extends AbstractSelect implements Action.Container, * the expandRatio used to divide excess space for this column */ public void setColumnExpandRatio(Object propertyId, float expandRatio) { + if (propertyId == null) { + // Since propertyId is null, this is the row header. Use the magic + // id to store the width of the row header. + propertyId = ROW_HEADER_FAKE_PROPERTY_ID; + } + + // Setting the column expand ratio should remove and defined column + // width + columnWidths.remove(propertyId); + if (expandRatio < 0) { - columnWidths.remove(propertyId); + columnExpandRatios.remove(propertyId); } else { - columnWidths.put(propertyId, new Float(expandRatio)); + columnExpandRatios.put(propertyId, expandRatio); } + + requestRepaint(); } + /** + * Gets the column expand ratio for a columnd. See + * {@link #setColumnExpandRatio(Object, float)} + * + * @param propertyId + * columns property id + * @return the expandRatio used to divide excess space for this column + */ public float getColumnExpandRatio(Object propertyId) { - final Object width = columnWidths.get(propertyId); - if (width == null || !(width instanceof Float)) { + final Float width = columnExpandRatios.get(propertyId); + if (width == null) { return -1; } - final Float value = (Float) width; - return value.floatValue(); - + return width.floatValue(); } /** @@ -959,12 +985,11 @@ public class Table extends AbstractSelect implements Action.Container, // id to retrieve the width of the row header. propertyId = ROW_HEADER_FAKE_PROPERTY_ID; } - final Object width = columnWidths.get(propertyId); - if (width == null || !(width instanceof Integer)) { + final Integer width = columnWidths.get(propertyId); + if (width == null) { return -1; } - final Integer value = (Integer) width; - return value.intValue(); + return width.intValue(); } /** @@ -3434,6 +3459,7 @@ public class Table extends AbstractSelect implements Action.Container, target.startTag("column"); target.addAttribute("cid", ROW_HEADER_COLUMN_KEY); paintColumnWidth(target, ROW_HEADER_FAKE_PROPERTY_ID); + paintColumnExpandRatio(target, ROW_HEADER_FAKE_PROPERTY_ID); target.endTag("column"); } final Collection sortables = getSortableContainerPropertyIds(); @@ -3461,6 +3487,7 @@ public class Table extends AbstractSelect implements Action.Container, .toString()); } paintColumnWidth(target, colId); + paintColumnExpandRatio(target, colId); target.endTag("column"); } } @@ -3706,12 +3733,14 @@ public class Table extends AbstractSelect implements Action.Container, private void paintColumnWidth(PaintTarget target, final Object columnId) throws PaintException { if (columnWidths.containsKey(columnId)) { - if (getColumnWidth(columnId) > -1) { - target.addAttribute("width", - String.valueOf(getColumnWidth(columnId))); - } else { - target.addAttribute("er", getColumnExpandRatio(columnId)); - } + target.addAttribute("width", getColumnWidth(columnId)); + } + } + + private void paintColumnExpandRatio(PaintTarget target, + final Object columnId) throws PaintException { + if (columnExpandRatios.containsKey(columnId)) { + target.addAttribute("er", getColumnExpandRatio(columnId)); } } diff --git a/uitest/src/com/vaadin/tests/components/table/TableColumnWidthsAndExpandRatios.html b/uitest/src/com/vaadin/tests/components/table/TableColumnWidthsAndExpandRatios.html new file mode 100644 index 0000000000..75d98ce2e6 --- /dev/null +++ b/uitest/src/com/vaadin/tests/components/table/TableColumnWidthsAndExpandRatios.html @@ -0,0 +1,83 @@ + + + + + + +New Test + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
New Test
open/run/com.vaadin.tests.components.table.TableColumnWidthsAndExpandRatios?restartApplication
screenCaptureinitial-all-columns-undefined
dragAndDropvaadin=runcomvaadintestscomponentstableTableColumnWidthsAndExpandRatios::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[0]/VScrollTable[0]/domChild[0]/domChild[0]/domChild[0]/domChild[0]/domChild[0]/domChild[0]/domChild[0]/domChild[0]-300,0
dragAndDropvaadin=runcomvaadintestscomponentstableTableColumnWidthsAndExpandRatios::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[0]/VScrollTable[0]/domChild[0]/domChild[0]/domChild[0]/domChild[0]/domChild[0]/domChild[0]/domChild[1]/domChild[0]-300,0
dragAndDropvaadin=runcomvaadintestscomponentstableTableColumnWidthsAndExpandRatios::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[0]/VScrollTable[0]/domChild[0]/domChild[0]/domChild[0]/domChild[0]/domChild[0]/domChild[0]/domChild[2]/domChild[0]-300,0
screenCapturecolumns-defined-width
mouseClickvaadin=runcomvaadintestscomponentstableTableColumnWidthsAndExpandRatios::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[1]/VHorizontalLayout[0]/ChildComponentContainer[0]/VNativeButton[0]114,4
screenCapturecolumn1-undefined
mouseClickvaadin=runcomvaadintestscomponentstableTableColumnWidthsAndExpandRatios::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[1]/VHorizontalLayout[0]/ChildComponentContainer[1]/VNativeButton[0]98,13
screenCapturecolumn2-undefined
mouseClickvaadin=runcomvaadintestscomponentstableTableColumnWidthsAndExpandRatios::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[1]/VHorizontalLayout[0]/ChildComponentContainer[2]/VNativeButton[0]40,10
screenCapturecolumns-undefined-width
+ + diff --git a/uitest/src/com/vaadin/tests/components/table/TableColumnWidthsAndExpandRatios.java b/uitest/src/com/vaadin/tests/components/table/TableColumnWidthsAndExpandRatios.java new file mode 100644 index 0000000000..747c99468f --- /dev/null +++ b/uitest/src/com/vaadin/tests/components/table/TableColumnWidthsAndExpandRatios.java @@ -0,0 +1,57 @@ +package com.vaadin.tests.components.table; + +import com.vaadin.tests.components.TestBase; +import com.vaadin.ui.Button; +import com.vaadin.ui.Button.ClickEvent; +import com.vaadin.ui.HorizontalLayout; +import com.vaadin.ui.NativeButton; +import com.vaadin.ui.Table; + +public class TableColumnWidthsAndExpandRatios extends TestBase { + + @Override + protected void setup() { + getLayout().setSizeFull(); + + final Table table = new Table(); + table.setSizeFull(); + + table.addContainerProperty("column1", String.class, "Humpty"); + table.addContainerProperty("column2", String.class, "Dumpty"); + table.addContainerProperty("column3", String.class, "Doe"); + + for (int row = 0; row < 100; row++) { + table.addItem(); + } + + HorizontalLayout buttons = new HorizontalLayout(); + for (Object col : table.getContainerPropertyIds()) { + buttons.addComponent(createResetButton(col, table)); + } + + addComponent(table); + addComponent(buttons); + } + + private NativeButton createResetButton(final Object property, + final Table table) { + return new NativeButton("Reset " + property + " width", + new Button.ClickListener() { + + public void buttonClick(ClickEvent event) { + table.setColumnWidth(property, -1); + } + }); + } + + @Override + protected String getDescription() { + return "Changing column width to -1 should remove any previous size measurements"; + } + + @Override + protected Integer getTicketNumber() { + return 7922; + } + +} -- cgit v1.2.3 From 781fc2a5e8e213b4d135de13c9b1c2a185eec025 Mon Sep 17 00:00:00 2001 From: Artur Signell Date: Thu, 14 Mar 2013 16:30:31 +0200 Subject: Deprecated TestBase to avoid new tests which are LegacyApplications Change-Id: Ic4bc242b6d2707e7a856256ca7eeddc4efd9eb83 --- uitest/src/com/vaadin/tests/components/TestBase.java | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'uitest/src/com/vaadin/tests') diff --git a/uitest/src/com/vaadin/tests/components/TestBase.java b/uitest/src/com/vaadin/tests/components/TestBase.java index d267d80669..15f39f6e5d 100644 --- a/uitest/src/com/vaadin/tests/components/TestBase.java +++ b/uitest/src/com/vaadin/tests/components/TestBase.java @@ -6,6 +6,12 @@ import com.vaadin.ui.Label; import com.vaadin.ui.LegacyWindow; import com.vaadin.ui.VerticalLayout; +/** + * + * @deprecated Use {@link AbstractTestUI} or {@link AbstractTestUIWithLog} + * instead. TestBase is a LegacyApplication + */ +@Deprecated public abstract class TestBase extends AbstractTestCase { @Override -- cgit v1.2.3 From f7b9f9f9afe8b09571d05f1790c9fe0c68a363a9 Mon Sep 17 00:00:00 2001 From: Marc Englund Date: Thu, 14 Mar 2013 14:21:53 +0200 Subject: Audio/Video fixes, for #11160 but it was much more broken. Also quite a few browser differences. Ticket: 11160 Change-Id: I1ee228e593eab75d96c285bfa26af9939e058d47 --- .../com/vaadin/client/ui/MediaBaseConnector.java | 25 ++++-- client/src/com/vaadin/client/ui/VMediaBase.java | 26 ++++++- .../com/vaadin/client/ui/audio/AudioConnector.java | 48 ++++++++---- .../vaadin/tests/components/media/AudioTest.html | 66 ++++++++++++++++ .../vaadin/tests/components/media/AudioTest.java | 86 +++++++++++++++++++++ .../src/com/vaadin/tests/components/media/bip.mp3 | Bin 0 -> 13837 bytes .../src/com/vaadin/tests/components/media/bip.ogg | Bin 0 -> 15137 bytes .../tests/components/media/toyphone_dialling.mp3 | Bin 0 -> 80083 bytes .../tests/components/media/toyphone_dialling.ogg | Bin 0 -> 77861 bytes 9 files changed, 225 insertions(+), 26 deletions(-) create mode 100644 uitest/src/com/vaadin/tests/components/media/AudioTest.html create mode 100644 uitest/src/com/vaadin/tests/components/media/AudioTest.java create mode 100644 uitest/src/com/vaadin/tests/components/media/bip.mp3 create mode 100644 uitest/src/com/vaadin/tests/components/media/bip.ogg create mode 100644 uitest/src/com/vaadin/tests/components/media/toyphone_dialling.mp3 create mode 100644 uitest/src/com/vaadin/tests/components/media/toyphone_dialling.ogg (limited to 'uitest/src/com/vaadin/tests') diff --git a/client/src/com/vaadin/client/ui/MediaBaseConnector.java b/client/src/com/vaadin/client/ui/MediaBaseConnector.java index 6824caff78..8614977be1 100644 --- a/client/src/com/vaadin/client/ui/MediaBaseConnector.java +++ b/client/src/com/vaadin/client/ui/MediaBaseConnector.java @@ -46,15 +46,26 @@ public abstract class MediaBaseConnector extends AbstractComponentConnector { } @Override - public void onStateChanged(StateChangeEvent stateChangeEvent) { - super.onStateChanged(stateChangeEvent); + public void onStateChanged(StateChangeEvent event) { + super.onStateChanged(event); - for (int i = 0; i < getState().sources.size(); i++) { - URLReference source = getState().sources.get(i); - String sourceType = getState().sourceTypes.get(i); - getWidget().addSource(source.getURL(), sourceType); + final VMediaBase widget = getWidget(); + final AbstractMediaState state = getState(); + + setAltText(state.altText); // must do before loading sources + widget.setAutoplay(state.autoplay); + widget.setMuted(state.muted); + widget.setControls(state.showControls); + + if (event.hasPropertyChanged("sources")) { + widget.removeAllSources(); + for (int i = 0; i < state.sources.size(); i++) { + URLReference source = state.sources.get(i); + String sourceType = state.sourceTypes.get(i); + widget.addSource(source.getURL(), sourceType); + } + widget.load(); } - setAltText(getState().altText); } @Override diff --git a/client/src/com/vaadin/client/ui/VMediaBase.java b/client/src/com/vaadin/client/ui/VMediaBase.java index 8d40775c8d..b77e8bb161 100644 --- a/client/src/com/vaadin/client/ui/VMediaBase.java +++ b/client/src/com/vaadin/client/ui/VMediaBase.java @@ -18,12 +18,16 @@ package com.vaadin.client.ui; import com.google.gwt.dom.client.Document; import com.google.gwt.dom.client.MediaElement; +import com.google.gwt.dom.client.NodeList; +import com.google.gwt.dom.client.SourceElement; +import com.google.gwt.dom.client.Text; import com.google.gwt.user.client.Element; import com.google.gwt.user.client.ui.Widget; public abstract class VMediaBase extends Widget { private MediaElement media; + private Text altText; /** * Sets the MediaElement that is to receive all commands and properties. @@ -44,7 +48,12 @@ public abstract class VMediaBase extends Widget { } public void setAltText(String alt) { - media.appendChild(Document.get().createTextNode(alt)); + if (altText == null) { + altText = Document.get().createTextNode(alt); + media.appendChild(altText); + } else { + altText.setNodeValue(alt); + } } public void setControls(boolean shouldShowControls) { @@ -59,8 +68,21 @@ public abstract class VMediaBase extends Widget { media.setMuted(mediaMuted); } + public void removeAllSources() { + NodeList l = media + .getElementsByTagName(SourceElement.TAG); + for (int i = l.getLength() - 1; i >= 0; i--) { + media.removeChild(l.getItem(i)); + } + + } + + public void load() { + media.load(); + } + public void addSource(String sourceUrl, String sourceType) { - Element src = Document.get().createElement("source").cast(); + Element src = Document.get().createElement(SourceElement.TAG).cast(); src.setAttribute("src", sourceUrl); src.setAttribute("type", sourceType); media.appendChild(src); diff --git a/client/src/com/vaadin/client/ui/audio/AudioConnector.java b/client/src/com/vaadin/client/ui/audio/AudioConnector.java index c7d20ef585..5a90cab09d 100644 --- a/client/src/com/vaadin/client/ui/audio/AudioConnector.java +++ b/client/src/com/vaadin/client/ui/audio/AudioConnector.java @@ -29,23 +29,6 @@ import com.vaadin.ui.Audio; @Connect(Audio.class) public class AudioConnector extends MediaBaseConnector { - @Override - public void onStateChanged(StateChangeEvent stateChangeEvent) { - super.onStateChanged(stateChangeEvent); - - Style style = getWidget().getElement().getStyle(); - - // Make sure that the controls are not clipped if visible. - if (getState().showControls - && (style.getHeight() == null || "".equals(style.getHeight()))) { - if (BrowserInfo.get().isChrome()) { - style.setHeight(32, Unit.PX); - } else { - style.setHeight(25, Unit.PX); - } - } - } - @Override protected Widget createWidget() { return GWT.create(VAudio.class); @@ -55,4 +38,35 @@ public class AudioConnector extends MediaBaseConnector { protected String getDefaultAltHtml() { return "Your browser does not support the audio element."; } + + @Override + public void onStateChanged(StateChangeEvent stateChangeEvent) { + super.onStateChanged(stateChangeEvent); + + // Opera (12.14) has a bug where an audio element w/o controls is shown + // as 150x300px, which is not usually desired. However, in order to show + // the error/alt message, we only do this in the exact situation. + if (BrowserInfo.get().isOpera() + && stateChangeEvent.hasPropertyChanged("showControls")) { + Style style = getWidget().getElement().getStyle(); + if (!getState().showControls) { + if (isUndefinedHeight() && isUndefinedWidth() + && getWidget().getOffsetHeight() == 150 + && getWidget().getOffsetWidth() == 300) { + // only if no size set and 150x300 + style.setWidth(0, Unit.PX); + style.setHeight(0, Unit.PX); + } + } else { + // clear sizes if it's supposed to be undefined + if (isUndefinedHeight()) { + style.clearHeight(); + } + if (isUndefinedWidth()) { + style.clearWidth(); + } + } + } + } + } diff --git a/uitest/src/com/vaadin/tests/components/media/AudioTest.html b/uitest/src/com/vaadin/tests/components/media/AudioTest.html new file mode 100644 index 0000000000..8425cad38a --- /dev/null +++ b/uitest/src/com/vaadin/tests/components/media/AudioTest.html @@ -0,0 +1,66 @@ + + + + + + +AudioTest + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
AudioTest
open/run/AudioTest?restartApplication
pause3000
screenCaptureshortAtEndUnmuted
mouseClickvaadin=runAudioTest::/VVerticalLayout[0]/Slot[1]/VVerticalLayout[0]/Slot[2]/VCheckBox[0]/domChild[0]11,7
mouseClickvaadin=runAudioTest::/VVerticalLayout[0]/Slot[1]/VVerticalLayout[0]/Slot[3]/VCheckBox[0]/domChild[0]6,7
clickvaadin=runAudioTest::/VVerticalLayout[0]/Slot[1]/VVerticalLayout[0]/Slot[5]/VButton[0]/domChild[0]/domChild[0]
pause5000
screenCapturelongerAtEndMuted
mouseClickvaadin=runAudioTest::/VVerticalLayout[0]/Slot[1]/VVerticalLayout[0]/Slot[1]/VCheckBox[0]/domChild[0]69,9
screenCapturecontrolsHidden
+ + diff --git a/uitest/src/com/vaadin/tests/components/media/AudioTest.java b/uitest/src/com/vaadin/tests/components/media/AudioTest.java new file mode 100644 index 0000000000..28d1a7716f --- /dev/null +++ b/uitest/src/com/vaadin/tests/components/media/AudioTest.java @@ -0,0 +1,86 @@ +/* + * Copyright 2000-2013 Vaadin Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ + +package com.vaadin.tests.components.media; + +import com.vaadin.data.util.MethodProperty; +import com.vaadin.server.ClassResource; +import com.vaadin.server.Resource; +import com.vaadin.tests.components.TestBase; +import com.vaadin.ui.Audio; +import com.vaadin.ui.Button; +import com.vaadin.ui.Button.ClickEvent; +import com.vaadin.ui.CheckBox; + +public class AudioTest extends TestBase { + + @Override + protected void setup() { + + // Public domain sounds from pdsounds.org 27.2.2013 + + final Resource[] s1 = { new ClassResource(getClass(), "bip.mp3"), + new ClassResource(getClass(), "bip.ogg") }; + final Resource[] s2 = { + new ClassResource(getClass(), "toyphone_dialling.mp3"), + new ClassResource(getClass(), "toyphone_dialling.ogg") }; + + final Audio audio = new Audio(); + + audio.setSources(s1); + audio.setShowControls(true); + audio.setHtmlContentAllowed(true); + audio.setAltText("Can't play media"); + audio.setAutoplay(true); + + addComponent(audio); + + CheckBox checkBox = new CheckBox("Show controls", + new MethodProperty(audio, "showControls")); + addComponent(checkBox); + checkBox = new CheckBox("HtmlContentAllowed", + new MethodProperty(audio, "htmlContentAllowed")); + addComponent(checkBox); + checkBox = new CheckBox("muted", new MethodProperty(audio, + "muted")); + addComponent(checkBox); + checkBox = new CheckBox("autoplay", new MethodProperty(audio, + "autoplay")); + addComponent(checkBox); + + Button b = new Button("Change", new Button.ClickListener() { + + @Override + public void buttonClick(ClickEvent event) { + audio.setSources(s2); + } + }); + addComponent(b); + getLayout().setHeight("400px"); + getLayout().setExpandRatio(b, 1.0f); + } + + @Override + protected String getDescription() { + return "Should autoplay, manipulating checkboxes should do appropriate thing, button changes file."; + } + + @Override + protected Integer getTicketNumber() { + return 11160; + } + +} diff --git a/uitest/src/com/vaadin/tests/components/media/bip.mp3 b/uitest/src/com/vaadin/tests/components/media/bip.mp3 new file mode 100644 index 0000000000..2c7e790cf7 Binary files /dev/null and b/uitest/src/com/vaadin/tests/components/media/bip.mp3 differ diff --git a/uitest/src/com/vaadin/tests/components/media/bip.ogg b/uitest/src/com/vaadin/tests/components/media/bip.ogg new file mode 100644 index 0000000000..4e5014d92f Binary files /dev/null and b/uitest/src/com/vaadin/tests/components/media/bip.ogg differ diff --git a/uitest/src/com/vaadin/tests/components/media/toyphone_dialling.mp3 b/uitest/src/com/vaadin/tests/components/media/toyphone_dialling.mp3 new file mode 100644 index 0000000000..1788026856 Binary files /dev/null and b/uitest/src/com/vaadin/tests/components/media/toyphone_dialling.mp3 differ diff --git a/uitest/src/com/vaadin/tests/components/media/toyphone_dialling.ogg b/uitest/src/com/vaadin/tests/components/media/toyphone_dialling.ogg new file mode 100644 index 0000000000..a042da5795 Binary files /dev/null and b/uitest/src/com/vaadin/tests/components/media/toyphone_dialling.ogg differ -- cgit v1.2.3 From 5ea677d377c96c60fbc546eb2381bb88f2d4b478 Mon Sep 17 00:00:00 2001 From: Leif Åstrand Date: Tue, 12 Mar 2013 18:34:18 +0200 Subject: Make TextArea.setCursorPosition work in all browsers (#8769) svn changeset:25579/svn branch:6.8 Conflicts: client/src/com/vaadin/client/ui/VTextField.java Change-Id: I3b53be8df4ce0564f34d8aa9bc1ce1c34648eadd --- client/src/com/vaadin/client/ui/VTextArea.java | 114 ++++++++++++++ client/src/com/vaadin/client/ui/VTextField.java | 4 + .../tests/components/textarea/ScrollCursor.html | 169 +++++++++++++++++++++ .../tests/components/textarea/ScrollCursor.java | 89 +++++++++++ 4 files changed, 376 insertions(+) create mode 100644 uitest/src/com/vaadin/tests/components/textarea/ScrollCursor.html create mode 100644 uitest/src/com/vaadin/tests/components/textarea/ScrollCursor.java (limited to 'uitest/src/com/vaadin/tests') diff --git a/client/src/com/vaadin/client/ui/VTextArea.java b/client/src/com/vaadin/client/ui/VTextArea.java index 4a5de23828..45e0532451 100644 --- a/client/src/com/vaadin/client/ui/VTextArea.java +++ b/client/src/com/vaadin/client/ui/VTextArea.java @@ -63,6 +63,120 @@ public class VTextArea extends VTextField { getTextAreaElement().setRows(rows); } + @Override + public void setSelectionRange(int pos, int length) { + super.setSelectionRange(pos, length); + final String value = getValue(); + /* + * Align position to index inside string value + */ + int index = pos; + if (index < 0) { + index = 0; + } + if (index > value.length()) { + index = value.length(); + } + // Get pixels count required to scroll textarea vertically + int scrollTop = getScrollTop(value, index); + int scrollLeft = -1; + /* + * Check if textarea has wrap attribute set to "off". In the latter case + * horizontal scroll is also required. + */ + if (!isWordwrap()) { + // Get pixels count required to scroll textarea horizontally + scrollLeft = getScrollLeft(value, index); + } + // Set back original text if previous methods calls changed it + if (!isWordwrap() || index < value.length()) { + setValue(value, false); + } + /* + * Call original method to set cursor position. In most browsers it + * doesn't lead to scrolling. + */ + super.setSelectionRange(pos, length); + /* + * Align vertical scroll to middle of textarea view (height) if + * scrolling is reqiured at all. + */ + if (scrollTop > 0) { + scrollTop += getElement().getClientHeight() / 2; + } + /* + * Align horizontal scroll to middle of textarea view (widht) if + * scrolling is reqiured at all. + */ + if (scrollLeft > 0) { + scrollLeft += getElement().getClientWidth() / 2; + } + /* + * Scroll if computed scrollTop is greater than scroll after cursor + * setting + */ + if (getElement().getScrollTop() < scrollTop) { + getElement().setScrollTop(scrollTop); + } + /* + * Scroll if computed scrollLeft is greater than scroll after cursor + * setting + */ + if (getElement().getScrollLeft() < scrollLeft) { + getElement().setScrollLeft(scrollLeft); + } + } + + /* + * Get horizontal scroll value required to get position visible. Method is + * called only when text wrapping is off. There is need to scroll + * horizontally in case words are wrapped. + */ + private int getScrollLeft(String value, int index) { + String beginning = value.substring(0, index); + // Compute beginning of the current line + int begin = beginning.lastIndexOf('\n'); + String line = value.substring(begin + 1); + index = index - begin - 1; + if (index < line.length()) { + index++; + } + line = line.substring(0, index); + /* + * Now line contains current line up to index position + */ + setValue(line.trim(), false); // Set this line to the textarea. + /* + * Scroll textarea up to the end of the line (maximum possible + * horizontal scrolling value). Now the end line becomes visible. + */ + getElement().setScrollLeft(getElement().getScrollWidth()); + // Return resulting horizontal scrolling value. + return getElement().getScrollLeft(); + } + + /* + * Get vertical scroll value required to get position visible + */ + private int getScrollTop(String value, int index) { + /* + * Trim text after position and set this trimmed text if index is not + * very end. + */ + if (index < value.length()) { + String beginning = value.substring(0, index); + setValue(beginning, false); + } + /* + * Now textarea contains trimmed text and could be scrolled up to the + * top. Scroll it to maximum possible value to get end of the text + * visible. + */ + getElement().setScrollTop(getElement().getScrollHeight()); + // Return resulting vertical scrolling value. + return getElement().getScrollTop(); + } + private class MaxLengthHandler implements KeyUpHandler, ChangeHandler { @Override diff --git a/client/src/com/vaadin/client/ui/VTextField.java b/client/src/com/vaadin/client/ui/VTextField.java index 0fbed0dd90..da9445c811 100644 --- a/client/src/com/vaadin/client/ui/VTextField.java +++ b/client/src/com/vaadin/client/ui/VTextField.java @@ -446,4 +446,8 @@ public class VTextField extends TextBoxBase implements Field, ChangeHandler, this.inputPrompt = inputPrompt; } + protected boolean isWordwrap() { + String wrap = getElement().getAttribute("wrap"); + return !"off".equals(wrap); + } } diff --git a/uitest/src/com/vaadin/tests/components/textarea/ScrollCursor.html b/uitest/src/com/vaadin/tests/components/textarea/ScrollCursor.html new file mode 100644 index 0000000000..9eaa1ceada --- /dev/null +++ b/uitest/src/com/vaadin/tests/components/textarea/ScrollCursor.html @@ -0,0 +1,169 @@ + + + + + + +New Test + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
New Test
open/run/com.vaadin.tests.components.textarea.ScrollCursor?restartApplication
mouseClickvaadin=runcomvaadintestscomponentstextareaScrollCursor::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/domChild[0]/domChild[0]191,94
clickvaadin=runcomvaadintestscomponentstextareaScrollCursor::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[3]/VButton[0]/domChild[0]/domChild[0]
clickvaadin=runcomvaadintestscomponentstextareaScrollCursor::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[1]/VButton[0]/domChild[0]/domChild[0]
screenCapturewrap-start
clickvaadin=runcomvaadintestscomponentstextareaScrollCursor::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[4]/VButton[0]/domChild[0]/domChild[0]
clickvaadin=runcomvaadintestscomponentstextareaScrollCursor::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[1]/VButton[0]/domChild[0]/domChild[0]
screenCapturewrap-middle
clickvaadin=runcomvaadintestscomponentstextareaScrollCursor::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[5]/VButton[0]/domChild[0]/domChild[0]
clickvaadin=runcomvaadintestscomponentstextareaScrollCursor::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[1]/VButton[0]/domChild[0]/domChild[0]
screenCapturewrap-end
clickvaadin=runcomvaadintestscomponentstextareaScrollCursor::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[3]/VButton[0]/domChild[0]/domChild[0]
clickvaadin=runcomvaadintestscomponentstextareaScrollCursor::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[1]/VButton[0]/domChild[0]/domChild[0]
screenCapturewrap-end-start
clickvaadin=runcomvaadintestscomponentstextareaScrollCursor::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[2]/VButton[0]/domChild[0]/domChild[0]
clickvaadin=runcomvaadintestscomponentstextareaScrollCursor::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[3]/VButton[0]/domChild[0]/domChild[0]
clickvaadin=runcomvaadintestscomponentstextareaScrollCursor::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[1]/VButton[0]/domChild[0]/domChild[0]
screenCapturenowrap-start
clickvaadin=runcomvaadintestscomponentstextareaScrollCursor::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[4]/VButton[0]/domChild[0]/domChild[0]
clickvaadin=runcomvaadintestscomponentstextareaScrollCursor::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[1]/VButton[0]/domChild[0]/domChild[0]
screenCapturenowrap-middle
clickvaadin=runcomvaadintestscomponentstextareaScrollCursor::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[5]/VButton[0]/domChild[0]/domChild[0]
clickvaadin=runcomvaadintestscomponentstextareaScrollCursor::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[1]/VButton[0]/domChild[0]/domChild[0]
screenCapturenowrap-end
clickvaadin=runcomvaadintestscomponentstextareaScrollCursor::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[3]/VButton[0]/domChild[0]/domChild[0]
clickvaadin=runcomvaadintestscomponentstextareaScrollCursor::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[1]/VButton[0]/domChild[0]
screenCapturenowrap-end-start
+ + diff --git a/uitest/src/com/vaadin/tests/components/textarea/ScrollCursor.java b/uitest/src/com/vaadin/tests/components/textarea/ScrollCursor.java new file mode 100644 index 0000000000..c95731d94f --- /dev/null +++ b/uitest/src/com/vaadin/tests/components/textarea/ScrollCursor.java @@ -0,0 +1,89 @@ +package com.vaadin.tests.components.textarea; + +import com.vaadin.tests.components.TestBase; +import com.vaadin.ui.Button; +import com.vaadin.ui.Button.ClickEvent; +import com.vaadin.ui.Button.ClickListener; +import com.vaadin.ui.TextArea; + +/** + * @author denis + * + */ +public class ScrollCursor extends TestBase { + + private TextArea textArea; + private int position; + + @Override + protected void setup() { + textArea = new TextArea(); + textArea.setValue("saddddddddddd fdgdfgfdgfd\n" + + "aasddddddddddd\n" + "dsaffffffdsf\n" + "sdf\n" + + "dsfsdfsdfsdfsd\n\n" + "ffffffffffffffffffff\n" + + "sdfdsfdsfsdfsdfsd xxxxxxxxxxxxxxxx\n" + "sdgfsd\n" + + "dsf\n" + "ds\n" + "fds\n" + "fds\nfs"); + addComponent(textArea); + Button button = new Button("Scroll"); + button.addListener(new ClickListener() { + + public void buttonClick(ClickEvent event) { + textArea.setCursorPosition(getPosition()); + } + }); + Button wrap = new Button("Set wrap"); + wrap.addListener(new ClickListener() { + + public void buttonClick(ClickEvent event) { + textArea.setWordwrap(false); + } + }); + + Button toBegin = new Button("To begin"); + toBegin.addListener(new ClickListener() { + + public void buttonClick(ClickEvent event) { + position = 3; + } + }); + + Button toMiddle = new Button("To middle"); + toMiddle.addListener(new ClickListener() { + + public void buttonClick(ClickEvent event) { + position = 130; + } + }); + + Button toEnd = new Button("To end"); + toEnd.addListener(new ClickListener() { + + public void buttonClick(ClickEvent event) { + position = textArea.getValue().toString().length(); + } + }); + + addComponent(button); + addComponent(wrap); + addComponent(toBegin); + addComponent(toMiddle); + addComponent(toEnd); + } + + @Override + protected String getDescription() { + return "Tests scrolling for TextArea with different word wrapping settings. " + + "Sets cursor position at the beginning, middle and the end " + + "of text and checks textarea is scrolled."; + } + + @Override + protected Integer getTicketNumber() { + return 8769; + } + + private int getPosition() { + return position; + } + +} -- cgit v1.2.3