Manage view elements

FireWeb application reflects DOM tree of HTML document in browser. The Application class is root of the document and is the body element of HTML. In package fireweb.org.html you can find all HTML elements implementations. You can control view elements as on DHTML, using pure Java objects.


There are several method to control view elements:

  1. Add element. Use add(object) on parent element to add child:
    	Div component = new Div().add(new Paragraph().setText("Pragraph 1"))
    			.add(new Paragraph().setText("Pragraph 2"));
    	application.add(component);
  2. Remove element. Use remove(object) or remove(index) on parent element to remove child:
    // As above
    ...
    component.remove(0);
    application.remove(component);
  3. Attach to parent. Similarly as add child to parent by add(object), we can attach child to parent element with setParent(object).
    Div component = new Div();
    component.setParent(application);
  4. Detach from parent. If you want to remove element from view simply detach it form parent element by removeParent().
    Div component = new Div();
    component.setParent(application);
    component.add(new Paragraph().setText("Pragraph 1"))
    	.add(new Paragraph().setText("Pragraph 2"));
    
    ...
    
    application.removeParent(component);
    
  5. Insert at position. To put child element on parent use insert(index, object).
    	Div component = new Div().setParent(application);
    	component.add(new Paragraph().setText("Pragraph 2"))
    			 .insert(0, new Paragraph().setText("Pragraph 1"));
    
  6. Replace at position. As inserted element we can replace child element at given index by replace(index, object).
    Div component = new Div().setParent(application);
    component.add(new Paragraph().setText("Pragraph 2"))
    	.insert(0, new Paragraph().setText("Pragraph 1"));
    
    ...
    
    component.replace(1, new Span().setText("Span"));
  7. Finding child elements of parent. You can get all children by getElements(),
    	Div component = new Div().setParent(application);
    	component.add(new Paragraph().setText("Pragraph 2"))
    		.add(new Span().setText("Span"));
    
    ...
    
    List<Element> children = component.getElements();
    or by given class or interface using getElements(class)
    Div component = new Div().setParent(application);
    component.add(new Paragraph().setText("Pragraph 2"))
    	.add(new Span().setText("Span"));
    
    ...
    
    List<Span> children = component.getElements(Span.class);
  8. Finding elements of view. Sometimes we want to find children elements lying on current and below elements tree. You can use findViewElements(class).
    Div component1 = new Div().setParent(application);
    component1.add(new Paragraph().setText("Pragraph 1"))
    	.add(new Span().setText("Span 1"));
    Div component2 = new Div().setParent(application);
    component2.add(new Paragraph().setText("Pragraph 2"))
    	.add(new Span().setText("Span 2"));
    component1.add(compnent2);
    
    ...
    
    List<Span> spans = application.findViewElements(Span.class);
    List<Paragraph> paragraphs = application
    	.findViewElements(Paragraph.class);
    List<Div> divs = application.findViewElements(Div.class);
  9. Getting or finding parent of current element. Parent element you can get by getParent().
    Div component = new Div().setParent(application);
    component.add(new Paragraph().setText("Pragraph 2"))
    	.add(new Span().setText("Span"));
    
    ...
    
    FireWebApplication app = component.getParent();
    
    Similarly as above we can find parent in elements tree by findParent(class).
    Span component = new Span().setParent(new Paragraph()
    			  	.setParent(new Div()));
    Div parent = component.findParent(Div.class);