Author: ndkhoiits
Date: 2010-04-05 23:56:06 -0400 (Mon, 05 Apr 2010)
New Revision: 2479
Modified:
portal/trunk/portlet/exoadmin/src/main/java/org/exoplatform/applicationregistry/webui/component/UIGadgetEditor.java
portal/trunk/portlet/exoadmin/src/main/java/org/exoplatform/applicationregistry/webui/component/UIGadgetInfo.java
portal/trunk/portlet/exoadmin/src/main/webapp/WEB-INF/classes/locale/portlet/exoadmin/ApplicationRegistryPortlet_en.properties
portal/trunk/webui/core/src/main/java/org/exoplatform/webui/form/validator/EmailAddressValidator.java
portal/trunk/webui/core/src/main/java/org/exoplatform/webui/form/validator/ExpressionValidator.java
portal/trunk/webui/core/src/main/java/org/exoplatform/webui/form/validator/IdentifierValidator.java
portal/trunk/webui/core/src/main/java/org/exoplatform/webui/form/validator/MandatoryValidator.java
portal/trunk/webui/core/src/main/java/org/exoplatform/webui/form/validator/NameValidator.java
portal/trunk/webui/core/src/main/java/org/exoplatform/webui/form/validator/NullFieldValidator.java
portal/trunk/webui/core/src/main/java/org/exoplatform/webui/form/validator/NumberFormatValidator.java
portal/trunk/webui/core/src/main/java/org/exoplatform/webui/form/validator/PositiveNumberFormatValidator.java
portal/trunk/webui/core/src/main/java/org/exoplatform/webui/form/validator/ResourceValidator.java
portal/trunk/webui/core/src/main/java/org/exoplatform/webui/form/validator/SpecialCharacterValidator.java
Log:
GTNPORTAL-1018
-Gadget's name is unique and add a name field
-Remove bindexpression argument in some validator because it's unused in some case.
For instance, in MandatoryValidator, message EmptyFieldValidator.msg.empty-input only use
1 argument
Modified:
portal/trunk/portlet/exoadmin/src/main/java/org/exoplatform/applicationregistry/webui/component/UIGadgetEditor.java
===================================================================
---
portal/trunk/portlet/exoadmin/src/main/java/org/exoplatform/applicationregistry/webui/component/UIGadgetEditor.java 2010-04-06
03:52:26 UTC (rev 2478)
+++
portal/trunk/portlet/exoadmin/src/main/java/org/exoplatform/applicationregistry/webui/component/UIGadgetEditor.java 2010-04-06
03:56:06 UTC (rev 2479)
@@ -42,7 +42,10 @@
import org.exoplatform.webui.exception.MessageException;
import org.exoplatform.webui.form.UIForm;
import org.exoplatform.webui.form.UIFormInput;
+import org.exoplatform.webui.form.UIFormStringInput;
import org.exoplatform.webui.form.UIFormTextAreaInput;
+import org.exoplatform.webui.form.validator.ExpressionValidator;
+import org.exoplatform.webui.form.validator.IdentifierValidator;
import org.exoplatform.webui.form.validator.MandatoryValidator;
import org.exoplatform.webui.form.validator.Validator;
@@ -61,19 +64,24 @@
{
final static public String FIELD_SOURCE = "source";
+ final static public String FIELD_NAME = "name";
private Source source_;
private String fullName_;
private String dirPath;
+
+ private String gadgetName_;
public UIGadgetEditor(InitParams initParams) throws Exception
{
Param param = initParams.getParam("SampleGadget");
WebuiRequestContext context = WebuiRequestContext.getCurrentInstance();
String sample = (String)param.getMapGroovyObject(context);
- addUIFormInput(new UIFormTextAreaInput(FIELD_SOURCE, null,
sample).addValidator(MandatoryValidator.class)
+ addUIFormInput(new UIFormStringInput(FIELD_NAME, null,
null).addValidator(MandatoryValidator.class).addValidator(ExpressionValidator.class,
"^[\\p{L}][\\p{ASCII}]+$",
+ "UIGadgetEditor.msg.Invalid"));
+ addUIFormInput(new UIFormTextAreaInput(FIELD_SOURCE, FIELD_SOURCE,
sample).addValidator(MandatoryValidator.class)
.addValidator(GadgetSpecValidator.class));
}
@@ -89,6 +97,11 @@
UIFormTextAreaInput uiInputSource = getUIFormTextAreaInput(FIELD_SOURCE);
uiInputSource.setValue(source_.getTextContent());
}
+
+ public void setGadgetName(String name) {
+ UIFormStringInput uiInputName = getUIStringInput(FIELD_NAME);
+ uiInputName.setValue(name);
+ }
public String getSourceFullName()
{
@@ -103,8 +116,13 @@
public void processRender(WebuiRequestContext context) throws Exception
{
UIFormTextAreaInput uiInputSource = getUIFormTextAreaInput(FIELD_SOURCE);
+ UIFormStringInput uiInputName = getUIStringInput(FIELD_NAME);
String encoded =
StringEscapeUtils.escapeHtml(StringEscapeUtils.unescapeHtml(uiInputSource.getValue()));
uiInputSource.setValue(encoded);
+ if(this.isEdit()) {
+ uiInputName.setEditable(false);
+ }
+
super.processRender(context);
}
@@ -137,56 +155,57 @@
{
UIGadgetEditor uiForm = event.getSource();
UIGadgetManagement uiManagement = uiForm.getParent();
- String name, fileName, dirPath;
+ String gadgetName;
String text =
uiForm.getUIFormTextAreaInput(UIGadgetEditor.FIELD_SOURCE).getValue();
GadgetRegistryService service =
uiForm.getApplicationComponent(GadgetRegistryService.class);
SourceStorage sourceStorage =
uiForm.getApplicationComponent(SourceStorage.class);
- boolean isEdit = uiForm.getSource() != null;
+ boolean isEdit = uiForm.isEdit();
if (isEdit)
{
- fileName = uiForm.getSourceFullName();
- name = uiForm.getSourceName();
- dirPath = uiForm.getDirPath();
+ gadgetName = uiForm.getSourceFullName();
}
else
{
- name = "gadget" + Calendar.getInstance().hashCode();
- fileName = name + ".xml";
- dirPath = name;
+ gadgetName = uiForm.getUIStringInput(UIGadgetEditor.FIELD_NAME).getValue();
}
//
- Gadget gadget = service.getGadget(name);
- if (isEdit)
- {
- if (gadget == null)
- {
- UIApplication uiApp = event.getRequestContext().getUIApplication();
- uiApp.addMessage(new
ApplicationMessage("gadget.msg.changeNotExist", null));
- uiManagement.reload();
- return;
- }
+ Gadget gadget = service.getGadget(gadgetName);
+
+ if(isEdit) {
+ if (gadget == null)
+ {
+ UIApplication uiApp = event.getRequestContext().getUIApplication();
+ uiApp.addMessage(new
ApplicationMessage("gadget.msg.changeNotExist", null,
ApplicationMessage.WARNING));
+ uiManagement.reload();
+ return;
+ }
}
+ else {
+ // If gadget is null we need to create it first
+ if (gadget == null)
+ {
+ gadget = new Gadget();
+ gadget.setName(gadgetName);
- // If gadget is null we need to create it first
- if (gadget == null)
- {
- gadget = new Gadget();
- gadget.setName("CHANGME");
+ // Those data will be taken from the gadget XML anyway
+ gadget.setDescription("");
+ gadget.setThumbnail("");
+ gadget.setLocal(true);
+ gadget.setTitle("");
+ gadget.setReferenceUrl("");
- // Those data will be taken from the gadget XML anyway
- gadget.setDescription("");
- gadget.setThumbnail("");
- gadget.setLocal(true);
- gadget.setTitle("");
- gadget.setReferenceUrl("");
-
- // Save gadget with empty data first
- service.saveGadget(gadget);
+ // Save gadget with empty data first
+ service.saveGadget(gadget);
+ }
+ else {
+ UIApplication uiApp = event.getRequestContext().getUIApplication();
+ uiApp.addMessage(new
ApplicationMessage("UIGadgetEditor.gadget.msg.gadgetIsExist", null,
ApplicationMessage.WARNING));
+ return;
+ }
}
-
//
- Source source = new Source(fileName, "application/xml");
+ Source source = new Source(gadgetName, "application/xml");
source.setTextContent(text);
source.setLastModified(Calendar.getInstance());
@@ -202,6 +221,10 @@
}
}
+
+ private boolean isEdit() {
+ return (this.getSource() != null);
+ }
public static class CancelActionListener extends EventListener<UIGadgetEditor>
{
Modified:
portal/trunk/portlet/exoadmin/src/main/java/org/exoplatform/applicationregistry/webui/component/UIGadgetInfo.java
===================================================================
---
portal/trunk/portlet/exoadmin/src/main/java/org/exoplatform/applicationregistry/webui/component/UIGadgetInfo.java 2010-04-06
03:52:26 UTC (rev 2478)
+++
portal/trunk/portlet/exoadmin/src/main/java/org/exoplatform/applicationregistry/webui/component/UIGadgetInfo.java 2010-04-06
03:56:06 UTC (rev 2479)
@@ -160,6 +160,7 @@
// get gadget's source: path = dir path + file name
Source source = sourceStorage.getSource(gadget);
uiEditor.setSource(source);
+ uiEditor.setGadgetName(gadget.getName());
uiEditor.setDirPath(dirPath);
uiManagement.getChildren().clear();
uiManagement.addChild(uiEditor);
Modified:
portal/trunk/portlet/exoadmin/src/main/webapp/WEB-INF/classes/locale/portlet/exoadmin/ApplicationRegistryPortlet_en.properties
===================================================================
---
portal/trunk/portlet/exoadmin/src/main/webapp/WEB-INF/classes/locale/portlet/exoadmin/ApplicationRegistryPortlet_en.properties 2010-04-06
03:52:26 UTC (rev 2478)
+++
portal/trunk/portlet/exoadmin/src/main/webapp/WEB-INF/classes/locale/portlet/exoadmin/ApplicationRegistryPortlet_en.properties 2010-04-06
03:56:06 UTC (rev 2479)
@@ -139,10 +139,13 @@
UIAddGadget.label.urlError=Data in url: '{0}' is not valid
## org.exoplatform.applicationregistry.webui.component.UIGadgetEditor
-UIGadgetEditor.label.source=Source:
+UIGadgetEditor.label.source=Source:
+UIGadgetEditor.label.name=Name:
UIGadgetEditor.action.Save=#{word.save}
UIGadgetEditor.action.Cancel=#{word.cancel}
UIGadgetEditor.msg.invalidSpec=This source is invalid gadget specification.
+UIGadgetEditor.gadget.msg.gadgetIsExist=This name already exists, please enter a
different name.
+UIGadgetEditor.msg.Invalid=The "{0}" field must not contains special
characters.
##package org.exoplatform.organization.webui.component.UIListPermissionSelector
UIListPermissionSelector.header.groupId=Group
UIListPermissionSelector.header.membership=Membership
Modified:
portal/trunk/webui/core/src/main/java/org/exoplatform/webui/form/validator/EmailAddressValidator.java
===================================================================
---
portal/trunk/webui/core/src/main/java/org/exoplatform/webui/form/validator/EmailAddressValidator.java 2010-04-06
03:52:26 UTC (rev 2478)
+++
portal/trunk/webui/core/src/main/java/org/exoplatform/webui/form/validator/EmailAddressValidator.java 2010-04-06
03:56:06 UTC (rev 2479)
@@ -59,7 +59,7 @@
String s = (String)uiInput.getValue();
if (s.matches(EMAIL_REGEX))
return;
- Object[] args = {label, uiInput.getBindingField()};
+ Object[] args = {label};
throw new MessageException(new
ApplicationMessage("EmailAddressValidator.msg.Invalid-input", args,
ApplicationMessage.WARNING));
}
Modified:
portal/trunk/webui/core/src/main/java/org/exoplatform/webui/form/validator/ExpressionValidator.java
===================================================================
---
portal/trunk/webui/core/src/main/java/org/exoplatform/webui/form/validator/ExpressionValidator.java 2010-04-06
03:52:26 UTC (rev 2478)
+++
portal/trunk/webui/core/src/main/java/org/exoplatform/webui/form/validator/ExpressionValidator.java 2010-04-06
03:56:06 UTC (rev 2479)
@@ -85,7 +85,7 @@
{
label = uiInput.getName();
}
- Object[] args = {label,};
+ Object[] args = {label};
throw new MessageException(new ApplicationMessage(key_, args,
ApplicationMessage.WARNING));
}
}
Modified:
portal/trunk/webui/core/src/main/java/org/exoplatform/webui/form/validator/IdentifierValidator.java
===================================================================
---
portal/trunk/webui/core/src/main/java/org/exoplatform/webui/form/validator/IdentifierValidator.java 2010-04-06
03:52:26 UTC (rev 2478)
+++
portal/trunk/webui/core/src/main/java/org/exoplatform/webui/form/validator/IdentifierValidator.java 2010-04-06
03:56:06 UTC (rev 2479)
@@ -68,7 +68,7 @@
{
continue;
}
- Object[] args = {label, uiInput.getBindingField()};
+ Object[] args = {label};
throw new MessageException(new
ApplicationMessage("IdentifierValidator.msg.Invalid-char", args,
ApplicationMessage.WARNING));
}
Modified:
portal/trunk/webui/core/src/main/java/org/exoplatform/webui/form/validator/MandatoryValidator.java
===================================================================
---
portal/trunk/webui/core/src/main/java/org/exoplatform/webui/form/validator/MandatoryValidator.java 2010-04-06
03:52:26 UTC (rev 2478)
+++
portal/trunk/webui/core/src/main/java/org/exoplatform/webui/form/validator/MandatoryValidator.java 2010-04-06
03:56:06 UTC (rev 2479)
@@ -61,7 +61,7 @@
label = uiInput.getName();
}
label = label.trim();
- Object[] args = {label, uiInput.getBindingField()};
+ Object[] args = {label};
throw new MessageException(new
ApplicationMessage("EmptyFieldValidator.msg.empty-input", args,
ApplicationMessage.WARNING));
}
Modified:
portal/trunk/webui/core/src/main/java/org/exoplatform/webui/form/validator/NameValidator.java
===================================================================
---
portal/trunk/webui/core/src/main/java/org/exoplatform/webui/form/validator/NameValidator.java 2010-04-06
03:52:26 UTC (rev 2478)
+++
portal/trunk/webui/core/src/main/java/org/exoplatform/webui/form/validator/NameValidator.java 2010-04-06
03:56:06 UTC (rev 2479)
@@ -62,7 +62,7 @@
{
continue;
}
- Object[] args = {label, uiInput.getBindingField()};
+ Object[] args = {label};
throw new MessageException(new
ApplicationMessage("NameValidator.msg.Invalid-char", args));
}
}
Modified:
portal/trunk/webui/core/src/main/java/org/exoplatform/webui/form/validator/NullFieldValidator.java
===================================================================
---
portal/trunk/webui/core/src/main/java/org/exoplatform/webui/form/validator/NullFieldValidator.java 2010-04-06
03:52:26 UTC (rev 2478)
+++
portal/trunk/webui/core/src/main/java/org/exoplatform/webui/form/validator/NullFieldValidator.java 2010-04-06
03:56:06 UTC (rev 2479)
@@ -52,7 +52,7 @@
{
label = uiInput.getName();
}
- Object[] args = {label, uiInput.getBindingField()};
+ Object[] args = {label};
throw new MessageException(new
ApplicationMessage("EmptyFieldValidator.msg.empty-input", args));
}
}
Modified:
portal/trunk/webui/core/src/main/java/org/exoplatform/webui/form/validator/NumberFormatValidator.java
===================================================================
---
portal/trunk/webui/core/src/main/java/org/exoplatform/webui/form/validator/NumberFormatValidator.java 2010-04-06
03:52:26 UTC (rev 2478)
+++
portal/trunk/webui/core/src/main/java/org/exoplatform/webui/form/validator/NumberFormatValidator.java 2010-04-06
03:56:06 UTC (rev 2479)
@@ -61,7 +61,7 @@
{
continue;
}
- Object[] args = {label, uiInput.getBindingField()};
+ Object[] args = {label};
throw new MessageException(new
ApplicationMessage("NumberFormatValidator.msg.Invalid-number", args));
}
}
Modified:
portal/trunk/webui/core/src/main/java/org/exoplatform/webui/form/validator/PositiveNumberFormatValidator.java
===================================================================
---
portal/trunk/webui/core/src/main/java/org/exoplatform/webui/form/validator/PositiveNumberFormatValidator.java 2010-04-06
03:52:26 UTC (rev 2478)
+++
portal/trunk/webui/core/src/main/java/org/exoplatform/webui/form/validator/PositiveNumberFormatValidator.java 2010-04-06
03:56:06 UTC (rev 2479)
@@ -69,7 +69,7 @@
}
if (error == true && s.charAt(0) == '-')
{
- Object[] args = {label, uiInput.getBindingField()};
+ Object[] args = {label};
throw new MessageException(new
ApplicationMessage("PositiveNumberFormatValidator.msg.Invalid-number", args));
}
}
Modified:
portal/trunk/webui/core/src/main/java/org/exoplatform/webui/form/validator/ResourceValidator.java
===================================================================
---
portal/trunk/webui/core/src/main/java/org/exoplatform/webui/form/validator/ResourceValidator.java 2010-04-06
03:52:26 UTC (rev 2478)
+++
portal/trunk/webui/core/src/main/java/org/exoplatform/webui/form/validator/ResourceValidator.java 2010-04-06
03:56:06 UTC (rev 2479)
@@ -68,7 +68,7 @@
{
continue;
}
- Object[] args = {label, uiInput.getBindingField()};
+ Object[] args = {label};
throw new MessageException(new
ApplicationMessage("ResourceValidator.msg.Invalid-char", args,
ApplicationMessage.WARNING));
}
Modified:
portal/trunk/webui/core/src/main/java/org/exoplatform/webui/form/validator/SpecialCharacterValidator.java
===================================================================
---
portal/trunk/webui/core/src/main/java/org/exoplatform/webui/form/validator/SpecialCharacterValidator.java 2010-04-06
03:52:26 UTC (rev 2478)
+++
portal/trunk/webui/core/src/main/java/org/exoplatform/webui/form/validator/SpecialCharacterValidator.java 2010-04-06
03:56:06 UTC (rev 2479)
@@ -60,7 +60,7 @@
{
continue;
}
- Object[] args = {label, uiInput.getBindingField()};
+ Object[] args = {label};
throw new MessageException(new
ApplicationMessage("SpecialCharacterValidator.msg.Invalid-char", args,
ApplicationMessage.WARNING));
}