From ab41d205cd998ad170add7640b12455142fe256c Mon Sep 17 00:00:00 2001 From: Manuel Rego Casasnovas Date: Wed, 13 Feb 2013 13:09:12 +0100 Subject: [PATCH] tim-connector: Improve configuration UI for connectors Several changes in the UI and implementation. FEA: ItEr77S16JiraAndTimConnectorContributionIntegration --- .../web/common/ConfigurationController.java | 206 +++++++----------- .../web/common/ConfigurationModel.java | 28 ++- .../web/common/IConfigurationModel.java | 2 +- .../src/main/webapp/common/configuration.zul | 63 +++--- 4 files changed, 123 insertions(+), 176 deletions(-) diff --git a/libreplan-webapp/src/main/java/org/libreplan/web/common/ConfigurationController.java b/libreplan-webapp/src/main/java/org/libreplan/web/common/ConfigurationController.java index f351731e0..323fd2af1 100644 --- a/libreplan-webapp/src/main/java/org/libreplan/web/common/ConfigurationController.java +++ b/libreplan-webapp/src/main/java/org/libreplan/web/common/ConfigurationController.java @@ -219,7 +219,6 @@ public class ConfigurationController extends GenericForwardComposer { } public void save() throws InterruptedException { - updateConnectorPropertyValues(); ConstraintChecker.isValid(configurationWindow); if (checkValidEntitySequenceRows()) { try { @@ -316,7 +315,7 @@ public class ConfigurationController extends GenericForwardComposer { /** * Tests connection */ - public void testConnectiion() { + public void testConnection() { String connectorId = getSelectedConnector(); if (connectorId == null || connectorId.isEmpty()) { throw new RuntimeException("Connector id should not be empty"); @@ -364,7 +363,8 @@ public class ConfigurationController extends GenericForwardComposer { private Map getAppProperties(String majorConnectorId) { - List appProperties = getAllPropertiesByMajorId(majorConnectorId); + List appProperties = configurationModel + .getAllAppPropertiesByMajorId(majorConnectorId); Map map = new HashMap(); for (AppProperties appProp : appProperties) { map.put(appProp.getPropertyName(), appProp.getPropertyValue()); @@ -1057,14 +1057,8 @@ public class ConfigurationController extends GenericForwardComposer { getAppPropertyConnectors(); } - public List getAppPropertyConnectors() { - List appPropertyConnectors = new ArrayList(); - Map> appPropertiesMap = getAllAppProperties(); - for (Map.Entry> entry : appPropertiesMap - .entrySet()) { - appPropertyConnectors.add(entry.getKey()); - } - return appPropertyConnectors; + public Set getAppPropertyConnectors() { + return getAllAppProperties().keySet(); } private Map> getAllAppProperties() { @@ -1072,17 +1066,6 @@ public class ConfigurationController extends GenericForwardComposer { } - public ListitemRenderer getAppPropertyConnectorsRenderer() { - return new ListitemRenderer() { - @Override - public void render(Listitem item, Object data) throws Exception { - String majorId = (String) data; - item.setLabel(majorId); - item.setValue(majorId); - } - }; - } - public String getSelectedConnector() { String connectorId = configurationModel.getAppConnectorId(); return connectorId; @@ -1090,126 +1073,91 @@ public class ConfigurationController extends GenericForwardComposer { public void setSelectedConnector(String connectorId) { configurationModel.setAppConnectorId(connectorId); - reloadAppProperties(connectorId); + Util.reloadBindings(appPropertriesGrid); } - public AppPropertriesRenderer getAppPropertriesRenderer() { - return new AppPropertriesRenderer(); - } - - public class AppPropertriesRenderer implements RowRenderer { - @Override - public void render(Row row, Object data) { - - AppProperties appProperties = (AppProperties) data; - row.appendChild(new Label(appProperties.getPropertyName())); - row.setValue(appProperties); - appendValueTextbox(row, appProperties); + public List getAppPropertries() { + String appConnectorId = configurationModel.getAppConnectorId(); + if (StringUtils.isEmpty(appConnectorId)) { + return Collections.emptyList(); } + return configurationModel.getAllAppPropertiesByMajorId(appConnectorId); } - private void appendValueTextbox(Row row, final AppProperties appProperties) { - final Textbox textbox = new Textbox(); - textbox.setWidth("250px"); - textbox.setConstraint(checkPropertyValue((AppProperties) row.getValue())); - - Util.bind(textbox, new Util.Getter() { - + public RowRenderer getAppPropertriesRenderer() { + return new RowRenderer() { @Override - public String get() { - return appProperties.getPropertyValue(); + public void render(Row row, Object data) { + AppProperties appProperties = (AppProperties) data; + row.setValue(appProperties); + + Util.appendLabel(row, appProperties.getPropertyName()); + appendValueTextbox(row, appProperties); } - }, new Util.Setter() { - @Override - public void set(String value) { + private void appendValueTextbox(Row row, + final AppProperties appProperties) { + final Textbox textbox = new Textbox(); + textbox.setConstraint(checkPropertyValue((AppProperties) row + .getValue())); + + Util.bind(textbox, new Util.Getter() { + + @Override + public String get() { + return appProperties.getPropertyValue(); + } + }, new Util.Setter() { + + @Override + public void set(String value) { + appProperties.setPropertyValue(value); + } + }); + if (appProperties.getPropertyName().equals("Password")) { + textbox.setType("password"); + } + + row.appendChild(textbox); + } + + public Constraint checkPropertyValue( + final AppProperties appProperties) { + final String name = appProperties.getPropertyName(); + return new Constraint() { + @Override + public void validate(Component comp, Object value) { + if (name.equals("Activated")) { + if (!value.equals("Y") && !value.equals("N")) { + throw new WrongValueException( + _("Only Y/N allowed")); + } + } else if (name.equals("Server") + || name.equals("Username") + || name.equals("Password")) { + ((InputElement) comp).setConstraint("no empty:" + + _("cannot be empty")); + } else if (name.equals("NrDaysTimesheetToTim") + || name.equals("NrDaysRosterFromTim")) { + if (!isNumeric((String) value)) { + throw new WrongValueException( + _("Only digits allowed")); + } + } + } + }; + } + + private boolean isNumeric(String input) { try { - appProperties.setPropertyValue(value); - } catch (IllegalArgumentException e) { - throw new WrongValueException(textbox, e.getMessage()); + Integer.parseInt(input); + return true; + } catch (NumberFormatException e) { + return false; } } - }); - if (appProperties.getPropertyName().equals("Password")) { - textbox.setType("password"); - } - if (appProperties.getPropertyValue().length() < 4) { - textbox.setWidth("20px"); - } - textbox.setInplace(true); - row.appendChild(textbox); - - } - - - public Constraint checkPropertyValue(final AppProperties appProperties) { - final String name = appProperties.getPropertyName(); - return new Constraint() { - @Override - public void validate(Component comp, Object value) { - if (name.equals("Activated")) { - if (!value.equals("Y") && !value.equals("N")) { - throw new WrongValueException(_("Only Y/N allowed")); - } - } else if (name.equals("Server") || name.equals("Username") - || name.equals("Password")) { - ((InputElement) comp).setConstraint("no empty:" - + _("cannot be empty")); - } else if (name.equals("NrDaysTimesheetToTim") - || name.equals("NrDaysRosterFromTim")) { - if (!isNumeric((String) value)) { - throw new WrongValueException(_("Only digits allowed")); - } - } - } }; } - private boolean isNumeric(String input) { - try { - Integer.parseInt(input); - return true; - } catch (NumberFormatException e) { - return false; - } - } - - private void reloadAppProperties(String connectorMajorId) { - appPropertriesGrid.setModel(new SimpleListModel( - getAllPropertiesByMajorId( - connectorMajorId) - .toArray())); - appPropertriesGrid.invalidate(); - } - - private List getAllPropertiesByMajorId( - String connectorMajorId) { - List appPropertiesList = new ArrayList(); - Map> appPropertiesMap = getAllAppProperties(); - if (appPropertiesMap.containsKey(connectorMajorId)) { - appPropertiesList = appPropertiesMap.get(connectorMajorId); - } - return appPropertiesList; - - } - - public void getSelectedConnectorProperties() { - reloadAppProperties(connectorCombo.getSelectedItem().getLabel()); - } - - private void updateConnectorPropertyValues() { - Rows rows = appPropertriesGrid.getRows(); - List appProperties = new ArrayList(); - - for (Row row : (List) rows.getChildren()) { - AppProperties appProp = (AppProperties) row.getValue(); - if (appProp != null) { - appProperties.add(appProp); - } - } - configurationModel.updateProperties(getSelectedConnector(), - appProperties); - - } } diff --git a/libreplan-webapp/src/main/java/org/libreplan/web/common/ConfigurationModel.java b/libreplan-webapp/src/main/java/org/libreplan/web/common/ConfigurationModel.java index 60675d093..458ae63cd 100644 --- a/libreplan-webapp/src/main/java/org/libreplan/web/common/ConfigurationModel.java +++ b/libreplan-webapp/src/main/java/org/libreplan/web/common/ConfigurationModel.java @@ -25,6 +25,7 @@ import static org.libreplan.web.I18nHelper._; import java.util.ArrayList; import java.util.Collection; +import java.util.Collections; import java.util.Currency; import java.util.HashMap; import java.util.HashSet; @@ -188,7 +189,7 @@ public class ConfigurationModel implements IConfigurationModel { public void confirm() { checkEntitySequences(); configurationDAO.save(configuration); - storeAppProperties(); + saveAppProperties(); try { storeAndRemoveEntitySequences(); } catch (IllegalStateException e) { @@ -724,11 +725,12 @@ public class ConfigurationModel implements IConfigurationModel { } } - public void storeAppProperties() { - List appProperties = appPropertiesMap - .get(getAppConnectorId()); - for (AppProperties appProperty : appProperties) { - appPropertiesDAO.save(appProperty); + private void saveAppProperties() { + for (String appConnectorId : appPropertiesMap.keySet()) { + for (AppProperties appProperty : appPropertiesMap + .get(appConnectorId)) { + appPropertiesDAO.save(appProperty); + } } } @@ -737,11 +739,6 @@ public class ConfigurationModel implements IConfigurationModel { return appPropertiesMap; } - @Override - public void updateProperties(String key, List value) { - this.appPropertiesMap.put(key, value); - } - @Override public void setAppConnectorId(String connectorId) { this.connectorId = connectorId; @@ -752,4 +749,13 @@ public class ConfigurationModel implements IConfigurationModel { return connectorId; } + @Override + public List getAllAppPropertiesByMajorId( + String majorConnectorId) { + if (appPropertiesMap == null) { + return Collections.emptyList(); + } + return appPropertiesMap.get(majorConnectorId); + } + } diff --git a/libreplan-webapp/src/main/java/org/libreplan/web/common/IConfigurationModel.java b/libreplan-webapp/src/main/java/org/libreplan/web/common/IConfigurationModel.java index c610eab17..735d579d1 100644 --- a/libreplan-webapp/src/main/java/org/libreplan/web/common/IConfigurationModel.java +++ b/libreplan-webapp/src/main/java/org/libreplan/web/common/IConfigurationModel.java @@ -202,6 +202,6 @@ public interface IConfigurationModel { String getAppConnectorId(); - void updateProperties(String key, List value); + List getAllAppPropertiesByMajorId(String majorConnectorId); } diff --git a/libreplan-webapp/src/main/webapp/common/configuration.zul b/libreplan-webapp/src/main/webapp/common/configuration.zul index 25dfb6c07..2084feb00 100644 --- a/libreplan-webapp/src/main/webapp/common/configuration.zul +++ b/libreplan-webapp/src/main/webapp/common/configuration.zul @@ -456,41 +456,34 @@ - - - - - - - - - - - - - - -