Author: chris.laprun(a)jboss.com
Date: 2008-05-20 19:05:27 -0400 (Tue, 20 May 2008)
New Revision: 10788
Modified:
branches/JBoss_Portal_Branch_2_7/core-admin/src/main/org/jboss/portal/core/admin/ui/actions/WindowComparator.java
branches/JBoss_Portal_Branch_2_7/core-admin/src/main/org/jboss/portal/core/admin/ui/common/PageManagerBean.java
branches/JBoss_Portal_Branch_2_7/core-admin/src/resources/portal-admin-war/jsf/common/editPageLayout.xhtml
branches/JBoss_Portal_Branch_2_7/core/src/main/org/jboss/portal/core/ui/content/portlet/PortletContentEditorPortlet.java
branches/JBoss_Portal_Branch_2_7/core/src/resources/portal-core-war/WEB-INF/jsp/content/portlet_editor.jsp
Log:
- Content integration:
+ Use content.uri again (not sure why it was changed)
+ Add namespace bound variable so that it can be accessed from JSF
+ Check the event name (though it doesn't seem to be properly called)
+ Use namespace in javascript in editPageLayout (there seems to be discrepancies with
JSF and namespacing)... :(
- Generification
Modified:
branches/JBoss_Portal_Branch_2_7/core/src/main/org/jboss/portal/core/ui/content/portlet/PortletContentEditorPortlet.java
===================================================================
---
branches/JBoss_Portal_Branch_2_7/core/src/main/org/jboss/portal/core/ui/content/portlet/PortletContentEditorPortlet.java 2008-05-20
22:12:48 UTC (rev 10787)
+++
branches/JBoss_Portal_Branch_2_7/core/src/main/org/jboss/portal/core/ui/content/portlet/PortletContentEditorPortlet.java 2008-05-20
23:05:27 UTC (rev 10788)
@@ -40,7 +40,6 @@
import javax.portlet.RenderRequest;
import javax.portlet.RenderResponse;
import javax.xml.namespace.QName;
-
import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;
@@ -65,6 +64,8 @@
/** . */
private InstanceContainer instanceContainer;
+ private static final QName CONTENT_SELECT = new
QName("urn:jboss:portal:content", "select");
+ private static final String CONTENT_URI = "content.uri";
public void init() throws PortletException
{
@@ -75,11 +76,11 @@
{
if ((req.getPortletMode().equals(EDIT_CONTENT)))
{
- String uri = req.getParameter("content_uri");
+ String uri = req.getParameter(CONTENT_URI);
if (uri != null)
{
- resp.setRenderParameter("content_uri", uri);
- resp.setEvent(new QName("urn:jboss:portal:content",
"select"), uri);
+ resp.setRenderParameter(CONTENT_URI, uri);
+ resp.setEvent(CONTENT_SELECT, uri);
}
}
}
@@ -103,7 +104,7 @@
protected void getContent(RenderRequest req, RenderResponse resp, boolean newContent)
throws PortletException, PortletSecurityException, IOException
{
- String selectedURI = req.getParameter("content_uri");
+ String selectedURI = req.getParameter(CONTENT_URI);
//
resp.setContentType("text/html");
Modified:
branches/JBoss_Portal_Branch_2_7/core/src/resources/portal-core-war/WEB-INF/jsp/content/portlet_editor.jsp
===================================================================
---
branches/JBoss_Portal_Branch_2_7/core/src/resources/portal-core-war/WEB-INF/jsp/content/portlet_editor.jsp 2008-05-20
22:12:48 UTC (rev 10787)
+++
branches/JBoss_Portal_Branch_2_7/core/src/resources/portal-core-war/WEB-INF/jsp/content/portlet_editor.jsp 2008-05-20
23:05:27 UTC (rev 10788)
@@ -133,7 +133,7 @@
%>
<portlet:actionURL var="url">
<portlet:param name="content.action.select"
value="true"/>
- <portlet:param name="content_uri" value="<%=
instance.getId() %>"/>
+ <portlet:param name="content.uri" value="<%=
instance.getId() %>"/>
</portlet:actionURL>
<div style="display:none">
Modified:
branches/JBoss_Portal_Branch_2_7/core-admin/src/main/org/jboss/portal/core/admin/ui/actions/WindowComparator.java
===================================================================
---
branches/JBoss_Portal_Branch_2_7/core-admin/src/main/org/jboss/portal/core/admin/ui/actions/WindowComparator.java 2008-05-20
22:12:48 UTC (rev 10787)
+++
branches/JBoss_Portal_Branch_2_7/core-admin/src/main/org/jboss/portal/core/admin/ui/actions/WindowComparator.java 2008-05-20
23:05:27 UTC (rev 10788)
@@ -31,13 +31,11 @@
* @author <a href="mailto:julien@jboss.org">Julien Viet</a>
* @version $Revision$
*/
-public class WindowComparator implements Comparator
+public class WindowComparator implements Comparator<Window>
{
- public int compare(Object o1, Object o2)
+ public int compare(Window w1, Window w2)
{
- Window w1 = (Window)o1;
- Window w2 = (Window)o2;
int sign = getOrder(w1) - getOrder(w2);
if (sign == 0)
{
Modified:
branches/JBoss_Portal_Branch_2_7/core-admin/src/main/org/jboss/portal/core/admin/ui/common/PageManagerBean.java
===================================================================
---
branches/JBoss_Portal_Branch_2_7/core-admin/src/main/org/jboss/portal/core/admin/ui/common/PageManagerBean.java 2008-05-20
22:12:48 UTC (rev 10787)
+++
branches/JBoss_Portal_Branch_2_7/core-admin/src/main/org/jboss/portal/core/admin/ui/common/PageManagerBean.java 2008-05-20
23:05:27 UTC (rev 10788)
@@ -50,7 +50,9 @@
import javax.faces.event.AbortProcessingException;
import javax.faces.event.ActionEvent;
import javax.faces.model.SelectItem;
+import javax.xml.namespace.QName;
import java.util.ArrayList;
+import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.Iterator;
@@ -80,6 +82,8 @@
/** . */
private static final int CONTENT_PARAM_PREFIX_LENGTH = CONTENT_PARAM_PREFIX.length();
+ private static final QName CONTENT_SELECT = new
QName("urn:jboss:portal:content", "select");
+
/** . */
private static final int MOVE_UP = 'u';
@@ -91,6 +95,7 @@
/** . */
private static final int ADD_ACTION = 'a';
+ private static final String VIEW_ROOT = ":_viewRoot";
public PageManagerBean(LayoutService layoutService, PortletInvoker portletInvoker)
{
@@ -124,12 +129,17 @@
/** . */
public Map selectedRenderParameters;
+ public String getNamespace()
+ {
+ return
FacesContext.getCurrentInstance().getExternalContext().encodeNamespace("") +
VIEW_ROOT;
+ }
+
public List getContentTypeItems()
- {
- LinkedList types = new LinkedList();
- for (Iterator i =
ContentProviderRegistryService.getInstance().getContentTypes().iterator(); i.hasNext();)
+ {
+ LinkedList<SelectItem> types = new LinkedList<SelectItem>();
+ for (Object o : ContentProviderRegistryService.getInstance().getContentTypes())
{
- ContentType contentType = (ContentType)i.next();
+ ContentType contentType = (ContentType)o;
SelectItem item = new SelectItem();
item.setValue(contentType);
item.setLabel(contentType.toString());
@@ -147,7 +157,7 @@
public ContentType getSelectedContentType()
{
- return selectedContentType;
+ return selectedContentType;
}
public void setSelectedContentType(ContentType selectedContentType)
@@ -172,14 +182,14 @@
protected String createWindowName(String contentType, String contentURI, boolean
appendNumber)
{
- String windowName = null;
+ String windowName;
ContentProvider contentProvider =
ContentProviderRegistryService.getInstance().getContentProvider(ContentType.create(contentType));
String instanceName = contentProvider.getPortletInfo().getPortletName(Mode.VIEW);
- if(instanceName == null)
+ if (instanceName == null)
{
- // Content type portlet: use URI (PortletInstance)
- windowName = contentURI;
+ // Content type portlet: use URI (PortletInstance)
+ windowName = contentURI;
}
else
{
@@ -188,9 +198,9 @@
appendNumber = true;
windowName = instanceName;
}
-
+
//
- if(windowName.indexOf("Instance") != -1)
+ if (windowName.indexOf("Instance") != -1)
{
// Replace the instance with window
windowName = windowName.replace("Instance", "Window");
@@ -200,16 +210,16 @@
// Or just append window
windowName = windowName + "Window";
}
-
+
//
if (appendNumber)
{
- // if the window already exists add a random number
+ // if the window already exists add a random number
return windowName + "_" + (int)(100 * Math.random());
}
else
{
- // Just the window without any number
+ // Just the window without any number
return windowName;
}
}
@@ -219,144 +229,149 @@
String id = event.getComponent().getId();
char direction = id.charAt(0);
String regionName = id.substring(2);
-
+
// Contains the names selected window in the UI
List selectedWindows = (List)assignedWindows.values.get(regionName);
- // Get the windows belonging to the selected region sorted by order
- List windows = new ArrayList();
- for (Iterator i = page.getChildren(PortalObject.WINDOW_MASK).iterator();
i.hasNext();)
+ Collection<PortalObject> children =
page.getChildren(PortalObject.WINDOW_MASK);
+ if (children != null)
{
- Window window = (Window)i.next();
- if (regionName.equals(window.getProperty(ThemeConstants.PORTAL_PROP_REGION)))
- {
- windows.add(window);
- }
- }
- Collections.sort(windows, new WindowComparator());
- //
- if (direction == MOVE_UP || direction == MOVE_DOWN)
- {
- //
- int index = direction == MOVE_UP ? 1 : windows.size() - 2;
- int length = windows.size() - 1;
- int step = direction == MOVE_UP ? 1 : -1;
-
- // Perform swaps
- while (length-- > 0)
+ // Get the windows belonging to the selected region sorted by order
+ List<Window> windows = new ArrayList<Window>(children.size());
+ for (Object o : children)
{
- Window window = (Window)windows.get(index);
- if (selectedWindows.contains(window.getName()))
+ Window window = (Window)o;
+ if
(regionName.equals(window.getProperty(ThemeConstants.PORTAL_PROP_REGION)))
{
- Collections.swap(windows, index - step, index);
+ windows.add(window);
}
- index += step;
}
- }
- else if (direction == ADD_ACTION)
- {
- if (selectedContentURI != null)
+ Collections.sort(windows, new WindowComparator());
+
+ //
+ if (direction == MOVE_UP || direction == MOVE_DOWN)
{
//
- String selectedContentURI = this.selectedContentURI;
- Map selectedContentParams = this.selectedContentParameters;
+ int index = direction == MOVE_UP ? 1 : windows.size() - 2;
+ int length = windows.size() - 1;
+ int step = direction == MOVE_UP ? 1 : -1;
- // Reset to new state
- this.selectedContentURI = null;
- this.selectedContentParameters = null;
- this.selectedRenderParameters = new HashMap();
-
- // Obtain a window name
- String windowName =
(String)FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap().get("blah");
- if (windowName.trim().length() == 0)
+ // Perform swaps
+ while (length-- > 0)
{
- windowName = createWindowName(selectedContentType.toString(),
selectedContentURI, false);
- while (page.getWindow(windowName) != null)
+ Window window = windows.get(index);
+ if (selectedWindows.contains(window.getName()))
{
- windowName = createWindowName(selectedContentType.toString(),
selectedContentURI, true);
+ Collections.swap(windows, index - step, index);
}
+ index += step;
}
-
- // Check for duplicate window name
- if (page.getWindow(windowName) != null)
+ }
+ else if (direction == ADD_ACTION)
+ {
+ if (selectedContentURI != null)
{
- FacesContext faces = FacesContext.getCurrentInstance();
- FacesMessage message = new FacesMessage(FacesMessage.SEVERITY_ERROR,
"Duplicate window name found on this page!", null);
- faces.addMessage("windowName", message);
- throw new AbortProcessingException();
- }
+ //
+ String selectedContentURI = this.selectedContentURI;
+ Map selectedContentParams = this.selectedContentParameters;
- //
- try
- {
- Window window = page.createWindow(windowName, selectedContentType,
selectedContentURI);
- Content content = window.getContent();
- for (Iterator i = selectedContentParams.entrySet().iterator();
i.hasNext();)
+ // Reset to new state
+ this.selectedContentURI = null;
+ this.selectedContentParameters = null;
+ this.selectedRenderParameters = new HashMap();
+
+ // Obtain a window name
+ String windowName =
(String)FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap().get("blah");
+ if (windowName.trim().length() == 0)
{
- Map.Entry entry = (Map.Entry)i.next();
- String paramName = (String)entry.getKey();
- String paramValue = (String)entry.getValue();
- content.setParameter(paramName, paramValue);
+ windowName = createWindowName(selectedContentType.toString(),
selectedContentURI, false);
+ while (page.getWindow(windowName) != null)
+ {
+ windowName = createWindowName(selectedContentType.toString(),
selectedContentURI, true);
+ }
}
+ // Check for duplicate window name
+ if (page.getWindow(windowName) != null)
+ {
+ FacesContext faces = FacesContext.getCurrentInstance();
+ FacesMessage message = new FacesMessage(FacesMessage.SEVERITY_ERROR,
"Duplicate window name found on this page!", null);
+ faces.addMessage("windowName", message);
+ throw new AbortProcessingException();
+ }
+
//
- window.setDeclaredProperty(ThemeConstants.PORTAL_PROP_REGION,
regionName);
- window.setDeclaredProperty(ThemeConstants.PORTAL_PROP_ORDER, ""
+ Integer.MAX_VALUE);
+ try
+ {
+ Window window = page.createWindow(windowName, selectedContentType,
selectedContentURI);
+ Content content = window.getContent();
+ for (Object o : selectedContentParams.entrySet())
+ {
+ Map.Entry<String,String> entry =
(Map.Entry<String,String>)o;
+ String paramName = entry.getKey();
+ String paramValue = entry.getValue();
+ content.setParameter(paramName, paramValue);
+ }
- // Sort windows
- Collections.sort(windows, new WindowComparator());
+ //
+ window.setDeclaredProperty(ThemeConstants.PORTAL_PROP_REGION,
regionName);
+ window.setDeclaredProperty(ThemeConstants.PORTAL_PROP_ORDER,
"" + Integer.MAX_VALUE);
- // Add the created one
- windows.add(window);
+ // Sort windows
+ Collections.sort(windows, new WindowComparator());
- // Update the order states
- for (int i = 0; i < windows.size(); i++)
+ // Add the created one
+ windows.add(window);
+
+ // Update the order states
+ for (int i = 0; i < windows.size(); i++)
+ {
+ Window tmp = windows.get(i);
+ tmp.setDeclaredProperty(ThemeConstants.PORTAL_PROP_ORDER,
"" + i);
+ }
+
+ this.windowName = "";
+ }
+ catch (DuplicatePortalObjectException unexpected)
{
- Window tmp = (Window)windows.get(i);
- tmp.setDeclaredProperty(ThemeConstants.PORTAL_PROP_ORDER, ""
+ i);
+ unexpected.printStackTrace();
}
-
- this.windowName = "";
}
- catch (DuplicatePortalObjectException unexpected)
+ else
{
- unexpected.printStackTrace();
+ FacesContext faces = FacesContext.getCurrentInstance();
+ FacesMessage message = new FacesMessage(FacesMessage.SEVERITY_ERROR,
"No content was selected!", null);
+ faces.addMessage("layoutForm", message);
+ throw new AbortProcessingException();
}
}
- else
+ else if (direction == MOVE_LEFT)
{
- FacesContext faces = FacesContext.getCurrentInstance();
- FacesMessage message = new FacesMessage(FacesMessage.SEVERITY_ERROR, "No
content was selected!", null);
- faces.addMessage("layoutForm", message);
- throw new AbortProcessingException();
- }
- }
- else if (direction == MOVE_LEFT)
- {
- for (Iterator i = windows.iterator(); i.hasNext();)
- {
- Window window = (Window)i.next();
- if (selectedWindows.contains(window.getName()))
+ for (Iterator i = windows.iterator(); i.hasNext();)
{
- i.remove();
- try
+ Window window = (Window)i.next();
+ if (selectedWindows.contains(window.getName()))
{
- page.destroyChild(window.getName());
+ i.remove();
+ try
+ {
+ page.destroyChild(window.getName());
+ }
+ catch (NoSuchPortalObjectException ignore)
+ {
+ ignore.printStackTrace();
+ }
}
- catch (NoSuchPortalObjectException ignore)
- {
- ignore.printStackTrace();
- }
}
}
- }
- // Update the order states
- for (int i = 0; i < windows.size(); i++)
- {
- Window window = (Window)windows.get(i);
- window.setDeclaredProperty(ThemeConstants.PORTAL_PROP_ORDER, "" + i);
+ // Update the order states
+ for (int i = 0; i < windows.size(); i++)
+ {
+ Window window = windows.get(i);
+ window.setDeclaredProperty(ThemeConstants.PORTAL_PROP_ORDER, "" +
i);
+ }
}
//
@@ -389,12 +404,17 @@
else if (event instanceof PortletEventEvent)
{
PortletEventEvent eventEvent = (PortletEventEvent)event;
- // TODO: Check the QName of the event
Event portletEvent = eventEvent.getEvent();
- String uri = (String)portletEvent.getPayload();
- this.selectedContentURI = uri;
- // TODO: Get params from the payload (for widgets)
- this.selectedContentParameters = new HashMap();
+ QName name = portletEvent.getName();
+ // only react to content selection events
+ if(CONTENT_SELECT.equals(name))
+ {
+ String uri = (String)portletEvent.getPayload();
+ this.selectedContentURI = uri;
+
+ // TODO: Get params from the payload (for widgets)
+ this.selectedContentParameters = new HashMap();
+ }
}
else if (event instanceof PortletActionEvent)
{
Modified:
branches/JBoss_Portal_Branch_2_7/core-admin/src/resources/portal-admin-war/jsf/common/editPageLayout.xhtml
===================================================================
---
branches/JBoss_Portal_Branch_2_7/core-admin/src/resources/portal-admin-war/jsf/common/editPageLayout.xhtml 2008-05-20
22:12:48 UTC (rev 10787)
+++
branches/JBoss_Portal_Branch_2_7/core-admin/src/resources/portal-admin-war/jsf/common/editPageLayout.xhtml 2008-05-20
23:05:27 UTC (rev 10788)
@@ -38,7 +38,7 @@
</tr>
<tr>
<td>
- <h:form id="abc">
+ <h:form id="contentTypesForm">
<label for="instanceId"
class="portlet-form-field-label-container">
<span class="portlet-form-field-label
admin-label">Content Type:</span>
<h:inputHidden id="windowNameCopy"
value="#{pageManager.windowName}"/>
@@ -46,8 +46,8 @@
id="instanceId"
value="#{pageManager.selectedContentType}"
styleClass="portlet-form-field contentType"
-
onchange="document.getElementById('abc:windowNameCopy').value =
document.getElementsByClassName('id-window-name')[0].value;
- document.getElementById('abc').submit();
">
+
onchange="document.getElementById('#{pageManager.namespace}:contentTypesForm:windowNameCopy').value
=
document.getElementById('#{pageManager.namespace}:windowForm:windowName').value;
+
document.getElementById('#{pageManager.namespace}:contentTypesForm').submit();
">
<f:selectItems
value="#{pageManager.contentTypeItems}"/>
</h:selectOneMenu>
</label>
@@ -73,7 +73,7 @@
initialMode="edit_content"
initialWindowState="normal"
renderParameters="#{pageManager.selectedRenderParameters}"
- onClick="url.setParameter('windowName',
document.getElementsByClassName('id-window-name')[0].value);"/>
+ onClick="url.setParameter('windowName',
document.getElementById('#{pageManager.namespace}:windowForm:windowName').value);"/>
</td>
</tr>
</table>
@@ -102,7 +102,7 @@
<tr>
<td valign="top">
<h:commandButton
-
onclick="document.getElementById('blah').value=document.getElementsByClassName('id-window-name')[0].value"
+
onclick="document.getElementById('blah').value=document.getElementById('#{pageManager.namespace}:windowForm:windowName').value"
value="Add" id="a_#{regionName}"
actionListener="#{pageManager.assignWindows}"
styleClass="portlet-form-button layout-button"/>