|
1 |
| |
|
2 |
| |
|
3 |
| |
|
4 |
| |
|
5 |
| |
|
6 |
| |
|
7 |
| |
|
8 |
| |
|
9 |
| |
|
10 |
| |
|
11 |
| |
|
12 |
| |
|
13 |
| |
|
14 |
| |
|
15 |
| |
|
16 |
| |
|
17 |
| |
|
18 |
| package org.ericmignot.modeler.gui.palette; |
|
19 |
| |
|
20 |
| import java.awt.BorderLayout; |
|
21 |
| import java.awt.Dimension; |
|
22 |
| |
|
23 |
| import javax.swing.ImageIcon; |
|
24 |
| import javax.swing.JDialog; |
|
25 |
| import javax.swing.JToggleButton; |
|
26 |
| |
|
27 |
| import org.ericmignot.modeler.action.UpdateAction; |
|
28 |
| import org.ericmignot.modeler.gui.StaticValues; |
|
29 |
| import org.ericmignot.modeler.gui.workarea.Item; |
|
30 |
| import org.ericmignot.modeler.gui.workarea.Updatable; |
|
31 |
| import org.ericmignot.modeler.util.action.NotifyableAction; |
|
32 |
| |
|
33 |
| public class UpdateTool extends ItemPaletteTool |
|
34 |
| { |
|
35 |
| |
|
36 |
0
| public JToggleButton getButton()
|
|
37 |
| { |
|
38 |
0
| if (this.button == null)
|
|
39 |
| { |
|
40 |
0
| this.button = new JToggleButton(
|
|
41 |
| StaticValues.getInstance().get("Design.Palette.Update", "Update"), |
|
42 |
| new ImageIcon(this.getClass().getClassLoader().getResource( |
|
43 |
| "org/ericmignot/modeler/gui/palette/update.gif"))); |
|
44 |
0
| this.button.setToolTipText(StaticValues.getInstance().get("Design.Palette.UpdateTooltip", "Update tool"));
|
|
45 |
| } |
|
46 |
0
| return this.button;
|
|
47 |
| } |
|
48 |
| |
|
49 |
0
| public boolean isItemCandidate(Item item)
|
|
50 |
| { |
|
51 |
0
| return (item != null && (item instanceof Updatable));
|
|
52 |
| } |
|
53 |
| |
|
54 |
0
| public NotifyableAction getAction(Item item, int x, int y)
|
|
55 |
| { |
|
56 |
0
| if (! ((Updatable)item).acceptUpdate(x, y))
|
|
57 |
| { |
|
58 |
0
| return null;
|
|
59 |
| } |
|
60 |
| |
|
61 |
0
| UpdatePanel updatePanel = ((Updatable)item).createUpdatePanel();
|
|
62 |
0
| if (updatePanel == null)
|
|
63 |
| { |
|
64 |
0
| return null;
|
|
65 |
| } |
|
66 |
0
| JDialog updateDialog = new JDialog();
|
|
67 |
0
| updateDialog.setTitle("Update object");
|
|
68 |
0
| updatePanel.setBusinessObject(item.getBusinessObject());
|
|
69 |
0
| updatePanel.setDialog(updateDialog);
|
|
70 |
| |
|
71 |
0
| updateDialog.getContentPane().setLayout(new BorderLayout());
|
|
72 |
0
| updateDialog.getContentPane().add(updatePanel);
|
|
73 |
0
| updateDialog.setModal(true);
|
|
74 |
0
| Dimension size = updatePanel.getPreferredSize();
|
|
75 |
0
| size.height += 40 + 25;
|
|
76 |
0
| updateDialog.setSize(size);
|
|
77 |
0
| updateDialog.setLocation(item.getLocationOnScreen());
|
|
78 |
0
| updateDialog.setVisible(true);
|
|
79 |
0
| if (updatePanel.getState() == UpdatePanel.OK)
|
|
80 |
| { |
|
81 |
0
| UpdateAction updateAction = new UpdateAction(
|
|
82 |
| item.getBusinessObject(), |
|
83 |
| updatePanel.getNewValues() |
|
84 |
| ); |
|
85 |
0
| return updateAction;
|
|
86 |
| } |
|
87 |
| else |
|
88 |
| { |
|
89 |
0
| return null;
|
|
90 |
| } |
|
91 |
| } |
|
92 |
| |
|
93 |
| } |