diff --git a/distro/changelog.xml b/distro/changelog.xml index eeefdee..7b1cbf3 100644 --- a/distro/changelog.xml +++ b/distro/changelog.xml @@ -1,4 +1,8 @@ + + Added regex in order to remove list of chars when renaming or creating new item. It is different for folder and item name + [Feature #5207] Integrate Image Preview Widget diff --git a/pom.xml b/pom.xml index 106a515..0b7c743 100644 --- a/pom.xml +++ b/pom.xml @@ -10,7 +10,7 @@ org.gcube.portlets.user workspace-tree-widget - 6.17.0-SNAPSHOT + 6.17.1-SNAPSHOT gCube Workspace Tree Widget gCube Workspace Tree Widget is a widget to navigate and interact with gCube Workspace diff --git a/src/main/java/org/gcube/portlets/user/workspace/client/AppControllerExplorer.java b/src/main/java/org/gcube/portlets/user/workspace/client/AppControllerExplorer.java index 92496ce..aa420ea 100644 --- a/src/main/java/org/gcube/portlets/user/workspace/client/AppControllerExplorer.java +++ b/src/main/java/org/gcube/portlets/user/workspace/client/AppControllerExplorer.java @@ -1215,7 +1215,7 @@ public class AppControllerExplorer implements EventHandler, TreeAppControllerInt private void doRenameItem(final RenameItemEvent event) { final FileModel target = event.getFileTarget(); - final DialogText dgt = new DialogText(ConstantsExplorer.MESSAGE_RENAME, ConstantsExplorer.MESSAGE_ITEM_NAME, event.getFileTarget().getName()); + final DialogText dgt = new DialogText(ConstantsExplorer.MESSAGE_RENAME, ConstantsExplorer.MESSAGE_ITEM_NAME, event.getFileTarget().getName(), target.isDirectory()); dgt.getButtonById(Dialog.OK).addListener(Events.Select, new Listener() { diff --git a/src/main/java/org/gcube/portlets/user/workspace/client/ConstantsExplorer.java b/src/main/java/org/gcube/portlets/user/workspace/client/ConstantsExplorer.java index ef420ec..108100a 100644 --- a/src/main/java/org/gcube/portlets/user/workspace/client/ConstantsExplorer.java +++ b/src/main/java/org/gcube/portlets/user/workspace/client/ConstantsExplorer.java @@ -92,7 +92,7 @@ public class ConstantsExplorer { public static final String NUMREQUESTS = "numrequests"; public static final String MESSAGE_WEBDAV_URL = "View Url WebDAV "; public static final String URL_WEBDAV = "WebDAV URL"; - public static final String REGEX_FOLDER_NAME = "Field name must not begin with one of the following characters"; + public static final String MESSAGE_SEARCH_FORCE_APHANUMERIC = "Field search must be alphanumeric and not contain special chars!"; public static final String MESSAGE_CREATE_NEW_MESSAGE = "Create New Message"; @@ -106,6 +106,12 @@ public class ConstantsExplorer { protected static final String UNSHARING = "Unsharing..."; public static final String FILEUPLOADHEADER = "File upload in: "; + + public static final String REGEX_TO_WSITEM_NAME = "[^\\[\\]<>\\|?/*%$\\\\:]*$"; + public static final String REGEX_TO_WSFOLDER_NAME = "[^.\\[\\]<>\\|?/*%$\\\\:]*$"; + public static final String REGEX_WSITEM_NAME_ALERT_MSG = "Field name must not contain: <>[]:\\|?/*%$ or contains / or \\"; + public static final String REGEX_WSFOLDER_NAME_ALERT_MSG = "Folder name must not contain: .<>[]:\\|?/*%$ or contains / or \\"; + // public static final String FILE = "File"; // public static final String ARCHIVE = "Archive"; diff --git a/src/main/java/org/gcube/portlets/user/workspace/client/view/sharing/DialogShareFolder.java b/src/main/java/org/gcube/portlets/user/workspace/client/view/sharing/DialogShareFolder.java index d1d97a7..989a78a 100644 --- a/src/main/java/org/gcube/portlets/user/workspace/client/view/sharing/DialogShareFolder.java +++ b/src/main/java/org/gcube/portlets/user/workspace/client/view/sharing/DialogShareFolder.java @@ -35,11 +35,12 @@ import com.google.gwt.user.client.ui.Label; + /** * The Class DialogShareFolder. * * @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it - * Jun 6, 2017 + * Jul 10, 2017 */ public class DialogShareFolder extends Dialog { @@ -81,6 +82,8 @@ public class DialogShareFolder extends Dialog { 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(); txtOwner.setAllowBlank(true); @@ -335,8 +338,9 @@ public class DialogShareFolder extends Dialog { txtName.setAllowBlank(false); txtName.setAutoValidate(true); txtName.setFieldLabel("Folder Name"); - txtName.getMessages().setRegexText(ConstantsExplorer.REGEX_FOLDER_NAME+": .<>\\|?/*%$ or contains / or \\"); - txtName.setRegex("^[^.<>\\|?/*%$]+[^\\/]*$"); + 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); @@ -533,7 +537,7 @@ public class DialogShareFolder extends Dialog { * @return the name */ public String getName() { - return txtName.getValue(); + return txtName.getValue().trim(); } /** diff --git a/src/main/java/org/gcube/portlets/user/workspace/client/view/windows/DialogAddFolderAndSmart.java b/src/main/java/org/gcube/portlets/user/workspace/client/view/windows/DialogAddFolderAndSmart.java index 7ae7af9..09b89b2 100644 --- a/src/main/java/org/gcube/portlets/user/workspace/client/view/windows/DialogAddFolderAndSmart.java +++ b/src/main/java/org/gcube/portlets/user/workspace/client/view/windows/DialogAddFolderAndSmart.java @@ -1,3 +1,4 @@ + package org.gcube.portlets.user.workspace.client.view.windows; import org.gcube.portlets.user.workspace.client.ConstantsExplorer; @@ -15,144 +16,148 @@ 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; - /** - * @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it + * The Class DialogAddFolderAndSmart. * + * @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it Jul 10, 2017 */ public class DialogAddFolderAndSmart extends Dialog { - + + /** + * + */ private int widthDialog = 500; private int heightTextArea = 150; private TextField txtName; private TextArea textAreaDescription = new TextArea(); - public enum AddType {FOLDER, SMARTFOLDER}; - + /** + * The Enum AddType. + * + * @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it Jul 10, + * 2017 + */ + public enum AddType { + FOLDER, SMARTFOLDER + }; + + /** + * Instantiates a new dialog add folder and smart. + * + * @param headerTitle + * the header title + * @param type + * the type + */ public DialogAddFolderAndSmart(String headerTitle, AddType type) { - - FormLayout layout = new FormLayout(); - layout.setLabelWidth(90); - layout.setDefaultWidth(300); - setLayout(layout); - setButtonAlign(HorizontalAlignment.CENTER); -// setHideOnButtonClick(true); -// setIcon(IconHelper.createStyle("user")); - if(type.equals(AddType.FOLDER)){ - setHeading(ConstantsExplorer.MESSAGE_ADD_FOLDER_IN + " "+ headerTitle); - setIcon(Resources.getIconAddFolder()); - } - else{ - setHeading(ConstantsExplorer.MESSAGE_ADD_SMART_FOLDER + " "+ headerTitle); - setIcon(Resources.getIconStar()); - } - setModal(true); -// setBodyBorder(true); - setBodyStyle("padding: 9px; background: none"); - setWidth(widthDialog); - setResizable(false); - setButtons(Dialog.OKCANCEL); -// this.getButtonById(Dialog.CANCEL).setText("Reset"); - - txtName = new TextField(); - txtName.setAllowBlank(false); -// txtName.setRegex("^[a-zA-Z0-9]+[ ]*[a-zA-Z0-9_-]+$"); -// txtName.setRegex("^[a-zA-Z0-9_]+[-]*[a-zA-Z0-9_\\s]*$"); - -// txtName.setRegex("^[a-zA-Z0-9]+[^.<>\\|?/*%$]*$"); - - txtName.setAutoValidate(true); - txtName.getMessages().setRegexText(ConstantsExplorer.REGEX_FOLDER_NAME+": .<>\\|?/*%$ or contains / or \\"); - txtName.setRegex("^[^.<>\\|?/*%$]+[^\\/]*$"); + FormLayout layout = new FormLayout(); + layout.setLabelWidth(90); + layout.setDefaultWidth(300); + setLayout(layout); + setButtonAlign(HorizontalAlignment.CENTER); + // setHideOnButtonClick(true); + // setIcon(IconHelper.createStyle("user")); + if (type.equals(AddType.FOLDER)) { + setHeading(ConstantsExplorer.MESSAGE_ADD_FOLDER_IN + " " + + headerTitle); + setIcon(Resources.getIconAddFolder()); + } + else { + setHeading(ConstantsExplorer.MESSAGE_ADD_SMART_FOLDER + " " + + headerTitle); + setIcon(Resources.getIconStar()); + } + setModal(true); + // setBodyBorder(true); + setBodyStyle("padding: 9px; background: none"); + setWidth(widthDialog); + setResizable(false); + setButtons(Dialog.OKCANCEL); + // this.getButtonById(Dialog.CANCEL).setText("Reset"); + txtName = new TextField(); + txtName.setAllowBlank(false); + // txtName.setRegex("^[a-zA-Z0-9]+[ ]*[a-zA-Z0-9_-]+$"); + // txtName.setRegex("^[a-zA-Z0-9_]+[-]*[a-zA-Z0-9_\\s]*$"); + // txtName.setRegex("^[a-zA-Z0-9]+[^.<>\\|?/*%$]*$"); + txtName.setAutoValidate(true); + txtName.getMessages().setRegexText(ConstantsExplorer.REGEX_WSFOLDER_NAME_ALERT_MSG); + txtName.setRegex(ConstantsExplorer.REGEX_TO_WSFOLDER_NAME); + // txt.setMinLength(2); + txtName.setFieldLabel(ConstantsExplorer.DIALOG_NAME); + // txtName.setValue(msgTxt); + textAreaDescription.setFieldLabel(ConstantsExplorer.DIALOG_DESCRIPTION); + textAreaDescription.setHeight(heightTextArea); + // textAreaDescription.setAllowBlank(false); + // formData = new FormData("-20"); + // vp = new VerticalPanel(); + // vp.setSpacing(10); + txtName.addKeyListener(new KeyListener() { // KEY ENTER -// txt.setMinLength(2); - txtName.setFieldLabel(ConstantsExplorer.DIALOG_NAME); -// txtName.setValue(msgTxt); - - textAreaDescription.setFieldLabel(ConstantsExplorer.DIALOG_DESCRIPTION); - textAreaDescription.setHeight(heightTextArea); -// textAreaDescription.setAllowBlank(false); - -// formData = new FormData("-20"); -// vp = new VerticalPanel(); -// vp.setSpacing(10); - - - - txtName.addKeyListener(new KeyListener() { // KEY ENTER - public void componentKeyPress(ComponentEvent event) { - if (event.getKeyCode() == KeyboardEvents.Enter.getEventCode()) + + if (event.getKeyCode() == KeyboardEvents.Enter.getEventCode()) getButtonById(Dialog.OK).fireEvent(Events.Select); - } }); - - - this.getButtonById(Dialog.CANCEL).addSelectionListener(new SelectionListener() { + this.getButtonById(Dialog.CANCEL).addSelectionListener( + new SelectionListener() { - @Override - public void componentSelected(ButtonEvent ce) { -// txtName.reset(); -// textAreaDescription.reset(); - - hide(); - } - }); - - - this.getButtonById(Dialog.OK).addSelectionListener(new SelectionListener() { + @Override + public void componentSelected(ButtonEvent ce) { - @Override - public void componentSelected(ButtonEvent ce) { - if(isValidForm()) + // txtName.reset(); + // textAreaDescription.reset(); hide(); - } - }); - - setFocusWidget(txtName); - add(txtName); + } + }); + this.getButtonById(Dialog.OK).addSelectionListener( + new SelectionListener() { + + @Override + public void componentSelected(ButtonEvent ce) { + + if (isValidForm()) + hide(); + } + }); + setFocusWidget(txtName); + add(txtName); add(textAreaDescription); - - this.show(); + this.show(); } - + /** + * Gets the name. + * + * @return the name + */ public String getName() { - return txtName.getValue(); + + return txtName.getValue().trim(); } + /** + * Gets the description. + * + * @return the description + */ public String getDescription() { - if(textAreaDescription.getValue()==null) + + if (textAreaDescription.getValue() == null) return ""; - return textAreaDescription.getValue(); } -// private boolean isValidUrl(){ -// -// try { -// URL url = new URL(txtUrl.getValue()); -// URLConnection conn = url.openConnection(); -// conn.connect(); -// } catch (MalformedURLException e) { -// System.out.println(ConstantsExplorer.ERRORURLNOTREACHABLE); -// return false; -// } catch (IOException e) { -// System.out.println(ConstantsExplorer.ERRORURLNOTREACHABLE); -// return false; -// } -// -// return true; -// } - - public boolean isValidForm(){ - - if(txtName.isValid() && txtName.getValue() != null) + /** + * Checks if is valid form. + * + * @return true, if is valid form + */ + public boolean isValidForm() { + + if (txtName.isValid() && txtName.getValue() != null) return true; - return false; - } } diff --git a/src/main/java/org/gcube/portlets/user/workspace/client/view/windows/DialogText.java b/src/main/java/org/gcube/portlets/user/workspace/client/view/windows/DialogText.java index 4113b81..bce5876 100644 --- a/src/main/java/org/gcube/portlets/user/workspace/client/view/windows/DialogText.java +++ b/src/main/java/org/gcube/portlets/user/workspace/client/view/windows/DialogText.java @@ -13,15 +13,27 @@ import com.extjs.gxt.ui.client.widget.Dialog; import com.extjs.gxt.ui.client.widget.form.TextField; import com.extjs.gxt.ui.client.widget.layout.FormLayout; + /** - * @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it + * The Class DialogText. * + * @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it + * Jul 10, 2017 */ public class DialogText extends Dialog { private TextField txt; - public DialogText(String headingTxt, String msgTitle, String msgTxt) { + + /** + * Instantiates a new dialog text. + * + * @param headingTxt the heading txt + * @param msgTitle the msg title + * @param msgTxt the msg txt + * @param isFolder the is folder + */ + public DialogText(String headingTxt, String msgTitle, String msgTxt, boolean isFolder) { FormLayout layout = new FormLayout(); layout.setLabelWidth(90); @@ -43,17 +55,24 @@ public class DialogText extends Dialog { txt.setValue(msgTxt); // txt.setRegex("^[a-zA-Z0-9]+[ a-zA-Z0-9_()-]*"); // txt.setRegex("^[a-zA-Z0-9]+[^.<>\\|?/*%$]*$"); - txt.getMessages().setRegexText(ConstantsExplorer.REGEX_FOLDER_NAME+": .<>\\|?/*%$ or contains / or \\"); - txt.setRegex("^[^.<>\\|?/*%$]+[^\\/]*$"); + + if(isFolder){ + txt.getMessages().setRegexText(ConstantsExplorer.REGEX_WSFOLDER_NAME_ALERT_MSG); + txt.setRegex(ConstantsExplorer.REGEX_TO_WSFOLDER_NAME); + }else{ + txt.getMessages().setRegexText(ConstantsExplorer.REGEX_WSITEM_NAME_ALERT_MSG); + txt.setRegex(ConstantsExplorer.REGEX_TO_WSITEM_NAME); + } + txt.setAutoValidate(true); txt.setAllowBlank(false); - + txt.addKeyListener(new KeyListener() { // KEY ENTER - + public void componentKeyPress(ComponentEvent event) { - if (event.getKeyCode() == KeyboardEvents.Enter.getEventCode()) + if (event.getKeyCode() == KeyboardEvents.Enter.getEventCode()) getButtonById(Dialog.OK).fireEvent(Events.Select); - + } }); @@ -66,7 +85,7 @@ public class DialogText extends Dialog { } }); - + this.getButtonById(Dialog.CANCEL).addSelectionListener(new SelectionListener() { @Override @@ -80,16 +99,33 @@ public class DialogText extends Dialog { this.show(); } + + /** + * Gets the txt value. + * + * @return the txt value + */ public String getTxtValue() { - return txt.getValue(); + return txt.getValue().trim(); } + /** + * Checks for value. + * + * @param field the field + * @return true, if successful + */ protected boolean hasValue(TextField field) { return field.getValue() != null && field.getValue().length() > 0; } + /** + * Checks if is valid form. + * + * @return true, if is valid form + */ public boolean isValidForm() { if(txt.isValid()) return true;