Bonjour a tous!!!!
(J'utilise JavaFx Builder pour mes UI)
Dans mon application, le Main principe dispose d'un MenuBar contenant les Items suivants: Open, New, Save, Save As et Exit.
l'apel de ces item au niveau du Main principal fonction parfaitement.
mon souci se situe au niveau de la boite de dialog lorsque j'essaie d'adapter le Menu bar dans celle ci.

je vous presente ci-dessous les differentes partie de mon API

- MainApp(principal) :

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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
package ch.makery.address;
 
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.prefs.Preferences;
 
import javafx.application.Application;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.fxml.FXMLLoader;
import javafx.scene.Scene;
import javafx.scene.control.Dialogs;
import javafx.scene.image.Image;
import javafx.scene.layout.AnchorPane;
import javafx.scene.layout.BorderPane;
import javafx.stage.Modality;
import javafx.stage.Stage;
import ch.makery.address.AbscenceOverviewController;
import ch.makery.address.model.Person;
import ch.makery.address.util.FileUtil;
import ch.makery.address.AbscenceEditDialogController;
 
import com.thoughtworks.xstream.XStream;
 
public class MainApp extends Application {
 
	private Stage primaryStage;
	private BorderPane rootLayout;
 
	/**
         * The data as an observable list of Persons.
         */
	private ObservableList<Person> personData = FXCollections.observableArrayList();
	private AbscenceOverviewController abscenceOverviewController;
 
	/**
         * Constructor
         */
	public MainApp() {
		// Add some sample data
		personData.add(new Person("Hans", "Muster"));
		personData.add(new Person("Ruth", "Mueller"));
		personData.add(new Person("Heinz", "Kurz"));
		personData.add(new Person("Cornelia", "Meier"));
		personData.add(new Person("Werner", "Meyer"));
		personData.add(new Person("Lydia", "Kunz"));
		personData.add(new Person("Anna", "Best"));
		personData.add(new Person("Stefan", "Meier"));
		personData.add(new Person("Martin", "Mueller"));
 
 
	}
 
	@Override
	public void start(Stage primaryStage) {
		this.primaryStage = primaryStage;
		this.primaryStage.setTitle("GRH-ALDIS");
		this.primaryStage.getIcons().add(new Image("file:resources/images/address_book_32.png"));
 
		try {
			// Load the root layout from the fxml file
			FXMLLoader loader = new FXMLLoader(MainApp.class.getResource("view/RootLayout.fxml"));
			rootLayout = (BorderPane) loader.load();
			Scene scene = new Scene(rootLayout);
			primaryStage.setScene(scene);
 
			// Give the controller access to the main app
			RootLayoutController controller = loader.getController();
			controller.setMainApp(this);
 
			primaryStage.show();
		} catch (IOException e) {
			// Exception gets thrown if the fxml file could not be loaded
			e.printStackTrace();
		}
 
		showPersonOverview();
 
		// Try to load last opened person file
		File filePerson = getPersonFilePath();
		if (filePerson != null) {
			loadPersonDataFromFile(filePerson);
		}
 
 
	}
 
	/**
         * Returns the data as an observable list of Persons. 
         * @return
         */
	public ObservableList<Person> getPersonData() {
		return personData;
	}
 
	/**
         * Returns the main stage.
         * @return
         */
	public Stage getPrimaryStage() {
		return primaryStage;
	}
 
 
	/**
         * Shows the person overview page in the center of the root layout.
         */
 
	public void showPersonOverview() {
		try {
			// Load the fxml file and set into the center of the main layout
			FXMLLoader loader = new FXMLLoader(MainApp.class.getResource("view/PersonOverview.fxml"));
			AnchorPane overviewPage = (AnchorPane) loader.load();
			rootLayout.setCenter(overviewPage);
 
			// Give the controller access to the main app
			PersonOverviewController controller = loader.getController();
			controller.setMainApp(this);
 
		} catch (IOException e) {
			// Exception gets thrown if the fxml file could not be loaded
			e.printStackTrace();
		}
	}
 
	public  void showListePerson(){
		try {
 
		FXMLLoader loader2 = new FXMLLoader(MainApp.class.getResource("view/ListePerson.fxml"));
		AnchorPane page = (AnchorPane) loader2.load();
		Stage dialogStage = new Stage();
		dialogStage.setTitle("Liste du Personnel");
		dialogStage.initModality(Modality.APPLICATION_MODAL);
		dialogStage.initOwner(dialogStage);
		Scene scene = new Scene(page);
		dialogStage.setScene(scene);
		dialogStage.show();
 
		// Set the permission formulaire into the controller
	    ListePerson controller = loader2.getController();
	    controller.setMainApp(this);
 
		} catch (IOException e) {
			// TODO Bloc catch généré automatiquement
			e.printStackTrace();
 
		}
 
	}
 
 
	public void showAbscenceListe(){
 
				try {
				FXMLLoader loader = new FXMLLoader(AbscenceOverviewController.class.getResource("view/RootLayoutAbsc.fxml"));
				BorderPane borderPane = (BorderPane) loader.load();	
				Stage dialogStageAbscL = new Stage();
				dialogStageAbscL.setTitle("Liste des Abscences");
				dialogStageAbscL.initModality(Modality.APPLICATION_MODAL);
				dialogStageAbscL.getIcons().add(new Image("file:resources/images/aldhis_list.png"));
				dialogStageAbscL.initOwner(primaryStage);
				Scene scene = new Scene(borderPane);
				dialogStageAbscL.setScene(scene);
 
				dialogStageAbscL.show();
 
				FXMLLoader loader2 = new FXMLLoader(AbscenceOverviewController.class.getResource("view/AbscenceOverview.fxml"));
				AnchorPane overviewPage = (AnchorPane) loader2.load();
				borderPane.setCenter(overviewPage);
 
				// Give the controller access to the main app
			    AbscenceOverviewController controller = loader2.getController();
			    controller.setAbscenceListController(abscenceOverviewController);
 
				}
				catch (IOException e) {
				// TODO Bloc catch généré automatiquement
				e.printStackTrace();
			 	}
 
	}
 
 
	public  boolean showNouvelleAbscence(){
		try {
 
		FXMLLoader loader2 = new FXMLLoader(AbscenceOverviewController.class.getResource("view/AbscenceEdit.fxml"));
		AnchorPane page = (AnchorPane) loader2.load();
		Stage dialogStageAbscN = new Stage();
		dialogStageAbscN.setTitle("Formulaire Abscence");
		dialogStageAbscN.initModality(Modality.APPLICATION_MODAL);
		dialogStageAbscN.initOwner(dialogStageAbscN);
		Scene scene = new Scene(page);
		dialogStageAbscN.setScene(scene);
		dialogStageAbscN.show();
 
		// Set the permission formulaire into the controller
	   AbscenceEditDialogController controller = loader2.getController();
	    controller.setDialogStage(dialogStageAbscN);
 
		return controller.isValideClicked();
 
		} catch (IOException e) {
			// TODO Bloc catch généré automatiquement
			e.printStackTrace();
			return false;
		}
 
	}
 
 
	/**
         * Opens a dialog to edit details for the specified person. If the user
         * clicks OK, the changes are saved into the provided person object and
         * true is returned.
         * 
         * @param person the person object to be edited
         * @return true if the user clicked OK, false otherwise.
         */
	public boolean showPersonEditDialog(Person person) {
		try {
			// Load the fxml file and create a new stage for the popup
			FXMLLoader loader = new FXMLLoader(MainApp.class.getResource("view/PersonEditDialog.fxml"));
			AnchorPane page = (AnchorPane) loader.load();
			Stage dialogStage = new Stage();
			dialogStage.setTitle("Edit Person");
			dialogStage.initModality(Modality.WINDOW_MODAL);
			dialogStage.getIcons().add(new Image("file:resources/images/edit.png"));
			dialogStage.initOwner(primaryStage);
			Scene scene = new Scene(page);
			dialogStage.setScene(scene);
 
			// Set the person into the controller
			PersonEditDialogController controller = loader.getController();
			controller.setDialogStage(dialogStage);
			controller.setPerson(person);
 
			// Show the dialog and wait until the user closes it
			dialogStage.showAndWait();
 
			return controller.isOkClicked();
 
		} catch (IOException e) {
			// Exception gets thrown if the fxml file could not be loaded
			e.printStackTrace();
			return false;
		}
	}
 
 
 
	/**
         * Returns the person file preference, i.e. the file that was last opened.
         * The preference is read from the OS specific registry. If no such
         * preference can be found, null is returned.
         * 
         * @return
         */
	public File getPersonFilePath() {
		Preferences prefs = Preferences.userNodeForPackage(MainApp.class);
		String filePath = prefs.get("filePath", null);
		if (filePath != null) {
			return new File(filePath);
		} else {
			return null;
		}
	}
 
 
	/**
         * Sets the file path of the currently loaded file.
         * The path is persisted in the OS specific registry.
         * 
         * @param file the file or null to remove the path
         */
	public void setPersonFilePath(File filePerson) {
		Preferences prefs = Preferences.userNodeForPackage(MainApp.class);
		if (filePerson != null) {
			prefs.put("filePath", filePerson.getPath());
 
			// Update the stage title
			primaryStage.setTitle("Base de Données ALDIS - " + filePerson.getName());
		} else {
			prefs.remove("filePath");
 
			// Update the stage title
			primaryStage.setTitle("Base de Données ALDIS");
		}
	}
 
	/**
         * Loads person data from the specified file. The current person data will
         * be replaced.
         * 
         * @param file
         */
	@SuppressWarnings("unchecked")
	public void loadPersonDataFromFile(File filePerson) {
		XStream xstreamPerson = new XStream();
		xstreamPerson.alias("person", Person.class);
 
		try {
			String xml = FileUtil.readFile(filePerson);
 
			ArrayList<Person> personList = (ArrayList<Person>) xstreamPerson.fromXML(xml);
 
			personData.clear();
			personData.addAll(personList);
 
			setPersonFilePath(filePerson);
		} catch (Exception e) { // catches ANY exception
			Dialogs.showErrorDialog(primaryStage,
					"Could not load data from file:\n" + filePerson.getPath(),
					"Could not load data", "Error", e);
		}
	}
 
 
	/**
         * Saves the current person data to the specified file.
         * 
         * @param file
         */
	public void savePersonDataToFile(File filePerson) {
		XStream xstreamPerson = new XStream();
		xstreamPerson.alias("person", Person.class);
 
		// Convert ObservableList to a normal ArrayList
		ArrayList<Person> personList = new ArrayList<>(personData);
 
		String xml = xstreamPerson.toXML(personList);
		try {
			FileUtil.saveFile(xml, filePerson);
 
			setPersonFilePath(filePerson);
		} catch (Exception e) { // catches ANY exception
			Dialogs.showErrorDialog(primaryStage,
					"Could not save data to file:\n" + filePerson.getPath(),
					"Could not save data", "Error", e);
		}
	}
 
	/**
         * Opens a dialog to show birthday statistics. 
         */
	public void showBirthdayStatistics() {
	  try {
	    // Load the fxml file and create a new stage for the popup
	    FXMLLoader loader = new FXMLLoader(MainApp.class.getResource("view/BirthdayStatistics.fxml"));
	    AnchorPane page = (AnchorPane) loader.load();
	    Stage dialogStage = new Stage();
	    dialogStage.setTitle("Birthday Statistics");
	    dialogStage.initModality(Modality.WINDOW_MODAL);
	    dialogStage.initOwner(primaryStage);
	    Scene scene = new Scene(page);
	    dialogStage.setScene(scene);
 
	    // Set the persons into the controller
	    BirthdayStatisticsController controller = loader.getController();
	    controller.setPersonData(personData);
 
	    dialogStage.show();
 
	  } catch (IOException e) {
	    // Exception gets thrown if the fxml file could not be loaded
	    e.printStackTrace();
	  }
	}
 
 
 
 
	public static void main(String[] args) {
		launch(args);
	}
}
**********************************************************
- RootLayoutController
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
package ch.makery.address;
 
import java.io.File;
 
import javafx.fxml.FXML;
import javafx.scene.control.Dialogs;
import javafx.stage.FileChooser;
 
/**
 * The controller for the root layout. The root layout provides the basic
 * application layout containing a menu bar and space where other JavaFX
 * elements can be placed.
 * 
 * @author Marco Jakob
 */
public class RootLayoutController {
 
  // Reference to the main application
  private MainApp mainApp;
  /**
  * Is called by the main application to give a reference back to itself.
  * 
  * @param mainApp
  */
  public void setMainApp(MainApp mainApp) {
      this.mainApp = mainApp;
  }
 
  /**
  * Creates an empty address book.
  */
  @FXML
  protected void handleNew() {
      mainApp.getPersonData().clear();
      mainApp.setPersonFilePath(null);
  }
 
  /**
  * Opens a FileChooser to let the user select an address book to load.
  */
  @FXML
  protected void handleOpen() {
      FileChooser fileChooser = new FileChooser();
 
      // Set extension filter
      FileChooser.ExtensionFilter extFilter = new FileChooser.ExtensionFilter("XML files (*.xml)", "*.xml");
      fileChooser.getExtensionFilters().add(extFilter);
 
      // Show save file dialog
      File file = fileChooser.showOpenDialog(mainApp.getPrimaryStage());
 
      if (file != null) {
          mainApp.loadPersonDataFromFile(file);
      }
  }
 
  /**
  * Saves the file to the person file that is currently open. If there is no
  * open file, the "save as" dialog is shown.
  */
  @FXML
  protected void handleSave() {
      File personFile = mainApp.getPersonFilePath();
      if (personFile != null) {
          mainApp.savePersonDataToFile(personFile);
      } else {
          handleSaveAs();
      }
  }
 
  /**
  * Opens a FileChooser to let the user select a file to save to.
  */
  @FXML
  protected void handleSaveAs() {
    FileChooser fileChooser = new FileChooser();
 
    // Set extension filter
    FileChooser.ExtensionFilter extFilter = new FileChooser.ExtensionFilter("XML files (*.xml)", "*.xml");
    fileChooser.getExtensionFilters().add(extFilter);
 
    // Show save file dialog
    File file = fileChooser.showSaveDialog(mainApp.getPrimaryStage());
 
    if (file != null) {
      // Make sure it has the correct extension
      if (!file.getPath().endsWith(".xml")) {
        file = new File(file.getPath() + ".xml");
      }
      mainApp.savePersonDataToFile(file);
    }
  }
 
  /**
  * Opens an about dialog.
  */
  @FXML
  protected void handleAbout() {
      Dialogs.showInformationDialog(mainApp.getPrimaryStage(), "Author: Marco Jakob\nWebsite: http://edu.makery.ch", "AddressApp", "About");
  }
 
  /**
  * Closes the application.
  */
  @FXML
  protected void handleExit() {
      System.exit(0);
  }
 
  /**
  * Opens the birthday statistics.
  */
 @FXML
 protected void handleShowBirthdayStatistics() {
   mainApp.showBirthdayStatistics();
 }
 
 @FXML
 protected void handleNouvellePermission(){
	// mainApp.showNouvellePermission();
 }
 
 
 @FXML
 protected void handleNouvelleAbscence(){
	 mainApp.showNouvelleAbscence();
 }
 
 @FXML
 protected void handleAbscenceListe(){
	 mainApp.showAbscenceListe();
 }
 
 @FXML
 protected void handleListePerson(){
	 mainApp.showListePerson();
 }
}
- PersonOverviewController
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
package ch.makery.address;
 
import javafx.beans.value.ChangeListener;
import javafx.beans.value.ObservableValue;
import javafx.fxml.FXML;
import javafx.scene.control.Dialogs;
import javafx.scene.control.Label;
import javafx.scene.control.TableColumn;
import javafx.scene.control.TableView;
import javafx.scene.control.cell.PropertyValueFactory;
import javafx.scene.image.ImageView;
import ch.makery.address.model.Person;
import ch.makery.address.util.CalendarUtil;
 
/**
 * The controller for the overview with address table and details view.
 * 
 * @author Marco Jakob
 */
public class PersonOverviewController {
	@FXML
	private TableView<Person> personTable;
	@FXML
	private TableColumn<Person, String> nomColumn;
	@FXML
	private TableColumn<Person, String> prenomColumn;
 
	@FXML
	private Label nomLabel;
	@FXML
	private Label prenomLabel;
	@FXML
	private Label sexeLabel;
	@FXML
	private Label dateNaissLabel;
	@FXML
	private Label lieuNaissLabel;
	@FXML
	private Label matrimonialeLabel;
	@FXML
	private Label enfMinLabel;
	@FXML
	private Label enfMajLabel;
	@FXML
	private Label totalEnfLabel;
	@FXML
	private Label adresseLabel;
	@FXML
	private Label tel1Label;
	@FXML
	private Label tel2Label;
	@FXML
	private Label mail1Label;
	@FXML
	private Label mail2Label;
	@FXML
	private Label fonctionLabel;
	@FXML
	private Label categorieLabel;
	@FXML
	private Label contratLabel;
	@FXML
	private Label dateEmbLabel;
	@FXML
	private Label diplomeLabel;
	@FXML
	private Label ancienLabel;
	@FXML
	private Label salaireDebutLabel;
	@FXML
	private Label salaireActuelLabel;
	@FXML
	private ImageView imageView;
 
	// Reference to the main application
	private MainApp mainApp;
 
	/**
         * The constructor. The constructor is called before the initialize()
         * method.
         */
	public PersonOverviewController() {
	}
 
	@FXML
	private void initialize() {
		// Initialize the person table
		nomColumn.setCellValueFactory(new PropertyValueFactory<Person, String>("nom"));
		prenomColumn.setCellValueFactory(new PropertyValueFactory<Person, String>("prenom"));
 
		// Auto resize columns
		personTable.setColumnResizePolicy(TableView.CONSTRAINED_RESIZE_POLICY);
 
		// clear person
		showPersonDetails(null);
 
		// Listen for selection changes
		personTable.getSelectionModel().selectedItemProperty().addListener(new ChangeListener<Person>() {
 
			@Override
			public void changed(ObservableValue<? extends Person> observable,
					Person oldValue, Person newValue) {
				showPersonDetails(newValue);
			}
		});
	}
 
	/**
         * Is called by the main application to give a reference back to itself.
         * 
         * @param mainApp
         */
	public void setMainApp(MainApp mainApp) {
		this.mainApp = mainApp;
 
		// Add observable list data to the table
		personTable.setItems(mainApp.getPersonData());
	}
 
	/**
         * Fills all text fields to show details about the person.
         * If the specified person is null, all text fields are cleared.
         * 
         * @param person the person or null
         */
	private void showPersonDetails(Person person) {
		if (person != null) {
			nomLabel.setText(person.getNom());
			prenomLabel.setText(person.getPrenom());
			sexeLabel.setText(person.getSexe());
			dateNaissLabel.setText(CalendarUtil.format(person.getDateNaiss()));
			//dLabel.setText(Integer.toString(person.getPostalCode()));
			lieuNaissLabel.setText(person.getLieuNaiss());
			matrimonialeLabel.setText(person.getMatrimoniale());
			enfMinLabel.setText(Integer.toString(person.getEnfMin()));
			enfMajLabel.setText(Integer.toString(person.getEnfMaj()));
			totalEnfLabel.setText(Integer.toString(person.getTotalEnf()));
			adresseLabel.setText(person.getAdresse());
			tel1Label.setText(person.getTel1());
			tel2Label.setText(person.getTel2());
			mail1Label.setText(person.getMail1());
			mail2Label.setText(person.getMail2());
			fonctionLabel.setText(person.getFonction());
			categorieLabel.setText(person.getCategorie());
			contratLabel.setText(person.getContrat());
			dateEmbLabel.setText(CalendarUtil.format(person.getDateEmb()));
			diplomeLabel.setText(person.getDiplome());
			ancienLabel.setText(Integer.toString(person.getAncien()));
			salaireDebutLabel.setText(Integer.toString(person.getSalaireDebut()));
			salaireActuelLabel.setText(Integer.toString(person.getSalaireActuel()));
			imageView.setImage(person.getImagePers());
 
		} else {
			nomLabel.setText("");
			prenomLabel.setText("");
			sexeLabel.setText("");
			dateNaissLabel.setText("");
			lieuNaissLabel.setText("");
			matrimonialeLabel.setText("");
			enfMinLabel.setText("");
			enfMajLabel.setText("");
			totalEnfLabel.setText("");
			adresseLabel.setText("");
			tel1Label.setText("");
			tel2Label.setText("");
			mail1Label.setText("");
			mail2Label.setText("");
			fonctionLabel.setText("");
			categorieLabel.setText("");
			contratLabel.setText("");
			dateEmbLabel.setText("");
			diplomeLabel.setText("");
			ancienLabel.setText("");
			salaireDebutLabel.setText("");
			salaireActuelLabel.setText("");
			imageView.setImage(null);
		}
	}
 
	/**
         * Called when the user clicks on the delete button.
         */
	@FXML
	private void handleSupprimerPerson() {
		int selectedIndex = personTable.getSelectionModel().getSelectedIndex();
		if (selectedIndex >= 0) {
			personTable.getItems().remove(selectedIndex);
		} else {
			// Nothing selected
			Dialogs.showWarningDialog(mainApp.getPrimaryStage(),
					"Please select a person in the table.",
					"No Person Selected", "No Selection");
		}
	}
 
	/**
         * Called when the user clicks the new button.
         * Opens a dialog to edit details for a new person.
         */
	@FXML
	private void handleNouveauPerson() {
		Person tempPerson = new Person();
		boolean okClicked = mainApp.showPersonEditDialog(tempPerson);
		if (okClicked) {
			mainApp.getPersonData().add(tempPerson);
		}
	}
 
	/**
         * Called when the user clicks the edit button.
         * Opens a dialog to edit details for the selected person.
         */
	@FXML
	private void handleModifierPerson() {
		Person selectedPerson = personTable.getSelectionModel().getSelectedItem();
		if (selectedPerson != null) {
			boolean okClicked = mainApp.showPersonEditDialog(selectedPerson);
			if (okClicked) {
				refreshPersonTable();
				showPersonDetails(selectedPerson);
			}
 
		} else {
			// Nothing selected
			Dialogs.showWarningDialog(mainApp.getPrimaryStage(),
					"Please select a person in the table.",
					"No Person Selected", "No Selection");
		}
	}
 
	/**
         * Refreshes the table. This is only necessary if an item that is already in
         * the table is changed. New and deleted items are refreshed automatically.
         * 
         * This is a workaround because otherwise we would need to use property
         * bindings in the model class and add a *property() method for each
         * property. Maybe this will not be necessary in future versions of JavaFX
         * (see <a href="http://javafx-jira.kenai.com/browse/RT-22599" target="_blank">http://javafx-jira.kenai.com/browse/RT-22599</a>)
         */
	private void refreshPersonTable() {
		int selectedIndex = personTable.getSelectionModel().getSelectedIndex();
		personTable.setItems(null);
		personTable.layout();
		personTable.setItems(mainApp.getPersonData());
		// Must set the selected index again (see <a href="http://javafx-jira.kenai.com/browse/RT-26291" target="_blank">http://javafx-jira.kenai.com/browse/RT-26291</a>)
		personTable.getSelectionModel().select(selectedIndex);
	}
}
Affichage de la boite de dialogue

- RootLayoutAbscController
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
package ch.makery.address;
 
import java.io.File;
 
import javafx.fxml.FXML;
import javafx.scene.control.Dialogs;
import javafx.stage.FileChooser;
import ch.makery.address.model.Abscence;
 
public class RootLayoutAbscController {
 
 
	private AbscenceOverviewController abscenceOverviewController;
 
	public void setAbscenceListController(AbscenceOverviewController abscenceOverviewController){
		this.abscenceOverviewController = abscenceOverviewController;
 
	}
 
 
	//*****************************************************************************************
	@FXML
	  private void handleNouveau() {
		  abscenceOverviewController.getAbscenceData().clear();
		  abscenceOverviewController.setAbscenceFilePath(null);
	  }
 
	/**
          * Opens a FileChooser to let the user select an address book to load.
         */
 
	  @FXML
	  private void handleOuvrir() {
 
		FileChooser fileChooser = new FileChooser();
 
		// Set extension filter
		FileChooser.ExtensionFilter extFilter = new FileChooser.ExtensionFilter("XML files (*.xml)", "*.xml");
		fileChooser.getExtensionFilters().add(extFilter);
 
		// Show save file dialog
		File abscenceFile = fileChooser.showOpenDialog(null);
 
			if (abscenceFile != null) {
			   abscenceOverviewController.loadAbscenceDataFromFile(abscenceFile);
			   }
	}
 
	  /**
          * Saves the file to the abscence file that is currently open. If there is no
          * open file, the "save as" dialog is shown.
          */
 
	  @FXML
	  private void handleEnregistrer() {
		File abscenceFile = abscenceOverviewController.getAbscenceFilePath();
		if (abscenceFile != null) {
			abscenceOverviewController.saveAbscenceDataToFile(abscenceFile);
		} else{
			handleEnregistrerSous();
			}   
	  }
 
	  /**
          * Opens a FileChooser to let the user select a file to save to.
          *
           */
	  @FXML
	  private void handleEnregistrerSous() {
 
		FileChooser fileChooser = new FileChooser();
 
		// Set extension filter
		FileChooser.ExtensionFilter extFilter = new FileChooser.ExtensionFilter("XML files (*.xml)", "*.xml");
		fileChooser.getExtensionFilters().add(extFilter);
 
		// Show save file dialog
		File abscenceFile = fileChooser.showSaveDialog(null);
 
		if (abscenceFile != null) {
 
		// Make sure it has the correct extension
			if (!abscenceFile.getPath().endsWith(".xml")) {
				abscenceFile = new File(abscenceFile.getPath() + ".xml");
			  }
			  abscenceOverviewController.saveAbscenceDataToFile(abscenceFile);
		}
	  }
 
	  @FXML
	  protected void handleQuitter() {
	      System.exit(0);
	  }
 
 
	/*
	 * 
	 * 
 
	  @FXML
	  private void handleExit(ActionEvent event) {
	        System.exit(0);
	      }
	  */
 
	  @FXML
		private void handleModifierAbscence() {
			Abscence selectedAbscence = abscenceOverviewController.abscenceTable.getSelectionModel().getSelectedItem();
			if (selectedAbscence != null) {
				boolean okClicked = abscenceOverviewController.showAbscenceEditDialog(selectedAbscence);
				if (okClicked) {
					abscenceOverviewController.refreshAbscenceTable();
					abscenceOverviewController.showAbscenceDetails(selectedAbscence);
				}
 
			} else {
				// Nothing selected
				Dialogs.showWarningDialog(null,
						"Veillez sélectionnez une personne dans la Table.",
						"Pas de Personne Sélectionnée", "Pas de Sélection");
			}
		}
 
		/**
                 * Called when the user clicks on the delete button.
                 */
		@FXML
		private void handleSupprimerAbscence() {
			int selectedIndex = abscenceOverviewController.abscenceTable.getSelectionModel().getSelectedIndex();
			if (selectedIndex >= 0) {
				abscenceOverviewController.abscenceTable.getItems().remove(selectedIndex);
			} else {
				// Nothing selected
				Dialogs.showErrorDialog( null,
						"Please select a person in the table.",
						"No Person Selected", "No Selection");
			}
		}
 
 
 
}
- AbscenceOverviewController
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
package ch.makery.address;
 
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.prefs.Preferences;
 
import javafx.application.Application;
import javafx.beans.value.ChangeListener;
import javafx.beans.value.ObservableValue;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.scene.Scene;
import javafx.scene.control.ComboBox;
import javafx.scene.control.Dialogs;
import javafx.scene.control.Label;
import javafx.scene.control.TableColumn;
import javafx.scene.control.TableView;
import javafx.scene.control.TextField;
import javafx.scene.control.cell.PropertyValueFactory;
import javafx.scene.layout.AnchorPane;
import javafx.stage.Modality;
import javafx.stage.Stage;
import ch.makery.address.model.Abscence;
import ch.makery.address.util.CalendarUtil;
import ch.makery.address.util.FileUtil;
 
import com.thoughtworks.xstream.XStream;
 
/**
 * 
 * @author Anohjp
 *
 */
 
public class AbscenceOverviewController{
 
	@FXML
	protected TextField filterField;
	@FXML 
	protected TableView<Abscence> abscenceTable;
	@FXML
	private TableColumn<Abscence, String> nomPersColumn;
	@FXML
	private TableColumn<Abscence, String> prenomPersColumn;
 
	@FXML
	private Label nomPersLabel;
	@FXML
	private Label prenomPersLabel;
	@FXML
	private Label fonctionLabel;
	@FXML
	private Label dateDebutLabel;
	@FXML
	private Label dateFinLabel;
	@FXML
	private Label dureeLabel;
	@FXML
	private Label motifLabel;
	@FXML
	ComboBox<String> trimestreComboBox = new ComboBox<String>();
	@FXML
	ComboBox<String> moisComboBox = new ComboBox<String>();
	@FXML
	ComboBox<String> semestreComboBox = new ComboBox<String>();
	@FXML
	ComboBox<Integer> anneeComboBox = new ComboBox<Integer>();
 
	//private String mois[] = new String[]{};
	//final ComboBox comboBox = new ComboBox();
 
	private ObservableList<Abscence> abscenceData = FXCollections.observableArrayList();
	//private ObservableList<Abscence> filteredData = FXCollections.observableArrayList();
	//private ObservableList<Abscence> comboBoxData = FXCollections.observableArrayList();
 
	private Stage dialogStageAbscL;
 
 
	// Creation d constructeur
	public AbscenceOverviewController(){
 
		abscenceData.add(new Abscence("Jean", "Ezan"));
		abscenceData.add(new Abscence("Paul", "Anoh"));
		abscenceData.add(new Abscence("Germain", "Ezan"));
		abscenceData.add(new Abscence("Jean", "Anoh"));
		abscenceData.add(new Abscence("Paul", "Ezan"));
		abscenceData.add(new Abscence("Germain", "Anoh"));
		abscenceData.add(new Abscence("Hans", "Muster"));
		abscenceData.add(new Abscence("Ruth", "Mueller"));
		abscenceData.add(new Abscence("Heinz", "Kurz"));
		abscenceData.add(new Abscence("Cornelia", "Meier"));
		abscenceData.add(new Abscence("Werner", "Meyer"));
	}
 
	@FXML
	private void initialize() {
 
		// Initialise la table permission
		nomPersColumn.setCellValueFactory(new PropertyValueFactory<Abscence, String>("nomPers"));
		prenomPersColumn.setCellValueFactory(new PropertyValueFactory<Abscence, String>("prenomPers"));		
 
		// Auto resize columns
		abscenceTable.setColumnResizePolicy(TableView.CONSTRAINED_RESIZE_POLICY);
 
		// effacer Abscence
		showAbscenceDetails(null);
 
		// Listen for selection changes/ Ecouteur de changement de selection
		abscenceTable.getSelectionModel().selectedItemProperty().addListener(new ChangeListener<Abscence>() {
 
			@Override
			public void changed(ObservableValue<? extends Abscence> observable,
				Abscence oldValue, Abscence newValue) {
					showAbscenceDetails(newValue);
				}
			});
 
	}//Fin de private void initialize()
 
//****************************************************************************************************	   
 
	public ObservableList<Abscence> getAbscenceData() {
		return abscenceData;
	}
 
	/**
         * Is called by the main application to give a reference back to itself.
         * 
         * @param mainApp
         */
	public void setAbscenceListController(AbscenceOverviewController abscenceOverviewController) {
		// Add observable list data to the table
		abscenceTable.setItems(getAbscenceData());	
	}
 
 
	/**
         * Fills all text fields to show details about the permission.
         * If the specified permission is null, all text fields are cleared.
         * 
         * @param Abscence the abscence or null
         */
	protected void showAbscenceDetails(Abscence abscence) {
		if (abscence != null) {
			nomPersLabel.setText(abscence.getNomPers());
			prenomPersLabel.setText(abscence.getPrenomPers());
			fonctionLabel.setText(abscence.getFonction());
			dateDebutLabel.setText(CalendarUtil.format(abscence.getDateDebut()));
			dateFinLabel.setText(CalendarUtil.format(abscence.getDateFin()));
			dureeLabel.setText(Integer.toString(abscence.getDureeAbsc()));
			motifLabel.setText(abscence.getMotif());
 
 
		} else {
			nomPersLabel.setText("");
			prenomPersLabel.setText("");
			fonctionLabel.setText("");
			dateDebutLabel.setText("");
			dateFinLabel.setText("");
			dureeLabel.setText("");
			motifLabel.setText("");
 
		}
	}
 
	/***
         * 
         * @param abscence, montre le formulaire d'abscence
         * @return
         */
 
	public  boolean showAbscenceEditDialog(Abscence abscence){
		try {
 
		FXMLLoader loader2 = new FXMLLoader(AbscenceOverviewController.class.getResource("view/AbscenceEditDialog.fxml"));
		AnchorPane page = (AnchorPane) loader2.load();
		Stage dialogStageAbscE = new Stage();
		dialogStageAbscE.setTitle("Formulaire Abscence");
		dialogStageAbscE.initModality(Modality.WINDOW_MODAL);
		dialogStageAbscE.initOwner(dialogStageAbscE);
		Scene scene = new Scene(page);
		dialogStageAbscE.setScene(scene);
		dialogStageAbscE.show();
 
		// Set the permission formulaire into the controller
		AbscenceEditDialogController controller = loader2.getController();
	    controller.setDialogStageAbscE(dialogStageAbscE);
	    controller.setAbscence(abscence);
 
		return controller.isValideClicked();
 
		} catch (IOException e) {
			// TODO Bloc catch généré automatiquement
			e.printStackTrace();
			return false;
		}
 
	}
 
 
	/**
         * Called when the user clicks the new button.
         * Opens a dialog to edit details for a new person.
        */
	@FXML
	private void handleNouvelleAbscence() {
		Abscence tempAbscence = new Abscence();
		boolean nouveauClicked = showAbscenceEditDialog(tempAbscence);
		if (nouveauClicked) {
			getAbscenceData().add(tempAbscence);
		}
	} 
 
	/***
         * Param du bouton Modifier
         */
	@FXML
	private void handleModifierAbscence() {
		Abscence selectedAbscence = abscenceTable.getSelectionModel().getSelectedItem();
		if (selectedAbscence != null) {
			boolean okClicked = showAbscenceEditDialog(selectedAbscence);
			if (okClicked) {
				refreshAbscenceTable();
				showAbscenceDetails(selectedAbscence);
			}
 
		} else {
			// Nothing selected
			Dialogs.showWarningDialog(null,
					"Veillez sélectionnez une Abscence dans la Table.",
					"Pas d'Abscence Sélectionnée", "Pas de Sélection");
		}
	}
 
	/**
         * Called when the user clicks on the delete button.
         */
	@FXML
	private void handleSupprimerAbscence() {
		int selectedIndex = abscenceTable.getSelectionModel().getSelectedIndex();
		if (selectedIndex >= 0) {
			abscenceTable.getItems().remove(selectedIndex);
		} else {
			// Nothing selected
			Dialogs.showWarningDialog(null,
					"Veillez sélectionner une Abscence dans la table",
					"Pas d'Abscence Sélectionnée", "Pas de Sélection");
		}
	}
 
 
	/**
         * Returns the data as an observable list of Abscence
         * @return
         */
 
 
	public File getAbscenceFilePath() {
		Preferences prefsAbs = Preferences.systemNodeForPackage(AbscenceOverviewController.class);
		String filePathAbsc = prefsAbs.get("filePathAbsc", null);
		if (filePathAbsc != null) {
			return new File(filePathAbsc);
		} 
		else {
			return null;
		}
	}
 
	/**
         * 
         * @param abscenceFile, setAbscenceFilePath
         */
 
	public void setAbscenceFilePath(File abscenceFile) {
		Preferences prefsAbs = Preferences.userNodeForPackage(AbscenceOverviewController.class);
		if (abscenceFile != null) {
			prefsAbs.put("filePath", abscenceFile.getPath());
 
			// Update the stage title
			dialogStageAbscL.setTitle("Abscence - " + abscenceFile.getName());
		} 
		else {
			prefsAbs.remove("filePathAbsc");
 
			// Update the stage title
			dialogStageAbscL.setTitle("Abscence");
		}
	}
 
	/**
         * 
         * @param abscenceFile, loadAbscenceDataFromFile
         */
	@SuppressWarnings("unchecked")
	public void loadAbscenceDataFromFile(File abscenceFile) {
		XStream xstreamAbscence = new XStream();
		xstreamAbscence.alias("abscence", Abscence.class);
 
		try {
			String xml = FileUtil.readFile(abscenceFile);
 
			ArrayList<Abscence> abscenceList = (ArrayList<Abscence>) xstreamAbscence.fromXML(xml);
 
			abscenceData.clear();
			abscenceData.addAll(abscenceList);
 
			setAbscenceFilePath(abscenceFile);
		} catch (Exception e) { // catches ANY exception
			Dialogs.showErrorDialog(null,
					"Impossible de charger les données du fichier:\n" + abscenceFile.getPath(),
					"Impossible de charger les données", "Error", e);
		}
	}
 
	/****
         * 
         * @param file, saveAbscenceDataToFile
         */
	public void saveAbscenceDataToFile(File abscenceFile) {
		XStream xstream = new XStream();
		xstream.alias("abscence", Abscence.class);
 
		// Convert ObservableList to a normal ArrayList
		ArrayList<Abscence> abscenceList = new ArrayList<>(abscenceData);		
		String xml = xstream.toXML(abscenceList);
 
		try {
			FileUtil.saveFile(xml, abscenceFile);
 
			setAbscenceFilePath(abscenceFile);
		} catch (Exception e) { // catches ANY exception
			Dialogs.showErrorDialog(null,
				"Impossible de charger les données du fichier:\n" + abscenceFile.getPath(),
				"Impossible de charger les données", "Error", e);
		}
	}
 
 
 
	/**
         * Refreshes the table. This is only necessary if an item that is already in
         * the table is changed. New and deleted items are refreshed automatically.
         * 
         * This is a workaround because otherwise we would need to use property
         * bindings in the model class and add a *property() method for each
         * property. Maybe this will not be necessary in future versions of JavaFX
         * (see <a href="http://javafx-jira.kenai.com/browse/RT-22599" target="_blank">http://javafx-jira.kenai.com/browse/RT-22599</a>)
         */
 
	protected void refreshAbscenceTable() {
		int selectedIndex = abscenceTable.getSelectionModel().getSelectedIndex();
		abscenceTable.setItems(null);
		abscenceTable.layout();
		abscenceTable.setItems(getAbscenceData());
		// Must set the selected index again (see <a href="http://javafx-jira.kenai.com/browse/RT-26291" target="_blank">http://javafx-jira.kenai.com/browse/RT-26291</a>)
		abscenceTable.getSelectionModel().select(selectedIndex);
	}
 
	@Override
	public void start(Stage arg0) throws Exception {
		// TODO Stub de la méthode généré automatiquement
 
	}
 
 
 
}// Fin de la classe PermissionListController