git-svn-id: http://svn.d4science-ii.research-infrastructures.eu/gcube/trunk/portlets/user/workspace-tree-widget@98506 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Francesco Mangiacrapa 2014-07-08 16:41:53 +00:00
parent ccf3e74207
commit fa8d28899e
14 changed files with 280 additions and 40 deletions

View File

@ -11,6 +11,7 @@
<!-- Moduel GXT -->
<inherits name='com.extjs.gxt.ui.GXT'/>
<inherits name="org.gcube.portlets.widgets.workspacesharingwidget.WorkspaceSharingWidget" />
<servlet path="/WorkspaceService" class="org.gcube.portlets.user.workspace.server.GWTWorkspaceServiceImpl" />
<!--

View File

@ -10,6 +10,8 @@ import org.gcube.portlets.user.workspace.client.event.AccountingHistoryEvent;
import org.gcube.portlets.user.workspace.client.event.AccountingHistoryEventHandler;
import org.gcube.portlets.user.workspace.client.event.AccountingReadersEvent;
import org.gcube.portlets.user.workspace.client.event.AccountingReadersEventHandler;
import org.gcube.portlets.user.workspace.client.event.AddAdministratorEvent;
import org.gcube.portlets.user.workspace.client.event.AddAdministratorEventHandler;
import org.gcube.portlets.user.workspace.client.event.AddFolderEvent;
import org.gcube.portlets.user.workspace.client.event.AddFolderEventHandler;
import org.gcube.portlets.user.workspace.client.event.AddSmartFolderEvent;
@ -101,6 +103,7 @@ import org.gcube.portlets.user.workspace.client.interfaces.SubscriberInterface;
import org.gcube.portlets.user.workspace.client.interfaces.TreeAppControllerInterface;
import org.gcube.portlets.user.workspace.client.model.FileModel;
import org.gcube.portlets.user.workspace.client.model.FolderModel;
import org.gcube.portlets.user.workspace.client.model.InfoContactModel;
import org.gcube.portlets.user.workspace.client.model.MessageModel;
import org.gcube.portlets.user.workspace.client.model.SmartFolderModel;
import org.gcube.portlets.user.workspace.client.model.SubTree;
@ -140,6 +143,11 @@ import org.gcube.portlets.widgets.fileupload.client.events.FileUploadCompleteEve
import org.gcube.portlets.widgets.fileupload.client.events.FileUploadCompleteEventHandler;
import org.gcube.portlets.widgets.fileupload.client.events.FileUploadSelectedEvent;
import org.gcube.portlets.widgets.fileupload.client.events.FileUploadSelectedEventHandler;
import org.gcube.portlets.widgets.workspacesharingwidget.client.SmartConstants;
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.vomanagement.usermanagement.ws.ListUsers;
import com.extjs.gxt.ui.client.Registry;
import com.extjs.gxt.ui.client.event.BaseEvent;
@ -148,6 +156,7 @@ import com.extjs.gxt.ui.client.event.Listener;
import com.extjs.gxt.ui.client.event.MessageBoxEvent;
import com.extjs.gxt.ui.client.widget.Dialog;
import com.extjs.gxt.ui.client.widget.Info;
import com.extjs.gxt.ui.client.widget.MessageBox;
import com.google.gwt.core.client.GWT;
import com.google.gwt.event.shared.EventHandler;
import com.google.gwt.event.shared.HandlerManager;
@ -271,6 +280,45 @@ public class AppControllerExplorer implements EventHandler, TreeAppControllerInt
}
});
eventBus.addHandler(AddAdministratorEvent.TYPE, new AddAdministratorEventHandler() {
@Override
public void onAddAdministrator(AddAdministratorEvent addAdministratorEvent) {
final FileModel file = addAdministratorEvent.getSelectedFolder();
if(file==null || file.getIdentifier()==null)
return;
rpcWorkspaceService.getOwnerByItemId(file.getIdentifier(), new AsyncCallback<InfoContactModel>() {
@Override
public void onFailure(Throwable caught) {
if(caught instanceof SessionExpiredException){
GWT.log("Session expired");
eventBus.fireEvent(new SessionExpiredEvent());
return;
}
new MessageBoxAlert("Error", "Sorry, an error occurred on recovering the contacts, try again later", null);
explorerPanel.unmask();
}
@Override
public void onSuccess(InfoContactModel infoContactModel) {
//IF IS OWNER
if(AppControllerExplorer.myLogin.compareToIgnoreCase(infoContactModel.getLogin())==0)
showAddAdministratorsDialog(file);
else
new MessageBoxAlert("Permission denied", "You have no permissions to add administrators. You are not manager of \""+file.getName()+"\"", null);
}
});
}
});
eventBus.addHandler(GetInfoEvent.TYPE, new GetInfoEventHandler() {
@Override
@ -576,8 +624,6 @@ public class AppControllerExplorer implements EventHandler, TreeAppControllerInt
boolean isLoading = BulkCreatorWindow.getInstance().addProgressBar(bulkCreatorEvent.getListBulks());
explorerPanel.setLoadingBulk(isLoading);
}
});
@ -596,7 +642,6 @@ public class AppControllerExplorer implements EventHandler, TreeAppControllerInt
GWT.log("PasteItemEvent is fired on : "+pasteItemEvent.getIds().size()+ "items, DestinationId: "+pasteItemEvent.getFolderDestinationId());
doCutCopyAndPaste(pasteItemEvent);
}
private void doCutCopyAndPaste(final PasteItemEvent pasteItemEvent) {
@ -2109,6 +2154,78 @@ public class AppControllerExplorer implements EventHandler, TreeAppControllerInt
return this.explorerPanel;
}
/**
*
* @param file
* @param showAlert
*/
private void showAddAdministratorsDialog(final FileModel file) {
org.gcube.portlets.widgets.workspacesharingwidget.shared.FileModel internalFile = new org.gcube.portlets.widgets.workspacesharingwidget.shared.FileModel(file.getIdentifier(), file.getName(), file.isDirectory());
WorkspaceSmartSharingController controller = new WorkspaceSmartSharingController(internalFile, null, false, false);
SmartConstants.HEADER_TITLE = "Add Administrators to: "+file.getName();
SmartConstants.SHARE_WITH_USERS = "Manage with users";
SmartConstants.ERROR_NO_USER_SELECTED = "You must pick at least one user to add to Administrators";
final SmartShare sharingWindow = controller.getSharingDialog();
sharingWindow.getButtonById(Dialog.OK).addListener(Events.Select, new Listener<BaseEvent>() {
@Override
public void handleEvent(BaseEvent be) {
if(sharingWindow.isValidForm(true)){
//THAT'S OK
List<org.gcube.portlets.widgets.workspacesharingwidget.shared.InfoContactModel> listUsers = sharingWindow.getSharedListUsers(); //@return the selected contacts (as InfoContactModel)
if(listUsers!=null && listUsers.size()>0){
List<String> logins = new ArrayList<String>(listUsers.size());
for (org.gcube.portlets.widgets.workspacesharingwidget.shared.InfoContactModel infoContactModel : listUsers) {
logins.add(infoContactModel.getLogin());
}
doAddAdministratorToFolderId(file, logins);
}
}
}
});
sharingWindow.show();
}
private void doAddAdministratorToFolderId(final FileModel file, final List<String> logins) {
rpcWorkspaceService.addAdministratorsByFolderId(file.getIdentifier(), logins, new AsyncCallback<Boolean>() {
@Override
public void onFailure(Throwable arg0) {
new MessageBoxAlert("Error", arg0.getMessage(), null);
}
@Override
public void onSuccess(Boolean arg0) {
String title = "Added";
String admin = logins.size()>1?"administrators":"administrator";
title += " "+admin;
String msg = logins.size() + " "+admin +" added correctly to "+file.getName();
MessageBox.info(title, msg, null);
}
});
}
private void loadMyLogin(){
rpcWorkspaceService.getMyLogin(new AsyncCallback<String>() {

View File

@ -34,39 +34,9 @@ public enum WorkspaceOperation {
ACCREAD("ACR", "ACR"), //ACCOUNTING READ
SHARE_LINK("SLK", "SLK"), //SHARE URL LINK
PUBLIC_LINK("PLK", "PLK"), //PUBLIC LINK
VRE_CHANGE_PERIMISSIONS("CHP", "CHP");
VRE_CHANGE_PERIMISSIONS("CHP", "CHP"),
ADD_ADMINISTRATOR("AAD", "AAD"); // ADD_ADMINISTRATOR
// //ID CONTEXT MENU
// public static final String INS = "INS"; //Insert Folder
// public static final String ADD = "ADD";
// public static final String REM = "REM";
// public static final String UPL = "UPL"; //Upload File
// public static final String DWL = "DWL";
// public static final String PRW = "PRW";
// public static final String RNM = "RNM";
// public static final String ISHF = "ASHF"; //Insert shared Folder
// public static final String SHR = "SHR"; //SHARE
// public static final String USHR = "USHR"; //UNSHARE
// public static final String UPA = "UPA"; //Upload Archive
// public static final String LNK = "LNK";
// public static final String SHW = "SHW";
// public static final String CLK = "CLK"; //Add Url
// public static final String ORT = "ORT"; //Open report template
// public static final String ORP = "ORP"; //Open report
// public static final String SDT = "SDT"; //Send to
// public static final String DWM = "DWN"; //Get all new messages
// public static final String MKR = "MKR"; //Mark as read
// public static final String MKNR = "MKNR"; //Mark as not read
// public static final String DLM = "DLM"; //Delete message
// public static final String FWM = "FWM"; //Forward message
// public static final String CPI = "CPI"; //copy item
// public static final String PSI = "PSI"; //paste
// public static final String RFH = "RFH"; //Refresh
// public static final String WDV = "WDV"; //WebDav
// public static final String CNM = "CNM"; //Create new message
// public static final String GTI = "GTI"; //GET INFO
private String id; // ID CONTEXT MENU
private String name;

View File

@ -0,0 +1,48 @@
package org.gcube.portlets.user.workspace.client.event;
import org.gcube.portlets.user.workspace.client.interfaces.EventsTypeEnum;
import org.gcube.portlets.user.workspace.client.interfaces.GuiEventInterface;
import org.gcube.portlets.user.workspace.client.model.FileModel;
import com.google.gwt.event.shared.GwtEvent;
/**
*
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
* @Jul 8, 2014
*
*/
public class AddAdministratorEvent extends GwtEvent<AddAdministratorEventHandler> implements GuiEventInterface{
public static Type<AddAdministratorEventHandler> TYPE = new Type<AddAdministratorEventHandler>();
private FileModel folder;
public AddAdministratorEvent(FileModel folder) {
this.folder = folder;
}
@Override
public Type<AddAdministratorEventHandler> getAssociatedType() {
return TYPE;
}
@Override
protected void dispatch(AddAdministratorEventHandler handler) {
handler.onAddAdministrator(this);
}
@Override
public EventsTypeEnum getKey() {
return EventsTypeEnum.ADD_ADMINISTRATOR_EVENT;
}
public FileModel getSelectedFolder() {
return folder;
}
}

View File

@ -0,0 +1,17 @@
package org.gcube.portlets.user.workspace.client.event;
import com.google.gwt.event.shared.EventHandler;
/**
*
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
* @Jul 8, 2014
*
*/
public interface AddAdministratorEventHandler extends EventHandler {
/**
* @param addAdministratorEvent
*/
void onAddAdministrator(AddAdministratorEvent addAdministratorEvent);
}

View File

@ -31,5 +31,6 @@ public enum EventsTypeEnum
PASTED_EVENT,
COPY_EVENT,
TRASH_EVENT,
UPDATED_VRE_PERMISSION;
UPDATED_VRE_PERMISSION,
ADD_ADMINISTRATOR_EVENT;
}

View File

@ -310,6 +310,9 @@ public interface Icons extends ClientBundle {
@Source("icons/admin.png")
ImageResource administrator();
@Source("icons/add_admin.png")
ImageResource addAdmin();
@Source("icons/specialfolder2.png")
ImageResource specialFolder();

View File

@ -519,6 +519,13 @@ public class Resources {
public static AbstractImagePrototype getSelectedRight() {
return AbstractImagePrototype.create(ICONS.selectedRight());
}
/**
* @return
*/
public static AbstractImagePrototype getIconAddAdministrator() {
return AbstractImagePrototype.create(ICONS.addAdmin());
}
//ImageResources
public static ImageResource getImagePathSeparator(){
@ -664,8 +671,5 @@ public class Resources {
// System.out.println("extensions - "+extension);
return Resources.getIconByExtension(extension);
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 933 B

View File

@ -252,4 +252,7 @@ public interface GWTWorkspaceService extends RemoteService{
TrashOperationContent executeOperationOnTrash(List<String> listTrashItemIds,
WorkspaceTrashOperation operation) throws Exception;
boolean addAdministratorsByFolderId(String folderId,
List<String> listContactIds) throws Exception;
}

View File

@ -203,5 +203,8 @@ public interface GWTWorkspaceServiceAsync {
void executeOperationOnTrash(List<String> listTrashItemIds,
WorkspaceTrashOperation operation,
AsyncCallback<TrashOperationContent> callback);
void addAdministratorsByFolderId(String folderId, List<String> listLogins,
AsyncCallback<Boolean> callback);
}

View File

@ -5,6 +5,7 @@ package org.gcube.portlets.user.workspace.client.util;
import org.gcube.portlets.user.workspace.client.resources.Resources;
import org.gcube.portlets.user.workspace.shared.WorkspaceACL;
import org.gcube.portlets.user.workspace.shared.WorkspaceACL.USER_TYPE;
import com.google.gwt.user.client.ui.AbstractImagePrototype;
@ -34,5 +35,19 @@ public class GetPermissionIconByACL {
return null;
}
public static AbstractImagePrototype getImage(WorkspaceACL.USER_TYPE userType) {
if(userType==null)
return null;
if (userType.equals(USER_TYPE.ADMINISTRATOR)) {
return Resources.getIconAdministrator();
} else if (userType.equals(USER_TYPE.GROUP)) {
return Resources.getIconUsers();
}
return null;
}
}

View File

@ -8,6 +8,7 @@ import org.gcube.portlets.user.workspace.client.ConstantsExplorer;
import org.gcube.portlets.user.workspace.client.constant.WorkspaceOperation;
import org.gcube.portlets.user.workspace.client.event.AccountingHistoryEvent;
import org.gcube.portlets.user.workspace.client.event.AccountingReadersEvent;
import org.gcube.portlets.user.workspace.client.event.AddAdministratorEvent;
import org.gcube.portlets.user.workspace.client.event.AddFolderEvent;
import org.gcube.portlets.user.workspace.client.event.CopytemEvent;
import org.gcube.portlets.user.workspace.client.event.CreateSharedFolderEvent;
@ -583,6 +584,25 @@ public class ContextMenuTree {
contextMenu.add(changePermission);
contextMenu.add(new SeparatorMenuItem());
MenuItem addAdministrator = new MenuItem();
addAdministrator.setId(WorkspaceOperation.ADD_ADMINISTRATOR.getId());
addAdministrator.setText("Add Administrator/s");
addAdministrator.setIcon(Resources.getIconAddAdministrator());
addAdministrator.addSelectionListener(new SelectionListener<MenuEvent>() {
public void componentSelected(MenuEvent ce) {
for (FileModel sel : listSelectedItems) {
eventBus.fireEvent(new AddAdministratorEvent(sel));
}
}
});
contextMenu.add(addAdministrator);
MenuItem refreshItem = new MenuItem();
refreshItem.setId(WorkspaceOperation.REFRESH_FOLDER.getId());
@ -709,7 +729,8 @@ public class ContextMenuTree {
contextMenu.getItemByItemId(WorkspaceOperation.PASTE.getId()).setEnabled(false); //paste
contextMenu.getItemByItemId(WorkspaceOperation.REFRESH_FOLDER.getId()).setVisible(false); //refresh
contextMenu.getItemByItemId(WorkspaceOperation.PUBLIC_LINK.getId()).setVisible(false); //public link
contextMenu.getItemByItemId(WorkspaceOperation.ADD_ADMINISTRATOR.getId()).setVisible(false); //public link
contextMenu.getItemByItemId(WorkspaceOperation.SHARE.getId()).setVisible(false); //SHARE
contextMenu.getItemByItemId(WorkspaceOperation.UNSHARE.getId()).setVisible(false); //UNSHARE
@ -776,6 +797,8 @@ public class ContextMenuTree {
contextMenu.getItemByItemId(WorkspaceOperation.SENDTO.getId()).setVisible(false); //send to
if(selectedItem.isShared()){//IS SHARED
contextMenu.getItemByItemId(WorkspaceOperation.ADD_ADMINISTRATOR.getId()).setVisible(true); //add administrator
if(selectedItem.isShareable()){ //IS SHARABLE
contextMenu.getItemByItemId(WorkspaceOperation.INSERT_SHARED_FOLDER.getId()).setVisible(false); //insert shared folder
contextMenu.getItemByItemId(WorkspaceOperation.UNSHARE.getId()).setVisible(true);

View File

@ -3032,5 +3032,40 @@ public class GWTWorkspaceServiceImpl extends RemoteServiceServlet implements GWT
throw new Exception(error);
}
}
/* (non-Javadoc)
* @see org.gcube.portlets.user.workspace.client.rpc.GWTWorkspaceService#addAdministratorsByFolderId(java.lang.String, java.util.List)
*
* true if administrators have been added, false otherwise
*/
@Override
public boolean addAdministratorsByFolderId(String folderId, List<String> listContactLogins) throws Exception {
if(folderId==null || listContactLogins==null || listContactLogins.size()==0)
return false;
try {
Workspace workspace = getWorkspace();
WorkspaceItem item = workspace.getItem(folderId);
workspaceLogger.info("Adding administator/s to folder: "+folderId);
if(item.getType().equals(WorkspaceItemType.SHARED_FOLDER)){
WorkspaceSharedFolder sharedFolder = (WorkspaceSharedFolder) item;
for (String login : listContactLogins) {
workspaceLogger.info("Setting administator: "+login);
sharedFolder.setAdmin(login);
}
return true;
}else
throw new Exception("The item is not instanceof "+WorkspaceItemType.SHARED_FOLDER);
} catch (Exception e) {
workspaceLogger.error("Error in server addAdministratorsByFolderId: "+e.getMessage());
workspaceLogger.error(e);
String error = ConstantsExplorer.SERVER_ERROR +" adding administrators, try again later";
throw new Exception(error);
}
}
}