diff --git a/src/main/java/org/gcube/portlets/user/td/informationwidget/client/TabularResourceProperties.java b/src/main/java/org/gcube/portlets/user/td/informationwidget/client/TabularResourceProperties.java index 95a7a68..625c296 100644 --- a/src/main/java/org/gcube/portlets/user/td/informationwidget/client/TabularResourceProperties.java +++ b/src/main/java/org/gcube/portlets/user/td/informationwidget/client/TabularResourceProperties.java @@ -1,25 +1,35 @@ package org.gcube.portlets.user.td.informationwidget.client; +import java.util.ArrayList; import java.util.HashMap; import org.gcube.portlets.user.td.gwtservice.client.rpc.TDGWTServiceAsync; import org.gcube.portlets.user.td.gwtservice.shared.exception.TDGWTSessionExpiredException; +import org.gcube.portlets.user.td.gwtservice.shared.share.Contacts; +import org.gcube.portlets.user.td.gwtservice.shared.share.ShareInfo; import org.gcube.portlets.user.td.gwtservice.shared.tr.TabResource; import org.gcube.portlets.user.td.gwtservice.shared.tr.TableData; +import org.gcube.portlets.user.td.informationwidget.client.custom.IconButton; import org.gcube.portlets.user.td.informationwidget.client.resources.ResourceBundle; import org.gcube.portlets.user.td.informationwidget.client.util.InfoMessageBox; import org.gcube.portlets.user.td.metadatawidget.client.TRMetadataAccordionPanel; import org.gcube.portlets.user.td.metadatawidget.client.TableMetadataAccordionPanel; +import org.gcube.portlets.user.td.widgetcommonevent.client.event.RibbonEvent; 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.RibbonType; 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.TRId; import com.allen_sauer.gwt.log.client.Log; +import com.google.gwt.event.dom.client.ClickEvent; +import com.google.gwt.event.dom.client.ClickHandler; import com.google.gwt.event.logical.shared.ValueChangeEvent; import com.google.gwt.event.logical.shared.ValueChangeHandler; import com.google.gwt.user.client.rpc.AsyncCallback; +import com.google.gwt.user.client.ui.HasHorizontalAlignment; +import com.google.gwt.user.client.ui.HorizontalPanel; import com.google.web.bindery.event.shared.EventBus; import com.sencha.gxt.cell.core.client.ButtonCell.IconAlign; import com.sencha.gxt.core.client.dom.ScrollSupport.ScrollMode; @@ -27,9 +37,9 @@ import com.sencha.gxt.core.client.util.Margins; import com.sencha.gxt.widget.core.client.FramedPanel; import com.sencha.gxt.widget.core.client.box.AlertMessageBox; import com.sencha.gxt.widget.core.client.button.TextButton; +import com.sencha.gxt.widget.core.client.container.BoxLayoutContainer.BoxLayoutData; import com.sencha.gxt.widget.core.client.container.HBoxLayoutContainer; import com.sencha.gxt.widget.core.client.container.VerticalLayoutContainer; -import com.sencha.gxt.widget.core.client.container.BoxLayoutContainer.BoxLayoutData; import com.sencha.gxt.widget.core.client.container.VerticalLayoutContainer.VerticalLayoutData; import com.sencha.gxt.widget.core.client.event.HideEvent; import com.sencha.gxt.widget.core.client.event.HideEvent.HideHandler; @@ -57,8 +67,11 @@ public class TabularResourceProperties extends FramedPanel { protected TextField agencyField; protected TextField dateField; protected TextArea rightField; + protected TextField ownerField; protected CheckBox finalizedField; protected TextField typeField; + + protected IconButton btnShare; protected TRMetadataAccordionPanel trMetadataPanel; protected VerticalLayoutContainer layoutTabularResource; @@ -128,6 +141,34 @@ public class TabularResourceProperties extends FramedPanel { rightField.setValue(""); layoutTabularResource.add(new FieldLabel(rightField, "Rights"), new VerticalLayoutData(1, -1)); + + + + ownerField = new TextField(); + ownerField.setReadOnly(true); + ownerField.setValue(""); + + btnShare = new IconButton(); + btnShare.setIcon(ResourceBundle.INSTANCE.share()); + btnShare.addClickHandler(new ClickHandler() { + + public void onClick(ClickEvent event) { + Log.debug("Clicked btnShare"); + eventBus.fireEvent(new RibbonEvent(RibbonType.SHARE)); + + } + }); + btnShare.setVisible(false); + + HorizontalPanel hp = new HorizontalPanel(); + hp.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_LEFT); + hp.add(ownerField); + hp.add(btnShare); + FieldLabel ownerLabel = new FieldLabel(hp, "Owner"); + + layoutTabularResource.add(ownerLabel, + new VerticalLayoutData(1, -1)); + finalizedField = new CheckBox(); // finalizedField.setBoxLabel(""); @@ -194,6 +235,7 @@ public class TabularResourceProperties extends FramedPanel { dateField.setValue(tabResource.getDate()); typeField.setValue(tabResource.getTrId().getTabularResourceType()); rightField.setValue(tabResource.getRight()); + ownerField.setValue(tabResource.getOwner().getLogin()); if (tabResource.isFinalized()) { finalizedField.setEnabled(false); finalizedField.setValue(true); @@ -201,9 +243,19 @@ public class TabularResourceProperties extends FramedPanel { finalizedField.setEnabled(true); finalizedField.setValue(false); } + } - + + protected void updateShareInfo(ShareInfo result){ + ArrayList contacts=result.getContacts(); + if(contacts!=null&& contacts.size()>0){ + btnShare.setVisible(true); + } else { + btnShare.setVisible(false); + } + } + public void addTable() { tableFieldSet = new FieldSet(); tableFieldSet.setHeadingText("Table"); @@ -248,15 +300,15 @@ public class TabularResourceProperties extends FramedPanel { layoutTable.add(tableMetadataPanel, new VerticalLayoutData(-1, -1)); tableFieldSet.add(layoutTable); } - + public void update() { TDGWTServiceAsync.INSTANCE .getTabResourceInformation(new AsyncCallback() { public void onSuccess(TabResource result) { - updateTabularResource(result); Log.info("Retrived TR: " + result.getTrId()); - getLastTable(result.getTrId()); + updateTabularResource(result); + getShareInformation(result.getTrId()); } public void onFailure(Throwable caught) { @@ -282,14 +334,48 @@ public class TabularResourceProperties extends FramedPanel { }); } + protected void getShareInformation(TRId trId){ + TDGWTServiceAsync.INSTANCE.getShareInfo(trId, + new AsyncCallback() { + + public void onSuccess(ShareInfo result) { + Log.debug("Retrived share info:" + result); + updateShareInfo(result); + getLastTable(tabResource.getTrId()); + + } + + public void onFailure(Throwable caught) { + if (caught instanceof TDGWTSessionExpiredException) { + eventBus.fireEvent(new SessionExpiredEvent( + SessionExpiredType.EXPIREDONSERVER)); + } else { + AlertMessageBox d = new AlertMessageBox("Error", + "Error retrienving Share Informations: " + + caught.getLocalizedMessage()); + d.addHideHandler(new HideHandler() { + + public void onHide(HideEvent event) { + // + + } + + }); + d.show(); + } + } + + }); + } + protected void getLastTable(TRId trId) { TDGWTServiceAsync.INSTANCE.getLastTable(trId, new AsyncCallback() { public void onSuccess(TableData result) { - updateTable(result); Log.debug("Retrived LastTable:" + result); - + updateTable(result); + } public void onFailure(Throwable caught) { diff --git a/src/main/java/org/gcube/portlets/user/td/informationwidget/client/custom/DefaultAppearance.java b/src/main/java/org/gcube/portlets/user/td/informationwidget/client/custom/DefaultAppearance.java new file mode 100644 index 0000000..55c9911 --- /dev/null +++ b/src/main/java/org/gcube/portlets/user/td/informationwidget/client/custom/DefaultAppearance.java @@ -0,0 +1,75 @@ +package org.gcube.portlets.user.td.informationwidget.client.custom; + + +import com.google.gwt.core.client.GWT; +import com.google.gwt.dom.client.Element; +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.user.client.ui.Image; +import com.sencha.gxt.core.client.XTemplates; +import com.sencha.gxt.core.client.dom.XElement; + +/** + * + * @author "Giancarlo Panichi" + * g.panichi@isti.cnr.it + * + */ +public class DefaultAppearance implements IconButtonAppearance { + + public interface Template extends XTemplates { + @XTemplate(source = "IconButton.html") + SafeHtml template(IconButtonStyle style); + } + + public interface IconButtonStyle extends CssResource { + @ClassName("iconButton") + public String getIconButton(); + + @ClassName("iconButtonImage") + public String getIconButtonImage(); + + @ClassName("iconButtonRef") + public String getIconButtonRef(); + + } + + private final IconButtonStyle style; + private final Template template; + + public interface IconButtonResources extends ClientBundle { + public static final IconButtonResources INSTANCE = GWT.create(IconButtonResources.class); + + @Source("IconButtonStyle.css") + IconButtonStyle style(); + } + + public DefaultAppearance() { + this(IconButtonResources.INSTANCE); + } + + public DefaultAppearance(IconButtonResources resources) { + this.style = resources.style(); + this.style.ensureInjected(); + + this.template = GWT.create(Template.class); + } + + + + public void onUpdateIcon(XElement parent, ImageResource icon) { + XElement element = parent.selectNode("." + style.getIconButtonImage()); + Image image=new Image(icon); + Element img=image.getElement(); + img.setClassName(style.getIconButtonRef()); + element.appendChild(img); + + } + + public void render(SafeHtmlBuilder sb) { + sb.append(template.template(style)); + } +} \ No newline at end of file diff --git a/src/main/java/org/gcube/portlets/user/td/informationwidget/client/custom/IconButton.html b/src/main/java/org/gcube/portlets/user/td/informationwidget/client/custom/IconButton.html new file mode 100644 index 0000000..9b36b96 --- /dev/null +++ b/src/main/java/org/gcube/portlets/user/td/informationwidget/client/custom/IconButton.html @@ -0,0 +1,4 @@ + +
+
+
\ No newline at end of file diff --git a/src/main/java/org/gcube/portlets/user/td/informationwidget/client/custom/IconButton.java b/src/main/java/org/gcube/portlets/user/td/informationwidget/client/custom/IconButton.java new file mode 100644 index 0000000..f9d4062 --- /dev/null +++ b/src/main/java/org/gcube/portlets/user/td/informationwidget/client/custom/IconButton.java @@ -0,0 +1,47 @@ +package org.gcube.portlets.user.td.informationwidget.client.custom; + + +import com.google.gwt.core.client.GWT; +import com.google.gwt.event.dom.client.ClickEvent; +import com.google.gwt.event.dom.client.ClickHandler; +import com.google.gwt.event.dom.client.HasClickHandlers; +import com.google.gwt.event.shared.HandlerRegistration; +import com.google.gwt.resources.client.ImageResource; +import com.google.gwt.safehtml.shared.SafeHtmlBuilder; +import com.google.gwt.user.client.Event; +import com.sencha.gxt.core.client.dom.XDOM; +import com.sencha.gxt.widget.core.client.Component; + +/** + * + * @author "Giancarlo Panichi" + * g.panichi@isti.cnr.it + * + */ +public class IconButton extends Component implements HasClickHandlers { + + private IconButtonAppearance appearance; + + public IconButton() { + this((IconButtonAppearance) GWT.create(DefaultAppearance.class)); + } + + public IconButton(IconButtonAppearance appearance) { + this.appearance = appearance; + + SafeHtmlBuilder sb = new SafeHtmlBuilder(); + this.appearance.render(sb); + + setElement(XDOM.create(sb.toSafeHtml())); + sinkEvents(Event.ONCLICK); + } + + public HandlerRegistration addClickHandler(ClickHandler handler) { + return addDomHandler(handler, ClickEvent.getType()); + } + + + public void setIcon(ImageResource icon) { + appearance.onUpdateIcon(getElement(), icon); + } +} diff --git a/src/main/java/org/gcube/portlets/user/td/informationwidget/client/custom/IconButtonAppearance.java b/src/main/java/org/gcube/portlets/user/td/informationwidget/client/custom/IconButtonAppearance.java new file mode 100644 index 0000000..faa4993 --- /dev/null +++ b/src/main/java/org/gcube/portlets/user/td/informationwidget/client/custom/IconButtonAppearance.java @@ -0,0 +1,16 @@ +package org.gcube.portlets.user.td.informationwidget.client.custom; + +import com.google.gwt.resources.client.ImageResource; +import com.google.gwt.safehtml.shared.SafeHtmlBuilder; +import com.sencha.gxt.core.client.dom.XElement; + +/** + * + * @author "Giancarlo Panichi" + * g.panichi@isti.cnr.it + * + */ +public interface IconButtonAppearance { + void render(SafeHtmlBuilder sb); + void onUpdateIcon(XElement parent, ImageResource icon); +} diff --git a/src/main/java/org/gcube/portlets/user/td/informationwidget/client/custom/IconButtonStyle.css b/src/main/java/org/gcube/portlets/user/td/informationwidget/client/custom/IconButtonStyle.css new file mode 100644 index 0000000..354f7dc --- /dev/null +++ b/src/main/java/org/gcube/portlets/user/td/informationwidget/client/custom/IconButtonStyle.css @@ -0,0 +1,17 @@ +@CHARSET "UTF-8"; + +.iconButton { + border: none; + font-size: 12px; + margin: 0px; + padding: 0px; +} + +.iconButton .iconButtonImage { + vertical-align: center; +} + +.iconButtonRef { + vertical-align: center; + cursor: pointer; +} diff --git a/src/main/java/org/gcube/portlets/user/td/informationwidget/client/resources/ResourceBundle.java b/src/main/java/org/gcube/portlets/user/td/informationwidget/client/resources/ResourceBundle.java index 63ee2c8..7e1a4d9 100644 --- a/src/main/java/org/gcube/portlets/user/td/informationwidget/client/resources/ResourceBundle.java +++ b/src/main/java/org/gcube/portlets/user/td/informationwidget/client/resources/ResourceBundle.java @@ -29,6 +29,12 @@ public interface ResourceBundle extends ClientBundle { @Source("table-validation_32.png") ImageResource tableValidation32(); + @Source("page-white-share.png") + ImageResource share(); + + @Source("page-white-share_32.png") + ImageResource share32(); + } \ No newline at end of file diff --git a/src/main/java/org/gcube/portlets/user/td/informationwidget/client/resources/page-white-share.png b/src/main/java/org/gcube/portlets/user/td/informationwidget/client/resources/page-white-share.png new file mode 100644 index 0000000..13c4a51 Binary files /dev/null and b/src/main/java/org/gcube/portlets/user/td/informationwidget/client/resources/page-white-share.png differ diff --git a/src/main/java/org/gcube/portlets/user/td/informationwidget/client/resources/page-white-share_32.png b/src/main/java/org/gcube/portlets/user/td/informationwidget/client/resources/page-white-share_32.png new file mode 100644 index 0000000..0080258 Binary files /dev/null and b/src/main/java/org/gcube/portlets/user/td/informationwidget/client/resources/page-white-share_32.png differ diff --git a/src/main/resources/org/gcube/portlets/user/td/informationwidget/client/custom/IconButton.html b/src/main/resources/org/gcube/portlets/user/td/informationwidget/client/custom/IconButton.html new file mode 100644 index 0000000..9b36b96 --- /dev/null +++ b/src/main/resources/org/gcube/portlets/user/td/informationwidget/client/custom/IconButton.html @@ -0,0 +1,4 @@ + +
+
+
\ No newline at end of file diff --git a/src/main/resources/org/gcube/portlets/user/td/informationwidget/client/custom/IconButtonStyle.css b/src/main/resources/org/gcube/portlets/user/td/informationwidget/client/custom/IconButtonStyle.css new file mode 100644 index 0000000..354f7dc --- /dev/null +++ b/src/main/resources/org/gcube/portlets/user/td/informationwidget/client/custom/IconButtonStyle.css @@ -0,0 +1,17 @@ +@CHARSET "UTF-8"; + +.iconButton { + border: none; + font-size: 12px; + margin: 0px; + padding: 0px; +} + +.iconButton .iconButtonImage { + vertical-align: center; +} + +.iconButtonRef { + vertical-align: center; + cursor: pointer; +} diff --git a/src/main/resources/org/gcube/portlets/user/td/informationwidget/client/resources/page-white-share.png b/src/main/resources/org/gcube/portlets/user/td/informationwidget/client/resources/page-white-share.png new file mode 100644 index 0000000..13c4a51 Binary files /dev/null and b/src/main/resources/org/gcube/portlets/user/td/informationwidget/client/resources/page-white-share.png differ diff --git a/src/main/resources/org/gcube/portlets/user/td/informationwidget/client/resources/page-white-share_32.png b/src/main/resources/org/gcube/portlets/user/td/informationwidget/client/resources/page-white-share_32.png new file mode 100644 index 0000000..0080258 Binary files /dev/null and b/src/main/resources/org/gcube/portlets/user/td/informationwidget/client/resources/page-white-share_32.png differ