Skip to content

Commit 92de8af

Browse files
selected item won't be cleared even if it was deleted from model (it removes the selected object by using == but not equals)
1 parent 6eaa169 commit 92de8af

File tree

1 file changed

+8
-1
lines changed
  • PluginsAndFeatures/azure-toolkit-for-intellij/azure-intellij-plugin-lib/src/main/java/com/microsoft/azure/toolkit/intellij/common

1 file changed

+8
-1
lines changed

PluginsAndFeatures/azure-toolkit-for-intellij/azure-intellij-plugin-lib/src/main/java/com/microsoft/azure/toolkit/intellij/common/AzureComboBox.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,11 @@
4747
import java.awt.event.ItemEvent;
4848
import java.awt.event.KeyEvent;
4949
import java.io.InterruptedIOException;
50+
import java.util.ArrayList;
51+
import java.util.Collections;
5052
import java.util.List;
51-
import java.util.*;
53+
import java.util.Objects;
54+
import java.util.Optional;
5255
import java.util.function.BiPredicate;
5356
import java.util.function.Function;
5457
import java.util.function.Predicate;
@@ -251,8 +254,12 @@ protected synchronized void setItems(final List<? extends T> items) {
251254
final List<? extends T> newItems = ObjectUtils.firstNonNull(items, Collections.emptyList());
252255
final List<? extends T> toRemove = ListUtils.removeAll(oldItems, newItems);
253256
final List<? extends T> toAdd = ListUtils.removeAll(newItems, oldItems);
257+
final T item = (T) model.getSelectedItem();
254258
toRemove.forEach(model::removeElement);
255259
model.addAll(toAdd);
260+
if (!newItems.contains(item)) {
261+
model.setSelectedItem(null);
262+
}
256263
this.refreshValue();
257264
});
258265
}

0 commit comments

Comments
 (0)