📄 filedownloaddialog.java
字号:
SybaseSQL ssSelNode = new SybaseSQL();
boolean successSelNode = ssSelNode.query(strSelNode);
if (successSelNode){
getDefaultTableModel_list().setRowCount(ssSelNode.count());
int i=0;
while (ssSelNode.nextRecord()){
String sysname=ssSelNode.getValue("SysName");
int pos=sysname.indexOf(".");
if(pos>0)
sysname=sysname.substring(0,pos);
defaultTableModel_list.setValueAt(sysname,i,0);
defaultTableModel_list.setValueAt(ssSelNode.getValue("ManageIP"),i,1);
defaultTableModel_list.setValueAt("private",i,2);
Boolean value = new Boolean(true);
defaultTableModel_list.setValueAt(value,i,3);
defaultTableModel_list.setValueAt("等待输入或返回",i,4);
i++;
}
}else getDefaultTableModel_list().setRowCount(1);
}
});
}
return jComboBox_Local;
}
/**
* This method initializes jTextField_Note
*
* @return javax.swing.jTextField_Note
*/
private JTextField getJTextField_Note() {
if (jTextField_Note == null) {
jTextField_Note = new JTextField();
jTextField_Note.setPreferredSize(new Dimension(120,30));
}
return jTextField_Note;
}
/**
* This method initializes jPanel1
*
* @return javax.swing.JPanel
*/
private JPanel getJPanel1() {
if (jPanel1 == null) {
jPanel1 = new JPanel();
GridLayout gridLayout1 = new GridLayout();
gridLayout1.setHgap(30);
gridLayout1.setVgap(30);
jPanel1.setLayout(gridLayout1);
jPanel1.setBounds(2, 246, 395, 40);
gridLayout1.setRows(1);
jPanel1.add(getJBt_Download(), null);
jPanel1.add(getJBt_Quit(), null);
jPanel1.add(getJBt_OpenFile(), null);
}
return jPanel1;
}
public static String getTempFileName() {
DateFormat df = new SimpleDateFormat("yyyyMMddHHmmss");
return df.format(new Date());
}
/**
* This method initializes JBt_Download
*
* @return javax.swing.JBt_Download
*/
private JButton getJBt_Download() {
if (jBt_Download == null) {
jBt_Download = new JButton();
jBt_Download.setText("开始下载");
jBt_Download.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent e) {
// TODO Auto-generated Event stub actionPerformed()
String ip=jTextField_DeviceIP.getText();
String down="T";
String community=jTextField_WriteComm.getText();
String fileType=jComboBox_FileType.getSelectedItem().toString();
String strTime = getTempFileName();
String fileName=null;
if(!fileType.equals("iosFile"))
fileName = ip+"_"+fileType+"_"+strTime;
else fileName=ip+"_"+jTextField_FileName.getText()+"_"+strTime;
URLConnection ucon = null ;
String parameters = "?RemoteAddr=" + ip + "&Community="
+ community + "&FileType=" + fileType+"&UpOrDown="+down+"&FileName="+fileName;
try {
URL theURL = new URL(snmpTftpURL + parameters ) ;
ucon = theURL.openConnection() ;
ucon.setUseCaches( false ) ;
ucon.setDoInput( true ) ;
ucon.setDoOutput( false ) ;
ucon.connect() ;
} catch ( Exception ex ) {
System.out.println("SnmpTftpServlet call failed" + ex.getMessage());
return;
}
System.out.println(snmpTftpURL + parameters);
int result=ucon.getHeaderFieldInt("Result",0);
if (result==1){
jTextField_FileName.setText(fileName);
ResWriteLog log = new ResWriteLog();
log.writeLog(userId,ip,"配置文件下载"+ip,"配置管理","1","");
System.out.println("download ok");// TODO Auto-generated Event stub actionPerformed()
if(!fileType.equals("iosFile")){
ConfigurationViewDialog configurationView= new ConfigurationViewDialog();
configurationView.displayConfig(fileName);
configurationView.setVisible(true);
}
}else if(result==0){
jTextField_FileName.setText(ucon.getHeaderField("FailureCause"));
ResWriteLog log = new ResWriteLog();
log.writeLog(userId,ip,"配置文件下载"+ip,"配置管理","0","");
}
}
});
}
return jBt_Download;
}
/**
* This method initializes jBt_Quit
*
* @return javax.swing.jBt_Quit
*/
private JButton getJBt_Quit() {
if (jBt_Quit == null) {
jBt_Quit = new JButton();
jBt_Quit.setText("退出");
jBt_Quit.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent e) {
setVisible(false); // TODO Auto-generated Event stub actionPerformed()
}
});
}
return jBt_Quit;
}
/**
* This method initializes jBt_OpenFile
*
* @return javax.swing.jBt_OpenFile
*/
private JButton getJBt_OpenFile() {
if (jBt_OpenFile == null) {
jBt_OpenFile = new JButton();
jBt_OpenFile.setText("查询文件");
jBt_OpenFile.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent e) {
ConfigurationQueryDialog configurationQuery= new ConfigurationQueryDialog();
configurationQuery.show();
}
});
}
return jBt_OpenFile;
}
class MyJTable extends JTable
{
public MyJTable()
{
super();
}
public void editingStopped(ChangeEvent e){
TableCellEditor editor = getCellEditor();
if (editor != null) {
Object value = editor.getCellEditorValue();
int n=editingColumn;
setValueAt(value, editingRow, editingColumn);
removeEditor();
if (getJRB_AllRow().isSelected()){
for (int i=0;i<getRowCount();i++)
setValueAt(value,i,n);
}
}
}
}
private MyJTable getJTable_Downlist(){
if(jTable_Downlist == null){
jTable_Downlist = new MyJTable();
CheckBoxCellRecelender cellDer=new CheckBoxCellRecelender();
DefaultCellEditor cellEdt = new DefaultCellEditor(new JCheckBox());
jTable_Downlist.setModel(getDefaultTableModel_list());
jTable_Downlist.getColumn("是否下载").setCellRenderer(cellDer);
jTable_Downlist.getColumn("是否下载").setCellEditor(cellEdt);
/*
jTable_Downlist.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(java.awt.event.MouseEvent e) {
if (e.getClickCount() == 2) // TODO Auto-generated Event stub mouseClicked()
System.out.println("OK");
}
});
*/
//TableCellEditor theEditor = jTable_Downlist.getDefaultEditor("Snmp写串");
//jTable_Downlist.addCellEditorListener(editingStopped);
}
return jTable_Downlist;
}
private DefaultTableModel getDefaultTableModel_list(){
if (defaultTableModel_list==null){
defaultTableModel_list = new DefaultTableModel();
defaultTableModel_list.addColumn("SysName");
defaultTableModel_list.addColumn("IP地址");
defaultTableModel_list.addColumn("Snmp写串");
defaultTableModel_list.addColumn("是否下载");
defaultTableModel_list.addColumn("文件名");
}
return defaultTableModel_list;
}
private JScrollPane getJScrollPane_Downlist(){
if (jScrollPane_Downlist == null){
jScrollPane_Downlist = new JScrollPane();
jScrollPane_Downlist.getViewport().setBackground( Color.white );
jScrollPane_Downlist.getViewport().add( getJTable_Downlist(), BorderLayout.CENTER );
jScrollPane_Downlist.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED );
jScrollPane_Downlist.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED );
}
return jScrollPane_Downlist;
}
private JButton getJBt_BatchDown(){
if (jBt_BatchDown == null){
jBt_BatchDown = new JButton("批量下载");
jBt_BatchDown.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent e) {
BatchDownThread batchDownThread = new BatchDownThread();
batchDownThread.start();
}
});
}
return jBt_BatchDown;
}
private void batchDown(){
int iCount = getDefaultTableModel_list().getRowCount();
ProgressMonitor progressWindow;
progressWindow=new ProgressMonitor(jTable_Downlist, "正在更新,请稍等....", "", 1,iCount);
progressWindow.setMillisToDecideToPopup(1);
progressWindow.setMillisToPopup(1);
progressWindow.setProgress(1);
String fileType=getJComboBox_FileType2().getSelectedItem().toString();
String down="T";
String fileName;
String community;
String ip;
String strTime = getTempFileName();
for (int i=0;i<iCount;i++){
ip=getDefaultTableModel_list().getValueAt(i,1).toString();
community=getDefaultTableModel_list().getValueAt(i,2).toString();
//String value = getDefaultTableModel_list().getValueAt(i,3).toString();
//System.out.println(value);
Boolean bl=new Boolean(getDefaultTableModel_list().getValueAt(i,3).toString());
if (bl.booleanValue()){
if(!fileType.equals("iosFile"))
fileName = ip+"_"+fileType+"_"+strTime;
else fileName=ip+"_"+getDefaultTableModel_list().getValueAt(i,4).toString()+"_"+strTime;
URLConnection ucon = null ;
String parameters = "?RemoteAddr=" + ip + "&Community="
+ community + "&FileType=" + fileType+"&UpOrDown="+down+"&FileName="+fileName;
try {
URL theURL = new URL(snmpTftpURL + parameters ) ;
ucon = theURL.openConnection() ;
ucon.setUseCaches( false ) ;
ucon.setDoInput( true ) ;
ucon.setDoOutput( false ) ;
ucon.connect() ;
} catch ( Exception ex ) {
System.out.println("SnmpTftpServlet call failed" + ex.getMessage());
progressWindow.close();
return;
}
int result=ucon.getHeaderFieldInt("Result",0);
if (result==1){
getDefaultTableModel_list().setValueAt(fileName,i,4);
}else if(result==0){
getDefaultTableModel_list().setValueAt(ucon.getHeaderField("FailureCause"),i,4);
}
}
try {
progressWindow.setProgress(i+1);
Thread.sleep(10);
}
catch(InterruptedException exc) {
System.out.println("err");
}
if(progressWindow.isCanceled()) {
return;
}
}
progressWindow.close();
}
class BatchDownThread extends Thread {
BatchDownThread() {
}
public void run() {
batchDown();
}
}
private JRadioButton getJRB_OneRow(){
if (jRB_OneRow == null){
jRB_OneRow = new JRadioButton("单行修改");
jRB_OneRow.setSelected(true);
}
return jRB_OneRow;
}
private JRadioButton getJRB_AllRow(){
if(jRB_AllRow==null){
jRB_AllRow = new JRadioButton("整列修改");
}
return jRB_AllRow;
}
}
class CheckBoxCellRecelender extends JCheckBox implements TableCellRenderer {
public CheckBoxCellRecelender() {
super();
this.setBackground(Color.white);
//this.setHorizontalAlignment(JCheckBox.CENTER);
}
public Component getTableCellRendererComponent(JTable table, Object value,
boolean isSelected, boolean hasFocus, int nRow, int nCol) {
if (value instanceof Boolean) {
setSelected(((Boolean)value).booleanValue());
}
return this;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -