Revision 6842

View differences:

trunk/frameworks/_fwAndami/src/com/iver/andami/preferences/GenericDlgPreferences.java
43 43
import java.awt.BorderLayout;
44 44
import java.awt.Component;
45 45
import java.awt.Dimension;
46
import java.awt.event.ActionEvent;
46 47
import java.awt.event.ActionListener;
47 48
import java.util.Enumeration;
48 49
import java.util.Hashtable;
......
99 100

  
100 101
	private JPanel jPanelContainer = null;
101 102
	private JButton jButtonRestore;
103
	private ActionListener action;
102 104

  
103 105
	private class MyTreeCellRenderer extends DefaultTreeCellRenderer
104 106
	{
......
135 137

  
136 138
	public GenericDlgPreferences() {
137 139
		super();
140
		this.action = new ActionListener() {
141
			public void actionPerformed(ActionEvent e) {
142
				PluginServices.getMDIManager().setWaitCursor();
143
				String actionCommand = e.getActionCommand();
144
				if ("RESTORE".equals(actionCommand)) {
145
					// Restore default values in current page
146
					if (activePreference!=null)
147
						activePreference.initializeDefaults();
148
				} else {
149
					Iterator it = preferences.keySet().iterator();
150

  
151
					if ("CANCEL".equals(actionCommand)) {
152
						// Restore previous values in all pages
153
						while (it.hasNext()) {
154
							IPreference pref = (IPreference) preferences.get(it.next());
155
							if (pref.isValueChanged())
156
								pref.initializeValues(); //
157
						}
158
						closeView();
159
					} else if ("OK".equals(actionCommand)) {
160
						// Apply values in all pages
161
						boolean shouldClose = true;
162
						while (it.hasNext()) {
163
							IPreference preference = (IPreference) preferences.get(it.next());
164
							try{
165
								if (preference.isValueChanged()) {
166
									preference.saveValues();
167
									preference.initializeValues();
168
								}
169
							}catch (StoreException ex) {
170
								// Reach this code should mean that the page has wrong values
171
								shouldClose = false;
172
								PluginServices.getMDIManager().restoreCursor();
173

  
174
								// Show error message
175
								JOptionPane.showMessageDialog((Component)PluginServices.getMainFrame(),ex.getMessage());
176

  
177
								// Focus on error message
178
								setActivePage(preference);
179
							}
180
						}
181
						if (shouldClose)
182
							closeView();
183
					}
184
				}
185
				PluginServices.getMDIManager().restoreCursor();
186
			}
187
		};
138 188
		initialize();
139 189
	}
140 190

  
......
342 392
		if (jButtonOK == null) {
343 393
			jButtonOK = new JButton();
344 394
			jButtonOK.setText(PluginServices.getText(this, "aceptar"));
345
			jButtonOK.addActionListener(new ActionListener()
346
					{
347
						public void actionPerformed(java.awt.event.ActionEvent e) {
348
							Iterator it = preferences.keySet().iterator();
349
							boolean shouldClose = true;
350
							while (it.hasNext()) {
351
								IPreference preference = (IPreference) preferences.get(it.next());
352
								try{
353
									if (preference.isValueChanged()) {
354
										preference.saveValues();
355
										preference.initializeValues();
356
									}
357
								}catch (StoreException ex) {
358
									shouldClose = false;
359
									JOptionPane.showMessageDialog((Component)PluginServices.getMainFrame(),ex.getMessage());
360
								}
361
							}
362
							if (shouldClose)
363
								closeView();
364

  
365

  
366
						};
367
					});
395
			jButtonOK.setActionCommand("OK");
396
			jButtonOK.addActionListener(action);
368 397
		}
369 398
		return jButtonOK;
370 399
	}
......
378 407
		if (jButtonRestore == null) {
379 408
			jButtonRestore = new JButton();
380 409
			jButtonRestore.setText(PluginServices.getText(this, "restore_defaults"));
381
			jButtonRestore.addActionListener(new ActionListener() {
382
				public void actionPerformed(java.awt.event.ActionEvent e) {
383
					if (activePreference!=null)
384
						activePreference.initializeDefaults();
385
				};
386
			});
410
			jButtonRestore.setActionCommand("RESTORE");
411
			jButtonRestore.addActionListener(action);
387 412
		}
388 413
		return jButtonRestore;
389 414
	}
......
401 426
		if (jButtonCancel == null) {
402 427
			jButtonCancel = new JButton();
403 428
			jButtonCancel.setText(PluginServices.getText(this, "cancelar"));
404
			jButtonCancel.addActionListener(new java.awt.event.ActionListener() {
405
				public void actionPerformed(java.awt.event.ActionEvent e) {
406
					Iterator it = preferences.keySet().iterator();
407
					while (it.hasNext()) {
408
						IPreference pref = (IPreference) preferences.get(it.next());
409
						if (pref.isValueChanged())
410
							pref.initializeValues(); //
411
					}
412
					closeView();
413
				}
414
			});
429
			jButtonCancel.setActionCommand("CANCEL");
430
			jButtonCancel.addActionListener(action);
415 431
		}
416 432
		return jButtonCancel;
417 433
	}

Also available in: Unified diff