2013-02-13 18:26:22 +01:00
|
|
|
package org.gcube.portlets.user.reportgenerator.client.targets;
|
|
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
|
2013-03-01 19:42:50 +01:00
|
|
|
import org.gcube.portlets.d4sreporting.common.shared.BasicComponent;
|
2013-03-05 19:47:10 +01:00
|
|
|
import org.gcube.portlets.d4sreporting.common.shared.ComponentType;
|
2013-03-01 19:42:50 +01:00
|
|
|
import org.gcube.portlets.d4sreporting.common.shared.RepeatableSequence;
|
2013-02-13 18:26:22 +01:00
|
|
|
import org.gcube.portlets.user.reportgenerator.client.Presenter.Presenter;
|
|
|
|
import org.gcube.portlets.user.reportgenerator.client.model.TemplateComponent;
|
|
|
|
|
2013-02-26 19:44:48 +01:00
|
|
|
import com.google.gwt.user.client.ui.Composite;
|
2013-02-13 18:26:22 +01:00
|
|
|
import com.google.gwt.user.client.ui.VerticalPanel;
|
|
|
|
|
2013-10-30 18:50:22 +01:00
|
|
|
public class ClientRepeatableSequence extends Composite implements ClientSequence {
|
2013-03-05 19:47:10 +01:00
|
|
|
protected ArrayList<TemplateComponent> groupedComponents = new ArrayList<TemplateComponent>();
|
2013-02-13 18:26:22 +01:00
|
|
|
|
2013-03-05 19:47:10 +01:00
|
|
|
private VerticalPanel myPanel = new VerticalPanel();
|
2013-02-26 19:44:48 +01:00
|
|
|
private Presenter p;
|
2013-11-18 18:25:49 +01:00
|
|
|
private String identifier;
|
2013-03-05 19:47:10 +01:00
|
|
|
protected RepeatableSequence repSequence;
|
|
|
|
|
|
|
|
protected RepeatableSequence originalSequence = new RepeatableSequence();
|
2013-02-13 18:26:22 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* constructor used by the system when reading the model
|
2013-03-05 19:47:10 +01:00
|
|
|
* @param sRS the sequence to repeat
|
2013-02-13 18:26:22 +01:00
|
|
|
*/
|
2013-03-01 19:42:50 +01:00
|
|
|
public ClientRepeatableSequence(Presenter p, RepeatableSequence sRS) {
|
2013-02-13 18:26:22 +01:00
|
|
|
this.p = p;
|
2013-03-05 19:47:10 +01:00
|
|
|
this.repSequence = sRS;
|
2013-11-18 18:25:49 +01:00
|
|
|
this.identifier = sRS.getKey();
|
2013-03-05 19:47:10 +01:00
|
|
|
this.originalSequence = extractOriginalSequence(sRS);
|
2013-12-06 11:35:34 +01:00
|
|
|
SequenceWidget seqW = new SequenceWidget(p, this, originalSequence, false, false); //TODO: Now all seq are removable, need to be handled differently
|
2013-03-05 19:47:10 +01:00
|
|
|
myPanel.add(seqW);
|
|
|
|
|
|
|
|
for (RepeatableSequence repeatSeq : getRepeats()) {
|
|
|
|
addAnother(repeatSeq);
|
2013-02-13 18:26:22 +01:00
|
|
|
}
|
2013-02-26 19:44:48 +01:00
|
|
|
initWidget(myPanel);
|
2013-03-05 19:47:10 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2013-12-06 11:35:34 +01:00
|
|
|
* when you repeat a sequence the model is not able to recognize if this was a sequence or not
|
|
|
|
* to overcome this limitation you have to identify the original sequence
|
2013-03-05 19:47:10 +01:00
|
|
|
* 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--;
|
2013-02-26 19:44:48 +01:00
|
|
|
}
|
2013-03-05 19:47:10 +01:00
|
|
|
if (comp.getType() != ComponentType.REPEAT_SEQUENCE_INNER)
|
|
|
|
groupedComponents.add(comp);
|
|
|
|
|
|
|
|
if (repeatDelimiterCounter == 0) {
|
|
|
|
toReturn = new RepeatableSequence(groupedComponents, sRS.getHeight());
|
|
|
|
return toReturn;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return toReturn;
|
|
|
|
}
|
2013-10-30 18:50:22 +01:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @return
|
|
|
|
*/
|
2013-03-05 19:47:10 +01:00
|
|
|
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;
|
2013-02-13 18:26:22 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public void add(TemplateComponent toAdd) {
|
2013-02-26 19:44:48 +01:00
|
|
|
if (toAdd.getType() != ComponentType.REPEAT_SEQUENCE_INNER) {
|
|
|
|
groupedComponents.add(toAdd);
|
|
|
|
myPanel.add(toAdd.getContent());
|
|
|
|
}
|
2013-02-13 18:26:22 +01:00
|
|
|
}
|
|
|
|
|
2013-03-05 19:47:10 +01:00
|
|
|
protected void addAnother(RepeatableSequence sRS) {
|
2013-03-06 19:06:42 +01:00
|
|
|
SequenceWidget seqW = new SequenceWidget(p, this, sRS, false, false);
|
|
|
|
myPanel.add(seqW);
|
|
|
|
}
|
|
|
|
|
2013-10-30 18:50:22 +01:00
|
|
|
|
2013-03-06 19:06:42 +01:00
|
|
|
protected void addNew(RepeatableSequence sRS) {
|
|
|
|
SequenceWidget seqW = new SequenceWidget(p, this, sRS, false, true);
|
2013-03-05 19:47:10 +01:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
2013-10-30 18:50:22 +01:00
|
|
|
|
|
|
|
@Override
|
2013-02-13 18:26:22 +01:00
|
|
|
public ArrayList<TemplateComponent> getGroupedComponents() {
|
|
|
|
return groupedComponents;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setGroupedComponents(ArrayList<TemplateComponent> groupedComponents) {
|
|
|
|
this.groupedComponents = groupedComponents;
|
2013-10-30 18:50:22 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2013-11-14 16:26:26 +01:00
|
|
|
public boolean add(String id, RepeatableSequence sequence) {
|
2013-10-30 18:50:22 +01:00
|
|
|
SequenceWidget seqW = new SequenceWidget(p, this, sequence, false, true);
|
|
|
|
myPanel.add(seqW);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public SequenceWidget remove(SequenceWidget toRemove) {
|
|
|
|
myPanel.remove(toRemove);
|
|
|
|
for (TemplateComponent tc : toRemove.getSeqGroupedComponents()) {
|
|
|
|
groupedComponents.remove(tc);
|
|
|
|
}
|
|
|
|
return toRemove;
|
2013-11-14 16:26:26 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void AddButtonClicked(RepeatableSequence sequence) {
|
|
|
|
add("not needed", sequence);
|
2013-11-18 18:25:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public String getIdentifier() {
|
|
|
|
return identifier;
|
2013-02-26 19:44:48 +01:00
|
|
|
}
|
2013-11-18 18:25:49 +01:00
|
|
|
|
|
|
|
|
2013-02-13 18:26:22 +01:00
|
|
|
}
|