package org.gcube.portlets.user.reportgenerator.client.targets; import java.util.ArrayList; import org.gcube.portlets.d4sreporting.common.shared.ComponentType; import org.gcube.portlets.d4sreporting.common.shared.SerializableComponent; import org.gcube.portlets.d4sreporting.common.shared.SerializableRepeatableSequence; import org.gcube.portlets.user.reportgenerator.client.Presenter.Presenter; import org.gcube.portlets.user.reportgenerator.client.model.TemplateComponent; import com.google.gwt.core.client.GWT; import com.google.gwt.dom.client.Style.Unit; import com.google.gwt.event.dom.client.ClickEvent; import com.google.gwt.event.dom.client.ClickHandler; import com.google.gwt.user.client.Window; import com.google.gwt.user.client.ui.Button; import com.google.gwt.user.client.ui.Composite; import com.google.gwt.user.client.ui.HasAlignment; import com.google.gwt.user.client.ui.HorizontalPanel; import com.google.gwt.user.client.ui.VerticalPanel; public class RepeatableSequence extends Composite { private ArrayList groupedComponents = new ArrayList(); private VerticalPanel myPanel; private HorizontalPanel buttonPanel = new HorizontalPanel(); private Presenter p; private Button addAnotherB = new Button("Add another entry"); /** * constructor used by the system when reading the model * @param sRS */ public RepeatableSequence(Presenter p, SerializableRepeatableSequence sRS) { this.p = p; addAnotherB.getElement().getStyle().setMargin(10, Unit.PX); addAnotherB.getElement().getStyle().setHeight(30, Unit.PX); addAnotherB.getElement().getStyle().setWidth(200, Unit.PX); myPanel = new VerticalPanel(); myPanel.setHorizontalAlignment(HasAlignment.ALIGN_LEFT); int size = sRS.getGroupedComponents().size(); for (int j = 0; j < size; j++) { SerializableComponent sComp = sRS.getGroupedComponents().get(j); if (j == size-1) { myPanel.add(buttonPanel); //add the button before the last element buttonPanel.setWidth("100%"); buttonPanel.setHorizontalAlignment(HasAlignment.ALIGN_RIGHT); buttonPanel.add(addAnotherB); } add(new TemplateComponent(p.getModel(), sComp, p)); } initWidget(myPanel); addAnotherB.addClickHandler(new ClickHandler() { @Override public void onClick(ClickEvent event) { Window.alert("TODO: Missing Implementation"); } }); } public void add(TemplateComponent toAdd) { if (toAdd.getType() != ComponentType.REPEAT_SEQUENCE_INNER) { groupedComponents.add(toAdd); GWT.log("ToAdd= getType " + toAdd.getType()); myPanel.add(toAdd.getContent()); } } public ArrayList getGroupedComponents() { return groupedComponents; } public void setGroupedComponents(ArrayList groupedComponents) { this.groupedComponents = groupedComponents; } }