2013-10-30 18:50:22 +01:00
|
|
|
package org.gcube.portlets.user.reportgenerator.client.targets;
|
|
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
|
2013-10-31 00:51:45 +01:00
|
|
|
import org.gcube.portlets.d4sreporting.common.shared.Tuple;
|
2013-10-30 18:50:22 +01:00
|
|
|
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;
|
2013-11-13 18:56:13 +01:00
|
|
|
import org.gcube.portlets.user.reportgenerator.shared.VMETypeIdentifier;
|
2013-10-30 18:50:22 +01:00
|
|
|
|
2013-11-14 16:26:26 +01:00
|
|
|
import com.google.gwt.core.shared.GWT;
|
|
|
|
import com.google.gwt.event.dom.client.HasClickHandlers;
|
2013-11-13 18:56:13 +01:00
|
|
|
import com.google.gwt.user.client.Window;
|
2013-10-30 18:50:22 +01:00
|
|
|
import com.google.gwt.user.client.ui.Composite;
|
|
|
|
import com.google.gwt.user.client.ui.VerticalPanel;
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @author massi
|
|
|
|
*
|
|
|
|
*/
|
2013-10-31 00:51:45 +01:00
|
|
|
public class ClientTuple extends Composite implements ClientSequence {
|
|
|
|
|
2013-10-30 18:50:22 +01:00
|
|
|
protected ArrayList<TemplateComponent> groupedComponents = new ArrayList<TemplateComponent>();
|
|
|
|
private VerticalPanel myPanel = new VerticalPanel();
|
|
|
|
|
2013-10-31 00:51:45 +01:00
|
|
|
private ArrayList<Tuple> tupleList;
|
|
|
|
private SequenceWidget first;
|
2013-11-13 18:56:13 +01:00
|
|
|
private Presenter p;
|
2013-10-30 18:50:22 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* s
|
|
|
|
* @param p
|
|
|
|
* @param ms
|
|
|
|
*/
|
2013-10-31 00:51:45 +01:00
|
|
|
public ClientTuple(Presenter p, ArrayList<Tuple> tupleList) {
|
2013-11-13 18:56:13 +01:00
|
|
|
this.p = p;
|
2013-10-31 00:51:45 +01:00
|
|
|
this.tupleList = tupleList;
|
|
|
|
for (Tuple seq : tupleList) {
|
|
|
|
if (myPanel.getWidgetCount()==0) { // if is the first one
|
2013-11-14 16:26:26 +01:00
|
|
|
first = getMasterSequence(seq);
|
2013-10-31 00:51:45 +01:00
|
|
|
myPanel.add(first);
|
|
|
|
} else {
|
|
|
|
SequenceWidget seqW = new SequenceWidget(p, this, seq, false, false);
|
|
|
|
myPanel.add(seqW);
|
2013-11-14 16:26:26 +01:00
|
|
|
}
|
2013-10-30 18:50:22 +01:00
|
|
|
}
|
|
|
|
initWidget(myPanel);
|
|
|
|
}
|
2013-11-14 16:26:26 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* the first seq has to behave differently
|
|
|
|
*/
|
|
|
|
private SequenceWidget getMasterSequence(RepeatableSequence seq) {
|
|
|
|
SequenceWidget toReturn = new SequenceWidget(p, this, seq, true, false);
|
|
|
|
if (tupleList.size() == 1) {
|
|
|
|
toReturn.enableClear();
|
|
|
|
}
|
|
|
|
return toReturn;
|
|
|
|
}
|
2013-10-31 00:51:45 +01:00
|
|
|
|
|
|
|
|
|
|
|
public ArrayList<Tuple> getTupleList() {
|
|
|
|
return tupleList;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void setTupleList(ArrayList<Tuple> tupleList) {
|
|
|
|
this.tupleList = tupleList;
|
|
|
|
}
|
|
|
|
|
2013-10-30 18:50:22 +01:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public ArrayList<TemplateComponent> getGroupedComponents() {
|
|
|
|
return groupedComponents;
|
|
|
|
}
|
2013-10-31 00:51:45 +01:00
|
|
|
|
2013-10-30 18:50:22 +01:00
|
|
|
@Override
|
2013-11-14 16:26:26 +01:00
|
|
|
public boolean add(String id, RepeatableSequence sequence) {
|
|
|
|
if (first.isSelectNewEnabled()) {
|
|
|
|
first = getMasterSequence(sequence);
|
|
|
|
myPanel.clear();
|
|
|
|
myPanel.add(first);
|
|
|
|
tupleList.clear();
|
|
|
|
} else {
|
|
|
|
SequenceWidget seqW = new SequenceWidget(p, this, sequence, false, true);
|
|
|
|
myPanel.add(seqW);
|
|
|
|
first.hideClearAssociationButton();
|
2013-11-13 18:56:13 +01:00
|
|
|
}
|
2013-11-14 16:26:26 +01:00
|
|
|
//needed for the model //TODO: preserve the id!!
|
|
|
|
Tuple toAdd = new Tuple(id, sequence.getGroupedComponents());
|
|
|
|
tupleList.add(toAdd);
|
2013-11-13 18:56:13 +01:00
|
|
|
return true;
|
2013-10-30 18:50:22 +01:00
|
|
|
}
|
2013-10-31 00:51:45 +01:00
|
|
|
|
|
|
|
|
2013-10-30 18:50:22 +01:00
|
|
|
@Override
|
|
|
|
public SequenceWidget remove(SequenceWidget toRemove) {
|
|
|
|
myPanel.remove(toRemove);
|
|
|
|
for (TemplateComponent tc : toRemove.getSeqGroupedComponents()) {
|
|
|
|
groupedComponents.remove(tc);
|
|
|
|
}
|
2013-10-31 00:51:45 +01:00
|
|
|
tupleList.remove(toRemove.getSequence());
|
|
|
|
if (tupleList.size() == 1)
|
|
|
|
first.enableClear();
|
2013-11-14 16:26:26 +01:00
|
|
|
|
|
|
|
GWT.log("List Tuple Size = "+tupleList.size());
|
2013-10-30 18:50:22 +01:00
|
|
|
return toRemove;
|
|
|
|
}
|
|
|
|
|
2013-11-14 16:26:26 +01:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public void AddButtonClicked(RepeatableSequence sequence) {
|
|
|
|
Tuple tuple = (Tuple) sequence;
|
|
|
|
VMETypeIdentifier type2Pass = null;
|
|
|
|
try {
|
|
|
|
type2Pass = p.getTypeIdFromString(tuple.getKey());
|
|
|
|
} catch (Exception e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
}
|
|
|
|
p.showVMERefAssociateDialog(type2Pass);
|
|
|
|
p.setClientSequenceSelected(this); //important!
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2013-10-30 18:50:22 +01:00
|
|
|
}
|