1 package sellwin.gui; 2 3 import sellwin.domain.*; 4 import sellwin.server.*; 5 import sellwin.utils.*; 6 7 import javax.swing.*; 8 import javax.swing.event.*; 9 import javax.swing.plaf.*; 10 import javax.swing.plaf.metal.*; 11 import java.rmi.*; 12 import java.net.*; 13 import java.awt.*; 14 import java.util.*; 15 import java.awt.event.*; 16 17 21 27 public class MainWindow extends JFrame { 28 29 final public static int OPP_TAB_INDEX = 1; 30 final public static int ACT_TAB_INDEX = 2; 31 final public static int FORECAST_TAB_INDEX = 3; 32 final public static int CUST_TAB_INDEX = 4; 33 final public static int QUOTE_TAB_INDEX = 5; 34 final public static int ORDER_TAB_INDEX = 6; 35 final public static int CONTACT_TAB_INDEX = 7; 36 37 public static final int INITIAL_WIDTH=777; 38 public static final int INITIAL_HEIGHT=500; 39 public static final Font LABEL_FONT = new Font("Helvetica", 1, 14); 40 public static final Font FIELD_FONT = new Font("Helvetica", 0, 12); 41 42 private static MainWindow thisFrame; 43 private static Whiteboard wb = null; 44 private static JTabbedPane tabbedPane = new JTabbedPane(); 45 private JPanel mainPanel = new JPanel(new BorderLayout()); 46 private static HelpDialog helpDialog = null; 47 private static AboutDialog aboutDialog = null; 48 private static LogonDialog logonDialog = null; 49 private static OppListDialog oppList = null; 50 private static SalesGroupDialog salesGroupDialog = null; 51 private static CustAdminDialog custAdminDialog = null; 52 private static UserAdminDialog salesPersonDialog = null; 53 private static ChatDialog chatDialog = null; 54 55 private static OppPanel oppPanel = null; 56 private static ActivPanel activPanel = null; 57 private static ForecastPanel forecastPanel = null; 58 private static CustPanel custPanel = null; 59 private static QuotesPanel quotePanel = null; 60 private static OrderFulfillPanel ordersPanel = null; 61 private static ContactsPanel contactsPanel = null; 62 private static LeadsDialog leadsDialog = null; 63 private static SyncDialog syncDialog = null; 64 private static PrefsDialog prefsDialog = null; 65 private static FunnelDialog funnelDialog = null; 66 67 private static JMenu helpMenu = new JMenu("Help"); 68 private static JMenuItem helpItem = new JMenuItem("Help", 'H'); 69 private static JMenuItem aboutItem = new JMenuItem("About", 'A'); 70 71 private static JMenu adminMenu = new JMenu("Admin"); 72 private static JMenuItem logonItem = new JMenuItem("Logon", 'L'); 73 private static JMenuItem logoutItem = new JMenuItem("Logout", 'o'); 74 private static JMenuItem openItem = new JMenuItem("Open", 'O'); 75 private static JMenuItem prefsItem = new JMenuItem("Preferences", 'P'); 76 private static JMenuItem addSalesPersonItem = new JMenuItem("Users", 'U'); 77 private static JMenuItem addSalesGroupItem = new JMenuItem("Groups", 'G'); 78 private static JMenuItem custAdminItem = new JMenuItem("Customers", 'C'); 79 private static JMenuItem leadsItem = new JMenuItem("Sales Leads", 'L'); 80 private static JMenu dataMenu = new JMenu("Data"); 81 private static JMenuItem syncItem = new JMenuItem("Sync with server", 'S'); 82 83 private static JMenu analyMenu = new JMenu("Analytics"); 84 private static JMenuItem funnelItem = new JMenuItem("Sales Funnel", 'F'); 85 86 private static JMenu utilityMenu = new JMenu("Utilities"); 87 private static JMenuItem chatItem = new JMenuItem("Chat", 'C'); 88 89 private static JMenuItem exitItem = new JMenuItem("Exit", 'E'); 90 91 public static Color LETTERS = Color.black; 92 private static JMenuBar menuBar = new JMenuBar(); 93 private static JMenu fileMenu = new JMenu("File"); 94 95 98 public MainWindow() 99 throws AngError, RemoteException { 100 101 thisFrame = this; 102 103 wb = new Whiteboard(this); 104 105 createMenuBar(); 106 setTitle("SellWin"); 107 setSize(INITIAL_WIDTH, INITIAL_HEIGHT); 108 109 110 try { 111 oppPanel = new OppPanel(); 112 activPanel = new ActivPanel(); 113 forecastPanel = new ForecastPanel(); 114 custPanel = new CustPanel(); 115 quotePanel = new QuotesPanel(); 116 ordersPanel = new OrderFulfillPanel(); 117 contactsPanel = new ContactsPanel(); 118 } catch (RuntimeException e) { 119 ErrorHandler.show(this, e); 120 System.exit(-1); 121 } 122 123 setItemsOff(); 124 125 tabbedPane.add("Opportunity", oppPanel); 126 tabbedPane.addTab("Activities", activPanel); 127 tabbedPane.addTab("Forecasts", forecastPanel); 128 tabbedPane.addTab("Customer", custPanel); 129 tabbedPane.addTab("Quotes", quotePanel); 130 tabbedPane.addTab("Orders", ordersPanel); 131 tabbedPane.addTab("Contacts", contactsPanel); 132 133 134 mainPanel.add(tabbedPane, BorderLayout.CENTER); 135 getContentPane().add(mainPanel); 136 137 setVisible(true); 138 139 143 startActivityCheck(); 144 145 if (logonDialog == null) 146 logonDialog = new LogonDialog(thisFrame); 147 logonDialog.setLocation(calcLocation()); 148 logonDialog.setInitialUser(); 149 logonDialog.show(); 150 logonDialog.requestFocus(); 151 152 tabbedPane.addChangeListener( 153 new ChangeListener() { 154 public void stateChanged(ChangeEvent e) { 155 } 156 } 157 ); 158 159 setLang(); 160 161 } 162 163 169 public static Whiteboard getWhiteboard() { 170 return wb; 171 } 172 173 177 public static void setLogonOff() { 178 logonItem.setEnabled(false); 179 logoutItem.setEnabled(true); 180 } 181 182 185 public final void createMenuBar() { 186 menuBar = new JMenuBar(); 187 menuBar.setMargin(new Insets(30, 3, 10, 5)); 188 189 helpMenu.add(helpItem); 190 helpItem.addActionListener( 191 new ActionListener() { 192 public void actionPerformed(ActionEvent e) { 193 if (helpDialog == null) 194 helpDialog = new HelpDialog(thisFrame); 195 helpDialog.setVisible(true); 196 helpDialog.setLocationRelativeTo(thisFrame); 197 helpDialog.show(); 198 } 199 } 200 ); 201 helpMenu.add(aboutItem); 202 aboutItem.addActionListener( 203 new ActionListener() { 204 public void actionPerformed(ActionEvent e) { 205 if (aboutDialog == null) 206 aboutDialog = new AboutDialog(thisFrame); 207 aboutDialog.setVisible(true); 208 aboutDialog.setLocationRelativeTo(thisFrame); 209 aboutDialog.show(); 210 } 211 } 212 ); 213 214 logonItem.addActionListener( 215 new ActionListener() { 216 public void actionPerformed(ActionEvent e) { 217 if (logonDialog == null) 218 logonDialog = new LogonDialog(thisFrame); 219 logonDialog.setLocation(calcLocation()); 220 logonDialog.show(); 221 logonDialog.requestFocus(); 222 } 223 }); 224 fileMenu.add(logonItem); 225 226 fileMenu.add(logoutItem); 227 logoutItem.addActionListener( 228 new ActionListener() { 229 public void actionPerformed(ActionEvent e) { 230 setItemsOff(); 231 logonItem.setEnabled(true); 232 JOptionPane.showMessageDialog( 233 thisFrame, 234 "Logout Successful", 235 "Logout Successful", 236 JOptionPane.INFORMATION_MESSAGE); 237 logonDialog.setLocation(calcLocation()); 238 logonDialog.setInitialUser(); 239 logonDialog.show(); 240 logonDialog.requestFocus(); 241 } 242 }); 243 244 openItem.addActionListener( 245 new ActionListener() { 246 public void actionPerformed(ActionEvent e) { 247 if (oppList == null) 248 oppList = new OppListDialog(); 249 oppList.loadUser(); 250 oppList.setLocation(calcLocation()); 251 oppList.show(); 252 } 253 }); 254 255 fileMenu.add(openItem); 256 exitItem.addActionListener( 257 new ActionListener() { 258 public void actionPerformed(ActionEvent e) { 259 System.exit(0); 260 } 261 }); 262 263 264 fileMenu.add(exitItem); 265 266 custAdminItem.addActionListener( 267 new ActionListener() { 268 public void actionPerformed(ActionEvent e) { 269 if (custAdminDialog == null) 270 custAdminDialog = new CustAdminDialog(thisFrame, false); 271 custAdminDialog.setLocation(calcLocation()); 272 custAdminDialog.show(); 273 } 274 }); 275 adminMenu.add(custAdminItem); 276 277 addSalesGroupItem.addActionListener( 278 new ActionListener() { 279 public void actionPerformed(ActionEvent e) { 280 if (salesGroupDialog == null) 281 salesGroupDialog = new SalesGroupDialog(); 282 else 283 salesGroupDialog.loadData(); 284 salesGroupDialog.setLocation(calcLocation()); 285 salesGroupDialog.show(); 286 } 287 }); 288 adminMenu.add(addSalesGroupItem); 289 290 addSalesPersonItem.addActionListener( 291 new ActionListener() { 292 public void actionPerformed(ActionEvent e) { 293 if (salesPersonDialog == null) 294 salesPersonDialog = new UserAdminDialog(thisFrame, false); 295 salesPersonDialog.setLocation(calcLocation()); 296 salesPersonDialog.show(); 297 } 298 }); 299 adminMenu.add(addSalesPersonItem); 300 301 adminMenu.add(prefsItem); 302 prefsItem.addActionListener( 303 new ActionListener() { 304 public void actionPerformed(ActionEvent e) { 305 if (prefsDialog == null) 306 prefsDialog = new PrefsDialog(); 307 prefsDialog.setLocation(calcLocation()); 308 prefsDialog.show(); 309 } 310 }); 311 312 analyMenu.add(funnelItem); 313 funnelItem.addActionListener( 314 new ActionListener() { 315 public void actionPerformed(ActionEvent e) { 316 if (funnelDialog == null) 317 funnelDialog = new FunnelDialog(); 318 funnelDialog.setLocation(calcLocation()); 319 funnelDialog.show(); 320 } 321 }); 322 323 utilityMenu.add(chatItem); 324 chatItem.addActionListener( 325 new ActionListener() { 326 public void actionPerformed(ActionEvent e) { 327 try { 328 if (chatDialog == null) 329 chatDialog = new ChatDialog(thisFrame, false); 330 331 chatDialog.setLocation(calcLocation()); 332 chatDialog.show(); 333 } catch (java.net.ConnectException cerr) { 334 ErrorHandler.show(thisFrame, cerr, wb.getLang().getString("connectError")); 335 } catch (Exception err) { 336 ErrorHandler.show(thisFrame, err, "here"); 337 } 338 } 339 }); 340 341 adminMenu.add(leadsItem); 342 leadsItem.addActionListener( 343 new ActionListener() { 344 public void actionPerformed(ActionEvent e) { 345 if (leadsDialog == null) 346 leadsDialog = new LeadsDialog(); 347 leadsDialog.setLocation(calcLocation()); 348 leadsDialog.loadCampaigns(); 349 leadsDialog.show(); 350 } 351 }); 352 353 menuBar.add(fileMenu); 354 menuBar.add(adminMenu); 355 356 dataMenu.add(syncItem); 357 syncItem.addActionListener( 358 new ActionListener() { 359 public void actionPerformed(ActionEvent e) { 360 if (syncDialog == null) 361 syncDialog = new SyncDialog(thisFrame, true); 362 syncDialog.show(); 363 } 364 }); 365 menuBar.add(dataMenu); 366 menuBar.add(analyMenu); 367 menuBar.add(utilityMenu); 368 menuBar.add(helpMenu); 369 370 this.setJMenuBar(menuBar); 371 372 setFont(); 373 374 } 375 376 379 public static void setItemsOff() { 380 logoutItem.setEnabled(false); 381 addSalesGroupItem.setEnabled(false); 382 addSalesPersonItem.setEnabled(false); 383 prefsItem.setEnabled(false); 384 tabbedPane.setEnabled(false); 385 adminMenu.setEnabled(false); 386 oppPanel.setEnabled(false); 387 activPanel.setEnabled(false); 388 forecastPanel.setEnabled(false); 389 custPanel.setEnabled(false); 390 quotePanel.setEnabled(false); 391 ordersPanel.setEnabled(false); 392 contactsPanel.setEnabled(false); 393 } 394 395 398 public static void setItemsOn() { 399 oppPanel.setEnabled(true); 400 custPanel.setEnabled(true); 401 openItem.setEnabled(true); 402 addSalesGroupItem.setEnabled(true); 403 addSalesPersonItem.setEnabled(true); 404 prefsItem.setEnabled(true); 405 tabbedPane.setEnabled(true); 406 adminMenu.setEnabled(true); 407 } 408 409 413 public static ContactsPanel getContactsPanel() { return contactsPanel; } 414 415 419 public static ForecastPanel getForecastPanel() { return forecastPanel; } 420 421 425 public static FunnelDialog getFunnelDialog() { return funnelDialog; } 426 427 431 public static ChatDialog getChatDialog() { return chatDialog; } 432 433 437 public static ActivPanel getActivityPanel() { return activPanel; } 438 439 443 public static LeadsDialog getLeadsDialog() { return leadsDialog; } 444 445 449 public static QuotesPanel getQuotesPanel() { return quotePanel; } 450 451 455 public static OrderFulfillPanel getOrdersPanel() { return ordersPanel; } 456 457 461 public static OppPanel getOppPanel() { return oppPanel; } 462 463 467 public static CustPanel getCustPanel() { return custPanel; } 468 469 473 public static OppListDialog getOppList() { 474 if (oppList == null) 475 oppList = new OppListDialog(); 476 return oppList; 477 } 478 479 484 public static JFrame getMainParent() { 485 return thisFrame; 486 } 487 488 493 public static Point calcLocation() { 494 Double x = new Double (thisFrame.getWidth()/2 + thisFrame.getLocation().getX()); 495 Double y = new Double (thisFrame.getHeight()/2 + thisFrame.getLocation().getY()); 496 Point pt = new Point(x.intValue(), y.intValue()); 497 return pt; 498 } 499 500 503 public static void refreshOpportunity() { 504 getOppPanel().refreshOpportunity(); 505 getContactsPanel().refreshOpportunity(); 506 getQuotesPanel().refreshOpportunity(); 507 getOrdersPanel().refreshOpportunity(); 508 getActivityPanel().refreshOpportunity(); 509 getForecastPanel().refreshOpportunity(); 510 getCustPanel().refreshOpportunity(); 511 } 512 513 517 public static void clearOpportunity() { 518 getOppPanel().clearOpportunity(); 519 getContactsPanel().clearOpportunity(); 520 getQuotesPanel().clearOpportunity(); 521 getOrdersPanel().clearOpportunity(); 522 getActivityPanel().clearOpportunity(); 523 getForecastPanel().clearOpportunity(); 524 getCustPanel().clearOpportunity(); 525 } 526 527 530 private void setFont() { 531 tabbedPane.setFont(LABEL_FONT); 532 menuBar.setFont(LABEL_FONT); 533 helpMenu.setFont(LABEL_FONT); 534 helpItem.setFont(LABEL_FONT); 535 aboutItem.setFont(LABEL_FONT); 536 fileMenu.setFont(LABEL_FONT); 537 logonItem.setFont(LABEL_FONT); 538 logoutItem.setFont(LABEL_FONT); 539 openItem.setFont(LABEL_FONT); 540 fileMenu.setFont(LABEL_FONT); 541 openItem.setFont(LABEL_FONT); 542 exitItem.setFont(LABEL_FONT); 543 custAdminItem.setFont(LABEL_FONT); 544 addSalesGroupItem.setFont(LABEL_FONT); 545 addSalesPersonItem.setFont(LABEL_FONT); 546 adminMenu.setFont(LABEL_FONT); 547 prefsItem.setFont(LABEL_FONT); 548 funnelItem.setFont(LABEL_FONT); 549 leadsItem.setFont(LABEL_FONT); 550 dataMenu.setFont(LABEL_FONT); 551 analyMenu.setFont(LABEL_FONT); 552 utilityMenu.setFont(LABEL_FONT); 553 syncItem.setFont(LABEL_FONT); 554 chatItem.setFont(LABEL_FONT); 555 } 556 557 560 public static void selectOrderTab() { 561 tabbedPane.setSelectedComponent(ordersPanel); 562 } 563 564 568 public static void startActivityCheck() { 569 try { 570 ActivityChecker checker = new ActivityChecker(); 571 checker.start(); 572 } catch (Exception e) { 573 ErrorHandler.show(thisFrame, e); 574 } 575 } 576 577 582 public static void setSecurity(Login login) { 583 if (login.activityReadable()) 584 tabbedPane.setEnabledAt(ACT_TAB_INDEX, true); 585 else 586 tabbedPane.setEnabledAt(ACT_TAB_INDEX, false); 587 588 if (login.forecastReadable()) 589 tabbedPane.setEnabledAt(FORECAST_TAB_INDEX, true); 590 else 591 tabbedPane.setEnabledAt(FORECAST_TAB_INDEX, false); 592 593 if (login.quoteReadable()) 594 tabbedPane.setEnabledAt(QUOTE_TAB_INDEX, true); 595 else 596 tabbedPane.setEnabledAt(QUOTE_TAB_INDEX, false); 597 598 if (login.orderReadable()) 599 tabbedPane.setEnabledAt(ORDER_TAB_INDEX, true); 600 else 601 tabbedPane.setEnabledAt(ORDER_TAB_INDEX, false); 602 603 604 addSalesPersonItem.setEnabled(false); 606 addSalesGroupItem.setEnabled(false); 607 custAdminItem.setEnabled(false); 608 609 if (login.isSystemAdmin()) { 610 addSalesPersonItem.setEnabled(true); 611 addSalesGroupItem.setEnabled(true); 612 custAdminItem.setEnabled(true); 613 return; 614 } 615 616 if (login.userAdminReadable()) { 617 addSalesPersonItem.setEnabled(true); 618 addSalesGroupItem.setEnabled(true); 619 } 620 621 if (login.basicAdminReadable()) { 622 custAdminItem.setEnabled(true); 623 } 624 } 625 626 629 public final void setLang() { 630 tabbedPane.setTitleAt(0, wb.getLang().getString("opportunity")); 631 tabbedPane.setTitleAt(1, wb.getLang().getString("activities")); 632 tabbedPane.setTitleAt(2, wb.getLang().getString("forecasts")); 633 tabbedPane.setTitleAt(3, wb.getLang().getString("customer")); 634 tabbedPane.setTitleAt(4, wb.getLang().getString("quotes")); 635 tabbedPane.setTitleAt(5, wb.getLang().getString("orders")); 636 tabbedPane.setTitleAt(6, wb.getLang().getString("contacts")); 637 638 helpMenu.setText(wb.getLang().getString("help")); 639 helpItem.setText(wb.getLang().getString("help")); 640 adminMenu.setText(wb.getLang().getString("admin")); 641 logonItem.setText(wb.getLang().getString("logon")); 642 logoutItem.setText(wb.getLang().getString("logout")); 643 openItem.setText(wb.getLang().getString("open")); 644 prefsItem.setText(wb.getLang().getString("prefs")); 645 addSalesPersonItem.setText(wb.getLang().getString("users")); 646 addSalesGroupItem.setText(wb.getLang().getString("groups")); 647 custAdminItem.setText(wb.getLang().getString("customers")); 648 funnelItem.setText(wb.getLang().getString("salesFunnel")); 649 leadsItem.setText(wb.getLang().getString("salesLeads")); 650 dataMenu.setText(wb.getLang().getString("data")); 651 analyMenu.setText(wb.getLang().getString("analytics")); 652 utilityMenu.setText(wb.getLang().getString("utilities")); 653 syncItem.setText(wb.getLang().getString("syncWithServer")); 654 exitItem.setText(wb.getLang().getString("exit")); 655 fileMenu.setText(wb.getLang().getString("file")); 656 657 Utility.setLang(getRootPane()); 658 659 oppPanel.setLang(); 660 activPanel.setLang(); 661 forecastPanel.setLang(); 662 custPanel.setLang(); 663 quotePanel.setLang(); 664 ordersPanel.setLang(); 665 contactsPanel.setLang(); 666 667 if (helpDialog != null) helpDialog.setLang(); 668 if (aboutDialog != null) aboutDialog.setLang(); 669 if (logonDialog != null) logonDialog.setLang(); 670 if (oppList != null) oppList.setLang(); 671 if (salesGroupDialog != null) salesGroupDialog.setLang(); 672 if (custAdminDialog != null) custAdminDialog.setLang(); 673 if (salesPersonDialog != null) salesPersonDialog.setLang(); 674 if (chatDialog != null) chatDialog.setLang(); 675 if (funnelDialog != null) funnelDialog.setLang(); 676 if (leadsDialog != null) leadsDialog.setLang(); 677 if (syncDialog != null) syncDialog.setLang(); 678 if (prefsDialog != null) prefsDialog.setLang(); 679 } 680 681 688 public final static SalesGroupDialog getSalesGroupDialog() { 689 if (salesGroupDialog == null) 690 salesGroupDialog = new SalesGroupDialog(); 691 return salesGroupDialog; 692 } 693 } 694 | Popular Tags |