📄 runaction.java
字号:
/*
* *****************************************************
* Copyright (c) 2005 IIM Lab. All Rights Reserved.
* Created by xuehao at 2005-10-12
* Contact: zxuehao@mail.ustc.edu.cn
* *****************************************************
*/
package org.indigo.gui.actions;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;
import java.util.HashMap;
import java.util.Vector;
import javax.swing.JOptionPane;
import javax.swing.JTree;
import javax.swing.tree.DefaultMutableTreeNode;
import javax.swing.tree.TreePath;
import org.indigo.commands.*;
import org.indigo.gui.IView;
import org.indigo.gui.TableView;
import org.indigo.gui.ViewManager;
import org.indigo.spider.Spider;
import org.indigo.spider.ThreadPool;
import org.indigo.util.*;
/**
* 当选择任务并启动时,此类完成主要的功能。
* 即此类是run按钮的监听器,当点击run时,执行此类的actionPerformed方法。
* @author wbz
*
*/
public class RunAction implements ActionListener
{
private IView itsView=null;
public void setTableView( IView v )
{
itsView = v;
}
/**
* run按钮的监听函数。当任务运行时,首先执行此函数。
*/
public void actionPerformed(ActionEvent e)
{
JTree tree = ViewManager.getInstance().getTree();//获取主界面左侧的结构树。
String nodeName="";
TreePath treePath= tree.getSelectionPath();//获取所选择的左侧结构树中的结点路径。
if( treePath==null || treePath.getPathCount()==1 )
return;
int i=1;
for( i=1; i<treePath.getPathCount(); i++ )//对结点路径进行处理,获得结点所对应的文件路径。
{
nodeName += treePath.getPathComponent(i).toString()+"/";
}
nodeName = nodeName.substring( 0, nodeName.length()-1 );//获得和结点对应的任务名。
// System.out.println( str );
File file = new File( "./taskconfig/" + nodeName + ".task" );
if( nodeName==null || file.isDirectory() || !file.exists() )
return ;
if( ViewManager.getInstance().checkInTab(nodeName) )//检查此相同的任务名是否已经启动。
{
return ;
}
else
{
ViewManager.getInstance().putInTab( nodeName, true );//如果没有启动则把此任务显示。
}
String taskName = "taskconfig/" + nodeName+".task";//任务对应的文件路径。
System.out.println( taskName );
Command cmd;
TaskProperties props = new TaskProperties();
props.open( taskName );//打开任务对应文件。
String str = props.getProperty( "Nested" );//判断任务中是否包含子任务。if bComp=true则包含子任务,否则不包含子任务。
boolean bComp=false;
if( str==null )
bComp = false;
else
if( str.equalsIgnoreCase("true") || str.equals("") )
bComp = true;
else
bComp = false;
boolean bWithXml;
str = MainConfig.getInstance().getProperty( "GuiWithXml" );
//判断是否把数据保存在xml中。
if( str==null || str.equals("") )
bWithXml = false;
if( str.equalsIgnoreCase("true") )
bWithXml = true;
else
bWithXml = false;
if( !bComp )
{
System.out.println( "will create raw command "+taskName );
cmd = new RawCommand( taskName, true, bWithXml );//把任务封装成RawCommand对象
}else
{
System.out.println( "will create composite command "+taskName );
cmd = new CompositeCommand( taskName, true, bWithXml );//如果此任务包含子任务,则把任务封装为CompositeCommand对象。
}
ThreadPool.getInstance().execute( new Spider(cmd) );//启动采集已经封装的任务。
// ( new Spider( cmd ) ).start();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -