1 package sellwin.gui; 2 3 import sellwin.domain.*; 4 import sellwin.server.BizServices; 5 import sellwin.utils.*; 6 import sellwin.server.*; 7 8 import java.rmi.*; 9 import javax.swing.*; 10 import javax.swing.border.*; 11 import java.awt.*; 12 import java.io.*; 13 import java.lang.*; 14 import java.util.*; 15 import java.awt.event.*; 16 17 import javax.ejb.*; 18 import javax.naming.*; 19 import javax.rmi.PortableRemoteObject ; 20 21 25 29 public class LogonDialog extends JDialog implements GUIChars { 30 31 private static final int MAX_ATTEMPTS=5; 32 private int attempts=0; 33 private JDialog thisDialog; 34 private Whiteboard wb; 35 36 private JTabbedPane tabbedPane = new JTabbedPane(); 37 38 private SellwinSession server = null; 39 private JPanel mainPanel = new JPanel(new BorderLayout()); 40 private JLabel idLabel = new JLabel("User ID:"); 41 private JTextField id = new JTextField(); 42 private JLabel passwordLabel = new JLabel("Password:"); 43 private JPasswordField psw = new JPasswordField(); 44 45 private PrefsPanel wholePrefsPanel = new PrefsPanel(); 46 private JButton prefsApplyButton = new JButton("Apply"); 47 private JButton prefsCloseButton = new JButton("Close"); 48 49 private JTextField dataDir = new JTextField(40); 50 private JButton logonButton = new JButton("OK"); 51 private JButton closeButton = new JButton("Close"); 52 private MainWindow parent = null; 53 54 55 59 public LogonDialog(MainWindow parent) { 60 super(); 61 62 this.parent = parent; 63 thisDialog = this; 64 wb = MainWindow.getWhiteboard(); 65 66 setTitle(wb.getLang().getString("userLogon")); 67 setFont(MainWindow.LABEL_FONT); 68 setSize(380, 300); 69 getContentPane().setLayout(new BorderLayout()); 70 71 setColors(); 72 setFonts(); 73 74 JPanel panel1 = new JPanel(); 75 76 GridBagLayout gbl = new GridBagLayout(); 77 GridBagConstraints gbc = new GridBagConstraints(); 78 panel1.setLayout(gbl); 79 panel1.setBorder(new EtchedBorder()); 80 81 gbc.anchor = GridBagConstraints.WEST; 82 panel1.add(idLabel, gbc); 83 84 gbc = new GridBagConstraints(); 85 gbc.anchor = GridBagConstraints.WEST; 86 gbc.gridx = 0; 87 gbc.gridy = 1; 88 panel1.add(passwordLabel, gbc); 89 90 gbc = new GridBagConstraints(); 91 gbc.insets = new java.awt.Insets (2, 7, 2, 7); 92 gbc.anchor = GridBagConstraints.WEST; 93 id.setMinimumSize(new Dimension(80, Prefs.FIELD_HEIGHT)); 94 id.setMaximumSize(new Dimension(80, Prefs.FIELD_HEIGHT)); 95 id.setPreferredSize(new Dimension(80, Prefs.FIELD_HEIGHT)); 96 panel1.add(id, gbc); 97 98 99 gbc = new GridBagConstraints(); 100 gbc.gridx = 1; 101 gbc.gridy = 1; 102 gbc.insets = new java.awt.Insets (2, 7, 2, 7); 103 gbc.anchor = GridBagConstraints.WEST; 104 psw.setMinimumSize(new Dimension(80, Prefs.FIELD_HEIGHT)); 105 psw.setMaximumSize(new Dimension(80, Prefs.FIELD_HEIGHT)); 106 psw.setPreferredSize(new Dimension(80, Prefs.FIELD_HEIGHT)); 107 panel1.add(psw, gbc); 108 109 111 JPanel prefsPanel = new JPanel(new BorderLayout()); 112 prefsPanel.add(wholePrefsPanel, BorderLayout.CENTER); 113 114 JPanel prefsbuttonPanel = new JPanel(); 115 prefsbuttonPanel.add(prefsApplyButton); 116 prefsbuttonPanel.add(prefsCloseButton); 117 prefsPanel.add(prefsbuttonPanel, BorderLayout.SOUTH); 118 119 mainPanel.add(panel1, BorderLayout.CENTER); 120 121 JPanel panel2 = new JPanel(); 122 logonButton.addActionListener( 123 new ActionListener() { 124 public void actionPerformed(ActionEvent e) { 125 try { 126 Properties props = Prefs.getApplProps(); 127 128 String mode = (String )(props.getProperty(Prefs.CONN_MODE)); 129 if (mode.equals(Prefs.LOCAL)) { 130 String db = (String )(props.getProperty(Prefs.LOCAL_DB)); 131 String id = (String )(props.getProperty(Prefs.LOCAL_DB_ID)); 132 String psw = (String )(props.getProperty(Prefs.LOCAL_DB_PSW)); 133 SellwinSession biz = new BizServices(Prefs.MYSQL); 134 ((BizServices)biz).init2Tier("jdbc:mysql:///"+ db, id, psw); 135 server = biz; 136 137 examineTables(biz); 138 139 140 } else { String serverName = (String )(props.getProperty(Prefs.SERVER_NAME)); 142 String port = "1099"; 143 LogWrite.write("connecting to server at " + serverName + " port " + port); 144 145 InitialContext ic = Utility.getEJBContext(serverName, port); 146 SellwinSessionHome sellwinHome = (SellwinSessionHome) ic.lookup("SellWinSessionBean"); 147 server = sellwinHome.create(); } 149 char[] temp = psw.getPassword(); 150 if (server == null) 151 LogWrite.write("server is null"); 152 LogWrite.write("cred = " + id.getText() + "-" + temp); 153 Login login = server.logon(id.getText(), new String (temp)); 154 wb.setCurrentLogin(login); 155 156 MainWindow.setSecurity(wb.getLogin()); 157 158 wb.setRemIF(server); 159 wb.setLoggedOn(true); 160 MainWindow.setLogonOff(); 161 MainWindow.getOppPanel().load(); 162 MainWindow.getOppList().loadUser(); 163 MainWindow.getOppList().setLocation(MainWindow.calcLocation()); 164 MainWindow.getOppList().show(); 165 MainWindow.setItemsOn(); 166 hide(); 167 props = Prefs.getApplProps(); 168 props.setProperty(Prefs.LAST_ID, id.getText()); 169 Prefs.saveApplProps(props); 170 attempts=0; 171 } catch (Exception g) { 172 ErrorHandler.show(thisDialog, g); 173 attempts++; 174 if (attempts >= MAX_ATTEMPTS) { 175 hide(); 176 ErrorHandler.show(thisDialog, new AngError("Log-in unsuccessful, please see System Administrator.")); 177 } else { 178 ErrorHandler.show(thisDialog, g); 179 } 180 } 181 } 182 }); 183 184 closeButton.addActionListener( 185 new ActionListener() { 186 public void actionPerformed(ActionEvent e) { 187 hide(); 188 } 189 }); 190 panel2.add(logonButton); 191 panel2.add(closeButton); 192 193 mainPanel.add(panel2, BorderLayout.SOUTH); 194 195 tabbedPane.add(wb.getLang().getString("logon"), mainPanel); 196 tabbedPane.add(wb.getLang().getString("prefs"), prefsPanel); 197 198 getContentPane().add(tabbedPane, BorderLayout.CENTER); 199 200 201 WindowListener l = new WindowAdapter() { 202 public void windowClosed(WindowEvent e) { 203 } 204 205 public void windowClosing(WindowEvent e) { 206 hide(); 207 } 208 }; 209 210 addWindowListener(l); 211 212 getRootPane().setDefaultButton(logonButton); 213 214 wholePrefsPanel.getProps(); 215 216 prefsCloseButton.addActionListener( 217 new ActionListener() { 218 public void actionPerformed(ActionEvent e) { 219 hide(); 220 } 221 }); 222 223 prefsApplyButton.addActionListener( 224 new ActionListener() { 225 public void actionPerformed(ActionEvent e) { 226 wholePrefsPanel.storeProps(); 227 } 228 }); 229 230 setLang(); 231 } 232 233 234 238 public final SellwinSession getRemInterface() { 239 return server; 240 } 241 242 245 public final void requestFocus() { 246 psw.requestFocus(); 247 } 248 249 253 public final void setInitialUser() { 254 String userName = Prefs.getLastID(); 255 if ((userName != null) || (userName.length() > 0)) 256 id.setText(userName); 257 } 258 259 262 public final void setColors() { 263 idLabel.setForeground(Color.black); 264 passwordLabel.setForeground(Color.black); 265 } 266 267 270 public final void setFonts() { 271 idLabel.setFont(MainWindow.LABEL_FONT); 272 id.setFont(MainWindow.FIELD_FONT); 273 passwordLabel.setFont(MainWindow.LABEL_FONT); 274 psw.setFont(MainWindow.FIELD_FONT); 275 prefsApplyButton.setFont(MainWindow.LABEL_FONT); 276 prefsCloseButton.setFont(MainWindow.LABEL_FONT); 277 dataDir.setFont(MainWindow.FIELD_FONT); 278 tabbedPane.setFont(MainWindow.LABEL_FONT); 279 logonButton.setFont(MainWindow.LABEL_FONT); 280 closeButton.setFont(MainWindow.LABEL_FONT); 281 } 282 283 class RadioListener implements ActionListener { 284 public RadioListener() { 285 super(); 286 } 287 288 291 public void actionPerformed(ActionEvent e) { 292 if (e.getActionCommand().equals(Prefs.CONNECTED)) 293 wb.setSpeed(Prefs.CONNECTED); 294 else 295 wb.setSpeed(Prefs.LOCAL); 296 } 297 } 298 299 302 public final void setLang() { 303 setTitle(wb.getLang().getString("userLogon")); 304 prefsApplyButton.setText(wb.getLang().getString("apply")); 305 prefsCloseButton.setText(wb.getLang().getString("close")); 306 logonButton.setText(wb.getLang().getString("ok")); 307 closeButton.setText(wb.getLang().getString("close")); 308 tabbedPane.setTitleAt(0, wb.getLang().getString("logon")); 309 tabbedPane.setTitleAt(1, wb.getLang().getString("prefs")); 310 idLabel.setText(wb.getLang().getString("userid")); 311 passwordLabel.setText(wb.getLang().getString("password")); 312 } 313 314 private void examineTables(SellwinSession biz) { 315 try { 316 if (((BizServices)biz).testTable()) 317 LogWrite.write("local database exists"); 318 else { 319 LogWrite.write("local database about to be created"); 320 ((BizServices)biz).createAllTables(); 321 LogWrite.write("local database has been created"); 322 } 323 324 int rc = ((BizServices)biz).testTableData(); 325 System.out.println("rc test Table data returned " + rc); 326 327 if (rc < 1) { 328 LogWrite.write("loading test data"); 329 ((BizServices)biz).loadTestData(); 330 LogWrite.write("test data load complete"); 331 } else 332 LogWrite.write("test data already loaded"); 333 334 } catch (Exception e) { 335 LogWrite.write(e); 336 } 337 } 338 } 339 | Popular Tags |