2013-02-06 15:40:17 +01:00
|
|
|
package org.gcube.portlets.user.workspace.client.view.sharing;
|
|
|
|
|
|
|
|
import java.util.List;
|
|
|
|
|
2014-02-11 16:41:56 +01:00
|
|
|
import org.gcube.portlets.user.workspace.client.AppControllerExplorer;
|
2013-02-06 15:40:17 +01:00
|
|
|
import org.gcube.portlets.user.workspace.client.ConstantsExplorer;
|
2013-02-12 16:02:00 +01:00
|
|
|
import org.gcube.portlets.user.workspace.client.model.FileModel;
|
2013-02-06 15:40:17 +01:00
|
|
|
import org.gcube.portlets.user.workspace.client.resources.Resources;
|
|
|
|
import org.gcube.portlets.user.workspace.client.view.sharing.multisuggest.MultiDragContact;
|
|
|
|
import org.gcube.portlets.user.workspace.client.view.sharing.multisuggest.MultiValuePanel;
|
|
|
|
import org.gcube.portlets.user.workspace.client.view.windows.MessageBoxAlert;
|
2015-11-05 11:23:01 +01:00
|
|
|
import org.gcube.portlets.user.workspace.shared.ListContact;
|
2019-02-22 12:18:03 +01:00
|
|
|
import org.gcube.portlets.widgets.workspacesharingwidget.client.rpc.WorkspaceSharingServiceAsync;
|
|
|
|
import org.gcube.portlets.widgets.workspacesharingwidget.shared.InfoContactModel;
|
|
|
|
import org.gcube.portlets.widgets.workspacesharingwidget.shared.WorkspaceACL;
|
2013-02-06 15:40:17 +01:00
|
|
|
|
|
|
|
import com.extjs.gxt.ui.client.Style.HorizontalAlignment;
|
|
|
|
import com.extjs.gxt.ui.client.Style.Scroll;
|
2014-02-14 15:28:35 +01:00
|
|
|
import com.extjs.gxt.ui.client.Style.VerticalAlignment;
|
2013-02-06 15:40:17 +01:00
|
|
|
import com.extjs.gxt.ui.client.event.ButtonEvent;
|
|
|
|
import com.extjs.gxt.ui.client.event.SelectionListener;
|
|
|
|
import com.extjs.gxt.ui.client.widget.Dialog;
|
2014-02-14 15:28:35 +01:00
|
|
|
import com.extjs.gxt.ui.client.widget.HorizontalPanel;
|
2013-02-06 15:40:17 +01:00
|
|
|
import com.extjs.gxt.ui.client.widget.LayoutContainer;
|
|
|
|
import com.extjs.gxt.ui.client.widget.form.TextArea;
|
|
|
|
import com.extjs.gxt.ui.client.widget.form.TextField;
|
|
|
|
import com.extjs.gxt.ui.client.widget.layout.FormLayout;
|
2014-02-12 12:49:07 +01:00
|
|
|
import com.google.gwt.core.shared.GWT;
|
2013-02-06 15:40:17 +01:00
|
|
|
import com.google.gwt.event.dom.client.ClickEvent;
|
|
|
|
import com.google.gwt.event.dom.client.ClickHandler;
|
|
|
|
import com.google.gwt.event.shared.HandlerManager;
|
|
|
|
import com.google.gwt.user.client.rpc.AsyncCallback;
|
|
|
|
import com.google.gwt.user.client.ui.Button;
|
|
|
|
import com.google.gwt.user.client.ui.FlexTable;
|
|
|
|
import com.google.gwt.user.client.ui.Label;
|
|
|
|
|
|
|
|
/**
|
2015-11-05 11:23:01 +01:00
|
|
|
* The Class DialogShareFolder.
|
2013-02-06 15:40:17 +01:00
|
|
|
*
|
2019-02-22 12:37:09 +01:00
|
|
|
* @author Francesco Mangiacrapa francesco.mangiacrapaATisti.cnr.it Jul 10, 2017
|
2013-02-06 15:40:17 +01:00
|
|
|
*/
|
|
|
|
public class DialogShareFolder extends Dialog {
|
2016-05-05 11:49:36 +02:00
|
|
|
|
2015-01-28 12:42:48 +01:00
|
|
|
private int widthDialog = 535;
|
2013-02-06 15:40:17 +01:00
|
|
|
private int heightTextArea = 100;
|
|
|
|
private TextField<String> txtName;
|
|
|
|
private TextArea textAreaDescription = new TextArea();
|
2013-02-12 16:02:00 +01:00
|
|
|
private FileModel parentFolder = null;
|
2016-05-05 11:49:36 +02:00
|
|
|
private UserStore userStore;
|
|
|
|
private MultiValuePanel suggestPanel;
|
2013-02-06 15:40:17 +01:00
|
|
|
private Button buttonMultiDrag = new Button("Choose Contacts");
|
2013-02-25 19:03:53 +01:00
|
|
|
private TextField<String> txtOwner;
|
2014-02-14 15:28:35 +01:00
|
|
|
private PanelTogglePermission permission;
|
2019-02-22 12:37:09 +01:00
|
|
|
private HorizontalPanel hpPermission = null;
|
|
|
|
private InfoContactModel shareOwner = null;
|
2015-11-05 11:23:01 +01:00
|
|
|
private ListContact<InfoContactModel> listAlreadyShared = new ListContact<InfoContactModel>();
|
2013-02-06 15:40:17 +01:00
|
|
|
|
|
|
|
/**
|
2015-11-05 11:23:01 +01:00
|
|
|
* Use to modify a shared folder or share an existing folder.
|
|
|
|
*
|
2019-02-22 12:37:09 +01:00
|
|
|
* @param folderParentName
|
|
|
|
* the folder parent name
|
|
|
|
* @param folder
|
|
|
|
* the folder
|
|
|
|
* @param eventBus
|
|
|
|
* the event bus
|
|
|
|
* @param userStore
|
|
|
|
* the user store
|
2013-02-06 15:40:17 +01:00
|
|
|
*/
|
2019-02-22 12:37:09 +01:00
|
|
|
public DialogShareFolder(String folderParentName, final FileModel folder, HandlerManager eventBus,
|
|
|
|
UserStore userStore) {
|
2016-05-16 10:50:15 +02:00
|
|
|
initUserStore(userStore);
|
2013-02-06 15:40:17 +01:00
|
|
|
initLayout(folderParentName);
|
2019-02-22 12:37:09 +01:00
|
|
|
this.parentFolder = folder;
|
|
|
|
this.setIcon(Resources.getIconShareFolder());
|
|
|
|
|
|
|
|
setWidth(widthDialog);
|
|
|
|
setButtons(Dialog.OKCANCEL);
|
|
|
|
setHeading("Share folder: " + folder.getName());
|
|
|
|
|
|
|
|
txtName = new TextField<String>();
|
|
|
|
txtName.setAllowBlank(false);
|
|
|
|
txtName.setValue(folder.getName());
|
|
|
|
txtName.setReadOnly(true);
|
|
|
|
txtName.setAutoValidate(true);
|
|
|
|
txtName.setFieldLabel("Folder Name");
|
|
|
|
txtName.getMessages().setRegexText(ConstantsExplorer.REGEX_WSFOLDER_NAME_ALERT_MSG);
|
|
|
|
txtName.setRegex(ConstantsExplorer.REGEX_TO_WSFOLDER_NAME);
|
|
|
|
|
|
|
|
txtOwner = new TextField<String>();
|
|
|
|
txtOwner.setAllowBlank(true);
|
|
|
|
txtOwner.setValue("");
|
|
|
|
txtOwner.setReadOnly(true);
|
|
|
|
txtOwner.setAutoValidate(false);
|
|
|
|
txtOwner.setFieldLabel("Owner");
|
|
|
|
|
|
|
|
textAreaDescription.setFieldLabel(ConstantsExplorer.DIALOG_DESCRIPTION);
|
|
|
|
textAreaDescription.setHeight(heightTextArea);
|
|
|
|
textAreaDescription.setWidth(380);
|
|
|
|
textAreaDescription.setValue(folder.getDescription());
|
|
|
|
|
|
|
|
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("Share with users");
|
|
|
|
flexTable.setWidget(0, 0, labelShareWith);
|
|
|
|
flexTable.setWidget(0, 1, suggestPanel);
|
|
|
|
|
|
|
|
buttonMultiDrag.setStyleName("wizardButton");
|
|
|
|
|
|
|
|
flexTable.setWidget(1, 0, new Label("Add more"));
|
|
|
|
flexTable.setWidget(1, 1, buttonMultiDrag);
|
|
|
|
|
|
|
|
Label labelDescription = new Label("Description");
|
|
|
|
flexTable.setWidget(2, 0, labelDescription);
|
|
|
|
flexTable.setWidget(2, 1, textAreaDescription);
|
|
|
|
|
|
|
|
hpPermission = new HorizontalPanel();
|
|
|
|
hpPermission.setVerticalAlign(VerticalAlignment.MIDDLE);
|
|
|
|
Label labelProperty = new Label("Permissions");
|
|
|
|
hpPermission.add(labelProperty);
|
|
|
|
|
|
|
|
WorkspaceSharingServiceAsync.INSTANCE.getACLs(new AsyncCallback<List<WorkspaceACL>>() {
|
2014-02-14 15:28:35 +01:00
|
|
|
|
2015-06-12 15:42:57 +02:00
|
|
|
@Override
|
|
|
|
public void onSuccess(List<WorkspaceACL> result) {
|
|
|
|
permission = new PanelTogglePermission(result);
|
2016-05-05 11:49:36 +02:00
|
|
|
|
2019-02-22 12:37:09 +01:00
|
|
|
// ONLY IF FOLDER IS ALREADY SHARED, LOOADING CURRENT ACL FROM
|
|
|
|
// HL
|
|
|
|
if (folder.isShared())
|
2015-06-12 15:42:57 +02:00
|
|
|
selectAclForFolder(folder);
|
2016-05-05 11:49:36 +02:00
|
|
|
|
2015-06-12 15:42:57 +02:00
|
|
|
hpPermission.add(permission);
|
|
|
|
hpPermission.layout();
|
|
|
|
layout();
|
|
|
|
}
|
2014-02-11 16:41:56 +01:00
|
|
|
|
2015-06-12 15:42:57 +02:00
|
|
|
@Override
|
|
|
|
public void onFailure(Throwable caught) {
|
|
|
|
hpPermission.add(new Label("Error on recovering ACLs"));
|
|
|
|
hpPermission.layout();
|
|
|
|
layout();
|
|
|
|
}
|
|
|
|
});
|
2016-05-05 11:49:36 +02:00
|
|
|
|
2019-02-22 12:37:09 +01:00
|
|
|
lc.add(flexTable);
|
|
|
|
if (hpPermission != null)
|
|
|
|
lc.add(hpPermission);
|
2017-06-06 18:12:44 +02:00
|
|
|
|
2019-02-22 12:37:09 +01:00
|
|
|
lc.mask();
|
2016-05-05 11:49:36 +02:00
|
|
|
|
2019-02-22 12:37:09 +01:00
|
|
|
userStore.getOwner(folder.getIdentifier(), new AsyncCallback<InfoContactModel>() {
|
2013-02-25 19:03:53 +01:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onFailure(Throwable caught) {
|
2019-02-22 12:37:09 +01:00
|
|
|
txtOwner.setValue("Error on retrieving Owner");
|
2013-02-25 19:03:53 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onSuccess(InfoContactModel result) {
|
2019-02-22 12:37:09 +01:00
|
|
|
GWT.log("getOwner returned: " + result);
|
|
|
|
shareOwner = result;
|
|
|
|
if (shareOwner != null)
|
|
|
|
txtOwner.setValue(shareOwner.getName());
|
|
|
|
// IF THE FOLDER IS NOT SHARED, CHECKS PERMISSIONS
|
|
|
|
if (!folder.isShared())
|
|
|
|
permissionControl(result.getLogin(), true);
|
|
|
|
|
|
|
|
fillRecipientAlreadyShared(folder.getIdentifier(), lc);
|
2013-02-25 19:03:53 +01:00
|
|
|
}
|
2015-11-05 11:23:01 +01:00
|
|
|
|
2013-02-25 19:03:53 +01:00
|
|
|
});
|
2013-02-06 15:40:17 +01:00
|
|
|
|
2017-06-06 18:12:44 +02:00
|
|
|
AsyncCallback<List<InfoContactModel>> callback = new AsyncCallback<List<InfoContactModel>>() {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onFailure(Throwable caught) {
|
2019-02-22 12:37:09 +01:00
|
|
|
new MessageBoxAlert("Alert", "Sorry, an error occurred during on getting Managers from server", null);
|
2017-06-07 12:33:58 +02:00
|
|
|
enableFormDialog(false);
|
2017-06-06 18:12:44 +02:00
|
|
|
hpPermission.unmask();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onSuccess(List<InfoContactModel> listManagers) {
|
|
|
|
permissionControl(listManagers, true, folder);
|
|
|
|
hpPermission.unmask();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2019-02-22 12:37:09 +01:00
|
|
|
if (folder.isShared())
|
2017-06-07 12:33:58 +02:00
|
|
|
getUsersManagers(folder.getIdentifier(), callback);
|
2017-06-06 18:12:44 +02:00
|
|
|
|
2019-02-22 12:37:09 +01:00
|
|
|
setFocusWidget(suggestPanel.getBox());
|
|
|
|
add(txtName);
|
|
|
|
add(txtOwner);
|
2013-02-06 15:40:17 +01:00
|
|
|
add(lc);
|
|
|
|
addListners();
|
2019-02-22 12:37:09 +01:00
|
|
|
enableFormDialog(false); // FORM IS DISABLED BY DEFAULT
|
2016-05-05 11:49:36 +02:00
|
|
|
|
2019-02-22 12:37:09 +01:00
|
|
|
this.show();
|
2013-02-06 15:40:17 +01:00
|
|
|
}
|
2016-05-05 11:49:36 +02:00
|
|
|
|
2017-06-06 18:12:44 +02:00
|
|
|
/**
|
|
|
|
* Inits the user store.
|
|
|
|
*
|
2019-02-22 12:37:09 +01:00
|
|
|
* @param userStore
|
|
|
|
* the user store
|
2017-06-06 18:12:44 +02:00
|
|
|
*/
|
2019-02-22 12:37:09 +01:00
|
|
|
private void initUserStore(UserStore userStore) {
|
2016-05-16 10:50:15 +02:00
|
|
|
this.userStore = userStore;
|
|
|
|
this.suggestPanel = new MultiValuePanel(userStore);
|
|
|
|
}
|
|
|
|
|
2015-11-05 11:23:01 +01:00
|
|
|
/**
|
|
|
|
* Update recipient of share.
|
|
|
|
*
|
2019-02-22 12:37:09 +01:00
|
|
|
* @param listContacts
|
|
|
|
* the list contacts
|
2015-11-05 11:23:01 +01:00
|
|
|
*/
|
2019-02-22 12:37:09 +01:00
|
|
|
private void updateRecipientOfShare(List<InfoContactModel> listContacts) {
|
2015-11-05 11:23:01 +01:00
|
|
|
suggestPanel.resetItemSelected();
|
2019-02-22 12:37:09 +01:00
|
|
|
for (InfoContactModel contact : listContacts) {
|
|
|
|
if (contact != null && contact.getName() != null) {
|
|
|
|
if (!isShareOwner(contact)) // skip owner
|
2015-11-05 11:23:01 +01:00
|
|
|
suggestPanel.addRecipient(contact.getName(), true);
|
|
|
|
else
|
2019-02-22 12:37:09 +01:00
|
|
|
suggestPanel.addRecipient(contact.getName(), false); // owner
|
|
|
|
// is
|
|
|
|
// not
|
|
|
|
// deletable
|
|
|
|
}
|
2015-11-05 11:23:01 +01:00
|
|
|
}
|
|
|
|
}
|
2016-05-05 11:49:36 +02:00
|
|
|
|
2015-11-05 11:23:01 +01:00
|
|
|
/**
|
|
|
|
* Fill recipient already shared.
|
|
|
|
*
|
2019-02-22 12:37:09 +01:00
|
|
|
* @param folderId
|
|
|
|
* the folder id
|
|
|
|
* @param lc
|
|
|
|
* the lc
|
2015-11-05 11:23:01 +01:00
|
|
|
*/
|
|
|
|
private void fillRecipientAlreadyShared(String folderId, final LayoutContainer lc) {
|
2016-05-05 11:49:36 +02:00
|
|
|
|
2019-02-22 12:37:09 +01:00
|
|
|
userStore.getListSharedUserByFolderId(folderId, new AsyncCallback<List<InfoContactModel>>() {
|
2016-05-05 11:49:36 +02:00
|
|
|
|
2019-02-22 12:37:09 +01:00
|
|
|
@Override
|
|
|
|
public void onSuccess(List<InfoContactModel> listContacts) {
|
2016-05-05 11:49:36 +02:00
|
|
|
|
2019-02-22 12:37:09 +01:00
|
|
|
if (listContacts != null) {
|
|
|
|
listAlreadyShared.addAll(listContacts);
|
|
|
|
updateRecipientOfShare(listContacts);
|
2015-11-05 11:23:01 +01:00
|
|
|
}
|
2019-02-22 12:37:09 +01:00
|
|
|
lc.unmask();
|
|
|
|
}
|
2016-05-05 11:49:36 +02:00
|
|
|
|
2019-02-22 12:37:09 +01:00
|
|
|
@Override
|
|
|
|
public void onFailure(Throwable caught) {
|
|
|
|
lc.unmask();
|
|
|
|
}
|
2015-11-05 11:23:01 +01:00
|
|
|
});
|
2016-05-05 11:49:36 +02:00
|
|
|
|
2015-11-05 11:23:01 +01:00
|
|
|
}
|
2016-05-05 11:49:36 +02:00
|
|
|
|
2015-11-05 11:23:01 +01:00
|
|
|
/**
|
|
|
|
* Permission control.
|
|
|
|
*
|
2019-02-22 12:37:09 +01:00
|
|
|
* @param owner
|
|
|
|
* the owner
|
|
|
|
* @param showAlert
|
|
|
|
* the show alert
|
2015-11-05 11:23:01 +01:00
|
|
|
*/
|
2019-02-22 12:37:09 +01:00
|
|
|
private void permissionControl(String owner, boolean showAlert) {
|
|
|
|
GWT.log("Permission control compare between owner: " + owner + " and my login: "
|
|
|
|
+ AppControllerExplorer.myLogin);
|
2016-05-05 11:49:36 +02:00
|
|
|
|
2019-02-22 12:37:09 +01:00
|
|
|
if (AppControllerExplorer.myLogin.compareToIgnoreCase(owner) != 0) {
|
2014-02-12 12:49:07 +01:00
|
|
|
enableFormDialog(false);
|
2019-02-22 12:37:09 +01:00
|
|
|
if (showAlert)
|
|
|
|
new MessageBoxAlert("Permission denied",
|
|
|
|
"You have no permissions to change sharing. You are not owner of \"" + txtName.getValue()
|
|
|
|
+ "\"",
|
|
|
|
null);
|
|
|
|
} else {
|
2014-02-12 12:49:07 +01:00
|
|
|
enableFormDialog(true);
|
|
|
|
}
|
|
|
|
}
|
2016-05-05 11:49:36 +02:00
|
|
|
|
2015-11-05 11:23:01 +01:00
|
|
|
/**
|
|
|
|
* Enable form dialog.
|
|
|
|
*
|
2019-02-22 12:37:09 +01:00
|
|
|
* @param bool
|
|
|
|
* the bool
|
2015-11-05 11:23:01 +01:00
|
|
|
*/
|
2019-02-22 12:37:09 +01:00
|
|
|
private void enableFormDialog(boolean bool) {
|
|
|
|
getButtonById(Dialog.OK).setEnabled(bool);
|
|
|
|
buttonMultiDrag.setEnabled(bool);
|
|
|
|
textAreaDescription.setEnabled(bool);
|
|
|
|
if (permission != null)
|
|
|
|
permission.setEnabled(bool);
|
2015-06-12 15:42:57 +02:00
|
|
|
|
2014-02-12 12:49:07 +01:00
|
|
|
}
|
2016-05-05 11:49:36 +02:00
|
|
|
|
2015-11-05 11:23:01 +01:00
|
|
|
/**
|
|
|
|
* Gets the parent folder.
|
|
|
|
*
|
|
|
|
* @return the parent folder
|
|
|
|
*/
|
2013-02-12 16:02:00 +01:00
|
|
|
public FileModel getParentFolder() {
|
|
|
|
return parentFolder;
|
2013-02-06 15:40:17 +01:00
|
|
|
}
|
2016-05-05 11:49:36 +02:00
|
|
|
|
2015-11-05 11:23:01 +01:00
|
|
|
/**
|
|
|
|
* Inits the layout.
|
|
|
|
*
|
2019-02-22 12:37:09 +01:00
|
|
|
* @param folderParentName
|
|
|
|
* the folder parent name
|
2015-11-05 11:23:01 +01:00
|
|
|
*/
|
2019-02-22 12:37:09 +01:00
|
|
|
public void initLayout(String folderParentName) {
|
2013-02-06 15:40:17 +01:00
|
|
|
FormLayout layout = new FormLayout();
|
2019-02-22 12:37:09 +01:00
|
|
|
layout.setLabelWidth(90);
|
|
|
|
layout.setDefaultWidth(380);
|
|
|
|
setLayout(layout);
|
|
|
|
setModal(true);
|
|
|
|
setScrollMode(Scroll.AUTOY);
|
|
|
|
setBodyStyle("padding: 9px; background: none");
|
|
|
|
setWidth(widthDialog);
|
|
|
|
setHeight(ConstantsExplorer.HEIGHT_DIALOG_SHARE_FOLDER);
|
|
|
|
setResizable(true);
|
|
|
|
setButtonAlign(HorizontalAlignment.CENTER);
|
|
|
|
setButtons(Dialog.OKCANCEL);
|
2013-02-06 15:40:17 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2015-11-05 11:23:01 +01:00
|
|
|
* Use to create a new shared folder.
|
|
|
|
*
|
2019-02-22 12:37:09 +01:00
|
|
|
* @param folderParentName
|
|
|
|
* the folder parent name
|
|
|
|
* @param eventBus
|
|
|
|
* the event bus
|
|
|
|
* @param userStore
|
|
|
|
* the user store
|
2013-02-06 15:40:17 +01:00
|
|
|
*/
|
2016-05-16 10:50:15 +02:00
|
|
|
public DialogShareFolder(String folderParentName, HandlerManager eventBus, UserStore userStore) {
|
|
|
|
initUserStore(userStore);
|
2013-02-06 15:40:17 +01:00
|
|
|
initLayout(folderParentName);
|
2019-02-22 12:37:09 +01:00
|
|
|
this.setIcon(Resources.getIconSharedFolder());
|
|
|
|
setHeading("Create a new shared folder in: " + folderParentName);
|
|
|
|
setHeight(ConstantsExplorer.HEIGHT_DIALOG_SHARE_FOLDER - 25);
|
|
|
|
setWidth(widthDialog);
|
|
|
|
setButtons(Dialog.OKCANCEL);
|
|
|
|
|
|
|
|
txtName = new TextField<String>();
|
|
|
|
txtName.setAllowBlank(false);
|
|
|
|
txtName.setAutoValidate(true);
|
|
|
|
txtName.setFieldLabel("Folder Name");
|
|
|
|
txtName.getMessages().setRegexText(ConstantsExplorer.REGEX_WSFOLDER_NAME_ALERT_MSG);
|
|
|
|
txtName.setRegex(ConstantsExplorer.REGEX_TO_WSFOLDER_NAME);
|
|
|
|
// txtName.setRegex("^[^.<>\\|?/*%$]+[^\\/]*$");
|
|
|
|
|
|
|
|
textAreaDescription.setFieldLabel(ConstantsExplorer.DIALOG_DESCRIPTION);
|
|
|
|
textAreaDescription.setHeight(heightTextArea);
|
|
|
|
textAreaDescription.setWidth(380);
|
|
|
|
|
|
|
|
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 lableShareWith = new Label("Share with users");
|
|
|
|
flexTable.setWidget(0, 0, lableShareWith);
|
|
|
|
flexTable.setWidget(0, 1, suggestPanel);
|
|
|
|
|
|
|
|
buttonMultiDrag.setStyleName("wizardButton");
|
|
|
|
|
|
|
|
flexTable.setWidget(1, 0, new Label("Add more"));
|
|
|
|
flexTable.setWidget(1, 1, buttonMultiDrag);
|
|
|
|
|
|
|
|
Label labelDescription = new Label("Description");
|
|
|
|
flexTable.setWidget(2, 0, labelDescription);
|
|
|
|
flexTable.setWidget(2, 1, textAreaDescription);
|
|
|
|
|
|
|
|
hpPermission = new HorizontalPanel();
|
|
|
|
hpPermission.setVerticalAlign(VerticalAlignment.MIDDLE);
|
|
|
|
Label labelProperty = new Label("Permissions");
|
|
|
|
hpPermission.add(labelProperty);
|
|
|
|
|
|
|
|
WorkspaceSharingServiceAsync.INSTANCE.getACLs(new AsyncCallback<List<WorkspaceACL>>() {
|
2014-02-11 16:41:56 +01:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onSuccess(List<WorkspaceACL> result) {
|
2014-02-14 15:28:35 +01:00
|
|
|
permission = new PanelTogglePermission(result);
|
2014-02-17 11:15:20 +01:00
|
|
|
hpPermission.add(permission);
|
|
|
|
hpPermission.layout();
|
2014-02-14 15:28:35 +01:00
|
|
|
layout();
|
2014-02-11 16:41:56 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onFailure(Throwable caught) {
|
2014-02-17 11:15:20 +01:00
|
|
|
hpPermission.add(new Label("Error on recovering ACLs"));
|
|
|
|
hpPermission.layout();
|
2014-02-14 15:28:35 +01:00
|
|
|
layout();
|
2014-02-11 16:41:56 +01:00
|
|
|
}
|
|
|
|
});
|
2015-06-12 15:42:57 +02:00
|
|
|
|
2019-02-22 12:37:09 +01:00
|
|
|
lc.add(flexTable);
|
|
|
|
lc.add(hpPermission);
|
2016-05-05 11:49:36 +02:00
|
|
|
|
2019-02-22 12:37:09 +01:00
|
|
|
setFocusWidget(txtName);
|
|
|
|
add(txtName);
|
2013-02-06 15:40:17 +01:00
|
|
|
add(lc);
|
2014-02-14 15:28:35 +01:00
|
|
|
|
2013-02-06 15:40:17 +01:00
|
|
|
addListners();
|
2016-05-05 11:49:36 +02:00
|
|
|
|
2019-02-22 12:37:09 +01:00
|
|
|
this.show();
|
2013-02-06 15:40:17 +01:00
|
|
|
}
|
2016-05-05 11:49:36 +02:00
|
|
|
|
2015-11-05 11:23:01 +01:00
|
|
|
/**
|
|
|
|
* Gets the shared list users.
|
|
|
|
*
|
|
|
|
* @return the shared list users
|
|
|
|
*/
|
2013-02-06 15:40:17 +01:00
|
|
|
public List<InfoContactModel> getSharedListUsers() {
|
2019-02-22 12:37:09 +01:00
|
|
|
// printSelectedUser();
|
2013-02-06 15:40:17 +01:00
|
|
|
return suggestPanel.getSelectedUser();
|
|
|
|
}
|
|
|
|
|
2015-11-05 11:23:01 +01:00
|
|
|
/**
|
|
|
|
* Adds the listners.
|
|
|
|
*/
|
2019-02-22 12:37:09 +01:00
|
|
|
public void addListners() {
|
2016-05-05 11:49:36 +02:00
|
|
|
|
2019-02-22 12:37:09 +01:00
|
|
|
this.getButtonById(Dialog.CANCEL).addSelectionListener(new SelectionListener<ButtonEvent>() {
|
2013-02-06 15:40:17 +01:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public void componentSelected(ButtonEvent ce) {
|
|
|
|
hide();
|
|
|
|
}
|
|
|
|
});
|
2016-05-05 11:49:36 +02:00
|
|
|
|
2019-02-22 12:37:09 +01:00
|
|
|
this.getButtonById(Dialog.OK).addSelectionListener(new SelectionListener<ButtonEvent>() {
|
2013-02-06 15:40:17 +01:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public void componentSelected(ButtonEvent ce) {
|
2019-02-22 12:37:09 +01:00
|
|
|
if (isValidForm(false))
|
2013-02-06 15:40:17 +01:00
|
|
|
hide();
|
|
|
|
}
|
2016-05-05 11:49:36 +02:00
|
|
|
});
|
|
|
|
|
2019-02-22 12:37:09 +01:00
|
|
|
buttonMultiDrag.addClickHandler(new ClickHandler() {
|
2016-05-05 11:49:36 +02:00
|
|
|
|
2013-02-06 15:40:17 +01:00
|
|
|
@Override
|
|
|
|
public void onClick(ClickEvent event) {
|
|
|
|
final MultiDragContact multiDrag = new MultiDragContact();
|
2013-06-12 16:30:45 +02:00
|
|
|
multiDrag.show();
|
2016-05-05 11:49:36 +02:00
|
|
|
|
2019-02-22 12:37:09 +01:00
|
|
|
List<InfoContactModel> exclusiveContacts = userStore
|
|
|
|
.getExclusiveContactsFromAllContact(suggestPanel.getSelectedUser());
|
2013-02-06 15:40:17 +01:00
|
|
|
multiDrag.addSourceContacts(exclusiveContacts);
|
2016-05-05 11:49:36 +02:00
|
|
|
|
2013-02-25 19:03:53 +01:00
|
|
|
for (InfoContactModel infoContactModel : suggestPanel.getSelectedUser()) {
|
2019-02-22 12:37:09 +01:00
|
|
|
// if(!listAlreadyShared.contains(infoContactModel))
|
|
|
|
if (!isShareOwner(infoContactModel))
|
2013-02-25 19:03:53 +01:00
|
|
|
multiDrag.addTargetContact(infoContactModel);
|
|
|
|
}
|
2016-05-05 11:49:36 +02:00
|
|
|
|
2015-11-05 11:23:01 +01:00
|
|
|
multiDrag.addAlreadySharedContacts(listAlreadyShared);
|
2016-05-05 11:49:36 +02:00
|
|
|
|
2013-02-06 15:40:17 +01:00
|
|
|
multiDrag.getButtonById(Dialog.OK).addSelectionListener(new SelectionListener<ButtonEvent>() {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void componentSelected(ButtonEvent ce) {
|
2019-02-22 12:37:09 +01:00
|
|
|
// initSuggestContacts();
|
2015-11-05 11:23:01 +01:00
|
|
|
suggestPanel.resetItemSelected();
|
2019-02-22 12:37:09 +01:00
|
|
|
// SHARE OWNER IS NULL IN CASE OF NEW SHARE
|
|
|
|
if (shareOwner != null)
|
|
|
|
suggestPanel.addRecipient(shareOwner.getName(), false);
|
2018-11-28 16:50:18 +01:00
|
|
|
|
2013-02-06 15:40:17 +01:00
|
|
|
for (InfoContactModel infoContactModel : multiDrag.getTargetListContact()) {
|
2019-02-22 12:37:09 +01:00
|
|
|
suggestPanel.addRecipient(infoContactModel.getName(), true);
|
|
|
|
}
|
2013-02-08 17:31:14 +01:00
|
|
|
suggestPanel.boxSetFocus();
|
2019-02-22 12:37:09 +01:00
|
|
|
// printSelectedUser();
|
2013-02-06 15:40:17 +01:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2016-05-05 11:49:36 +02:00
|
|
|
|
2015-11-05 11:23:01 +01:00
|
|
|
/**
|
|
|
|
* Checks if is share owner.
|
|
|
|
*
|
2019-02-22 12:37:09 +01:00
|
|
|
* @param infoContactModel
|
|
|
|
* the info contact model
|
2015-11-05 11:23:01 +01:00
|
|
|
* @return true, if is share owner
|
|
|
|
*/
|
2019-02-22 12:37:09 +01:00
|
|
|
public boolean isShareOwner(InfoContactModel infoContactModel) {
|
2015-11-05 11:23:01 +01:00
|
|
|
|
2019-02-22 12:37:09 +01:00
|
|
|
if (infoContactModel != null && shareOwner != null
|
|
|
|
&& InfoContactModel.COMPARATORLOGINS.compare(infoContactModel, shareOwner) == 0)
|
2015-11-05 11:23:01 +01:00
|
|
|
return true;
|
2016-05-05 11:49:36 +02:00
|
|
|
|
2015-11-05 11:23:01 +01:00
|
|
|
return false;
|
|
|
|
}
|
2016-05-05 11:49:36 +02:00
|
|
|
|
2015-11-05 11:23:01 +01:00
|
|
|
/**
|
|
|
|
* List already shared contains.
|
|
|
|
*
|
2019-02-22 12:37:09 +01:00
|
|
|
* @param contact
|
|
|
|
* the contact
|
2015-11-05 11:23:01 +01:00
|
|
|
* @return true, if successful
|
|
|
|
*/
|
2019-02-22 12:37:09 +01:00
|
|
|
private boolean listAlreadySharedContains(InfoContactModel contact) {
|
2016-05-05 11:49:36 +02:00
|
|
|
|
2019-02-22 12:37:09 +01:00
|
|
|
if (contact == null)
|
2013-06-07 17:32:53 +02:00
|
|
|
return false;
|
2016-05-05 11:49:36 +02:00
|
|
|
|
2013-06-07 17:32:53 +02:00
|
|
|
for (InfoContactModel ct : listAlreadyShared) {
|
2019-02-22 12:37:09 +01:00
|
|
|
if (InfoContactModel.COMPARATORLOGINS.compare(ct, contact) == 0)
|
|
|
|
// if(ct.getLogin().compareTo(contact.getLogin())==0)
|
2013-06-07 17:32:53 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
2016-05-05 11:49:36 +02:00
|
|
|
|
2019-02-22 12:37:09 +01:00
|
|
|
// DEBUG
|
2015-11-05 11:23:01 +01:00
|
|
|
/**
|
|
|
|
* Prints the selected user.
|
|
|
|
*/
|
|
|
|
@SuppressWarnings("unused")
|
2019-02-22 12:37:09 +01:00
|
|
|
private void printSelectedUser() {
|
2016-05-05 11:49:36 +02:00
|
|
|
|
2013-02-27 19:17:22 +01:00
|
|
|
System.out.println("SELETECTED USERS: ");
|
|
|
|
for (InfoContactModel contact : suggestPanel.getSelectedUser())
|
|
|
|
System.out.println(contact);
|
|
|
|
}
|
2016-05-05 11:49:36 +02:00
|
|
|
|
2015-11-05 11:23:01 +01:00
|
|
|
/**
|
|
|
|
* Inits the suggest contacts.
|
|
|
|
*/
|
|
|
|
@SuppressWarnings("unused")
|
2019-02-22 12:37:09 +01:00
|
|
|
private void initSuggestContacts() {
|
2013-02-25 19:03:53 +01:00
|
|
|
suggestPanel.resetItemSelected();
|
2015-06-12 15:42:57 +02:00
|
|
|
for (InfoContactModel contact : listAlreadyShared)
|
2013-03-11 19:06:56 +01:00
|
|
|
suggestPanel.addRecipient(contact.getName(), false);
|
2013-02-25 19:03:53 +01:00
|
|
|
}
|
2013-02-06 15:40:17 +01:00
|
|
|
|
2015-11-05 11:23:01 +01:00
|
|
|
/**
|
|
|
|
* Gets the name.
|
|
|
|
*
|
|
|
|
* @return the name
|
|
|
|
*/
|
2013-02-06 15:40:17 +01:00
|
|
|
public String getName() {
|
2017-07-10 12:51:17 +02:00
|
|
|
return txtName.getValue().trim();
|
2013-02-06 15:40:17 +01:00
|
|
|
}
|
|
|
|
|
2015-11-05 11:23:01 +01:00
|
|
|
/**
|
|
|
|
* Gets the description.
|
|
|
|
*
|
|
|
|
* @return the description
|
|
|
|
*/
|
2013-02-06 15:40:17 +01:00
|
|
|
public String getDescription() {
|
2019-02-22 12:37:09 +01:00
|
|
|
if (textAreaDescription.getValue() == null)
|
2013-02-06 15:40:17 +01:00
|
|
|
return "";
|
2016-05-05 11:49:36 +02:00
|
|
|
|
2013-02-06 15:40:17 +01:00
|
|
|
return textAreaDescription.getValue();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2015-11-05 11:23:01 +01:00
|
|
|
* Checks if is valid form.
|
|
|
|
*
|
2019-02-22 12:37:09 +01:00
|
|
|
* @param displayAlert
|
|
|
|
* the display alert
|
2015-11-05 11:23:01 +01:00
|
|
|
* @return true, if is valid form
|
2013-02-06 15:40:17 +01:00
|
|
|
*/
|
2019-02-22 12:37:09 +01:00
|
|
|
public boolean isValidForm(boolean displayAlert) {
|
2016-05-05 11:49:36 +02:00
|
|
|
|
2019-02-22 12:37:09 +01:00
|
|
|
if (!txtName.isValid()) {
|
|
|
|
if (displayAlert)
|
2013-02-06 15:40:17 +01:00
|
|
|
new MessageBoxAlert("Attention", "Name must not be empty", null);
|
|
|
|
txtName.focus();
|
|
|
|
return false;
|
|
|
|
}
|
2016-05-05 11:49:36 +02:00
|
|
|
|
2019-02-22 12:37:09 +01:00
|
|
|
if (getSharedListUsers().size() == 0) {
|
|
|
|
if (displayAlert)
|
2013-02-06 15:40:17 +01:00
|
|
|
new MessageBoxAlert("Attention", "You must pick at least one user with which share the folder", null);
|
|
|
|
suggestPanel.boxSetFocus();
|
|
|
|
return false;
|
|
|
|
}
|
2016-05-05 11:49:36 +02:00
|
|
|
|
2013-02-06 15:40:17 +01:00
|
|
|
return true;
|
2016-05-05 11:49:36 +02:00
|
|
|
|
2013-02-06 15:40:17 +01:00
|
|
|
}
|
2016-05-05 11:49:36 +02:00
|
|
|
|
2015-11-05 11:23:01 +01:00
|
|
|
/**
|
|
|
|
* Gets the selected acl.
|
|
|
|
*
|
|
|
|
* @return the selected acl
|
|
|
|
*/
|
2019-02-22 12:37:09 +01:00
|
|
|
public WorkspaceACL getSelectedACL() {
|
|
|
|
if (permission != null)
|
2014-02-11 16:41:56 +01:00
|
|
|
return permission.getSelectedACL();
|
|
|
|
return null;
|
|
|
|
}
|
2016-05-05 11:49:36 +02:00
|
|
|
|
2015-11-05 11:23:01 +01:00
|
|
|
/**
|
|
|
|
* Select acl for folder.
|
|
|
|
*
|
2019-02-22 12:37:09 +01:00
|
|
|
* @param folder
|
|
|
|
* the folder
|
2015-11-05 11:23:01 +01:00
|
|
|
*/
|
2019-02-22 12:37:09 +01:00
|
|
|
private void selectAclForFolder(FileModel folder) {
|
|
|
|
GWT.log("Loading ACL to: " + folder);
|
|
|
|
WorkspaceSharingServiceAsync.INSTANCE.getACLsForSharedFolderId(folder.getIdentifier(),
|
|
|
|
new AsyncCallback<WorkspaceACL>() {
|
2014-09-24 12:55:32 +02:00
|
|
|
|
2019-02-22 12:37:09 +01:00
|
|
|
@Override
|
|
|
|
public void onFailure(Throwable arg0) {
|
|
|
|
GWT.log("An error occurred on selecting current ACL " + arg0);
|
2016-05-05 11:49:36 +02:00
|
|
|
|
2019-02-22 12:37:09 +01:00
|
|
|
}
|
2014-09-24 12:55:32 +02:00
|
|
|
|
2019-02-22 12:37:09 +01:00
|
|
|
@Override
|
|
|
|
public void onSuccess(WorkspaceACL arg0) {
|
|
|
|
GWT.log("Loaded ACL " + arg0);
|
|
|
|
permission.selectACL(arg0);
|
|
|
|
hpPermission.layout();
|
|
|
|
layout();
|
|
|
|
}
|
|
|
|
});
|
2016-05-05 11:49:36 +02:00
|
|
|
|
2014-09-24 12:55:32 +02:00
|
|
|
}
|
|
|
|
|
2017-06-06 18:12:44 +02:00
|
|
|
/**
|
|
|
|
* Gets the users managers.
|
|
|
|
*
|
2019-02-22 12:37:09 +01:00
|
|
|
*
|
|
|
|
* @param sharedFolderId
|
|
|
|
* share folder id
|
|
|
|
* @param callback
|
|
|
|
* list of contacts
|
2017-06-06 18:12:44 +02:00
|
|
|
*/
|
2019-02-22 12:37:09 +01:00
|
|
|
public void getUsersManagers(final String sharedFolderId, final AsyncCallback<List<InfoContactModel>> callback) {
|
2017-06-06 18:12:44 +02:00
|
|
|
|
2019-02-22 12:37:09 +01:00
|
|
|
WorkspaceSharingServiceAsync.INSTANCE.getAdministratorsByFolderId(sharedFolderId,
|
|
|
|
new AsyncCallback<List<InfoContactModel>>() {
|
2017-06-06 18:12:44 +02:00
|
|
|
|
2019-02-22 12:37:09 +01:00
|
|
|
@Override
|
|
|
|
public void onFailure(Throwable arg0) {
|
|
|
|
GWT.log("an error occured in getting user managers by Id " + sharedFolderId + " "
|
|
|
|
+ arg0.getMessage());
|
|
|
|
new MessageBoxAlert("Alert",
|
|
|
|
"Sorry, an error occurred on getting users managers, try again later", null);
|
2017-06-06 18:12:44 +02:00
|
|
|
|
2019-02-22 12:37:09 +01:00
|
|
|
}
|
2017-06-06 18:12:44 +02:00
|
|
|
|
2019-02-22 12:37:09 +01:00
|
|
|
@Override
|
|
|
|
public void onSuccess(List<InfoContactModel> listManagers) {
|
|
|
|
callback.onSuccess(listManagers);
|
2017-06-06 18:12:44 +02:00
|
|
|
|
2019-02-22 12:37:09 +01:00
|
|
|
}
|
|
|
|
});
|
2017-06-06 18:12:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Permission control.
|
|
|
|
*
|
2019-02-22 12:37:09 +01:00
|
|
|
* @param listManagers
|
|
|
|
* the list managers
|
|
|
|
* @param showAlert
|
|
|
|
* the show alert
|
|
|
|
* @param folder
|
|
|
|
* the folder
|
2017-06-06 18:12:44 +02:00
|
|
|
*/
|
2019-02-22 12:37:09 +01:00
|
|
|
private void permissionControl(List<InfoContactModel> listManagers, boolean showAlert, FileModel folder) {
|
2017-06-06 18:12:44 +02:00
|
|
|
|
|
|
|
boolean permissionsOk = false;
|
|
|
|
for (InfoContactModel infoContactModel : listManagers) {
|
|
|
|
|
2019-02-22 12:37:09 +01:00
|
|
|
GWT.log("DialogPermission control compare between : " + infoContactModel.getLogin() + " and my login: "
|
|
|
|
+ AppControllerExplorer.myLogin);
|
|
|
|
if (AppControllerExplorer.myLogin.compareToIgnoreCase(infoContactModel.getLogin()) == 0) {
|
2017-06-06 18:12:44 +02:00
|
|
|
permissionsOk = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2019-02-22 12:37:09 +01:00
|
|
|
if (permissionsOk) {
|
2017-06-06 18:12:44 +02:00
|
|
|
enableFormDialog(true);
|
2019-02-22 12:37:09 +01:00
|
|
|
} else {
|
2017-06-06 18:12:44 +02:00
|
|
|
enableFormDialog(false);
|
2019-02-22 12:37:09 +01:00
|
|
|
if (showAlert)
|
|
|
|
new MessageBoxAlert("Permission denied",
|
|
|
|
"You have no permissions to change sharing. You are not manager of \"" + folder.getName()
|
|
|
|
+ "\"",
|
|
|
|
null);
|
2017-06-06 18:12:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2013-02-06 15:40:17 +01:00
|
|
|
}
|