package energybox;

import javafx.application.Platform;

import java.util.Iterator;

public final class ControllerUpdater implements UpdatesController {
    private final MainFormController controller;

    public ControllerUpdater(MainFormController controller) {
        this.controller = controller;
    }

    public void invoke(ProcessTrace trace) {
        controller.sourceIP = trace.getSourceIP();
        controller.addressOccurrence = trace.getAddressOccurrence();
//            controller.criteria = trace.getCriteria();
        controller.packetList.clear();
        controller.packetList.addAll(trace.getPacketList());
        System.out.println("ProcessTraceOSX, IPsource: " + controller.sourceIP + " Criteria: "+ trace.getCriteria());
        // Run the method that opens the results forms
        if (!controller.ipField.getText().equals(""))
        {
            controller.sourceIP = controller.ipField.getText();
        }

        if (trace.hasErrors()) {
            StringBuilder sb = new StringBuilder();
            Iterator<String> iter = trace.getErrorMessages().iterator();
            while (iter.hasNext()) {
                sb.append(iter.next());
                if(iter.hasNext()) sb.append("\n");
            }
            String errorMessage = sb.toString();
            controller.errorText.setText(errorMessage);

            Platform.runLater(new Runnable() {
                @Override
                public void run() {
                    OSTools.showErrorDialog("Error", errorMessage);
                }
            });
        }
        Platform.runLater(controller);
    }
}

@@ -746,201 +746,8 @@
 ());
-%0A        // Run the method that opens the results forms%0A        if (!controller.ipField.getText().equals(%22%22))%0A        %7B%0A            controller.sourceIP = controller.ipField.getText();%0A        %7D
 %0A%0A  
@@ -1053,24 +1053,30 @@
             
+final 
 String error

Set IP only once.