diff --git a/src/main/java/org/gcube/portlets/user/td/tablewidget/client/custom/ValidationButton.css b/src/main/java/org/gcube/portlets/user/td/tablewidget/client/custom/ValidationButton.css new file mode 100644 index 0000000..8be4ac0 --- /dev/null +++ b/src/main/java/org/gcube/portlets/user/td/tablewidget/client/custom/ValidationButton.css @@ -0,0 +1,3 @@ +.image { + cursor: pointer; +} \ No newline at end of file diff --git a/src/main/java/org/gcube/portlets/user/td/tablewidget/client/custom/ValidationButton.html b/src/main/java/org/gcube/portlets/user/td/tablewidget/client/custom/ValidationButton.html new file mode 100644 index 0000000..fdb54aa --- /dev/null +++ b/src/main/java/org/gcube/portlets/user/td/tablewidget/client/custom/ValidationButton.html @@ -0,0 +1 @@ +
{img}
\ No newline at end of file diff --git a/src/main/java/org/gcube/portlets/user/td/tablewidget/client/custom/ValidationCell.java b/src/main/java/org/gcube/portlets/user/td/tablewidget/client/custom/ValidationCell.java new file mode 100644 index 0000000..d675340 --- /dev/null +++ b/src/main/java/org/gcube/portlets/user/td/tablewidget/client/custom/ValidationCell.java @@ -0,0 +1,94 @@ +package org.gcube.portlets.user.td.tablewidget.client.custom; + + +import com.google.gwt.cell.client.ValueUpdater; +import com.google.gwt.core.client.GWT; +import com.google.gwt.dom.client.Element; +import com.google.gwt.dom.client.NativeEvent; +import com.google.gwt.event.shared.HandlerRegistration; +import com.google.gwt.resources.client.ImageResource; +import com.google.gwt.safehtml.shared.SafeHtmlBuilder; +import com.sencha.gxt.cell.core.client.ResizeCell; +import com.sencha.gxt.core.client.dom.XElement; +import com.sencha.gxt.widget.core.client.event.BeforeSelectEvent; +import com.sencha.gxt.widget.core.client.event.SelectEvent; +import com.sencha.gxt.widget.core.client.event.SelectEvent.HasSelectHandlers; +import com.sencha.gxt.widget.core.client.event.SelectEvent.SelectHandler; + +/** + * + * @author "Giancarlo Panichi" + * + */ +public class ValidationCell extends ResizeCell implements HasSelectHandlers { + + private final ValidationCellAppearance appearance; + private ImageResource trueIcon; + private ImageResource falseIcon; + private String title; + + public ValidationCell() { + this(GWT. create(ValidationCellAppearance.class)); + } + + public ValidationCell(ValidationCellAppearance appearance) { + super("click"); + this.appearance = appearance; + } + + public void setTrueIcon(ImageResource icon) { + this.trueIcon = icon; + } + + public void setFalseIcon(ImageResource icon) { + this.falseIcon = icon; + } + + public void setTitle(String title) { + this.title = title; + } + + @Override + public HandlerRegistration addSelectHandler(SelectHandler handler) { + return addHandler(handler, SelectEvent.getType()); + } + + @Override + public void render(Context context, + Boolean value, SafeHtmlBuilder sb) { + this.appearance.trueIcon = trueIcon; + this.appearance.falseIcon = falseIcon; + if(title==null){ + title=""; + } + + this.appearance.title = title; + this.appearance.render(sb, value); + } + + @Override + public void onBrowserEvent(Context context, + Element parent, Boolean value, NativeEvent event, + ValueUpdater valueUpdater) { + Element target = event.getEventTarget().cast(); + // ignore the parent element + if (isDisableEvents() || !parent.getFirstChildElement().isOrHasChild(target)) { + return; + } + + XElement p = parent.cast(); + + String eventType = event.getType(); + if ("click".equals(eventType)) { + onClick(context, p, value, event, valueUpdater); + } + } + + private void onClick(Context context, XElement p, Boolean value, NativeEvent event, ValueUpdater valueUpdater) { + if (!isDisableEvents() && fireCancellableEvent(context, new BeforeSelectEvent(context))) { + fireEvent(context, new SelectEvent(context)); + } + } + + +} \ No newline at end of file diff --git a/src/main/java/org/gcube/portlets/user/td/tablewidget/client/custom/ValidationCellAppearance.java b/src/main/java/org/gcube/portlets/user/td/tablewidget/client/custom/ValidationCellAppearance.java new file mode 100644 index 0000000..fe7a526 --- /dev/null +++ b/src/main/java/org/gcube/portlets/user/td/tablewidget/client/custom/ValidationCellAppearance.java @@ -0,0 +1,78 @@ +package org.gcube.portlets.user.td.tablewidget.client.custom; + +import com.google.gwt.core.client.GWT; +import com.google.gwt.resources.client.ClientBundle; +import com.google.gwt.resources.client.CssResource; +import com.google.gwt.resources.client.ImageResource; +import com.google.gwt.safehtml.shared.SafeHtml; +import com.google.gwt.safehtml.shared.SafeHtmlBuilder; +import com.google.gwt.safehtml.shared.SafeHtmlUtils; +import com.google.gwt.user.client.ui.AbstractImagePrototype; +import com.sencha.gxt.core.client.XTemplates; + +/** + * + * @author "Giancarlo Panichi" + * + */ +public class ValidationCellAppearance { + + public interface Style extends CssResource { + String image(); + } + + public interface Template extends XTemplates { + @XTemplate(source = "ValidationButton.html") + SafeHtml template(Style style, SafeHtml img, String title, String alt); + } + + public interface Resources extends ClientBundle { + @Source("ValidationButton.css") + Style style(); + } + + private final Style style; + private final Template template; + + public ImageResource trueIcon; + public ImageResource falseIcon; + + public String title; + + public ValidationCellAppearance() { + this((Resources) GWT.create(Resources.class)); + } + + public ValidationCellAppearance(Resources resources) { + this.style = resources.style(); + this.style.ensureInjected(); + this.template = GWT.create(Template.class); + } + + public void render(SafeHtmlBuilder sb, Boolean value) { + SafeHtml safeIcon = SafeHtmlUtils.fromString(""); + String alt = ""; + if (value != null) { + if (value) { + safeIcon = makeImage(trueIcon); + alt = "true"; + } else { + safeIcon = makeImage(falseIcon); + alt = "false"; + } + } + sb.append(template.template(style, safeIcon, title, alt)); + } + + /** + * Make icons available as SafeHtml to be displayed inside the table + * + * @param resource + * @return + */ + private static SafeHtml makeImage(ImageResource resource) { + AbstractImagePrototype proto = AbstractImagePrototype.create(resource); + String html = proto.getHTML(); + return SafeHtmlUtils.fromTrustedString(html); + } +} \ No newline at end of file diff --git a/src/main/java/org/gcube/portlets/user/td/tablewidget/client/validation/ValidationsTasksPanel.java b/src/main/java/org/gcube/portlets/user/td/tablewidget/client/validation/ValidationsTasksPanel.java index a8a914d..cfc13af 100644 --- a/src/main/java/org/gcube/portlets/user/td/tablewidget/client/validation/ValidationsTasksPanel.java +++ b/src/main/java/org/gcube/portlets/user/td/tablewidget/client/validation/ValidationsTasksPanel.java @@ -1,11 +1,16 @@ package org.gcube.portlets.user.td.tablewidget.client.validation; import java.util.ArrayList; +import java.util.HashMap; import java.util.List; import org.gcube.portlets.user.td.gwtservice.client.rpc.TDGWTServiceAsync; +import org.gcube.portlets.user.td.gwtservice.shared.Constants; +import org.gcube.portlets.user.td.gwtservice.shared.OperationsId; import org.gcube.portlets.user.td.gwtservice.shared.exception.TDGWTSessionExpiredException; +import org.gcube.portlets.user.td.gwtservice.shared.task.InvocationS; import org.gcube.portlets.user.td.gwtservice.shared.task.ValidationsTasksMetadata; +import org.gcube.portlets.user.td.tablewidget.client.custom.ValidationCell; 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; @@ -13,11 +18,15 @@ 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.client.event.SessionExpiredEvent; +import org.gcube.portlets.user.td.widgetcommonevent.client.event.WidgetRequestEvent; import org.gcube.portlets.user.td.widgetcommonevent.client.type.SessionExpiredType; +import org.gcube.portlets.user.td.widgetcommonevent.client.type.WidgetRequestType; +import org.gcube.portlets.user.td.widgetcommonevent.shared.RequestProperties; import org.gcube.portlets.user.td.widgetcommonevent.shared.TRId; -import com.sencha.gxt.widget.core.client.event.CollapseItemEvent.CollapseItemHandler; + import com.allen_sauer.gwt.log.client.Log; import com.google.gwt.cell.client.AbstractCell; +import com.google.gwt.cell.client.Cell.Context; import com.google.gwt.resources.client.ImageResource; import com.google.gwt.safehtml.shared.SafeHtmlBuilder; import com.google.gwt.safehtml.shared.SafeHtmlUtils; @@ -35,6 +44,7 @@ import com.sencha.gxt.widget.core.client.container.MarginData; 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.event.CollapseItemEvent; +import com.sencha.gxt.widget.core.client.event.CollapseItemEvent.CollapseItemHandler; import com.sencha.gxt.widget.core.client.event.ExpandItemEvent; import com.sencha.gxt.widget.core.client.event.ExpandItemEvent.ExpandItemHandler; import com.sencha.gxt.widget.core.client.event.SelectEvent; @@ -63,6 +73,62 @@ public class ValidationsTasksPanel extends FramedPanel { protected TreeStore store; protected TreeGrid tree; + @SuppressWarnings("rawtypes") + protected AbstractCell actionButton = new AbstractCell() { + + @Override + public void render(Context context, Boolean value, SafeHtmlBuilder sb) { + + if (value == null) { + sb.appendHtmlConstant(""); + } else { + Log.debug("Context: pos=" + context.getIndex() + ", key=" + + context.getKey() + ", column=" + context.getColumn()); + String key = (String) context.getKey(); + BaseDto d = store.findModelWithKey(key); + + /* + * List list = ; + * Log.debug("List: ["+list.toString()+"]"); int i = 0; BaseDto + * d=null; for (; i < list.size(); i++) { BaseDto dt = + * list.get(i); if (dt.getId().compareTo((String) + * context.getKey()) == 0) { d=dt; + * Log.debug("Retrieved: "+d+" at pos:"+i); break; } } + */ + + String title = ""; + if (d != null) { + Log.debug(d.toString()); + if (d instanceof ValidationDto) { + ValidationDto v = (ValidationDto) d; + Log.debug("ValidationDto: [" + v.getId() + ", " + + v.getDescription() + ", " + v.getValid() + + ", " + v.getInvocation() + "]"); + if (v.getInvocation() != null) { + title = v.getInvocation().toString(); + } + } + } + + if (value) { + + sb.appendHtmlConstant("true"); + + } else { + sb.appendHtmlConstant("false"); + + } + } + + } + }; + class KeyProvider implements ModelKeyProvider { @Override public String getKey(BaseDto item) { @@ -175,64 +241,23 @@ public class ValidationsTasksPanel extends FramedPanel { } }, 38, "Valid"); cc3.setHeader("Valid"); - cc3.setCell(new AbstractCell() { + + ValidationCell validationButton = new ValidationCell(); + validationButton.setTrueIcon(ResourceBundle.INSTANCE.ok()); + validationButton.setFalseIcon(ResourceBundle.INSTANCE.exit()); + validationButton.addSelectHandler(new SelectHandler() { @Override - public void render(Context context, Boolean value, - SafeHtmlBuilder sb) { - - if (value == null) { - sb.appendHtmlConstant(""); - } else { - Log.debug("Context: pos=" + context.getIndex() + ", key=" - + context.getKey() + ", column=" - + context.getColumn()); - String key = (String) context.getKey(); - BaseDto d = store.findModelWithKey(key); - - /* - * List list = ; - * Log.debug("List: ["+list.toString()+"]"); int i = 0; - * BaseDto d=null; for (; i < list.size(); i++) { BaseDto dt - * = list.get(i); if (dt.getId().compareTo((String) - * context.getKey()) == 0) { d=dt; - * Log.debug("Retrieved: "+d+" at pos:"+i); break; } } - */ - - String title = ""; - if (d != null) { - Log.debug(d.toString()); - if (d instanceof ValidationDto) { - ValidationDto v = (ValidationDto) d; - Log.debug("ValidationDto: [" + v.getId() + ", " - + v.getDescription() + ", " - + v.getValid() + ", " - + v.getInvocation() + "]"); - if (v.getInvocation() != null) { - title = v.getInvocation().toString(); - } - } - } - - if (value) { - - sb.appendHtmlConstant("true"); - - } else { - sb.appendHtmlConstant("false"); - - } - } + public void onSelect(SelectEvent event) { + Log.debug("Button ValidationCell Pressed"); + Context context = event.getContext(); + requestSolution(context); } }); + cc3.setCell(validationButton); + List> l = new ArrayList>(); l.add(cc1); // l.add(cc2); @@ -329,6 +354,47 @@ public class ValidationsTasksPanel extends FramedPanel { } + // TODO + protected void requestSolution(Context context) { + String key = (String) context.getKey(); + BaseDto d = store.findModelWithKey(key); + + String title = ""; + if (d != null) { + Log.debug(d.toString()); + if (d instanceof ValidationDto) { + ValidationDto v = (ValidationDto) d; + Log.debug("ValidationDto: [" + v.getId() + ", " + + v.getDescription() + ", " + v.getValid() + ", " + + v.getInvocation() + "]"); + if (v.getInvocation() != null) { + InvocationS invocationS = v.getInvocation(); + title = invocationS.toString(); + Long op = invocationS.getOperationId(); + if (op.compareTo(OperationsId.ChangeToDimensionColumn + .toLong()) == 0) { + WidgetRequestEvent widgetRequestEvent = new WidgetRequestEvent( + WidgetRequestType.CURATIONBYREPLACEBATCHDIALOG); + widgetRequestEvent.setTrId(trId); + HashMap map = new HashMap(); + map.put(Constants.REQUEST_PROPERTIES_REFCOLUMN, + invocationS.getRefColumn()); + map.put(Constants.REQUEST_PROPERTIES_COLUMNID, + invocationS.getColumnId()); + RequestProperties props = new RequestProperties(map); + widgetRequestEvent.setRequestProperties(props); + eventBus.fireEvent(widgetRequestEvent); + } else { + UtilsGXT3.info("Invocation Info", title); + } + + } + + } + } + + } + protected void retrieveValidations() { TDGWTServiceAsync.INSTANCE.getValidationsTasksMetadata(trId,