Bonjour à tous,
Je suis en train de coder une petite application basée sur un MVC classique et basique. Mon interface graphique est composée d'un panel gauche contenant un JTree et d'un panel droit de type JTabbedPane contenant lui-même des JTabbedPane.
Chaque feuille du JTree représente un scénario de test. Chaque test est composé de plusieurs processus. Ainsi, lors de l'exécution d'un scénario, un nouveau JTabbedPane est créé et dans celui-ci, un nouveau JTabbedPane est créé pour chaque nouveau processus démarré.
Mon problème se situe au niveau de l'affichage des résultats de chaque processus : j'aimerais que celui-ci se fasse à la volée, alors qu'avec mon code actuel, les résultats sont affichés en une fois à la fin du processus.
C'est assez embêtant car si le processus prend plusieurs minutes, je n'ai aucune idée de son avancement...
J'ai utilisé la classe PrintWriter (au plus simple) mais j'ai dû passer à côté de quelque chose.
Voici les différentes classes utilisées (tout du moins, celles qui ont un intérêt à mes yeux) :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66 public class MyApplicationGUI extends MyApplicationView implements ActionListener { private JFrame mainFrame = null; private JTabbedPane rightPane = null; private JTree tree; private PrintWriter guiPrintWriter = null; /** * * @param controller */ public MyApplicationGUI(MyApplicationController controller){ super(controller); // Setup the frame, panels, menu, etc... buildFrame(); } ... /** * * @return */ @Override public PrintWriter getGuiPrintWriter() { return guiPrintWriter; } ... /** * New process means new sub-tab to be opened under the corresponding * scenario tab in the right pane. * * @param event */ public void processChanged(ProcessChangedEvent event) { String currentScenarioName = event.getCurrentScenarioName(); String newProcessName = event.getNewProcess(); // Retrieve the JTabbedPane of the scenario (should be the one active) JTabbedPane scenTabPane = getScenarioTabbedPane(currentScenarioName); // Close the previous stream if any if (guiPrintWriter != null) { guiPrintWriter.close(); } if (scenTabPane != null) { LogPane pane = new LogPane(); scenTabPane.add(newProcessName, pane.getPanel()); scenTabPane.setSelectedComponent(pane.getPanel()); guiPrintWriter = new PrintWriter(pane, true); } } ... private JTabbedPane getScenarioTabbedPane(String scenarioName) { return (JTabbedPane) rightPane.getComponentAt(rightPane.indexOfTab(scenarioName)); } }
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39 public class MyApplicationController { public MyApplicationView maGUI = null; private MyApplicationModel maModel = null; ... public MyApplicationController (MyApplicationModel model) { this.maModel = model; maGUI = new MyApplicationGUI(this); addListenersToModel(); } ... private void executionMode1(Scenario currentScenario) { String scenarioName = currentScenario.getScenarioName(); Collection<ScenarioProcess> scenarioProcesses = currentScenario.getScenarioProcesses(); for (ScenarioProcess currentProcess : scenarioProcesses) { String processName = currentProcess.getProcessName(); model.setCurrentProcess(processName); ScenarioProcessFactory scenarioProcessFactory = ScenarioProcessFactory.newInstance(); ScenarioProcessInterface scenarioProcess = scenarioProcessFactory.createScenarioProcess(currentProcess.getProcessType()); if (scenarioProcess != null) { if (!scenarioProcess.execute(scenarioName, currentProcess.getScenarioData(), maGUI.getGuiPrintWriter())) { // Put the current sub-tab in red and go on with the next processes maGUI.scenarioProcessFailure(scenarioName, processName); } } } } }
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 public class Process1 implements ScenarioProcessInterface { private PrintWriter process1PrintWriter = null; ... public synchronized boolean execute(String scenarioName, Collection<ScenarioData> scenarioData, PrintWriter guiPrintWriter) { this.process1PrintWriter = guiPrintWriter; ... process1PrintWriter.println("Start of the execution..."); ... process1PrintWriter.println("End of the execution..."); } }
Partager