Code Search for Developers
 
 
  

JobsForm.java from GridBlocks at Krugle


Show JobsForm.java syntax highlighted

/*
 * Copyright (c) 2004
 * Helsinki Institute of Physics
 * see LICENSE file for details
 *
 * LiteDescription.java
 * Created on Mar 24, 2004
 */

package fi.hip.gb.client;

import java.util.Vector;

import javax.microedition.lcdui.Choice;
import javax.microedition.lcdui.ChoiceGroup;

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

/**
 * Container for jobIDs and their data. Contains a <code>ChoiceGroup</code>
 * which can be inserted directly inside a form. 
 * 
 * @author Juho Karppinen
 */
public class JobsForm {
	/** list of available sessions */
	private Vector sessions = new Vector();
	/** ui component for selecting job from the list of jobs */
	private ChoiceGroup cgSession = new ChoiceGroup("[not synchronized]", Choice.EXCLUSIVE);
	
	/**
	 * Creates the list of jobs
	 */
	public JobsForm() {
	}

	/**
	 * Gets the choicegroup component containing list of all jobs.
	 * @return choice group object
	 */
	public ChoiceGroup getChoiceGroup() {
	    return this.cgSession;
	}
	
	
	/**
	 * Gets the ID of selected job
	 * @return job ID as Long
	 */
	public Long getSelectedJob() {
		return (Long)this.sessions.elementAt(this.cgSession.getSelectedIndex());
	}
	
	/**
	 * Gets the name of the selected job
	 * @return the job name of selected job
	 */
	public String getSelectedJobName() {
		return this.cgSession.getString(this.cgSession.getSelectedIndex());
	}
	
	/**
	 * Adds new job to the list of jobs
	 * @param text contains syntax jobID#jobname
	 */
	public void addJob(String text) {
		// parse ID and name
		int indexOf = text.indexOf('#');
		//System.out.println("job # " + text);
		Long jobID = new Long(Long.parseLong(text.substring(0, indexOf)));
		String jobname = text.substring(indexOf+1);
		
		addJob(jobID, jobname);
	}

	/**
	 * Adds a job to the list of jobs if it doesn't yet exists.
	 * There is no harm to add the same job many times, duplicates
	 * are not made.
	 * 
	 * @param jobID id of the job
	 * @param name name of the job
	 */
	public void addJob(Long jobID, String name) {
	    if(this.sessions.indexOf(jobID) == -1) {
			int selectedSession = this.cgSession.append(name, null);
		    
			this.sessions.insertElementAt(jobID, selectedSession);
			this.cgSession.setLabel(this.cgSession.size() + " jobs available");
			this.cgSession.setSelectedIndex(selectedSession, true);
	    }
	}
	
	/**
	 * State has changed, update the item
	 * @param jobID id of the job
	 * @param state current state of the job
	 */
	public void statusUpdate(Long jobID, int state) {
	    int index = this.sessions.indexOf(jobID);
	    String name = this.cgSession.getString(index);
	    name = name.substring(0, 
	            name.indexOf('<')!=-1 ? name.indexOf('<')-1 : name.length());
	    this.cgSession.set(index, name + " <" + LiteStatus.STATES[state] + ">", null);
	}
	
	/**
	 * Clears all jobs.
	 */
	public void clearJobs() {
	    clearJobs("No jobs available");
	}
	
	/**
	 * Clears all jobs and sets the new title.
	 * @param title title for the ChoiceGroup object
	 */
	public void clearJobs(String title) {
	    this.cgSession.deleteAll();
	    this.sessions.removeAllElements();
	    this.cgSession.setLabel(title);
	}
	
	/**
	 * Removes the selected job from the list.
	 */
	public void removeJob() {
	    removeJob(getSelectedJob());
	}
	
	/**
	 * Removes the job from the list.
	 * @param jobID id to be removed from the list
	 */
	public void removeJob(Long jobID) {
		int index = this.sessions.indexOf(jobID);
		this.cgSession.delete(index);
		this.sessions.removeElementAt(index);
		this.cgSession.setLabel(this.cgSession.size() + " jobs 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