net.sf.gluebooster.java.booster.basic.gui.swing.JOptionPaneUserInteraction Maven / Gradle / Ivy
package net.sf.gluebooster.java.booster.basic.gui.swing;
import java.awt.Component;
import javax.swing.JOptionPane;
import net.sf.gluebooster.java.booster.basic.gui.DialogConfiguration;
import net.sf.gluebooster.java.booster.basic.gui.UserInteractionAbstraction;
import net.sf.gluebooster.java.booster.essentials.utils.Constants;
import net.sf.gluebooster.java.booster.essentials.utils.ThrowableBoostUtils;
/**
* Implementation of the user interaction by using the JOptionPane.
*
* @author CBauer
*
*/
public class JOptionPaneUserInteraction extends UserInteractionAbstraction {
/**
* The parent component of dialogs.
*/
private Component parentComponent = null;
public Component getParentComponent() {
return parentComponent;
}
public void setParentComponent(Component parentComponent) {
this.parentComponent = parentComponent;
}
/**
* Show an input dialog and return its result.
*
* @param configuration
* configuration of the dialog
* @return the result of the dialog
*/
private String showInputDialog(DialogConfiguration configuration) throws Exception {
return JOptionPane.showInputDialog(parentComponent, configuration.getMessage(), configuration.getInitialValue());
}
@Override
protected Object callImpl(DialogConfiguration... parameters) throws Exception {
// Object command = parameters[0];
DialogConfiguration dialog = parameters[0];
Object command = dialog.getType();
if (Constants.CONFIRM.is(command) || Constants.MESSAGE.is(command)) {
JOptionPane.showMessageDialog((Component) dialog.getParent(), dialog.getMessage(), dialog.getTitle(), JOptionPane.PLAIN_MESSAGE);
return JOptionPane.PLAIN_MESSAGE;
} else if (Constants.OK_CANCEL.is(command)) {
return JOptionPane.showConfirmDialog((Component) dialog.getParent(), dialog.getMessage(), dialog.getTitle(), JOptionPane.OK_CANCEL_OPTION);
} else if (Constants.INPUT.is(command)) {
return JOptionPane.showInputDialog(parentComponent, dialog.getMessage(), dialog.getInitialValue());
} else {
throw ThrowableBoostUtils.createNotImplementedException("command not supported: ", command);
}
}
}