KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > genimen > djeneric > tools > administrator > helpers > ImportContextDialog


1 /*
2  * Copyright (c) 2001-2005 by Genimen BV (www.genimen.com) All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, is permitted provided that the following conditions are met: -
6  * Redistributions of source code must retain the above copyright notice, this
7  * list of conditions and the following disclaimer. - Redistributions in binary
8  * form must reproduce the above copyright notice, this list of conditions and
9  * the following disclaimer in the documentation and/or other materials
10  * provided with the distribution. - All advertising materials mentioning
11  * features or use of this software must display the following acknowledgment:
12  * "This product includes Djeneric." - Products derived from this software may
13  * not be called "Djeneric" nor may "Djeneric" appear in their names without
14  * prior written permission of Genimen BV. - Redistributions of any form
15  * whatsoever must retain the following acknowledgment: "This product includes
16  * Djeneric."
17  *
18  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER AND CONTRIBUTORS "AS IS"
19  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21  * ARE DISCLAIMED. IN NO EVENT SHALL GENIMEN BV, DJENERIC.ORG, OR CONTRIBUTORS
22  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28  * POSSIBILITY OF SUCH DAMAGE.
29  */

30 package com.genimen.djeneric.tools.administrator.helpers;
31
32 import java.awt.BorderLayout JavaDoc;
33 import java.awt.Dimension JavaDoc;
34 import java.awt.Toolkit JavaDoc;
35 import java.awt.event.ActionEvent JavaDoc;
36 import java.io.File JavaDoc;
37
38 import javax.swing.JButton JavaDoc;
39 import javax.swing.JDialog JavaDoc;
40 import javax.swing.JFileChooser JavaDoc;
41 import javax.swing.JLabel JavaDoc;
42 import javax.swing.JOptionPane JavaDoc;
43 import javax.swing.JPanel JavaDoc;
44 import javax.swing.JTextField JavaDoc;
45
46 import com.genimen.djeneric.language.Messages;
47 import com.genimen.djeneric.repository.DjPersistenceManager;
48 import com.genimen.djeneric.tools.administrator.Administrator;
49 import com.genimen.djeneric.tools.modeler.ModelEditor;
50 import com.genimen.djeneric.ui.DjVerticalFlowLayout;
51 import com.genimen.djeneric.ui.Util;
52 import com.genimen.djeneric.util.DjFileFilter;
53
54 /**
55  * Description of the Class
56  *
57  * @author Wido Riezebos @created 27 mei 2002
58  */

