Added regex in order to remove list of chars when renaming or creating new item. It is different for folder and item name

Updated pom version at 6.17.1

git-svn-id: http://svn.d4science-ii.research-infrastructures.eu/gcube/trunk/portlets/user/workspace-tree-widget@150974 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Francesco Mangiacrapa 2017-07-10 10:51:17 +00:00
parent 3a8697659e
commit ac1e018c9a
7 changed files with 179 additions and 124 deletions

View File

@ -1,4 +1,8 @@
<ReleaseNotes> <ReleaseNotes>
<Changeset component="org.gcube.portlets-user.workspace-portlet-tree.6-17-1"
date="2017-07-10">
<Change>Added regex in order to remove list of chars when renaming or creating new item. It is different for folder and item name</Change>
</Changeset>
<Changeset component="org.gcube.portlets-user.workspace-portlet-tree.6-17-0" <Changeset component="org.gcube.portlets-user.workspace-portlet-tree.6-17-0"
date="2017-05-22"> date="2017-05-22">
<Change>[Feature #5207] Integrate Image Preview Widget</Change> <Change>[Feature #5207] Integrate Image Preview Widget</Change>

View File

@ -10,7 +10,7 @@
<groupId>org.gcube.portlets.user</groupId> <groupId>org.gcube.portlets.user</groupId>
<artifactId>workspace-tree-widget</artifactId> <artifactId>workspace-tree-widget</artifactId>
<version>6.17.0-SNAPSHOT</version> <version>6.17.1-SNAPSHOT</version>
<name>gCube Workspace Tree Widget</name> <name>gCube Workspace Tree Widget</name>
<description> <description>
gCube Workspace Tree Widget is a widget to navigate and interact with gCube Workspace gCube Workspace Tree Widget is a widget to navigate and interact with gCube Workspace

View File

@ -1215,7 +1215,7 @@ public class AppControllerExplorer implements EventHandler, TreeAppControllerInt
private void doRenameItem(final RenameItemEvent event) { private void doRenameItem(final RenameItemEvent event) {
final FileModel target = event.getFileTarget(); 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<BaseEvent>() { dgt.getButtonById(Dialog.OK).addListener(Events.Select, new Listener<BaseEvent>() {

View File

@ -92,7 +92,7 @@ public class ConstantsExplorer {
public static final String NUMREQUESTS = "numrequests"; public static final String NUMREQUESTS = "numrequests";
public static final String MESSAGE_WEBDAV_URL = "View Url WebDAV "; public static final String MESSAGE_WEBDAV_URL = "View Url WebDAV ";
public static final String URL_WEBDAV = "WebDAV URL"; 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_SEARCH_FORCE_APHANUMERIC = "Field search must be alphanumeric and not contain special chars!";
public static final String MESSAGE_CREATE_NEW_MESSAGE = "Create New Message"; public static final String MESSAGE_CREATE_NEW_MESSAGE = "Create New Message";
@ -106,6 +106,12 @@ public class ConstantsExplorer {
protected static final String UNSHARING = "Unsharing..."; protected static final String UNSHARING = "Unsharing...";
public static final String FILEUPLOADHEADER = "File upload in: "; 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 FILE = "File";
// public static final String ARCHIVE = "Archive"; // public static final String ARCHIVE = "Archive";

View File

@ -35,11 +35,12 @@ import com.google.gwt.user.client.ui.Label;
/** /**
* The Class DialogShareFolder. * The Class DialogShareFolder.
* *
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it * @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
* Jun 6, 2017 * Jul 10, 2017
*/ */
public class DialogShareFolder extends Dialog { public class DialogShareFolder extends Dialog {
@ -81,6 +82,8 @@ public class DialogShareFolder extends Dialog {
txtName.setReadOnly(true); txtName.setReadOnly(true);
txtName.setAutoValidate(true); txtName.setAutoValidate(true);
txtName.setFieldLabel("Folder Name"); 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 = new TextField<String>();
txtOwner.setAllowBlank(true); txtOwner.setAllowBlank(true);
@ -335,8 +338,9 @@ public class DialogShareFolder extends Dialog {
txtName.setAllowBlank(false); txtName.setAllowBlank(false);
txtName.setAutoValidate(true); txtName.setAutoValidate(true);
txtName.setFieldLabel("Folder Name"); txtName.setFieldLabel("Folder Name");
txtName.getMessages().setRegexText(ConstantsExplorer.REGEX_FOLDER_NAME+": .<>\\|?/*%$ or contains / or \\"); txtName.getMessages().setRegexText(ConstantsExplorer.REGEX_WSFOLDER_NAME_ALERT_MSG);
txtName.setRegex("^[^.<>\\|?/*%$]+[^\\/]*$"); txtName.setRegex(ConstantsExplorer.REGEX_TO_WSFOLDER_NAME);
// txtName.setRegex("^[^.<>\\|?/*%$]+[^\\/]*$");
textAreaDescription.setFieldLabel(ConstantsExplorer.DIALOG_DESCRIPTION); textAreaDescription.setFieldLabel(ConstantsExplorer.DIALOG_DESCRIPTION);
textAreaDescription.setHeight(heightTextArea); textAreaDescription.setHeight(heightTextArea);
@ -533,7 +537,7 @@ public class DialogShareFolder extends Dialog {
* @return the name * @return the name
*/ */
public String getName() { public String getName() {
return txtName.getValue(); return txtName.getValue().trim();
} }
/** /**

View File

@ -1,3 +1,4 @@
package org.gcube.portlets.user.workspace.client.view.windows; package org.gcube.portlets.user.workspace.client.view.windows;
import org.gcube.portlets.user.workspace.client.ConstantsExplorer; 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.form.TextField;
import com.extjs.gxt.ui.client.widget.layout.FormLayout; 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 { public class DialogAddFolderAndSmart extends Dialog {
/**
*
*/
private int widthDialog = 500; private int widthDialog = 500;
private int heightTextArea = 150; private int heightTextArea = 150;
private TextField<String> txtName; private TextField<String> txtName;
private TextArea textAreaDescription = new TextArea(); 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) { public DialogAddFolderAndSmart(String headerTitle, AddType type) {
FormLayout layout = new FormLayout();
layout.setLabelWidth(90);
layout.setDefaultWidth(300);
setLayout(layout);
setButtonAlign(HorizontalAlignment.CENTER); FormLayout layout = new FormLayout();
// setHideOnButtonClick(true); layout.setLabelWidth(90);
// setIcon(IconHelper.createStyle("user")); layout.setDefaultWidth(300);
if(type.equals(AddType.FOLDER)){ setLayout(layout);
setHeading(ConstantsExplorer.MESSAGE_ADD_FOLDER_IN + " "+ headerTitle); setButtonAlign(HorizontalAlignment.CENTER);
setIcon(Resources.getIconAddFolder()); // setHideOnButtonClick(true);
} // setIcon(IconHelper.createStyle("user"));
else{ if (type.equals(AddType.FOLDER)) {
setHeading(ConstantsExplorer.MESSAGE_ADD_SMART_FOLDER + " "+ headerTitle); setHeading(ConstantsExplorer.MESSAGE_ADD_FOLDER_IN + " " +
setIcon(Resources.getIconStar()); headerTitle);
} setIcon(Resources.getIconAddFolder());
setModal(true); }
// setBodyBorder(true); else {
setBodyStyle("padding: 9px; background: none"); setHeading(ConstantsExplorer.MESSAGE_ADD_SMART_FOLDER + " " +
setWidth(widthDialog); headerTitle);
setResizable(false); setIcon(Resources.getIconStar());
setButtons(Dialog.OKCANCEL); }
// this.getButtonById(Dialog.CANCEL).setText("Reset"); setModal(true);
// setBodyBorder(true);
txtName = new TextField<String>(); setBodyStyle("padding: 9px; background: none");
txtName.setAllowBlank(false); setWidth(widthDialog);
// txtName.setRegex("^[a-zA-Z0-9]+[ ]*[a-zA-Z0-9_-]+$"); setResizable(false);
// txtName.setRegex("^[a-zA-Z0-9_]+[-]*[a-zA-Z0-9_\\s]*$"); setButtons(Dialog.OKCANCEL);
// this.getButtonById(Dialog.CANCEL).setText("Reset");
// txtName.setRegex("^[a-zA-Z0-9]+[^.<>\\|?/*%$]*$"); txtName = new TextField<String>();
txtName.setAllowBlank(false);
txtName.setAutoValidate(true); // txtName.setRegex("^[a-zA-Z0-9]+[ ]*[a-zA-Z0-9_-]+$");
txtName.getMessages().setRegexText(ConstantsExplorer.REGEX_FOLDER_NAME+": .<>\\|?/*%$ or contains / or \\"); // txtName.setRegex("^[a-zA-Z0-9_]+[-]*[a-zA-Z0-9_\\s]*$");
txtName.setRegex("^[^.<>\\|?/*%$]+[^\\/]*$"); // 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) { public void componentKeyPress(ComponentEvent event) {
if (event.getKeyCode() == KeyboardEvents.Enter.getEventCode())
if (event.getKeyCode() == KeyboardEvents.Enter.getEventCode())
getButtonById(Dialog.OK).fireEvent(Events.Select); getButtonById(Dialog.OK).fireEvent(Events.Select);
} }
}); });
this.getButtonById(Dialog.CANCEL).addSelectionListener(
new SelectionListener<ButtonEvent>() {
this.getButtonById(Dialog.CANCEL).addSelectionListener(new SelectionListener<ButtonEvent>() {
@Override @Override
public void componentSelected(ButtonEvent ce) { public void componentSelected(ButtonEvent ce) {
// txtName.reset();
// textAreaDescription.reset();
hide();
}
});
this.getButtonById(Dialog.OK).addSelectionListener(new SelectionListener<ButtonEvent>() {
@Override // txtName.reset();
public void componentSelected(ButtonEvent ce) { // textAreaDescription.reset();
if(isValidForm())
hide(); hide();
} }
}); });
this.getButtonById(Dialog.OK).addSelectionListener(
setFocusWidget(txtName); new SelectionListener<ButtonEvent>() {
add(txtName);
@Override
public void componentSelected(ButtonEvent ce) {
if (isValidForm())
hide();
}
});
setFocusWidget(txtName);
add(txtName);
add(textAreaDescription); add(textAreaDescription);
this.show();
this.show();
} }
/**
* Gets the name.
*
* @return the name
*/
public String getName() { public String getName() {
return txtName.getValue();
return txtName.getValue().trim();
} }
/**
* Gets the description.
*
* @return the description
*/
public String getDescription() { public String getDescription() {
if(textAreaDescription.getValue()==null)
if (textAreaDescription.getValue() == null)
return ""; return "";
return textAreaDescription.getValue(); return textAreaDescription.getValue();
} }
// private boolean isValidUrl(){ /**
// * Checks if is valid form.
// try { *
// URL url = new URL(txtUrl.getValue()); * @return true, if is valid form
// URLConnection conn = url.openConnection(); */
// conn.connect(); public boolean isValidForm() {
// } catch (MalformedURLException e) {
// System.out.println(ConstantsExplorer.ERRORURLNOTREACHABLE); if (txtName.isValid() && txtName.getValue() != null)
// return false;
// } catch (IOException e) {
// System.out.println(ConstantsExplorer.ERRORURLNOTREACHABLE);
// return false;
// }
//
// return true;
// }
public boolean isValidForm(){
if(txtName.isValid() && txtName.getValue() != null)
return true; return true;
return false; return false;
} }
} }

View File

@ -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.form.TextField;
import com.extjs.gxt.ui.client.widget.layout.FormLayout; 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 { public class DialogText extends Dialog {
private TextField<String> txt; private TextField<String> 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(); FormLayout layout = new FormLayout();
layout.setLabelWidth(90); layout.setLabelWidth(90);
@ -43,17 +55,24 @@ public class DialogText extends Dialog {
txt.setValue(msgTxt); txt.setValue(msgTxt);
// txt.setRegex("^[a-zA-Z0-9]+[ a-zA-Z0-9_()-]*"); // txt.setRegex("^[a-zA-Z0-9]+[ a-zA-Z0-9_()-]*");
// txt.setRegex("^[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.setAutoValidate(true);
txt.setAllowBlank(false); txt.setAllowBlank(false);
txt.addKeyListener(new KeyListener() { // KEY ENTER txt.addKeyListener(new KeyListener() { // KEY ENTER
public void componentKeyPress(ComponentEvent event) { public void componentKeyPress(ComponentEvent event) {
if (event.getKeyCode() == KeyboardEvents.Enter.getEventCode()) if (event.getKeyCode() == KeyboardEvents.Enter.getEventCode())
getButtonById(Dialog.OK).fireEvent(Events.Select); getButtonById(Dialog.OK).fireEvent(Events.Select);
} }
}); });
@ -66,7 +85,7 @@ public class DialogText extends Dialog {
} }
}); });
this.getButtonById(Dialog.CANCEL).addSelectionListener(new SelectionListener<ButtonEvent>() { this.getButtonById(Dialog.CANCEL).addSelectionListener(new SelectionListener<ButtonEvent>() {
@Override @Override
@ -80,16 +99,33 @@ public class DialogText extends Dialog {
this.show(); this.show();
} }
/**
* Gets the txt value.
*
* @return the txt value
*/
public String getTxtValue() { 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<String> field) { protected boolean hasValue(TextField<String> field) {
return field.getValue() != null && field.getValue().length() > 0; return field.getValue() != null && field.getValue().length() > 0;
} }
/**
* Checks if is valid form.
*
* @return true, if is valid form
*/
public boolean isValidForm() { public boolean isValidForm() {
if(txt.isValid()) if(txt.isValid())
return true; return true;