mirror of
https://github.com/correl/mage.git
synced 2024-12-25 11:11:16 +00:00
UI: added start selection value on choice dialog popup;
This commit is contained in:
parent
2d9fa97808
commit
e4dfa5925b
3 changed files with 42 additions and 1 deletions
|
@ -23,6 +23,7 @@ import mage.client.MageFrame;
|
|||
import mage.client.util.SettingsManager;
|
||||
import mage.client.util.gui.GuiDisplayUtil;
|
||||
import mage.client.util.gui.MageDialogState;
|
||||
import org.jsoup.Connection;
|
||||
|
||||
/**
|
||||
*
|
||||
|
@ -36,8 +37,20 @@ public class PickChoiceDialog extends MageDialog {
|
|||
DefaultListModel<KeyValueItem> dataModel = new DefaultListModel();
|
||||
|
||||
final private static String HTML_TEMPLATE = "<html><div style='text-align: center;'>%s</div></html>";
|
||||
|
||||
|
||||
public void showDialog(Choice choice) {
|
||||
showDialog(choice, null, null, null);
|
||||
}
|
||||
|
||||
public void showDialog(Choice choice, String startSelectionValue) {
|
||||
showDialog(choice, null, null, startSelectionValue);
|
||||
}
|
||||
|
||||
public void showDialog(Choice choice, UUID objectId, MageDialogState mageDialogState) {
|
||||
showDialog(choice, objectId, mageDialogState, null);
|
||||
}
|
||||
|
||||
public void showDialog(Choice choice, UUID objectId, MageDialogState mageDialogState, String startSelectionValue) {
|
||||
this.choice = choice;
|
||||
|
||||
setLabelText(this.labelMessage, choice.getMessage());
|
||||
|
@ -136,6 +149,23 @@ public class PickChoiceDialog extends MageDialog {
|
|||
// final load
|
||||
loadData();
|
||||
|
||||
// start selection
|
||||
if((startSelectionValue != null)){
|
||||
int selectIndex = -1;
|
||||
for(int i = 0; i < this.listChoices.getModel().getSize() - 1; i++){
|
||||
KeyValueItem listItem = (KeyValueItem)this.listChoices.getModel().getElementAt(i);
|
||||
if (listItem.Key.equals(startSelectionValue)){
|
||||
selectIndex = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if(selectIndex >= 0){
|
||||
this.listChoices.setSelectedIndex(selectIndex);
|
||||
this.listChoices.ensureIndexIsVisible(selectIndex);
|
||||
}
|
||||
}
|
||||
|
||||
this.setVisible(true);
|
||||
}
|
||||
|
||||
|
|
|
@ -61,6 +61,7 @@ public interface Choice {
|
|||
Map<String,String> getKeyChoices();
|
||||
void setChoiceByKey(String choiceKey);
|
||||
String getChoiceKey();
|
||||
String getChoiceValue();
|
||||
|
||||
// search
|
||||
boolean isSearchEnabled();
|
||||
|
|
|
@ -149,12 +149,22 @@ public class ChoiceImpl implements Choice, Serializable {
|
|||
return choiceKey;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getChoiceValue() {
|
||||
if ((keyChoices != null) && (keyChoices.containsKey(choiceKey))){
|
||||
return keyChoices.get(choiceKey);
|
||||
}else{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setChoiceByKey(String choiceKey) {
|
||||
String choiceToSet = keyChoices.get(choiceKey);
|
||||
if (choiceToSet != null) {
|
||||
this.choice = choiceToSet;
|
||||
this.choiceKey = choiceKey;
|
||||
this.chosen = true;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue