Constructed Deck Editor controller updates the decklist cursor to select current deck in editor (if any).

The DeckView = when initialised = after editing the current deck in editor, tries to select it in the decklist view. However, at startup this won't be actually successful due to an un-initialised table model.

The issue only happens at startup time, and it is related to the fact that despite any selected item can be set (with the current Deck in editor) - see `populate` - the `update` method that initialise the (table)models is only called afterwards.
Therefore, the update method of Controller has been modified to re-try a selection with current deck in editor.

The whole procedure is skipped if the selected index is different from zero = assuming zero is the default fallback option.
If that's not the case, say the zero first deck should be indeed selected, the selected item shouldn't be activated twice anyway if that's exactly what's already been selected.
This commit is contained in:
leriomaggio
2021-10-29 10:40:26 +01:00
parent b7b11ffba7
commit e20b46dde2
2 changed files with 22 additions and 2 deletions

View File

@@ -1,8 +1,12 @@
package forge.screens.deckeditor.controllers;
import forge.deck.DeckBase;
import forge.deck.DeckProxy;
import forge.gui.framework.ICDoc;
import forge.item.InventoryItem;
import forge.itemmanager.DeckManager;
import forge.itemmanager.ItemManagerConfig;
import forge.screens.deckeditor.CDeckEditorUI;
import forge.screens.deckeditor.views.VAllDecks;
/**
@@ -39,6 +43,20 @@ public enum CAllDecks implements ICDoc {
*/
@Override
public void update() {
view.getLstDecks().setup(ItemManagerConfig.CONSTRUCTED_DECKS);
DeckManager deckManager = view.getLstDecks();
deckManager.setup(ItemManagerConfig.CONSTRUCTED_DECKS);
if (deckManager.getSelectedIndex() == 0) {
// This may be default and so requiring potential update!
ACEditorBase<? extends InventoryItem, ? extends DeckBase> editorCtrl =
CDeckEditorUI.SINGLETON_INSTANCE.getCurrentEditorController();
if (editorCtrl != null) {
String currentDeckName = editorCtrl.getDeckController().getModelName();
if (currentDeckName != null && currentDeckName.length() > 0) {
DeckProxy deckProxy = deckManager.stringToItem(currentDeckName);
if (deckProxy != null && !deckManager.getSelectedItem().equals(deckProxy))
view.getLstDecks().setSelectedItem(deckProxy);
}
}
}
}
}

View File

@@ -86,8 +86,10 @@ public enum VAllDecks implements IVDoc<CAllDecks> {
parentBody.add(new ItemManagerContainer(lstDecks), "push, grow");
String preferredDeck = DeckPreferences.getCurrentDeck();
DeckProxy deckProxy = lstDecks.stringToItem(preferredDeck);
if (deckProxy != null)
if (deckProxy != null) {
lstDecks.editDeck(deckProxy);
lstDecks.setSelectedItem(deckProxy);
}
}
//========== Retrieval methods