Added Share Template
git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/portlets/user/tabular-data-share-widget@100775 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
c59c0cd395
commit
b238ead566
|
@ -7,9 +7,9 @@ import org.gcube.portlets.user.td.gwtservice.client.rpc.TDGWTServiceAsync;
|
||||||
import org.gcube.portlets.user.td.gwtservice.shared.exception.TDGWTIsLockedException;
|
import org.gcube.portlets.user.td.gwtservice.shared.exception.TDGWTIsLockedException;
|
||||||
import org.gcube.portlets.user.td.gwtservice.shared.exception.TDGWTSessionExpiredException;
|
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.Contacts;
|
||||||
import org.gcube.portlets.user.td.gwtservice.shared.share.ShareInfo;
|
import org.gcube.portlets.user.td.gwtservice.shared.share.ShareTabResource;
|
||||||
import org.gcube.portlets.user.td.gwtservice.shared.tr.TabResource;
|
import org.gcube.portlets.user.td.gwtservice.shared.tr.TabResource;
|
||||||
import org.gcube.portlets.user.td.sharewidget.client.util.InfoMessageBox;
|
import org.gcube.portlets.user.td.sharewidget.client.util.UtilsGXT3;
|
||||||
import org.gcube.portlets.user.td.widgetcommonevent.client.event.ChangeTableRequestEvent;
|
import org.gcube.portlets.user.td.widgetcommonevent.client.event.ChangeTableRequestEvent;
|
||||||
import org.gcube.portlets.user.td.widgetcommonevent.client.event.SessionExpiredEvent;
|
import org.gcube.portlets.user.td.widgetcommonevent.client.event.SessionExpiredEvent;
|
||||||
import org.gcube.portlets.user.td.widgetcommonevent.client.type.ChangeTableRequestType;
|
import org.gcube.portlets.user.td.widgetcommonevent.client.type.ChangeTableRequestType;
|
||||||
|
@ -28,9 +28,6 @@ import com.extjs.gxt.ui.client.event.Listener;
|
||||||
import com.extjs.gxt.ui.client.widget.Dialog;
|
import com.extjs.gxt.ui.client.widget.Dialog;
|
||||||
import com.google.gwt.user.client.rpc.AsyncCallback;
|
import com.google.gwt.user.client.rpc.AsyncCallback;
|
||||||
import com.google.web.bindery.event.shared.EventBus;
|
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;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
|
@ -43,7 +40,7 @@ public class TRShare {
|
||||||
|
|
||||||
private EventBus eventBus;
|
private EventBus eventBus;
|
||||||
private TabResource tabResource;
|
private TabResource tabResource;
|
||||||
private ShareInfo shareInfo;
|
private ShareTabResource shareInfo;
|
||||||
|
|
||||||
public TRShare(TRId trId, EventBus eventBus) {
|
public TRShare(TRId trId, EventBus eventBus) {
|
||||||
this.trId = trId;
|
this.trId = trId;
|
||||||
|
@ -53,23 +50,7 @@ public class TRShare {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
* protected void retrieveInfo() {
|
|
||||||
* TDGWTServiceAsync.INSTANCE.getShareInfo(trId, new
|
|
||||||
* AsyncCallback<ShareInfo>() {
|
|
||||||
*
|
|
||||||
* public void onFailure(Throwable caught) { if (caught instanceof
|
|
||||||
* TDGWTSessionExpiredException) { eventBus.fireEvent(new
|
|
||||||
* SessionExpiredEvent( SessionExpiredType.EXPIREDONSERVER)); } else {
|
|
||||||
* Log.debug("ShareInfo Error: " + caught.getLocalizedMessage());
|
|
||||||
* alert("Error retrienving share info", "Error retrieving share info"); } }
|
|
||||||
*
|
|
||||||
* public void onSuccess(ShareInfo result) { shareInfo = result;
|
|
||||||
* shareWindow(); }
|
|
||||||
*
|
|
||||||
* }); }
|
|
||||||
*/
|
|
||||||
|
|
||||||
public void retrieveInfo() {
|
public void retrieveInfo() {
|
||||||
TDGWTServiceAsync.INSTANCE.getTabResourceInformation(trId,
|
TDGWTServiceAsync.INSTANCE.getTabResourceInformation(trId,
|
||||||
new AsyncCallback<TabResource>() {
|
new AsyncCallback<TabResource>() {
|
||||||
|
@ -88,13 +69,13 @@ public class TRShare {
|
||||||
} else {
|
} else {
|
||||||
if (caught instanceof TDGWTIsLockedException) {
|
if (caught instanceof TDGWTIsLockedException) {
|
||||||
Log.error(caught.getLocalizedMessage());
|
Log.error(caught.getLocalizedMessage());
|
||||||
alert("Error Locked",
|
UtilsGXT3.alert("Error Locked",
|
||||||
caught.getLocalizedMessage());
|
caught.getLocalizedMessage());
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
Log.error("Error retrienving properties: "
|
Log.error("Error retrienving properties: "
|
||||||
+ caught.getLocalizedMessage());
|
+ caught.getLocalizedMessage());
|
||||||
alert("Error",
|
UtilsGXT3.alert("Error",
|
||||||
"Retrieving tabular resource info: "
|
"Retrieving tabular resource info: "
|
||||||
+ caught.getLocalizedMessage());
|
+ caught.getLocalizedMessage());
|
||||||
|
|
||||||
|
@ -152,7 +133,7 @@ public class TRShare {
|
||||||
cred.isGroup());
|
cred.isGroup());
|
||||||
listContacts.add(cont);
|
listContacts.add(cont);
|
||||||
}
|
}
|
||||||
shareInfo=new ShareInfo(tabResource,listContacts);
|
shareInfo=new ShareTabResource(tabResource,listContacts);
|
||||||
|
|
||||||
TDGWTServiceAsync.INSTANCE.setShare(shareInfo,
|
TDGWTServiceAsync.INSTANCE.setShare(shareInfo,
|
||||||
new AsyncCallback<Void>() {
|
new AsyncCallback<Void>() {
|
||||||
|
@ -164,7 +145,7 @@ public class TRShare {
|
||||||
} else {
|
} else {
|
||||||
Log.debug("Share Error: "
|
Log.debug("Share Error: "
|
||||||
+ caught.getLocalizedMessage());
|
+ caught.getLocalizedMessage());
|
||||||
alert("Error sharing tabular resource",
|
UtilsGXT3.alert("Error sharing tabular resource",
|
||||||
"Error sharing tabular resource: "
|
"Error sharing tabular resource: "
|
||||||
+ caught.getLocalizedMessage());
|
+ caught.getLocalizedMessage());
|
||||||
}
|
}
|
||||||
|
@ -174,7 +155,7 @@ public class TRShare {
|
||||||
Log.debug("Tabular Resource Shared: "
|
Log.debug("Tabular Resource Shared: "
|
||||||
+ shareInfo.getTabResource().getTrId()
|
+ shareInfo.getTabResource().getTrId()
|
||||||
.toString());
|
.toString());
|
||||||
info("Shared", "Tabular Resource is shared");
|
UtilsGXT3.info("Shared", "Tabular Resource is shared");
|
||||||
|
|
||||||
ChangeTableWhy why = ChangeTableWhy.TABLEUPDATED;
|
ChangeTableWhy why = ChangeTableWhy.TABLEUPDATED;
|
||||||
ChangeTableRequestEvent changeTableRequestEvent = new ChangeTableRequestEvent(
|
ChangeTableRequestEvent changeTableRequestEvent = new ChangeTableRequestEvent(
|
||||||
|
@ -187,28 +168,6 @@ public class TRShare {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
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();
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
|
@ -0,0 +1,130 @@
|
||||||
|
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.exception.TDGWTSessionExpiredException;
|
||||||
|
import org.gcube.portlets.user.td.gwtservice.shared.share.Contacts;
|
||||||
|
import org.gcube.portlets.user.td.gwtservice.shared.share.ShareTemplate;
|
||||||
|
import org.gcube.portlets.user.td.gwtservice.shared.template.TemplateData;
|
||||||
|
import org.gcube.portlets.user.td.sharewidget.client.util.UtilsGXT3;
|
||||||
|
import org.gcube.portlets.user.td.widgetcommonevent.client.event.SessionExpiredEvent;
|
||||||
|
import org.gcube.portlets.user.td.widgetcommonevent.client.type.SessionExpiredType;
|
||||||
|
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 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;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author "Giancarlo Panichi" <a
|
||||||
|
* href="mailto:g.panichi@isti.cnr.it">g.panichi@isti.cnr.it</a>
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public class TemplateShare {
|
||||||
|
|
||||||
|
private EventBus eventBus;
|
||||||
|
private TemplateData templateData;
|
||||||
|
private ShareTemplate shareTemplate;
|
||||||
|
|
||||||
|
public TemplateShare(TemplateData templateData, EventBus eventBus) {
|
||||||
|
this.templateData=templateData;
|
||||||
|
this.eventBus = eventBus;
|
||||||
|
|
||||||
|
shareWindow();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Call Window
|
||||||
|
*/
|
||||||
|
protected void shareWindow() {
|
||||||
|
|
||||||
|
FileModel file = new FileModel(String.valueOf(templateData.getId()), templateData.getName(), false);
|
||||||
|
|
||||||
|
List<CredentialModel> listAlreadySharedContact = new ArrayList<CredentialModel>();
|
||||||
|
for (Contacts contacts : templateData.getContacts()) {
|
||||||
|
CredentialModel cm = new CredentialModel(null, contacts.getLogin(),
|
||||||
|
false);
|
||||||
|
listAlreadySharedContact.add(cm);
|
||||||
|
}
|
||||||
|
|
||||||
|
WorkspaceSmartSharingController controller = new WorkspaceSmartSharingController(
|
||||||
|
file, listAlreadySharedContact, false, true);
|
||||||
|
|
||||||
|
final SmartShare sharingWindow = controller.getSharingDialog();
|
||||||
|
|
||||||
|
sharingWindow.show();
|
||||||
|
|
||||||
|
sharingWindow.getButtonById(Dialog.OK).addListener(Events.Select,
|
||||||
|
new Listener<BaseEvent>() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void handleEvent(BaseEvent be) {
|
||||||
|
|
||||||
|
if (sharingWindow.isValidForm(true)) {
|
||||||
|
shareCall(sharingWindow
|
||||||
|
.getSharedListUsersCredential());
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void shareCall(List<CredentialModel> credentials) {
|
||||||
|
ArrayList<Contacts> listContacts = new ArrayList<Contacts>();
|
||||||
|
for (CredentialModel cred : credentials) {
|
||||||
|
Contacts cont = new Contacts(cred.getId(), cred.getLogin(),
|
||||||
|
cred.isGroup());
|
||||||
|
listContacts.add(cont);
|
||||||
|
}
|
||||||
|
shareTemplate=new ShareTemplate(templateData,listContacts);
|
||||||
|
|
||||||
|
TDGWTServiceAsync.INSTANCE.setShareTemplate(shareTemplate,
|
||||||
|
new AsyncCallback<Void>() {
|
||||||
|
|
||||||
|
public void onFailure(Throwable caught) {
|
||||||
|
if (caught instanceof TDGWTSessionExpiredException) {
|
||||||
|
eventBus.fireEvent(new SessionExpiredEvent(
|
||||||
|
SessionExpiredType.EXPIREDONSERVER));
|
||||||
|
} else {
|
||||||
|
Log.debug("Share Error: "
|
||||||
|
+ caught.getLocalizedMessage());
|
||||||
|
UtilsGXT3.alert("Error sharing template",
|
||||||
|
"Error sharing template: "
|
||||||
|
+ caught.getLocalizedMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void onSuccess(Void result) {
|
||||||
|
Log.debug("Template Shared: "
|
||||||
|
+ shareTemplate.getTemplateData().getId());
|
||||||
|
UtilsGXT3.info("Shared", "Template is shared");
|
||||||
|
/*
|
||||||
|
ChangeTableWhy why = ChangeTableWhy.TABLEUPDATED;
|
||||||
|
ChangeTableRequestEvent changeTableRequestEvent = new ChangeTableRequestEvent(
|
||||||
|
ChangeTableRequestType.SHARE, trId, why);
|
||||||
|
eventBus.fireEvent(changeTableRequestEvent);*/
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in New Issue