ref 17169: Selection of users in the Sharing panel

https://support.d4science.org/issues/17169

Added support to admins discovery by VREs

git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/portlets/widgets/workspace-sharing-widget@181337 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Giancarlo Panichi 2019-07-26 18:14:13 +00:00
parent 600dddc376
commit 2bebec9b84
23 changed files with 1656 additions and 613 deletions

View File

@ -31,5 +31,14 @@
<!-- Specify the paths for translatable code -->
<source path='client' />
<source path='shared' />
<!-- <inherits name="com.google.gwt.logging.Logging" /> -->
<!-- <set-property name="gwt.logging.logLevel" value="SEVERE" /> -->
<!-- <set-property name="gwt.logging.enabled" value="TRUE" /> -->
<!-- <set-property name="gwt.logging.consoleHandler" value="ENABLED"/> -->
<!-- <set-property name="gwt.logging.firebugHandler" value="ENABLED" /> -->
<!-- <set-property name="gwt.logging.popupHandler" value="ENABLED" /> -->
</module>

View File

@ -10,8 +10,8 @@ import org.gcube.portlets.widgets.workspacesharingwidget.client.permissions.Mess
import org.gcube.portlets.widgets.workspacesharingwidget.client.permissions.PanelTogglePermission;
import org.gcube.portlets.widgets.workspacesharingwidget.client.rpc.WorkspaceSharingServiceAsync;
import org.gcube.portlets.widgets.workspacesharingwidget.client.view.sharing.UserStore;
import org.gcube.portlets.widgets.workspacesharingwidget.client.view.sharing.multisuggest.DialogMultiDragContact;
import org.gcube.portlets.widgets.workspacesharingwidget.client.view.sharing.multisuggest.MultiDragContact;
import org.gcube.portlets.widgets.workspacesharingwidget.client.view.sharing.user.DialogMultiDragContact;
import org.gcube.portlets.widgets.workspacesharingwidget.client.view.sharing.user.MultiDragContact;
import org.gcube.portlets.widgets.workspacesharingwidget.shared.InfoContactModel;
import org.gcube.portlets.widgets.workspacesharingwidget.shared.WorkspaceACL;
@ -42,9 +42,7 @@ public class MultiDragContactsEditPermissions {
private UserStore userStore = new UserStore();
private ConstantsSharing.LOAD_CONTACTS_AS loadContactAs;
private DialogMultiDragContact dialogMultiDragContact = new DialogMultiDragContact(
MultiDragConstants.HEADING_DIALOG, MultiDragConstants.ALL_CONTACTS_LEFT_LIST,
MultiDragConstants.SHARE_WITH_RIGHT_LIST, false, false);
private DialogMultiDragContact dialogMultiDragContact;
private List<InfoContactModel> sources = new ArrayList<InfoContactModel>();
private boolean hiddenMySelf;
private String workspaceItemId;
@ -54,6 +52,9 @@ public class MultiDragContactsEditPermissions {
public MultiDragContactsEditPermissions(ConstantsSharing.LOAD_CONTACTS_AS load, final String workspaceItemId,
boolean hiddenMySelf) {
dialogMultiDragContact= new DialogMultiDragContact(
MultiDragConstants.HEADING_DIALOG, MultiDragConstants.ALL_CONTACTS_LEFT_LIST,
MultiDragConstants.SHARE_WITH_RIGHT_LIST, false, false,hiddenMySelf);
initMultiDrag(load, workspaceItemId, hiddenMySelf);
// dialog = super.getDialogMultiDragContact();

View File

@ -0,0 +1,57 @@
/**
*
*/
package org.gcube.portlets.widgets.workspacesharingwidget.client;
import java.util.List;
import org.gcube.portlets.widgets.workspacesharingwidget.client.view.sharing.admin.DialogMultiDragContactAdmin;
import org.gcube.portlets.widgets.workspacesharingwidget.shared.InfoContactModel;
import com.google.gwt.core.client.GWT;
/**
* @author Francesco Mangiacrapa Jul 30, 2014
*
* A simple multi drag dialog to manage users administrators of a
* workspace item
*/
public class MultiDragWorkspaceContactAdmin {
private DialogMultiDragContactAdmin dialogMultiDragContactAdmin;
/**
* Load administrators or shared users to workspace item id
*
* @param workspaceItemId
* Item id
*
* @param workspaceItemId
*/
public MultiDragWorkspaceContactAdmin(String workspaceItemId) {
GWT.log("MultiDragWorkspaceContactAdmin(): "+workspaceItemId);
try {
dialogMultiDragContactAdmin = new DialogMultiDragContactAdmin(MultiDragConstants.HEADING_DIALOG,
MultiDragConstants.ALL_CONTACTS_LEFT_LIST, MultiDragConstants.SHARE_WITH_RIGHT_LIST, workspaceItemId);
} catch (Throwable e){
GWT.log("Error in MultiDragWorkspaceContactAdmin(): "+e.getLocalizedMessage(),e);
}
}
/**
*
* @return the multi drag DialogMultiDragContact
*/
public DialogMultiDragContactAdmin getDialogMultiDragContact() {
return dialogMultiDragContactAdmin;
}
public void show() {
dialogMultiDragContactAdmin.show();
}
public List<InfoContactModel> getTargetContacts() {
return dialogMultiDragContactAdmin.getMultiDrag().getTargetListContactWithMyLogin();
}
}

View File

@ -8,7 +8,7 @@ import java.util.List;
import org.gcube.portlets.widgets.workspacesharingwidget.client.rpc.WorkspaceSharingServiceAsync;
import org.gcube.portlets.widgets.workspacesharingwidget.client.view.sharing.UserStore;
import org.gcube.portlets.widgets.workspacesharingwidget.client.view.sharing.multisuggest.DialogMultiDragContact;
import org.gcube.portlets.widgets.workspacesharingwidget.client.view.sharing.user.DialogMultiDragContact;
import org.gcube.portlets.widgets.workspacesharingwidget.shared.InfoContactModel;
import com.extjs.gxt.ui.client.widget.MessageBox;
@ -18,19 +18,14 @@ import com.google.gwt.user.client.rpc.AsyncCallback;
/**
* @author Francesco Mangiacrapa Jul 30, 2014
*
* A simple multi drag dialog to manage users (shared or administrators)
* A simple multi drag dialog to manage users administrators
* of a workspace item
*/
public class SimpleMultiDragWorkspaceContact {
public class MultiDragWorkspaceContactUser {
private UserStore userStore = new UserStore();
private ConstantsSharing.LOAD_CONTACTS_AS loadContactAs;
private DialogMultiDragContact dialogMultiDragContact = new DialogMultiDragContact(
MultiDragConstants.HEADING_DIALOG, MultiDragConstants.ALL_CONTACTS_LEFT_LIST,
MultiDragConstants.SHARE_WITH_RIGHT_LIST, false, false);
private DialogMultiDragContact dialogMultiDragContactSimple;
private List<InfoContactModel> targets = new ArrayList<InfoContactModel>();
private boolean readGroupsFromPortal;
private boolean readGroupsFromHL;
private boolean hiddenMySelf;
private String workspaceItemId;
private String myLogin;
@ -39,36 +34,29 @@ public class SimpleMultiDragWorkspaceContact {
/**
* Load administrators or shared users to workspace item id
*
* @param load
* if LOAD_CONTACTS_AS.SHARED_USER loads target users from Shared
* Users if LOAD_CONTACTS_AS.ADMINISTRATOR loads target users
* from Administrators
*
* @param workspaceItemId
* Item id
* @param readGroupsFromHL
* Groups
* @param readGroupsFromPortal
* Portal
* @param hiddenMySelf
* if true the login read from ASL is hidden (so it's not
* removable to target users), the login returned anyway among
* the target users
*/
public SimpleMultiDragWorkspaceContact(ConstantsSharing.LOAD_CONTACTS_AS load, String workspaceItemId,
final boolean readGroupsFromHL, final boolean readGroupsFromPortal, final boolean hiddenMySelf) {
this.loadContactAs = load;
this.readGroupsFromHL = readGroupsFromHL;
this.readGroupsFromPortal = readGroupsFromPortal;
this.hiddenMySelf = hiddenMySelf;
public MultiDragWorkspaceContactUser(String workspaceItemId,
final boolean hiddenMySelf) {
this.workspaceItemId = workspaceItemId;
dialogMultiDragContactSimple=new DialogMultiDragContact(
MultiDragConstants.HEADING_DIALOG, MultiDragConstants.ALL_CONTACTS_LEFT_LIST,
MultiDragConstants.SHARE_WITH_RIGHT_LIST, false, false, hiddenMySelf);
if (hiddenMySelf)
loadMyLogin(true);
else
loadSharedContacts();
}
private void loadMyLogin(final boolean loadContacts) {
WorkspaceSharingServiceAsync.INSTANCE.getMyLogin(new AsyncCallback<String>() {
@ -96,31 +84,7 @@ public class SimpleMultiDragWorkspaceContact {
*/
private void loadSharedContacts() {
switch (loadContactAs) {
case ADMINISTRATOR:
// LOADING LIST OF ALREADY SHARED USER
userStore.getAdministratorsByFolderId(workspaceItemId, new AsyncCallback<List<InfoContactModel>>() {
@Override
public void onFailure(Throwable caught) {
GWT.log("Error on loading admnistrators");
MessageBox.alert("Error on loading admnistrators", caught.getMessage(), null);
}
@Override
public void onSuccess(List<InfoContactModel> result) {
GWT.log("Returned " + result.size() + " admin/s");
fillMultiDrag(result);
loadAllContacts(readGroupsFromHL, readGroupsFromPortal);
}
});
break;
case SHARED_USER:
// LOADING LIST OF ALREADY SHARED USER
userStore.getListSharedUserByFolderId(workspaceItemId, new AsyncCallback<List<InfoContactModel>>() {
@ -129,7 +93,7 @@ public class SimpleMultiDragWorkspaceContact {
public void onSuccess(List<InfoContactModel> result) {
GWT.log("Returned " + result.size() + " contact/s");
fillMultiDrag(result);
loadAllContacts(readGroupsFromHL, readGroupsFromPortal);
loadAllContacts();
}
@Override
@ -140,24 +104,10 @@ public class SimpleMultiDragWorkspaceContact {
}
});
break;
default:
loadAllContacts(readGroupsFromHL, readGroupsFromPortal);
break;
}
}
public void addTargetContact(List<InfoContactModel> listContacts) {
if (listContacts != null) {
for (InfoContactModel infoContactModel : listContacts) {
dialogMultiDragContact.getMultiDrag().addTargetContact(infoContactModel);
}
}
}
private void fillMultiDrag(List<InfoContactModel> result) {
GWT.log("Filling multi-drag..");
@ -169,7 +119,7 @@ public class SimpleMultiDragWorkspaceContact {
myContact = infoContactModel;
GWT.log("Skipping myLogin as: " + myContact);
} else {
dialogMultiDragContact.getMultiDrag().addTargetContact(infoContactModel);
dialogMultiDragContactSimple.getMultiDrag().addTargetContact(infoContactModel);
targets.add(infoContactModel);
}
}
@ -179,7 +129,7 @@ public class SimpleMultiDragWorkspaceContact {
/**
* Load all contacts
*/
private void loadAllContacts(boolean readGroupsFromHL, boolean readGroupsFromPortal) {
private void loadAllContacts() {
userStore.getListContact(addSourceContacts, false);
}
@ -199,9 +149,25 @@ public class SimpleMultiDragWorkspaceContact {
if (result != null && result.size() > 0) {
if (hiddenMySelf)
contactTargets.add(myContact);
AsyncCallback<List<InfoContactModel>> callback=new AsyncCallback<List<InfoContactModel>>() {
List<InfoContactModel> exclusiveContacts = userStore.getExclusiveContactsFromAllContact(contactTargets);
dialogMultiDragContact.getMultiDrag().addSourceContacts(exclusiveContacts);
@Override
public void onFailure(Throwable caught) {
GWT.log("Error retrieving contacts: "+caught,caught);
}
@Override
public void onSuccess(List<InfoContactModel> result) {
GWT.log("Contact List retrieved");
dialogMultiDragContactSimple.getMultiDrag().addSourceContacts(result);
}
};
userStore.getExclusiveContactsFromAllContact(contactTargets,callback);
}
}
};
@ -211,16 +177,16 @@ public class SimpleMultiDragWorkspaceContact {
* @return the multi drag DialogMultiDragContact
*/
public DialogMultiDragContact getDialogMultiDragContact() {
return dialogMultiDragContact;
return dialogMultiDragContactSimple;
}
public void show() {
dialogMultiDragContact.show();
dialogMultiDragContactSimple.show();
}
public List<InfoContactModel> getTargetContacts() {
return dialogMultiDragContact.getMultiDrag().getTargetListContact();
return dialogMultiDragContactSimple.getMultiDrag().getTargetListContact();
}
public List<InfoContactModel> getTargetContactsWithMyLogin() {

View File

@ -1,7 +1,7 @@
package org.gcube.portlets.widgets.workspacesharingwidget.client;
import org.gcube.portlets.widgets.workspacesharingwidget.client.resources.Resources;
import org.gcube.portlets.widgets.workspacesharingwidget.client.view.sharing.multisuggest.MultiDragContact;
import org.gcube.portlets.widgets.workspacesharingwidget.client.view.sharing.user.MultiDragContact;
import com.extjs.gxt.ui.client.Style.HorizontalAlignment;
import com.extjs.gxt.ui.client.Style.Scroll;

View File

@ -87,8 +87,8 @@ public class WorkspaceSharingWidgetEntryPoint implements EntryPoint {
private void showSimpleMultiDrag() {
final SimpleMultiDragWorkspaceContact multiDragContact = new SimpleMultiDragWorkspaceContact(
ConstantsSharing.LOAD_CONTACTS_AS.SHARED_USER, ITEMID, true, false, true);
final MultiDragWorkspaceContactUser multiDragContact = new MultiDragWorkspaceContactUser(
ITEMID, true);
Button openSharingWindow = new Button("Show Simple Multi Drag", new ClickHandler() {
public void onClick(ClickEvent event) {

View File

@ -6,9 +6,9 @@ import org.gcube.portlets.widgets.workspacesharingwidget.shared.AllowAccess;
import org.gcube.portlets.widgets.workspacesharingwidget.shared.CredentialModel;
import org.gcube.portlets.widgets.workspacesharingwidget.shared.ExtendedWorkspaceACL;
import org.gcube.portlets.widgets.workspacesharingwidget.shared.FileModel;
import org.gcube.portlets.widgets.workspacesharingwidget.shared.GGroup;
import org.gcube.portlets.widgets.workspacesharingwidget.shared.InfoContactModel;
import org.gcube.portlets.widgets.workspacesharingwidget.shared.ReportAssignmentACL;
import org.gcube.portlets.widgets.workspacesharingwidget.shared.UserVRE;
import org.gcube.portlets.widgets.workspacesharingwidget.shared.WorkspaceACL;
import com.google.gwt.user.client.rpc.RemoteService;
@ -26,9 +26,9 @@ public interface WorkspaceSharingService extends RemoteService {
List<InfoContactModel> getUsersByKeyword(String keyword) throws Exception;
List<GGroup> getVREList() throws Exception;
List<UserVRE> getUserVREList() throws Exception;
List<InfoContactModel> getAllContactsByVRE(GGroup gGroup) throws Exception;
List<InfoContactModel> getAllContactsByVRE(UserVRE gGroup) throws Exception;
List<InfoContactModel> getListUserSharedByFolderSharedId(String folderSharedId) throws Exception;

View File

@ -6,9 +6,9 @@ import org.gcube.portlets.widgets.workspacesharingwidget.shared.AllowAccess;
import org.gcube.portlets.widgets.workspacesharingwidget.shared.CredentialModel;
import org.gcube.portlets.widgets.workspacesharingwidget.shared.ExtendedWorkspaceACL;
import org.gcube.portlets.widgets.workspacesharingwidget.shared.FileModel;
import org.gcube.portlets.widgets.workspacesharingwidget.shared.GGroup;
import org.gcube.portlets.widgets.workspacesharingwidget.shared.InfoContactModel;
import org.gcube.portlets.widgets.workspacesharingwidget.shared.ReportAssignmentACL;
import org.gcube.portlets.widgets.workspacesharingwidget.shared.UserVRE;
import org.gcube.portlets.widgets.workspacesharingwidget.shared.WorkspaceACL;
import com.google.gwt.core.client.GWT;
@ -23,9 +23,9 @@ public interface WorkspaceSharingServiceAsync {
void getUsersByKeyword(String keyword, AsyncCallback<List<InfoContactModel>> callback);
void getVREList(AsyncCallback<List<GGroup>> callback);
void getUserVREList(AsyncCallback<List<UserVRE>> callback);
void getAllContactsByVRE(GGroup gGroup, AsyncCallback<List<InfoContactModel>> callback);
void getAllContactsByVRE(UserVRE gGroup, AsyncCallback<List<InfoContactModel>> callback);
void getListUserSharedByFolderSharedId(String folderSharedId, AsyncCallback<List<InfoContactModel>> callback);

View File

@ -13,8 +13,6 @@ public interface ContactFetcher {
public void getListSharedUserByFolderId(String sharedFolderId, AsyncCallback<List<InfoContactModel>> callback);
public List<InfoContactModel> getExclusiveContactsFromAllContact(List<InfoContactModel> listSharedUser);
public void getOwner(String sharedFolderId, AsyncCallback<InfoContactModel> callback);
public void getInfoContactModelsFromCredential(List<CredentialModel> listAlreadySharedContact,
@ -22,4 +20,7 @@ public interface ContactFetcher {
public void getAdministratorsByFolderId(String sharedFolderId, AsyncCallback<List<InfoContactModel>> callback);
public void getExclusiveContactsFromAllContact(List<InfoContactModel> listSharedUser,
AsyncCallback<List<InfoContactModel>> callback);
}

View File

@ -6,9 +6,9 @@ import java.util.List;
import org.gcube.portlets.widgets.workspacesharingwidget.client.ConstantsSharing;
import org.gcube.portlets.widgets.workspacesharingwidget.client.WorkspaceSharingController;
import org.gcube.portlets.widgets.workspacesharingwidget.client.permissions.PanelTogglePermission;
import org.gcube.portlets.widgets.workspacesharingwidget.client.view.sharing.multisuggest.DialogMultiDragContact;
import org.gcube.portlets.widgets.workspacesharingwidget.client.view.sharing.multisuggest.MultiDragContact;
import org.gcube.portlets.widgets.workspacesharingwidget.client.view.sharing.multisuggest.MultiValuePanel;
import org.gcube.portlets.widgets.workspacesharingwidget.client.view.sharing.user.DialogMultiDragContact;
import org.gcube.portlets.widgets.workspacesharingwidget.client.view.sharing.user.MultiDragContact;
import org.gcube.portlets.widgets.workspacesharingwidget.shared.ACL_TYPE;
import org.gcube.portlets.widgets.workspacesharingwidget.shared.FileModel;
import org.gcube.portlets.widgets.workspacesharingwidget.shared.InfoContactModel;
@ -329,10 +329,27 @@ public class DialogShareWItem extends Dialog {
final DialogMultiDragContact dialog = new DialogMultiDragContact(true, true);
final MultiDragContact multiDrag = dialog.getMultiDrag();
dialog.show();
AsyncCallback<List<InfoContactModel>> callback=new AsyncCallback<List<InfoContactModel>>() {
@Override
public void onFailure(Throwable caught) {
GWT.log("Error retrieving contacts: "+caught,caught);
}
@Override
public void onSuccess(List<InfoContactModel> result) {
GWT.log("Contact List retrieved: ");
multiDrag.addSourceContacts(result);
}
};
userStore.getExclusiveContactsFromAllContact(suggestPanel.getSelectedUser(),callback);
List<InfoContactModel> exclusiveContacts = userStore
.getExclusiveContactsFromAllContact(suggestPanel.getSelectedUser());
multiDrag.addSourceContacts(exclusiveContacts);
for (InfoContactModel infoContactModel : suggestPanel.getSelectedUser()) {
if (!listAlreadyShared.contains(infoContactModel))

View File

@ -9,9 +9,9 @@ import java.util.List;
import org.gcube.portlets.widgets.workspacesharingwidget.client.ConstantsSharing;
import org.gcube.portlets.widgets.workspacesharingwidget.client.SmartConstants;
import org.gcube.portlets.widgets.workspacesharingwidget.client.resources.Resources;
import org.gcube.portlets.widgets.workspacesharingwidget.client.view.sharing.multisuggest.DialogMultiDragContact;
import org.gcube.portlets.widgets.workspacesharingwidget.client.view.sharing.multisuggest.MultiDragContact;
import org.gcube.portlets.widgets.workspacesharingwidget.client.view.sharing.multisuggest.MultiValuePanel;
import org.gcube.portlets.widgets.workspacesharingwidget.client.view.sharing.user.DialogMultiDragContact;
import org.gcube.portlets.widgets.workspacesharingwidget.client.view.sharing.user.MultiDragContact;
import org.gcube.portlets.widgets.workspacesharingwidget.shared.CredentialModel;
import org.gcube.portlets.widgets.workspacesharingwidget.shared.FileModel;
import org.gcube.portlets.widgets.workspacesharingwidget.shared.InfoContactModel;
@ -26,6 +26,7 @@ import com.extjs.gxt.ui.client.widget.LayoutContainer;
import com.extjs.gxt.ui.client.widget.MessageBox;
import com.extjs.gxt.ui.client.widget.form.TextField;
import com.extjs.gxt.ui.client.widget.layout.FormLayout;
import com.google.gwt.core.shared.GWT;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.user.client.rpc.AsyncCallback;
@ -36,10 +37,9 @@ import com.google.gwt.user.client.ui.Label;
/**
* The Class SmartShare.
*
* @author Francesco Mangiacrapa
* Mar 3, 2014
* @author Francesco Mangiacrapa Mar 3, 2014
*/
public class SmartShare extends Dialog implements SmartDialogInterface{
public class SmartShare extends Dialog implements SmartDialogInterface {
private TextField<String> txtName;
private FileModel fileToShare = null;
@ -49,19 +49,20 @@ public class SmartShare extends Dialog implements SmartDialogInterface{
private boolean readGroupsFromHL;
private boolean readGroupsFromPortal;
/**
* SmartShare base constructor by default does not retrieve groupss.
*/
/**
* SmartShare base constructor by default does not retrieve groupss.
*/
public SmartShare() {
this(false, false);
}
/**
* Instantiates a new smart share.
*
* @param readGroupsFromHL - if true read group names from HL
* @param readGroupsFromPortal - if true read group names from Portal (as VRE)
* @param readGroupsFromHL
* - if true read group names from HL
* @param readGroupsFromPortal
* - if true read group names from Portal (as VRE)
*/
public SmartShare(boolean readGroupsFromHL, boolean readGroupsFromPortal) {
this.readGroupsFromHL = readGroupsFromHL;
@ -70,7 +71,7 @@ public class SmartShare extends Dialog implements SmartDialogInterface{
initLayout();
}
private List<InfoContactModel> listAlreadyShared = new ArrayList<InfoContactModel>(){
private List<InfoContactModel> listAlreadyShared = new ArrayList<InfoContactModel>() {
private static final long serialVersionUID = -610980920163628336L;
@ -80,101 +81,104 @@ public class SmartShare extends Dialog implements SmartDialogInterface{
@Override
public boolean contains(Object o) {
if(o==null)
if (o == null)
return false;
InfoContactModel contact = (InfoContactModel) o;
for (int i = 0; i < listAlreadyShared.size(); i++){
if (contact.getName().compareTo(listAlreadyShared.get(i).getName())==0)
return true;
}
for (int i = 0; i < listAlreadyShared.size(); i++) {
if (contact.getName().compareTo(listAlreadyShared.get(i).getName()) == 0)
return true;
}
return false;
};
};
/**
* Use to modify a shared folder or share an existing folder.
*
* @param fileModel the file model
* @param listAlreadySharedContact the list already shared contact
* @param fileModel
* the file model
* @param listAlreadySharedContact
* the list already shared contact
*/
public void updateSharingDialog(FileModel fileModel, List<CredentialModel> listAlreadySharedContact){
public void updateSharingDialog(FileModel fileModel, List<CredentialModel> listAlreadySharedContact) {
this.fileToShare = fileModel;
String heading;
if(SmartConstants.HEADER_TITLE==null){
if (SmartConstants.HEADER_TITLE == null) {
heading = "Share";
if(fileModel.isDirectory())
heading+=" folder: ";
else
heading+= " : ";
if (fileModel.isDirectory())
heading += " folder: ";
else
heading += " : ";
setHeading(heading+fileModel.getName());
}else
setHeading(heading + fileModel.getName());
} else
setHeading(SmartConstants.HEADER_TITLE);
txtName = new TextField<String>();
txtName.setAllowBlank(false);
txtName.setValue(fileModel.getName());
txtName.setReadOnly(true);
txtName.setAutoValidate(true);
txtName = new TextField<String>();
txtName.setAllowBlank(false);
txtName.setValue(fileModel.getName());
txtName.setReadOnly(true);
txtName.setAutoValidate(true);
if(SmartConstants.ITEM_NAME!=null)
txtName.setFieldLabel(SmartConstants.ITEM_NAME);
if (SmartConstants.ITEM_NAME != null)
txtName.setFieldLabel(SmartConstants.ITEM_NAME);
final LayoutContainer lc = new LayoutContainer();
lc.setStyleAttribute("margin-top", "10px");
lc.setStyleAttribute("margin-bottom", "10px");
lc.setSize(480, 50);
final LayoutContainer lc = new LayoutContainer();
lc.setStyleAttribute("margin-top", "10px");
lc.setStyleAttribute("margin-bottom", "10px");
lc.setSize(480, 50);
final FlexTable flexTable = new FlexTable();
flexTable.setStyleName("userssuggest");
Label labelShareWith = new Label("");
if (SmartConstants.SHARE_WITH_USERS != null)
labelShareWith.setText(SmartConstants.SHARE_WITH_USERS);
final FlexTable flexTable = new FlexTable();
flexTable.setStyleName("userssuggest");
Label labelShareWith = new Label("");
if(SmartConstants.SHARE_WITH_USERS!=null)
labelShareWith.setText(SmartConstants.SHARE_WITH_USERS);
flexTable.setWidget(0, 0, labelShareWith);
flexTable.setWidget(0, 1, suggestPanel);
flexTable.setWidget(0, 0, labelShareWith);
flexTable.setWidget(0, 1, suggestPanel);
buttonMultiDrag.setStyleName("wizardButton");
buttonMultiDrag.setStyleName("wizardButton");
Label labelAddMore = new Label("");
if (SmartConstants.ADD_MORE != null)
labelAddMore.setText(SmartConstants.ADD_MORE);
Label labelAddMore = new Label("");
if(SmartConstants.ADD_MORE!=null)
labelAddMore.setText(SmartConstants.ADD_MORE);
flexTable.setWidget(1, 0, labelAddMore);
flexTable.setWidget(1, 1, buttonMultiDrag);
flexTable.setWidget(1, 0, labelAddMore);
flexTable.setWidget(1, 1, buttonMultiDrag);
if (listAlreadySharedContact != null && listAlreadySharedContact.size() > 0) {
if(listAlreadySharedContact!=null && listAlreadySharedContact.size()>0){
userStore.getInfoContactModelsFromCredential(listAlreadySharedContact,
new AsyncCallback<List<InfoContactModel>>() {
userStore.getInfoContactModelsFromCredential(listAlreadySharedContact, new AsyncCallback<List<InfoContactModel>>() {
@Override
public void onSuccess(List<InfoContactModel> result) {
for (InfoContactModel infoContactModel : result) {
// String name =
// infoContactModel.getName()!=null &&
// !infoContactModel.getName().isEmpty()?infoContactModel.getName():infoContactModel.getLogin();
listAlreadyShared.add(infoContactModel);
suggestPanel.addRecipient(infoContactModel, false);
layout();
}
lc.unmask();
lc.layout();
layout();
}
@Override
public void onSuccess(List<InfoContactModel> result) {
for (InfoContactModel infoContactModel : result) {
//String name = infoContactModel.getName()!=null && !infoContactModel.getName().isEmpty()?infoContactModel.getName():infoContactModel.getLogin();
listAlreadyShared.add(infoContactModel);
suggestPanel.addRecipient(infoContactModel,false);
layout();
}
lc.unmask();
lc.layout();
layout();
}
@Override
public void onFailure(Throwable caught) {
lc.unmask();
}
});
}
@Override
public void onFailure(Throwable caught) {
lc.unmask();
}
});
}
lc.add(flexTable);
setFocusWidget(suggestPanel.getBox());
add(txtName);
lc.add(flexTable);
setFocusWidget(suggestPanel.getBox());
add(txtName);
add(lc);
addListeners();
@ -192,30 +196,29 @@ public class SmartShare extends Dialog implements SmartDialogInterface{
/**
* Inits the layout.
*/
private void initLayout(){
private void initLayout() {
FormLayout layout = new FormLayout();
layout.setLabelWidth(90);
layout.setDefaultWidth(380);
setLayout(layout);
setModal(true);
setScrollMode(Scroll.AUTOY);
setBodyStyle("padding: 9px; background: none");
setWidth(ConstantsSharing.WIDTH_DIALOG);
setHeight(ConstantsSharing.HEIGHT_DIALOG);
setResizable(true);
setButtonAlign(HorizontalAlignment.CENTER);
setButtons(Dialog.OKCANCEL);
setIcon(Resources.getIconShare());
layout.setLabelWidth(90);
layout.setDefaultWidth(380);
setLayout(layout);
setModal(true);
setScrollMode(Scroll.AUTOY);
setBodyStyle("padding: 9px; background: none");
setWidth(ConstantsSharing.WIDTH_DIALOG);
setHeight(ConstantsSharing.HEIGHT_DIALOG);
setResizable(true);
setButtonAlign(HorizontalAlignment.CENTER);
setButtons(Dialog.OKCANCEL);
setIcon(Resources.getIconShare());
}
/**
* Gets the shared list users.
*
* @return the selected contacts (as InfoContactModel)
*/
public List<InfoContactModel> getSharedListUsers() {
// printSelectedUser();
// printSelectedUser();
List<InfoContactModel> contacts = new ArrayList<InfoContactModel>();
@ -228,7 +231,6 @@ public class SmartShare extends Dialog implements SmartDialogInterface{
return contacts;
}
/**
* Gets the shared list users credential.
*
@ -241,7 +243,7 @@ public class SmartShare extends Dialog implements SmartDialogInterface{
for (InfoContactModel wsuser : suggestPanel.getSelectedUser()) {
CredentialModel credential = wsuser.getReferenceCredential();
if(credential==null)
if (credential == null)
credential = new CredentialModel(null, "UNKWNOWN LOGIN", wsuser.isGroup());
toReturn.add(credential);
@ -252,17 +254,18 @@ public class SmartShare extends Dialog implements SmartDialogInterface{
/**
* Gets the credential model from info contact model.
*
* @param infoContact the info contact
* @param infoContact
* the info contact
* @return the credential model from info contact model
*/
private CredentialModel getCredentialModelFromInfoContactModel(InfoContactModel infoContact){
private CredentialModel getCredentialModelFromInfoContactModel(InfoContactModel infoContact) {
if(infoContact==null)
if (infoContact == null)
return null;
if(infoContact.getReferenceCredential()==null){
if (infoContact.getReferenceCredential() == null) {
return new CredentialModel(null, infoContact.getLogin(), infoContact.isGroup());
}else if(infoContact.getReferenceCredential()!=null)
} else if (infoContact.getReferenceCredential() != null)
return infoContact.getReferenceCredential();
return null;
@ -272,9 +275,9 @@ public class SmartShare extends Dialog implements SmartDialogInterface{
/**
* Adds the listeners.
*/
public void addListeners(){
public void addListeners() {
this.getButtonById(Dialog.CANCEL).addSelectionListener(new SelectionListener<ButtonEvent>() {
this.getButtonById(Dialog.CANCEL).addSelectionListener(new SelectionListener<ButtonEvent>() {
@Override
public void componentSelected(ButtonEvent ce) {
@ -282,29 +285,43 @@ public class SmartShare extends Dialog implements SmartDialogInterface{
}
});
this.getButtonById(Dialog.OK).addSelectionListener(new SelectionListener<ButtonEvent>() {
this.getButtonById(Dialog.OK).addSelectionListener(new SelectionListener<ButtonEvent>() {
@Override
public void componentSelected(ButtonEvent ce) {
if(isValidForm(false))
if (isValidForm(false))
hide();
}
});
buttonMultiDrag.addClickHandler(new ClickHandler() {
buttonMultiDrag.addClickHandler(new ClickHandler() {
@Override
public void onClick(ClickEvent event) {
final DialogMultiDragContact dialog = new DialogMultiDragContact(true,true);
final DialogMultiDragContact dialog = new DialogMultiDragContact(true, true);
final MultiDragContact multiDrag = dialog.getMultiDrag();
dialog.show();
// printSelectedUser();
List<InfoContactModel> exclusiveContacts = userStore.getExclusiveContactsFromAllContact(suggestPanel.getSelectedUser());
multiDrag.addSourceContacts(exclusiveContacts);
AsyncCallback<List<InfoContactModel>> callback = new AsyncCallback<List<InfoContactModel>>() {
@Override
public void onFailure(Throwable caught) {
GWT.log("Error retrieving contacts: " + caught, caught);
}
@Override
public void onSuccess(List<InfoContactModel> result) {
GWT.log("Contact List retrieved: ");
multiDrag.addSourceContacts(result);
}
};
userStore.getExclusiveContactsFromAllContact(suggestPanel.getSelectedUser(), callback);
for (InfoContactModel infoContactModel : suggestPanel.getSelectedUser()) {
if(!listAlreadyShared.contains(infoContactModel))
if (!listAlreadyShared.contains(infoContactModel))
multiDrag.addTargetContact(infoContactModel);
}
@ -317,14 +334,15 @@ public class SmartShare extends Dialog implements SmartDialogInterface{
initSuggestContacts();
for (InfoContactModel infoContactModel : multiDrag.getTargetListContact()) {
suggestPanel.addRecipient(infoContactModel,true);
}
suggestPanel.addRecipient(infoContactModel, true);
}
// for (InfoContactModel infoContactModel : multiDrag.getTargetListContact()) {
//
// if(!listAlreadySharedContains(infoContactModel))
// suggestPanel.addRecipient(infoContactModel.getName(),true);
// }
// for (InfoContactModel infoContactModel :
// multiDrag.getTargetListContact()) {
//
// if(!listAlreadySharedContains(infoContactModel))
// suggestPanel.addRecipient(infoContactModel.getName(),true);
// }
suggestPanel.boxSetFocus();
}
@ -336,37 +354,38 @@ public class SmartShare extends Dialog implements SmartDialogInterface{
/**
* List already shared contains.
*
* @param contact the contact
* @param contact
* the contact
* @return true, if successful
*/
private boolean listAlreadySharedContains(InfoContactModel contact){
private boolean listAlreadySharedContains(InfoContactModel contact) {
if(contact==null)
if (contact == null)
return false;
for (InfoContactModel ct : listAlreadyShared) {
if(ct.getLogin().compareTo(contact.getLogin())==0){
if (ct.getLogin().compareTo(contact.getLogin()) == 0) {
return true;
}
}
return false;
}
//DEBUG
// DEBUG
/**
* Prints the selected user.
*/
/*private void printSelectedUser(){
GWT.log("SELETECTED USERS: ");
for (InfoContactModel contact : suggestPanel.getSelectedUser())
GWT.log(contact.toString());
}*/
/*
* private void printSelectedUser(){
*
* GWT.log("SELETECTED USERS: "); for (InfoContactModel contact :
* suggestPanel.getSelectedUser()) GWT.log(contact.toString()); }
*/
/**
* Inits the suggest contacts.
*/
private void initSuggestContacts(){
private void initSuggestContacts() {
suggestPanel.resetItemSelected();
@ -375,35 +394,38 @@ public class SmartShare extends Dialog implements SmartDialogInterface{
}
}
/**
* Enable confirm button.
*
* @param enabled the enabled
* @param enabled
* the enabled
*/
public void enableConfirmButton(boolean enabled){
public void enableConfirmButton(boolean enabled) {
this.getButtonById(Dialog.OK).setEnabled(enabled);
}
/**
* Sets the as error.
*
* @param message the new as error
* @param message
* the new as error
*/
public void setAsError(String message){
public void setAsError(String message) {
enableFormDialog(false);
this.add(new Html("<br/> <p style=\"color:red; font-family:verdana, arial; font-size:14px;\">"+message+"</p>"));
this.add(new Html(
"<br/> <p style=\"color:red; font-family:verdana, arial; font-size:14px;\">" + message + "</p>"));
this.layout();
}
/**
* Enable form dialog.
*
* @param bool the bool
* @param bool
* the bool
*/
private void enableFormDialog(boolean bool){
getButtonById(Dialog.OK).setEnabled(bool);
buttonMultiDrag.setEnabled(bool);
private void enableFormDialog(boolean bool) {
getButtonById(Dialog.OK).setEnabled(bool);
buttonMultiDrag.setEnabled(bool);
}
/**
@ -418,20 +440,21 @@ public class SmartShare extends Dialog implements SmartDialogInterface{
/**
* Checks if is valid form.
*
* @param displayAlert in case of error
* @param displayAlert
* in case of error
* @return true, if is valid form
*/
public boolean isValidForm(boolean displayAlert){
public boolean isValidForm(boolean displayAlert) {
if(!txtName.isValid()){
if(displayAlert)
if (!txtName.isValid()) {
if (displayAlert)
MessageBox.alert("Attention", "Name must not be empty", null);
txtName.focus();
return false;
}
if(getSharedListUsers().size()==0){
if(displayAlert)
if (getSharedListUsers().size() == 0) {
if (displayAlert)
MessageBox.alert("Attention", SmartConstants.ERROR_NO_USER_SELECTED, null);
suggestPanel.boxSetFocus();
return false;
@ -439,7 +462,6 @@ public class SmartShare extends Dialog implements SmartDialogInterface{
return true;
}
/**
* Checks if is read groups from hl.
*
@ -449,7 +471,6 @@ public class SmartShare extends Dialog implements SmartDialogInterface{
return readGroupsFromHL;
}
/**
* Checks if is read groups from portal.
*

View File

@ -13,156 +13,198 @@ import com.google.gwt.core.client.GWT;
import com.google.gwt.user.client.rpc.AsyncCallback;
/**
* @author Francesco Mangiacrapa
* @author Francesco Mangiacrapa
*
*/
public class UserStore implements ContactFetcher{
public class UserStore implements ContactFetcher {
public static List<InfoContactModel> listAllContact = null;
private static List<InfoContactModel> listAllContact = new ArrayList<InfoContactModel>();;
// public boolean syncronizeCleanSharedUser = false;
// public boolean syncronizeCleanSharedUser = false;
public UserStore() {
loadAllUsersFromServer();
}
private void loadSharedUserBySharedFolderId(final String sharedFolderId,
final AsyncCallback<List<InfoContactModel>> callback) {
// comboSharedUsers.mask("Loading users");
WorkspaceSharingController.rpcWorkspaceSharingService.getListUserSharedByFolderSharedId(sharedFolderId,
new AsyncCallback<List<InfoContactModel>>() {
@Override
public void onFailure(Throwable caught) {
MessageBox.alert("Error",
ConstantsSharing.SERVER_ERROR + " retrieving user. " + ConstantsSharing.TRY_AGAIN,
null);
callback.onFailure(caught);
}
@Override
public void onSuccess(List<InfoContactModel> result) {
GWT.log("Get List user shared loaded " + result.size() + " contacts from server for "
+ sharedFolderId);
callback.onSuccess(result);
}
});
}
@Override
public void getListSharedUserByFolderId(String sharedFolderId, AsyncCallback<List<InfoContactModel>> callback){
public void getListSharedUserByFolderId(String sharedFolderId, AsyncCallback<List<InfoContactModel>> callback) {
loadSharedUserBySharedFolderId(sharedFolderId, callback);
}
private void loadAllUsersFromServer(){
listAllContact = new ArrayList<InfoContactModel>();
WorkspaceSharingController.rpcWorkspaceSharingService.getAllContacts(new AsyncCallback<List<InfoContactModel>>() {
@Override
public void onSuccess(List<InfoContactModel> result) {
GWT.log("Get all contacts loaded "+result.size() + " contacts from server");
listAllContact = result;
}
@Override
public void onFailure(Throwable caught) {
MessageBox.alert("Error", ConstantsSharing.SERVER_ERROR +" retrieving user " + ConstantsSharing.TRY_AGAIN, null);
}
});
}
private void loadSharedUserBySharedFolderId(final String sharedFolderId, final AsyncCallback<List<InfoContactModel>> callback){
// comboSharedUsers.mask("Loading users");
WorkspaceSharingController.rpcWorkspaceSharingService.getListUserSharedByFolderSharedId(sharedFolderId, new AsyncCallback<List<InfoContactModel>>() {
@Override
public void onFailure(Throwable caught) {
MessageBox.alert("Error", ConstantsSharing.SERVER_ERROR +" retrieving user. " + ConstantsSharing.TRY_AGAIN, null);
callback.onFailure(caught);
}
@Override
public void onSuccess(List<InfoContactModel> result) {
GWT.log("Get List user shared loaded "+result.size() + " contacts from server for "+sharedFolderId);
callback.onSuccess(result);
}
});
}
@Override
public List<InfoContactModel> getExclusiveContactsFromAllContact(List<InfoContactModel> listSharedUser){
List<InfoContactModel> listExclusiveContact = new ArrayList<InfoContactModel>(listAllContact);
for (InfoContactModel contact : listSharedUser) {
if(listAllContact.contains(contact)){
listExclusiveContact.remove(contact);
public void getExclusiveContactsFromAllContact(final List<InfoContactModel> listSharedUser,
final AsyncCallback<List<InfoContactModel>> callback) {
if (listAllContact == null || listAllContact.isEmpty()) {
WorkspaceSharingController.rpcWorkspaceSharingService
.getAllContacts(new AsyncCallback<List<InfoContactModel>>() {
@Override
public void onSuccess(List<InfoContactModel> result) {
GWT.log("Get all contacts loaded " + result.size() + " contacts from server");
listAllContact = result;
List<InfoContactModel> listExclusiveContact = new ArrayList<InfoContactModel>(
listAllContact);
for (InfoContactModel contact : listSharedUser) {
if (listExclusiveContact.contains(contact)) {
listExclusiveContact.remove(contact);
}
}
callback.onSuccess(listExclusiveContact);
}
@Override
public void onFailure(Throwable caught) {
MessageBox.alert("Error",
ConstantsSharing.SERVER_ERROR + " retrieving user " + ConstantsSharing.TRY_AGAIN,
null);
callback.onFailure(new Throwable("Error retrieving users!"));
}
});
} else {
List<InfoContactModel> listExclusiveContact = new ArrayList<InfoContactModel>(listAllContact);
for (InfoContactModel contact : listSharedUser) {
if (listAllContact.contains(contact)) {
listExclusiveContact.remove(contact);
}
}
callback.onSuccess(listExclusiveContact);
}
return listExclusiveContact;
}
@Override
public void getOwner(final String sharedFolderId,final AsyncCallback<InfoContactModel> callback) {
WorkspaceSharingController.rpcWorkspaceSharingService.getOwnerByItemId(sharedFolderId, new AsyncCallback<InfoContactModel>() {
public void getOwner(final String sharedFolderId, final AsyncCallback<InfoContactModel> callback) {
@Override
public void onFailure(Throwable caught) {
GWT.log("an error occured in get Owner by Id "+sharedFolderId + " "+caught.getMessage());
}
WorkspaceSharingController.rpcWorkspaceSharingService.getOwnerByItemId(sharedFolderId,
new AsyncCallback<InfoContactModel>() {
@Override
public void onSuccess(InfoContactModel result) {
callback.onSuccess(result);
}
});
@Override
public void onFailure(Throwable caught) {
GWT.log("an error occured in get Owner by Id " + sharedFolderId + " " + caught.getMessage());
callback.onFailure(caught);
}
@Override
public void onSuccess(InfoContactModel result) {
callback.onSuccess(result);
}
});
}
@Override
public void getInfoContactModelsFromCredential(List<CredentialModel> listAlreadySharedContact, final AsyncCallback<List<InfoContactModel>> callback){
WorkspaceSharingController.rpcWorkspaceSharingService.getInfoContactModelsFromCredential(listAlreadySharedContact, new AsyncCallback<List<InfoContactModel>>() {
public void getInfoContactModelsFromCredential(List<CredentialModel> listAlreadySharedContact,
final AsyncCallback<List<InfoContactModel>> callback) {
@Override
public void onFailure(Throwable caught) {
GWT.log("an error occured ingetInfoContactModelsFromCredential "+caught.getMessage());
}
WorkspaceSharingController.rpcWorkspaceSharingService.getInfoContactModelsFromCredential(
listAlreadySharedContact, new AsyncCallback<List<InfoContactModel>>() {
@Override
public void onSuccess(List<InfoContactModel> result) {
callback.onSuccess(result);
}
});
@Override
public void onFailure(Throwable caught) {
GWT.log("an error occured ingetInfoContactModelsFromCredential " + caught.getMessage());
}
@Override
public void onSuccess(List<InfoContactModel> result) {
callback.onSuccess(result);
}
});
}
/* (non-Javadoc)
* @see org.gcube.portlets.widgets.workspacesharingwidget.client.view.sharing.ContactFetcher#getListContact(com.google.gwt.user.client.rpc.AsyncCallback, boolean, boolean, boolean)
/*
* (non-Javadoc)
*
* @see
* org.gcube.portlets.widgets.workspacesharingwidget.client.view.sharing.
* ContactFetcher#getListContact(com.google.gwt.user.client.rpc.
* AsyncCallback, boolean, boolean, boolean)
*/
@Override
public void getListContact(AsyncCallback<List<InfoContactModel>> callback,boolean reloadList) {
if(listAllContact==null||listAllContact.isEmpty()){
callback.onFailure(new Throwable("Error retrieving all users!"));
public void getListContact(final AsyncCallback<List<InfoContactModel>> callback, boolean reloadList) {
if (listAllContact == null || listAllContact.isEmpty() || reloadList) {
WorkspaceSharingController.rpcWorkspaceSharingService
.getAllContacts(new AsyncCallback<List<InfoContactModel>>() {
@Override
public void onSuccess(List<InfoContactModel> result) {
GWT.log("Get all contacts loaded " + result.size() + " contacts from server");
listAllContact = result;
callback.onSuccess(listAllContact);
}
@Override
public void onFailure(Throwable caught) {
MessageBox.alert("Error",
ConstantsSharing.SERVER_ERROR + " retrieving user " + ConstantsSharing.TRY_AGAIN,
null);
callback.onFailure(new Throwable("Error retrieving users!"));
}
});
} else {
callback.onSuccess(listAllContact);
}
//if(reloadList || listAllContact==null)
// loadAllUsersFromServer(callback);
// else
// callback.onSuccess(listAllContact);
}
/* (non-Javadoc)
* @see org.gcube.portlets.widgets.workspacesharingwidget.client.view.sharing.ContactFetcher#getAdministratorsByFolderId(java.lang.String, com.google.gwt.user.client.rpc.AsyncCallback)
/*
* (non-Javadoc)
*
* @see
* org.gcube.portlets.widgets.workspacesharingwidget.client.view.sharing.
* ContactFetcher#getAdministratorsByFolderId(java.lang.String,
* com.google.gwt.user.client.rpc.AsyncCallback)
*/
@Override
public void getAdministratorsByFolderId(String sharedFolderId, final AsyncCallback<List<InfoContactModel>> callback) {
if(sharedFolderId==null || sharedFolderId.isEmpty())
public void getAdministratorsByFolderId(String sharedFolderId,
final AsyncCallback<List<InfoContactModel>> callback) {
if (sharedFolderId == null || sharedFolderId.isEmpty())
return;
WorkspaceSharingController.rpcWorkspaceSharingService.getAdministratorsByFolderId(sharedFolderId, new AsyncCallback<List<InfoContactModel>>() {
WorkspaceSharingController.rpcWorkspaceSharingService.getAdministratorsByFolderId(sharedFolderId,
new AsyncCallback<List<InfoContactModel>>() {
@Override
public void onFailure(Throwable caught) {
callback.onFailure(caught);
}
@Override
public void onFailure(Throwable caught) {
callback.onFailure(caught);
}
@Override
public void onSuccess(List<InfoContactModel> result) {
callback.onSuccess(result);
}
});
@Override
public void onSuccess(List<InfoContactModel> result) {
callback.onSuccess(result);
}
});
}
}

View File

@ -0,0 +1,163 @@
/**
*
*/
package org.gcube.portlets.widgets.workspacesharingwidget.client.view.sharing.admin;
import org.gcube.portlets.widgets.workspacesharingwidget.client.resources.Resources;
import com.extjs.gxt.ui.client.Style.HorizontalAlignment;
import com.extjs.gxt.ui.client.event.ButtonEvent;
import com.extjs.gxt.ui.client.event.SelectionListener;
import com.extjs.gxt.ui.client.widget.Dialog;
import com.extjs.gxt.ui.client.widget.LayoutContainer;
import com.extjs.gxt.ui.client.widget.MessageBox;
import com.extjs.gxt.ui.client.widget.button.Button;
import com.extjs.gxt.ui.client.widget.toolbar.ToolBar;
import com.google.gwt.core.client.GWT;
import com.google.gwt.user.client.Random;
/**
* @author Francesco Mangiacrapa Jan 27, 2015
*
*/
public class DialogMultiDragContactAdmin extends Dialog {
private static final String GROUP_DRAGGING_CONTACTS = "Group dragging contacts";
private static final int HEIGHT_DIALOG = 542;
private static final int WIDTH_DIALOG = 620;
private String txtHelp = "Drag one or more contacts from the left (All Contacts) to the right (Share with) to add users in your sharing list.";
private String titleHelp = "Group dragging action";
// private boolean hideOnPressOkButton=false;
private MultiDragContactAdmin multiDragContactAdmin;
// private boolean visibleTextArea=false;
private ToolBar toolBar;
private String headTitle;
private LayoutContainer lcTop = new LayoutContainer();
private LayoutContainer lcMiddle = new LayoutContainer();
private LayoutContainer lcBottom = new LayoutContainer();
public DialogMultiDragContactAdmin(String headTitle, String leftListContactsTitle, String rightListContactsTitle,
String workspaceItemId) {
GWT.log("DialogMultiDragContactAdmin()");
try {
this.headTitle = headTitle;
this.multiDragContactAdmin = new MultiDragContactAdmin(leftListContactsTitle, rightListContactsTitle,
workspaceItemId);
init();
} catch (Throwable e) {
GWT.log("Error in DialogMultiDragContactAdmin()" + e.getLocalizedMessage(), e);
}
}
public void showToolBar(boolean bool) {
this.toolBar.setVisible(bool);
}
private void init() {
if (headTitle == null)
this.setHeading(GROUP_DRAGGING_CONTACTS);
else
this.setHeading(headTitle);
setId(DialogMultiDragContactAdmin.class.getName() + Random.nextInt());
setSize(WIDTH_DIALOG, HEIGHT_DIALOG);
setResizable(false);
setMaximizable(false);
setIcon(Resources.getIconUsers());
setModal(true);
// setScrollMode(Scroll.AUTOY);
// setResizable(true);
setButtonAlign(HorizontalAlignment.CENTER);
setButtons(Dialog.OKCANCEL);
toolBar = new ToolBar();
Button buttonHelp = new Button();
buttonHelp.setIcon(Resources.getIconInfo());
buttonHelp.addSelectionListener(new SelectionListener<ButtonEvent>() {
@Override
public void componentSelected(ButtonEvent ce) {
MessageBox.info(titleHelp, txtHelp, null);
}
});
toolBar.add(buttonHelp);
setTopComponent(toolBar);
this.getButtonById(Dialog.CANCEL).addSelectionListener(new SelectionListener<ButtonEvent>() {
@Override
public void componentSelected(ButtonEvent ce) {
hide();
}
});
this.getButtonById(Dialog.OK).addSelectionListener(new SelectionListener<ButtonEvent>() {
@Override
public void componentSelected(ButtonEvent ce) {
hide();
}
});
lcMiddle.add(multiDragContactAdmin);
add(lcTop);
add(lcMiddle);
add(lcBottom);
}
public MultiDragContactAdmin getMultiDrag() {
return multiDragContactAdmin;
}
public String getHeadTitle() {
return headTitle;
}
public String getTxtHelp() {
return txtHelp;
}
public String getTitleHelp() {
return titleHelp;
}
public ToolBar getToolBar() {
return toolBar;
}
public void setTxtHelp(String txtHelp) {
this.txtHelp = txtHelp;
}
public void setTitleHelp(String titleHelp) {
this.titleHelp = titleHelp;
}
public void setToolBar(ToolBar toolBar) {
this.toolBar = toolBar;
}
public LayoutContainer getLcTop() {
return lcTop;
}
public LayoutContainer getLcMiddle() {
return lcMiddle;
}
public LayoutContainer getLcBottom() {
return lcBottom;
}
}

View File

@ -0,0 +1,697 @@
package org.gcube.portlets.widgets.workspacesharingwidget.client.view.sharing.admin;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import org.gcube.portlets.widgets.workspacesharingwidget.client.ConstantsSharing;
import org.gcube.portlets.widgets.workspacesharingwidget.client.WorkspaceSharingController;
import org.gcube.portlets.widgets.workspacesharingwidget.client.resources.Resources;
import org.gcube.portlets.widgets.workspacesharingwidget.client.rpc.WorkspaceSharingServiceAsync;
import org.gcube.portlets.widgets.workspacesharingwidget.shared.InfoContactModel;
import org.gcube.portlets.widgets.workspacesharingwidget.shared.UserVRE;
import com.extjs.gxt.ui.client.Style.HorizontalAlignment;
import com.extjs.gxt.ui.client.Style.Orientation;
import com.extjs.gxt.ui.client.Style.SortDir;
import com.extjs.gxt.ui.client.Style.VerticalAlignment;
import com.extjs.gxt.ui.client.dnd.GridDragSource;
import com.extjs.gxt.ui.client.dnd.GridDropTarget;
import com.extjs.gxt.ui.client.event.BaseEvent;
import com.extjs.gxt.ui.client.event.ButtonEvent;
import com.extjs.gxt.ui.client.event.Events;
import com.extjs.gxt.ui.client.event.Listener;
import com.extjs.gxt.ui.client.event.SelectionChangedEvent;
import com.extjs.gxt.ui.client.event.SelectionChangedListener;
import com.extjs.gxt.ui.client.event.SelectionListener;
import com.extjs.gxt.ui.client.store.ListStore;
import com.extjs.gxt.ui.client.store.Store;
import com.extjs.gxt.ui.client.store.StoreSorter;
import com.extjs.gxt.ui.client.util.Margins;
import com.extjs.gxt.ui.client.widget.ContentPanel;
import com.extjs.gxt.ui.client.widget.HorizontalPanel;
import com.extjs.gxt.ui.client.widget.Label;
import com.extjs.gxt.ui.client.widget.LayoutContainer;
import com.extjs.gxt.ui.client.widget.MessageBox;
import com.extjs.gxt.ui.client.widget.VerticalPanel;
import com.extjs.gxt.ui.client.widget.button.Button;
import com.extjs.gxt.ui.client.widget.form.ComboBox;
import com.extjs.gxt.ui.client.widget.form.StoreFilterField;
import com.extjs.gxt.ui.client.widget.grid.ColumnConfig;
import com.extjs.gxt.ui.client.widget.grid.ColumnData;
import com.extjs.gxt.ui.client.widget.grid.ColumnModel;
import com.extjs.gxt.ui.client.widget.grid.Grid;
import com.extjs.gxt.ui.client.widget.grid.GridCellRenderer;
import com.extjs.gxt.ui.client.widget.layout.CenterLayout;
import com.extjs.gxt.ui.client.widget.layout.RowData;
import com.extjs.gxt.ui.client.widget.layout.RowLayout;
import com.extjs.gxt.ui.client.widget.tips.QuickTip;
import com.google.gwt.core.client.GWT;
import com.google.gwt.user.client.Random;
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.gwt.user.client.ui.FlexTable;
/**
*
* @author Francesco Mangiacrapa Jan 27, 2015
*
*/
public class MultiDragContactAdmin extends ContentPanel {
//
private String leftListContactsTitle;
private String rightListContactsTitle;
private String workspaceItemId;
private String myLogin;
private InfoContactModel myContact;
private List<InfoContactModel> targetContact;
private List<UserVRE> vresList;
private HashMap<UserVRE, List<InfoContactModel>> contactsMap;
//
private static final String ALL_CONTACTS = "All Contacts";
private static final String SHARE_WITH = "Share with...";
//
private static final int HEIGHT_VRE_PANEL = 40;
private static final int WIDTH_VRE_PANEL = 597;
private static final int HEIGHT_CONTACTS_PANEL = 400;
private static final int WIDTH_CONTACTS_PANEL = 597;
private static final int HEIGHT_GRID = 310;
private static final int PADDING = 5;
//
private GridDropTarget dropSource;
private GridDropTarget dropTarget;
private ListStore<InfoContactModel> storeSource = new ListStore<InfoContactModel>();
private ListStore<InfoContactModel> storeTarget = new ListStore<InfoContactModel>();
private Grid<InfoContactModel> gridAllContacts;
private Grid<InfoContactModel> gridShareWith;
private Button buttonSelectedLeft;
private Button buttonSelectedRight;
private Button buttonAllRight;
private Button buttonAllLeft;
private Label labelAllContacts;
private Label labelShareWith;
private ComboBox<UserVRE> vreListCombo;
private ListStore<UserVRE> vreListStore;
public MultiDragContactAdmin(String leftListContactsTitle, String rightListContactsTitle, String workspaceItemId) {
super();
GWT.log("MultiDragContactAdmin()");
this.leftListContactsTitle = leftListContactsTitle;
this.rightListContactsTitle = rightListContactsTitle;
this.workspaceItemId = workspaceItemId;
this.contactsMap = new HashMap<>();
try {
init();
create();
retrieveMyLogin();
} catch (Throwable e) {
GWT.log("Error in MultiDragContactAdmin: " + e.getLocalizedMessage(), e);
}
}
private void init() {
GWT.log("MultiDragContactAdmin Init");
setHeaderVisible(false);
setBodyBorder(false);
setBorders(false);
// setStyleAttribute("margin", "10px");
setBodyStyle("padding: " + PADDING + "px; background: none");
}
private void retrieveMyLogin() {
WorkspaceSharingServiceAsync.INSTANCE.getMyLogin(new AsyncCallback<String>() {
@Override
public void onFailure(Throwable caught) {
GWT.log("Error retrieving my login");
myLogin = null;
retrieveListOfAdmin();
}
@Override
public void onSuccess(String result) {
GWT.log("My login is: " + result);
myLogin = result;
retrieveListOfAdmin();
}
});
}
private void retrieveListOfAdmin() {
WorkspaceSharingController.rpcWorkspaceSharingService.getAdministratorsByFolderId(workspaceItemId,
new AsyncCallback<List<InfoContactModel>>() {
@Override
public void onFailure(Throwable caught) {
GWT.log("Error retrieving administrators for workspaceItemId: " + workspaceItemId);
targetContact = new ArrayList<>();
}
@Override
public void onSuccess(List<InfoContactModel> result) {
GWT.log("Administrators for folder retrieved");
if (myLogin != null && !myLogin.isEmpty()) {
for (InfoContactModel infoContactModel : result) {
if (infoContactModel.getLogin().compareTo(myLogin) == 0) {
myContact = infoContactModel;
break;
}
}
}
if (myContact != null) {
result.remove(myContact);
targetContact = result;
} else {
targetContact = result;
}
storeTarget.removeAll();
storeTarget.add(targetContact);
storeTarget.commitChanges();
retrieveVREs();
}
});
}
private void retrieveVREs() {
GWT.log("MultiDragContactAdmin load VREs");
WorkspaceSharingController.rpcWorkspaceSharingService.getUserVREList(new AsyncCallback<List<UserVRE>>() {
@Override
public void onFailure(Throwable caught) {
GWT.log("Error retrieving VRE for user: " + caught.getLocalizedMessage(), caught);
MessageBox.alert("Error",
ConstantsSharing.SERVER_ERROR + " retrieving VREs " + ConstantsSharing.TRY_AGAIN, null);
}
@Override
public void onSuccess(List<UserVRE> result) {
try {
if (result != null && !result.isEmpty()) {
GWT.log("Get all VREs loaded " + result.size() + " from server");
vresList = result;
vreListStore.removeAll();
vreListStore.add(vresList);
vreListStore.commitChanges();
vreListCombo.setValue(vresList.get(0));
} else {
GWT.log("No VREs found from server");
MessageBox.alert("Attention", "No VREs found " + ConstantsSharing.TRY_AGAIN, null);
}
} catch (Throwable e) {
GWT.log("Error ");
}
}
});
}
private void create() {
GWT.log("MultiDragContactAdmin Create Start");
// SORTING STORE
GWT.log("Create VREPanel");
// VRE
final ContentPanel vrePanel = new ContentPanel();
vrePanel.setId("vre-panel-share-admin" + Random.nextInt());
vrePanel.setSize(WIDTH_VRE_PANEL, HEIGHT_VRE_PANEL);
vrePanel.setHeaderVisible(false);
vrePanel.setLayout(new RowLayout(Orientation.HORIZONTAL));
// TODO
// VRE Select
vreListStore = new ListStore<UserVRE>();
vreListCombo = new ComboBox<UserVRE>();
vreListCombo.setStore(vreListStore);
vreListCombo.setDisplayField(UserVRE.GROUP_NAME);
vreListCombo.setWidth(554);
vreListCombo.setAllowBlank(false);
vreListCombo.addSelectionChangedListener(new SelectionChangedListener<UserVRE>() {
@Override
public void selectionChanged(SelectionChangedEvent<UserVRE> selected) {
retrieveContactList(selected.getSelectedItem());
}
});
FlexTable vreLayout = new FlexTable();
vreLayout.setCellSpacing(6);
vreLayout.setWidth("565px");
// FlexCellFormatter cellFormatter = vreLayout.getFlexCellFormatter();
Label vreLabel = new Label("VRE:");
vreLabel.setStyleAttribute("padding", "5px");
vreLayout.setWidget(0, 0, vreLabel);
vreLayout.setWidget(0, 1, vreListCombo);
vrePanel.add(vreLayout);
add(vrePanel);
//
GWT.log("MultiDragContactAdmin Create Grids Panel");
setGropUserStoreSorter(storeSource);
setGropUserStoreSorter(storeTarget);
final ContentPanel cp = new ContentPanel();
cp.setId("All-Contacts-Share-Contacts-" + Random.nextInt());
cp.setSize(WIDTH_CONTACTS_PANEL, HEIGHT_CONTACTS_PANEL);
cp.setHeaderVisible(false);
cp.setLayout(new RowLayout(Orientation.HORIZONTAL));
final VerticalPanel vpAllContacts = new VerticalPanel();
vpAllContacts.setHorizontalAlign(HorizontalAlignment.CENTER);
labelAllContacts = new Label(ALL_CONTACTS);
setLeftListContactsTitle(leftListContactsTitle);
vpAllContacts.add(labelAllContacts);
gridAllContacts = new Grid<InfoContactModel>(storeSource, createColumnModel());
storeSource.setDefaultSort(InfoContactModel.FULLNAME, SortDir.ASC);
storeSource.sort(InfoContactModel.FULLNAME, SortDir.ASC);
storeTarget.setDefaultSort(InfoContactModel.FULLNAME, SortDir.ASC);
storeTarget.sort(InfoContactModel.FULLNAME, SortDir.ASC);
final StoreFilterField<InfoContactModel> filter = new StoreFilterField<InfoContactModel>() {
@Override
protected boolean doSelect(Store<InfoContactModel> store, InfoContactModel parent, InfoContactModel record,
String property, String filter) {
String name = record.getName();
name = name.toLowerCase();
if (name.contains(filter.toLowerCase())) {
return true;
}
return false;
}
};
//
filter.setEmptyText("Filter All Contacts");
HorizontalPanel hp = new HorizontalPanel();
hp.setStyleAttribute("padding-top", "5px");
hp.setStyleAttribute("padding-bottom", "5px");
hp.add(filter);
filter.bind(storeSource);
gridAllContacts.setHeight(HEIGHT_GRID);
gridAllContacts.setBorders(false);
gridAllContacts.getView().setAutoFill(true);
// gridAllContacts.setAutoExpandColumn(InfoContactModel.FULLNAME);
gridAllContacts.setBorders(true);
vpAllContacts.add(hp);
vpAllContacts.add(gridAllContacts);
RowData rowData = new RowData(.4, 1);
rowData.setMargins(new Margins(6));
cp.add(vpAllContacts, rowData);
rowData = new RowData(.2, 1);
rowData.setMargins(new Margins(6));
LayoutContainer lc = createMoveContactsContainer();
cp.add(lc, rowData);
rowData = new RowData(.4, 1);
rowData.setMargins(new Margins(6, 6, 6, 0));
final VerticalPanel vpShareWith = new VerticalPanel();
vpShareWith.setHorizontalAlign(HorizontalAlignment.CENTER);
labelShareWith = new Label(SHARE_WITH);
setRightListContactsTitle(rightListContactsTitle);
vpShareWith.add(labelShareWith);
gridShareWith = new Grid<InfoContactModel>(storeTarget, createColumnModel());
final StoreFilterField<InfoContactModel> filter2 = new StoreFilterField<InfoContactModel>() {
@Override
protected boolean doSelect(Store<InfoContactModel> store, InfoContactModel parent, InfoContactModel record,
String property, String filter) {
String name = record.getName();
name = name.toLowerCase();
if (name.contains(filter.toLowerCase())) {
return true;
}
return false;
}
};
// filter.setFieldLabel("Filter Contacts");
// filter2.setWidth(247);
filter2.setEmptyText("Filter Share with");
hp = new HorizontalPanel();
hp.setStyleAttribute("padding-top", "5px");
hp.setStyleAttribute("padding-bottom", "5px");
hp.add(filter2);
filter2.bind(storeTarget);
gridShareWith.setHeight(HEIGHT_GRID);
gridShareWith.setBorders(false);
gridShareWith.getView().setAutoFill(true);
// gridShareWith.setAutoExpandColumn(InfoContactModel.FULLNAME);
gridShareWith.setBorders(true);
vpShareWith.add(hp);
vpShareWith.add(gridShareWith);
cp.add(vpShareWith, rowData);
new GridDragSource(gridAllContacts);
new GridDragSource(gridShareWith);
dropSource = new GridDropTarget(gridAllContacts);
dropSource.setAllowSelfAsSource(false);
dropTarget = new GridDropTarget(gridShareWith);
dropTarget.setAllowSelfAsSource(false);
add(cp);
cp.addListener(Events.Render, new Listener<BaseEvent>() {
@Override
public void handleEvent(BaseEvent be) {
GWT.log("MultiDragContactAdmin CP Render Called");
int width = gridAllContacts.getWidth();
filter.setWidth(width - 2);
filter2.setWidth(width - 2);
gridAllContacts.setWidth(width);
vpAllContacts.setWidth(width + 7);
gridShareWith.setWidth(width);
vpShareWith.setWidth(width + 10);
vpShareWith.layout();
vpAllContacts.layout();
cp.layout();
}
});
// needed to enable quicktips (qtitle for the heading and qtip for the
// content) that are setup in the change GridCellRenderer
new QuickTip(gridAllContacts);
GWT.log("MultiDragContactAdmin view Created");
}
// TODO
private void retrieveContactList(final UserVRE userVRE) {
if (!contactsMap.isEmpty() && contactsMap.containsKey(userVRE)) {
List<InfoContactModel> contacts=contactsMap.get(userVRE);
updateStoreSource(contacts);
} else {
GWT.log("MultiDragContactAdmin retrieve contacts list");
WorkspaceSharingController.rpcWorkspaceSharingService.getAllContactsByVRE(userVRE,
new AsyncCallback<List<InfoContactModel>>() {
@Override
public void onFailure(Throwable e) {
GWT.log("Error retrieving all contacts by VRE: " + e.getLocalizedMessage(), e);
MessageBox.alert("Error", ConstantsSharing.SERVER_ERROR
+ " retrieving Contacts in this VRE " + ConstantsSharing.TRY_AGAIN, null);
}
@Override
public void onSuccess(List<InfoContactModel> result) {
GWT.log("Contacts retrieved from server");
contactsMap.put(userVRE, result);
updateStoreSource(result);
}
});
}
}
private void updateStoreSource(List<InfoContactModel> result) {
GWT.log("Update SourceStore");
storeSource.removeAll();
result.removeAll(storeTarget.getModels());
result.remove(myContact);
storeSource.add(result);
storeSource.commitChanges();
}
private LayoutContainer createMoveContactsContainer() {
LayoutContainer lc = new LayoutContainer();
lc.setLayout(new CenterLayout());
VerticalPanel vp1 = new VerticalPanel();
vp1.setHorizontalAlign(HorizontalAlignment.CENTER);
vp1.setVerticalAlign(VerticalAlignment.MIDDLE);
buttonSelectedLeft = new Button();
buttonSelectedLeft.setIcon(Resources.getSelectedLeft());
buttonSelectedLeft.setToolTip("Move selected contact/s from 'All Contact' to 'Share with'");
buttonSelectedLeft.addSelectionListener(new SelectionListener<ButtonEvent>() {
@Override
public void componentSelected(ButtonEvent ce) {
List<InfoContactModel> selectedItems = gridAllContacts.getSelectionModel().getSelectedItems();
if (selectedItems != null && selectedItems.size() > 0) {
for (InfoContactModel extendedInfoContactModel : selectedItems) {
storeTarget.add(extendedInfoContactModel);
storeSource.remove(extendedInfoContactModel);
}
}
}
});
buttonSelectedRight = new Button();
buttonSelectedRight.setIcon(Resources.getSelectedRight());
buttonSelectedRight.setToolTip("Move selected contact/s from 'Share with' to 'All Contact'");
buttonSelectedRight.addSelectionListener(new SelectionListener<ButtonEvent>() {
@Override
public void componentSelected(ButtonEvent ce) {
List<InfoContactModel> selectedItems = gridShareWith.getSelectionModel().getSelectedItems();
if (selectedItems != null && selectedItems.size() > 0) {
for (InfoContactModel extendedInfoContactModel : selectedItems) {
storeSource.add(extendedInfoContactModel);
storeTarget.remove(extendedInfoContactModel);
}
}
}
});
buttonAllLeft = new Button();
buttonAllLeft.setIcon(Resources.getAllLeft());
buttonAllLeft.setToolTip("Move all contact/s from 'All Contact' to 'Share with'");
buttonAllLeft.addSelectionListener(new SelectionListener<ButtonEvent>() {
@Override
public void componentSelected(ButtonEvent ce) {
if (storeSource != null && storeSource.getCount() > 0) {
for (InfoContactModel extendedInfoContactModel : storeSource.getModels()) {
storeTarget.add(extendedInfoContactModel);
storeSource.remove(extendedInfoContactModel);
}
}
}
});
buttonAllRight = new Button();
buttonAllRight.setIcon(Resources.getAllRight());
buttonAllRight.setToolTip("Move all contact/s from 'Share with' to 'All Contact'");
buttonAllRight.addSelectionListener(new SelectionListener<ButtonEvent>() {
@Override
public void componentSelected(ButtonEvent ce) {
if (storeTarget != null && storeTarget.getCount() > 0) {
for (InfoContactModel extendedInfoContactModel : storeTarget.getModels()) {
storeSource.add(extendedInfoContactModel);
storeTarget.remove(extendedInfoContactModel);
}
}
}
});
vp1.add(buttonSelectedLeft);
vp1.add(buttonAllLeft);
vp1.add(buttonSelectedRight);
vp1.add(buttonAllRight);
lc.add(vp1);
vp1.addListener(Events.Render, new Listener<BaseEvent>() {
@Override
public void handleEvent(BaseEvent be) {
buttonSelectedLeft.el().setStyleAttribute("margin-top", "40px");
buttonAllLeft.el().setStyleAttribute("margin-top", "5px");
buttonSelectedRight.el().setStyleAttribute("margin-top", "20px");
buttonAllRight.el().setStyleAttribute("margin", "5px");
}
});
return lc;
}
private ColumnModel createColumnModel() {
List<ColumnConfig> configs = new ArrayList<ColumnConfig>();
ColumnConfig icon = new ColumnConfig("Icon", "", 25);
configs.add(icon);
ColumnConfig columnConfigDisplayName = new ColumnConfig(InfoContactModel.FULLNAME, "Name", 150);
configs.add(columnConfigDisplayName);
ColumnConfig type = new ColumnConfig(InfoContactModel.ISGROUP, "Type", 50);
configs.add(type);
GridCellRenderer<InfoContactModel> iconRender = new GridCellRenderer<InfoContactModel>() {
@Override
public String render(InfoContactModel model, String property, ColumnData config, int rowIndex, int colIndex,
ListStore<InfoContactModel> store, Grid<InfoContactModel> grid) {
if (model.isGroup()) {
return Resources.getIconGroup().getHTML();
} else {
return Resources.getIconUser().getHTML();
}
}
};
icon.setRenderer(iconRender);
GridCellRenderer<InfoContactModel> displayNameCellRender = new GridCellRenderer<InfoContactModel>() {
public String render(InfoContactModel model, String property, ColumnData config, int rowIndex, int colIndex,
ListStore<InfoContactModel> store, Grid<InfoContactModel> grid) {
if (model != null) {
String value = model.get(property);
if (value != null) {
return "<span qtitle='' qtip='" + model.getLogin() + "'>" + value + "</span>";
}
}
return "";
}
};
columnConfigDisplayName.setRenderer(displayNameCellRender);
GridCellRenderer<InfoContactModel> typeRender = new GridCellRenderer<InfoContactModel>() {
@Override
public String render(InfoContactModel model, String property, ColumnData config, int rowIndex, int colIndex,
ListStore<InfoContactModel> store, Grid<InfoContactModel> grid) {
Boolean isGroup = (Boolean) model.get(property);
String color = "#0F4FA8";
String val = "";
if (isGroup) {
val = "Group";
color = "#05316D";
return "<span style='font-weight: bold; color:" + color + "'>" + val + "</span>";
} else {
val = "User";
return "<span style='font-weight: bold; color:" + color + "'>" + val + "</span>";
}
}
};
type.setRenderer(typeRender);
return new ColumnModel(configs);
}
public List<InfoContactModel> getTargetListContactWithMyLogin() {
List<InfoContactModel> target = new ArrayList<>();
target.addAll(storeTarget.getModels());
target.add(myContact);
return target;
}
private void setGropUserStoreSorter(ListStore<InfoContactModel> store) {
// Sorting files
store.setStoreSorter(new StoreSorter<InfoContactModel>() {
@Override
public int compare(Store<InfoContactModel> store, InfoContactModel m1, InfoContactModel m2,
String property) {
boolean m1Group = m1.isGroup();
boolean m2Group = m2.isGroup();
if (m1Group && !m2Group) {
return -1;
} else if (!m1Group && m2Group) {
return 1;
}
return m1.getName().compareToIgnoreCase(m2.getName());
}
});
}
// public void setHeadTitle(String headTitle){
// this.headTitle = headTitle;
//
// if(headTitle==null)
// this.setHeading(GROUP_DRAGGING_CONTACTS);
// else
// this.setHeading(headTitle);
// }
public void setLeftListContactsTitle(String leftListContactsTitle) {
this.leftListContactsTitle = leftListContactsTitle;
if (leftListContactsTitle == null)
labelAllContacts.setText(ALL_CONTACTS);
else
labelAllContacts.setText(leftListContactsTitle);
}
public void setRightListContactsTitle(String rightListContactsTitle) {
this.rightListContactsTitle = rightListContactsTitle;
if (rightListContactsTitle == null)
labelShareWith.setText(SHARE_WITH);
else
labelShareWith.setText(rightListContactsTitle);
}
public String getLeftListContactsTitle() {
return leftListContactsTitle;
}
// public String getHeadTitle() {
// return headTitle;
// }
public String getRightListContactsTitle() {
return rightListContactsTitle;
}
}

View File

@ -140,7 +140,7 @@ public class MultiValuePanel extends Composite {
if (itemBox.getValue() != null && !itemBox.getValue().trim().isEmpty()) {
final ListItem displayItem = new ListItem();
displayItem.setStyleName("multivalue-panel-token-ws");
Paragraph p = new Paragraph(itemBox.getValue());
Paragraph p = new Paragraph(suggest.getInfoContactModel().getName());
Span span = new Span("x");
span.addClickHandler(new ClickHandler() {
@ -153,10 +153,10 @@ public class MultiValuePanel extends Composite {
displayItem.add(span);
// original value of the item selected
GWT.log("Adding selected item '" + itemBox.getValue());
GWT.log("Adding selected user '" + suggest.getInfoContactModel().getName());
// itemsSelected.add(itemBox.getValue());
// GWT.log("Total: " + itemsSelected);
users.put(itemBox.getValue(), suggest.getInfoContactModel());
users.put(suggest.getInfoContactModel().getName(), suggest.getInfoContactModel());
list.insert(displayItem, list.getWidgetCount() - 1);
itemBox.setValue("");

View File

@ -1,10 +1,11 @@
/**
*
*/
package org.gcube.portlets.widgets.workspacesharingwidget.client.view.sharing.multisuggest;
package org.gcube.portlets.widgets.workspacesharingwidget.client.view.sharing.user;
import java.util.List;
import org.gcube.portlets.widgets.workspacesharingwidget.client.ConstantsSharing.LOAD_CONTACTS_AS;
import org.gcube.portlets.widgets.workspacesharingwidget.client.resources.Resources;
import org.gcube.portlets.widgets.workspacesharingwidget.shared.InfoContactModel;
@ -44,7 +45,7 @@ public class DialogMultiDragContact extends Dialog{
private LayoutContainer lcMiddle = new LayoutContainer();
private LayoutContainer lcBottom = new LayoutContainer();
public DialogMultiDragContact(String headTitle, String leftListContactsTitle, String rightListContactsTitle, boolean visibleAlreadyShared, boolean hideOnPressOk) {
public DialogMultiDragContact(String headTitle, String leftListContactsTitle, String rightListContactsTitle, boolean visibleAlreadyShared, boolean hideOnPressOk, boolean hiddenMySelf) {
this.multiDragContact = new MultiDragContact(leftListContactsTitle, rightListContactsTitle, visibleAlreadyShared);
this.hideOnPressOkButton = hideOnPressOk;
this.visibleTextArea = visibleAlreadyShared;

View File

@ -1,4 +1,4 @@
package org.gcube.portlets.widgets.workspacesharingwidget.client.view.sharing.multisuggest;
package org.gcube.portlets.widgets.workspacesharingwidget.client.view.sharing.user;
import java.util.ArrayList;
import java.util.List;
@ -45,19 +45,17 @@ import com.google.gwt.user.client.Random;
/**
*
* @author Francesco Mangiacrapa
* Jan 27, 2015
* @author Francesco Mangiacrapa Jan 27, 2015
*
*/
public class MultiDragContact extends ContentPanel {
private static final int HEIGHT_CP = 375;
private static final String ALL_CONTACTS = "All Contacts";
private static final String SHARE_WITH = "Share with...";
public static final int WIDTH_CP = 597;
// private static final int HEIGHT_DIALOG = 542;
// private static final int HEIGHT_DIALOG = 542;
public static final int HEIGHT_GRID = 310;
public static final int PADDING = 5;
@ -76,16 +74,17 @@ public class MultiDragContact extends ContentPanel {
private Button buttonSelectedRight;
private Button buttonAllRight;
private Button buttonAllLeft;
// private boolean hideOnPressOkButton;
// private String headTitle;
// private boolean hideOnPressOkButton;
// private String headTitle;
private String leftListContactsTitle;
private String rightListContactsTitle;
private Label allContacts;
private Label shareWith;
public MultiDragContact(String leftListContactsTitle, String rightListContactsTitle, boolean visibleAlreadyShared) {
this(visibleAlreadyShared);
// setHeadTitle(headTitle);
// setHeadTitle(headTitle);
setLeftListContactsTitle(leftListContactsTitle);
setRightListContactsTitle(rightListContactsTitle);
}
@ -95,22 +94,23 @@ public class MultiDragContact extends ContentPanel {
this.setBodyBorder(false);
this.setBorders(false);
// setStyleAttribute("margin", "10px");
setBodyStyle("padding: "+PADDING+"px; background: none");
// setStyleAttribute("margin", "10px");
setBodyStyle("padding: " + PADDING + "px; background: none");
// SORTING STORE
setGropUserStoreSorter(storeSource);
setGropUserStoreSorter(storeTarget);
ContentPanel cpAlreadyShared = new ContentPanel();
cpAlreadyShared.setWidth(WIDTH_CP);
cpAlreadyShared.setId("Already-Shared-"+Random.nextInt());
cpAlreadyShared.setId("Already-Shared-" + Random.nextInt());
cpAlreadyShared.getElement().getStyle().setHeight(ALREADY_SHARED_HEIGHT, Unit.PX);
//cpAlreadyShared.setStyleAttribute("height", ALREADY_SHARED_HEIGHT+"px important!");
// cpAlreadyShared.setStyleAttribute("height", ALREADY_SHARED_HEIGHT+"px
// important!");
cpAlreadyShared.setHeaderVisible(false);
cpAlreadyShared.setVisible(visibleAlreadyShared);
cpAlreadyShared.setLayout(new FitLayout());
//cpAlreadyShared.setScrollMode(Scroll.AUTOY);
// cpAlreadyShared.setScrollMode(Scroll.AUTOY);
VerticalPanel vpShared = new VerticalPanel();
vpShared.setVerticalAlign(VerticalAlignment.MIDDLE);
@ -140,7 +140,7 @@ public class MultiDragContact extends ContentPanel {
add(cpAlreadyShared);
final ContentPanel cp = new ContentPanel();
cp.setId("All-Contacts-Share-Contacts-"+Random.nextInt());
cp.setId("All-Contacts-Share-Contacts-" + Random.nextInt());
cp.setSize(WIDTH_CP, HEIGHT_CP);
cp.setHeaderVisible(false);
cp.setLayout(new RowLayout(Orientation.HORIZONTAL));
@ -151,8 +151,7 @@ public class MultiDragContact extends ContentPanel {
allContacts = new Label(ALL_CONTACTS);
vpAllContacts.add(allContacts);
gridAllContacts = new Grid<InfoContactModel>(storeSource,
createColumnModel());
gridAllContacts = new Grid<InfoContactModel>(storeSource, createColumnModel());
storeSource.setDefaultSort(InfoContactModel.FULLNAME, SortDir.ASC);
storeSource.sort(InfoContactModel.FULLNAME, SortDir.ASC);
@ -163,8 +162,7 @@ public class MultiDragContact extends ContentPanel {
final StoreFilterField<InfoContactModel> filter = new StoreFilterField<InfoContactModel>() {
@Override
protected boolean doSelect(Store<InfoContactModel> store,
InfoContactModel parent, InfoContactModel record,
protected boolean doSelect(Store<InfoContactModel> store, InfoContactModel parent, InfoContactModel record,
String property, String filter) {
String name = record.getName();
@ -177,8 +175,8 @@ public class MultiDragContact extends ContentPanel {
};
// filter.setFieldLabel("Filter Contacts");
// filter.setWidth(247);
//
filter.setEmptyText("Filter All Contacts");
HorizontalPanel hp = new HorizontalPanel();
hp.setStyleAttribute("padding-top", "5px");
@ -213,13 +211,12 @@ public class MultiDragContact extends ContentPanel {
shareWith = new Label(SHARE_WITH);
vpShareWith.add(shareWith);
gridShareWith = new Grid<InfoContactModel>(storeTarget,createColumnModel());
gridShareWith = new Grid<InfoContactModel>(storeTarget, createColumnModel());
final StoreFilterField<InfoContactModel> filter2 = new StoreFilterField<InfoContactModel>() {
@Override
protected boolean doSelect(Store<InfoContactModel> store,
InfoContactModel parent, InfoContactModel record,
protected boolean doSelect(Store<InfoContactModel> store, InfoContactModel parent, InfoContactModel record,
String property, String filter) {
String name = record.getName();
@ -233,7 +230,7 @@ public class MultiDragContact extends ContentPanel {
};
// filter.setFieldLabel("Filter Contacts");
// filter2.setWidth(247);
// filter2.setWidth(247);
filter2.setEmptyText("Filter Share with");
hp = new HorizontalPanel();
@ -263,17 +260,17 @@ public class MultiDragContact extends ContentPanel {
add(cp);
cp.addListener(Events.Render, new Listener<BaseEvent>() {
cp.addListener(Events.Render, new Listener<BaseEvent>() {
@Override
public void handleEvent(BaseEvent be) {
int width = gridAllContacts.getWidth();
filter.setWidth(width-2);
filter2.setWidth(width-2);
filter.setWidth(width - 2);
filter2.setWidth(width - 2);
gridAllContacts.setWidth(width);
vpAllContacts.setWidth(width+7);
vpAllContacts.setWidth(width + 7);
gridShareWith.setWidth(width);
vpShareWith.setWidth(width+10);
vpShareWith.setWidth(width + 10);
vpShareWith.layout();
vpAllContacts.layout();
cp.layout();
@ -296,90 +293,81 @@ public class MultiDragContact extends ContentPanel {
buttonSelectedLeft = new Button();
buttonSelectedLeft.setIcon(Resources.getSelectedLeft());
buttonSelectedLeft.setToolTip("Move selected contact/s from 'All Contact' to 'Share with'");
buttonSelectedLeft
.addSelectionListener(new SelectionListener<ButtonEvent>() {
buttonSelectedLeft.addSelectionListener(new SelectionListener<ButtonEvent>() {
@Override
public void componentSelected(ButtonEvent ce) {
@Override
public void componentSelected(ButtonEvent ce) {
List<InfoContactModel> selectedItems = gridAllContacts
.getSelectionModel().getSelectedItems();
List<InfoContactModel> selectedItems = gridAllContacts.getSelectionModel().getSelectedItems();
if (selectedItems != null && selectedItems.size() > 0) {
if (selectedItems != null && selectedItems.size() > 0) {
for (InfoContactModel extendedInfoContactModel : selectedItems) {
storeTarget.add(extendedInfoContactModel);
storeSource.remove(extendedInfoContactModel);
}
}
for (InfoContactModel extendedInfoContactModel : selectedItems) {
storeTarget.add(extendedInfoContactModel);
storeSource.remove(extendedInfoContactModel);
}
});
}
}
});
buttonSelectedRight = new Button();
buttonSelectedRight.setIcon(Resources.getSelectedRight());
buttonSelectedRight.setToolTip("Move selected contact/s from 'Share with' to 'All Contact'");
buttonSelectedRight
.addSelectionListener(new SelectionListener<ButtonEvent>() {
buttonSelectedRight.addSelectionListener(new SelectionListener<ButtonEvent>() {
@Override
public void componentSelected(ButtonEvent ce) {
@Override
public void componentSelected(ButtonEvent ce) {
List<InfoContactModel> selectedItems = gridShareWith
.getSelectionModel().getSelectedItems();
List<InfoContactModel> selectedItems = gridShareWith.getSelectionModel().getSelectedItems();
if (selectedItems != null && selectedItems.size() > 0) {
if (selectedItems != null && selectedItems.size() > 0) {
for (InfoContactModel extendedInfoContactModel : selectedItems) {
storeSource.add(extendedInfoContactModel);
storeTarget.remove(extendedInfoContactModel);
}
}
for (InfoContactModel extendedInfoContactModel : selectedItems) {
storeSource.add(extendedInfoContactModel);
storeTarget.remove(extendedInfoContactModel);
}
});
}
}
});
buttonAllLeft = new Button();
buttonAllLeft.setIcon(Resources.getAllLeft());
buttonAllLeft.setToolTip("Move all contact/s from 'All Contact' to 'Share with'");
buttonAllLeft
.addSelectionListener(new SelectionListener<ButtonEvent>() {
buttonAllLeft.addSelectionListener(new SelectionListener<ButtonEvent>() {
@Override
public void componentSelected(ButtonEvent ce) {
if (storeSource != null && storeSource.getCount() > 0) {
for (InfoContactModel extendedInfoContactModel : storeSource
.getModels()) {
storeTarget.add(extendedInfoContactModel);
storeSource.remove(extendedInfoContactModel);
}
}
@Override
public void componentSelected(ButtonEvent ce) {
if (storeSource != null && storeSource.getCount() > 0) {
for (InfoContactModel extendedInfoContactModel : storeSource.getModels()) {
storeTarget.add(extendedInfoContactModel);
storeSource.remove(extendedInfoContactModel);
}
});
}
}
});
buttonAllRight = new Button();
buttonAllRight.setIcon(Resources.getAllRight());
buttonAllRight
.setToolTip("Move all contact/s from 'Share with' to 'All Contact'");
buttonAllRight.setToolTip("Move all contact/s from 'Share with' to 'All Contact'");
buttonAllRight
.addSelectionListener(new SelectionListener<ButtonEvent>() {
buttonAllRight.addSelectionListener(new SelectionListener<ButtonEvent>() {
@Override
public void componentSelected(ButtonEvent ce) {
if (storeTarget != null && storeTarget.getCount() > 0) {
for (InfoContactModel extendedInfoContactModel : storeTarget
.getModels()) {
storeSource.add(extendedInfoContactModel);
storeTarget.remove(extendedInfoContactModel);
}
}
@Override
public void componentSelected(ButtonEvent ce) {
if (storeTarget != null && storeTarget.getCount() > 0) {
for (InfoContactModel extendedInfoContactModel : storeTarget.getModels()) {
storeSource.add(extendedInfoContactModel);
storeTarget.remove(extendedInfoContactModel);
}
});
}
}
});
vp1.add(buttonSelectedLeft);
vp1.add(buttonAllLeft);
@ -394,8 +382,7 @@ public class MultiDragContact extends ContentPanel {
public void handleEvent(BaseEvent be) {
buttonSelectedLeft.el().setStyleAttribute("margin-top", "40px");
buttonAllLeft.el().setStyleAttribute("margin-top", "5px");
buttonSelectedRight.el()
.setStyleAttribute("margin-top", "20px");
buttonSelectedRight.el().setStyleAttribute("margin-top", "20px");
buttonAllRight.el().setStyleAttribute("margin", "5px");
}
@ -410,20 +397,16 @@ public class MultiDragContact extends ContentPanel {
ColumnConfig icon = new ColumnConfig("Icon", "", 25);
configs.add(icon);
ColumnConfig columnConfigDisplayName = new ColumnConfig(
InfoContactModel.FULLNAME, "Name", 150);
ColumnConfig columnConfigDisplayName = new ColumnConfig(InfoContactModel.FULLNAME, "Name", 150);
configs.add(columnConfigDisplayName);
ColumnConfig type = new ColumnConfig(InfoContactModel.ISGROUP, "Type",
50);
ColumnConfig type = new ColumnConfig(InfoContactModel.ISGROUP, "Type", 50);
configs.add(type);
GridCellRenderer<InfoContactModel> iconRender = new GridCellRenderer<InfoContactModel>() {
@Override
public String render(InfoContactModel model, String property,
ColumnData config, int rowIndex, int colIndex,
ListStore<InfoContactModel> store,
Grid<InfoContactModel> grid) {
public String render(InfoContactModel model, String property, ColumnData config, int rowIndex, int colIndex,
ListStore<InfoContactModel> store, Grid<InfoContactModel> grid) {
if (model.isGroup()) {
return Resources.getIconGroup().getHTML();
} else {
@ -435,17 +418,14 @@ public class MultiDragContact extends ContentPanel {
icon.setRenderer(iconRender);
GridCellRenderer<InfoContactModel> displayNameCellRender = new GridCellRenderer<InfoContactModel>() {
public String render(InfoContactModel model, String property,
ColumnData config, int rowIndex, int colIndex,
ListStore<InfoContactModel> store,
Grid<InfoContactModel> grid) {
public String render(InfoContactModel model, String property, ColumnData config, int rowIndex, int colIndex,
ListStore<InfoContactModel> store, Grid<InfoContactModel> grid) {
if (model != null) {
String value = model.get(property);
if (value != null) {
return "<span qtitle='' qtip='" + model.getLogin()
+ "'>" + value + "</span>";
return "<span qtitle='' qtip='" + model.getLogin() + "'>" + value + "</span>";
}
}
@ -457,22 +437,18 @@ public class MultiDragContact extends ContentPanel {
GridCellRenderer<InfoContactModel> typeRender = new GridCellRenderer<InfoContactModel>() {
@Override
public String render(InfoContactModel model, String property,
ColumnData config, int rowIndex, int colIndex,
ListStore<InfoContactModel> store,
Grid<InfoContactModel> grid) {
public String render(InfoContactModel model, String property, ColumnData config, int rowIndex, int colIndex,
ListStore<InfoContactModel> store, Grid<InfoContactModel> grid) {
Boolean isGroup = (Boolean) model.get(property);
String color = "#0F4FA8";
String val = "";
if (isGroup) {
val = "Group";
color = "#05316D";
return "<span style='font-weight: bold; color:" + color
+ "'>" + val + "</span>";
return "<span style='font-weight: bold; color:" + color + "'>" + val + "</span>";
} else {
val = "User";
return "<span style='font-weight: bold; color:" + color
+ "'>" + val + "</span>";
return "<span style='font-weight: bold; color:" + color + "'>" + val + "</span>";
}
}
};
@ -520,7 +496,6 @@ public class MultiDragContact extends ContentPanel {
storeTarget.add(listContact);
}
public void addSourceContact(InfoContactModel contact) {
if (contact != null)
storeSource.add(contact);
@ -541,8 +516,8 @@ public class MultiDragContact extends ContentPanel {
store.setStoreSorter(new StoreSorter<InfoContactModel>() {
@Override
public int compare(Store<InfoContactModel> store,
InfoContactModel m1, InfoContactModel m2, String property) {
public int compare(Store<InfoContactModel> store, InfoContactModel m1, InfoContactModel m2,
String property) {
boolean m1Group = m1.isGroup();
boolean m2Group = m2.isGroup();
@ -557,19 +532,12 @@ public class MultiDragContact extends ContentPanel {
});
}
// public void setHeadTitle(String headTitle){
// this.headTitle = headTitle;
//
// if(headTitle==null)
// this.setHeading(GROUP_DRAGGING_CONTACTS);
// else
// this.setHeading(headTitle);
// }
public void setLeftListContactsTitle(String leftListContactsTitle) {
this.leftListContactsTitle = leftListContactsTitle;
if(leftListContactsTitle==null)
if (leftListContactsTitle == null)
allContacts.setText(ALL_CONTACTS);
else
allContacts.setText(leftListContactsTitle);
@ -578,7 +546,7 @@ public class MultiDragContact extends ContentPanel {
public void setRightListContactsTitle(String rightListContactsTitle) {
this.rightListContactsTitle = rightListContactsTitle;
if(rightListContactsTitle==null)
if (rightListContactsTitle == null)
shareWith.setText(SHARE_WITH);
else
shareWith.setText(rightListContactsTitle);
@ -588,9 +556,7 @@ public class MultiDragContact extends ContentPanel {
return leftListContactsTitle;
}
// public String getHeadTitle() {
// return headTitle;
// }
public String getRightListContactsTitle() {
return rightListContactsTitle;

View File

@ -4,6 +4,8 @@
package org.gcube.portlets.widgets.workspacesharingwidget.server;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@ -30,7 +32,7 @@ import org.gcube.portlets.widgets.workspacesharingwidget.server.util.WsUtil;
import org.gcube.portlets.widgets.workspacesharingwidget.shared.ACL_TYPE;
import org.gcube.portlets.widgets.workspacesharingwidget.shared.FileModel;
import org.gcube.portlets.widgets.workspacesharingwidget.shared.FolderModel;
import org.gcube.portlets.widgets.workspacesharingwidget.shared.GGroup;
import org.gcube.portlets.widgets.workspacesharingwidget.shared.UserVRE;
import org.gcube.portlets.widgets.workspacesharingwidget.shared.GXTFolderItemTypeEnum;
import org.gcube.portlets.widgets.workspacesharingwidget.shared.InfoContactModel;
import org.gcube.portlets.widgets.workspacesharingwidget.shared.WorkspaceACL;
@ -38,7 +40,6 @@ import org.gcube.portlets.widgets.workspacesharingwidget.shared.WorkspaceACL.USE
import org.gcube.portlets.widgets.workspacesharingwidget.shared.system.VO;
import org.gcube.portlets.widgets.workspacesharingwidget.shared.system.VRE;
import org.gcube.vomanagement.usermanagement.GroupManager;
import org.gcube.vomanagement.usermanagement.UserManager;
import org.gcube.vomanagement.usermanagement.impl.LiferayGroupManager;
import org.gcube.vomanagement.usermanagement.impl.LiferayUserManager;
import org.gcube.vomanagement.usermanagement.model.GCubeGroup;
@ -57,6 +58,28 @@ public class GWTWorkspaceSharingBuilder {
private static HashMap<String, InfoContactModel> hashTestUser = null;
private static LiferayUserManager liferayUserManager;
private static GroupManager groupManager;
public static LiferayUserManager getLiferayUserManager() {
if (liferayUserManager == null) {
liferayUserManager = new LiferayUserManager();
return liferayUserManager;
} else {
return liferayUserManager;
}
}
public static GroupManager getGroupManager() {
if (groupManager == null) {
groupManager = new LiferayGroupManager();
return groupManager;
} else {
return groupManager;
}
}
/**
* Used in test mode.
*
@ -91,6 +114,9 @@ public class GWTWorkspaceSharingBuilder {
hashTestUser.put("valentina.marioli", new InfoContactModel("valentina.marioli", "valentina.marioli",
"Valentina Marioli", "@isti.cnr.it", false));
hashTestUser.put("giancarlo.panichi", new InfoContactModel("giancarlo.panichi", "giancarlo.panichi",
"Giancarlo Panichi", "@isti.cnr.it", false));
hashTestUser.put("devVRE", new InfoContactModel("devVRE", "devVRE", "devVRE", "", true));
// hashTestUser.put(WsUtil.TEST_USER.toString(),
@ -271,7 +297,7 @@ public class GWTWorkspaceSharingBuilder {
*/
public List<InfoContactModel> buildGXTListContactsModelFromUserModel(PortalContextInfo info) throws Exception {
List<GCubeUser> listUsers = new LiferayUserManager().listUsersByGroup(info.getCurrGroupId());
List<GCubeUser> listUsers = getLiferayUserManager().listUsersByGroup(info.getCurrGroupId());
if (listUsers == null) {
logger.error("No users found in: " + info.getCurrentScope());
@ -306,10 +332,10 @@ public class GWTWorkspaceSharingBuilder {
* @throws Exception
* Error
*/
public List<InfoContactModel> buildGXTListContactsModelFromUserModel(PortalContextInfo info, GGroup gGroup)
public List<InfoContactModel> buildGXTListContactsModelByVRE(PortalContextInfo info, UserVRE gGroup)
throws Exception {
List<GCubeUser> listUsers = new LiferayUserManager().listUsersByGroup(gGroup.getGroupId());
List<GCubeUser> listUsers = getLiferayUserManager().listUsersByGroup(gGroup.getGroupId());
if (listUsers == null) {
logger.error("No users found in: " + info.getCurrentScope());
@ -331,37 +357,65 @@ public class GWTWorkspaceSharingBuilder {
logger.trace("buildGXTListContactsModel is not returning user: " + userModel.getUsername()
+ "because name is null or empty");
}
logger.trace("List contact model completed, return " + listContactsModel.size() + " contacts");
return listContactsModel;
}
public ArrayList<GGroup> getVREList(PortalContextInfo info) throws Exception {
public ArrayList<UserVRE> getUserVREList(PortalContextInfo info) throws Exception {
try {
logger.info("Current context is " + info.getCurrGroupId());
ArrayList<GGroup> contexts = new ArrayList<>();
ArrayList<UserVRE> contexts = new ArrayList<>();
GroupManager gm = new LiferayGroupManager();
GCubeGroup currentGroup = gm.getGroup(info.getCurrGroupId());
// GCubeGroup currentGroup = gm.getGroup(info.getCurrGroupId());
logger.info("Current user: " + info.getUsername());
// is root
List<GCubeGroup> children = currentGroup.getChildren();
for (GCubeGroup gCubeGroup : children) {
long userId = getLiferayUserManager().getUserId(info.getUsername());
// get the vo children
List<GCubeGroup> childrenVO = gCubeGroup.getChildren();
for (GCubeGroup voChildren : childrenVO) {
GGroup gGroup = new GGroup(voChildren.getGroupId(), voChildren.getParentGroupId(),
voChildren.getGroupName(), voChildren.getDescription());
contexts.add(gGroup);
logger.info("UserId is: " + userId);
// Get Gateways
List<GCubeGroup> listOfGroups = getGroupManager().listGroupsByUser(userId);
if (listOfGroups != null && !listOfGroups.isEmpty()) {
for (GCubeGroup gCubeGroup : listOfGroups) {
// Get VOs
List<GCubeGroup> voGroups = gCubeGroup.getChildren();
if (voGroups != null && !voGroups.isEmpty()) {
for (GCubeGroup voGroup : voGroups) {
// Get VREs
List<GCubeGroup> vreGroups = voGroup.getChildren();
if (vreGroups != null && !vreGroups.isEmpty()) {
for (GCubeGroup vreGroup : vreGroups) {
UserVRE gGroup = new UserVRE(vreGroup.getGroupId(), vreGroup.getParentGroupId(),
vreGroup.getGroupName(), vreGroup.getDescription());
contexts.add(gGroup);
}
}
}
}
}
}
Collections.sort(contexts, new Comparator<UserVRE>() {
public int compare(UserVRE vre1, UserVRE vre2) {
if (vre1.getGroupName() == null) {
return -1;
} else {
if (vre2.getGroupName() == null) {
return +1;
} else {
return vre1.getGroupName().compareTo(vre2.getGroupName());
}
}
}
});
return contexts;
} catch (Exception e) {
logger.error("Error retrieving the list of VRE!", e);
logger.error("Error retrieving the list of user VRE!", e);
throw new Exception("Error retrieving the list of VRE!", e);
}
@ -371,8 +425,8 @@ public class GWTWorkspaceSharingBuilder {
try {
logger.debug("Search use keyword: " + keyword);
List<InfoContactModel> listInfoContactModel = new ArrayList<>();
UserManager userManager = new LiferayUserManager();
List<GCubeUser> users = userManager.searchUsersByGroup(keyword, info.getCurrGroupId());
List<GCubeUser> users = getLiferayUserManager().searchUsersByGroup(keyword, info.getCurrGroupId());
for (int i = 0; i < users.size() && i < 30; i++) {
GCubeUser user = users.get(i);

View File

@ -1,5 +1,8 @@
package org.gcube.portlets.widgets.workspacesharingwidget.server;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.time.temporal.ChronoUnit;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
@ -45,14 +48,13 @@ import org.gcube.portlets.widgets.workspacesharingwidget.shared.AllowAccess;
import org.gcube.portlets.widgets.workspacesharingwidget.shared.CredentialModel;
import org.gcube.portlets.widgets.workspacesharingwidget.shared.ExtendedWorkspaceACL;
import org.gcube.portlets.widgets.workspacesharingwidget.shared.FileModel;
import org.gcube.portlets.widgets.workspacesharingwidget.shared.GGroup;
import org.gcube.portlets.widgets.workspacesharingwidget.shared.InfoContactModel;
import org.gcube.portlets.widgets.workspacesharingwidget.shared.ReportAssignmentACL;
import org.gcube.portlets.widgets.workspacesharingwidget.shared.SessionExpiredException;
import org.gcube.portlets.widgets.workspacesharingwidget.shared.UserVRE;
import org.gcube.portlets.widgets.workspacesharingwidget.shared.WorkspaceACL;
import org.gcube.vomanagement.usermanagement.GroupManager;
import org.gcube.vomanagement.usermanagement.UserManager;
import org.gcube.vomanagement.usermanagement.impl.LiferayGroupManager;
import org.gcube.vomanagement.usermanagement.impl.LiferayUserManager;
import org.gcube.vomanagement.usermanagement.model.GCubeGroup;
import org.gcube.vomanagement.usermanagement.model.GCubeUser;
@ -69,7 +71,9 @@ import com.google.gwt.user.server.rpc.RemoteServiceServlet;
@SuppressWarnings("serial")
public class WorkspaceSharingServiceImpl extends RemoteServiceServlet implements WorkspaceSharingService {
protected static Logger logger = LoggerFactory.getLogger(WorkspaceSharingServiceImpl.class);
private static Logger logger = LoggerFactory.getLogger(WorkspaceSharingServiceImpl.class);
private static DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss.SSS");
/**
* Gets the notification producer.
@ -107,22 +111,7 @@ public class WorkspaceSharingServiceImpl extends RemoteServiceServlet implements
org.gcube.common.homelibrary.home.exceptions.InternalErrorException, HomeNotFoundException {
logger.trace("Get Workspace");
PortalContext pContext = PortalContext.getConfiguration();
// USER
GCubeUser user = pContext.getCurrentUser(httpServletRequest);
String username = user.getUsername();
String fullName = user.getFullname();
String email = user.getEmail();
String avatarID = user.getUserAvatarId();
String avatarURL = user.getUserAvatarURL();
// SESSION
String currentScope = pContext.getCurrentScope(httpServletRequest);
String userToken = pContext.getCurrentUserToken(httpServletRequest);
long currGroupId = pContext.getCurrentGroupId(httpServletRequest);
PortalContextInfo info = new PortalContextInfo(username, fullName, email, avatarID, avatarURL, currentScope,
userToken, currGroupId);
PortalContextInfo info = WsUtil.getPortalContext(this.getThreadLocalRequest());
logger.trace("PortalContextInfo: " + info);
ScopeProvider.instance.set(info.getCurrentScope());
@ -194,23 +183,23 @@ public class WorkspaceSharingServiceImpl extends RemoteServiceServlet implements
}
@Override
public List<GGroup> getVREList() throws Exception {
public List<UserVRE> getUserVREList() throws Exception {
try {
PortalContextInfo info = WsUtil.getPortalContext(this.getThreadLocalRequest());
GWTWorkspaceSharingBuilder builder = new GWTWorkspaceSharingBuilder();
List<GGroup> listContactsModel = builder.getVREList(info);
List<UserVRE> listContactsModel = builder.getUserVREList(info);
return listContactsModel;
} catch (Exception e) {
logger.error("Error in getVREList(): " + e.getLocalizedMessage(), e);
throw new Exception("Error retrieving VRE List!", e);
logger.error("Error in getUserVREList(): " + e.getLocalizedMessage(), e);
throw new Exception("Error retrieving User VRE List!", e);
}
}
@Override
public List<InfoContactModel> getAllContactsByVRE(GGroup gGroup) throws Exception {
public List<InfoContactModel> getAllContactsByVRE(UserVRE gGroup) throws Exception {
try {
logger.info("Call getAllContactsByVRE(): " + gGroup);
@ -230,7 +219,7 @@ public class WorkspaceSharingServiceImpl extends RemoteServiceServlet implements
GWTWorkspaceSharingBuilder builder = new GWTWorkspaceSharingBuilder();
List<InfoContactModel> listContactsModel = builder.buildGXTListContactsModelFromUserModel(info, gGroup);
List<InfoContactModel> listContactsModel = builder.buildGXTListContactsModelByVRE(info, gGroup);
// listContactsModel.addAll(builder.getGXTListContactsModelFromVOs(info));
@ -252,21 +241,25 @@ public class WorkspaceSharingServiceImpl extends RemoteServiceServlet implements
*/
@Override
public List<InfoContactModel> getListUserSharedByFolderSharedId(String itemId) throws Exception {
LocalDateTime startTime = LocalDateTime.now();
logger.info("Call getListUserSharedByFolderSharedId() Start Time: "+startTime.format(formatter));
try {
logger.info("Call getListUserSharedByFolderSharedId(): [folderId=" + itemId + "]");
if (itemId == null || itemId.isEmpty()) {
logger.error("Error in getListUserSharedByFolderSharedId(), invalid folder id: [id=" + itemId + "]");
throw new Exception("Invalid item id requested: " + itemId);
}
StorageHubClient shc = new StorageHubClient();
OpenResolver openResolver = shc.open(itemId);
FolderContainer folderContainer = openResolver.asFolder();
FolderItem folder = folderContainer.get();
FolderItem folder = folderContainer.get();
if (folder.isShared()) {
if (folder instanceof SharedFolder) {
SharedFolder sharedFolder = (SharedFolder) folder;
return retrieveUsersListFromSharedFolder(sharedFolder);
} else {
FolderContainer rootSharedFolderContainer = folderContainer.getRootSharedFolder();
@ -289,6 +282,13 @@ public class WorkspaceSharingServiceImpl extends RemoteServiceServlet implements
} catch (Exception e) {
logger.error("Error in getListUserSharedByFolderSharedId(): " + e.getLocalizedMessage(), e);
throw new Exception(e.getLocalizedMessage(), e);
} finally {
LocalDateTime endTime = LocalDateTime.now();
logger.info("Call getListUserSharedByFolderSharedId() End Time: "+endTime.format(formatter));
long diff = ChronoUnit.MILLIS.between(startTime, endTime);
logger.info("Call getListUserSharedByFolderSharedId() Delay: MILLIS="+diff);
}
}
@ -311,7 +311,11 @@ public class WorkspaceSharingServiceImpl extends RemoteServiceServlet implements
if (map != null && !map.isEmpty()) {
List<InfoContactModel> listShared = new ArrayList<>();
List<String> keys = new ArrayList<String>(map.keySet());
UserManager um = new LiferayUserManager();
LocalDateTime startTime = LocalDateTime.now();
logger.info("Liferay retrieve users Start Time: "+startTime.format(formatter));
UserManager um = GWTWorkspaceSharingBuilder.getLiferayUserManager();
GCubeUser curr;
for (String username : keys) {
curr = null;
@ -326,6 +330,11 @@ public class WorkspaceSharingServiceImpl extends RemoteServiceServlet implements
listShared.add(userInfo);
}
}
LocalDateTime endTime = LocalDateTime.now();
logger.info("Liferay retrieve users End Time: "+endTime.format(formatter));
long diff = ChronoUnit.MILLIS.between(startTime, endTime);
logger.info("Liferay Delay: MILLIS="+diff);
return listShared;
} else {
logger.info("The folder with id: " + sharedFolder.getId() + " has a invalid map!");
@ -345,14 +354,17 @@ public class WorkspaceSharingServiceImpl extends RemoteServiceServlet implements
*/
@Override
public InfoContactModel getOwnerByItemId(String itemId) throws Exception {
//TODO
LocalDateTime startTime = LocalDateTime.now();
logger.info("Call getOwnerByItemId() Start Time: "+startTime.format(formatter));
try {
logger.info("Call getOwnerByItemId(): [itemId=" + itemId + "]");
if (itemId == null || itemId.isEmpty()) {
logger.error("Error in getOwnerByItemId(), invalid item id: " + itemId);
throw new Exception("Invalid request, item id: " + itemId);
}
StorageHubClient shc = new StorageHubClient();
OpenResolver openResolverForFile = shc.open(itemId);
ItemContainer<Item> itemContainer = openResolverForFile.asItem();
@ -361,16 +373,18 @@ public class WorkspaceSharingServiceImpl extends RemoteServiceServlet implements
if (item != null) {
logger.debug("Owner: " + item.getOwner());
if (item.getOwner() != null && !item.getOwner().isEmpty()) {
PortalContextInfo info = WsUtil.getPortalContext(this.getThreadLocalRequest());
GWTWorkspaceSharingBuilder builder = new GWTWorkspaceSharingBuilder();
List<InfoContactModel> listContactsModel = builder.buildGXTListContactsModelFromUserModel(info);
for (InfoContactModel infoContactModel : listContactsModel) {
if (infoContactModel.getLogin().compareTo(item.getOwner()) == 0) {
logger.debug("Retrieved: " + infoContactModel);
try {
UserManager um = GWTWorkspaceSharingBuilder.getLiferayUserManager();
GCubeUser curr=um.getUserByUsername(item.getOwner());
if (curr != null && curr.getFullname() != null && !curr.getFullname().isEmpty()) {
InfoContactModel infoContactModel = new InfoContactModel(String.valueOf(curr.getUserId()), curr.getUsername(), curr.getFullname(),
extractDomainFromEmail(curr.getEmail()), false);
logger.debug("Owner found: "+infoContactModel);
return infoContactModel;
}
} catch(Throwable e){
}
logger.debug("Owner not found from user model!");
return new InfoContactModel(item.getOwner(), item.getOwner(), item.getOwner(), "", false);
@ -386,6 +400,13 @@ public class WorkspaceSharingServiceImpl extends RemoteServiceServlet implements
} catch (Exception e) {
logger.error("Error in getOwnerByItemId(): " + e.getLocalizedMessage(), e);
throw new Exception(e.getMessage());
} finally {
LocalDateTime endTime = LocalDateTime.now();
logger.info("Call getOwnerByItemId() End Time: "+endTime.format(formatter));
long diff = ChronoUnit.MILLIS.between(startTime, endTime);
logger.info("Call getOwnerByItemId() Delay: MILLIS="+diff);
}
}
@ -1125,7 +1146,7 @@ public class WorkspaceSharingServiceImpl extends RemoteServiceServlet implements
logger.info("Unshared folded for users: " + users);
ArrayList<InfoContactModel> listContacts = new ArrayList<>();
for (String key : users) {
InfoContactModel contact = new InfoContactModel(key, key, key, "",false);
InfoContactModel contact = new InfoContactModel(key, key, key, "", false);
listContacts.add(contact);
}
NotificationsProducer np = getNotificationProducer(
@ -1321,15 +1342,14 @@ public class WorkspaceSharingServiceImpl extends RemoteServiceServlet implements
private List<GCubeGroup> retrieveCurrentUserACLFromGroup(String userName) throws Exception {
try {
// Instanciate the manager
GroupManager groupManager = new LiferayGroupManager();
// retrieve the groups to whom a given user belongs (given the user
// identifier)
long userId;
userId = new LiferayUserManager().getUserId(userName);
LiferayUserManager liferayUserManager = GWTWorkspaceSharingBuilder.getLiferayUserManager();
long userId = liferayUserManager.getUserId(userName);
GroupManager groupManager = GWTWorkspaceSharingBuilder.getGroupManager();
List<GCubeGroup> listOfGroups = groupManager.listGroupsByUser(userId);
List<GCubeGroup> vres = new ArrayList<GCubeGroup>();
for (GCubeGroup g : listOfGroups) {
if (groupManager.isVRE(g.getGroupId())) {

View File

@ -1,64 +0,0 @@
package org.gcube.portlets.widgets.workspacesharingwidget.shared;
import java.io.Serializable;
public class GGroup implements Serializable {
private static final long serialVersionUID = 1L;
private long groupId;
private long parentGroupId;
private String groupName;
private String description;
public GGroup() {
super();
}
public GGroup(long groupId, long parentGroupId, String groupName, String description) {
super();
this.groupId = groupId;
this.parentGroupId = parentGroupId;
this.groupName = groupName;
this.description = description;
}
public long getGroupId() {
return groupId;
}
public void setGroupId(long groupId) {
this.groupId = groupId;
}
public long getParentGroupId() {
return parentGroupId;
}
public void setParentGroupId(long parentGroupId) {
this.parentGroupId = parentGroupId;
}
public String getGroupName() {
return groupName;
}
public void setGroupName(String groupName) {
this.groupName = groupName;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
@Override
public String toString() {
return "GGroup [groupId=" + groupId + ", parentGroupId=" + parentGroupId + ", groupName=" + groupName
+ ", description=" + description + "]";
}
}

View File

@ -0,0 +1,85 @@
package org.gcube.portlets.widgets.workspacesharingwidget.shared;
import java.io.Serializable;
import java.util.Comparator;
import com.extjs.gxt.ui.client.data.BaseModelData;
public class UserVRE extends BaseModelData implements Serializable, Comparable<UserVRE> {
private static final long serialVersionUID = 1L;
protected static final String GROUP_ID = "groupId";
public static final String PARENT_GROUP_ID = "parentGroupId";
public static final String GROUP_NAME = "groupName";
public static final String GROUP_DESCRIPTION = "groupDescription";
public UserVRE() {
super();
}
public UserVRE(long groupId, long parentGroupId, String groupName, String description) {
super();
setGroupId(groupId);
setParentGroupId(parentGroupId);
setGroupName(groupName);
setDescription(description);
}
public long getGroupId() {
return get(GROUP_ID);
}
public void setGroupId(long groupId) {
set(GROUP_ID, groupId);
}
public long getParentGroupId() {
return get(PARENT_GROUP_ID);
}
public void setParentGroupId(long parentGroupId) {
set(PARENT_GROUP_ID, parentGroupId);
}
public String getGroupName() {
return get(GROUP_NAME);
}
public void setGroupName(String groupName) {
set(GROUP_NAME, groupName);
}
public String getDescription() {
return get(GROUP_DESCRIPTION);
}
public void setDescription(String description) {
set(GROUP_DESCRIPTION, description);
}
public static Comparator<UserVRE> COMPARATOR_USER_VRE = new Comparator<UserVRE>() {
public int compare(UserVRE o1, UserVRE o2) {
return (o1.getGroupId() < o2.getGroupId()) ? -1 : ((o1.getGroupId() == o2.getGroupId()) ? 0 : 1);
}
};
@Override
public int compareTo(UserVRE o) {
return UserVRE.COMPARATOR_USER_VRE.compare(this, o);
}
@Override
public boolean equals(Object obj) {
int compare = compareTo((UserVRE) obj);
return compare == 0 ? true : false;
}
@Override
public String toString() {
return "UserGroup [getGroupId()=" + getGroupId() + ", getParentGroupId()=" + getParentGroupId()
+ ", getGroupName()=" + getGroupName() + ", getDescription()=" + getDescription() + "]";
}
}

View File

@ -7,7 +7,6 @@ public class VRE extends ResearchEnvironment implements Serializable {
public VRE() {
super();
// TODO Auto-generated constructor stub
}
public VRE(String vreName, String description, String imageURL,

View File

@ -31,5 +31,13 @@
<!-- Specify the paths for translatable code -->
<source path='client' />
<source path='shared' />
<!-- <inherits name="com.google.gwt.logging.Logging" /> -->
<!-- <set-property name="gwt.logging.logLevel" value="SEVERE" /> -->
<!-- <set-property name="gwt.logging.enabled" value="TRUE" /> -->
<!-- <set-property name="gwt.logging.consoleHandler" value="ENABLED"/> -->
<!-- <set-property name="gwt.logging.firebugHandler" value="ENABLED" /> -->
<!-- <set-property name="gwt.logging.popupHandler" value="ENABLED" /> -->
</module>