如何使用按钮的任务工厂方法

时间:2017-08-04 19:48:16

标签: java cytoscape

我正在开发一个关于Cytoscape的应用程序,这是一个数据可视化程序。当我点击使用任务工厂的按钮时,我需要做某些事情。我实现了我的任务工厂和任务类。我在actionperformed部分注册了它,但它没有用。当我在控制台上运行代码时,没有错误消息。

如何将任务工厂注册到按钮?

以下是我的代码中与此相关的部分:

在MyControlPanel类中:

this.provoImportButton.setText("Import");
    this.provoImportButton.setVerticalAlignment(1);
    this.provoImportButton.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            provoImportCore.importFile();
        }
    });

在provoImportCore类中:

public void importFile(){
    String path = getWholePath();
    ExtractEdgesNodesTaskFactory extractEdgesNodesTaskFactory = new ExtractEdgesNodesTaskFactory(adapter,path);
    adapter.getCyServiceRegistrar().registerService(extractEdgesNodesTaskFactory,TaskFactory.class,new Properties());
}

ExtractEdgesNodesTaskFactory类:

public class ExtractEdgesNodesTaskFactory extends AbstractTaskFactory {

private CySwingAppAdapter adapter;
private String path;

public ExtractEdgesNodesTaskFactory(CySwingAppAdapter adapter, String path) {
    this.path = path;
    this.adapter = adapter;
}

public TaskIterator createTaskIterator() {
    return new TaskIterator(new ExtractEdgesNodesTask(adapter,path));
}

}

ExtractEdgesNodesTask类:

public class ExtractEdgesNodesTask extends AbstractTask{
private CySwingAppAdapter adapter;
private String path;

public ExtractEdgesNodesTask(CySwingAppAdapter adapter, String path){
    super();
    this.path =path;
    this.adapter = adapter;
}

public void run(TaskMonitor taskMonitor) {
    taskMonitor.setStatusMessage("Extracting Edges and Nodes ...");
    try {
        Process process = Runtime.getRuntime().exec(path);
    } catch (Exception es) {
        JOptionPane.showMessageDialog(this.adapter.getCySwingApplication().getJFrame(),
                "The file that you choosed are not valid."  ,
                "Error!", JOptionPane.INFORMATION_MESSAGE);
        es.printStackTrace(System.err);
    }
}

public String getPath() {
    return path;
}

public void setPath(String path) {
    this.path = path;
}

}

1 个答案:

答案 0 :(得分:2)