Author: ndkhoiits
Date: 2011-08-10 05:37:17 -0400 (Wed, 10 Aug 2011)
New Revision: 7040
Modified:
portal/trunk/portlet/dashboard/src/main/java/org/exoplatform/gadget/webui/component/UIGadgetPortlet.java
portal/trunk/portlet/dashboard/src/main/webapp/groovy/gadget/webui/component/UIGadgetViewMode.gtmpl
portal/trunk/webui/portal/src/main/java/org/exoplatform/portal/webui/application/ModelAdapter.java
portal/trunk/webui/portal/src/main/java/org/exoplatform/portal/webui/application/UIPortlet.java
Log:
GTNPORTAL-1860 support for saving gadget portlet wrapper preferences withing the gadget
Modified:
portal/trunk/portlet/dashboard/src/main/java/org/exoplatform/gadget/webui/component/UIGadgetPortlet.java
===================================================================
---
portal/trunk/portlet/dashboard/src/main/java/org/exoplatform/gadget/webui/component/UIGadgetPortlet.java 2011-08-10
08:46:33 UTC (rev 7039)
+++
portal/trunk/portlet/dashboard/src/main/java/org/exoplatform/gadget/webui/component/UIGadgetPortlet.java 2011-08-10
09:37:17 UTC (rev 7040)
@@ -26,6 +26,7 @@
import org.exoplatform.container.ExoContainerContext;
import org.exoplatform.portal.webui.application.GadgetUtil;
import org.exoplatform.web.application.ApplicationMessage;
+import org.exoplatform.webui.application.WebuiApplication;
import org.exoplatform.webui.application.WebuiRequestContext;
import org.exoplatform.webui.application.portlet.PortletRequestContext;
import org.exoplatform.webui.config.annotation.ComponentConfig;
@@ -38,6 +39,7 @@
import org.json.JSONObject;
import javax.portlet.PortletPreferences;
+import javax.portlet.PortletRequest;
/**
* Created by The eXo Platform SARL
@@ -52,11 +54,48 @@
private static final Logger log = LoggerFactory.getLogger(GadgetImporter.class);
+ /** User pref. */
+ private String userPref;
+
public UIGadgetPortlet() throws Exception
{
addChild(UIGadgetViewMode.class, null, null);
}
+
+ public String getUserPref()
+ {
+ return userPref;
+ }
+ @Override
+ public void processAction(WebuiRequestContext context) throws Exception
+ {
+ super.processAction(context);
+
+ //
+ PortletRequest req = context.getRequest();
+
+ //
+ userPref = req.getParameter("userPref");
+ if (userPref != null && !userPref.isEmpty())
+ {
+ PortletPreferences prefs = req.getPreferences();
+ prefs.setValue("userPref", userPref);
+ prefs.store();
+ }
+ }
+
+ @Override
+ public void processRender(WebuiApplication app, WebuiRequestContext context) throws
Exception
+ {
+ PortletRequest req = context.getRequest();
+ PortletPreferences prefs = req.getPreferences();
+ userPref = prefs.getValue("userPref", null);
+
+ //
+ super.processRender(app, context);
+ }
+
public String getUrl()
{
PortletRequestContext pcontext =
(PortletRequestContext)WebuiRequestContext.getCurrentInstance();
Modified:
portal/trunk/portlet/dashboard/src/main/webapp/groovy/gadget/webui/component/UIGadgetViewMode.gtmpl
===================================================================
---
portal/trunk/portlet/dashboard/src/main/webapp/groovy/gadget/webui/component/UIGadgetViewMode.gtmpl 2011-08-10
08:46:33 UTC (rev 7039)
+++
portal/trunk/portlet/dashboard/src/main/webapp/groovy/gadget/webui/component/UIGadgetViewMode.gtmpl 2011-08-10
09:37:17 UTC (rev 7040)
@@ -12,7 +12,7 @@
if(url != null) {
def metadata = uicomponent.getParent().getMetadata(url);
- def userPref = null;
+ def userPref = uicomponent.getParent().getUserPref();
JavascriptManager jsmanager = rcontext.getJavascriptManager();
jsmanager.importJavascript("eXo.gadget.UIGadget") ;
jsmanager.addCustomizedOnLoadScript("eXo.gadget.UIGadget.createGadget('$url','$id',
$metadata, $userPref, 'canvas', '$hostName');") ;
Modified:
portal/trunk/webui/portal/src/main/java/org/exoplatform/portal/webui/application/ModelAdapter.java
===================================================================
---
portal/trunk/webui/portal/src/main/java/org/exoplatform/portal/webui/application/ModelAdapter.java 2011-08-10
08:46:33 UTC (rev 7039)
+++
portal/trunk/webui/portal/src/main/java/org/exoplatform/portal/webui/application/ModelAdapter.java 2011-08-10
09:37:17 UTC (rev 7040)
@@ -27,7 +27,6 @@
import org.exoplatform.portal.config.model.TransientApplicationState;
import org.exoplatform.portal.pc.ExoPortletState;
import org.exoplatform.portal.pc.ExoPortletStateType;
-import org.exoplatform.portal.pom.config.Utils;
import org.exoplatform.portal.pom.spi.gadget.Gadget;
import org.exoplatform.portal.pom.spi.portlet.Portlet;
import org.exoplatform.portal.pom.spi.portlet.PortletBuilder;
@@ -40,6 +39,7 @@
import java.io.Serializable;
import java.util.Arrays;
+import java.util.Collections;
import java.util.List;
import java.util.Map;
@@ -204,6 +204,12 @@
String url = GadgetUtil.reproduceUrl(model.getUrl(), model.isLocal());
ExoPortletState prefs = new ExoPortletState(WRAPPER_ID);
prefs.getState().put("url", Arrays.asList(url));
+ DataStorage dataStorage =
(DataStorage)container.getComponentInstanceOfType(DataStorage.class);
+ Gadget gadget = dataStorage.load(applicationState, ApplicationType.GADGET);
+ if (gadget != null && gadget.getUserPref() != null)
+ {
+ prefs.getState().put("userPref",
Collections.singletonList(gadget.getUserPref()));
+ }
return StatefulPortletContext.create(LOCAL_STATE_ID,
ExoPortletStateType.getInstance(), prefs);
}
@@ -211,7 +217,33 @@
public ApplicationState<Gadget> update(ExoContainer container,
ExoPortletState updateState,
ApplicationState<Gadget>
gadgetApplicationState) throws Exception
{
- throw new UnsupportedOperationException("Cannot edit gadget
preferences");
+ // Compute new preferences
+ String userPref = null;
+ for (Map.Entry<String, List<String>> entry :
updateState.getState().entrySet())
+ {
+ if (entry.getKey().equals("userPref") &&
entry.getValue().size() > 0)
+ {
+ userPref = entry.getValue().get(0);
+ }
+ }
+
+ if (gadgetApplicationState instanceof TransientApplicationState<?>)
+ {
+ throw new UnsupportedOperationException("todo");
+ }
+ else
+ {
+ if (userPref != null)
+ {
+ Gadget gadget = new Gadget();
+ gadget.addUserPref(userPref);
+ DataStorage dataStorage =
(DataStorage)container.getComponentInstanceOfType(DataStorage.class);
+ dataStorage.save(gadgetApplicationState, gadget);
+ }
+ }
+
+ //
+ return gadgetApplicationState;
}
@Override
Modified:
portal/trunk/webui/portal/src/main/java/org/exoplatform/portal/webui/application/UIPortlet.java
===================================================================
---
portal/trunk/webui/portal/src/main/java/org/exoplatform/portal/webui/application/UIPortlet.java 2011-08-10
08:46:33 UTC (rev 7039)
+++
portal/trunk/webui/portal/src/main/java/org/exoplatform/portal/webui/application/UIPortlet.java 2011-08-10
09:37:17 UTC (rev 7040)
@@ -52,7 +52,6 @@
import org.gatein.common.net.media.MediaType;
import org.gatein.common.util.ParameterValidation;
import org.gatein.pc.api.Mode;
-import org.gatein.pc.api.NoSuchPortletException;
import org.gatein.pc.api.PortletContext;
import org.gatein.pc.api.PortletInvoker;
import org.gatein.pc.api.PortletInvokerException;
@@ -1003,7 +1002,8 @@
public void update(C updateState) throws Exception
{
WebuiRequestContext context = WebuiRequestContext.getCurrentInstance();
- ExoContainer container = context.getApplication().getApplicationServiceContainer();
state.setApplicationState(adapter.update(container, updateState,
state.getApplicationState()));
+ ExoContainer container =
context.getApplication().getApplicationServiceContainer();
+ state.setApplicationState(adapter.update(container, updateState,
state.getApplicationState()));
setState(state);
}