Minor Update

git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/portlets/user/tabular-data-information-widget@97523 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Giancarlo Panichi 2014-06-18 16:29:16 +00:00
parent 965cea7b50
commit 188e139dec
13 changed files with 279 additions and 7 deletions

View File

@ -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> 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<TabResource>() {
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<ShareInfo>() {
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<TableData>() {
public void onSuccess(TableData result) {
updateTable(result);
Log.debug("Retrived LastTable:" + result);
updateTable(result);
}
public void onFailure(Throwable caught) {

View File

@ -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"
* <a href="mailto:g.panichi@isti.cnr.it">g.panichi@isti.cnr.it</a>
*
*/
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));
}
}

View File

@ -0,0 +1,4 @@
<!-- file: ./IconButton.html -->
<div class="{style.iconButton}">
<div class="{style.iconButtonImage}"></div>
</div>

View File

@ -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"
* <a href="mailto:g.panichi@isti.cnr.it">g.panichi@isti.cnr.it</a>
*
*/
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);
}
}

View File

@ -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"
* <a href="mailto:g.panichi@isti.cnr.it">g.panichi@isti.cnr.it</a>
*
*/
public interface IconButtonAppearance {
void render(SafeHtmlBuilder sb);
void onUpdateIcon(XElement parent, ImageResource icon);
}

View File

@ -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;
}

View File

@ -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();
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 830 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.7 KiB

View File

@ -0,0 +1,4 @@
<!-- file: ./IconButton.html -->
<div class="{style.iconButton}">
<div class="{style.iconButtonImage}"></div>
</div>

View File

@ -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;
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 830 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.7 KiB