Code Search for Developers
 
 
  

Results.java from GridBlocks at Krugle


Show Results.java syntax highlighted

/*
 * Copyright (c) 2005
 * Helsinki Institute of Physics
 * see LICENSE file for details
 *
 * Results.java
 * Created on Nov 20, 2003
 */

package fi.hip.gb.client;

import java.util.Enumeration;
import java.util.Vector;

import javax.microedition.lcdui.Choice;
import javax.microedition.lcdui.ChoiceGroup;
import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.CommandListener;
import javax.microedition.lcdui.Displayable;
import javax.microedition.lcdui.Form;

import fi.hip.gb.midlet.core.LiteStorage;

/**
 * Results stored on record store can be enumerated
 * and shown in a list where they can be selected and viewed
 * on the screen.
 * 
 * @author Juho Karppinen
 */
public class Results extends Form implements CommandListener {	
	/** available results */
	private ChoiceGroup results;
	/** mappes the result for correct storage */
	private Vector storages = new Vector();
 
	/** command for showing the result */
	private Command showCommand = new Command("Show", Command.SCREEN, 1);
	/** command for deleteing the result */
	private Command deleteCommand = new Command("Delete", Command.SCREEN, 1);
	/** command for sending the result over bluetooth network */
	private Command sendCommand = new Command("Send over bluetooth", Command.SCREEN, 2);
	
	public Results() {
		super("Offline results");
		
		results = new ChoiceGroup("0 results available", Choice.EXCLUSIVE);
		append(results);
		
		addCommand(new Command("Back", Command.BACK, 1));
		setCommandListener(this);
		
		this.storages = LiteStorage.iterate();
		for (Enumeration en = this.storages.elements(); en.hasMoreElements();) {
            LiteStorage storage = (LiteStorage) en.nextElement();
            this.results.append(storage.getDescription().getJobname(), null);
        }
		updateCount();
	}

	public void commandAction(Command c, Displayable disp) {
		if ((c.getCommandType() == Command.BACK)) {
			MIDui.back(true);
		} else {
			int currentIndex = this.results.getSelectedIndex();
			int recordID =
				((Integer) this.storages.elementAt(currentIndex)).intValue();
			
			LiteStorage item = null;
			try {
				item = new LiteStorage(recordID);
			}catch(Exception e) {
				MIDui.showException("Failed to load result", e);
			}
			if(c == showCommand) {
				MIDui.showStatus(item);
			} else if(c == deleteCommand) {
				deleteItem(item);
			} else if(c == sendCommand) {
				MIDui.instance.sendItem(item);
				//LiteStatus status = new LiteStatus(new Long(-1), LiteStatus.RESULT_STATE, null, null, null, null, null, new LiteResult[] {result});
				//status.setJobName("name");
				//MIDui.instance.showBroadcasts(status);
			}
		}
	}
	
	/**
	 * Removes the item from record store
	 * @param item the result element to be removed
	 */
	private void deleteItem(LiteStorage item) {
	    /*
		try {
			int currentIndex = results.getSelectedIndex();
			results.delete(currentIndex);
			storages.removeElementAt(currentIndex);
			StorageUtils.deleteRecord(LiteStorage.STORAGE_NAME, item.getRecordID());
			
			updateCount();
			
			MIDui.showAlert("Result deleted",
					item.getDescription().getJobname() + " deleted succesfully",
				AlertType.INFO);
		} catch (Exception rse) {
			MIDui.showException("Cannot delete result " + item.getDescription().getJobname(), rse);
		}
		*/
	}
	
	/**
	 * Updates the UI to reflect the change of result count
	 */
	private void updateCount() {
		if(results.size() > 0) {	
			addCommand(showCommand);
			addCommand(deleteCommand);
			addCommand(sendCommand);
		} else {
			removeCommand(showCommand);
			removeCommand(deleteCommand);
			removeCommand(sendCommand);
		}
		results.setLabel(results.size() + " results available");
	}
}



See more files for this project here

GridBlocks

GridBlocks builds a grid application framework via easy-to-use building blocks in distributed environment. The framework offers components for Grid security, distributed storage, computing, and Portlet web interfaces.

Project homepage: http://sourceforge.net/projects/gridblocks
Programming language(s): Java,JSP,XML
License: other

  BluetoothBrowser.java
  Broadcasts.java
  CameraCanvas.java
  Configs.java
  DispatchForm.java
  GPSForm.java
  GenericImageCanvas.java
  GenericResultForm.java
  GraphicsCanvas.java
  InfoForm.java
  InputUI.java
  JobsForm.java
  Logging.java
  MIDui.java
  MediaPlayer.java
  PictureCanvas.java
  ProgressForm.java
  Results.java
  StatusForm.java
  TextForm.java
  Thumbnails.java