package pt.up.fe.aiad.gui;

import jade.wrapper.StaleProxyException;
import javafx.fxml.FXML;
import javafx.scene.control.ListView;
import pt.up.fe.aiad.scheduler.SchedulerAgent;
import pt.up.fe.aiad.utils.FXUtils;

public class ClientController {
    private String _addressIp;
    private int _port;
    private String _nickname;
    private SchedulerAgent _agent;

    @FXML
    private ListView<String> _allAgents;


    @FXML
    void initialize() {
        System.out.println("ClientController.init");
    }

    public void initData(String addressIp, int port, String nickname) {
        System.out.println("ClientController.initData");
        _addressIp = addressIp;
        _port = port;
        _nickname = nickname;
        _agent = new SchedulerAgent(SchedulerAgent.Type.ABT); //TODO add type
        _allAgents.setItems(_agent._allAgents);
    }


    public void start() {
        System.out.println("ClientController.startServer: " + _nickname + " (" + _addressIp + ":" + _port + ")");
        if (MainController.container != null) {
            try {
                MainController.container.acceptNewAgent(_nickname, _agent).start();
            } catch (StaleProxyException e) {
                FXUtils.showExceptionDialog(e);
            }
        }
    }
}

@@ -21,16 +21,36 @@
 d.gui;%0A%0A
+import jade.core.*;%0A
 import j
@@ -1279,20 +1279,477 @@
 %7D%0A        %7D%0A
+        else %7B%0A            ProfileImpl iae = new ProfileImpl(_addressIp, _port, _addressIp + %22:%22 + Integer.toString(_port) + %22/JADE%22, false);%0A            MainController.container = jade.core.Runtime.instance().createAgentContainer(iae);%0A            try %7B%0A                MainController.container.acceptNewAgent(_nickname, _agent).start();%0A            %7D catch (StaleProxyException e) %7B%0A                FXUtils.showExceptionDialog(e);%0A            %7D%0A        %7D%0A
     %7D%0A%7D%0A

Create container on remote platform when launching client and no container has yet been created