Skip to content
This repository has been archived by the owner on Mar 15, 2022. It is now read-only.

Commit

Permalink
BZ1027841: [Usability] The same key can be used multiple time
Browse files Browse the repository at this point in the history
  • Loading branch information
rpelisse authored and hpehl committed May 16, 2015
1 parent aba3d7a commit b731d1b
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 8 deletions.
Expand Up @@ -22,7 +22,6 @@
import com.google.gwt.user.client.Command;
import com.google.gwt.user.client.ui.DeckPanel;
import com.google.gwt.user.client.ui.Widget;
import java.util.ArrayList;
import org.jboss.as.console.client.core.ApplicationProperties;
import org.jboss.as.console.client.shared.BeanFactory;
import org.jboss.as.console.client.shared.properties.PropertyRecord;
Expand All @@ -33,7 +32,10 @@
import org.jboss.as.console.client.shared.subsys.jca.model.XADataSource;
import org.jboss.ballroom.client.widgets.window.TrappedFocusPanel;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
* @author Heiko Braun
Expand Down Expand Up @@ -95,7 +97,7 @@ public void showWidget(int index) {
}
};

chooseTemplateStep = new ChooseTemplateStep<XADataSource>(getPresenter(), templates, true, new Command() {
chooseTemplateStep = new ChooseTemplateStep<>(getPresenter(), templates, true, new Command() {
@Override
public void execute() {
onStart();
Expand Down Expand Up @@ -153,12 +155,33 @@ public void onConfigureDriver(JDBCDriver driver) {
deck.showWidget(3);
}

private static Map<String, PropertyRecord> indexProperties(List<PropertyRecord> properties) {
Map<String, PropertyRecord> indexedProperties = new HashMap<>();
for (PropertyRecord record : properties) {
if (!indexedProperties.containsKey(record.getKey()))
indexedProperties.put(record.getKey(), record);
else
throw new IllegalArgumentException("Duplicate key entry:" + record.getKey());
}
return indexedProperties;
}

private List<PropertyRecord> ensureUniqueProperty(List<PropertyRecord> newProperties) {
Map<String, PropertyRecord> indexedProperties = indexProperties(newProperties);
if (xaDataSource.getProperties() != null)
for (PropertyRecord record : xaDataSource.getProperties() )
if (indexedProperties.containsKey(record.getKey()))
throw new IllegalArgumentException("Property " + record.getKey() + " has already been defined with value:"
+ record.getValue());
return newProperties;
}

public void onConfigureProperties(List<PropertyRecord> properties) {
if (xaDataSource.getProperties() == null) {
xaDataSource.setProperties(new ArrayList<PropertyRecord>());
xaDataSource.setProperties(new ArrayList<>());
}
xaDataSource.getProperties().clear();
xaDataSource.getProperties().addAll(properties);
xaDataSource.getProperties().addAll(ensureUniqueProperty(properties));
deck.showWidget(4);
}

Expand Down
Expand Up @@ -58,7 +58,7 @@ Widget asWidget() {
VerticalPanel layout = new VerticalPanel();
layout.setStyleName("window-content");

layout.add(new HTML("<h3>"+ Console.CONSTANTS.subsys_jca_xadataSource_step3()+"</h3>"));
layout.add(new HTML("<h3>" + Console.CONSTANTS.subsys_jca_xadataSource_step3() + "</h3>"));

propEditor = new PropertyEditor(this, true, true);

Expand All @@ -77,10 +77,16 @@ public void onClick(ClickEvent event) {

boolean hasProperties = propEditor.getPropertyTable().getRowCount() > 0;

if(!hasProperties)
if (!hasProperties)
errorMessages.setVisible(true);
else
wizard.onConfigureProperties(properties);
else {
try {
wizard.onConfigureProperties(properties);
} catch (IllegalArgumentException e) {
errorMessages.setVisible(true);
errorMessages.setText(e.getMessage());
}
}
}
};

Expand Down

0 comments on commit b731d1b

Please sign in to comment.