/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package it.cnr.iasi.giant.action;

import it.cnr.iasi.giant.Main;
import it.cnr.iasi.giant.thread.ClusterLoaderThread;
import it.cnr.iasi.giant.thread.NetworkLoaderThread;
import java.io.File;
import java.util.ArrayList;
import javax.swing.JFileChooser;
import javax.swing.JOptionPane;

/**
 *
 * @author Fabio Cumbo
 * @info GIANT
 * @version v1.0
 * @organization IASI-CNR : Istituto di Analisi dei Sistemi ed Informatica 
 *                  "Antonio Ruberti" - Consiglio Nazionale delle Ricerche
 * 
 */
public class SelectClustersAction extends Action {

    @Override
    public ArrayList<Object> execute(String command) {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    @Override
    public ArrayList<Object> execute() {
        if (!NetworkLoaderThread.getDegreeMap().isEmpty()) {
            JFileChooser chooser = new JFileChooser();

            int code = chooser.showOpenDialog(Main.getApp().getFrameOverride());
            File file;
            if (code == JFileChooser.APPROVE_OPTION) {
                file = chooser.getSelectedFile();
                if (file.exists()) {
                    Main.getApp().getClusterField().setText(file.getName());
                    ClusterLoaderThread loader = new ClusterLoaderThread(file);
                    loader.start();
                }
                else {
                    JOptionPane.showMessageDialog(Main.getApp().getFrameOverride(), "Specified file does not exist!", "ERROR", JOptionPane.ERROR_MESSAGE);
                }
            }
        }
        else {
            JOptionPane.showMessageDialog(Main.getApp().getFrameOverride(), "Load network first...", "ERROR!", JOptionPane.ERROR_MESSAGE);
        }
        System.out.println("SelectClustersAction");
        return null;
    }
    
}
