Add table items comparison to enable save button
Signed-off-by: SirWayne <dennis.melzer@bosch-si.com>
This commit is contained in:
@@ -200,6 +200,10 @@
|
|||||||
<groupId>org.springframework.security</groupId>
|
<groupId>org.springframework.security</groupId>
|
||||||
<artifactId>spring-security-web</artifactId>
|
<artifactId>spring-security-web</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.apache.commons</groupId>
|
||||||
|
<artifactId>commons-collections4</artifactId>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.vaadin</groupId>
|
<groupId>com.vaadin</groupId>
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ import static com.google.common.base.Preconditions.checkNotNull;
|
|||||||
|
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collection;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@@ -20,6 +21,7 @@ import java.util.Objects;
|
|||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
import org.apache.commons.collections4.CollectionUtils;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.eclipse.hawkbit.ui.artifacts.smtable.SoftwareModuleAddUpdateWindow;
|
import org.eclipse.hawkbit.ui.artifacts.smtable.SoftwareModuleAddUpdateWindow;
|
||||||
import org.eclipse.hawkbit.ui.components.SPUIComponentProvider;
|
import org.eclipse.hawkbit.ui.components.SPUIComponentProvider;
|
||||||
@@ -31,6 +33,7 @@ import org.eclipse.hawkbit.ui.utils.SPUIComponentIdProvider;
|
|||||||
import org.eclipse.hawkbit.ui.utils.SPUIStyleDefinitions;
|
import org.eclipse.hawkbit.ui.utils.SPUIStyleDefinitions;
|
||||||
|
|
||||||
import com.google.common.base.Strings;
|
import com.google.common.base.Strings;
|
||||||
|
import com.google.common.collect.Sets;
|
||||||
import com.vaadin.data.Container.ItemSetChangeEvent;
|
import com.vaadin.data.Container.ItemSetChangeEvent;
|
||||||
import com.vaadin.data.Container.ItemSetChangeListener;
|
import com.vaadin.data.Container.ItemSetChangeListener;
|
||||||
import com.vaadin.data.Property.ValueChangeEvent;
|
import com.vaadin.data.Property.ValueChangeEvent;
|
||||||
@@ -204,7 +207,7 @@ public class CommonDialogWindow extends Window implements Serializable {
|
|||||||
Object value = field.getValue();
|
Object value = field.getValue();
|
||||||
|
|
||||||
if (field instanceof Table) {
|
if (field instanceof Table) {
|
||||||
value = ((Table) field).getContainerDataSource().getItemIds();
|
value = Sets.newHashSet(((Table) field).getContainerDataSource().getItemIds());
|
||||||
}
|
}
|
||||||
orginalValues.put(field, value);
|
orginalValues.put(field, value);
|
||||||
}
|
}
|
||||||
@@ -214,13 +217,15 @@ public class CommonDialogWindow extends Window implements Serializable {
|
|||||||
|
|
||||||
private final void addListeners() {
|
private final void addListeners() {
|
||||||
for (final AbstractField<?> field : allComponents) {
|
for (final AbstractField<?> field : allComponents) {
|
||||||
field.addValueChangeListener(new ChangeListener(field));
|
|
||||||
if (field instanceof TextChangeNotifier) {
|
if (field instanceof TextChangeNotifier) {
|
||||||
((TextChangeNotifier) field).addTextChangeListener(new ChangeListener(field));
|
((TextChangeNotifier) field).addTextChangeListener(new ChangeListener(field));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (field instanceof Table) {
|
if (field instanceof Table) {
|
||||||
((Table) field).addItemSetChangeListener(new ChangeListener(field));
|
((Table) field).addItemSetChangeListener(new ChangeListener(field));
|
||||||
|
} else {
|
||||||
|
field.addValueChangeListener(new ChangeListener(field));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -236,17 +241,10 @@ public class CommonDialogWindow extends Window implements Serializable {
|
|||||||
|
|
||||||
private boolean isValuesChanged(final Component currentChangedComponent, final Object newValue) {
|
private boolean isValuesChanged(final Component currentChangedComponent, final Object newValue) {
|
||||||
for (final AbstractField<?> field : allComponents) {
|
for (final AbstractField<?> field : allComponents) {
|
||||||
Object orginalValue = orginalValues.get(field);
|
final Object orginalValue = orginalValues.get(field);
|
||||||
Object currentValue = field.getValue();
|
final Object currentValue = getCurrentVaue(currentChangedComponent, newValue, field);
|
||||||
if (field.equals(currentChangedComponent)) {
|
|
||||||
currentValue = newValue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (String.class.equals(field.getType())) {
|
if (!isValueEquals(field, orginalValue, currentValue)) {
|
||||||
orginalValue = Strings.emptyToNull((String) orginalValue);
|
|
||||||
currentValue = Strings.emptyToNull((String) currentValue);
|
|
||||||
}
|
|
||||||
if (!Objects.equals(orginalValue, currentValue)) {
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -254,6 +252,33 @@ public class CommonDialogWindow extends Window implements Serializable {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private boolean isValueEquals(final AbstractField<?> field, final Object orginalValue, final Object currentValue) {
|
||||||
|
if (Set.class.equals(field.getType())) {
|
||||||
|
return CollectionUtils.isEqualCollection(CollectionUtils.emptyIfNull((Collection<?>) orginalValue),
|
||||||
|
CollectionUtils.emptyIfNull((Collection<?>) currentValue));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (String.class.equals(field.getType())) {
|
||||||
|
return Objects.equals(Strings.emptyToNull((String) orginalValue),
|
||||||
|
Strings.emptyToNull((String) currentValue));
|
||||||
|
}
|
||||||
|
|
||||||
|
return Objects.equals(orginalValue, currentValue);
|
||||||
|
}
|
||||||
|
|
||||||
|
private Object getCurrentVaue(final Component currentChangedComponent, final Object newValue,
|
||||||
|
final AbstractField<?> field) {
|
||||||
|
Object currentValue = field.getValue();
|
||||||
|
if (field instanceof Table) {
|
||||||
|
currentValue = ((Table) field).getContainerDataSource().getItemIds();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (field.equals(currentChangedComponent)) {
|
||||||
|
currentValue = newValue;
|
||||||
|
}
|
||||||
|
return currentValue;
|
||||||
|
}
|
||||||
|
|
||||||
private boolean shouldMandatoryLabelShown() {
|
private boolean shouldMandatoryLabelShown() {
|
||||||
for (final AbstractField<?> field : allComponents) {
|
for (final AbstractField<?> field : allComponents) {
|
||||||
if (field.isRequired()) {
|
if (field.isRequired()) {
|
||||||
@@ -269,17 +294,14 @@ public class CommonDialogWindow extends Window implements Serializable {
|
|||||||
.collect(Collectors.toList());
|
.collect(Collectors.toList());
|
||||||
|
|
||||||
for (final AbstractField<?> field : requiredComponents) {
|
for (final AbstractField<?> field : requiredComponents) {
|
||||||
Object value = field.getValue();
|
Object value = getCurrentVaue(currentChangedComponent, newValue, field);
|
||||||
if (field.equals(currentChangedComponent)) {
|
|
||||||
value = newValue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (String.class.equals(field.getType())) {
|
if (String.class.equals(field.getType())) {
|
||||||
value = Strings.emptyToNull((String) value);
|
value = Strings.emptyToNull((String) value);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Set.class.equals(field.getType())) {
|
if (Set.class.equals(field.getType())) {
|
||||||
value = emptyToNull((Set<?>) value);
|
value = emptyToNull((Collection<?>) value);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (value == null) {
|
if (value == null) {
|
||||||
@@ -290,7 +312,7 @@ public class CommonDialogWindow extends Window implements Serializable {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Object emptyToNull(final Set<?> c) {
|
private static Object emptyToNull(final Collection<?> c) {
|
||||||
return (c == null || c.isEmpty()) ? null : c;
|
return (c == null || c.isEmpty()) ? null : c;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -407,7 +429,12 @@ public class CommonDialogWindow extends Window implements Serializable {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void containerItemSetChange(final ItemSetChangeEvent event) {
|
public void containerItemSetChange(final ItemSetChangeEvent event) {
|
||||||
saveButton.setEnabled(isSaveButtonEnabledAfterValueChange(field, event.getContainer().getItemIds()));
|
if (!(field instanceof Table)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
final Table table = (Table) field;
|
||||||
|
saveButton.setEnabled(
|
||||||
|
isSaveButtonEnabledAfterValueChange(table, table.getContainerDataSource().getItemIds()));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
6
pom.xml
6
pom.xml
@@ -111,6 +111,7 @@
|
|||||||
<jlorem.version>1.1</jlorem.version>
|
<jlorem.version>1.1</jlorem.version>
|
||||||
<json-simple.version>1.1.1</json-simple.version>
|
<json-simple.version>1.1.1</json-simple.version>
|
||||||
<commons-lang3.version>3.4</commons-lang3.version>
|
<commons-lang3.version>3.4</commons-lang3.version>
|
||||||
|
<commons-collections4.version>4.0</commons-collections4.version>
|
||||||
<json.version>20141113</json.version>
|
<json.version>20141113</json.version>
|
||||||
<rsql-parser.version>2.0.0</rsql-parser.version>
|
<rsql-parser.version>2.0.0</rsql-parser.version>
|
||||||
<!-- Misc libraries versions - END -->
|
<!-- Misc libraries versions - END -->
|
||||||
@@ -560,6 +561,11 @@
|
|||||||
<artifactId>commons-lang3</artifactId>
|
<artifactId>commons-lang3</artifactId>
|
||||||
<version>${commons-lang3.version}</version>
|
<version>${commons-lang3.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.apache.commons</groupId>
|
||||||
|
<artifactId>commons-collections4</artifactId>
|
||||||
|
<version>${commons-collections4.version}</version>
|
||||||
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.springframework.boot</groupId>
|
<groupId>org.springframework.boot</groupId>
|
||||||
<artifactId>spring-boot-starter-test</artifactId>
|
<artifactId>spring-boot-starter-test</artifactId>
|
||||||
|
|||||||
Reference in New Issue
Block a user