*/
@Override
public void writeDesign(Element design, DesignContext designContext) {
- // clear element contents
- DesignAttributeHandler.clearElement(design);
AbstractComponent def = designContext.getDefaultInstance(this);
Attributes attr = design.attributes();
// handle default attributes
*
* @since 7.4
* @param design
- * The design as HTML to obtain the state from
+ * The element to obtain the state from
* @param designContext
* The DesignContext instance used for parsing the design
*/
*
* @since 7.4
* @param design
- * The design as HTML to update with the current state
+ * The element to write the component state to. Any previous
+ * attributes or child nodes are <i>not</i> cleared.
* @param designContext
+ * The DesignContext instance used for writing the design
+ *
*/
public void writeDesign(Element design, DesignContext designContext);
*/
package com.vaadin.tests.server.component.abstractfield;
-import static org.junit.Assert.assertTrue;
-
-import org.jsoup.nodes.Attributes;
-import org.jsoup.nodes.Element;
-import org.jsoup.parser.Tag;
import org.junit.Test;
import com.vaadin.data.util.ObjectProperty;
import com.vaadin.tests.design.DeclarativeTestBase;
import com.vaadin.ui.AbstractField;
import com.vaadin.ui.TextField;
-import com.vaadin.ui.declarative.DesignContext;
/**
* Tests declarative support for implementations of {@link AbstractField}.
testWrite(design, tf);
}
- @Test
- public void testWriteRemovesOldContent() {
- Attributes attr = new Attributes();
- attr.put("should_be_removed", "foo");
- Element design = new Element(Tag.valueOf("v-text-field"), "", attr);
- AbstractField component = new TextField();
- component.setReadOnly(true);
- component.writeDesign(design, new DesignContext());
- // we only changed one of the attributes, others are at default values
- assertEquals(1, design.attributes().size());
- assertTrue("Design must contain readonly", design.hasAttr("readonly"));
- assertTrue("Readonly must be true", design.attr("readonly").equals("")
- || design.attr("readonly").equals("true"));
- }
-
@Test
public void testModelReadOnly() {
// Test that read only value coming from property data source is not
*/
package com.vaadin.tests.server.component.abstractorderedlayout;
-import static org.junit.Assert.assertTrue;
-
import java.util.Arrays;
import java.util.List;
-import org.jsoup.nodes.Attributes;
-import org.jsoup.nodes.Element;
-import org.jsoup.parser.Tag;
import org.junit.Test;
import com.vaadin.shared.ui.label.ContentMode;
import com.vaadin.ui.Button;
import com.vaadin.ui.Label;
import com.vaadin.ui.VerticalLayout;
-import com.vaadin.ui.declarative.DesignContext;
/**
* Tests declarative support for AbstractOrderedLayout.
testWrite(design, layout);
}
- @Test
- public void testWriteRemovesOldElementContent() {
- // Create an element with some content
- Attributes rootAttributes = new Attributes();
- rootAttributes.put("caption", "test-layout");
- Element design = new Element(Tag.valueOf("v-vertical-layout"), "",
- rootAttributes);
- Attributes firstChildAttributes = new Attributes();
- firstChildAttributes.put("caption", "test-label");
- Element firstChild = new Element(Tag.valueOf("v-label"), "",
- firstChildAttributes);
- design.appendChild(firstChild);
-
- Attributes secondChildAttributes = new Attributes();
- secondChildAttributes.put("caption", "test-button");
- Element secondChild = new Element(Tag.valueOf("v-button"), "",
- secondChildAttributes);
- design.appendChild(secondChild);
- Attributes thirdChildAttributes = new Attributes();
- thirdChildAttributes.put("caption", "test-button-2");
- Element thirdChild = new Element(Tag.valueOf("v-button"), "",
- thirdChildAttributes);
- design.appendChild(thirdChild);
- // Create and write a layout and check the new contents of the element
- // node
- VerticalLayout layout = new VerticalLayout();
- layout.addComponent(new Label("test-label"));
- layout.getComponent(0).setCaption("test-caption");
- layout.setExpandRatio(layout.getComponent(0), 1.0f);
- layout.addComponent(new Label("test-label-2"));
- layout.writeDesign(design, new DesignContext());
- assertEquals(2, design.childNodes().size());
- assertEquals("v-label", ((Element) design.childNode(0)).tagName());
- assertEquals("test-caption", design.childNode(0).attr("caption"));
- assertTrue(design.childNode(0).hasAttr(":expand"));
- assertEquals("", design.childNode(0).attr(":expand"));
-
- }
-
private String getDesign(float expandRatio, boolean margin,
String... alignments) {
String result = "<v-vertical-layout caption=test-layout";
*/
package com.vaadin.tests.server.component.abstractsplitpanel;
-import static junit.framework.TestCase.assertTrue;
-
-import org.jsoup.nodes.Element;
import org.junit.Test;
import com.vaadin.server.Sizeable.Unit;
import com.vaadin.ui.AbstractSplitPanel;
import com.vaadin.ui.Button;
import com.vaadin.ui.HorizontalSplitPanel;
-import com.vaadin.ui.Label;
import com.vaadin.ui.Table;
import com.vaadin.ui.VerticalLayout;
import com.vaadin.ui.VerticalSplitPanel;
-import com.vaadin.ui.declarative.DesignContext;
/**
* Tests declarative support for AbstractSplitPanel.
testRead(design, sp);
testWrite(design, sp);
}
-
- @Test
- public void testReSynchronize() {
- // Test that old children and attributes are removed when an element is
- // synchronized to a new component.
- DesignContext ctx = new DesignContext();
- VerticalSplitPanel sp = new VerticalSplitPanel();
- sp.setMinSplitPosition(5.5f, Unit.PERCENTAGE);
- sp.setMaxSplitPosition(95, Unit.PERCENTAGE);
- sp.setFirstComponent(new Button("First slot"));
- sp.setSecondComponent(new Label("Second slot"));
- Element e = ctx.createElement(sp);
- sp = new VerticalSplitPanel();
- sp.writeDesign(e, ctx);
- assertTrue("There should be no attributes in the node.", e.attributes()
- .size() == 0);
- assertTrue("There should be no child elements.",
- e.children().size() == 0);
- }
}
\ No newline at end of file
*/
package com.vaadin.tests.server.component.button;
-import static org.junit.Assert.assertTrue;
-
-import org.jsoup.nodes.Attributes;
-import org.jsoup.nodes.Element;
-import org.jsoup.parser.Tag;
import org.junit.Test;
import com.vaadin.event.ShortcutAction.KeyCode;
import com.vaadin.tests.design.DeclarativeTestBase;
import com.vaadin.ui.Button;
import com.vaadin.ui.NativeButton;
-import com.vaadin.ui.declarative.DesignContext;
/**
* Tests declarative support for implementations of {@link Button} and
testRead(design, b);
testWrite(design, b);
}
-
- @Test
- public void testWriteUpdatesContentMode() {
- DesignContext ctx = new DesignContext();
- Button button = new Button("OK");
- Element e = new Element(Tag.valueOf("v-button"), "", new Attributes());
- button.writeDesign(e, ctx);
- assertTrue("Button is plain text by default", e.hasAttr("plain-text"));
-
- button.setHtmlContentAllowed(true);
- button.writeDesign(e, ctx);
- assertTrue("Button is updated to HTML", !e.hasAttr("plain-text"));
- }
}
\ No newline at end of file
*/
package com.vaadin.tests.server.component.csslayout;
-import org.jsoup.nodes.Attributes;
-import org.jsoup.nodes.Element;
-import org.jsoup.parser.Tag;
import org.junit.Test;
import com.vaadin.shared.ui.label.ContentMode;
import com.vaadin.ui.Button;
import com.vaadin.ui.CssLayout;
import com.vaadin.ui.Label;
-import com.vaadin.ui.declarative.DesignContext;
/**
* Tests declarative support for CssLayout.
testRead(design, layout);
testWrite(design, layout);
}
-
- @Test
- public void testWriteWithOldContents() {
- // Test that any old contents of an element are removed when
- // writing a design.
- Element design = createDesign();
- CssLayout layout = new CssLayout();
- layout.addComponent(new Label("test-label"));
- layout.getComponent(0).setCaption("test-caption");
- layout.addComponent(new Label("test-label-2"));
- layout.writeDesign(design, new DesignContext());
- assertEquals(2, design.childNodes().size());
- assertEquals("v-label", ((Element) design.childNode(0)).tagName());
- assertEquals("test-caption", design.childNode(0).attr("caption"));
- }
-
- private Element createDesign() {
- // create an element with some contents
- Attributes rootAttributes = new Attributes();
- rootAttributes.put("caption", "test-layout");
- Element node = new Element(Tag.valueOf("v-vertical-layout"), "",
- rootAttributes);
- Attributes childAttributes = new Attributes();
- childAttributes.put("caption", "test-label");
- Element child = new Element(Tag.valueOf("v-label"), "", childAttributes);
- node.appendChild(child);
-
- return node;
- }
}
*/
package com.vaadin.tests.server.component.label;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
-
-import org.jsoup.nodes.Attributes;
-import org.jsoup.nodes.Element;
-import org.jsoup.parser.Tag;
import org.junit.Test;
import com.vaadin.shared.ui.label.ContentMode;
import com.vaadin.tests.design.DeclarativeTestBase;
import com.vaadin.ui.Label;
-import com.vaadin.ui.declarative.DesignContext;
/**
* Tests declarative support for implementations of {@link Label}.
testWrite(design, l);
}
- @Test
- public void testWriteContentMode() {
- // test that the plain-text attribute is overwritten by writeDesign
- DesignContext ctx = new DesignContext();
- Label l = new Label("label");
- l.setContentMode(ContentMode.TEXT);
- Element e = new Element(Tag.valueOf("v-label"), "", new Attributes());
- l.writeDesign(e, ctx);
- assertTrue("Label should be marked as plain text",
- e.hasAttr("plain-text"));
- l.setContentMode(ContentMode.HTML);
- l.writeDesign(e, ctx);
- assertFalse("Label should not be marked as plain text",
- e.hasAttr("plain-text"));
- }
-
private Label createLabel(String content, String caption, boolean html) {
Label label = new Label();
label.setContentMode(html ? ContentMode.HTML : ContentMode.TEXT);
*/
package com.vaadin.tests.server.component.tabsheet;
-import org.jsoup.nodes.Attributes;
-import org.jsoup.nodes.Element;
-import org.jsoup.parser.Tag;
import org.junit.Test;
import com.vaadin.server.ExternalResource;
import com.vaadin.ui.TabSheet;
import com.vaadin.ui.TabSheet.Tab;
import com.vaadin.ui.TextField;
-import com.vaadin.ui.declarative.DesignContext;
/**
* Tests declarative support for TabSheet.
testRead(design, ts);
testWrite(design, ts);
}
-
- @Test
- public void testWriteRemovesOldContent() {
- // create old content that should be removed when writing
- Element design = new Element(Tag.valueOf("v-tab-sheet"), "",
- new Attributes());
- design.appendChild(new Element(Tag.valueOf("tab"), "", new Attributes()));
- design.appendChild(new Element(Tag.valueOf("tab"), "", new Attributes()));
- design.appendChild(new Element(Tag.valueOf("tab"), "", new Attributes()));
- // create a new TabSheet with one tab
- TabSheet ts = new TabSheet();
- ts.setTabIndex(5);
- ts.addTab(new TextField());
- Tab tab = ts.getTab(0);
- tab.setVisible(false);
- tab.setClosable(true);
- tab.setEnabled(false);
- // write the design and check written contents
- ts.writeDesign(design, new DesignContext());
- assertEquals("There should be only one child", 1, design.children()
- .size());
- assertEquals("v-text-field", design.child(0).child(0).tagName());
- assertEquals("5", design.attr("tabindex"));
- Element tabDesign = design.child(0);
- assertEquals("false", tabDesign.attr("visible"));
- }
}
\ No newline at end of file