[jboss-cvs] jboss-portal/core/src/main/org/jboss/portal/core/portlet/management ...
Boleslaw Dawidowicz
bdaw at o2.pl
Tue Jul 25 16:54:01 EDT 2006
User: bdaw
Date: 06/07/25 16:54:01
Modified: core/src/main/org/jboss/portal/core/portlet/management
InstanceManagerBean.java PortletManagerBean.java
Log:
management portlet - pagination and sorting of portlets and instances
Revision Changes Path
1.31 +126 -13 jboss-portal/core/src/main/org/jboss/portal/core/portlet/management/InstanceManagerBean.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: InstanceManagerBean.java
===================================================================
RCS file: /cvsroot/jboss/jboss-portal/core/src/main/org/jboss/portal/core/portlet/management/InstanceManagerBean.java,v
retrieving revision 1.30
retrieving revision 1.31
diff -u -b -r1.30 -r1.31
--- InstanceManagerBean.java 26 Jun 2006 15:01:35 -0000 1.30
+++ InstanceManagerBean.java 25 Jul 2006 20:54:01 -0000 1.31
@@ -23,6 +23,7 @@
import org.jboss.logging.Logger;
import org.jboss.portal.common.util.Tools;
+import org.jboss.portal.common.util.LocalizedString;
import org.jboss.portal.common.value.Value;
import org.jboss.portal.common.value.ValueMap;
import org.jboss.portal.core.model.instance.Instance;
@@ -36,7 +37,9 @@
import org.jboss.portal.identity.RoleModule;
import org.jboss.portal.portlet.Portlet;
import org.jboss.portal.portlet.PortletInvokerException;
+import org.jboss.portal.portlet.container.PortletContainer;
import org.jboss.portal.portlet.info.PreferencesInfo;
+import org.jboss.portal.portlet.info.MetaInfo;
import org.jboss.portal.security.AuthorizationDomainRegistry;
import org.jboss.portal.security.SecurityConstants;
import org.jboss.portal.security.spi.provider.DomainConfigurator;
@@ -50,45 +53,91 @@
import java.util.List;
import java.util.Map;
import java.util.Set;
+import java.util.Comparator;
+import java.util.Collections;
+import java.util.Locale;
/**
* @author <a href="mailto:julien at jboss.org">Julien Viet</a>
- * @version $Revision: 1.30 $
+ * @author <a href="mailto:boleslaw dot dawidowicz at jboss.org">Boleslaw Dawidowicz</a>
+ * @version $Revision: 1.31 $
*/
public class InstanceManagerBean
{
- /** . */
+ /**
+ * .
+ */
private Logger log = Logger.getLogger(getClass());
- /** . */
+ /**
+ * .
+ */
private InstanceContainer instanceContainer;
- /** . */
+ /**
+ * .
+ */
private String selectedId;
- /** . */
+ /**
+ * .
+ */
private String selectedPlugin;
- /** . */
+ /**
+ * .
+ */
private AuthorizationDomainRegistry authorizationDomainRegistry;
- /** . */
+ /**
+ * .
+ */
private RoleModule roleModule;
- /** . */
+ /**
+ * .
+ */
private PreferencesBean selectedPreferences;
- /** . */
+ /**
+ * .
+ */
private AbstractAuthorizationBean auth = new AuthorizationBean();
- /** . */
+ /**
+ * .
+ */
private Integer selectedRow;
+ private String sortColumn;
+
+ private boolean sortAscending;
+
public InstanceManagerBean()
{
}
+ public String getSortColumn()
+ {
+ return sortColumn;
+ }
+
+ public void setSortColumn(String sortColumn)
+ {
+ this.sortColumn = sortColumn;
+ }
+
+ public boolean getSortAscending()
+ {
+ return sortAscending;
+ }
+
+ public void setSortAscending(boolean sortAscending)
+ {
+ this.sortAscending = sortAscending;
+ }
+
public Integer getSelectedRow()
{
return selectedRow;
@@ -183,7 +232,9 @@
return auth;
}
- /** Return an array of all instances known in this container. */
+ /**
+ * Return an array of all instances known in this container.
+ */
public Collection getInstances()
{
List instances = new ArrayList();
@@ -206,6 +257,17 @@
+ ". This instance won't be listed.\nReason:\n\t" + e.getLocalizedMessage());
}
}
+
+ try
+ {
+ sortInstances(instances, sortColumn, sortAscending);
+ }
+ catch (Exception e)
+ {
+ log.info("Error during sorting instances: ");
+ e.printStackTrace();
+ }
+
return instances;
}
@@ -252,7 +314,9 @@
}
}
- /** Refresh the selected prefs. */
+ /**
+ * Refresh the selected prefs.
+ */
public void refresh()
{
selectedPreferences = null;
@@ -331,6 +395,55 @@
}
}
+ public static void sortInstances(List instances, final String column, final boolean ascending)
+ {
+ Comparator comparator = new Comparator()
+ {
+ public int compare(Object o1, Object o2)
+ {
+
+
+ if (column == null)
+ {
+ return 0;
+ }
+ if (column.equals("id"))
+ {
+ Instance i1 = (Instance)((Object[])o1)[0];
+ Instance i2 = (Instance)((Object[])o2)[0];
+ return ascending ? i1.getId().compareToIgnoreCase(i2.getId()) : i2.getId()
+ .compareToIgnoreCase(i1.getId());
+ }
+ if (column.equals("portlet"))
+ {
+ Portlet p1 = (Portlet)((Object[])o1)[1];
+ Portlet p2 = (Portlet)((Object[])o2)[1];
+
+ LocalizedString displayName = p1.getInfo().getMeta().getMetaValue(MetaInfo.DISPLAY_NAME);
+ FacesContext ctx = FacesContext.getCurrentInstance();
+ Locale locale = ctx.getExternalContext().getRequestLocale();
+ String name1 = displayName.getString(locale, true);
+ displayName = p2.getInfo().getMeta().getMetaValue(MetaInfo.DISPLAY_NAME);
+ String name2 = displayName.getString(locale, true);
+
+ if (name1 == null || name2 == null)
+ {
+ return 0;
+ }
+
+ return ascending ? name1.compareToIgnoreCase(name2) : name2
+ .compareToIgnoreCase(name1);
+ }
+
+ else
+ {
+ return 0;
+ }
+ }
+ };
+ Collections.sort(instances, comparator);
+ }
+
public class AuthorizationBean extends AbstractAuthorizationBean
{
@@ -379,7 +492,7 @@
public SelectItem[] getAvailableActions()
{
- return new SelectItem[] {
+ return new SelectItem[]{
new SelectItem("view")
};
}
1.30 +150 -13 jboss-portal/core/src/main/org/jboss/portal/core/portlet/management/PortletManagerBean.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: PortletManagerBean.java
===================================================================
RCS file: /cvsroot/jboss/jboss-portal/core/src/main/org/jboss/portal/core/portlet/management/PortletManagerBean.java,v
retrieving revision 1.29
retrieving revision 1.30
diff -u -b -r1.29 -r1.30
--- PortletManagerBean.java 26 Jun 2006 15:01:35 -0000 1.29
+++ PortletManagerBean.java 25 Jul 2006 20:54:01 -0000 1.30
@@ -23,8 +23,10 @@
import org.jboss.logging.Logger;
import org.jboss.portal.common.util.Tools;
+import org.jboss.portal.common.util.LocalizedString;
import org.jboss.portal.common.value.Value;
import org.jboss.portal.core.model.instance.InstanceContainer;
+import org.jboss.portal.core.model.instance.Instance;
import org.jboss.portal.faces.matrix.Cell;
import org.jboss.portal.faces.matrix.Row;
import org.jboss.portal.faces.matrix.RowSetModel;
@@ -36,6 +38,7 @@
import org.jboss.portal.portlet.PortletInvokerException;
import org.jboss.portal.portlet.info.PreferenceInfo;
import org.jboss.portal.portlet.info.PreferencesInfo;
+import org.jboss.portal.portlet.info.MetaInfo;
import org.jboss.portal.security.AuthorizationDomainRegistry;
import org.jboss.portal.security.SecurityConstants;
import org.jboss.portal.security.spi.provider.DomainConfigurator;
@@ -52,44 +55,90 @@
import java.util.Map;
import java.util.Set;
import java.util.Locale;
+import java.util.Comparator;
/**
* @author <a href="mailto:julien at jboss.org">Julien Viet</a>
- * @version $Revision: 1.29 $
+ * @author <a href="mailto:boleslaw dot dawidowicz at jboss.org">Boleslaw Dawidowicz</a>
+ * @version $Revision: 1.30 $
*/
public class PortletManagerBean
{
- /** . */
+ /**
+ * .
+ */
private Logger log = Logger.getLogger(getClass());
- /** . */
+ /**
+ * .
+ */
private InstanceContainer instanceContainer;
- /** . */
+ /**
+ * .
+ */
private AuthorizationDomainRegistry authorizationDomainRegistry;
- /** . */
+ /**
+ * .
+ */
private String selectedPortletId;
- /** The current tab name. */
+ /**
+ * The current tab name.
+ */
private String selectedPlugin;
- /** . */
+ /**
+ * .
+ */
private RoleModule roleModule;
- /** . */
+ /**
+ * .
+ */
private PreferencesBean selectedPreferences;
- /** . */
+ /**
+ * .
+ */
private String selectedFederatedId;
- /** . */
+ /**
+ * .
+ */
private AbstractAuthorizationBean auth = new AuthorizationBean();
- /** . */
+ /**
+ * .
+ */
private FederatingPortletInvoker federatingPortletInvoker;
+ private String sortColumn;
+
+ private boolean sortAscending;
+
+ public String getSortColumn()
+ {
+ return sortColumn;
+ }
+
+ public void setSortColumn(String sortColumn)
+ {
+ this.sortColumn = sortColumn;
+ }
+
+ public boolean getSortAscending()
+ {
+ return sortAscending;
+ }
+
+ public void setSortAscending(boolean sortAscending)
+ {
+ this.sortAscending = sortAscending;
+ }
+
public RoleModule getRoleModule()
{
return roleModule;
@@ -182,6 +231,17 @@
{
log.warn("Couldn't access portlet invoker. Portlets won't be listed.\nReason:\n\t" + e.getLocalizedMessage());
}
+
+ try
+ {
+ sortPortlets(portlets, sortColumn, sortAscending);
+ }
+ catch (Exception e)
+ {
+ log.info("Error during sorting portlets: ");
+ e.printStackTrace();
+ }
+
return portlets;
}
@@ -244,7 +304,9 @@
return selectedPreferences;
}
- /** Refresh the selected prefs if they are available. */
+ /**
+ * Refresh the selected prefs if they are available.
+ */
public void refresh()
{
selectedPreferences = null;
@@ -300,6 +362,81 @@
}
}
+ public static void sortPortlets(List portlets, final String column, final boolean ascending)
+ {
+ Comparator comparator = new Comparator()
+ {
+ public int compare(Object o1, Object o2)
+ {
+ Portlet p1 = (Portlet)o1;
+ Portlet p2 = (Portlet)o2;
+
+ if (p1 == null || p2 == null)
+ {
+ return 0;
+ }
+
+ if (column == null)
+ {
+ return 0;
+ }
+ if (column.equals("id"))
+ {
+ return ascending ? p1.getId().compareToIgnoreCase(p2.getId()) : p2.getId()
+ .compareToIgnoreCase(p1.getId());
+ }
+ if (column.equals("name"))
+ {
+
+ LocalizedString displayName = p1.getInfo().getMeta().getMetaValue(MetaInfo.DISPLAY_NAME);
+ FacesContext ctx = FacesContext.getCurrentInstance();
+ Locale locale = ctx.getExternalContext().getRequestLocale();
+ String name1 = displayName.getString(locale, true);
+ if (name1 == null)
+ {
+ name1 = "";
+ }
+ displayName = p2.getInfo().getMeta().getMetaValue(MetaInfo.DISPLAY_NAME);
+ String name2 = displayName.getString(locale, true);
+ if (name2 == null)
+ {
+ name2 = "";
+ }
+
+ return ascending ? name1.compareToIgnoreCase(name2) : name2
+ .compareToIgnoreCase(name1);
+ }
+
+ if (column.equals("description"))
+ {
+ LocalizedString displayName = p1.getInfo().getMeta().getMetaValue(MetaInfo.DESCRIPTION);
+ FacesContext ctx = FacesContext.getCurrentInstance();
+ Locale locale = ctx.getExternalContext().getRequestLocale();
+ String name1 = displayName.getString(locale, true);
+ if (name1 == null)
+ {
+ name1 = "-";
+ }
+ displayName = p2.getInfo().getMeta().getMetaValue(MetaInfo.DESCRIPTION);
+ String name2 = displayName.getString(locale, true);
+ if (name2 == null)
+ {
+ name2 = "-";
+ }
+
+ return ascending ? name1.compareToIgnoreCase(name2) : name2
+ .compareToIgnoreCase(name1);
+ }
+
+ else
+ {
+ return 0;
+ }
+ }
+ };
+ Collections.sort(portlets, comparator);
+ }
+
public class AuthorizationBean extends AbstractAuthorizationBean
{
@@ -342,7 +479,7 @@
public SelectItem[] getAvailableActions()
{
- return new SelectItem[] {
+ return new SelectItem[]{
new SelectItem("view")
};
}
More information about the jboss-cvs-commits
mailing list