This repository has been archived on 2021-11-25. You can view files and clone it, but cannot push or open issues or pull requests.
vmereports-manager-portlet/src/main/java/org/gcube/portlets/user/reportgenerator/client/targets/AttributeArea.java

143 lines
4.2 KiB
Java

package org.gcube.portlets.user.reportgenerator.client.targets;
import org.gcube.portlets.d4sreporting.common.shared.ComponentType;
import org.gcube.portlets.d4sreporting.common.shared.SerializableAttribute;
import org.gcube.portlets.d4sreporting.common.shared.SerializableAttributeArea;
import org.gcube.portlets.user.reportgenerator.client.Presenter.Presenter;
import com.google.gwt.core.client.GWT;
import com.google.gwt.dom.client.Style.Unit;
import com.google.gwt.user.client.ui.CheckBox;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.HTML;
import com.google.gwt.user.client.ui.HasHorizontalAlignment;
import com.google.gwt.user.client.ui.HasVerticalAlignment;
import com.google.gwt.user.client.ui.HorizontalPanel;
/**
* <code> AttributeArea </code> class
*
* @author Massimiliano Assante, ISTI-CNR - massimiliano.assante@isti.cnr.it
* @version April 2011 (1.0)
*/
public class AttributeArea extends Composite {
private HorizontalPanel myPanel;
private HTML attrName;
private CheckBox[] boxes;
/**
* Coming form a template constructor
*/
public AttributeArea(final Presenter presenter, int left, int top, int width, final int height, String textToDisplay) {
myPanel = new HorizontalPanel();
myPanel.setTitle("Attribute Area");
myPanel.setVerticalAlignment(HasVerticalAlignment.ALIGN_BOTTOM);
myPanel.setPixelSize(width, 20);
myPanel.addStyleName("attributeArea");
attrName = new HTML(getAttributeName(textToDisplay));
attrName.getElement().getStyle().setMarginLeft(25, Unit.PX);
attrName.getElement().getStyle().setMarginRight(5, Unit.PX);
HorizontalPanel boxesPanel = new HorizontalPanel();
boxesPanel.add(attrName);
myPanel.add(boxesPanel);
myPanel.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_LEFT);
boxes = getCheckboxes(textToDisplay);
for (int i = 0; i < boxes.length; i++) {
boxesPanel.add(boxes[i]);
}
initWidget(myPanel);
}
/**
* Coming form a report constructor
*/
public AttributeArea(final Presenter presenter, int left, int top, int width, final int height, SerializableAttributeArea sata) {
myPanel = new HorizontalPanel();
myPanel.setTitle("Attribute Area");
myPanel.setVerticalAlignment(HasVerticalAlignment.ALIGN_BOTTOM);
myPanel.setPixelSize(width, 20);
myPanel.addStyleName("attributeArea");
attrName = new HTML(sata.getAttrName(), true);
attrName.getElement().getStyle().setMarginLeft(10, Unit.PX);
attrName.getElement().getStyle().setMarginRight(5, Unit.PX);
HorizontalPanel boxesPanel = new HorizontalPanel();
boxesPanel.add(attrName);
myPanel.add(boxesPanel);
myPanel.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_LEFT);
int values = sata.getValues().size();
boxes = new CheckBox[values];
int j = 0;
for (SerializableAttribute attr: sata.getValues()) {
CheckBox toAdd = new CheckBox(attr.getName());
toAdd.setStyleName("checkAttribute");
toAdd.setValue(attr.getValue());
boxes[j] = toAdd;
j++;
}
//adding it to the panel
for (int i = 0; i < boxes.length; i++) {
boxesPanel.add(boxes[i]);
}
initWidget(myPanel);
}
/**
*
* @param toParse
* @return
*/
private String getAttributeName(String toParse) {
if (toParse == null)
return "";
String toReturn = "";
try {
toReturn = toParse.substring(0, toParse.indexOf(":"));
} catch (StringIndexOutOfBoundsException e) {
GWT.log("Could not find : returning empty");
}
return toReturn;
}
/**
*
* @param toParse
* @return
*/
private CheckBox[] getCheckboxes(String toParse) {
String toSplit = toParse.substring(toParse.indexOf(":")+1, toParse.length());
String[] values = toSplit.split("\\|");
GWT.log("toSplit" + toSplit);
GWT.log("values" + values.length);
CheckBox[] boxes = new CheckBox[values.length];
for (int i = 0; i < values.length; i++) {
boxes[i] = new CheckBox();
boxes[i].setStyleName("checkAttribute");
boxes[i].setText(" " + values[i].trim());
}
return boxes;
}
/**
*
* @return
*/
public ComponentType getType() {
return ComponentType.ATTRIBUTE;
}
/**
*
* @return
*/
public CheckBox[] getBoxes() {
return boxes;
}
/**
*
* @return
*/
public String getAttrName() {
return attrName.getText();
}
}