From 235299f9c4957238ceac89cb07ae7aa4d83dae33 Mon Sep 17 00:00:00 2001 From: Giancarlo Panichi Date: Mon, 10 Mar 2014 11:10:35 +0000 Subject: [PATCH] Added Share git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/portlets/user/tabular-data-share-widget@92867 82a268e6-3cf1-43bd-a215-b396298e98cf --- .classpath | 7 +- .settings/com.google.gdt.eclipse.core.prefs | 2 +- pom.xml | 6 - .../sharewidget/client/ShareWidgetEntry.java | 10 +- .../user/td/sharewidget/client/TRShare.java | 170 ++++++++++++++---- .../client/util/InfoMessageBox.java | 22 +++ 6 files changed, 166 insertions(+), 51 deletions(-) create mode 100644 src/main/java/org/gcube/portlets/user/td/sharewidget/client/util/InfoMessageBox.java diff --git a/.classpath b/.classpath index 6b426f4..444501a 100644 --- a/.classpath +++ b/.classpath @@ -1,12 +1,12 @@ - + - + @@ -30,8 +30,7 @@ - - + diff --git a/.settings/com.google.gdt.eclipse.core.prefs b/.settings/com.google.gdt.eclipse.core.prefs index 6028af8..7254093 100644 --- a/.settings/com.google.gdt.eclipse.core.prefs +++ b/.settings/com.google.gdt.eclipse.core.prefs @@ -1,4 +1,4 @@ eclipse.preferences.version=1 -lastWarOutDir=/home/giancarlo/workspace/tabular-data-share-widget/target/tabular-data-share-widget-1.0.0-SNAPSHOT +lastWarOutDir=/home/giancarlo/workspace/tabular-data-share-widget/target/tabular-data-share-widget-0.0.1-SNAPSHOT warSrcDir=src/main/webapp warSrcDirIsOutput=false diff --git a/pom.xml b/pom.xml index 0e3829b..35f8366 100644 --- a/pom.xml +++ b/pom.xml @@ -180,17 +180,12 @@ gwt-log - org.slf4j slf4j-api compile - - - - junit @@ -356,5 +351,4 @@ - war diff --git a/src/main/java/org/gcube/portlets/user/td/sharewidget/client/ShareWidgetEntry.java b/src/main/java/org/gcube/portlets/user/td/sharewidget/client/ShareWidgetEntry.java index 58e7ef9..098966e 100644 --- a/src/main/java/org/gcube/portlets/user/td/sharewidget/client/ShareWidgetEntry.java +++ b/src/main/java/org/gcube/portlets/user/td/sharewidget/client/ShareWidgetEntry.java @@ -2,14 +2,22 @@ package org.gcube.portlets.user.td.sharewidget.client; +import org.gcube.portlets.user.td.widgetcommonevent.shared.TRId; + import com.allen_sauer.gwt.log.client.Log; import com.google.gwt.core.client.EntryPoint; +import com.google.web.bindery.event.shared.EventBus; +import com.google.web.bindery.event.shared.SimpleEventBus; public class ShareWidgetEntry implements EntryPoint { public void onModuleLoad() { - TRShare trShare=new TRShare(); + TRId trId=new TRId("1"); + EventBus eventBus=new SimpleEventBus(); + + @SuppressWarnings("unused") + TRShare trShare=new TRShare(trId,eventBus); Log.info("Hello!"); } } diff --git a/src/main/java/org/gcube/portlets/user/td/sharewidget/client/TRShare.java b/src/main/java/org/gcube/portlets/user/td/sharewidget/client/TRShare.java index acde7a8..4de9232 100644 --- a/src/main/java/org/gcube/portlets/user/td/sharewidget/client/TRShare.java +++ b/src/main/java/org/gcube/portlets/user/td/sharewidget/client/TRShare.java @@ -1,32 +1,87 @@ package org.gcube.portlets.user.td.sharewidget.client; +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.share.Contacts; +import org.gcube.portlets.user.td.gwtservice.shared.share.ShareInfo; +import org.gcube.portlets.user.td.sharewidget.client.util.InfoMessageBox; +import org.gcube.portlets.user.td.widgetcommonevent.shared.TRId; import org.gcube.portlets.widgets.workspacesharingwidget.client.WorkspaceSmartSharingController; import org.gcube.portlets.widgets.workspacesharingwidget.client.view.sharing.SmartShare; import org.gcube.portlets.widgets.workspacesharingwidget.shared.CredentialModel; import org.gcube.portlets.widgets.workspacesharingwidget.shared.FileModel; -import org.gcube.portlets.widgets.workspacesharingwidget.shared.InfoContactModel; +import com.allen_sauer.gwt.log.client.Log; import com.extjs.gxt.ui.client.event.BaseEvent; import com.extjs.gxt.ui.client.event.Events; import com.extjs.gxt.ui.client.event.Listener; import com.extjs.gxt.ui.client.widget.Dialog; +import com.google.gwt.user.client.rpc.AsyncCallback; +import com.google.web.bindery.event.shared.EventBus; +import com.sencha.gxt.widget.core.client.box.AlertMessageBox; +import com.sencha.gxt.widget.core.client.event.HideEvent; +import com.sencha.gxt.widget.core.client.event.HideEvent.HideHandler; - +/** + * + * @author "Giancarlo Panichi" g.panichi@isti.cnr.it + * + */ public class TRShare { - public TRShare() { - FileModel file = new FileModel("id", "filename", false); + private TRId trId; - /** - * This controller instance the smart sharing dialog - * - * @param file - * - a fake file to display the field name ("filename") into - * dialog - * @param listAlreadySharedContact - */ + @SuppressWarnings("unused") + private EventBus eventBus; + private ShareInfo shareInfo; + + public TRShare(TRId trId, EventBus eventBus) { + this.trId = trId; + this.eventBus = eventBus; + + retrieveInfo(); + + } + + protected void retrieveInfo() { + TDGWTServiceAsync.INSTANCE.getShareInfo(trId, + new AsyncCallback() { + + public void onFailure(Throwable caught) { + Log.debug("ShareInfo Error: " + + caught.getLocalizedMessage()); + alert("Error retrienving share info", + "Error retrieving share info"); + + } + + public void onSuccess(ShareInfo result) { + shareInfo = result; + shareWindow(); + } + + }); + } + + /** + * Call Window + */ + protected void shareWindow() { + + FileModel file = new FileModel(shareInfo.getTabResource().getTrId() + .getId(), shareInfo.getTabResource().getName(), false); + + List listAlreadySharedContact = new ArrayList(); + for (Contacts contacts : shareInfo.getContacts()) { + CredentialModel cm = new CredentialModel(null, contacts.getLogin(), + false); + listAlreadySharedContact.add(cm); + } WorkspaceSmartSharingController controller = new WorkspaceSmartSharingController( - file, null); + file, listAlreadySharedContact); final SmartShare sharingWindow = controller.getSharingDialog(); @@ -39,35 +94,72 @@ public class TRShare { public void handleEvent(BaseEvent be) { if (sharingWindow.isValidForm(true)) { - // THAT'S OK - - sharingWindow.getSharedListUsers(); // @return the - // selected - // contacts (as - // InfoContactModel) - - sharingWindow.getSharedListUsersCredential(); // @return - // the - // selected - // contacts - // (as - // CredentialModel) - - for (InfoContactModel contact : sharingWindow - .getSharedListUsers()) { - System.out.println(contact); - } - - for (CredentialModel credential : sharingWindow - .getSharedListUsersCredential()) { - System.out.println(credential); - } + shareCall(sharingWindow + .getSharedListUsersCredential()); } } }); - + } - -} + + protected void shareCall(List credentials) { + ArrayList listContacts = new ArrayList(); + for (CredentialModel cred : credentials) { + Contacts cont = new Contacts(cred.getId(), cred.getLogin(), + cred.isGroup()); + listContacts.add(cont); + } + + shareInfo.setContacts(listContacts); + + TDGWTServiceAsync.INSTANCE.setShare(shareInfo, + new AsyncCallback() { + + public void onFailure(Throwable caught) { + Log.debug("Share Error: " + + caught.getLocalizedMessage()); + alert("Error sharing tabular resource", + "Error shareing tabular resource"); + + } + + public void onSuccess(Void result) { + Log.debug("Tabular Resource Shared: " + + shareInfo.getTabResource().getTrId() + .toString()); + info("Shared", + "Tabular Resource is shared"); + + } + + }); + + } + + private void alert(String title, String message) { + final AlertMessageBox d = new AlertMessageBox(title, message); + d.addHideHandler(new HideHandler() { + + public void onHide(HideEvent event) { + + } + }); + d.show(); + + } + + private void info(String title, String message) { + final InfoMessageBox d = new InfoMessageBox(title, message); + d.addHideHandler(new HideHandler() { + + public void onHide(HideEvent event) { + + } + }); + d.show(); + + } + +} \ No newline at end of file diff --git a/src/main/java/org/gcube/portlets/user/td/sharewidget/client/util/InfoMessageBox.java b/src/main/java/org/gcube/portlets/user/td/sharewidget/client/util/InfoMessageBox.java new file mode 100644 index 0000000..d8c9b79 --- /dev/null +++ b/src/main/java/org/gcube/portlets/user/td/sharewidget/client/util/InfoMessageBox.java @@ -0,0 +1,22 @@ +package org.gcube.portlets.user.td.sharewidget.client.util; + +import com.sencha.gxt.widget.core.client.box.MessageBox; + +public class InfoMessageBox extends MessageBox { + + /** + * Creates a message box with an info icon and the specified title and + * message. + * + * @param title + * the message box title + * @param message + * the message displayed in the message box + */ + public InfoMessageBox(String title, String message) { + super(title, message); + + setIcon(ICONS.info()); + } + +} \ No newline at end of file