continuum-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From batkin...@apache.org
Subject svn commit: r1662336 - in /continuum/trunk/continuum-webapp/src/main: java/org/apache/maven/continuum/web/util/StateGenerator.java java/org/apache/maven/continuum/web/view/StateCell.java webapp/images/icon_unknown_sml.gif
Date Thu, 26 Feb 2015 00:10:43 GMT
Author: batkinson
Date: Thu Feb 26 00:10:42 2015
New Revision: 1662336

URL: http://svn.apache.org/r1662336
Log:
Simplified and improved build state icon generation.

Added:
    continuum/trunk/continuum-webapp/src/main/webapp/images/icon_unknown_sml.gif
Modified:
    continuum/trunk/continuum-webapp/src/main/java/org/apache/maven/continuum/web/util/StateGenerator.java
    continuum/trunk/continuum-webapp/src/main/java/org/apache/maven/continuum/web/view/StateCell.java

Modified: continuum/trunk/continuum-webapp/src/main/java/org/apache/maven/continuum/web/util/StateGenerator.java
URL: http://svn.apache.org/viewvc/continuum/trunk/continuum-webapp/src/main/java/org/apache/maven/continuum/web/util/StateGenerator.java?rev=1662336&r1=1662335&r2=1662336&view=diff
==============================================================================
--- continuum/trunk/continuum-webapp/src/main/java/org/apache/maven/continuum/web/util/StateGenerator.java
(original)
+++ continuum/trunk/continuum-webapp/src/main/java/org/apache/maven/continuum/web/util/StateGenerator.java
Thu Feb 26 00:10:42 2015
@@ -21,6 +21,9 @@ package org.apache.maven.continuum.web.u
 
 import org.apache.maven.continuum.project.ContinuumProjectState;
 
+import java.util.HashMap;
+import java.util.Map;
+
 /**
  * @author <a href="mailto:evenisse@apache.org">Emmanuel Venisse</a>
  */
@@ -34,53 +37,54 @@ public class StateGenerator
 
     public static final String ERROR = "Error";
 
+    public static final String CANCELLED = "Canceled";
+
     public static final String BUILDING = "Building";
 
     public static final String UPDATING = "Updating";
 
+    public static final String UPDATED = "Updated";
+
     public static final String CHECKING_OUT = "Checking Out";
 
+    public static final String CHECKED_OUT = "Checked Out";
+
+    public static final int UNKNOWN_STATE = Integer.MIN_VALUE;
+
     public static final String UNKNOWN = "Unknown";
 
