216 lines
6.5 KiB
Java
216 lines
6.5 KiB
Java
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.Metadata;
|
|
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 Entry");
|
|
private Button selectNewB = new Button("Add Source");
|
|
private Button clearB = new Button("Clear Association");
|
|
|
|
private HorizontalPanel buttonPanel = new HorizontalPanel();
|
|
HorizontalPanel buttonsWrapperPanel = new HorizontalPanel();
|
|
private ClientSequence owner;
|
|
private RepeatableSequence repSequence;
|
|
private ArrayList<TemplateComponent> seqGroupedComponents = new ArrayList<TemplateComponent>();
|
|
|
|
//in case of references tells if the ref is empty
|
|
private boolean isEmptyRef = false;
|
|
|
|
public SequenceWidget(Presenter p, ClientSequence owner, RepeatableSequence repSequence, boolean notRemovable, boolean isNew) {
|
|
this.owner = owner;
|
|
this.repSequence = repSequence;
|
|
addAnotherB.getElement().getStyle().setMargin(10, Unit.PX);
|
|
addAnotherB.getElement().getStyle().setWidth(130, Unit.PX);
|
|
addAnotherB.addStyleName("addEntryButton");
|
|
buttonPanel.getElement().getStyle().setMarginTop(20, Unit.PX);
|
|
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);
|
|
}
|
|
//if isNew and is not locked and is of type BODY then put fields to blank
|
|
if (isNew && (!sComp.isLocked()) &&
|
|
(sComp.getType() == ComponentType.BODY ||
|
|
sComp.getType() == ComponentType.BODY_NOT_FORMATTED ||
|
|
sComp.getType() == ComponentType.DYNA_IMAGE) ) {
|
|
sComp.setPossibleContent("");
|
|
sComp.setMetadata(new ArrayList<Metadata>());
|
|
}
|
|
TemplateComponent toAdd = new TemplateComponent(p.getModel(), sComp, p, false, null);
|
|
if (isNew && sComp.getType() == ComponentType.REPORT_REFERENCE ) { //when adding a new Sequence blanks the Ref
|
|
ClientReportReference cRef = (ClientReportReference) toAdd.getContent();
|
|
cRef.clear();
|
|
}
|
|
add(toAdd);
|
|
|
|
|
|
} //end for
|
|
initWidget(myPanel);
|
|
|
|
if (notRemovable) {
|
|
buttonsWrapperPanel.add(addAnotherB);
|
|
addAnotherB.addClickHandler(new ClickHandler() {
|
|
@Override
|
|
public void onClick(ClickEvent event) {
|
|
addAnother();
|
|
}
|
|
});
|
|
}
|
|
else {
|
|
|
|
removeThisB.getElement().getStyle().setWidth(130, Unit.PX);
|
|
removeThisB.getElement().getStyle().setMargin(10, Unit.PX);
|
|
removeThisB.addStyleName("deleteEntryButton");
|
|
buttonsWrapperPanel.add(removeThisB);
|
|
|
|
removeThisB.addClickHandler(new ClickHandler() {
|
|
@Override
|
|
public void onClick(ClickEvent event) {
|
|
removeMe();
|
|
}
|
|
});
|
|
|
|
buttonsWrapperPanel.add(addAnotherB);
|
|
addAnotherB.addClickHandler(new ClickHandler() {
|
|
@Override
|
|
public void onClick(ClickEvent event) {
|
|
addAnother();
|
|
}
|
|
});
|
|
|
|
|
|
}
|
|
}
|
|
|
|
protected boolean hideClearAssociationButton() {
|
|
return buttonsWrapperPanel.remove(clearB);
|
|
}
|
|
|
|
protected boolean hideAddEntryButton() {
|
|
return buttonsWrapperPanel.remove(addAnotherB);
|
|
}
|
|
|
|
private void addAnother() {
|
|
owner.AddButtonClicked(repSequence);
|
|
}
|
|
|
|
private void selectNew() {
|
|
owner.AddButtonClicked(repSequence);
|
|
}
|
|
|
|
public void enableClear() {
|
|
clearB.getElement().getStyle().setWidth(130, Unit.PX);
|
|
clearB.getElement().getStyle().setMargin(10, Unit.PX);
|
|
clearB.addStyleName("deleteAssociationButton");
|
|
|
|
clearB.addClickHandler(new ClickHandler() {
|
|
@Override
|
|
public void onClick(ClickEvent event) {
|
|
clearAssociation();
|
|
}
|
|
});
|
|
|
|
buttonsWrapperPanel.insert(clearB, 0);
|
|
|
|
}
|
|
|
|
public void clearAssociation() {
|
|
|
|
GWT.log("Clearing Association");
|
|
//in the MODEL leave only the delimiters
|
|
ArrayList<BasicComponent> cleanedRef = new ArrayList<BasicComponent>();
|
|
for (BasicComponent bc : repSequence.getGroupedComponents()) {
|
|
if (bc.getType() == ComponentType.REPEAT_SEQUENCE_DELIMITER) {
|
|
cleanedRef.add(bc);
|
|
}
|
|
}
|
|
repSequence.setGroupedComponents(cleanedRef);
|
|
|
|
//in the VIEW
|
|
for (TemplateComponent tc : seqGroupedComponents) {
|
|
if (tc.getType() == ComponentType.BODY_NOT_FORMATTED || tc.getType() == ComponentType.HEADING_2) {
|
|
myPanel.remove(tc.getContent());
|
|
}
|
|
}
|
|
|
|
buttonsWrapperPanel.clear();
|
|
selectNewB.getElement().getStyle().setWidth(130, Unit.PX);
|
|
selectNewB.getElement().getStyle().setMargin(10, Unit.PX);
|
|
selectNewB.addStyleName("deleteAssociationButton");
|
|
|
|
selectNewB.addClickHandler(new ClickHandler() {
|
|
@Override
|
|
public void onClick(ClickEvent event) {
|
|
selectNew();
|
|
}
|
|
});
|
|
|
|
buttonsWrapperPanel.add(selectNewB);
|
|
isEmptyRef = true;
|
|
}
|
|
|
|
protected boolean isAnEmptyRef() {
|
|
return isEmptyRef;
|
|
}
|
|
|
|
public void add(TemplateComponent toAdd) {
|
|
if (toAdd.getType() != ComponentType.REPEAT_SEQUENCE_INNER) {
|
|
owner.getGroupedComponents().add(toAdd);
|
|
seqGroupedComponents.add(toAdd);
|
|
myPanel.add(toAdd.getContent());
|
|
}
|
|
}
|
|
|
|
public ArrayList<TemplateComponent> getSeqGroupedComponents() {
|
|
return seqGroupedComponents;
|
|
}
|
|
|
|
public void removeAddAnotherButton() {
|
|
buttonsWrapperPanel.remove(addAnotherB);
|
|
}
|
|
|
|
|
|
|
|
private void removeMe() {
|
|
owner.remove(this);
|
|
}
|
|
|
|
public RepeatableSequence getSequence() {
|
|
return repSequence;
|
|
}
|
|
|
|
public void alignButtonsLeft() {
|
|
buttonPanel.setWidth("10%");
|
|
}
|
|
}
|