diff --git a/pom.xml b/pom.xml
index 624ba7d..dc0440d 100644
--- a/pom.xml
+++ b/pom.xml
@@ -186,33 +186,33 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
org.gcube.portlets.widgets
@@ -220,6 +220,13 @@
[0.0.1-SNAPSHOT, 2.0.0-SNAPSHOT)
+
+ org.gcube.portlets.widgets
+ switch-button-widget
+ [1.0.0-SNAPSHOT, 2.0.0-SNAPSHOT)
+ compile
+
+
commons-httpclient
commons-httpclient
diff --git a/src/main/java/org/gcube/portlets/user/workspace/WorkspaceTree.gwt.xml b/src/main/java/org/gcube/portlets/user/workspace/WorkspaceTree.gwt.xml
index d3d6fe8..8c6db6c 100644
--- a/src/main/java/org/gcube/portlets/user/workspace/WorkspaceTree.gwt.xml
+++ b/src/main/java/org/gcube/portlets/user/workspace/WorkspaceTree.gwt.xml
@@ -31,6 +31,8 @@
+
+
{
+ }
+
+ /**
+ * Instantiates a new dialog shareable link.
+ *
+ * @param item the item
+ * @param version the version
+ */
+ public DialogShareableLink(FileModel item, String version) {
+ initWidget(uiBinder.createAndBindUi(this));
+
+ this.fileItem = item;
+ this.fileVersion = version;
+ this.actionAlert.setAnimation(true);
+
+ showShareableLinkOptions(item, version);
+ //getElement().setClassName("gwt-DialogBoxNew");
+ modalBox.setTitle("Get Shareable Link to: "+Format.ellipse(item.getName(), 15));
+ ModalFooter modalFooter = new ModalFooter();
+ final Button buttClose = new Button("Close");
+ modalFooter.add(buttClose);
+
+ switchButton.addValueChangeHandler(new ValueChangeHandler() {
+
+ @Override
+ public void onValueChange(ValueChangeEvent event) {
+
+ GWT.log("Switch to: "+event.getValue());
+ acessToFolderLink(fileItem, event.getValue());
+ }
+
+ });
+
+ buttClose.addClickHandler(new ClickHandler() {
+
+ @Override
+ public void onClick(ClickEvent event) {
+ modalBox.hide();
+ }
+ });
+
+ modalBox.add(this);
+ modalBox.add(modalFooter);
+ modalBox.show();
+
+ }
+
+ /**
+ * Show shareable link options.
+ *
+ * @param item the item
+ * @param version the version
+ */
+ public void showShareableLinkOptions(FileModel item, String version) {
+
+ //cgRemovePublicLink.setVisible(false);
+ cgPrivateLink.setVisible(false);
+ cgPublicLink.setVisible(true);
+ alertFilePublicLink.setVisible(false);
+ alertFolderPublicLink.setVisible(false);
+ filedEnableDisableSharing.setVisible(false);
+ panelFieldsContainer.setVisible(false);
+ showMessage("", false);
+ this.itemIsPublicStatus = item.isPublic();
+
+ if(item.isDirectory()) { //CASE FOLDER - MANAGING AS PUBLIC LINK TO FOLDER
+ switchButton.setValue(item.isPublic());
+ //IT IS PRIVATE LINK
+ if(item.isPublic()) { //CASE PUBLIC FOLDER
+ alertFolderPublicLink.setVisible(true);
+ //cgRemovePublicLink.setVisible(true);
+ filedEnableDisableSharing.setVisible(true);
+ labelLinkSharing.setText("Anyone with the Public Link can access to the content");
+ panelFieldsContainer.setVisible(true);
+ acessToFolderLink(item, true);
+ }
+
+ if(item.isShared()) { //CASE SHARED FOLDER
+ panelFieldsContainer.setVisible(true);
+ cgPrivateLink.setVisible(true);
+ loadAndShowPrivateLink(item, textPrivateLink);
+
+ if(!item.isPublic()) { //THE FOLDER IS NOT PUBLIC
+ cgPublicLink.setVisible(false);
+ filedEnableDisableSharing.setVisible(true);
+ labelLinkSharing.setText("");
+ //labelLinkSharing.setText("Only your cowokers (sharing members) can access to the content");
+ }
+ }
+
+ //THE FOLDER IS PRIVATE - NO SHARED AND NO PUBLIC
+ if(!item.isPublic() && !item.isShared()) {
+ filedEnableDisableSharing.setVisible(true);
+ alertFolderPublicLink.setVisible(true);
+ labelLinkSharing.setText("The folder is private, not shared");
+ }
+
+ }else { //CASE FILE - MANAGING AS PUBLIC LINK TO FILE
+ panelFieldsContainer.setVisible(true);
+ alertFilePublicLink.setVisible(true);
+ if(!item.isPublic()) { //THE FILE IS PRIVATE
+ if(version!=null && !version.isEmpty()) {
+ showPublicLinkForFileItemIdToVersion(item, textPublicLink, version);
+ }else {
+ loadAndShowPublicLinkForItem(item, textPublicLink);
+ }
+ }else {
+ //???
+ }
+ }
+
+ }
+
+
+ /**
+ * Load and show private link.
+ *
+ * @param item the item
+ * @param toTextBox the to text box
+ */
+ private void loadAndShowPrivateLink(FileModel item, TextBox toTextBox) {
+
+ String currentUrl = portalURL();
+ int lastChar = currentUrl.lastIndexOf("?");
+ currentUrl = lastChar > -1 ? currentUrl.substring(0, lastChar) : currentUrl;
+ String shareLinkUrl = currentUrl + "?" + ConstantsExplorer.GET_ITEMID_PARAMETER + "=" + item.getIdentifier();
+ shareLinkUrl += "&" + ConstantsExplorer.GET_OPERATION_PARAMETER + "=" + WsPortletInitOperation.gotofolder;
+ toTextBox.setText(shareLinkUrl);
+ }
+
+ /**
+ * Portal url.
+ *
+ * @return the string
+ */
+ public static native String portalURL()/*-{
+ return $wnd.location.href;
+ }-*/;
+
+
+
+ /**
+ * Load and show public link for item.
+ *
+ * @param item the item
+ * @param toTextBox the to text box
+ */
+ private void loadAndShowPublicLinkForItem(FileModel item, final TextBox toTextBox) {
+
+ AppControllerExplorer.rpcWorkspaceService.getPublicLinkForFileItemId(item.getIdentifier(), true,
+ new AsyncCallback() {
+
+ @Override
+ public void onSuccess(PublicLink publicLink) {
+ String toURL = publicLink.getShortURL() != null && !publicLink.getShortURL().isEmpty()
+ ? publicLink.getShortURL()
+ : publicLink.getCompleteURL();
+ toTextBox.setValue(toURL);
+ }
+
+ @Override
+ public void onFailure(Throwable caught) {
+ if (caught instanceof SessionExpiredException) {
+ GWT.log("Session expired");
+ AppControllerExplorer.getEventBus().fireEvent(new SessionExpiredEvent());
+ return;
+ }
+ //new MessageBoxAlert("Error", caught.getMessage(), null);
+ //toTextBox.setText(caught.getMessage());
+ showError(caught.getMessage());
+ }
+ });
+ }
+
+
+ /**
+ * Show public link for file item id to version.
+ *
+ * @param item the item
+ * @param toTextBox the to text box
+ * @param version the version
+ */
+ private void showPublicLinkForFileItemIdToVersion(FileModel item, final TextBox toTextBox, final String version) {
+
+ AppControllerExplorer.rpcWorkspaceService.getPublicLinkForFileItemIdToVersion(item.getIdentifier(),
+ version, true, new AsyncCallback() {
+
+ @Override
+ public void onSuccess(PublicLink publicLink) {
+ String toURL = getValidURL(publicLink);
+ toTextBox.setValue(toURL);
+ }
+
+ @Override
+ public void onFailure(Throwable caught) {
+ if (caught instanceof SessionExpiredException) {
+ GWT.log("Session expired");
+ AppControllerExplorer.getEventBus().fireEvent(new SessionExpiredEvent());
+ return;
+ }
+ //new MessageBoxAlert("Error", caught.getMessage(), null);
+ showError(caught.getMessage());
+ }
+ });
+ }
+
+ /**
+ * Show error.
+ *
+ * @param msg the msg
+ */
+ private void showError(String msg) {
+ errorAlert.setVisible(true);
+ errorAlert.setText(msg);
+ }
+
+ /**
+ * Gets the valid URL.
+ *
+ * @param publicLink the public link
+ * @return the valid URL
+ */
+ private String getValidURL(PublicLink publicLink) {
+
+ if(publicLink==null)
+ return "Error on getting a valid shareble link";
+
+ return publicLink.getShortURL() != null && !publicLink.getShortURL().isEmpty()
+ ? publicLink.getShortURL()
+ : publicLink.getCompleteURL();
+ }
+
+ /**
+ * Acess to folder link.
+ *
+ * @param item the item
+ * @param setAsPublic the set as public
+ */
+ private void acessToFolderLink(final FileModel item, final boolean setAsPublic) {
+
+ panelFieldsContainer.setVisible(false);
+
+ WorkspaceSharingServiceAsync.INSTANCE.accessToFolderLink(item.getIdentifier(),
+ new AsyncCallback() {
+
+ @Override
+ public void onFailure(Throwable caught) {
+ panelFieldsContainer.setVisible(false);
+ if (caught instanceof SessionExpiredException) {
+ GWT.log("Session expired");
+ AppControllerExplorer.getEventBus().fireEvent(new SessionExpiredEvent());
+ return;
+ }
+ showError(caught.getMessage());
+ }
+
+ @Override
+ public void onSuccess(AllowAccess result) {
+ panelFieldsContainer.setVisible(true);
+ GWT.log("AllowAccess? " + result);
+ if (result.getAccessGranted()) {
+ String msg = setAsPublic ? "Getting" : "Removing";
+ msg = msg + " Public Link... permissions granted";
+ showMessage(msg, true);
+ allowAccessToFolderLink(item.getIdentifier(), setAsPublic);
+ } else {
+ showError("Permission Denied!" + " "+result.getAccessAllowDenyMotivation());
+ }
+
+ }
+ });
+ }
+
+
+ /**
+ * Show message.
+ *
+ * @param msg the msg
+ * @param visible the visible
+ */
+ private void showMessage(String msg, boolean visible) {
+ actionAlert.setVisible(visible);
+ actionAlert.setText(msg==null?"":msg);
+
+ }
+
+ /**
+ * Allow access to folder link.
+ *
+ * @param folderId
+ * the folder id
+ * @param setIsPublic
+ * the set is public
+ */
+ protected void allowAccessToFolderLink(String folderId, final boolean setIsPublic) {
+
+ AppControllerExplorer.rpcWorkspaceService.markFolderAsPublicForFolderItemId(folderId, setIsPublic,
+ new AsyncCallback() {
+
+ @Override
+ public void onSuccess(PublicLink publicLink) {
+
+ if (!setIsPublic && publicLink == null) {
+ String msg = "Public Link to the folder '" + fileItem.getName() + "' removed correctly";
+ showMessage(msg, true);
+ AppControllerExplorer.getEventBus().fireEvent(new RefreshFolderEvent(fileItem.getParentFileModel(), true, false, false));
+
+ //REFRESHING ONLY ON CHANGING STATUS
+ if(itemIsPublicStatus) {
+ //HERE THE PREVIOUS STATUS WAS ISPUBLIC = TRUE
+ fileItem.setIsPublic(false);
+ showShareableLinkOptions(fileItem,fileVersion);
+ }
+ return;
+ }
+
+
+ textPublicLink.setValue(publicLink.getCompleteURL());
+// txtShortURL.setValue(publicLink.getShortURL());
+// selectTxt();
+
+ Timer t = new Timer() {
+ @Override
+ public void run() {
+ GWT.log("Runing refresh after wait: " + AppControllerExplorer.delayTime);
+ AppControllerExplorer.getEventBus()
+ .fireEvent(new RefreshFolderEvent(fileItem.getParentFileModel(), true, false, false));
+ }
+ };
+
+ t.schedule(AppControllerExplorer.delayTime);
+
+ showMessage("", false);
+ //REFRESHING ONLY ON CHANGING STATUS
+ if(!itemIsPublicStatus) {
+ //HERE THE PREVIOUS STATUS WAS ISPUBLIC = FALSE
+ fileItem.setIsPublic(true);
+ showShareableLinkOptions(fileItem,fileVersion);
+ }
+ }
+
+ @Override
+ public void onFailure(Throwable caught) {
+ panelFieldsContainer.setVisible(false);
+ if (caught instanceof SessionExpiredException) {
+ GWT.log("Session expired");
+ AppControllerExplorer.getEventBus().fireEvent(new SessionExpiredEvent());
+ return;
+ }
+ showError(caught.getMessage());
+ }
+ });
+ }
+}
diff --git a/src/main/java/org/gcube/portlets/user/workspace/client/view/windows/DialogShareableLink.ui.xml b/src/main/java/org/gcube/portlets/user/workspace/client/view/windows/DialogShareableLink.ui.xml
new file mode 100644
index 0000000..9d28057
--- /dev/null
+++ b/src/main/java/org/gcube/portlets/user/workspace/client/view/windows/DialogShareableLink.ui.xml
@@ -0,0 +1,109 @@
+
+
+
+ .textbox-width {
+ width: 200px;
+ }
+
+ .back-color-info {
+ background-color: #fafaff !important;
+ }
+
+ .margin-bottom-20 {
+ margin-bottom: 20px;
+ }
+
+ .padding-left-30 {
+ padding-left: 30px;
+ margin-top: 5px;
+ }
+
+ .text-bold {
+ font-weight: bold;
+ }
+
+
+
+
+
+ Link Sharing
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ By sharing
+ via Public
+ Link
+ to folder with
+ your coworkers you will
+ enact anyone
+ with the
+ link to
+ view the
+ content, no login will be
+ requested
+ By sharing a
+ Public Link
+ to
+ file your coworkers can download it.
+ No login will be
+ requested.
+ The link will always point to the version
+ of file at the
+ time of
+ public link creation
+ Public Link
+
+
+
+
+
+
+
+
+
+ By sharing via Private Link
+ with
+ your
+ coworkers you will
+ enact users (only the members belonging to the shared folder),
+ after login, to access
+ the
+ content
+ Private Link
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file