+    public static final Map<Integer, String[]> stateIconArgs = new HashMap<Integer,
String[]>();
+
+    static
+    {
+        stateIconArgs.put( ContinuumProjectState.OK, new String[] { "/images/icon_success_sml.gif",
SUCCESS } );
+        stateIconArgs.put( ContinuumProjectState.UPDATED, new String[] { "/images/icon_success_sml.gif",
UPDATED } );
+        stateIconArgs.put( ContinuumProjectState.FAILED, new String[] { "/images/icon_warning_sml.gif",
FAILED } );
+        stateIconArgs.put( ContinuumProjectState.ERROR, new String[] { "/images/icon_error_sml.gif",
ERROR } );
+        stateIconArgs.put( ContinuumProjectState.BUILDING, new String[] { "/images/building.gif",
BUILDING } );
+        stateIconArgs.put( ContinuumProjectState.UPDATING, new String[] { "/images/checkingout.gif",
UPDATING } );
+        stateIconArgs.put( ContinuumProjectState.CHECKING_OUT,
+                           new String[] { "/images/checkingout.gif", CHECKING_OUT } );
+        stateIconArgs.put( ContinuumProjectState.CHECKEDOUT,
+                           new String[] { "/images/icon_success_sml.gif", CHECKED_OUT } );
+        stateIconArgs.put( ContinuumProjectState.CANCELLED,
+                           new String[] { "/images/icon_unknown_sml.gif", CANCELLED } );
+    }
+
     public static String generate( int state, String contextPath )
     {
+        String iconFmt = "<img src=\"" + contextPath + "%s\" alt=\"%2$s\" title=\"%2$s\"
border=\"0\" />";
+
         if ( state == ContinuumProjectState.NEW )
         {
             return NEW;
         }
-        else if ( state == ContinuumProjectState.OK || state == ContinuumProjectState.UPDATED
)
-        {
-            return "<img src=\"" + contextPath + "/images/icon_success_sml.gif\" alt=\""
+ SUCCESS + "\" title=\"" +
-                SUCCESS + "\" border=\"0\" />";
-        }
-        else if ( state == ContinuumProjectState.FAILED )
-        {
-            return "<img src=\"" + contextPath + "/images/icon_warning_sml.gif\" alt=\""
+ FAILED + "\" title=\"" +
-                FAILED + "\" border=\"0\" />";
-        }
-        else if ( state == ContinuumProjectState.ERROR )
-        {
-            return "<img src=\"" + contextPath + "/images/icon_error_sml.gif\" alt=\""
+ ERROR + "\" title=\"" + ERROR +
-                "\" border=\"0\" />";
-        }
-        else if ( state == ContinuumProjectState.BUILDING )
-        {
-            return "<img src=\"" + contextPath + "/images/building.gif\" alt=\"" + BUILDING
+ "\" title=\"" + BUILDING +
-                "\" border=\"0\" />";
-        }
-        else if ( state == ContinuumProjectState.UPDATING )
-        {
-            return "<img src=\"" + contextPath + "/images/checkingout.gif\" alt=\"" +
UPDATING + "\" title=\"" +
-                UPDATING + "\" border=\"0\" />";
-        }
-        else if ( state == ContinuumProjectState.CHECKING_OUT )
-        {
-            return "<img src=\"" + contextPath + "/images/checkingout.gif\" alt=\"" +
CHECKING_OUT + "\" title=\"" +
-                CHECKING_OUT + "\" border=\"0\" />";
-        }
-        else
+
+        if ( stateIconArgs.containsKey( state ) )
         {
-            return UNKNOWN;
+            return String.format( iconFmt, stateIconArgs.get( state ) );
         }
+
+        return String.format( iconFmt, "/images/icon_unknown_sml.gif", UNKNOWN );
     }
 }

Modified: continuum/trunk/continuum-webapp/src/main/java/org/apache/maven/continuum/web/view/StateCell.java
URL: http://svn.apache.org/viewvc/continuum/trunk/continuum-webapp/src/main/java/org/apache/maven/continuum/web/view/StateCell.java?rev=1662336&r1=1662335&r2=1662336&view=diff
==============================================================================
--- continuum/trunk/continuum-webapp/src/main/java/org/apache/maven/continuum/web/view/StateCell.java
(original)
+++ continuum/trunk/continuum-webapp/src/main/java/org/apache/maven/continuum/web/view/StateCell.java
Thu Feb 26 00:10:42 2015
@@ -19,8 +19,7 @@ package org.apache.maven.continuum.web.v
  * under the License.
  */
 
-import java.util.HashMap;
-
+import com.opensymphony.xwork2.ActionContext;
 import org.apache.continuum.model.project.ProjectScmRoot;
 import org.apache.maven.continuum.project.ContinuumProjectState;
 import org.apache.maven.continuum.security.ContinuumRoleConstants;
@@ -39,7 +38,7 @@ import org.extremecomponents.table.bean.
 import org.extremecomponents.table.cell.DisplayCell;
 import org.extremecomponents.table.core.TableModel;
 
