From f203e31d00258195d55ddd7950a884fa21e800fb Mon Sep 17 00:00:00 2001 From: Michael Hirsch Date: Thu, 28 Apr 2016 16:20:13 +0200 Subject: [PATCH] use constants for html tags used often Signed-off-by: Michael Hirsch --- .../CreateOrUpdateFilterTable.java | 41 +++++++++++-------- .../management/targettable/TargetTable.java | 41 +++++++++++-------- .../ui/rollout/rollout/RolloutListGrid.java | 37 +++++++++-------- .../hawkbit/ui/utils/HawkbitCommonUtil.java | 5 +++ 4 files changed, 72 insertions(+), 52 deletions(-) diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/filtermanagement/CreateOrUpdateFilterTable.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/filtermanagement/CreateOrUpdateFilterTable.java index cf8a514d4..debd35056 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/filtermanagement/CreateOrUpdateFilterTable.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/filtermanagement/CreateOrUpdateFilterTable.java @@ -8,6 +8,11 @@ */ package org.eclipse.hawkbit.ui.filtermanagement; +import static org.eclipse.hawkbit.ui.utils.HawkbitCommonUtil.HTML_LI_CLOSE_TAG; +import static org.eclipse.hawkbit.ui.utils.HawkbitCommonUtil.HTML_LI_OPEN_TAG; +import static org.eclipse.hawkbit.ui.utils.HawkbitCommonUtil.HTML_UL_CLOSE_TAG; +import static org.eclipse.hawkbit.ui.utils.HawkbitCommonUtil.HTML_UL_OPEN_TAG; + import java.util.ArrayList; import java.util.Date; import java.util.HashMap; @@ -263,7 +268,7 @@ public class CreateOrUpdateFilterTable extends Table { private static final long serialVersionUID = 688730421728162456L; @Override - public String generateDescription(Component source, Object itemId, Object propertyId) { + public String generateDescription(final Component source, final Object itemId, final Object propertyId) { final DistributionSet distributionSet; final Item item = getItem(itemId); if (propertyId != null) { @@ -279,35 +284,35 @@ public class CreateOrUpdateFilterTable extends Table { } private String getDSDetails(final DistributionSet distributionSet) { - StringBuilder swModuleNames = new StringBuilder(); - StringBuilder swModuleVendors = new StringBuilder(); - final Set swModules = (Set) distributionSet.getModules(); + final StringBuilder swModuleNames = new StringBuilder(); + final StringBuilder swModuleVendors = new StringBuilder(); + final Set swModules = distributionSet.getModules(); swModules.forEach(swModule -> { swModuleNames.append(swModule.getName()); swModuleNames.append(" , "); swModuleVendors.append(swModule.getVendor()); swModuleVendors.append(" , "); }); - StringBuilder stringBuilder = new StringBuilder(); - stringBuilder.append("
    "); - stringBuilder.append("
  • "); - stringBuilder.append(" DistributionSet Description : ").append((String) distributionSet.getDescription()); - stringBuilder.append("
  • "); - stringBuilder.append("
  • "); + final StringBuilder stringBuilder = new StringBuilder(); + stringBuilder.append(HTML_UL_OPEN_TAG); + stringBuilder.append(HTML_LI_OPEN_TAG); + stringBuilder.append(" DistributionSet Description : ").append(distributionSet.getDescription()); + stringBuilder.append(HTML_LI_CLOSE_TAG); + stringBuilder.append(HTML_LI_OPEN_TAG); stringBuilder.append(" DistributionSet Type : ").append((distributionSet.getType()).getName()); - stringBuilder.append("
  • "); - stringBuilder.append("
  • "); + stringBuilder.append(HTML_LI_CLOSE_TAG); + stringBuilder.append(HTML_LI_OPEN_TAG); stringBuilder.append(" Required Migration step : ") .append(distributionSet.isRequiredMigrationStep() ? "Yes" : "No"); - stringBuilder.append("
  • "); - stringBuilder.append("
  • "); + stringBuilder.append(HTML_LI_CLOSE_TAG); + stringBuilder.append(HTML_LI_OPEN_TAG); stringBuilder.append("SoftWare Modules : ").append(swModuleNames.toString()); - stringBuilder.append("
  • "); - stringBuilder.append("
  • "); + stringBuilder.append(HTML_LI_CLOSE_TAG); + stringBuilder.append(HTML_LI_OPEN_TAG); stringBuilder.append("Vendor(s) : ").append(swModuleVendors.toString()); - stringBuilder.append("
  • "); + stringBuilder.append(HTML_LI_CLOSE_TAG); - stringBuilder.append("
"); + stringBuilder.append(HTML_UL_CLOSE_TAG); return stringBuilder.toString(); } diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/targettable/TargetTable.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/targettable/TargetTable.java index a1e759950..0055e06e4 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/targettable/TargetTable.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/targettable/TargetTable.java @@ -8,6 +8,11 @@ */ package org.eclipse.hawkbit.ui.management.targettable; +import static org.eclipse.hawkbit.ui.utils.HawkbitCommonUtil.HTML_LI_CLOSE_TAG; +import static org.eclipse.hawkbit.ui.utils.HawkbitCommonUtil.HTML_LI_OPEN_TAG; +import static org.eclipse.hawkbit.ui.utils.HawkbitCommonUtil.HTML_UL_CLOSE_TAG; +import static org.eclipse.hawkbit.ui.utils.HawkbitCommonUtil.HTML_UL_OPEN_TAG; + import java.util.ArrayList; import java.util.Collection; import java.util.Collections; @@ -1089,7 +1094,7 @@ public class TargetTable extends AbstractTable implements private static final long serialVersionUID = 688730421728162456L; @Override - public String generateDescription(Component source, Object itemId, Object propertyId) { + public String generateDescription(final Component source, final Object itemId, final Object propertyId) { final DistributionSet distributionSet; final Item item = getItem(itemId); if (propertyId != null) { @@ -1105,34 +1110,34 @@ public class TargetTable extends AbstractTable implements } private String getDSDetails(final DistributionSet distributionSet) { - StringBuilder swModuleNames = new StringBuilder(); - StringBuilder swModuleVendors = new StringBuilder(); - final Set swModules = (Set) distributionSet.getModules(); + final StringBuilder swModuleNames = new StringBuilder(); + final StringBuilder swModuleVendors = new StringBuilder(); + final Set swModules = distributionSet.getModules(); swModules.forEach(swModule -> { swModuleNames.append(swModule.getName()); swModuleNames.append(" , "); swModuleVendors.append(swModule.getVendor()); swModuleVendors.append(" , "); }); - StringBuilder stringBuilder = new StringBuilder(); - stringBuilder.append("
    "); - stringBuilder.append("
  • "); - stringBuilder.append(" DistributionSet Description : ").append((String) distributionSet.getDescription()); - stringBuilder.append("
  • "); - stringBuilder.append("
  • "); + final StringBuilder stringBuilder = new StringBuilder(); + stringBuilder.append(HTML_UL_OPEN_TAG); + stringBuilder.append(HTML_LI_OPEN_TAG); + stringBuilder.append(" DistributionSet Description : ").append(distributionSet.getDescription()); + stringBuilder.append(HTML_LI_CLOSE_TAG); + stringBuilder.append(HTML_LI_OPEN_TAG); stringBuilder.append(" DistributionSet Type : ").append((distributionSet.getType()).getName()); - stringBuilder.append("
  • "); - stringBuilder.append("
  • "); + stringBuilder.append(HTML_LI_CLOSE_TAG); + stringBuilder.append(HTML_LI_OPEN_TAG); stringBuilder.append(" Required Migration step : ") .append(distributionSet.isRequiredMigrationStep() ? "Yes" : "No"); - stringBuilder.append("
  • "); - stringBuilder.append("
  • "); + stringBuilder.append(HTML_LI_CLOSE_TAG); + stringBuilder.append(HTML_LI_OPEN_TAG); stringBuilder.append("SoftWare Modules : ").append(swModuleNames.toString()); - stringBuilder.append("
  • "); - stringBuilder.append("
  • "); + stringBuilder.append(HTML_LI_CLOSE_TAG); + stringBuilder.append(HTML_LI_OPEN_TAG); stringBuilder.append("Vendor(s) : ").append(swModuleVendors.toString()); - stringBuilder.append("
  • "); - stringBuilder.append("
"); + stringBuilder.append(HTML_LI_CLOSE_TAG); + stringBuilder.append(HTML_UL_CLOSE_TAG); return stringBuilder.toString(); } } diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rollout/RolloutListGrid.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rollout/RolloutListGrid.java index 1ad0bfc35..7f3877a9a 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rollout/RolloutListGrid.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rollout/RolloutListGrid.java @@ -8,6 +8,11 @@ */ package org.eclipse.hawkbit.ui.rollout.rollout; +import static org.eclipse.hawkbit.ui.utils.HawkbitCommonUtil.HTML_LI_CLOSE_TAG; +import static org.eclipse.hawkbit.ui.utils.HawkbitCommonUtil.HTML_LI_OPEN_TAG; +import static org.eclipse.hawkbit.ui.utils.HawkbitCommonUtil.HTML_UL_CLOSE_TAG; +import static org.eclipse.hawkbit.ui.utils.HawkbitCommonUtil.HTML_UL_OPEN_TAG; + import java.util.ArrayList; import java.util.Arrays; import java.util.EnumMap; @@ -477,14 +482,14 @@ public class RolloutListGrid extends AbstractGrid { return DistributionBarHelper .getTooltip(((TotalTargetCountStatus) cell.getValue()).getStatusTotalCountMap()); } else if (SPUILabelDefinitions.VAR_DIST_NAME_VERSION.equals(cell.getPropertyId())) { - return getDSDetails((Item) cell.getItem()); + return getDSDetails(cell.getItem()); } return null; } private String getDSDetails(final Item rolloutItem) { - StringBuilder swModuleNames = new StringBuilder(); - StringBuilder swModuleVendors = new StringBuilder(); + final StringBuilder swModuleNames = new StringBuilder(); + final StringBuilder swModuleVendors = new StringBuilder(); final Set swModules = (Set) rolloutItem.getItemProperty(SW_MODULES).getValue(); swModules.forEach(swModule -> { swModuleNames.append(swModule.getName()); @@ -492,30 +497,30 @@ public class RolloutListGrid extends AbstractGrid { swModuleVendors.append(swModule.getVendor()); swModuleVendors.append(" , "); }); - StringBuilder stringBuilder = new StringBuilder(); - stringBuilder.append("
    "); - stringBuilder.append("
  • "); + final StringBuilder stringBuilder = new StringBuilder(); + stringBuilder.append(HTML_UL_OPEN_TAG); + stringBuilder.append(HTML_LI_OPEN_TAG); stringBuilder.append(" DistributionSet Description : ") .append((String) rolloutItem.getItemProperty(SPUILabelDefinitions.VAR_DESC).getValue()); - stringBuilder.append("
  • "); - stringBuilder.append("
  • "); + stringBuilder.append(HTML_LI_CLOSE_TAG); + stringBuilder.append(HTML_LI_OPEN_TAG); stringBuilder.append(" DistributionSet Type : ") .append((String) rolloutItem.getItemProperty(DS_TYPE).getValue()); - stringBuilder.append("
  • "); - stringBuilder.append("
  • "); + stringBuilder.append(HTML_LI_CLOSE_TAG); + stringBuilder.append(HTML_LI_OPEN_TAG); stringBuilder.append("Required Migration step : ") .append((boolean) rolloutItem.getItemProperty(IS_REQUIRED_MIGRATION_STEP).getValue() ? "Yes" : "No"); - stringBuilder.append("
  • "); + stringBuilder.append(HTML_LI_CLOSE_TAG); - stringBuilder.append("
  • "); + stringBuilder.append(HTML_LI_OPEN_TAG); stringBuilder.append("SoftWare Modules : ").append(swModuleNames.toString()); - stringBuilder.append("
  • "); + stringBuilder.append(HTML_LI_CLOSE_TAG); - stringBuilder.append("
  • "); + stringBuilder.append(HTML_LI_OPEN_TAG); stringBuilder.append("Vendor(s) : ").append(swModuleVendors.toString()); - stringBuilder.append("
  • "); + stringBuilder.append(HTML_LI_CLOSE_TAG); - stringBuilder.append("
"); + stringBuilder.append(HTML_UL_CLOSE_TAG); return stringBuilder.toString(); } diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/utils/HawkbitCommonUtil.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/utils/HawkbitCommonUtil.java index df4a1309e..0e71567af 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/utils/HawkbitCommonUtil.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/utils/HawkbitCommonUtil.java @@ -73,6 +73,11 @@ public final class HawkbitCommonUtil { */ public static final String SPAN_CLOSE = ""; + public static final String HTML_LI_CLOSE_TAG = ""; + public static final String HTML_LI_OPEN_TAG = "
  • "; + public static final String HTML_UL_CLOSE_TAG = ""; + public static final String HTML_UL_OPEN_TAG = "
      "; + private static final Logger LOG = LoggerFactory.getLogger(HawkbitCommonUtil.class); private static final String JS_DRAG_COUNT_REM_CHILD = " if(x) { document.head.removeChild(x); } ";