KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > genimen > djeneric > tools > specifier > dialogs > ImportResultDialog


1 package com.genimen.djeneric.tools.specifier.dialogs;
2
3 import java.awt.BorderLayout JavaDoc;
4 import java.awt.Color JavaDoc;
5 import java.awt.Component JavaDoc;
6 import java.awt.Dimension JavaDoc;
7 import java.awt.Frame JavaDoc;
8 import java.awt.Toolkit JavaDoc;
9 import java.awt.event.ActionEvent JavaDoc;
10 import java.awt.event.ActionListener JavaDoc;
11 import java.awt.event.KeyAdapter JavaDoc;
12 import java.awt.event.KeyEvent JavaDoc;
13 import java.awt.event.MouseAdapter JavaDoc;
14 import java.awt.event.MouseEvent JavaDoc;
15 import java.util.Collections JavaDoc;
16 import java.util.Comparator JavaDoc;
17
18 import javax.swing.DefaultComboBoxModel JavaDoc;
19 import javax.swing.JButton JavaDoc;
20 import javax.swing.JDialog JavaDoc;
21 import javax.swing.JLabel JavaDoc;
22 import javax.swing.JList JavaDoc;
23 import javax.swing.JPanel JavaDoc;
24 import javax.swing.JScrollPane JavaDoc;
25 import javax.swing.JTabbedPane JavaDoc;
26 import javax.swing.ListCellRenderer JavaDoc;
27
28 import com.genimen.djeneric.language.Messages;
29 import com.genimen.djeneric.repository.DjObject;
30 import com.genimen.djeneric.repository.util.DjObjectImporter;
31 import com.genimen.djeneric.ui.Util;
32 import com.genimen.djeneric.util.DjLogger;
33
34 public class ImportResultDialog extends JDialog JavaDoc
35 {
36   private static final long serialVersionUID = 1L;
37   JPanel JavaDoc panel1 = new JPanel JavaDoc();
38   BorderLayout JavaDoc borderLayout1 = new BorderLayout JavaDoc();
39   JTabbedPane JavaDoc _tabs = new JTabbedPane JavaDoc();
40   JPanel JavaDoc _buttonPanel = new JPanel JavaDoc();
41   BorderLayout JavaDoc borderLayout2 = new BorderLayout JavaDoc();
42   JPanel JavaDoc _buttonEast = new JPanel JavaDoc();
43   JButton JavaDoc _butSave = new JButton JavaDoc();
44   JButton JavaDoc _butCancel = new JButton JavaDoc();
45   JPanel JavaDoc _pnlCreated = new JPanel JavaDoc();
46   JPanel JavaDoc _pnlDeleted = new JPanel JavaDoc();
47   JPanel JavaDoc _pnlUpdated = new JPanel JavaDoc();
48   JScrollPane JavaDoc _scrDeleted = new JScrollPane JavaDoc();
49   BorderLayout JavaDoc borderLayout3 = new BorderLayout JavaDoc();
50   BorderLayout JavaDoc borderLayout4 = new BorderLayout JavaDoc();
51   BorderLayout JavaDoc borderLayout5 = new BorderLayout JavaDoc();
52   JScrollPane JavaDoc _scrUpdated = new JScrollPane JavaDoc();
53   JScrollPane JavaDoc _scrCreated = new JScrollPane JavaDoc();
54   JList JavaDoc _lstDeleted = new JList JavaDoc();
55   JList JavaDoc _lstCreated = new JList JavaDoc();
56   JList JavaDoc _lstUpdated = new JList JavaDoc();
57   boolean _wasCancelled = true;
58   Frame JavaDoc _owner;
59   JPanel JavaDoc jPanel1 = new JPanel JavaDoc();
60   BorderLayout JavaDoc borderLayout6 = new BorderLayout JavaDoc();
61   JPanel JavaDoc jPanel2 = new JPanel JavaDoc();
62   JButton JavaDoc _butDetails = new JButton JavaDoc();
63
64   public ImportResultDialog(Frame JavaDoc owner, DjObjectImporter importer)
65   {
66     super(owner, Messages.getString("ObjectImporter.CheckResults"), true);
67     try
68     {
69       _owner = owner;
70       setDefaultCloseOperation(DISPOSE_ON_CLOSE);
71       jbInit();
72
73       importer.getCreated().sort();
74       importer.getUpdated().sort();
75       importer.getDeleted().sort();
76
77       ResultListCellRenderer renderer = new ResultListCellRenderer();
78
79       _lstCreated.setCellRenderer(renderer);
80       _lstUpdated.setCellRenderer(renderer);
81       _lstDeleted.setCellRenderer(renderer);
82
83       ImportResultComparator irc = new ImportResultComparator();
84       Collections.sort(importer.getCreated(), irc);
85       Collections.sort(importer.getUpdated(), irc);
86       Collections.sort(importer.getDeleted(), irc);
87
88       _lstCreated.setModel(new DefaultComboBoxModel JavaDoc(importer.getCreated().toArray()));
89       _lstUpdated.setModel(new DefaultComboBoxModel JavaDoc(importer.getUpdated().toArray()));
90       _lstDeleted.setModel(new DefaultComboBoxModel JavaDoc(importer.getDeleted().toArray()));
91
92       setSize(500, 400);
93
94       Dimension JavaDoc screenSize = Toolkit.getDefaultToolkit().getScreenSize();
95       Dimension JavaDoc frameSize = getSize();
96       setLocation((screenSize.width - frameSize.width) / 2, (screenSize.height - frameSize.height) / 2);
97       setVisible(true);
98     }
99     catch (Exception JavaDoc x)
100     {
101       DjLogger.log(x);
102     }
103   }
104
105   public boolean wasCancelled()
106   {
107     return _wasCancelled;
108   }
109
110   private void jbInit() throws Exception JavaDoc
111   {
112     panel1.setLayout(borderLayout1);
113     _buttonPanel.setLayout(borderLayout2);
114
115     _butSave.setText(Messages.getString("global.Save"));
116     _butSave.addActionListener(new ImportResultDialog__butSave_actionAdapter(this));
117     _butCancel.setText(Messages.getString("global.Cancel"));
118     _butCancel.addActionListener(new ImportResultDialog__butCancel_actionAdapter(this));
119     _pnlDeleted.setLayout(borderLayout3);
120     _pnlCreated.setLayout(borderLayout4);
121     _pnlUpdated.setLayout(borderLayout5);
122     _lstUpdated.addMouseListener(new ImportResultDialog__lstCreated_mouseAdapter(this));
123     _lstUpdated.addKeyListener(new ImportResultDialog__lstCreated_keyAdapter(this));
124     jPanel1.setLayout(borderLayout6);
125     _butDetails.setText(Messages.getString("ObjectImporter.Details"));
126     _butDetails.addActionListener(new ImportResultDialog__butDetails_actionAdapter(this));
127     getContentPane().add(panel1);
128     panel1.add(_tabs, java.awt.BorderLayout.CENTER);
129     panel1.add(_buttonPanel, java.awt.BorderLayout.SOUTH);
130     _buttonPanel.add(_buttonEast, java.awt.BorderLayout.EAST);
131     _buttonEast.add(_butCancel);
132     _buttonEast.add(_butSave);
133     _tabs.add(_pnlCreated, "Created");
134     _tabs.add(_pnlUpdated, "Updated");
135     _tabs.add(_pnlDeleted, "Deleted");
136     _pnlDeleted.add(_scrDeleted, java.awt.BorderLayout.CENTER);
137     _scrDeleted.getViewport().add(_lstDeleted);
138     _pnlCreated.add(_scrCreated, java.awt.BorderLayout.CENTER);
139     _scrCreated.getViewport().add(_lstCreated);
140     _pnlUpdated.add(_scrUpdated, java.awt.BorderLayout.CENTER);
141     _scrUpdated.getViewport().add(_lstUpdated);
142     _pnlUpdated.add(jPanel1, java.awt.BorderLayout.SOUTH);
143     jPanel1.add(jPanel2, java.awt.BorderLayout.EAST);
144     jPanel2.add(_butDetails);
145     Util.sizeButtons(_buttonEast);
146   }
147
148   public void _butSave_actionPerformed(ActionEvent JavaDoc e)
149   {
150     _wasCancelled = false;
151     setVisible(false);
152   }
153
154   public void _butCancel_actionPerformed(ActionEvent JavaDoc e)
155   {
156     setVisible(false);
157   }
158
159   public void _lstCreated_mouseClicked(MouseEvent JavaDoc e)
160   {
161     if (e.getClickCount() >= 2) showDetails();
162   }
163
164   public void _lstCreated_keyPressed(KeyEvent JavaDoc e)
165   {
166     if (e.getKeyCode() == KeyEvent.VK_ENTER) showDetails();
167   }
168
169   private void showDetails()
170   {
171     DjObject object = (DjObject) _lstUpdated.getSelectedValue();
172     if (object != null) new ObjectInspectorDialog(_owner, object);
173   }
174
175   public void _butDetails_actionPerformed(ActionEvent JavaDoc e)
176   {
177     showDetails();
178   }
179 }
180
181 class ImportResultDialog__butDetails_actionAdapter implements ActionListener JavaDoc
182 {
183   private ImportResultDialog adaptee;
184
185   ImportResultDialog__butDetails_actionAdapter(ImportResultDialog adaptee)
186   {
187     this.adaptee = adaptee;
188   }
189
190   public void actionPerformed(ActionEvent JavaDoc e)
191   {
192     adaptee._butDetails_actionPerformed(e);
193   }
194 }
195
196 class ImportResultDialog__lstCreated_keyAdapter extends KeyAdapter JavaDoc
197 {
198   private ImportResultDialog adaptee;
199
200   ImportResultDialog__lstCreated_keyAdapter(ImportResultDialog adaptee)
201   {
202     this.adaptee = adaptee;
203   }
204
205   public void keyPressed(KeyEvent JavaDoc e)
206   {
207     adaptee._lstCreated_keyPressed(e);
208   }
209 }
210
211 class ImportResultDialog__lstCreated_mouseAdapter extends MouseAdapter JavaDoc
212 {
213   private ImportResultDialog adaptee;
214
215   ImportResultDialog__lstCreated_mouseAdapter(ImportResultDialog adaptee)
216   {
217     this.adaptee = adaptee;
218   }
219
220   public void mouseClicked(MouseEvent JavaDoc e)
221   {
222     adaptee._lstCreated_mouseClicked(e);
223   }
224 }
225
226 class ImportResultDialog__butCancel_actionAdapter implements ActionListener JavaDoc
227 {
228   private ImportResultDialog adaptee;
229
230   ImportResultDialog__butCancel_actionAdapter(ImportResultDialog adaptee)
231   {
232     this.adaptee = adaptee;
233   }
234
235   public void actionPerformed(ActionEvent JavaDoc e)
236   {
237     adaptee._butCancel_actionPerformed(e);
238   }
239 }
240
241 class ImportResultDialog__butSave_actionAdapter implements ActionListener JavaDoc
242 {
243   private ImportResultDialog adaptee;
244
245   ImportResultDialog__butSave_actionAdapter(ImportResultDialog adaptee)
246   {
247     this.adaptee = adaptee;
248   }
249
250   public void actionPerformed(ActionEvent JavaDoc e)
251   {
252     adaptee._butSave_actionPerformed(e);
253   }
254 }
255
256 class ResultListCellRenderer extends JLabel JavaDoc implements ListCellRenderer JavaDoc
257 {
258   private static final long serialVersionUID = 1L;
259
260   public ResultListCellRenderer()
261   {
262   }
263
264   public Component JavaDoc getListCellRendererComponent(JList JavaDoc list, Object JavaDoc value, int index, boolean isSelected,
265                                                 boolean cellHasFocus)
266   {
267     DjObject object = (DjObject) value;
268     setText(object.getExtent().getNameSingular() + ": " + value.toString());
269     if (isSelected)
270     {
271       setOpaque(true);
272       setBackground(Color.BLACK);
273       setForeground(Color.WHITE);
274     }
275     else
276     {
277       setOpaque(false);
278       setBackground(Color.WHITE);
279       setForeground(Color.BLACK);
280     }
281     return this;
282   }
283 }
284
285 class ImportResultComparator implements Comparator JavaDoc
286 {
287
288   public int compare(Object JavaDoc o1, Object JavaDoc o2)
289   {
290     if (!(o1 instanceof DjObject && o2 instanceof DjObject)) return 0;
291
292     DjObject djo1 = (DjObject) o1;
293     DjObject djo2 = (DjObject) o2;
294
295     String JavaDoc s1 = djo1.getExtent().getName() + djo1.toString();
296     String JavaDoc s2 = djo2.getExtent().getName() + djo2.toString();
297     return s1.compareTo(s2);
298   }
299 }
300
Popular Tags