001: /*
002: *
003: * Copyright (c) 2007, Sun Microsystems, Inc.
004: *
005: * All rights reserved.
006: *
007: * Redistribution and use in source and binary forms, with or without
008: * modification, are permitted provided that the following conditions
009: * are met:
010: *
011: * * Redistributions of source code must retain the above copyright
012: * notice, this list of conditions and the following disclaimer.
013: * * Redistributions in binary form must reproduce the above copyright
014: * notice, this list of conditions and the following disclaimer in the
015: * documentation and/or other materials provided with the distribution.
016: * * Neither the name of Sun Microsystems nor the names of its contributors
017: * may be used to endorse or promote products derived from this software
018: * without specific prior written permission.
019: *
020: * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
021: * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
022: * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
023: * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
024: * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
025: * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
026: * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
027: * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
028: * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
029: * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
030: * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
031: */
032: package example.pim;
033:
034: import javax.microedition.lcdui.Alert;
035: import javax.microedition.lcdui.AlertType;
036: import javax.microedition.lcdui.Command;
037: import javax.microedition.lcdui.CommandListener;
038: import javax.microedition.lcdui.Display;
039: import javax.microedition.lcdui.Displayable;
040: import javax.microedition.lcdui.Form;
041: import javax.microedition.lcdui.List;
042: import javax.microedition.midlet.MIDlet;
043: import javax.microedition.pim.PIM;
044: import javax.microedition.pim.PIMException;
045: import javax.microedition.pim.PIMList;
046:
047: /**
048: * Demonstrate the use of JSR 75 PIM APIs
049: */
050: public class ListSelectionScreen extends List implements
051: CommandListener, Runnable {
052: private final Command selectCommand = new Command("Select",
053: Command.OK, 1);
054: private final Command backCommand = new Command("Back",
055: Command.BACK, 1);
056: private final PIMDemo midlet;
057: private final Displayable caller;
058: private final int listType;
059:
060: public ListSelectionScreen(PIMDemo midlet, Displayable caller,
061: int listType) {
062: super ("Select a list", List.IMPLICIT);
063:
064: String[] lists = PIM.getInstance().listPIMLists(listType);
065:
066: for (int i = 0; i < lists.length; i++) {
067: append(lists[i], null);
068: }
069:
070: setSelectCommand(selectCommand);
071: addCommand(backCommand);
072: setCommandListener(this );
073: this .midlet = midlet;
074: this .caller = caller;
075: this .listType = listType;
076: }
077:
078: public void commandAction(Command command, Displayable displayable) {
079: if (command == backCommand) {
080: Display.getDisplay(midlet).setCurrent(caller);
081: } else if (command == selectCommand) {
082: Form form = new Form("Loading PIM list");
083: form.append("Please wait...");
084: Display.getDisplay(midlet).setCurrent(form);
085: new Thread(this ).start();
086: }
087: }
088:
089: public void run() {
090: String listName = getString(getSelectedIndex());
091:
092: try {
093: PIMList list = PIM.getInstance().openPIMList(listType,
094: PIM.READ_WRITE, listName);
095: Displayable screen = new ItemSelectionScreen(midlet, this ,
096: listType, list);
097: Display.getDisplay(midlet).setCurrent(screen);
098: } catch (Exception e) {
099: midlet.reportException(e, this);
100: }
101: }
102: }
|