Added TreeGrid Validation

git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/portlets/user/tabular-data-table-widget@95436 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Giancarlo Panichi 2014-05-08 13:20:56 +00:00 committed by Giancarlo Panichi
parent 593808b243
commit 466b6521d5
10 changed files with 457 additions and 0 deletions

View File

@ -69,5 +69,11 @@ public interface ResourceBundle extends ClientBundle {
@Source("arrow-undo-all_32.png")
ImageResource undoAll32();
@Source("table-validation.png")
ImageResource tableValidation();
@Source("table-validation_32.png")
ImageResource tableValidation32();
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 881 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.7 KiB

View File

@ -0,0 +1,269 @@
package org.gcube.portlets.user.td.tablewidget.client.validation;
import java.util.ArrayList;
import java.util.List;
import org.gcube.portlets.user.td.gwtservice.client.rpc.TDGWTServiceAsync;
import org.gcube.portlets.user.td.gwtservice.shared.task.ValidationsTasksMetadata;
import org.gcube.portlets.user.td.tablewidget.client.resources.ResourceBundle;
import org.gcube.portlets.user.td.tablewidget.client.util.UtilsGXT3;
import org.gcube.portlets.user.td.tablewidget.client.validation.tree.BaseDto;
import org.gcube.portlets.user.td.tablewidget.client.validation.tree.FolderDto;
import org.gcube.portlets.user.td.tablewidget.client.validation.tree.TreeDataGenerator;
import org.gcube.portlets.user.td.tablewidget.client.validation.tree.ValidationDto;
import org.gcube.portlets.user.td.widgetcommonevent.shared.TRId;
import com.allen_sauer.gwt.log.client.Log;
import com.google.gwt.cell.client.AbstractCell;
import com.google.gwt.safehtml.shared.SafeHtmlBuilder;
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.web.bindery.event.shared.EventBus;
import com.sencha.gxt.core.client.ToStringValueProvider;
import com.sencha.gxt.core.client.ValueProvider;
import com.sencha.gxt.core.client.dom.ScrollSupport.ScrollMode;
import com.sencha.gxt.data.shared.ModelKeyProvider;
import com.sencha.gxt.data.shared.TreeStore;
import com.sencha.gxt.widget.core.client.FramedPanel;
import com.sencha.gxt.widget.core.client.container.VerticalLayoutContainer;
import com.sencha.gxt.widget.core.client.container.VerticalLayoutContainer.VerticalLayoutData;
import com.sencha.gxt.widget.core.client.grid.ColumnConfig;
import com.sencha.gxt.widget.core.client.grid.ColumnModel;
import com.sencha.gxt.widget.core.client.treegrid.TreeGrid;
/**
*
* @author "Giancarlo Panichi" <a
* href="mailto:g.panichi@isti.cnr.it">g.panichi@isti.cnr.it</a>
*
*/
public class ValidationsTasksPanel extends FramedPanel {
protected String WIDTH = "298px";
protected String HEIGHT = "520px";
protected TRId trId;
protected VerticalLayoutContainer vl;
protected EventBus eventBus;
protected ValidationsTasksMetadata validationsTasksMetadata;
protected TreeDataGenerator gen;
protected TreeStore<BaseDto> store;
class KeyProvider implements ModelKeyProvider<BaseDto> {
@Override
public String getKey(BaseDto item) {
return (item instanceof FolderDto ? "f-" : "m-")
+ item.getId().toString();
}
}
public ValidationsTasksPanel(EventBus eventBus) {
super();
this.eventBus = eventBus;
forceLayoutOnResize = true;
retrieveCurrentTR();
}
public ValidationsTasksPanel(TRId trId, EventBus eventBus) {
super();
this.trId = trId;
this.eventBus = eventBus;
forceLayoutOnResize = true;
draw();
}
protected void draw() {
init();
retrieveValidations();
}
protected void init() {
setWidth(WIDTH);
setHeight(HEIGHT);
setHeaderVisible(false);
setBodyBorder(false);
}
protected void createTreeData(){
gen=new TreeDataGenerator(validationsTasksMetadata);
create();
}
protected void create() {
vl = new VerticalLayoutContainer();
vl.setScrollMode(ScrollMode.AUTO);
vl.setAdjustForScroll(true);
this.add(vl);
store = new TreeStore<BaseDto>(new KeyProvider());
FolderDto root = gen.getRoot();
for (BaseDto base : root.getChildren()) {
store.add(base);
if (base instanceof FolderDto) {
processFolder(store, (FolderDto) base);
}
}
ColumnConfig<BaseDto, String> cc1 = new ColumnConfig<BaseDto, String>(
new ToStringValueProvider<BaseDto>("task"));
cc1.setHeader("Task");
ColumnConfig<BaseDto, String> cc2 = new ColumnConfig<BaseDto, String>(
new ValueProvider<BaseDto, String>() {
@Override
public String getValue(BaseDto object) {
return object instanceof ValidationDto ? ((ValidationDto) object)
.getDescription() : "";
}
@Override
public void setValue(BaseDto object, String value) {
if (object instanceof ValidationDto) {
((ValidationDto) object).setDescription(value);
}
}
@Override
public String getPath() {
return "description";
}
});
cc2.setHeader("Description");
ColumnConfig<BaseDto, Boolean> cc3 = new ColumnConfig<BaseDto, Boolean>(
new ValueProvider<BaseDto, Boolean>() {
@Override
public Boolean getValue(BaseDto object) {
return object instanceof ValidationDto ? ((ValidationDto) object)
.getValid() : false;
}
@Override
public void setValue(BaseDto object, Boolean value) {
if (object instanceof ValidationDto) {
((ValidationDto) object).setValid(value);
}
}
@Override
public String getPath() {
return "valid";
}
});
cc3.setHeader("Valid");
cc3.setCell(new AbstractCell<Boolean>() {
@Override
public void render(Context context, Boolean value,
SafeHtmlBuilder sb) {
if (value) {
sb.appendHtmlConstant("<img src='"
+ ResourceBundle.INSTANCE.ok().getSafeUri()
.asString() + "' alt='true'>");
} else {
sb.appendHtmlConstant("<img src='"
+ ResourceBundle.INSTANCE.exit().getSafeUri()
.asString() + "' alt='true'>");
}
}
});
List<ColumnConfig<BaseDto, ?>> l = new ArrayList<ColumnConfig<BaseDto, ?>>();
l.add(cc1);
l.add(cc2);
l.add(cc3);
ColumnModel<BaseDto> cm = new ColumnModel<BaseDto>(l);
final TreeGrid<BaseDto> tree = new TreeGrid<BaseDto>(store, cm, cc1);
tree.getStyle().setLeafIcon(ResourceBundle.INSTANCE.tableValidation());
tree.getView().setAutoExpandColumn(cc1);
/*
* ToolBar buttonBar = new ToolBar();
*
* buttonBar.add(new TextButton("Expand All", new SelectHandler() {
*
* @Override public void onSelect(SelectEvent event) { tree.expandAll();
* } })); buttonBar.add(new TextButton("Collapse All", new
* SelectHandler() {
*
* @Override public void onSelect(SelectEvent event) {
* tree.collapseAll(); } }));
*
* v.add(buttonBar, new VerticalLayoutData(1, -1));
*/
vl.add(tree, new VerticalLayoutData(1, 1));
}
protected void retrieveValidations() {
TDGWTServiceAsync.INSTANCE.getValidationsTasksMetadata(trId,
new AsyncCallback<ValidationsTasksMetadata>() {
public void onFailure(Throwable caught) {
Log.error("Load validations metadata failure: "
+ caught.getLocalizedMessage());
UtilsGXT3.alert(
"Error retrieving validations metadata",
"Error retrieving validations metadata");
}
public void onSuccess(ValidationsTasksMetadata result) {
Log.debug("loaded " + result.getId());
validationsTasksMetadata = result;
createTreeData();
}
});
}
public void update() {
retrieveCurrentTR();
}
public void update(TRId trId) {
this.trId = trId;
draw();
}
protected void retrieveCurrentTR() {
TDGWTServiceAsync.INSTANCE.getCurrentTRId(new AsyncCallback<TRId>() {
public void onFailure(Throwable caught) {
Log.error("Error retrieving current TRId: "
+ caught.getLocalizedMessage());
UtilsGXT3.alert("Error",
"Error retrieving current tabular resource id");
}
public void onSuccess(TRId result) {
Log.debug("retrieved " + result);
trId = result;
draw();
}
});
}
private void processFolder(TreeStore<BaseDto> store, FolderDto folder) {
for (BaseDto child : folder.getChildren()) {
store.add(folder, child);
if (child instanceof FolderDto) {
processFolder(store, (FolderDto) child);
}
}
}
}

View File

@ -0,0 +1,32 @@
package org.gcube.portlets.user.td.tablewidget.client.validation.tree;
import java.io.Serializable;
/**
*
* @author "Giancarlo Panichi"
*
*/
public class BaseDto implements Serializable {
private static final long serialVersionUID = -5535466371215737037L;
protected String id;
public BaseDto(){
}
public BaseDto(String id){
this.id=id;
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
}

View File

@ -0,0 +1,55 @@
package org.gcube.portlets.user.td.tablewidget.client.validation.tree;
import java.util.ArrayList;
/**
*
* @author "Giancarlo Panichi"
*
*/
public class FolderDto extends BaseDto {
private static final long serialVersionUID = 4644048540524701598L;
protected String description;
protected ArrayList<BaseDto> childrens;
public FolderDto(){
}
public FolderDto(String id,String description, ArrayList<BaseDto> childrens){
super(id);
this.description=description;
this.childrens=childrens;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public ArrayList<BaseDto> getChildren() {
return childrens;
}
public void setChildren(ArrayList<BaseDto> children) {
this.childrens = children;
}
@Override
public String toString() {
return "FolderDto [id="+id+", description=" + description + ", childrens="
+ childrens + "]";
}
}

View File

@ -0,0 +1,46 @@
package org.gcube.portlets.user.td.tablewidget.client.validation.tree;
import java.util.ArrayList;
import org.gcube.portlets.user.td.gwtservice.shared.task.JobS;
import org.gcube.portlets.user.td.gwtservice.shared.task.TaskS;
import org.gcube.portlets.user.td.gwtservice.shared.task.ValidationsTasksMetadata;
import org.gcube.portlets.user.td.gwtservice.shared.tr.table.Validations;
import com.google.gwt.i18n.client.DateTimeFormat;
public class TreeDataGenerator {
protected DateTimeFormat sdf = DateTimeFormat
.getFormat("yyyy-MM-dd HH:mm:ss");
protected FolderDto root;
public TreeDataGenerator(ValidationsTasksMetadata validationsTasksMetadata) {
if (validationsTasksMetadata.getTasks().size() > 0) {
ArrayList<BaseDto> childrens = new ArrayList<BaseDto>();
for (TaskS task : validationsTasksMetadata.getTasks()) {
ArrayList<BaseDto> jobs = new ArrayList<BaseDto>();
for (JobS job : task.getJobs()) {
ArrayList<BaseDto> validations = new ArrayList<BaseDto>();
for (Validations v : job.getValidations()) {
ValidationDto validationDto = new ValidationDto(
v.getDescription(), v.isValid());
validations.add(validationDto);
}
FolderDto foldJob = new FolderDto(job.getId(),
job.getDescription(), validations);
jobs.add(foldJob);
}
FolderDto foldTask = new FolderDto(task.getId(),
sdf.format(task.getStartTime()), jobs);
childrens.add(foldTask);
}
root = new FolderDto("0", "root", childrens);
}
}
public FolderDto getRoot() {
return root;
}
}

View File

@ -0,0 +1,49 @@
package org.gcube.portlets.user.td.tablewidget.client.validation.tree;
/**
*
* @author "Giancarlo Panichi"
*
*/
public class ValidationDto extends BaseDto {
private static final long serialVersionUID = -4353641080571614057L;
protected String description;
protected Boolean valid;
public ValidationDto(){
}
public ValidationDto(String description, Boolean valid){
this.description=description;
this.valid=valid;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public Boolean getValid() {
return valid;
}
public void setValid(Boolean valid) {
this.valid = valid;
}
@Override
public String toString() {
return "ValidationDto [description=" + description + ", valid=" + valid
+ "]";
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 881 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.7 KiB