@Override
public void addComponent(Component c) {
// Add to components before calling super.addComponent
- // so that it is available to AttachListeners
+ // so that it is available to AttachListeners
components.add(c);
try {
super.addComponent(c);
public void addComponentAsFirst(Component c) {
// If c is already in this, we must remove it before proceeding
// see ticket #7668
- if(c.getParent() == this) {
+ if (c.getParent() == this) {
removeComponent(c);
}
components.addFirst(c);
public void addComponent(Component c, int index) {
// If c is already in this, we must remove it before proceeding
// see ticket #7668
- if(c.getParent() == this) {
+ if (c.getParent() == this) {
// When c is removed, all components after it are shifted down
- if(index > getComponentIndex(c)) {
+ if (index > getComponentIndex(c)) {
index--;
}
removeComponent(c);
@Override
public void addComponent(Component c) {
// Add to components before calling super.addComponent
- // so that it is available to AttachListeners
+ // so that it is available to AttachListeners
components.add(c);
try {
super.addComponent(c);
public void addComponentAsFirst(Component c) {
// If c is already in this, we must remove it before proceeding
// see ticket #7668
- if(c.getParent() == this) {
+ if (c.getParent() == this) {
removeComponent(c);
}
components.addFirst(c);
public void addComponent(Component c, int index) {
// If c is already in this, we must remove it before proceeding
// see ticket #7668
- if(c.getParent() == this) {
+ if (c.getParent() == this) {
// When c is removed, all components after it are shifted down
- if(index > components.indexOf(c)) {
+ if (index > components.indexOf(c)) {
index--;
}
removeComponent(c);
package com.vaadin.tests.server.component.abstractorderedlayout;\r
\r
+import static org.junit.Assert.assertFalse;\r
+import static org.junit.Assert.assertSame;\r
+import static org.junit.Assert.fail;\r
+\r
import java.util.Iterator;\r
import java.util.NoSuchElementException;\r
\r
import org.junit.Test;\r
\r
-import static org.junit.Assert.assertFalse;\r
-import static org.junit.Assert.assertSame;\r
-import static org.junit.Assert.fail;\r
-\r
-import com.vaadin.ui.Component;\r
import com.vaadin.ui.AbstractOrderedLayout;\r
+import com.vaadin.ui.Component;\r
import com.vaadin.ui.HorizontalLayout;\r
+import com.vaadin.ui.Label;\r
import com.vaadin.ui.Layout;\r
import com.vaadin.ui.VerticalLayout;\r
-import com.vaadin.ui.Label;\r
\r
public class AddComponentsTest {\r
\r
- Component[] children = new Component[] {\r
- new Label("A"), new Label("B"), \r
+ Component[] children = new Component[] { new Label("A"), new Label("B"),\r
new Label("C"), new Label("D") };\r
- \r
+\r
@Test\r
public void moveComponentsBetweenLayouts() {\r
AbstractOrderedLayout layout1 = new HorizontalLayout();\r
AbstractOrderedLayout layout2 = new VerticalLayout();\r
- \r
+\r
layout1.addComponent(children[0]);\r
layout1.addComponent(children[1]);\r
- \r
+\r
layout2.addComponent(children[2]);\r
layout2.addComponent(children[3]);\r
- \r
+\r
layout2.addComponent(children[1], 1);\r
assertOrder(layout1, new int[] { 0 });\r
assertOrder(layout2, new int[] { 2, 1, 3 });\r
- \r
+\r
layout1.addComponent(children[3], 0);\r
assertOrder(layout1, new int[] { 3, 0 });\r
assertOrder(layout2, new int[] { 2, 1 });\r
- \r
+\r
layout2.addComponent(children[0]);\r
assertOrder(layout1, new int[] { 3 });\r
assertOrder(layout2, new int[] { 2, 1, 0 });\r
- \r
+\r
layout1.addComponentAsFirst(children[1]);\r
assertOrder(layout1, new int[] { 1, 3 });\r
assertOrder(layout2, new int[] { 2, 0 });\r
}\r
- \r
+\r
@Test\r
public void shuffleChildComponents() {\r
shuffleChildComponents(new HorizontalLayout());\r
shuffleChildComponents(new VerticalLayout());\r
}\r
- \r
+\r
private void shuffleChildComponents(AbstractOrderedLayout layout) {\r
- \r
+\r
for (int i = 0; i < children.length; ++i) {\r
layout.addComponent(children[i], i);\r
}\r
- \r
+\r
assertOrder(layout, new int[] { 0, 1, 2, 3 });\r
\r
// Move C from #2 to #1\r
// Exhibits defect #7668\r
layout.addComponent(children[2], 1);\r
assertOrder(layout, new int[] { 0, 2, 1, 3 });\r
- \r
+\r
// Move C from #1 to #4 (which becomes #3 when #1 is erased)\r
layout.addComponent(children[2], 4);\r
assertOrder(layout, new int[] { 0, 1, 3, 2 });\r
- \r
+\r
// Keep everything in place\r
layout.addComponent(children[1], 1);\r
assertOrder(layout, new int[] { 0, 1, 3, 2 });\r
- \r
+\r
// Move D from #2 to #0\r
layout.addComponent(children[3], 0);\r
assertOrder(layout, new int[] { 3, 0, 1, 2 });\r
- \r
+\r
// Move A from #1 to end (#4 which becomes #3)\r
layout.addComponent(children[0]);\r
assertOrder(layout, new int[] { 3, 1, 2, 0 });\r
// Keep everything in place\r
layout.addComponent(children[0]);\r
assertOrder(layout, new int[] { 3, 1, 2, 0 });\r
- \r
+\r
// Move C from #2 to #0\r
layout.addComponentAsFirst(children[2]);\r
assertOrder(layout, new int[] { 2, 3, 1, 0 });\r
}\r
\r
/**\r
- * Asserts that layout has the components in children\r
- * in the order specified by indices.\r
+ * Asserts that layout has the components in children in the order specified\r
+ * by indices.\r
*/\r
private void assertOrder(Layout layout, int[] indices) {\r
Iterator<?> i = layout.getComponentIterator();\r
try {\r
- for(int index : indices) {\r
+ for (int index : indices) {\r
assertSame(children[index], i.next());\r
}\r
assertFalse("Too many components in layout", i.hasNext());\r
- } catch(NoSuchElementException e) {\r
+ } catch (NoSuchElementException e) {\r
fail("Too few components in layout");\r
}\r
}\r
import static org.junit.Assert.assertFalse;\r
import static org.junit.Assert.fail;\r
\r
-\r
import com.vaadin.ui.Component;\r
import com.vaadin.ui.CssLayout;\r
import com.vaadin.ui.Label;\r
\r
public class AddComponentsTest {\r
\r
- private Component[] children = new Component[] {\r
- new Label("A"), new Label("B"), \r
- new Label("C"), new Label("D") };\r
- \r
+ private Component[] children = new Component[] { new Label("A"),\r
+ new Label("B"), new Label("C"), new Label("D") };\r
+\r
@Test\r
public void moveComponentsBetweenLayouts() {\r
CssLayout layout1 = new CssLayout();\r
CssLayout layout2 = new CssLayout();\r
- \r
+\r
layout1.addComponent(children[0]);\r
layout1.addComponent(children[1]);\r
- \r
+\r
layout2.addComponent(children[2]);\r
layout2.addComponent(children[3]);\r
- \r
+\r
layout2.addComponent(children[1], 1);\r
assertOrder(layout1, new int[] { 0 });\r
assertOrder(layout2, new int[] { 2, 1, 3 });\r
- \r
+\r
layout1.addComponent(children[3], 0);\r
assertOrder(layout1, new int[] { 3, 0 });\r
assertOrder(layout2, new int[] { 2, 1 });\r
- \r
+\r
layout2.addComponent(children[0]);\r
assertOrder(layout1, new int[] { 3 });\r
assertOrder(layout2, new int[] { 2, 1, 0 });\r
- \r
+\r
layout1.addComponentAsFirst(children[1]);\r
assertOrder(layout1, new int[] { 1, 3 });\r
assertOrder(layout2, new int[] { 2, 0 });\r
}\r
- \r
+\r
@Test\r
public void shuffleChildComponents() {\r
CssLayout layout = new CssLayout();\r
- \r
+\r
for (int i = 0; i < children.length; ++i) {\r
layout.addComponent(children[i], i);\r
}\r
- \r
+\r
assertOrder(layout, new int[] { 0, 1, 2, 3 });\r
\r
// Move C from #2 to #1\r
// Exhibits defect #7668\r
layout.addComponent(children[2], 1);\r
assertOrder(layout, new int[] { 0, 2, 1, 3 });\r
- \r
+\r
// Move C from #1 to #4 (which becomes #3 when #1 is erased)\r
layout.addComponent(children[2], 4);\r
assertOrder(layout, new int[] { 0, 1, 3, 2 });\r
- \r
+\r
// Keep everything in place\r
layout.addComponent(children[1], 1);\r
assertOrder(layout, new int[] { 0, 1, 3, 2 });\r
- \r
+\r
// Move D from #2 to #0\r
layout.addComponent(children[3], 0);\r
assertOrder(layout, new int[] { 3, 0, 1, 2 });\r
- \r
+\r
// Move A from #1 to end (#4 which becomes #3)\r
layout.addComponent(children[0]);\r
assertOrder(layout, new int[] { 3, 1, 2, 0 });\r
// Keep everything in place\r
layout.addComponent(children[0]);\r
assertOrder(layout, new int[] { 3, 1, 2, 0 });\r
- \r
+\r
// Move C from #2 to #0\r
layout.addComponentAsFirst(children[2]);\r
assertOrder(layout, new int[] { 2, 3, 1, 0 });\r
}\r
\r
/**\r
- * Asserts that layout has the components in children\r
- * in the order specified by indices.\r
+ * Asserts that layout has the components in children in the order specified\r
+ * by indices.\r
*/\r
private void assertOrder(Layout layout, int[] indices) {\r
Iterator<?> i = layout.getComponentIterator();\r
try {\r
- for(int index : indices) {\r
+ for (int index : indices) {\r
assertSame(children[index], i.next());\r
}\r
assertFalse("Too many components in layout", i.hasNext());\r
- } catch(NoSuchElementException e) {\r
+ } catch (NoSuchElementException e) {\r
fail("Too few components in layout");\r
}\r
}\r