tim-connector: Improve configuration UI for connectors
Several changes in the UI and implementation. FEA: ItEr77S16JiraAndTimConnectorContributionIntegration
This commit is contained in:
parent
c5796d602b
commit
ab41d205cd
4 changed files with 123 additions and 176 deletions
|
|
@ -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<String, String> getAppProperties(String majorConnectorId) {
|
||||
List<AppProperties> appProperties = getAllPropertiesByMajorId(majorConnectorId);
|
||||
List<AppProperties> appProperties = configurationModel
|
||||
.getAllAppPropertiesByMajorId(majorConnectorId);
|
||||
Map<String, String> map = new HashMap<String, String>();
|
||||
for (AppProperties appProp : appProperties) {
|
||||
map.put(appProp.getPropertyName(), appProp.getPropertyValue());
|
||||
|
|
@ -1057,14 +1057,8 @@ public class ConfigurationController extends GenericForwardComposer {
|
|||
getAppPropertyConnectors();
|
||||
}
|
||||
|
||||
public List<String> getAppPropertyConnectors() {
|
||||
List<String> appPropertyConnectors = new ArrayList<String>();
|
||||
Map<String, List<AppProperties>> appPropertiesMap = getAllAppProperties();
|
||||
for (Map.Entry<String, List<AppProperties>> entry : appPropertiesMap
|
||||
.entrySet()) {
|
||||
appPropertyConnectors.add(entry.getKey());
|
||||
}
|
||||
return appPropertyConnectors;
|
||||
public Set<String> getAppPropertyConnectors() {
|
||||
return getAllAppProperties().keySet();
|
||||
}
|
||||
|
||||
private Map<String, List<AppProperties>> 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<AppProperties> 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<String>() {
|
||||
|
||||
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<String>() {
|
||||
|
||||
@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<String>() {
|
||||
|
||||
@Override
|
||||
public String get() {
|
||||
return appProperties.getPropertyValue();
|
||||
}
|
||||
}, new Util.Setter<String>() {
|
||||
|
||||
@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<AppProperties> getAllPropertiesByMajorId(
|
||||
String connectorMajorId) {
|
||||
List<AppProperties> appPropertiesList = new ArrayList<AppProperties>();
|
||||
Map<String, List<AppProperties>> 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> appProperties = new ArrayList<AppProperties>();
|
||||
|
||||
for (Row row : (List<Row>) rows.getChildren()) {
|
||||
AppProperties appProp = (AppProperties) row.getValue();
|
||||
if (appProp != null) {
|
||||
appProperties.add(appProp);
|
||||
}
|
||||
}
|
||||
configurationModel.updateProperties(getSelectedConnector(),
|
||||
appProperties);
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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> 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<AppProperties> 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<AppProperties> getAllAppPropertiesByMajorId(
|
||||
String majorConnectorId) {
|
||||
if (appPropertiesMap == null) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
return appPropertiesMap.get(majorConnectorId);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -202,6 +202,6 @@ public interface IConfigurationModel {
|
|||
|
||||
String getAppConnectorId();
|
||||
|
||||
void updateProperties(String key, List<AppProperties> value);
|
||||
List<AppProperties> getAllAppPropertiesByMajorId(String majorConnectorId);
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -456,41 +456,34 @@
|
|||
<separator />
|
||||
</tabpanel>
|
||||
<tabpanel id="panelConnectors">
|
||||
<panel border="normal"
|
||||
title="Application properties">
|
||||
<panelchildren id="panelConnector">
|
||||
<vbox>
|
||||
<hbox pack="center">
|
||||
<label value="${i18n:_('Select connector')}" />
|
||||
<combobox id="connectorCombo" autodrop="true"
|
||||
model="@{configurationController.appPropertyConnectors}"
|
||||
onAfterRender="configurationController.getSelectedConnectorProperties()"
|
||||
selectedItem="@{configurationController.selectedConnector}">
|
||||
<comboitem
|
||||
self="@{each=appPropertyConnectors}"
|
||||
label="@{appPropertyConnectors}"
|
||||
value="@{appPropertyConnectors}" />
|
||||
</combobox>
|
||||
</hbox>
|
||||
<separator bar="false" height="4px"
|
||||
orient="vertical" />
|
||||
<grid id="appPropertriesGrid"
|
||||
sizedByContent="false" height="300px"
|
||||
rowRenderer="@{configurationController.appPropertriesRenderer}">
|
||||
<columns>
|
||||
<column
|
||||
label="${i18n:_('Name')}" width="200px"/>
|
||||
<column
|
||||
label="${i18n:_('Value')}" />
|
||||
</columns>
|
||||
</grid>
|
||||
</vbox>
|
||||
<separator />
|
||||
<button label="${i18n:_('Test Tim connection')}"
|
||||
onClick="configurationController.testConnectiion()" />
|
||||
<separator />
|
||||
</panelchildren>
|
||||
</panel>
|
||||
<groupbox style="margin-top: 5px" closable="false">
|
||||
<caption label="${i18n:_('Application properties')}" />
|
||||
<vbox>
|
||||
<hbox pack="center">
|
||||
<label value="${i18n:_('Select connector')}" />
|
||||
<combobox id="connectorCombo" autodrop="true"
|
||||
model="@{configurationController.appPropertyConnectors}"
|
||||
selectedItem="@{configurationController.selectedConnector}">
|
||||
<comboitem
|
||||
self="@{each=appPropertyConnectors}"
|
||||
label="@{appPropertyConnectors}"
|
||||
value="@{appPropertyConnectors}" />
|
||||
</combobox>
|
||||
</hbox>
|
||||
<separator />
|
||||
<grid id="appPropertriesGrid"
|
||||
model="@{configurationController.appPropertries}"
|
||||
rowRenderer="@{configurationController.appPropertriesRenderer}">
|
||||
<columns>
|
||||
<column label="${i18n:_('Name')}" width="200px"/>
|
||||
<column label="${i18n:_('Value')}" />
|
||||
</columns>
|
||||
</grid>
|
||||
</vbox>
|
||||
<separator />
|
||||
<button label="${i18n:_('Test connection')}"
|
||||
onClick="configurationController.testConnection()" />
|
||||
</groupbox>
|
||||
</tabpanel>
|
||||
</tabpanels>
|
||||
</tabbox>
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue