
jive.DevWizard Maven / Gradle / Ivy
package jive;
import fr.esrf.Tango.DevFailed;
import fr.esrf.Tango.DevSource;
import fr.esrf.TangoApi.*;
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Vector;
/** The Device wizard dialog. */
public class DevWizard extends JDialog implements ActionListener {
final static Font wizFont = new Font("Dialog",Font.PLAIN,12);
// Common component of the Wizard dialog
private JButton nextButton;
private JButton backButton;
private JButton skipButton;
private JButton cancelButton;
private JPanel buttoniPanel;
private JPanel buttonPanel;
private JPanel innerPanel;
private JPanel helpPanel;
private JTextArea helpText;
private JTextArea helpIconText;
private JLabel helpIcon;
private JLabel helpLabel;
private JPanel wizardContainer;
private Vector allPanels;
int activePanel = -1;
private Database db;
private String dbName;
static DeviceProxy starter = null;
static public String lastServStarted;
/**
* Construct a wizard dialog.
* @param parent Parent frame
*/
public DevWizard(Frame parent) {
super(parent,true);
initComponents();
this.starter = null;
lastServStarted = null;
}
/**
* Construct a wizard dialog.
* @param parent Parent dialog
*/
public DevWizard(Dialog parent) {
super(parent,true);
initComponents();
this.starter = null;
lastServStarted = null;
}
/**
* Construct a wizard dialog.
* @param parent Parent frame
* @param starter Starter device reference to start created server.
*/
public DevWizard(Frame parent, DeviceProxy starter) {
this(parent);
this.starter = starter;
lastServStarted = null;
}
/**
* Construct a wizard dialog.
* @param parent Parent dialog
* @param starter Starter device reference to start created server.
*/
public DevWizard(Dialog parent, DeviceProxy starter) {
this(parent);
this.starter = starter;
lastServStarted = null;
}
/**
* Shows the server wizard.
* @param serverList List of allowed server. Pass null for free server selection.
*/
public void showWizard(String[] serverList) {
allPanels = new Vector();
allPanels.add(new ServerPanel(this,serverList)); // Server registration
displayWizard();
}
/**
* Shows the classes wizard.
* @param serverName Name of server to be edited
*/
public void showClassesWizard(String serverName) {
allPanels = new Vector();
try {
DeviceProxy admin = new DeviceProxy("dserver/"+serverName);
addPanel(new ClassPanel(this,serverName,admin));
displayWizard();
} catch (DevFailed e) {
JiveUtils.showTangoError(e);
}
}
/**
* Shows the devices wizard.
* @param serverName Name of the server
* @param className Name of class
*/
public void showDevicesWizard(String serverName,String className) {
allPanels = new Vector();
WizardPanel devPanel = new DevicePanel(this,serverName,className);
addPanel( devPanel );
addPanel( new FinishPanel(this,serverName,null,devPanel) );
displayWizard();
}
/**
* Shows the property wizard for the specified device.
* @param serverName Name of the server hosting the device
* @param className Name of class hosting the device
* @param devName Device to be edited
*/
public void showDeviceWizard(String serverName,String className,String devName) {
allPanels = new Vector();
try {
DeviceData classData = new DeviceData();
classData.insert(className);
DeviceProxy adminDev = new DeviceProxy("dserver/"+serverName);
DeviceData ret = adminDev.command_inout("QueryWizardDevProperty", classData);
String[] conf = ret.extractStringArray();
for (int j = 0; j < conf.length; j += 3) {
addPanel( new PropertyPanel(this, PropertyPanel.DEVICE_PROPERTY,serverName,
devName, conf[j], conf[j + 1], conf[j + 2], className));
}
addPanel( new FinishPanel(this,serverName,null,null) );
displayWizard();
} catch (DevFailed e) {
JiveUtils.showTangoError(e);
}
}
private void displayWizard() {
setActivePanel(0);
JiveUtils.centerDialog(this);
setVisible(true);
dispose();
}
boolean canBack() {
return activePanel>0;
}
private void initComponents() {
innerPanel = new JPanel(new BorderLayout());
setContentPane(innerPanel);
setResizable(false);
// --------------------------------------------------------
// Button panel
// --------------------------------------------------------
backButton = new JButton("< Back");
backButton.setFont(wizFont);
backButton.addActionListener(this);
nextButton = new JButton("Next >");
nextButton.setFont(wizFont);
nextButton.addActionListener(this);
skipButton = new JButton("Skip");
skipButton.setFont(wizFont);
skipButton.addActionListener(this);
cancelButton = new JButton("Cancel");
cancelButton.setFont(wizFont);
cancelButton.addActionListener(this);
buttoniPanel = new JPanel();
FlowLayout fl = new FlowLayout(FlowLayout.RIGHT);
buttoniPanel.setLayout(fl);
buttoniPanel.add(backButton);
buttoniPanel.add(nextButton);
buttoniPanel.add(skipButton);
buttoniPanel.add(new JLabel(" "));
buttoniPanel.add(cancelButton);
buttonPanel = new JPanel(new BorderLayout());
buttonPanel.add(buttoniPanel,BorderLayout.CENTER);
JSeparator sep = new JSeparator();
sep.setOrientation(JSeparator.HORIZONTAL);
buttonPanel.add(sep,BorderLayout.NORTH);
innerPanel.add(buttonPanel,BorderLayout.SOUTH);
// --------------------------------------------------------
// Help panel
// --------------------------------------------------------
helpPanel = new JPanel(null);
//helpPanel.setBackground(Color.GREEN);
helpPanel.setPreferredSize(new Dimension(520,240));
helpIcon = new JLabel();
helpIcon.setBounds(10,10,128,128);
helpPanel.add(helpIcon);
helpLabel = new JLabel();
helpLabel.setFont(new Font("Dialog",Font.BOLD,16));
helpLabel.setBounds(140,10,370,30);
helpPanel.add(helpLabel);
helpText = new JTextArea();
helpText.setEditable(false);
helpText.setBorder(null);
helpText.setBounds(140,40,370,98);
helpText.setBackground(innerPanel.getBackground());
helpText.setLineWrap(true);
helpText.setWrapStyleWord(true);
helpPanel.add(helpText);
helpIconText = new JTextArea();
helpIconText.setEditable(false);
helpIconText.setBorder(null);
helpIconText.setMargin(new Insets(0,0,0,0));
helpIconText.setBackground(innerPanel.getBackground());
helpIconText.setFont(new Font("Dialog",Font.BOLD,10));
helpIconText.setLineWrap(true);
helpIconText.setWrapStyleWord(true);
helpIconText.setBounds(10,140,148,95);
helpPanel.add(helpIconText);
innerPanel.add(helpPanel,BorderLayout.NORTH);
wizardContainer = new JPanel(new GridLayout(1,1));
wizardContainer.setBorder(null);
wizardContainer.setBounds(160,140,350,95);
helpPanel.add(wizardContainer);
// ------------------------------------------------------
// Global Tango initialisation
// ------------------------------------------------------
try {
db = ApiUtil.get_db_obj();
dbName = db.get_tango_host();
} catch (DevFailed e) {
JiveUtils.showTangoError(e);
return;
}
setTitle("Tango Device Installation Wizard on " + dbName);
}
void addPanel(WizardPanel p) {
allPanels.add(p);
}
void addPanel(int idx,WizardPanel p) {
allPanels.add(idx,p);
}
WizardPanel getPanel(int i) {
return (WizardPanel)allPanels.get(i);
}
Vector getPanels() {
return allPanels;
}
private void setActivePanel(int p) {
activePanel = p;
WizardPanel panel = getPanel(p);
helpIcon.setIcon(panel.getIcon());
helpText.setText(panel.getDescription());
helpLabel.setText(panel.getTitle());
helpIconText.setText(panel.getSubTitle());
wizardContainer.removeAll();
wizardContainer.add(panel);
backButton.setEnabled(panel.getBackState());
backButton.setText(panel.getBackText());
nextButton.setEnabled(panel.getNextState());
nextButton.setText(panel.getNextText());
skipButton.setVisible(panel.getSkipState());
skipButton.setText(panel.getSkipText());
innerPanel.revalidate();
repaint();
}
private void goToNextPanel() {
if(activePanel+1";
}
public boolean next() {
return false;
}
public boolean getSkipState() {
return false;
}
public String getSkipText() {
return "Skip";
}
public boolean skip() {
return false;
}
public void removeNextPanel() {
// Remove all panels that follow this panel
int idx = parent.getPanels().indexOf(this);
int toDel = parent.getPanels().size() - idx - 1;
for(int i=0;i display just a warning
JOptionPane.showMessageDialog(parent,
srvName + " is alredy running on " + running_on,
"Jive Message", JOptionPane.WARNING_MESSAGE);
return ALREADY_STARTED;
}
else
fr.esrf.TangoDs.Except.throw_exception("StartServerFailed",
srvName + " is already running on " + d.get_host(),
"DevWizard.startServer()");
}
// Check if already registred on another host
if (running_on!=null)
{
if (running_on.startsWith(hostname)==false)
{
// Same host -> display warning and ask question
Object[] options = { "Continue", "Cancel" };
if (JOptionPane.showOptionDialog(parent,
srvName + " is alredy registred on " + running_on,
"Warning",
JOptionPane.DEFAULT_OPTION,
JOptionPane.WARNING_MESSAGE,
null, options, options[0])!=JOptionPane.OK_OPTION)
return DO_NOT_START;
}
}
return START_IT;
}
/**
* Start the server
*/
private DeviceProxy startServer(String srvName)
{
DeviceProxy dev = null;
String devname = "dserver/" + srvName;
String hostname = DevWizard.starter.name();
hostname = hostname.substring(hostname.lastIndexOf("/")+1);
try
{
dev = new DeviceProxy(devname);
switch(canBeStarted(dev, srvName, hostname))
{
case DO_NOT_START:
return null;
case ALREADY_STARTED:
return dev;
default:
// Register server on host to be displayed in astor
// even startup failed.
DbDevExportInfo info =
new DbDevExportInfo(devname, "null", hostname, "null");
ApiUtil.get_db_obj().export_device(info);
ApiUtil.get_db_obj().unexport_device(devname);
// Try to start it
DeviceData argin = new DeviceData();
argin.insert(srvName);
DevWizard.starter.command_inout("DevStart", argin);
// Check if startup succeed
DevWizard.starter.set_source(DevSource.DEV);
boolean started = false;
for (int i=0 ; !started && i<5 ; i++) // 5 seconds timeout
{
Thread.sleep(1000);
DeviceAttribute att = DevWizard.starter.read_attribute("RunningServers");
String[] servlist = att.extractStringArray();
for (int j=0 ; j0;
}
public boolean next() {
int idx = classList.getSelectedIndex();
if(idx<0) {
JiveUtils.showJiveError("Please select a class first.");
return false;
}
removeNextPanel();
// Create class property panel
try {
DeviceData classData = new DeviceData();
classData.insert(allClasses[idx]);
DeviceData ret = adminDev.command_inout("QueryWizardClassProperty", classData);
String[] conf = ret.extractStringArray();
for (int j = 0; j < conf.length; j += 3) {
parent.addPanel(new PropertyPanel(parent, PropertyPanel.CLASS_PROPERTY,serverName,
allClasses[idx], conf[j], conf[j + 1], conf[j + 2],null));
}
} catch (DevFailed e) {
JiveUtils.showTangoError(e);
}
// Create Device panel
WizardPanel devPanel = new DevicePanel(parent,serverName,allClasses[idx]);
parent.addPanel( devPanel );
parent.addPanel( new FinishPanel(parent,serverName,this,devPanel) );
return true;
}
public boolean getSkipState() {
return allClasses.length>0;
}
public boolean skip() {
int idx = classList.getSelectedIndex();
if(idx<0) {
JiveUtils.showJiveError("Please select a class first.");
return false;
}
// Skip class definiton
// Jump to device definition
// Create Device panel
removeNextPanel();
WizardPanel devPanel = new DevicePanel(parent,serverName,allClasses[idx]);
parent.addPanel( devPanel );
parent.addPanel( new FinishPanel(parent,serverName,this,devPanel) );
return true;
}
public String getSkipText() {
return "Declare device";
}
public String getNextText() {
return "Edit Class";
}
public boolean back() {
return true;
}
}
/**
* Device Decalration panel.
*/
class DevicePanel extends WizardPanel {
String className;
String serverName;
JComboBox deviceCombo;
JLabel deviceLabel;
public DevicePanel(DevWizard parent,String serverName,String className) {
setLayout(null);
this.parent = parent;
this.className = className;
this.serverName = serverName;
deviceLabel = new JLabel("Device name");
deviceLabel.setFont(DevWizard.wizFont);
deviceLabel.setBounds(10,30,100,25);
add(deviceLabel);
deviceCombo = new JComboBox();
deviceCombo.setEditable(true);
deviceCombo.setFont(DevWizard.wizFont);
deviceCombo.setBounds(115,30,160,25);
add(deviceCombo);
try {
Database db = ApiUtil.get_db_obj();
String[] devList = db.get_device_name(serverName ,className);
for(int i=0;i
© 2015 - 2025 Weber Informatics LLC | Privacy Policy