1 30 package com.genimen.djeneric.tools.administrator.helpers; 31 32 import java.awt.BorderLayout ; 33 import java.awt.Dimension ; 34 import java.awt.Toolkit ; 35 import java.awt.event.ActionEvent ; 36 import java.io.File ; 37 38 import javax.swing.JButton ; 39 import javax.swing.JDialog ; 40 import javax.swing.JFileChooser ; 41 import javax.swing.JLabel ; 42 import javax.swing.JOptionPane ; 43 import javax.swing.JPanel ; 44 import javax.swing.JTextField ; 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 59 public class ImportContextDialog extends JDialog 60 { 61 private static final long serialVersionUID = 1L; 62 JPanel panel1 = new JPanel (); 63 BorderLayout borderLayout1 = new BorderLayout (); 64 JPanel jPanel1 = new JPanel (); 65 JPanel jPanel2 = new JPanel (); 66 JPanel jPanel3 = new JPanel (); 67 BorderLayout borderLayout2 = new BorderLayout (); 68 JPanel jPanel4 = new JPanel (); 69 JButton _butOk = new JButton (); 70 JButton _butCancel = new JButton (); 71 JLabel jLabel1 = new JLabel (); 72 DjVerticalFlowLayout verticalFlowLayout1 = new DjVerticalFlowLayout(); 73 JLabel jLabel3 = new JLabel (); 74 DjVerticalFlowLayout verticalFlowLayout2 = new DjVerticalFlowLayout(); 75 JTextField _edtContextName = new JTextField (); 76 boolean _wasCancelled = true; 77 DjPersistenceManager _manager; 78 JPanel jPanel5 = new JPanel (); 79 JTextField _edtImportFile = new JTextField (); 80 BorderLayout borderLayout3 = new BorderLayout (); 81 JButton butBrowse = new JButton (); 82 Administrator _administrator; 83 84 96 public ImportContextDialog(Administrator administrator, DjPersistenceManager manager, String contextName) 97 throws Exception 98 { 99 super(administrator, Messages.getString("global.ImportContext"), true); 100 _administrator = administrator; 101 _manager = manager; 102 jbInit(); 103 setSize(new Dimension (400, 125)); 104 105 if (contextName != null) 106 { 107 _edtContextName.setText(contextName); 108 _edtContextName.setEditable(false); 109 _edtContextName.setEnabled(false); 110 } 111 112 Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); 113 Dimension frameSize = getSize(); 114 setLocation((screenSize.width - frameSize.width) / 2, (screenSize.height - frameSize.height) / 2); 115 116 setVisible(true); 117 } 118 119 124 public boolean wasCancelled() 125 { 126 return _wasCancelled; 127 } 128 129 void jbInit() throws Exception 130 { 131 panel1.setLayout(borderLayout1); 132 jPanel3.setLayout(borderLayout2); 133 _butOk.setText(Messages.getString("global.Ok")); 134 _butOk.addActionListener(new java.awt.event.ActionListener () 135 { 136 public void actionPerformed(ActionEvent e) 137 { 138 _butOk_actionPerformed(e); 139 } 140 }); 141 _butCancel.setText(Messages.getString("global.Cancel")); 142 _butCancel.addActionListener(new java.awt.event.ActionListener () 143 { 144 public void actionPerformed(ActionEvent 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 (24, 24)); 155 butBrowse.setText("..."); 156 butBrowse.addActionListener(new java.awt.event.ActionListener () 157 { 158 public void actionPerformed(ActionEvent 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 e) 181 { 182 setVisible(false); 183 } 184 185 void _butOk_actionPerformed(ActionEvent 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 getContextName() 204 { 205 return _edtContextName.getText().trim(); 206 } 207 208 public String getFileName() 209 { 210 return _edtImportFile.getText().trim(); 211 } 212 213 void butBrowse_actionPerformed(ActionEvent e) 214 { 215 JFileChooser fc = new JFileChooser (); 216 fc.setDialogTitle(Messages.getString("ImportContextDialog.ImportFromFile")); 217 DjFileFilter filter = new DjFileFilter(new String []{ModelEditor.DUMP_EXTENSION}, "Dump"); 218 219 fc.setFileFilter(filter); 220 221 String 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 (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 |