1. /*
  2. * Copyright 1999,2004 The Apache Software Foundation.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. package peaklau.eaglefund;
  17. import javax.microedition.lcdui.Alert;
  18. import javax.microedition.lcdui.AlertType;
  19. import javax.microedition.lcdui.ChoiceGroup;
  20. import javax.microedition.lcdui.Command;
  21. import javax.microedition.lcdui.CommandListener;
  22. import javax.microedition.lcdui.Displayable;
  23. import javax.microedition.lcdui.Form;
  24. /**
  25. * User Interface for deleting funds.<br>
  26. *
  27. * <br>
  28. * @author peaklau <br>
  29. * email:<A HREF="mailto:peaklau@hotmail.com">peaklau@hotmail.com</A> <br>
  30. * <a href="http://www.peaklau.com/fund/english/">HomePage</a>
  31. * @version $Revision: 1.1 $ $Date: 2007/05/09 16:07:04 $
  32. */
  33. public class FundDeleteScreen extends Form implements CommandListener {
  34. private Command back=new Command("返回",Command.BACK,1);
  35. private Command refresh=new Command("刷新数据",Command.BACK,1);
  36. private Command ok=new Command("确认删除",Command.OK,1);
  37. private Alert alert=null;
  38. private INavigator navigator=null;
  39. private ChoiceGroup codeChoices=null;
  40. private int codeChoicesID=0;
  41. public FundDeleteScreen(INavigator navigator){
  42. super("删除基金");
  43. this.navigator=navigator;
  44. codeChoices=new ChoiceGroup("选择要删除的基金",ChoiceGroup.MULTIPLE,DataCenter.getFunds(),null);
  45. codeChoicesID=append(codeChoices);
  46. addCommand(ok);
  47. addCommand(back);
  48. addCommand(refresh);
  49. setCommandListener(this);
  50. alert=new Alert("提示信息");
  51. }
  52. private void refreshData(){
  53. if(codeChoices!=null){
  54. this.delete(codeChoicesID);
  55. }
  56. codeChoices=new ChoiceGroup("选择要删除的基金",ChoiceGroup.MULTIPLE,DataCenter.getFunds(),null);
  57. codeChoicesID=append(codeChoices);
  58. }
  59. public void commandAction(Command command, Displayable displayable) {
  60. if(command == refresh){
  61. refreshData();
  62. }else if(command == back){
  63. navigator.getDisplay().setCurrent(navigator.getDisplayable("mainScreen"));
  64. }else if(command == ok){
  65. for(int i=0;i<codeChoices.size();i++){
  66. if(codeChoices.isSelected(i)){
  67. String str=codeChoices.getString(i);
  68. int index=str.indexOf("(");
  69. String code=str.substring(index+1,str.length()-1);
  70. //System.out.println("select "+i+" "+codes.getString(i)+" code="+code);
  71. DataCenter.delFund(code);
  72. }
  73. }
  74. refreshData();
  75. alert.setString("删除成功!");
  76. alert.setType(AlertType.INFO);
  77. navigator.getDisplay().setCurrent(alert,navigator.getDisplayable("valueScreen"));
  78. navigator.getCanvas("valueScreen").refresh();
  79. }
  80. }
  81. }