added support for Repeating Components
git-svn-id: http://svn.research-infrastructures.eu/public/d4science/gcube/trunk/portlets/user/reports@70912 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
1448a8ef51
commit
f0e76cedbc
|
@ -43,7 +43,6 @@ import com.google.gwt.user.client.ui.Widget;
|
|||
*
|
||||
* This class represent all the possible template components IN THE MODEL
|
||||
* @author Massimiliano Assante, ISTI-CNR - massimiliano.assante@isti.cnr.it
|
||||
* @version July 2011 (3.0)
|
||||
*/
|
||||
public class TemplateComponent {
|
||||
|
||||
|
|
|
@ -2,63 +2,95 @@ 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.BasicComponent;
|
||||
import org.gcube.portlets.d4sreporting.common.shared.ComponentType;
|
||||
import org.gcube.portlets.d4sreporting.common.shared.RepeatableSequence;
|
||||
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 ClientRepeatableSequence extends Composite {
|
||||
private ArrayList<TemplateComponent> groupedComponents = new ArrayList<TemplateComponent>();
|
||||
protected ArrayList<TemplateComponent> groupedComponents = new ArrayList<TemplateComponent>();
|
||||
|
||||
private VerticalPanel myPanel;
|
||||
private HorizontalPanel buttonPanel = new HorizontalPanel();
|
||||
private VerticalPanel myPanel = new VerticalPanel();
|
||||
private Presenter p;
|
||||
private Button addAnotherB = new Button("Add another entry");
|
||||
|
||||
protected RepeatableSequence repSequence;
|
||||
|
||||
protected RepeatableSequence originalSequence = new RepeatableSequence();
|
||||
|
||||
/**
|
||||
* constructor used by the system when reading the model
|
||||
* @param sRS
|
||||
* @param sRS the sequence to repeat
|
||||
*/
|
||||
public ClientRepeatableSequence(Presenter p, RepeatableSequence 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++) {
|
||||
BasicComponent 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));
|
||||
this.repSequence = sRS;
|
||||
this.originalSequence = extractOriginalSequence(sRS);
|
||||
SequenceWidget seqW = new SequenceWidget(p, this, originalSequence, true);
|
||||
myPanel.add(seqW);
|
||||
|
||||
for (RepeatableSequence repeatSeq : getRepeats()) {
|
||||
addAnother(repeatSeq);
|
||||
}
|
||||
initWidget(myPanel);
|
||||
|
||||
addAnotherB.addClickHandler(new ClickHandler() {
|
||||
|
||||
@Override
|
||||
public void onClick(ClickEvent event) {
|
||||
Window.alert("TODO: Missing Implementation");
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
* when you repeat a sequence the model is not able to recognize is this was a sequence or not
|
||||
* to overcome this limitation you have to identify the original sequence by identifying it
|
||||
* to identify it you can use the REPEAT_SEQUENCE_DELIMITER ELEMENT
|
||||
* @param sRS
|
||||
*/
|
||||
private RepeatableSequence extractOriginalSequence(RepeatableSequence sRS) {
|
||||
RepeatableSequence toReturn = null;
|
||||
int repeatDelimiterCounter = 2;
|
||||
ArrayList<BasicComponent> groupedComponents = new ArrayList<BasicComponent>();
|
||||
|
||||
for (BasicComponent comp : sRS.getGroupedComponents()) {
|
||||
if (comp.getType() == ComponentType.REPEAT_SEQUENCE_DELIMITER) {
|
||||
repeatDelimiterCounter--;
|
||||
}
|
||||
if (comp.getType() != ComponentType.REPEAT_SEQUENCE_INNER)
|
||||
groupedComponents.add(comp);
|
||||
|
||||
if (repeatDelimiterCounter == 0) {
|
||||
toReturn = new RepeatableSequence(groupedComponents, sRS.getHeight());
|
||||
return toReturn;
|
||||
}
|
||||
}
|
||||
return toReturn;
|
||||
}
|
||||
|
||||
private ArrayList<RepeatableSequence> getRepeats() {
|
||||
ArrayList<RepeatableSequence> toReturn = new ArrayList<RepeatableSequence>();
|
||||
int repeatDelimiterCounter = 2;
|
||||
|
||||
ArrayList<BasicComponent> groupedComponents = new ArrayList<BasicComponent>();
|
||||
for (BasicComponent comp : repSequence.getGroupedComponents()) {
|
||||
if (comp.getType() == ComponentType.REPEAT_SEQUENCE_DELIMITER) {
|
||||
repeatDelimiterCounter--;
|
||||
}
|
||||
if (comp.getType() != ComponentType.REPEAT_SEQUENCE_INNER)
|
||||
groupedComponents.add(comp);
|
||||
|
||||
if (repeatDelimiterCounter == 0) {
|
||||
toReturn.add(new RepeatableSequence(groupedComponents, repSequence.getHeight()));
|
||||
repeatDelimiterCounter = 2;
|
||||
groupedComponents = new ArrayList<BasicComponent>();
|
||||
}
|
||||
}
|
||||
//if there is only the first sequence return nothing
|
||||
if (toReturn.size() <= 1) {
|
||||
toReturn = new ArrayList<RepeatableSequence>();
|
||||
}
|
||||
else //return all of them without the first one
|
||||
toReturn.remove(0);
|
||||
return toReturn;
|
||||
}
|
||||
|
||||
public void add(TemplateComponent toAdd) {
|
||||
|
@ -69,6 +101,20 @@ public class ClientRepeatableSequence extends Composite {
|
|||
}
|
||||
}
|
||||
|
||||
protected void addAnother(RepeatableSequence sRS) {
|
||||
SequenceWidget seqW = new SequenceWidget(p, this, sRS, false);
|
||||
myPanel.add(seqW);
|
||||
}
|
||||
/**
|
||||
* remove the widget and its components
|
||||
* @param toRemove
|
||||
*/
|
||||
protected void removeSeqWidget(SequenceWidget toRemove) {
|
||||
myPanel.remove(toRemove);
|
||||
for (TemplateComponent tc : toRemove.getSeqGroupedComponents()) {
|
||||
groupedComponents.remove(tc);
|
||||
}
|
||||
}
|
||||
|
||||
public ArrayList<TemplateComponent> getGroupedComponents() {
|
||||
return groupedComponents;
|
||||
|
|
|
@ -0,0 +1,110 @@
|
|||
package org.gcube.portlets.user.reportgenerator.client.targets;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import org.gcube.portlets.d4sreporting.common.shared.BasicComponent;
|
||||
import org.gcube.portlets.d4sreporting.common.shared.ComponentType;
|
||||
import org.gcube.portlets.d4sreporting.common.shared.RepeatableSequence;
|
||||
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.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 SequenceWidget extends Composite {
|
||||
|
||||
private VerticalPanel myPanel;
|
||||
|
||||
private Button addAnotherB = new Button("Add another entry");
|
||||
private Button removeThisB = new Button("Remove this entry");
|
||||
private Presenter p;
|
||||
private HorizontalPanel buttonPanel = new HorizontalPanel();
|
||||
HorizontalPanel buttonsWrapperPanel = new HorizontalPanel();
|
||||
private ClientRepeatableSequence owner;
|
||||
private RepeatableSequence repSequence;
|
||||
private ArrayList<TemplateComponent> seqGroupedComponents = new ArrayList<TemplateComponent>();
|
||||
|
||||
public SequenceWidget(Presenter p, ClientRepeatableSequence owner, RepeatableSequence repSequence, boolean isFirst) {
|
||||
this.p = p;
|
||||
this.owner = owner;
|
||||
this.repSequence = repSequence;
|
||||
addAnotherB.getElement().getStyle().setMargin(10, Unit.PX);
|
||||
addAnotherB.getElement().getStyle().setHeight(30, Unit.PX);
|
||||
addAnotherB.getElement().getStyle().setWidth(180, Unit.PX);
|
||||
addAnotherB.addStyleName("addEntryButton");
|
||||
myPanel = new VerticalPanel();
|
||||
myPanel.setHorizontalAlignment(HasAlignment.ALIGN_LEFT);
|
||||
myPanel.setStyleName("seqWidget");
|
||||
int size = repSequence.getGroupedComponents().size();
|
||||
GWT.log("SequenceWidget Size = " + size);
|
||||
for (int j = 0; j < size; j++) {
|
||||
BasicComponent sComp = repSequence.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(buttonsWrapperPanel);
|
||||
}
|
||||
add(new TemplateComponent(p.getModel(), sComp, p));
|
||||
}
|
||||
initWidget(myPanel);
|
||||
|
||||
if (isFirst) {
|
||||
buttonsWrapperPanel.add(addAnotherB);
|
||||
addAnotherB.addClickHandler(new ClickHandler() {
|
||||
@Override
|
||||
public void onClick(ClickEvent event) {
|
||||
addAnother();
|
||||
}
|
||||
});
|
||||
}
|
||||
else {
|
||||
removeThisB.getElement().getStyle().setMargin(10, Unit.PX);
|
||||
removeThisB.getElement().getStyle().setHeight(30, Unit.PX);
|
||||
removeThisB.getElement().getStyle().setWidth(180, Unit.PX);
|
||||
removeThisB.addStyleName("deleteEntryButton");
|
||||
buttonsWrapperPanel.add(removeThisB);
|
||||
|
||||
removeThisB.addClickHandler(new ClickHandler() {
|
||||
@Override
|
||||
public void onClick(ClickEvent event) {
|
||||
removeMe();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
public void add(TemplateComponent toAdd) {
|
||||
if (toAdd.getType() != ComponentType.REPEAT_SEQUENCE_INNER) {
|
||||
owner.groupedComponents.add(toAdd);
|
||||
seqGroupedComponents.add(toAdd);
|
||||
GWT.log("ToAdd= getType " + toAdd.getType());
|
||||
myPanel.add(toAdd.getContent());
|
||||
}
|
||||
}
|
||||
|
||||
public ArrayList<TemplateComponent> getSeqGroupedComponents() {
|
||||
return seqGroupedComponents;
|
||||
}
|
||||
|
||||
public void removeAddAnotherButton() {
|
||||
buttonsWrapperPanel.remove(addAnotherB);
|
||||
}
|
||||
|
||||
private void addAnother() {
|
||||
owner.addAnother(repSequence);
|
||||
}
|
||||
|
||||
private void removeMe() {
|
||||
owner.removeSeqWidget(this);
|
||||
}
|
||||
|
||||
}
|
|
@ -1,5 +1,31 @@
|
|||
@import url('reports/old-dialog.css');
|
||||
|
||||
.deleteEntryButton {
|
||||
background-image: none !important;
|
||||
background-repeat: none !important;
|
||||
background-color: #D62222 !important;
|
||||
color: #FFF !important;
|
||||
}
|
||||
|
||||
.deleteEntryButton:hover {
|
||||
color: #FFF !important;
|
||||
}
|
||||
|
||||
.addEntryButton {
|
||||
background-image: none !important;
|
||||
background-repeat: none !important;
|
||||
background-color: #02990C !important;
|
||||
color: #FFF !important;
|
||||
}
|
||||
|
||||
.addEntryButton:hover {
|
||||
color: #FFF !important;
|
||||
}
|
||||
|
||||
.seqWidget {
|
||||
margin-top: 10px;
|
||||
}
|
||||
|
||||
.grouping-inner {
|
||||
background: url('images/grouping-border.png') repeat-x;
|
||||
display: block;
|
||||
|
|
Reference in New Issue