Author: chris.laprun(a)jboss.com
Date: 2010-01-13 12:34:03 -0500 (Wed, 13 Jan 2010)
New Revision: 1262
Added:
portal/trunk/portlet/exoadmin/src/main/java/org/exoplatform/wsrp/webui/component/UIWsrpRegistrationDetails.java
Removed:
portal/trunk/portlet/exoadmin/src/main/java/org/exoplatform/wsrp/webui/component/UIWSRPFormInputSet.java
Modified:
portal/trunk/portlet/exoadmin/src/main/java/org/exoplatform/wsrp/webui/component/UIWsrpProducerEditor.java
portal/trunk/portlet/exoadmin/src/main/java/org/exoplatform/wsrp/webui/component/UIWsrpProducerOverview.java
Log:
- Renamed UIWSRPFormInputSet to UIWsrpRegistrationDetails and moved all the fields
pertaining to registration details BUT
configuration is NOT working and results in the portlet failing to display. :(
Deleted:
portal/trunk/portlet/exoadmin/src/main/java/org/exoplatform/wsrp/webui/component/UIWSRPFormInputSet.java
===================================================================
---
portal/trunk/portlet/exoadmin/src/main/java/org/exoplatform/wsrp/webui/component/UIWSRPFormInputSet.java 2010-01-13
15:17:03 UTC (rev 1261)
+++
portal/trunk/portlet/exoadmin/src/main/java/org/exoplatform/wsrp/webui/component/UIWSRPFormInputSet.java 2010-01-13
17:34:03 UTC (rev 1262)
@@ -1,84 +0,0 @@
-/*
-* JBoss, a division of Red Hat
-* Copyright 2008, Red Hat Middleware, LLC, and individual contributors as indicated
-* by the @authors tag. See the copyright.txt in the distribution for a
-* full listing of individual contributors.
-*
-* This is free software; you can redistribute it and/or modify it
-* under the terms of the GNU Lesser General Public License as
-* published by the Free Software Foundation; either version 2.1 of
-* the License, or (at your option) any later version.
-*
-* This software is distributed in the hope that it will be useful,
-* but WITHOUT ANY WARRANTY; without even the implied warranty of
-* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-* Lesser General Public License for more details.
-*
-* You should have received a copy of the GNU Lesser General Public
-* License along with this software; if not, write to the Free
-* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
-* 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
-*/
-
-package org.exoplatform.wsrp.webui.component;
-
-import org.exoplatform.webui.application.WebuiRequestContext;
-import org.exoplatform.webui.core.UIComponent;
-import org.exoplatform.webui.form.UIForm;
-import org.exoplatform.webui.form.UIFormInputSet;
-
-import java.io.Writer;
-import java.util.MissingResourceException;
-import java.util.ResourceBundle;
-
-/**
- * @author <a href="mailto:chris.laprun@jboss.com">Chris
Laprun</a>
- * @version $Revision$
- */
-public class UIWSRPFormInputSet extends UIFormInputSet
-{
- public UIWSRPFormInputSet(String name)
- {
- super(name);
- }
-
- @Override
- public void processRender(WebuiRequestContext context) throws Exception
- {
- if (getComponentConfig() != null)
- {
- super.processRender(context);
- return;
- }
-
- Writer w = context.getWriter();
- w.write("<div class=\"UIFormInputSet\">");
-
- ResourceBundle res = context.getApplicationResourceBundle();
- UIForm uiForm = getAncestorOfType(UIForm.class);
- for (UIComponent inputEntry : getChildren())
- {
- if (inputEntry.isRendered())
- {
- w.write("<div class=\"row\">");
-
- String label;
- try
- {
- label = uiForm.getLabel(res, inputEntry.getId());
- }
- catch (MissingResourceException ex)
- {
- label = inputEntry.getName();
- System.err.println("\n " + uiForm.getId() + ".label."
+ inputEntry.getId() + " not found value");
- }
-
- w.write("<label>" + label + "</label>");
- renderUIComponent(inputEntry);
-
- w.write("</div>");
- }
- }
- w.write("</div>");
- }
-}
Modified:
portal/trunk/portlet/exoadmin/src/main/java/org/exoplatform/wsrp/webui/component/UIWsrpProducerEditor.java
===================================================================
---
portal/trunk/portlet/exoadmin/src/main/java/org/exoplatform/wsrp/webui/component/UIWsrpProducerEditor.java 2010-01-13
15:17:03 UTC (rev 1261)
+++
portal/trunk/portlet/exoadmin/src/main/java/org/exoplatform/wsrp/webui/component/UIWsrpProducerEditor.java 2010-01-13
17:34:03 UTC (rev 1262)
@@ -24,7 +24,6 @@
import org.exoplatform.portal.webui.util.Util;
import org.exoplatform.web.application.ApplicationMessage;
-import org.exoplatform.webui.application.WebuiRequestContext;
import org.exoplatform.webui.config.annotation.ComponentConfig;
import org.exoplatform.webui.config.annotation.EventConfig;
import org.exoplatform.webui.core.UIApplication;
@@ -33,43 +32,34 @@
import org.exoplatform.webui.event.EventListener;
import org.exoplatform.webui.form.UIForm;
import org.exoplatform.webui.form.UIFormCheckBoxInput;
-import org.exoplatform.webui.form.UIFormInputBase;
-import org.exoplatform.webui.form.UIFormInputSet;
-import org.exoplatform.webui.form.UIFormStringInput;
-import org.gatein.registration.RegistrationPolicy;
-import org.gatein.registration.policies.DefaultRegistrationPolicy;
import org.gatein.wsrp.producer.config.ProducerConfiguration;
import org.gatein.wsrp.producer.config.ProducerConfigurationService;
import org.gatein.wsrp.producer.config.ProducerRegistrationRequirements;
-/** @author Wesley Hales */
-
+/**
+ * @author Wesley Hales
+ * @author Chris Laprun
+ */
@ComponentConfig(
lifecycle = UIFormLifecycle.class,
template = "app:/groovy/wsrp/webui/component/UIWsrpProducerEditor.gtmpl",
events = {
@EventConfig(listeners = UIWsrpProducerEditor.SaveActionListener.class)
- })
-
+ }
+)
public class UIWsrpProducerEditor extends UIForm
{
private static final String REG_REQUIRED_FOR_DESCRIPTION =
"registrationrequiredforfulldescription";
private static final String STRICT_MODE = "strictmode";
private static final String REQUIRES_REGISTRATION = "requiresregistration";
- private static final String POLICY_CLASS = "policyClassName";
- private static final String VALIDATOR_CLASS = "validatorClassName";
private static final String REGISTRATION_DETAILS = "registrationdetails";
private ProducerConfigurationService configService;
-
- private UIFormInputSet registrationDetails;
- private UIFormInputBase<String> policy;
- private UIFormInputBase<String> validator;
+ private UIWsrpRegistrationDetails registrationDetails;
private UIFormCheckBoxInput regReqForDesc;
private UIFormCheckBoxInput strictMode;
private UIFormCheckBoxInput<Boolean> regRequired;
-
public UIWsrpProducerEditor() throws Exception
{
configService =
Util.getUIPortalApplication().getApplicationComponent(ProducerConfigurationService.class);
@@ -89,22 +79,18 @@
// registration details
// form set to gather registration information
- registrationDetails = new UIWSRPFormInputSet(REGISTRATION_DETAILS);
+ registrationDetails = new UIWsrpRegistrationDetails(REGISTRATION_DETAILS, this);
addUIFormInput(registrationDetails);
- // policy
- policy = new UIFormStringInput(POLICY_CLASS, POLICY_CLASS, null);
- registrationDetails.addUIFormInput(policy);
+ init();
+ }
- // validator
- validator = new UIFormStringInput(VALIDATOR_CLASS, VALIDATOR_CLASS, null);
- registrationDetails.addUIFormInput(validator);
-
-
- //init();
+ ProducerConfigurationService getService()
+ {
+ return configService;
}
- public void processRender(WebuiRequestContext context) throws Exception
+ private void init() throws Exception
{
ProducerConfiguration configuration = configService.getConfiguration();
@@ -115,53 +101,19 @@
boolean registrationRequired = registrationRequirements.isRegistrationRequired();
regRequired.setValue(registrationRequired);
-
// if registration is required then we display more information
if (registrationRequired)
{
-
+ registrationDetails.init(registrationRequirements);
registrationDetails.setRendered(true);
-
context.getUIApplication().findComponentById(UIWsrpProducerOverview.REGISTRATION_PROPERTIES).setRendered(true);
-
- RegistrationPolicy policy = registrationRequirements.getPolicy();
- String policyClassName = policy.getClass().getName();
- this.policy.setValue(policyClassName);
-
- // if policy is the default one, display information about the validator
- if
(ProducerRegistrationRequirements.DEFAULT_POLICY_CLASS_NAME.equals(policyClassName))
- {
- DefaultRegistrationPolicy defaultPolicy = (DefaultRegistrationPolicy)policy;
- validator.setValue(defaultPolicy.getValidator().getClass().getName());
- validator.setRendered(true);
- }
- else
- {
- validator.setRendered(false);
- }
-
- // registration properties
-
}
else
{
registrationDetails.setRendered(false);
-
context.getUIApplication().findComponentById(UIWsrpProducerOverview.REGISTRATION_PROPERTIES).setRendered(false);
}
-
- super.processRender(context);
}
- ProducerConfigurationService getService()
- {
- return configService;
- }
- private void init() throws Exception
- {
-
- }
-
-
static public class SaveActionListener extends
EventListener<UIWsrpProducerEditor>
{
public void execute(Event<UIWsrpProducerEditor> event) throws Exception
@@ -177,7 +129,7 @@
registrationRequirements.setRegistrationRequired(requiresReg);
if (requiresReg)
{
- registrationRequirements.reloadPolicyFrom(source.policy.getValue(),
source.validator.getValue());
+
source.registrationDetails.updateRegistrationDetailsFromForm(registrationRequirements);
}
try
@@ -195,14 +147,13 @@
}
}
-
public static class RegistrationOnChangeActionListener extends
EventListener<UIFormCheckBoxInput>
{
public void execute(Event<UIFormCheckBoxInput> event) throws Exception
{
UIFormCheckBoxInput source = event.getSource();
UIWsrpProducerEditor parent =
source.getAncestorOfType(UIWsrpProducerEditor.class);
- //parent.init();
+ parent.init();
//update only the parent, avoid updating the full portlet
event.getRequestContext().addUIComponentToUpdateByAjax(parent);
Modified:
portal/trunk/portlet/exoadmin/src/main/java/org/exoplatform/wsrp/webui/component/UIWsrpProducerOverview.java
===================================================================
---
portal/trunk/portlet/exoadmin/src/main/java/org/exoplatform/wsrp/webui/component/UIWsrpProducerOverview.java 2010-01-13
15:17:03 UTC (rev 1261)
+++
portal/trunk/portlet/exoadmin/src/main/java/org/exoplatform/wsrp/webui/component/UIWsrpProducerOverview.java 2010-01-13
17:34:03 UTC (rev 1262)
@@ -22,245 +22,25 @@
*/
package org.exoplatform.wsrp.webui.component;
-import org.exoplatform.commons.utils.LazyPageList;
-import org.exoplatform.commons.utils.ListAccess;
-import org.exoplatform.container.ExoContainer;
-import org.exoplatform.container.ExoContainerContext;
-import org.exoplatform.portal.webui.util.Util;
-import org.exoplatform.web.application.ApplicationMessage;
-import org.exoplatform.webui.application.WebuiRequestContext;
import org.exoplatform.webui.config.annotation.ComponentConfig;
-import org.exoplatform.webui.config.annotation.ComponentConfigs;
-import org.exoplatform.webui.config.annotation.EventConfig;
-import org.exoplatform.webui.core.UIApplication;
import org.exoplatform.webui.core.UIContainer;
-import org.exoplatform.webui.core.UIGrid;
-import org.exoplatform.webui.core.UIPopupWindow;
import org.exoplatform.webui.core.lifecycle.UIApplicationLifecycle;
-import org.exoplatform.webui.core.renderers.ValueRenderer;
-import org.exoplatform.webui.event.Event;
-import org.exoplatform.webui.event.EventListener;
-import org.gatein.wsrp.producer.config.ProducerConfiguration;
-import org.gatein.wsrp.producer.config.ProducerConfigurationService;
-import org.gatein.wsrp.registration.LocalizedString;
-import org.gatein.wsrp.registration.RegistrationPropertyDescription;
-import javax.xml.namespace.QName;
-import java.util.ArrayList;
-import java.util.Comparator;
-import java.util.List;
-import java.util.Map;
-
-/** @author Wesley Hales */
-@ComponentConfigs({
- @ComponentConfig(id = UIWsrpProducerOverview.REGISTRATION_PROPERTIES, type =
UIGrid.class, template = "system:/groovy/webui/core/UIGrid.gtmpl"),
- @ComponentConfig(
- lifecycle = UIApplicationLifecycle.class,
- template =
"app:/groovy/wsrp/webui/component/UIWsrpProducerOverview.gtmpl",
- events = {
- @EventConfig(listeners =
UIWsrpProducerOverview.AddPropertyActionListener.class),
- @EventConfig(listeners = UIWsrpProducerOverview.EditActionListener.class),
- @EventConfig(listeners = UIWsrpProducerOverview.DeleteActionListener.class)
- }
- )})
-
+/**
+ * @author Wesley Hales
+ * @author Chris Laprun
+ */
+@ComponentConfig(
+ lifecycle = UIApplicationLifecycle.class,
+ template = "app:/groovy/wsrp/webui/component/UIWsrpProducerOverview.gtmpl"
+)
public class UIWsrpProducerOverview extends UIContainer
{
- private static String[] FIELDS = {"key", "name",
"description", "label", "hint"};
- private static String[] SELECT_ACTIONS = {"Add", "Edit",
"Delete"};
-
- public static final String REGISTRATION_PROPERTIES =
"RegistrationPropertySelector";
- private static final String REGISTRATION_PROPERTIES_ITERATOR =
"ProducerPropPageIterator";
- private UIGrid registrationProperties;
- private ProducerConfigurationService configService;
private UIWsrpProducerEditor producerForm;
public UIWsrpProducerOverview() throws Exception
{
- //setSelectedTab(2);
- configService =
Util.getUIPortalApplication().getApplicationComponent(ProducerConfigurationService.class);
- ProducerConfiguration configuration = configService.getConfiguration();
- //producerForm = createUIComponent();
- addChild(UIWsrpProducerEditor.class, null, null);
- // registration properties
- registrationProperties = addChild(UIGrid.class, REGISTRATION_PROPERTIES,
REGISTRATION_PROPERTIES);
-
- // add renderer for LocalizedString
- ValueRenderer<LocalizedString> renderer = new
ValueRenderer<LocalizedString>()
- {
- @Override
- public String render(LocalizedString value)
- {
- return value.getValue();
- }
- };
- registrationProperties.registerRendererFor(renderer, LocalizedString.class);
-
- //configure the edit and delete buttons based on an id from the data list - this
will also be passed as param to listener
- registrationProperties.configure("key", FIELDS, SELECT_ACTIONS);
-
registrationProperties.getUIPageIterator().setId(REGISTRATION_PROPERTIES_ITERATOR);
- //registrationDetails.addChild(registrationProperties.getUIPageIterator());
- registrationProperties.getUIPageIterator().setRendered(false);
-
- Map<QName, RegistrationPropertyDescription> regProps =
configuration.getRegistrationRequirements().getRegistrationProperties();
-
registrationProperties.getUIPageIterator().setPageList(createPageList(getPropertyList(regProps)));
-
- //add the popup for property edit and adding new properties
- UIPopupWindow popup = addChild(UIPopupWindow.class, null, null);
- popup.setWindowSize(400, 300);
- UIWsrpProducerPropertyEditor propertyForm =
createUIComponent(UIWsrpProducerPropertyEditor.class, null, "Producer Property
Editor");
- popup.setUIComponent(propertyForm);
- popup.setRendered(false);
-
+ producerForm = createUIComponent(UIWsrpProducerEditor.class, null, "Producer
Editor");
+ addChild(producerForm);
}
-
- private List<RegistrationPropertyDescription> getPropertyList(Map<QName,
RegistrationPropertyDescription> descriptions) throws Exception
- {
- Comparator<RegistrationPropertyDescription> descComparator = new
Comparator<RegistrationPropertyDescription>()
- {
- public int compare(RegistrationPropertyDescription o1,
RegistrationPropertyDescription o2)
- {
- return o1.getName().toString().compareTo(o2.getName().toString());
- }
- };
- List<RegistrationPropertyDescription> result = new
ArrayList<RegistrationPropertyDescription>();
- for (Object o : descriptions.entrySet())
- {
- Map.Entry entry = (Map.Entry)o;
- RegistrationPropertyDescription rpd =
(RegistrationPropertyDescription)entry.getValue();
- result.add(rpd);
-
- }
-
-
- //List<RegistrationPropertyDescription> result = new
ArrayList<RegistrationPropertyDescription>(descriptions.values());
- //Collections.sort(result, descComparator);
- return result;
- }
-
- private LazyPageList<RegistrationPropertyDescription> createPageList(final
List<RegistrationPropertyDescription> pageList)
- {
- return new LazyPageList<RegistrationPropertyDescription>(new
ListAccess<RegistrationPropertyDescription>()
- {
-
- public int getSize() throws Exception
- {
- return pageList.size();
- }
-
- public RegistrationPropertyDescription[] load(int index, int length) throws
Exception, IllegalArgumentException
- {
- RegistrationPropertyDescription[] pcs = new
RegistrationPropertyDescription[pageList.size()];
-
- if (index < 0)
- {
- throw new IllegalArgumentException("Illegal index: index must be a
positive number");
- }
-
- if (length < 0)
- {
- throw new IllegalArgumentException("Illegal length: length must be a
positive number");
- }
-
- if (index + length > pageList.size())
- {
- throw new IllegalArgumentException(
- "Illegal index or length: sum of the index and the length cannot
be greater than the list size");
- }
-
- for (int i = 0; i < length; i++)
- {
- pcs[i] = pageList.get(i + index);
- }
-
- return pcs;
- }
-
- }, 10);
- }
-
- static public class EditActionListener extends
EventListener<UIWsrpProducerOverview>
- {
- public void execute(Event<UIWsrpProducerOverview> event) throws Exception
- {
- UIWsrpProducerOverview source = event.getSource();
- UIPopupWindow popup = source.getChild(UIPopupWindow.class);
- UIWsrpProducerPropertyEditor editor =
(UIWsrpProducerPropertyEditor)popup.getUIComponent();
- String id = event.getRequestContext().getRequestParameter(OBJECTID);
- try
- {
-
editor.setRegistrationPropertyDescription(source.getService().getConfiguration().getRegistrationRequirements().getRegistrationPropertyWith(id));
- }
- catch (Exception e)
- {
- e.printStackTrace();
- }
- popup.setUIComponent(editor);
- popup.setRendered(true);
- popup.setShow(true);
-
- }
- }
-
- static public class DeleteActionListener extends
EventListener<UIWsrpProducerOverview>
- {
- public void execute(Event<UIWsrpProducerOverview> event)
- {
- UIWsrpProducerOverview source = event.getSource();
- UIApplication uiApp = event.getRequestContext().getUIApplication();
- UIPopupWindow popup = source.getChild(UIPopupWindow.class);
- String id = event.getRequestContext().getRequestParameter(OBJECTID);
- try
- {
- ProducerConfigurationService service = source.getService();
-
service.getConfiguration().getRegistrationRequirements().removeRegistrationProperty(id);
- service.saveConfiguration();
- }
- catch (Exception e)
- {
- e.printStackTrace();
- uiApp.addMessage(new ApplicationMessage("Failed to delete Producer
Property. Cause: " + e.getCause(), null, ApplicationMessage.ERROR));
- }
-
- }
- }
-
- static public class AddPropertyActionListener extends
EventListener<UIWsrpProducerOverview>
- {
- public void execute(Event<UIWsrpProducerOverview> event) throws Exception
- {
- UIWsrpProducerOverview source = event.getSource();
- UIPopupWindow popup = source.getChild(UIPopupWindow.class);
- UIWsrpProducerPropertyEditor editor =
(UIWsrpProducerPropertyEditor)popup.getUIComponent();
-
- //reset the form
- editor.setRegistrationPropertyDescription(null);
- popup.setRendered(true);
- popup.setShow(true);
- popup.setShowCloseButton(true);
- //popup.setShowMask(true);
-
- }
- }
-
- ProducerConfigurationService getService()
- {
- return configService;
- }
-
- public void processRender(WebuiRequestContext context) throws Exception
- {
-// UITabPane uiTabPane =
context.getUIApplication().findComponentById("UIWsrpConsoleTab");
-// uiTabPane.setSelectedTab(2);
- super.processRender(context);
- }
-
-
- public ProducerConfigurationService getProducerConfigurationService() throws
Exception
- {
- ExoContainer manager = ExoContainerContext.getCurrentContainer();
- return
(ProducerConfigurationService)manager.getComponentInstanceOfType(ProducerConfigurationService.class);
- }
-
-
}
Copied:
portal/trunk/portlet/exoadmin/src/main/java/org/exoplatform/wsrp/webui/component/UIWsrpRegistrationDetails.java
(from rev 1241,
portal/trunk/portlet/exoadmin/src/main/java/org/exoplatform/wsrp/webui/component/UIWSRPFormInputSet.java)
===================================================================
---
portal/trunk/portlet/exoadmin/src/main/java/org/exoplatform/wsrp/webui/component/UIWsrpRegistrationDetails.java
(rev 0)
+++
portal/trunk/portlet/exoadmin/src/main/java/org/exoplatform/wsrp/webui/component/UIWsrpRegistrationDetails.java 2010-01-13
17:34:03 UTC (rev 1262)
@@ -0,0 +1,319 @@
+/*
+ * JBoss, a division of Red Hat
+ * Copyright 2010, Red Hat Middleware, LLC, and individual
+ * contributors as indicated by the @authors tag. See the
+ * copyright.txt in the distribution for a full listing of
+ * individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+
+package org.exoplatform.wsrp.webui.component;
+
+import org.exoplatform.commons.utils.LazyPageList;
+import org.exoplatform.commons.utils.ListAccess;
+import org.exoplatform.web.application.ApplicationMessage;
+import org.exoplatform.webui.application.WebuiRequestContext;
+import org.exoplatform.webui.config.annotation.ComponentConfig;
+import org.exoplatform.webui.config.annotation.ComponentConfigs;
+import org.exoplatform.webui.config.annotation.EventConfig;
+import org.exoplatform.webui.core.UIApplication;
+import org.exoplatform.webui.core.UIComponent;
+import org.exoplatform.webui.core.UIGrid;
+import org.exoplatform.webui.core.UIPopupWindow;
+import org.exoplatform.webui.core.lifecycle.UIApplicationLifecycle;
+import org.exoplatform.webui.core.renderers.ValueRenderer;
+import org.exoplatform.webui.event.Event;
+import org.exoplatform.webui.event.EventListener;
+import org.exoplatform.webui.form.UIForm;
+import org.exoplatform.webui.form.UIFormInputBase;
+import org.exoplatform.webui.form.UIFormInputSet;
+import org.exoplatform.webui.form.UIFormStringInput;
+import org.gatein.registration.RegistrationPolicy;
+import org.gatein.registration.policies.DefaultRegistrationPolicy;
+import org.gatein.wsrp.producer.config.ProducerConfigurationService;
+import org.gatein.wsrp.producer.config.ProducerRegistrationRequirements;
+import org.gatein.wsrp.registration.LocalizedString;
+import org.gatein.wsrp.registration.RegistrationPropertyDescription;
+
+import javax.xml.namespace.QName;
+import java.io.Writer;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.List;
+import java.util.Map;
+import java.util.MissingResourceException;
+import java.util.ResourceBundle;
+
+/**
+ * @author <a href="mailto:chris.laprun@jboss.com">Chris
Laprun</a>
+ * @version $Revision$
+ */
+@ComponentConfigs({
+ @ComponentConfig(id = "RegistrationPropertySelector", type = UIGrid.class,
template = "system:/groovy/webui/core/UIGrid.gtmpl"),
+ @ComponentConfig(
+ lifecycle = UIApplicationLifecycle.class,
+ events = {
+ @EventConfig(listeners =
UIWsrpRegistrationDetails.AddPropertyActionListener.class),
+ @EventConfig(listeners =
UIWsrpRegistrationDetails.EditPropertyActionListener.class),
+ @EventConfig(listeners =
UIWsrpRegistrationDetails.DeletePropertyActionListener.class)
+ })
+})
+public class UIWsrpRegistrationDetails extends UIFormInputSet
+{
+ private UIFormInputBase<String> policy;
+ private UIFormInputBase<String> validator;
+ private UIGrid registrationProperties;
+ static String[] FIELDS = {"name", "description",
"label", "hint"};
+ static String[] SELECT_ACTIONS = {"AddProperty", "EditProperty",
"DeleteProperty"};
+ static final String POLICY_CLASS = "policyClassName";
+ static final String VALIDATOR_CLASS = "validatorClassName";
+ static final String REGISTRATION_PROPERTIES =
"RegistrationPropertySelector";
+ static final String REGISTRATION_PROPERTIES_ITERATOR =
"ProducerPropPageIterator";
+
+ public UIWsrpRegistrationDetails(String name, UIWsrpProducerEditor parent) throws
Exception
+ {
+ super(name);
+
+ // policy
+ policy = new UIFormStringInput(POLICY_CLASS, POLICY_CLASS, null);
+ addUIFormInput(policy);
+
+ // validator
+ validator = new UIFormStringInput(VALIDATOR_CLASS, VALIDATOR_CLASS, null);
+ addUIFormInput(validator);
+
+ // registration properties
+ registrationProperties = addChild(UIGrid.class, REGISTRATION_PROPERTIES,
REGISTRATION_PROPERTIES);
+
+ // add renderer for LocalizedString
+ ValueRenderer<LocalizedString> renderer = new
ValueRenderer<LocalizedString>()
+ {
+ @Override
+ public String render(LocalizedString value)
+ {
+ return value.getValue();
+ }
+ };
+ registrationProperties.registerRendererFor(renderer, LocalizedString.class);
+
+ //configure the edit and delete buttons based on an id from the data list - this
will also be passed as param to listener
+ registrationProperties.configure("name", FIELDS, SELECT_ACTIONS);
+
registrationProperties.getUIPageIterator().setId(REGISTRATION_PROPERTIES_ITERATOR);
+ registrationProperties.getUIPageIterator().setRendered(false);
+ addChild(registrationProperties.getUIPageIterator());
+
+ init(parent.getService().getConfiguration().getRegistrationRequirements());
+
+ //add the popup for property edit and adding new properties
+ UIPopupWindow popup = addChild(UIPopupWindow.class, null, null);
+ popup.setWindowSize(400, 300);
+ UIWsrpProducerPropertyEditor propertyForm =
createUIComponent(UIWsrpProducerPropertyEditor.class, null, "Producer Property
Editor");
+ popup.setUIComponent(propertyForm);
+ popup.setRendered(false);
+ }
+
+ void init(ProducerRegistrationRequirements registrationRequirements) throws Exception
+ {
+ RegistrationPolicy policy = registrationRequirements.getPolicy();
+ String policyClassName = policy.getClass().getName();
+ this.policy.setValue(policyClassName);
+
+ // if policy is the default one, display information about the validator
+ if
(ProducerRegistrationRequirements.DEFAULT_POLICY_CLASS_NAME.equals(policyClassName))
+ {
+ DefaultRegistrationPolicy defaultPolicy = (DefaultRegistrationPolicy)policy;
+ validator.setValue(defaultPolicy.getValidator().getClass().getName());
+ validator.setRendered(true);
+ }
+ else
+ {
+ validator.setRendered(false);
+ }
+
+ // registration properties
+ Map<QName, RegistrationPropertyDescription> regProps =
registrationRequirements.getRegistrationProperties();
+
registrationProperties.getUIPageIterator().setPageList(createPageList(getPropertyList(regProps)));
+ }
+
+ private List<RegistrationPropertyDescription> getPropertyList(Map<QName,
RegistrationPropertyDescription> descriptions) throws Exception
+ {
+ Comparator<RegistrationPropertyDescription> descComparator = new
Comparator<RegistrationPropertyDescription>()
+ {
+ public int compare(RegistrationPropertyDescription o1,
RegistrationPropertyDescription o2)
+ {
+ return o1.getName().toString().compareTo(o2.getName().toString());
+ }
+ };
+
+ List<RegistrationPropertyDescription> result = new
ArrayList<RegistrationPropertyDescription>(descriptions.values());
+ Collections.sort(result, descComparator);
+ return result;
+ }
+
+ private LazyPageList<RegistrationPropertyDescription> createPageList(final
List<RegistrationPropertyDescription> pageList)
+ {
+ return new LazyPageList<RegistrationPropertyDescription>(new
ListAccess<RegistrationPropertyDescription>()
+ {
+
+ public int getSize() throws Exception
+ {
+ return pageList.size();
+ }
+
+ public RegistrationPropertyDescription[] load(int index, int length) throws
Exception, IllegalArgumentException
+ {
+ RegistrationPropertyDescription[] pcs = new
RegistrationPropertyDescription[pageList.size()];
+
+ if (index < 0)
+ {
+ throw new IllegalArgumentException("Illegal index: index must be a
positive number");
+ }
+
+ if (length < 0)
+ {
+ throw new IllegalArgumentException("Illegal length: length must be a
positive number");
+ }
+
+ if (index + length > pageList.size())
+ {
+ throw new IllegalArgumentException(
+ "Illegal index or length: sum of the index and the length cannot
be greater than the list size");
+ }
+
+ for (int i = 0; i < length; i++)
+ {
+ pcs[i] = pageList.get(i + index);
+ }
+
+ return pcs;
+ }
+
+ }, 10);
+ }
+
+ @Override
+ public void processRender(WebuiRequestContext context) throws Exception
+ {
+ if (getComponentConfig() != null)
+ {
+ super.processRender(context);
+ return;
+ }
+
+ Writer w = context.getWriter();
+ w.write("<div class=\"UIFormInputSet\">");
+
+ ResourceBundle res = context.getApplicationResourceBundle();
+ UIForm uiForm = getAncestorOfType(UIForm.class);
+ for (UIComponent inputEntry : getChildren())
+ {
+ if (inputEntry.isRendered())
+ {
+ w.write("<div class=\"row\">");
+
+ String label;
+ try
+ {
+ label = uiForm.getLabel(res, inputEntry.getId());
+ }
+ catch (MissingResourceException ex)
+ {
+ label = inputEntry.getName();
+ System.err.println("\n " + uiForm.getId() + ".label."
+ inputEntry.getId() + " not found value");
+ }
+
+ w.write("<label>" + label + "</label>");
+ renderUIComponent(inputEntry);
+
+ w.write("</div>");
+ }
+ }
+ w.write("</div>");
+ }
+
+ public void updateRegistrationDetailsFromForm(ProducerRegistrationRequirements
registrationRequirements)
+ {
+ registrationRequirements.reloadPolicyFrom(policy.getValue(),
validator.getValue());
+
+ // todo: deal with registration properties
+ }
+
+ static public class EditPropertyActionListener extends
EventListener<UIWsrpProducerEditor>
+ {
+ public void execute(Event<UIWsrpProducerEditor> event) throws Exception
+ {
+ UIWsrpProducerEditor source = event.getSource();
+ UIPopupWindow popup = source.getChild(UIPopupWindow.class);
+ UIWsrpProducerPropertyEditor editor =
(UIWsrpProducerPropertyEditor)popup.getUIComponent();
+ String id = event.getRequestContext().getRequestParameter(OBJECTID);
+ try
+ {
+
editor.setRegistrationPropertyDescription(source.getService().getConfiguration().getRegistrationRequirements().getRegistrationPropertyWith(id));
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace();
+ }
+ popup.setUIComponent(editor);
+ popup.setRendered(true);
+ popup.setShow(true);
+
+ }
+ }
+
+ static public class DeletePropertyActionListener extends
EventListener<UIWsrpProducerEditor>
+ {
+ public void execute(Event<UIWsrpProducerEditor> event)
+ {
+ UIWsrpProducerEditor source = event.getSource();
+ UIApplication uiApp = event.getRequestContext().getUIApplication();
+ UIPopupWindow popup = source.getChild(UIPopupWindow.class);
+ String id = event.getRequestContext().getRequestParameter(OBJECTID);
+ try
+ {
+ ProducerConfigurationService service = source.getService();
+
service.getConfiguration().getRegistrationRequirements().removeRegistrationProperty(id);
+ service.saveConfiguration();
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace();
+ uiApp.addMessage(new ApplicationMessage("Failed to delete Producer
Property. Cause: " + e.getCause(), null, ApplicationMessage.ERROR));
+ }
+
+ }
+ }
+
+ static public class AddPropertyActionListener extends
EventListener<UIWsrpProducerEditor>
+ {
+ public void execute(Event<UIWsrpProducerEditor> event) throws Exception
+ {
+ UIWsrpProducerEditor source = event.getSource();
+ UIPopupWindow popup = source.getChild(UIPopupWindow.class);
+ UIWsrpProducerPropertyEditor editor =
(UIWsrpProducerPropertyEditor)popup.getUIComponent();
+
+ //reset the form
+ editor.setRegistrationPropertyDescription(null);
+ popup.setRendered(true);
+ popup.setShow(true);
+ popup.setShowCloseButton(true);
+ //popup.setShowMask(true);
+
+ }
+ }
+}