Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
//+======================================================================
// $Source: $
//
// Project: Tango
//
// Description: Basic Dialog Class to display info
//
// $Author: pascal_verdier $
//
// Copyright (C) : 2004,2005,2006,2007,2008,2009,2009
// European Synchrotron Radiation Facility
// BP 220, Grenoble 38043
// FRANCE
//
// This file is part of Tango.
//
// Tango is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Tango is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Tango. If not, see .
//
// $Revision: $
//
// $Log: $
//
//-======================================================================
package admin.astor.tools;
import admin.astor.AstorUtil;
import fr.esrf.Tango.DevFailed;
import fr.esrf.TangoApi.ApiUtil;
import fr.esrf.TangoApi.DbServer;
import fr.esrf.TangoDs.Except;
import fr.esrf.tangoatk.widget.util.ATKGraphicsUtils;
import fr.esrf.tangoatk.widget.util.ErrorPane;
import javax.swing.*;
import java.awt.*;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.net.URL;
import java.util.ArrayList;
import java.util.List;
/**
* JDialog Class to display server info
*
* @author Pascal Verdier
*/
@SuppressWarnings("MagicConstant")
public class ServerUsageDialog extends JDialog {
private JFrame parent;
private List tangoClasses = new ArrayList<>();
private List domains = new ArrayList<>();
private int nbServers;
private String wildcard;
private String urlFile;
private int serversCounter = 0;
private static final String header =
"\n" +
"\n" +
"\n" +
" title \n" +
"\n" +
"\n" +
"\n";
private static final String footer =
"\n" +
"\n";
//===============================================================
/**
* Creates new form ServerUsageDialog
*
* @param parent the parent instance
* @throws DevFailed if Database commands fail
*/
//===============================================================
public ServerUsageDialog(JFrame parent) throws DevFailed {
super(parent, true);
this.parent = parent;
initComponents(null);
}
//===============================================================
/**
* Creates new form ServerUsageDialog
*
* @param parent the parent instance
* @throws DevFailed if Database commands fail
*/
//===============================================================
@SuppressWarnings("WeakerAccess")
public ServerUsageDialog(JFrame parent, String server) throws DevFailed {
super(parent, true);
this.parent = parent;
initComponents(server);
}
//===============================================================
//===============================================================
private void initComponents(String server) throws DevFailed {
initComponents();
displayServerUsage(server);
ATKGraphicsUtils.centerDialog(this);
}
//===============================================================
//===============================================================
private void displayServerUsage(String inputServer) throws DevFailed {
List serverList;
if (inputServer!=null) {
serverList = new ArrayList<>();
serverList.add(inputServer);
}
else {
// Get a server list from database for selection
String[] servers = ApiUtil.get_db_obj().get_server_name_list();
ListDialog dialog = new ListDialog(parent,
"Servers in " + ApiUtil.getTangoHost(), servers);
serverList = dialog.showDialog();
if (serverList==null || serverList.isEmpty()) {
doClose();
return;
}
}
try {
AstorUtil.startSplash(serverList.get(0));
for (String server : serverList) {
wildcard = server;
// Convert to a wildcard and clear previous computation results
wildcard += "/*";
titleLabel.setText(wildcard);
tangoClasses.clear();
domains.clear();
// Get existing server/instances list
String[] serverNames = ApiUtil.get_db_obj().get_server_list(wildcard);
nbServers = serverNames.length;
// And for each one, distribute by class
for (String serverName : serverNames) {
AstorUtil.increaseSplashProgress(1, serverName);
fillTangoClasses(serverName);
// Sleep a bit to do not overload database
try {
Thread.sleep(20);
} catch (InterruptedException e) { /* */ }
}
// Build tml code and url and put it in edito pane
URL url = new URL(buildTmpFile(toHtml()));
JEditorPane editorPane = new JEditorPane();
editorPane.setEditable(false);
editorPane.setPage(url);
// Then pane scrollable pane and in a tabbed pane
JScrollPane scrollPane = new JScrollPane(editorPane);
scrollPane.setPreferredSize(new Dimension(480, 440));
tabbedPane.add(scrollPane);
tabbedPane.setTitleAt(serversCounter++, server);
tabbedPane.setSelectedComponent(scrollPane);
}
AstorUtil.stopSplash();
}
catch (IOException e) {
Except.throw_exception("URL failed", e.getMessage());
}
//new PopupHtml(parent, false).show(toHtml());
}
//======================================================
//======================================================
private String buildTmpFile(String code) {
String urlStr = null;
try {
int random_value = new java.util.Random().nextInt(30000);
String tmpDir = System.getProperty("java.io.tmpdir");
urlFile = tmpDir + "/html." + random_value;
FileOutputStream outputStream = new FileOutputStream(urlFile);
outputStream.write((header + code + footer).getBytes());
outputStream.close();
urlStr = "file:" + urlFile;
} catch (Exception e) {
ErrorPane.showErrorMessage(parent, null, e);
e.printStackTrace();
}
return urlStr;
}
//===============================================================
/**
* This method is called from within the constructor to
* initialize the form.
* WARNING: Do NOT modify this code. The content of this method is
* always regenerated by the Form Editor.
*/
//===============================================================
// //GEN-BEGIN:initComponents
private void initComponents() {
javax.swing.JPanel topPanel = new javax.swing.JPanel();
titleLabel = new javax.swing.JLabel();
javax.swing.JPanel bottomPanel = new javax.swing.JPanel();
javax.swing.JButton anotherBtn = new javax.swing.JButton();
javax.swing.JLabel jLabel1 = new javax.swing.JLabel();
javax.swing.JButton cancelBtn = new javax.swing.JButton();
tabbedPane = new javax.swing.JTabbedPane();
addWindowListener(new java.awt.event.WindowAdapter() {
public void windowClosing(java.awt.event.WindowEvent evt) {
closeDialog(evt);
}
});
titleLabel.setFont(new java.awt.Font("Dialog", 1, 18)); // NOI18N
titleLabel.setText("Dialog Title");
topPanel.add(titleLabel);
getContentPane().add(topPanel, java.awt.BorderLayout.NORTH);
anotherBtn.setText("Another Server");
anotherBtn.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
anotherBtnActionPerformed(evt);
}
});
bottomPanel.add(anotherBtn);
jLabel1.setText(" ");
bottomPanel.add(jLabel1);
cancelBtn.setText("Dismiss");
cancelBtn.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
cancelBtnActionPerformed(evt);
}
});
bottomPanel.add(cancelBtn);
getContentPane().add(bottomPanel, java.awt.BorderLayout.SOUTH);
getContentPane().add(tabbedPane, java.awt.BorderLayout.CENTER);
pack();
}// //GEN-END:initComponents
//===============================================================
//===============================================================
@SuppressWarnings({"UnusedParameters"})
private void cancelBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cancelBtnActionPerformed
doClose();
}//GEN-LAST:event_cancelBtnActionPerformed
//===============================================================
//===============================================================
@SuppressWarnings({"UnusedParameters"})
private void closeDialog(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_closeDialog
doClose();
}//GEN-LAST:event_closeDialog
//===============================================================
//===============================================================
@SuppressWarnings({"UnusedParameters"})
private void anotherBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_anotherBtnActionPerformed
try {
displayServerUsage(null);
} catch (DevFailed e) {
ErrorPane.showErrorMessage(parent, null, e);
}
}//GEN-LAST:event_anotherBtnActionPerformed
//===============================================================
/**
* Closes the dialog
*/
//===============================================================
private void doClose() {
// Remove url file if exists
try {
if (urlFile!=null)
if (!new File(urlFile).delete())
System.err.println("Cannot delete " + urlFile);
} catch (Exception e) {
ErrorPane.showErrorMessage(parent, null, e);
}
if (parent == null)
System.exit(0);
else {
setVisible(false);
dispose();
}
}
//===============================================================
//===============================================================
private void fillTangoClasses(String serverName) throws DevFailed {
DbServer server = new DbServer(serverName);
String[] class_dev = server.get_device_class_list();
boolean doneForServer = false;
for (int i=0 ; i").append(nbDevices).append(" devices for ").
append(nbServers).append(" server instances \n");
sb.append("
\n");
// On table containing 2 tables
sb.append("
\n");
// One table by domain with instances
sb.append("By Domain:\n");
sb.append("
\n");
sb.append("
Domain
Instances
Devices
\n");
for (Domain domain : domains) {
sb.append("
").append(domain.name).append("
")
.append(domain.nbServers).append("
")
.append(domain.size()).append("
\n");
}
sb.append("
\n");
sb.append("
\n");
// One table devices / class
sb.append("Devices by Class:\n");
sb.append("
\n");
sb.append("
Class name
Devices
\n");
for (TangoClass tangoClass : tangoClasses) {
sb.append("