59 public class ImportContextDialog extends JDialog JavaDoc
60 {
61   private static final long serialVersionUID = 1L;
62   JPanel JavaDoc panel1 = new JPanel JavaDoc();
63   BorderLayout JavaDoc borderLayout1 = new BorderLayout JavaDoc();
64   JPanel JavaDoc jPanel1 = new JPanel JavaDoc();
65   JPanel JavaDoc jPanel2 = new JPanel JavaDoc();
66   JPanel JavaDoc jPanel3 = new JPanel JavaDoc();
67   BorderLayout JavaDoc borderLayout2 = new BorderLayout JavaDoc();
68   JPanel JavaDoc jPanel4 = new JPanel JavaDoc();
69   JButton JavaDoc _butOk = new JButton JavaDoc();
70   JButton JavaDoc _butCancel = new JButton JavaDoc();
71   JLabel JavaDoc jLabel1 = new JLabel JavaDoc();
72   DjVerticalFlowLayout verticalFlowLayout1 = new DjVerticalFlowLayout();
73   JLabel JavaDoc jLabel3 = new JLabel JavaDoc();
74   DjVerticalFlowLayout verticalFlowLayout2 = new DjVerticalFlowLayout();
75   JTextField JavaDoc _edtContextName = new JTextField JavaDoc();
76   boolean _wasCancelled = true;
77   DjPersistenceManager _manager;
78   JPanel JavaDoc jPanel5 = new JPanel JavaDoc();
79   JTextField JavaDoc _edtImportFile = new JTextField JavaDoc();
80   BorderLayout JavaDoc borderLayout3 = new BorderLayout JavaDoc();
81   JButton JavaDoc butBrowse = new JButton JavaDoc();
82   Administrator _administrator;
83
84   /**
85    * Constructor for the DefineRepositoryDialog object
86    *
87    * @param administrator
88    * Description of the Parameter
89    * @param title
90    * Description of the Parameter
91    * @param descr
92    * Description of the Parameter
93    * @exception Exception
94    * Description of the Exception
95    */

96   public ImportContextDialog(Administrator administrator, DjPersistenceManager manager, String JavaDoc contextName)
97       throws Exception JavaDoc
98   {
99     super(administrator, Messages.getString("global.ImportContext"), true);
100     _administrator = administrator;
101     _manager = manager;
102     jbInit();
103     setSize(new Dimension JavaDoc(400, 125));
104
105     if (contextName != null)
106     {
107       _edtContextName.setText(contextName);
108       _edtContextName.setEditable(false);
109       _edtContextName.setEnabled(false);
110     }
111
112     Dimension JavaDoc screenSize = Toolkit.getDefaultToolkit().getScreenSize();
113     Dimension JavaDoc frameSize = getSize();
114     setLocation((screenSize.width - frameSize.width) / 2, (screenSize.height - frameSize.height) / 2);
115
116     setVisible(true);
117   }
118
119   /**
120    * Description of the Method
121    *
122    * @return Description of the Return Value
123    */

124   public boolean wasCancelled()
125   {
126     return _wasCancelled;
127   }
128
129   void jbInit() throws Exception JavaDoc
130   {
131     panel1.setLayout(borderLayout1);
132     jPanel3.setLayout(borderLayout2);
133     _butOk.setText(Messages.getString("global.Ok"));
134     _butOk.addActionListener(new java.awt.event.ActionListener JavaDoc()
135     {
136       public void actionPerformed(ActionEvent JavaDoc e)
137       {
138         _butOk_actionPerformed(e);
139       }
140     });
141     _butCancel.setText(Messages.getString("global.Cancel"));
142     _butCancel.addActionListener(new java.awt.event.ActionListener JavaDoc()
143     {
144       public void actionPerformed(ActionEvent JavaDoc e)
145       {
146         _butCancel_actionPerformed(e);
147       }
148     });
149     jLabel1.setText(Messages.getString("ImportContextDialog.ImportFile"));
150     jPanel1.setLayout(verticalFlowLayout1);
151     jLabel3.setText(Messages.getString("ImportContextDialog.ContextName"));
152     jPanel2.setLayout(verticalFlowLayout2);
153     jPanel5.setLayout(borderLayout3);
154     butBrowse.setPreferredSize(new Dimension JavaDoc(24, 24));
155     butBrowse.setText("...");
156     butBrowse.addActionListener(new java.awt.event.ActionListener JavaDoc()
157     {
158       public void actionPerformed(ActionEvent JavaDoc e)
159       {
160         butBrowse_actionPerformed(e);
161       }
162     });
163     getContentPane().add(panel1);
164     panel1.add(jPanel1, BorderLayout.WEST);
165     jPanel1.add(jLabel1, null);
166     jPanel1.add(jLabel3, null);
167     panel1.add(jPanel2, BorderLayout.CENTER);
168     jPanel2.add(jPanel5, null);
169     jPanel5.add(_edtImportFile, BorderLayout.CENTER);
170     jPanel5.add(butBrowse, BorderLayout.EAST);
171     jPanel2.add(_edtContextName, null);
172     panel1.add(jPanel3, BorderLayout.SOUTH);
173     jPanel3.add(jPanel4, BorderLayout.EAST);
174     jPanel4.add(_butCancel, null);
175     jPanel4.add(_butOk, null);
176     Util.sizeButtons(jPanel4);
177     Util.sizeLabels(jPanel1);
178   }
179
180   void _butCancel_actionPerformed(ActionEvent JavaDoc e)
181   {
182     setVisible(false);
183   }
184
185   void _butOk_actionPerformed(ActionEvent JavaDoc e)
186   {
187     if (_edtContextName.getText().trim().length() == 0)
188     {
189       JOptionPane.showMessageDialog(this, Messages.getString("ImportContextDialog.ContextNameRequired"));
190       return;
191     }
192
193     if (_edtImportFile.getText().trim().length() == 0)
194     {
195       JOptionPane.showMessageDialog(this, Messages.getString("ImportContextDialog.FileRequired"));
196       return;
197     }
198
199     _wasCancelled = false;
200     setVisible(false);
201   }
202
203   public String JavaDoc getContextName()
204   {
205     return _edtContextName.getText().trim();
206   }
207
208   public String JavaDoc getFileName()
209   {
210     return _edtImportFile.getText().trim();
211   }
212
213   void butBrowse_actionPerformed(ActionEvent JavaDoc e)
214   {
215     JFileChooser JavaDoc fc = new JFileChooser JavaDoc();
216     fc.setDialogTitle(Messages.getString("ImportContextDialog.ImportFromFile"));
217     DjFileFilter filter = new DjFileFilter(new String JavaDoc[]{ModelEditor.DUMP_EXTENSION}, "Dump");
218
219     fc.setFileFilter(filter);
220
221     String JavaDoc path = _edtImportFile.getText();
222
223     if (path.trim().length() == 0) path = _administrator.getProperty(AdminPanel.DUMPLOCATION, System.getProperties()
224         .getProperty("user.dir"));
225
226     fc.setCurrentDirectory(new File JavaDoc(path));
227     fc.setFileSelectionMode(JFileChooser.FILES_ONLY);
228
229     if (fc.showOpenDialog(this) != JFileChooser.CANCEL_OPTION)
230     {
231       _administrator.setProperty(AdminPanel.DUMPLOCATION, fc.getSelectedFile().getAbsolutePath());
232       _edtImportFile.setText(fc.getSelectedFile().getAbsolutePath());
233     }
234   }
235 }
Popular Tags