root / branches / v10 / frameworks / _fwAndami / src / com / iver / andami / ui / wizard / UnsavedDataPanel.java @ 13656
History | View | Annotate | Download (15.7 KB)
1 | 12577 | caballero | package com.iver.andami.ui.wizard; |
---|---|---|---|
2 | |||
3 | import java.awt.BorderLayout; |
||
4 | 12606 | jmvivo | import java.awt.Color; |
5 | 12595 | jmvivo | import java.awt.Dimension; |
6 | import java.awt.FlowLayout; |
||
7 | import java.awt.GridBagConstraints; |
||
8 | import java.awt.GridBagLayout; |
||
9 | 12619 | jmvivo | import java.awt.Insets; |
10 | 12595 | jmvivo | import java.awt.event.ActionEvent; |
11 | import java.awt.event.ActionListener; |
||
12 | import java.awt.event.MouseEvent; |
||
13 | import java.awt.event.MouseListener; |
||
14 | 12619 | jmvivo | import java.awt.image.BufferedImage; |
15 | 12595 | jmvivo | import java.util.ArrayList; |
16 | import java.util.Iterator; |
||
17 | 12583 | jmvivo | |
18 | 12619 | jmvivo | import javax.swing.ImageIcon; |
19 | 12583 | jmvivo | import javax.swing.JCheckBox; |
20 | 12595 | jmvivo | import javax.swing.JLabel; |
21 | import javax.swing.JPanel; |
||
22 | 12577 | caballero | import javax.swing.JScrollPane; |
23 | |||
24 | 12595 | jmvivo | import org.gvsig.gui.beans.swing.JButton; |
25 | |||
26 | 12583 | jmvivo | import com.iver.andami.PluginServices; |
27 | import com.iver.andami.plugins.status.IUnsavedData; |
||
28 | import com.iver.andami.ui.mdiManager.IWindow; |
||
29 | import com.iver.andami.ui.mdiManager.WindowInfo; |
||
30 | 12577 | caballero | |
31 | 12619 | jmvivo | /**
|
32 | * Ask for elements to save before application exit
|
||
33 | *
|
||
34 | *
|
||
35 | */
|
||
36 | public class UnsavedDataPanel extends JPanel implements IWindow, ActionListener { |
||
37 | 12606 | jmvivo | /**
|
38 | *
|
||
39 | */
|
||
40 | private static final long serialVersionUID = -4745219917358767905L; |
||
41 | |||
42 | |||
43 | 12619 | jmvivo | private static ImageIcon blanckIcon = null; |
44 | 12583 | jmvivo | private JPanel pResources = null; |
45 | private JPanel pButtons = null; |
||
46 | 12577 | caballero | private JScrollPane pScrollList = null; |
47 | 12595 | jmvivo | private myList list = null; |
48 | 12583 | jmvivo | private JLabel lblDescription = null; |
49 | private JButton botSave = null; |
||
50 | 12714 | cesar | private JButton botDiscard = null; |
51 | 12583 | jmvivo | private JButton botDontExit = null; |
52 | private JPanel pActionButtons = null; |
||
53 | private JPanel pSelectionButtons = null; |
||
54 | private JButton botSelectAll = null; |
||
55 | private JButton botDeselectAll = null; |
||
56 | 12577 | caballero | |
57 | 12583 | jmvivo | private ArrayList listeners = new ArrayList(); |
58 | 12595 | jmvivo | private JLabel lblResourceDescription = null; |
59 | private IUnsavedData[] unsavedDataList; |
||
60 | 12621 | cesar | private String windowTitle = PluginServices.getText(this, "save_resources"); |
61 | 12583 | jmvivo | |
62 | |||
63 | 12595 | jmvivo | |
64 | 12577 | caballero | /**
|
65 | * This is the default constructor
|
||
66 | */
|
||
67 | 12595 | jmvivo | public UnsavedDataPanel(IUnsavedData[] unsavedDatalist) { |
68 | 12577 | caballero | super();
|
69 | initialize(); |
||
70 | 12606 | jmvivo | this.setUnsavedDataArray(unsavedDatalist);
|
71 | 12577 | caballero | } |
72 | |||
73 | /**
|
||
74 | * This method initializes this
|
||
75 | 12583 | jmvivo | *
|
76 | 12577 | caballero | * @return void
|
77 | */
|
||
78 | private void initialize() { |
||
79 | 12583 | jmvivo | BorderLayout borderLayout = new BorderLayout(); |
80 | borderLayout.setHgap(5);
|
||
81 | borderLayout.setVgap(5);
|
||
82 | lblDescription = new JLabel(); |
||
83 | 12871 | cesar | lblDescription.setText(PluginServices.getText(this, "select_resources_to_save_before_exit")); |
84 | 12583 | jmvivo | lblDescription.setPreferredSize(new Dimension(497, 40)); |
85 | lblDescription.setName("lblDescription");
|
||
86 | this.setLayout(borderLayout);
|
||
87 | 13656 | caballero | this.setSize(396, 272); |
88 | 12583 | jmvivo | this.add(getPResources(), java.awt.BorderLayout.CENTER);
|
89 | this.add(getPButtons(), java.awt.BorderLayout.SOUTH);
|
||
90 | this.add(lblDescription, BorderLayout.NORTH); |
||
91 | 12577 | caballero | } |
92 | |||
93 | /**
|
||
94 | 12583 | jmvivo | * This method initializes pResources
|
95 | *
|
||
96 | * @return javax.swing.JPanel
|
||
97 | 12577 | caballero | */
|
98 | 12583 | jmvivo | private JPanel getPResources() { |
99 | if (pResources == null) { |
||
100 | pResources = new JPanel(); |
||
101 | 12595 | jmvivo | pResources.setLayout(new BorderLayout()); |
102 | pResources.add(getPScrollList(), BorderLayout.CENTER);
|
||
103 | pResources.add(getLblResourceDescription(), BorderLayout.SOUTH);
|
||
104 | 12577 | caballero | } |
105 | 12583 | jmvivo | return pResources;
|
106 | 12577 | caballero | } |
107 | |||
108 | 12595 | jmvivo | |
109 | 12577 | caballero | /**
|
110 | 12595 | jmvivo | * This method initializes lblResourceDescription
|
111 | *
|
||
112 | * @return javax.swing.JLabel
|
||
113 | */
|
||
114 | private JLabel getLblResourceDescription() { |
||
115 | if (lblResourceDescription == null) { |
||
116 | lblResourceDescription = new JLabel(); |
||
117 | lblResourceDescription.setText("");
|
||
118 | lblResourceDescription.setPreferredSize(new Dimension(38, 50)); |
||
119 | lblResourceDescription.setName("lblResourceDescription");
|
||
120 | } |
||
121 | return lblResourceDescription;
|
||
122 | } |
||
123 | |||
124 | |||
125 | /**
|
||
126 | 12583 | jmvivo | * This method initializes pButtons
|
127 | *
|
||
128 | * @return javax.swing.JPanel
|
||
129 | 12577 | caballero | */
|
130 | 12583 | jmvivo | private JPanel getPButtons() { |
131 | if (pButtons == null) { |
||
132 | BorderLayout borderLayout2 = new BorderLayout(); |
||
133 | borderLayout2.setHgap(5);
|
||
134 | borderLayout2.setVgap(5);
|
||
135 | pButtons = new JPanel(); |
||
136 | pButtons.setLayout(borderLayout2); |
||
137 | pButtons.add(getPSelectionButtons(), BorderLayout.NORTH);
|
||
138 | pButtons.add(getPActionButtons(), BorderLayout.SOUTH);
|
||
139 | 12577 | caballero | } |
140 | 12583 | jmvivo | return pButtons;
|
141 | 12577 | caballero | } |
142 | |||
143 | /**
|
||
144 | 12583 | jmvivo | * This method initializes pScrollList
|
145 | *
|
||
146 | * @return javax.swing.JScrollPane
|
||
147 | 12577 | caballero | */
|
148 | private JScrollPane getPScrollList() { |
||
149 | if (pScrollList == null) { |
||
150 | pScrollList = new JScrollPane(); |
||
151 | pScrollList.setPreferredSize(new java.awt.Dimension(350,350)); |
||
152 | pScrollList.setViewportView(getList()); |
||
153 | } |
||
154 | return pScrollList;
|
||
155 | } |
||
156 | |||
157 | /**
|
||
158 | 12583 | jmvivo | * This method initializes list
|
159 | *
|
||
160 | * @return javax.swing.JList
|
||
161 | 12577 | caballero | */
|
162 | 12595 | jmvivo | private myList getList() {
|
163 | 12577 | caballero | if (list == null) { |
164 | 12595 | jmvivo | list = new myList();
|
165 | 12606 | jmvivo | list.setBackground(Color.white);
|
166 | 12577 | caballero | } |
167 | return list;
|
||
168 | } |
||
169 | |||
170 | 12583 | jmvivo | /**
|
171 | * This method initializes botSave
|
||
172 | *
|
||
173 | * @return javax.swing.JButton
|
||
174 | */
|
||
175 | private JButton getBotSave() { |
||
176 | if (botSave == null) { |
||
177 | botSave = new JButton(); |
||
178 | botSave.setName("botSave");
|
||
179 | botSave.setToolTipText(PluginServices.getText(this, "save_selected_resources_and_exit")); |
||
180 | 12714 | cesar | botSave.setText(PluginServices.getText(this, "ok")); |
181 | botSave.setActionCommand("Accept");
|
||
182 | 12583 | jmvivo | botSave.addActionListener(this);
|
183 | } |
||
184 | return botSave;
|
||
185 | } |
||
186 | 13656 | caballero | |
187 | 12714 | cesar | /**
|
188 | * This method initializes botDiscard
|
||
189 | *
|
||
190 | * @return javax.swing.JButton
|
||
191 | */
|
||
192 | private JButton getBotDiscard() { |
||
193 | if (botDiscard == null) { |
||
194 | botDiscard = new JButton(); |
||
195 | botDiscard.setName("botDiscard");
|
||
196 | botDiscard.setToolTipText(PluginServices.getText(this, "discard_changes_and_exit")); |
||
197 | botDiscard.setText(PluginServices.getText(this, "discard_changes")); |
||
198 | botDiscard.setActionCommand("Discard");
|
||
199 | botDiscard.addActionListener(this);
|
||
200 | } |
||
201 | return botDiscard;
|
||
202 | } |
||
203 | 12583 | jmvivo | |
204 | /**
|
||
205 | * This method initializes botDontExit
|
||
206 | *
|
||
207 | * @return javax.swing.JButton
|
||
208 | */
|
||
209 | private JButton getBotDontExit() { |
||
210 | if (botDontExit == null) { |
||
211 | botDontExit = new JButton(); |
||
212 | botDontExit.setName("botDontExit");
|
||
213 | 12668 | cesar | botDontExit.setToolTipText(PluginServices.getText(this, "cancel_the_application_termination")); |
214 | botDontExit.setText(PluginServices.getText(this, "cancelar")); |
||
215 | 12714 | cesar | botDontExit.setActionCommand("Cancel");
|
216 | 12583 | jmvivo | botDontExit.addActionListener(this);
|
217 | } |
||
218 | return botDontExit;
|
||
219 | } |
||
220 | |||
221 | /**
|
||
222 | * This method initializes pActionButtons
|
||
223 | *
|
||
224 | * @return javax.swing.JPanel
|
||
225 | */
|
||
226 | private JPanel getPActionButtons() { |
||
227 | if (pActionButtons == null) { |
||
228 | FlowLayout flowLayout = new FlowLayout(); |
||
229 | flowLayout.setAlignment(FlowLayout.RIGHT);
|
||
230 | pActionButtons = new JPanel(); |
||
231 | pActionButtons.setLayout(flowLayout); |
||
232 | pActionButtons.setName("pActionButtons");
|
||
233 | pActionButtons.add(getBotSave(), null);
|
||
234 | 12714 | cesar | pActionButtons.add(getBotDiscard(), null);
|
235 | 12583 | jmvivo | pActionButtons.add(getBotDontExit(), null);
|
236 | } |
||
237 | return pActionButtons;
|
||
238 | } |
||
239 | |||
240 | /**
|
||
241 | * This method initializes pSelectionButtons
|
||
242 | *
|
||
243 | * @return javax.swing.JPanel
|
||
244 | */
|
||
245 | private JPanel getPSelectionButtons() { |
||
246 | if (pSelectionButtons == null) { |
||
247 | FlowLayout flowLayout1 = new FlowLayout(); |
||
248 | flowLayout1.setAlignment(FlowLayout.LEFT);
|
||
249 | pSelectionButtons = new JPanel(); |
||
250 | pSelectionButtons.setLayout(flowLayout1); |
||
251 | pSelectionButtons.setName("pSelectionButtons");
|
||
252 | pSelectionButtons.add(getBotSelectAll(), null);
|
||
253 | pSelectionButtons.add(getBotDeselectAll(), null);
|
||
254 | } |
||
255 | return pSelectionButtons;
|
||
256 | } |
||
257 | |||
258 | /**
|
||
259 | * This method initializes botSelectAll
|
||
260 | *
|
||
261 | * @return javax.swing.JButton
|
||
262 | */
|
||
263 | private JButton getBotSelectAll() { |
||
264 | if (botSelectAll == null) { |
||
265 | botSelectAll = new JButton(); |
||
266 | botSelectAll.setText(PluginServices.getText(this, "select_all")); |
||
267 | botSelectAll.setName("botSelectAll");
|
||
268 | botSelectAll.setToolTipText(PluginServices.getText(this, "select_all_resources")); |
||
269 | 12607 | jmvivo | botSelectAll.setActionCommand("SelectAll");
|
270 | 12583 | jmvivo | botSelectAll.addActionListener(this);
|
271 | } |
||
272 | return botSelectAll;
|
||
273 | } |
||
274 | |||
275 | /**
|
||
276 | * This method initializes botDeselectAll
|
||
277 | *
|
||
278 | * @return javax.swing.JButton
|
||
279 | */
|
||
280 | private JButton getBotDeselectAll() { |
||
281 | if (botDeselectAll == null) { |
||
282 | botDeselectAll = new JButton(); |
||
283 | botDeselectAll.setName("botDeselectAll");
|
||
284 | botDeselectAll.setToolTipText(PluginServices.getText(this, "deselect_all_resources")); |
||
285 | botDeselectAll.setText(PluginServices.getText(this, "deselect_all")); |
||
286 | 12607 | jmvivo | botDeselectAll.setActionCommand("DeselectAll");
|
287 | 12583 | jmvivo | botDeselectAll.addActionListener(this);
|
288 | } |
||
289 | return botDeselectAll;
|
||
290 | } |
||
291 | |||
292 | public WindowInfo getWindowInfo() {
|
||
293 | 12596 | cesar | WindowInfo wi = new WindowInfo(WindowInfo.MODALDIALOG
|
294 | 12606 | jmvivo | | WindowInfo.RESIZABLE |
295 | 12596 | cesar | | WindowInfo.MAXIMIZABLE); |
296 | 12621 | cesar | wi.setTitle(windowTitle); |
297 | 13656 | caballero | wi.setHeight(270);
|
298 | 12633 | cesar | wi.setWidth(450);
|
299 | 12596 | cesar | return wi;
|
300 | 12583 | jmvivo | } |
301 | |||
302 | 12621 | cesar | public void setWindowTitle(String windowTitle) { |
303 | this.windowTitle = windowTitle;
|
||
304 | } |
||
305 | 13656 | caballero | |
306 | 12633 | cesar | public void setCancelText(String text, String tooltipText) { |
307 | getBotDontExit().setToolTipText(tooltipText); |
||
308 | getBotDontExit().setText(text); |
||
309 | } |
||
310 | 13656 | caballero | |
311 | 12714 | cesar | public void setDiscardText(String text, String tooltipText) { |
312 | getBotDiscard().setToolTipText(tooltipText); |
||
313 | getBotDiscard().setText(text); |
||
314 | } |
||
315 | 13656 | caballero | |
316 | 12633 | cesar | public void setAcceptText(String text, String tooltipText) { |
317 | getBotSave().setToolTipText(tooltipText); |
||
318 | getBotSave().setText(text); |
||
319 | } |
||
320 | 13656 | caballero | |
321 | 12633 | cesar | public void setHeaderText(String text) { |
322 | lblDescription.setText(text); |
||
323 | } |
||
324 | 13656 | caballero | |
325 | 12619 | jmvivo | /**
|
326 | * Register a listener to call
|
||
327 | *
|
||
328 | * @param a UnsavedDataPanelListener instance
|
||
329 | */
|
||
330 | 12583 | jmvivo | public void addActionListener(UnsavedDataPanelListener listener){ |
331 | this.listeners.add(listener);
|
||
332 | } |
||
333 | |||
334 | public void removeActionListener(UnsavedDataPanelListener listener){ |
||
335 | this.listeners.remove(listener);
|
||
336 | } |
||
337 | |||
338 | public class UnsavedDataPanelListener { |
||
339 | 12714 | cesar | public void cancel(UnsavedDataPanel panel){ |
340 | 12583 | jmvivo | |
341 | } |
||
342 | |||
343 | 12714 | cesar | public void accept(UnsavedDataPanel panel){ |
344 | 12583 | jmvivo | |
345 | } |
||
346 | 13656 | caballero | |
347 | 12714 | cesar | public void discard(UnsavedDataPanel panel) { |
348 | 13656 | caballero | |
349 | 12714 | cesar | } |
350 | 12595 | jmvivo | } |
351 | 12583 | jmvivo | |
352 | 12595 | jmvivo | private class myList extends JPanel{ |
353 | |||
354 | /**
|
||
355 | *
|
||
356 | */
|
||
357 | private static final long serialVersionUID = 3179254463477354501L; |
||
358 | |||
359 | private GridBagConstraints constraints; |
||
360 | 12619 | jmvivo | private GridBagConstraints constraintsLast; |
361 | 12595 | jmvivo | |
362 | public myList(){
|
||
363 | super();
|
||
364 | initialize(); |
||
365 | } |
||
366 | |||
367 | private void initialize(){ |
||
368 | this.setLayout(new GridBagLayout()); |
||
369 | this.constraints = new GridBagConstraints(); |
||
370 | this.constraints.fill = GridBagConstraints.HORIZONTAL; |
||
371 | 12619 | jmvivo | this.constraints.gridwidth = GridBagConstraints.REMAINDER; |
372 | this.constraints.weightx =0; |
||
373 | this.constraints.gridx =0; |
||
374 | this.constraints.gridy=0; |
||
375 | this.constraints.anchor = GridBagConstraints.WEST; |
||
376 | this.constraints.insets =new Insets(3,3,0,0); |
||
377 | 12595 | jmvivo | |
378 | 12619 | jmvivo | this.constraintsLast = new GridBagConstraints(); |
379 | this.constraintsLast.fill = GridBagConstraints.BOTH; |
||
380 | this.constraintsLast.gridheight = GridBagConstraints.REMAINDER; |
||
381 | this.constraintsLast.gridwidth = GridBagConstraints.REMAINDER; |
||
382 | this.constraintsLast.gridx =0; |
||
383 | this.constraintsLast.weightx =1; |
||
384 | this.constraintsLast.weighty =1; |
||
385 | this.constraintsLast.anchor = GridBagConstraints.FIRST_LINE_START; |
||
386 | |||
387 | |||
388 | 12595 | jmvivo | } |
389 | |||
390 | 12619 | jmvivo | public void addItems(IUnsavedData[] itemList){ |
391 | int i;
|
||
392 | this.removeAll();
|
||
393 | if (itemList.length == 0){ |
||
394 | return;
|
||
395 | } |
||
396 | |||
397 | for (i=0;i< itemList.length;i++){ |
||
398 | this.constraints.gridy = i;
|
||
399 | this.add(newItem(itemList[i]), this.constraints); |
||
400 | } |
||
401 | this.constraintsLast.gridy=itemList.length;
|
||
402 | this.add(new JLabel(),this.constraintsLast); |
||
403 | |||
404 | 12595 | jmvivo | } |
405 | 12619 | jmvivo | public int getItemsCount(){ |
406 | return this.getComponentCount() -1; |
||
407 | } |
||
408 | |||
409 | public myUnsavedItem getItem(int i){ |
||
410 | if (i>= this.getComponentCount()){ |
||
411 | return null; |
||
412 | } |
||
413 | return (myUnsavedItem)this.getComponent(i); |
||
414 | } |
||
415 | |||
416 | private myUnsavedItem newItem(IUnsavedData itemData){
|
||
417 | myUnsavedItem item; |
||
418 | item = new myUnsavedItem(itemData);
|
||
419 | item.addMouseListener(new MouseListener(){ |
||
420 | public void mouseClicked(MouseEvent e) { |
||
421 | myUnsavedItem item = (myUnsavedItem)e.getComponent(); |
||
422 | getLblResourceDescription().setText(item.getDescription()); |
||
423 | } |
||
424 | public void mouseEntered(MouseEvent e) { |
||
425 | } |
||
426 | |||
427 | public void mouseExited(MouseEvent e) { |
||
428 | } |
||
429 | |||
430 | public void mousePressed(MouseEvent e) { |
||
431 | } |
||
432 | |||
433 | public void mouseReleased(MouseEvent e) { |
||
434 | } |
||
435 | |||
436 | }); |
||
437 | return item;
|
||
438 | } |
||
439 | |||
440 | 12583 | jmvivo | } |
441 | |||
442 | 12595 | jmvivo | private class myUnsavedItem extends JPanel{ |
443 | /**
|
||
444 | *
|
||
445 | */
|
||
446 | private static final long serialVersionUID = -6280057775368437349L; |
||
447 | 12583 | jmvivo | private JCheckBox chkChecked; |
448 | 12595 | jmvivo | private JLabel lblText; |
449 | private IUnsavedData dataItem;
|
||
450 | 12583 | jmvivo | |
451 | 12595 | jmvivo | public myUnsavedItem(IUnsavedData dataItem ){
|
452 | super();
|
||
453 | this.initialize();
|
||
454 | this.setData(dataItem);
|
||
455 | } |
||
456 | 12583 | jmvivo | |
457 | 12595 | jmvivo | private void initialize(){ |
458 | 12606 | jmvivo | this.setOpaque(false); |
459 | 12619 | jmvivo | BorderLayout layout = new BorderLayout(); |
460 | layout.setHgap(5);
|
||
461 | this.setLayout(layout);
|
||
462 | 12595 | jmvivo | this.add(this.getChkChecked(),BorderLayout.WEST); |
463 | this.add(this.getLblText(),BorderLayout.CENTER); |
||
464 | } |
||
465 | 12583 | jmvivo | |
466 | 12595 | jmvivo | private JLabel getLblText() { |
467 | if (lblText == null){ |
||
468 | lblText = new JLabel(); |
||
469 | lblText.setName("lblText");
|
||
470 | } |
||
471 | return lblText;
|
||
472 | 12583 | jmvivo | } |
473 | |||
474 | 12595 | jmvivo | private JCheckBox getChkChecked() { |
475 | if (chkChecked == null){ |
||
476 | chkChecked = new JCheckBox(); |
||
477 | chkChecked.setName("chkChecked");
|
||
478 | chkChecked.setSelected(true);
|
||
479 | 12606 | jmvivo | chkChecked.setOpaque(false);
|
480 | 12595 | jmvivo | } |
481 | return chkChecked;
|
||
482 | 12583 | jmvivo | } |
483 | |||
484 | 12595 | jmvivo | public boolean isSelected(){ |
485 | return getChkChecked().isSelected();
|
||
486 | } |
||
487 | |||
488 | public void setSelected(boolean selected){ |
||
489 | getChkChecked().setSelected(selected); |
||
490 | } |
||
491 | |||
492 | public void setData(IUnsavedData dataItem){ |
||
493 | this.dataItem = dataItem;
|
||
494 | JLabel lbl = getLblText();
|
||
495 | 12619 | jmvivo | if (dataItem.getIcon() != null){ |
496 | lbl.setIcon(dataItem.getIcon()); |
||
497 | } else{
|
||
498 | lbl.setIcon(getBlanckIcon()); |
||
499 | } |
||
500 | 12595 | jmvivo | lbl.setText(dataItem.getResourceName()); |
501 | getChkChecked().setSelected(true);
|
||
502 | } |
||
503 | |||
504 | public IUnsavedData getData(){
|
||
505 | return this.dataItem; |
||
506 | } |
||
507 | |||
508 | public String getDescription(){ |
||
509 | return this.dataItem.getDescription(); |
||
510 | } |
||
511 | |||
512 | 12619 | jmvivo | private ImageIcon getBlanckIcon(){ |
513 | if (blanckIcon== null){ |
||
514 | BufferedImage buff =new BufferedImage(16, 16, BufferedImage.TYPE_INT_ARGB); |
||
515 | blanckIcon = new ImageIcon(buff); |
||
516 | } |
||
517 | return blanckIcon;
|
||
518 | } |
||
519 | 12595 | jmvivo | |
520 | 12583 | jmvivo | } |
521 | |||
522 | public void actionPerformed(ActionEvent e) { |
||
523 | 12714 | cesar | if (e.getActionCommand() == "Cancel"){ |
524 | 12595 | jmvivo | fireDontExitEvent(); |
525 | 12583 | jmvivo | return;
|
526 | } |
||
527 | 12714 | cesar | if (e.getActionCommand() == "Accept"){ |
528 | fireAcceptEvent(); |
||
529 | 12583 | jmvivo | return;
|
530 | } |
||
531 | 12714 | cesar | if (e.getActionCommand() == "Discard") { |
532 | fireDiscardEvent(); |
||
533 | return;
|
||
534 | } |
||
535 | 12583 | jmvivo | if (e.getActionCommand() == "SelectAll"){ |
536 | selectAll(); |
||
537 | return;
|
||
538 | } |
||
539 | if (e.getActionCommand() == "DeselectAll"){ |
||
540 | deselectAll(); |
||
541 | return;
|
||
542 | } |
||
543 | } |
||
544 | |||
545 | 12606 | jmvivo | public void close(){ |
546 | PluginServices.getMDIManager().closeWindow(this);
|
||
547 | |||
548 | } |
||
549 | |||
550 | 12714 | cesar | private void fireAcceptEvent() { |
551 | 12595 | jmvivo | Iterator iter = this.listeners.iterator(); |
552 | while (iter.hasNext()){
|
||
553 | 12714 | cesar | ((UnsavedDataPanelListener)iter.next()).accept(this);
|
554 | 12595 | jmvivo | } |
555 | 12583 | jmvivo | } |
556 | 13656 | caballero | |
557 | 12714 | cesar | private void fireDiscardEvent() { |
558 | Iterator iter = this.listeners.iterator(); |
||
559 | while (iter.hasNext()){
|
||
560 | ((UnsavedDataPanelListener)iter.next()).discard(this);
|
||
561 | } |
||
562 | } |
||
563 | 12583 | jmvivo | |
564 | 12595 | jmvivo | private void fireDontExitEvent() { |
565 | Iterator iter = this.listeners.iterator(); |
||
566 | while (iter.hasNext()){
|
||
567 | 12714 | cesar | ((UnsavedDataPanelListener)iter.next()).cancel(this);
|
568 | 12595 | jmvivo | } |
569 | } |
||
570 | 12583 | jmvivo | |
571 | 12595 | jmvivo | private void setSelectedsAll( boolean selected){ |
572 | int i;
|
||
573 | myList theList = getList(); |
||
574 | myUnsavedItem item; |
||
575 | 12619 | jmvivo | for (i=0;i < theList.getItemsCount();i++){ |
576 | item = (myUnsavedItem)theList.getItem(i); |
||
577 | 12595 | jmvivo | item.setSelected(selected); |
578 | } |
||
579 | 12607 | jmvivo | theList.doLayout(); |
580 | 12583 | jmvivo | } |
581 | |||
582 | 12619 | jmvivo | public void deselectAll() { |
583 | 12595 | jmvivo | this.setSelectedsAll(false); |
584 | } |
||
585 | 12583 | jmvivo | |
586 | 12619 | jmvivo | public void selectAll() { |
587 | 12595 | jmvivo | this.setSelectedsAll(true); |
588 | 12583 | jmvivo | } |
589 | |||
590 | 12595 | jmvivo | |
591 | 12619 | jmvivo | /**
|
592 | * Set the resorces to ask for
|
||
593 | *
|
||
594 | * @param IUnsavedData[] resources pending to save
|
||
595 | */
|
||
596 | 12583 | jmvivo | public void setUnsavedDataArray(IUnsavedData[] unsavedDatalist){ |
597 | 12595 | jmvivo | this.unsavedDataList = unsavedDatalist;
|
598 | myList theList = getList(); |
||
599 | 12583 | jmvivo | |
600 | 12619 | jmvivo | theList.addItems(unsavedDatalist); |
601 | 12666 | cesar | theList.validate(); |
602 | 12595 | jmvivo | |
603 | 12583 | jmvivo | } |
604 | 12595 | jmvivo | |
605 | |||
606 | private IUnsavedData[] getUnsavedData(boolean selected){ |
||
607 | int i;
|
||
608 | myList theList = getList(); |
||
609 | ArrayList aList = new ArrayList(); |
||
610 | myUnsavedItem item; |
||
611 | IUnsavedData[] result;
|
||
612 | |||
613 | 12619 | jmvivo | for (i=0;i < theList.getItemsCount();i++){ |
614 | item = (myUnsavedItem)theList.getItem(i); |
||
615 | 12595 | jmvivo | if (item.isSelected() == selected){
|
616 | aList.add(item.getData()); |
||
617 | } |
||
618 | } |
||
619 | result = new IUnsavedData[aList.size()];
|
||
620 | System.arraycopy(aList.toArray(), 0, result, 0, aList.size()); |
||
621 | return result;
|
||
622 | } |
||
623 | |||
624 | |||
625 | 12619 | jmvivo | /**
|
626 | * Returns the IUnsavedData selecteds for the user to save
|
||
627 | *
|
||
628 | * @return IUnsaveData[] to save
|
||
629 | */
|
||
630 | 12595 | jmvivo | public IUnsavedData[] getSelectedsUnsavedData(){ |
631 | return this.getUnsavedData(true); |
||
632 | |||
633 | } |
||
634 | |||
635 | 12619 | jmvivo | /**
|
636 | * Returns the IUnsavedData not selecteds for the user
|
||
637 | *
|
||
638 | * @return IUnsavedData[] to ignore
|
||
639 | */
|
||
640 | 12595 | jmvivo | public IUnsavedData[] getUnselectedsUnsavedData(){ |
641 | return this.getUnsavedData(false); |
||
642 | } |
||
643 | |||
644 | 12577 | caballero | } // @jve:decl-index=0:visual-constraint="10,10"
|