Show DefaultUIListener.java syntax highlighted
/*
* Copyright (c) 2007
* Helsinki Institute of Physics
* see LICENSE file for details
*
* DefaultUIListener.java
* Created on Aug 11, 2003
*/
package fi.hip.gb.client;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.FocusEvent;
import java.awt.event.FocusListener;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import java.awt.event.WindowEvent;
import java.awt.event.WindowListener;
import java.rmi.RemoteException;
import javax.swing.JButton;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;
import fi.hip.gb.core.Config;
import fi.hip.gb.core.SessionHandler;
import fi.hip.gb.net.ComputingInterface;
/**
* Listener for default main dialog UI
*
* @author Juho Karppinen
*/
public class DefaultUIListener implements ActionListener, ItemListener, FocusListener,
WindowListener, ListSelectionListener {
/** our main ui */
private DefaultUI ui;
/** Handler for results */
private ResultHandler resultHandler;
/** initialize normal grid proxy */
protected final static String GRIDPROXY_CMD = "GRIDPROXY_CMD";
/** initialize proxy using myproxy server */
protected final static String MYPROXY_CMD = "MYPROXY_CMD";
/** set proxy options */
protected final static String PROXY_OPTIONS_CMD = "PROXY_OPTIONS_CMD";
/** connect to server and load jobs and available list of servers */
protected final static String SYNC_CMD = "SYNC_CMD";
/** remove all jobs */
protected final static String REMOVE_CMD = "REMOVE_CMD";
/** cancel the job */
protected final static String CANCEL_CMD = "CANCEL_CMD";
/** finish permantent agent */
protected final static String FINISH_CMD = "FINISH_CMD";
/** start creation of new job */
protected final static String NEWJOB_CMD = "NEWJOB_CMD";
/** clean all jobs */
protected final static String CLEAR_CMD = "CLEAR_CMD";
/** close the application */
protected final static String CLOSE_CMD = "CLOSE_CMD";
/** show the work description */
protected final static String SHOW_WDS = "WDS_CMD";
/** show the error of execution */
protected final static String SHOW_ERROR = "ERROR_CMD";
protected DefaultUIListener(DefaultUI parentUI) {
ui = parentUI;
resultHandler = new ResultHandler();
}
/**
* Fires when some button is pressed
*
* @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
*/
public void actionPerformed(ActionEvent ae) {
if (ae.getActionCommand().equals(SYNC_CMD)) {
// connects to proxy and fetches existing jobs and services
Main.sync();
} else if (ae.getActionCommand().equals(GRIDPROXY_CMD)) {
ui.gridProxyInit(false);
} else if (ae.getActionCommand().equals(MYPROXY_CMD)) {
ui.gridProxyInit(true);
} else if (ae.getActionCommand().equals(PROXY_OPTIONS_CMD)) {
new ConfigUI(1);
} else if (ae.getActionCommand().equals(NEWJOB_CMD)) {
// open dialog for creating new file, uses defaults from the file
ui.openNewJobUI(null);
} else if (ae.getActionCommand().equals(REMOVE_CMD)) {
// remove selected job from the list and release all resources from
// the server
ui.removeSelectedJob();
} else if (ae.getActionCommand().equals(CANCEL_CMD)) {
// Cancel execution but don't remove instance from server
try {
SessionHandler.getService().abort(ui.getSelectedJob(), ComputingInterface.ABORT_JOB);
} catch (RemoteException e) {
}
} else if (ae.getActionCommand().equals(FINISH_CMD)) {
// stop the permanent agent but don't remove the job
try {
SessionHandler.getService().abort(ui.getSelectedJob(), ComputingInterface.STOP_EXECUTION);
} catch (RemoteException e) {
}
} else if (ae.getActionCommand().equals(CLEAR_CMD)) {
// remove all jobs from list and release their resources from the
// server
ui.removeAllJobs();
} else if (ae.getActionCommand().equals(CLOSE_CMD)) {
ui.dispose();
} else if (ae.getActionCommand().equals(SHOW_WDS)) {
try {
resultHandler.showDescription(SessionHandler.getInstance().getSession(ui.getSelectedJob()), ui);
} catch (RemoteException re) {
Main.errorMessage("Could not show description because the session was not found " + re.getMessage(), null, ui);
}
} else if (ae.getActionCommand().equals(SHOW_ERROR)) {
try {
resultHandler.showError(SessionHandler.getInstance().getSession(ui.getSelectedJob()), ui);
} catch (RemoteException re) {
Main.errorMessage("Could not show the error because the session was not found " + re.getMessage(), null, ui);
}
} else {
String action = ae.getActionCommand();
String[] resultNames;
if (action.equals("*"))
resultNames = new String[0];
else
resultNames = new String[] { action };
try {
// Depending on sourcebutton, show information or show/download results
JButton source = (JButton) ae.getSource();
if(source.getText().equals(Config.getLocalized("analysis.buttons.resultShow"))) {
resultHandler.showResults(SessionHandler.getInstance().getSession(ui.getSelectedJob()),
resultNames);
} else if(source.getText().equals(Config.getLocalized("analysis.buttons.resultInfo"))) {
resultHandler.showResultInfo(SessionHandler.getInstance().getSession(ui.getSelectedJob()),
action,
ui);
} else {
SessionHandler.getService().getResult(ui.getSelectedJob(), resultNames, Boolean.TRUE);
}
} catch(RemoteException re) {
ui.errorMessage("Failed to download the result", re.getMessage(), null, ui);
}
}
}
/**
* For auto download check boxes
* @param ie
*/
public void itemStateChanged(ItemEvent ie) {
Config.getInstance().setAutoDownload(ie.getStateChange() == ItemEvent.SELECTED);
Config.getInstance().store();
}
/**
* Fires when topmost job has been changed on the job list
*
* @see javax.swing.event.ListSelectionListener#valueChanged(javax.swing.event.ListSelectionEvent)
*/
public void valueChanged(ListSelectionEvent e) {
int firstIndex = e.getFirstIndex();
if (firstIndex == -1) {
//if(_cancelBtn != null)
// _cancelBtn.setEnabled(false);
} else {
ui.selectionChanged();
}
}
/**
* @see java.awt.event.FocusListener#focusGained(java.awt.event.FocusEvent)
*/
public void focusGained(FocusEvent fe) {
}
/**
* @see java.awt.event.FocusListener#focusLost(java.awt.event.FocusEvent)
*/
public void focusLost(FocusEvent fe) {
}
/**
* @see java.awt.event.WindowListener#windowClosing(java.awt.event.WindowEvent)
*/
public void windowClosing(WindowEvent e) {
e.getWindow().dispose();
}
/**
* @see java.awt.event.WindowListener#windowClosed(java.awt.event.WindowEvent)
*/
public void windowClosed(WindowEvent e) {
Main.exit();
}
/**
* @see java.awt.event.WindowListener#windowActivated(java.awt.event.WindowEvent)
*/
public void windowActivated(WindowEvent e) {
}
/**
* @see java.awt.event.WindowListener#windowDeactivated(java.awt.event.WindowEvent)
*/
public void windowDeactivated(WindowEvent e) {
}
/**
* @see java.awt.event.WindowListener#windowDeiconified(java.awt.event.WindowEvent)
*/
public void windowDeiconified(WindowEvent e) {
}
/**
* @see java.awt.event.WindowListener#windowIconified(java.awt.event.WindowEvent)
*/
public void windowIconified(WindowEvent e) {
}
/**
* @see java.awt.event.WindowListener#windowOpened(java.awt.event.WindowEvent)
*/
public void windowOpened(WindowEvent e) {
}
}
See more files for this project here