2014-02-25 14:28:30 +01:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
package org.gcube.portlets.widgets.workspacesharingwidget.client;
|
|
|
|
|
|
|
|
import org.gcube.portlets.widgets.workspacesharingwidget.client.rpc.WorkspaceSharingService;
|
|
|
|
import org.gcube.portlets.widgets.workspacesharingwidget.client.rpc.WorkspaceSharingServiceAsync;
|
2014-02-28 12:30:44 +01:00
|
|
|
import org.gcube.portlets.widgets.workspacesharingwidget.client.view.sharing.DialogShareWItem;
|
2014-02-27 16:03:30 +01:00
|
|
|
import org.gcube.portlets.widgets.workspacesharingwidget.shared.ACL_TYPE;
|
2014-02-28 12:30:44 +01:00
|
|
|
import org.gcube.portlets.widgets.workspacesharingwidget.shared.FileModel;
|
2014-02-25 14:28:30 +01:00
|
|
|
|
2014-02-28 12:30:44 +01:00
|
|
|
import com.extjs.gxt.ui.client.widget.MessageBox;
|
2014-02-27 16:11:36 +01:00
|
|
|
import com.extjs.gxt.ui.client.widget.Window;
|
2014-02-25 14:28:30 +01:00
|
|
|
import com.google.gwt.core.client.GWT;
|
2014-02-25 15:58:42 +01:00
|
|
|
import com.google.gwt.user.client.rpc.AsyncCallback;
|
2014-02-25 14:28:30 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
|
|
|
|
* @Feb 25, 2014
|
2014-02-25 15:58:42 +01:00
|
|
|
*
|
2014-02-25 14:28:30 +01:00
|
|
|
*/
|
|
|
|
public class WorkspaceSharingController {
|
|
|
|
|
2014-02-27 16:03:30 +01:00
|
|
|
public static final WorkspaceSharingServiceAsync rpcWorkspaceSharingService = (WorkspaceSharingServiceAsync) GWT.create(WorkspaceSharingService.class);
|
2014-02-25 15:58:42 +01:00
|
|
|
|
2014-02-27 16:03:30 +01:00
|
|
|
private static String myLogin;
|
2014-02-25 15:58:42 +01:00
|
|
|
|
2014-02-27 16:03:30 +01:00
|
|
|
private String workspaceItemId;
|
|
|
|
|
|
|
|
private boolean shareOnlyOwner;
|
|
|
|
|
|
|
|
private ACL_TYPE defaultPermission;
|
2014-02-28 12:30:44 +01:00
|
|
|
|
2014-03-03 15:54:53 +01:00
|
|
|
private DialogShareWItem sharingDialog = null;
|
2014-02-27 16:03:30 +01:00
|
|
|
|
|
|
|
|
2014-03-03 13:03:34 +01:00
|
|
|
// /**
|
|
|
|
// * This dialog doesn't show setting permissions, it use default server permissions
|
|
|
|
// * @param workspace itemId to share
|
|
|
|
// */
|
|
|
|
// public WorkspaceSharingController(String itemId) {
|
|
|
|
// }
|
|
|
|
//
|
2014-02-27 16:03:30 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* This dialog show setting permissions
|
|
|
|
* @param itemId workace item id
|
|
|
|
* @param shareOnlyOwner if true, only owner can share
|
|
|
|
* @param defaultPermission ACL_TYPE default permission
|
|
|
|
*/
|
|
|
|
public WorkspaceSharingController(String itemId, boolean shareOnlyOwner, ACL_TYPE defaultPermission) {
|
|
|
|
this.workspaceItemId = itemId;
|
|
|
|
this.shareOnlyOwner = shareOnlyOwner;
|
|
|
|
this.defaultPermission = defaultPermission;
|
|
|
|
|
2014-02-28 12:30:44 +01:00
|
|
|
|
|
|
|
if(workspaceItemId==null || workspaceItemId.isEmpty()){
|
|
|
|
MessageBox.alert("Error", "Item id is null or empty", null);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
initWindow();
|
|
|
|
|
2014-02-27 16:03:30 +01:00
|
|
|
if(shareOnlyOwner){
|
2014-02-28 12:30:44 +01:00
|
|
|
loadMyLogin(true, true);
|
|
|
|
}else{
|
|
|
|
loadFileModel(true);
|
2014-02-27 16:03:30 +01:00
|
|
|
}
|
2014-02-28 12:30:44 +01:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void initWindow(){
|
2014-03-03 15:54:53 +01:00
|
|
|
sharingDialog = new DialogShareWItem();
|
|
|
|
sharingDialog.setSize(ConstantsSharing.WIDTH_DIALOG+20, ConstantsSharing.HEIGHT_DIALOG+20);
|
|
|
|
sharingDialog.mask("Loading File from Workspace", ConstantsSharing.LOADINGSTYLE);
|
2014-02-27 16:03:30 +01:00
|
|
|
}
|
|
|
|
|
2014-02-28 12:30:44 +01:00
|
|
|
|
|
|
|
private void loadFileModel(final boolean showSharingDialog){
|
|
|
|
|
|
|
|
rpcWorkspaceSharingService.getFileModelByWorkpaceItemId(workspaceItemId, new AsyncCallback<FileModel>() {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onFailure(Throwable caught) {
|
2014-03-03 15:54:53 +01:00
|
|
|
sharingDialog.unmask();
|
2014-02-28 12:30:44 +01:00
|
|
|
MessageBox.alert("Error", caught.getMessage(), null);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onSuccess(FileModel result) {
|
2014-03-03 15:54:53 +01:00
|
|
|
sharingDialog.unmask();
|
|
|
|
sharingDialog.mask("File loaded", ConstantsSharing.LOADINGSTYLE);
|
2014-02-28 12:30:44 +01:00
|
|
|
|
|
|
|
if(showSharingDialog)
|
2014-03-03 15:54:53 +01:00
|
|
|
updateSharingDialog(result);
|
2014-02-28 12:30:44 +01:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @param fileModel
|
|
|
|
*/
|
2014-03-03 15:54:53 +01:00
|
|
|
private void updateSharingDialog(FileModel fileModel){
|
|
|
|
sharingDialog.unmask();
|
|
|
|
sharingDialog.updateSharingDialog(fileModel, shareOnlyOwner, defaultPermission);
|
|
|
|
// dialogShareItem.show();
|
2014-02-28 12:30:44 +01:00
|
|
|
|
2014-03-03 15:54:53 +01:00
|
|
|
sharingDialog.layout();
|
2014-02-28 12:30:44 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @param loadFileModel
|
|
|
|
* @param showSharingDialog
|
|
|
|
*/
|
|
|
|
private void loadMyLogin(final boolean loadFileModel, final boolean showSharingDialog) {
|
2014-02-25 15:58:42 +01:00
|
|
|
|
|
|
|
rpcWorkspaceSharingService.getMyLogin(new AsyncCallback<String>() {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onFailure(Throwable caught) {
|
|
|
|
GWT.log("Error on loading my login is empty");
|
|
|
|
myLogin = "";
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onSuccess(String result) {
|
|
|
|
GWT.log("My login is: " + result);
|
|
|
|
myLogin = result;
|
2014-02-28 12:30:44 +01:00
|
|
|
|
|
|
|
if(loadFileModel)
|
|
|
|
loadFileModel(showSharingDialog);
|
2014-02-25 15:58:42 +01:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2014-02-27 16:03:30 +01:00
|
|
|
public static String getMyLogin() {
|
|
|
|
return myLogin;
|
|
|
|
}
|
|
|
|
|
|
|
|
public String getWorkspaceItemId() {
|
|
|
|
return workspaceItemId;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public boolean isShareOnlyOwner() {
|
|
|
|
return shareOnlyOwner;
|
|
|
|
}
|
|
|
|
|
2014-02-27 16:11:36 +01:00
|
|
|
|
|
|
|
public ACL_TYPE getDefaultPermission() {
|
|
|
|
return defaultPermission;
|
2014-02-27 16:03:30 +01:00
|
|
|
}
|
|
|
|
|
2014-02-28 12:30:44 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @return
|
|
|
|
*/
|
2014-03-03 15:54:53 +01:00
|
|
|
public Window getSharingDialog() {
|
|
|
|
return sharingDialog;
|
2014-02-28 12:30:44 +01:00
|
|
|
}
|
|
|
|
|
2014-02-25 14:28:30 +01:00
|
|
|
}
|