2017-07-10 12:51:17 +02:00
|
|
|
|
2013-02-06 15:40:17 +01:00
|
|
|
package org.gcube.portlets.user.workspace.client.view.windows;
|
|
|
|
|
|
|
|
import org.gcube.portlets.user.workspace.client.ConstantsExplorer;
|
|
|
|
import org.gcube.portlets.user.workspace.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.ComponentEvent;
|
|
|
|
import com.extjs.gxt.ui.client.event.Events;
|
|
|
|
import com.extjs.gxt.ui.client.event.KeyListener;
|
|
|
|
import com.extjs.gxt.ui.client.event.KeyboardEvents;
|
|
|
|
import com.extjs.gxt.ui.client.event.SelectionListener;
|
|
|
|
import com.extjs.gxt.ui.client.widget.Dialog;
|
|
|
|
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;
|
|
|
|
|
|
|
|
/**
|
2017-07-10 12:51:17 +02:00
|
|
|
* The Class DialogAddFolderAndSmart.
|
2013-02-06 15:40:17 +01:00
|
|
|
*
|
2019-02-22 14:40:20 +01:00
|
|
|
* @author Francesco Mangiacrapa francesco.mangiacrapa{@literal @}isti.cnr.it Jul 10, 2017
|
2013-02-06 15:40:17 +01:00
|
|
|
*/
|
|
|
|
public class DialogAddFolderAndSmart extends Dialog {
|
2017-07-10 12:51:17 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
*/
|
2013-02-06 15:40:17 +01:00
|
|
|
private int widthDialog = 500;
|
|
|
|
private int heightTextArea = 150;
|
|
|
|
private TextField<String> txtName;
|
|
|
|
private TextArea textAreaDescription = new TextArea();
|
|
|
|
|
2017-07-10 12:51:17 +02:00
|
|
|
/**
|
|
|
|
* The Enum AddType.
|
|
|
|
*
|
2019-02-22 14:40:20 +01:00
|
|
|
* @author Francesco Mangiacrapa francesco.mangiacrapa{@literal @}isti.cnr.it Jul 10,
|
2017-07-10 12:51:17 +02:00
|
|
|
* 2017
|
|
|
|
*/
|
|
|
|
public enum AddType {
|
|
|
|
FOLDER, SMARTFOLDER
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Instantiates a new dialog add folder and smart.
|
|
|
|
*
|
|
|
|
* @param headerTitle
|
|
|
|
* the header title
|
|
|
|
* @param type
|
|
|
|
* the type
|
|
|
|
*/
|
2013-02-06 15:40:17 +01:00
|
|
|
public DialogAddFolderAndSmart(String headerTitle, AddType type) {
|
2017-07-10 12:51:17 +02:00
|
|
|
|
|
|
|
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<String>();
|
|
|
|
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
|
|
|
|
|
2013-02-06 15:40:17 +01:00
|
|
|
public void componentKeyPress(ComponentEvent event) {
|
2017-07-10 12:51:17 +02:00
|
|
|
|
|
|
|
if (event.getKeyCode() == KeyboardEvents.Enter.getEventCode())
|
2013-02-06 15:40:17 +01:00
|
|
|
getButtonById(Dialog.OK).fireEvent(Events.Select);
|
|
|
|
}
|
|
|
|
});
|
2017-07-10 12:51:17 +02:00
|
|
|
this.getButtonById(Dialog.CANCEL).addSelectionListener(
|
|
|
|
new SelectionListener<ButtonEvent>() {
|
2013-02-06 15:40:17 +01:00
|
|
|
|
2017-07-10 12:51:17 +02:00
|
|
|
@Override
|
|
|
|
public void componentSelected(ButtonEvent ce) {
|
|
|
|
|
|
|
|
// txtName.reset();
|
|
|
|
// textAreaDescription.reset();
|
2013-02-06 15:40:17 +01:00
|
|
|
hide();
|
2017-07-10 12:51:17 +02:00
|
|
|
}
|
|
|
|
});
|
|
|
|
this.getButtonById(Dialog.OK).addSelectionListener(
|
|
|
|
new SelectionListener<ButtonEvent>() {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void componentSelected(ButtonEvent ce) {
|
|
|
|
|
|
|
|
if (isValidForm())
|
|
|
|
hide();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
setFocusWidget(txtName);
|
|
|
|
add(txtName);
|
2013-02-06 15:40:17 +01:00
|
|
|
add(textAreaDescription);
|
2017-07-10 12:51:17 +02:00
|
|
|
this.show();
|
2013-02-06 15:40:17 +01:00
|
|
|
}
|
|
|
|
|
2017-07-10 12:51:17 +02: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
|
|
|
}
|
|
|
|
|
2017-07-10 12:51:17 +02:00
|
|
|
/**
|
|
|
|
* Gets the description.
|
|
|
|
*
|
|
|
|
* @return the description
|
|
|
|
*/
|
2013-02-06 15:40:17 +01:00
|
|
|
public String getDescription() {
|
2017-07-10 12:51:17 +02:00
|
|
|
|
|
|
|
if (textAreaDescription.getValue() == null)
|
2013-02-06 15:40:17 +01:00
|
|
|
return "";
|
|
|
|
return textAreaDescription.getValue();
|
|
|
|
}
|
|
|
|
|
2017-07-10 12:51:17 +02:00
|
|
|
/**
|
|
|
|
* Checks if is valid form.
|
|
|
|
*
|
|
|
|
* @return true, if is valid form
|
|
|
|
*/
|
|
|
|
public boolean isValidForm() {
|
|
|
|
|
|
|
|
if (txtName.isValid() && txtName.getValue() != null)
|
2013-02-06 15:40:17 +01:00
|
|
|
return true;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|