-import com.opensymphony.xwork2.ActionContext;
+import java.util.HashMap;
 
 /**
  * Used in Summary view
@@ -53,84 +52,33 @@ public class StateCell
 {
     protected String getCellValue( TableModel tableModel, Column column )
     {
+        String contextPath = tableModel.getContext().getContextPath();
+
         if ( tableModel.getCurrentRowBean() instanceof ProjectSummary )
         {
             ProjectSummary project = (ProjectSummary) tableModel.getCurrentRowBean();
-
-            switch ( project.getState() )
+            String state = StateGenerator.generate( project.getState(), contextPath );
+            if ( project.getLatestBuildId() != -1 && !StateGenerator.NEW.equals(
state ) &&
+                project.getState() != ContinuumProjectState.UPDATING && isAuthorized(
project.getProjectGroupName() ) )
             {
-                case ContinuumProjectState.NEW:
-                case ContinuumProjectState.OK:
-                case ContinuumProjectState.FAILED:
-                case ContinuumProjectState.ERROR:
-                case ContinuumProjectState.BUILDING:
-                case ContinuumProjectState.UPDATING:
-                case ContinuumProjectState.CHECKING_OUT:
-                {
-                    String state = StateGenerator.generate( project.getState(),
-                                                            tableModel.getContext().getContextPath()
);
-
-                    if ( project.getLatestBuildId() != -1 && !StateGenerator.NEW.equals(
state ) &&
-                        project.getState() != ContinuumProjectState.UPDATING )
-                    {
-                        if ( isAuthorized( project.getProjectGroupName() ) )
-                        {
-                            return createActionLink( "buildResult", project, state );
-                        }
-                        else
-                        {
-                            return state;
-                        }
-                    }
-                    else
-                    {
-                        return state;
-                    }
-                }
-
-                default:
-                {
-                    return "&nbsp;";
-                }
+                return createActionLink( "buildResult", project, state );
             }
+            return state;
         }
-        else
+
+        if ( tableModel.getCurrentRowBean() instanceof ProjectScmRoot )
         {
             ProjectScmRoot projectScmRoot = (ProjectScmRoot) tableModel.getCurrentRowBean();
-
-            switch ( projectScmRoot.getState() )
+            String state = StateGenerator.generate( projectScmRoot.getState(), contextPath
);
+            if ( !StateGenerator.NEW.equals( state ) && isAuthorized( projectScmRoot.getProjectGroup().getName()
) &&
+                projectScmRoot.getState() == ContinuumProjectState.ERROR )
             {
-                case ContinuumProjectState.UPDATING:
-                case ContinuumProjectState.UPDATED:
-                case ContinuumProjectState.ERROR:
-                {
-                    String state = StateGenerator.generate( projectScmRoot.getState(),
-                                                            tableModel.getContext().getContextPath()
);
-
-                    if ( !StateGenerator.NEW.equals( state ) )
-                    {
-                        if ( isAuthorized( projectScmRoot.getProjectGroup().getName() ) &&
-                            projectScmRoot.getState() == ContinuumProjectState.ERROR )
-                        {
-                            return createActionLink( "scmResult", projectScmRoot, state );
-                        }
-                        else
-                        {
-                            return state;
-                        }
-                    }
-                    else
-                    {
-                        return state;
-                    }
-                }
-
-                default:
-                {
-                    return "&nbsp;";
-                }
+                return createActionLink( "scmResult", projectScmRoot, state );
             }
+            return state;
         }
+
+        return StateGenerator.generate( StateGenerator.UNKNOWN_STATE, contextPath );
     }
 
     private static String createActionLink( String action, ProjectSummary project, String
state )

Added: continuum/trunk/continuum-webapp/src/main/webapp/images/icon_unknown_sml.gif
URL: http://svn.apache.org/viewvc/continuum/trunk/continuum-webapp/src/main/webapp/images/icon_unknown_sml.gif?rev=1662336&view=auto
==============================================================================
Binary files continuum/trunk/continuum-webapp/src/main/webapp/images/icon_unknown_sml.gif
(added) and continuum/trunk/continuum-webapp/src/main/webapp/images/icon_unknown_sml.gif Thu
Feb 26 00:10:42 2015 differ



Mime
View raw message