1 package com.ca.directory.jxplorer; 2 3 import javax.swing.*; 4 import javax.swing.event.*; 5 import java.awt.*; 6 import java.awt.event.*; 7 import java.util.*; 8 import java.util.logging.Logger ; 9 10 import com.ca.directory.jxplorer.search.*; 11 import com.ca.commons.naming.*; 12 import com.ca.directory.jxplorer.tree.*; 13 import com.ca.commons.cbutil.*; 14 import com.ca.commons.security.KeystoreGUI; 15 16 import java.io.File ; 17 import java.io.IOException ; 18 19 20 public class MainMenu extends JMenuBar 21 { 22 23 29 private static Logger log = Logger.getLogger(MainMenu.class.getName()); 30 31 JXplorer jxplorer; 32 JXOpenConWin getConnection = null; 34 JMenu fileMenu; 35 JMenuItem connect, disconnect, print, refreshTree, exit; 36 37 JMenu editMenu; 38 JMenuItem cut, copy, paste, delete, rename, copyDN, newEntry, pasteAlias; 39 40 JMenu ldifMenu; 41 JMenuItem fullExport, subExport, importFile, viewOffline; 42 43 JMenu searchMenu; 44 JMenuItem search, deleteFilter, attrList; 45 46 JMenu bookmarkMenu; 47 JMenuItem editBookmark, addBookmark, deleteBookmark; 48 49 JMenu lookAndFeelMenu; 50 JMenuItem refresh; 51 52 JMenu optionsMenu, toolsMenu; 53 JMenuItem advancedOptions; 54 55 JMenu sslMenu; 56 JMenuItem simpleSSL, authSSL, keystoreOptions; 57 58 JMenu helpMenu; 59 JMenuItem helpContents, helpSearch, helpAbout; 60 61 SmartTree tree; 62 63 String dirIcons; 64 String dirImages; 65 String dirTemplates; 66 67 public static Properties myProperties; public static String propertyFile; public static String localDir; public static String fileURLPrefix; 72 public MainMenu(JXplorer jxplorer) 73 { 74 super(); 75 this.jxplorer = jxplorer; 76 77 setImageDirs(); 79 83 84 86 fileMenu = new JMenu(CBIntText.get("File")); 88 fileMenu.setMnemonic('F'); 89 setupFileMenu(fileMenu); 90 91 92 editMenu = new JMenu(CBIntText.get("Edit")); 93 editMenu.setMnemonic('E'); 94 setupEditMenu(editMenu); 95 96 lookAndFeelMenu = new JMenu(CBIntText.get("View")); 98 lookAndFeelMenu.setMnemonic('V'); 99 setupLookAndFeelMenu(lookAndFeelMenu); 100 101 ldifMenu = new JMenu(CBIntText.get("LDIF")); 103 ldifMenu.setMnemonic('L'); 104 setupLdifMenu(ldifMenu); 105 106 searchMenu = new JMenu(CBIntText.get("Search")); 108 searchMenu.setMnemonic('S'); 109 setupSearchMenu(searchMenu); 110 111 bookmarkMenu = new JMenu(CBIntText.get("Bookmark")); 113 bookmarkMenu.setMnemonic('B'); 114 setupBookmarkMenu(bookmarkMenu); 115 116 optionsMenu = new JMenu(CBIntText.get("Options")); 118 optionsMenu.setMnemonic('O'); 119 setupOptionsMenu(optionsMenu); 120 121 toolsMenu = new JMenu(CBIntText.get("Tools")); 123 toolsMenu.setMnemonic('T'); 124 setupToolsMenu(toolsMenu); 125 126 sslMenu = new JMenu(CBIntText.get("Security")); 128 sslMenu.setMnemonic('i'); 129 setupSSLMenu(sslMenu); 130 131 helpMenu = new JMenu(CBIntText.get("Help")); 133 helpMenu.setMnemonic('H'); 134 setupHelpMenu(helpMenu); 135 136 this.add(fileMenu); 138 this.add(editMenu); 139 this.add(lookAndFeelMenu); 140 this.add(bookmarkMenu); 141 this.add(searchMenu); 142 this.add(ldifMenu); 143 this.add(optionsMenu); 144 this.add(toolsMenu); 145 this.add(sslMenu); 146 this.add(helpMenu); 147 148 jxplorer.setJMenuBar(this); 149 150 setDisconnected(); 151 } 152 153 160 161 protected void setupFileMenu(JMenu fileMenu) 162 { 163 165 ActionListener fileListener = new ActionListener() 166 { 167 public void actionPerformed(ActionEvent e) 168 { 169 JMenuItem src = ((JMenuItem)e.getSource()); 170 171 tree = jxplorer.getActiveTree(); 172 173 if (src == connect) 174 connect(); 175 else if (src == disconnect) 176 disconnect(); 177 else if (src == print) 178 print(); 179 else if (src == refreshTree) 180 jxplorer.mrTree.collapse(); 181 else if (src == exit) 182 jxplorer.shutdown(); 183 184 jxplorer.repaint(); 185 } 186 }; 187 188 190 connect = setMenuItem(fileMenu, fileListener, 191 new String [] {CBIntText.get("Connect"), "C", CBIntText.get("Connect to a directory server."), "E", dirImages+"connect.gif" } ); 192 193 disconnect = setMenuItem(fileMenu, fileListener, 194 new String [] {CBIntText.get("Disconnect"), "D", CBIntText.get("Disconnect from a directory server."), "E", dirImages+"disconnect.gif" } ); 195 196 print = setMenuItem(fileMenu, fileListener, 197 new String [] {CBIntText.get("Print"), "P", CBIntText.get("Print out the current entry."), "E", dirImages+"print.gif" } ); 198 199 setMenuItem(fileMenu, fileListener, new String [] {"-", "", "", "" } ); 200 201 refreshTree = setMenuItem(fileMenu, fileListener, 202 new String [] {CBIntText.get("Refresh Tree"), "R", CBIntText.get("Forces the tree to be reloaded from the directory."), "E", dirImages+"refresh_all.gif" } ); 203 204 setMenuItem(fileMenu, fileListener, new String [] {"-", "", "", "" } ); 205 206 exit = setMenuItem(fileMenu, fileListener, 207 new String [] {CBIntText.get("Exit"), "x", CBIntText.get("Quit the JXplorer application."), "E", dirImages+"blank.gif" } ); 208 209 ButtonRegister br = JXplorer.getButtonRegister(); 210 br.registerItem(br.CONNECT, connect); 211 br.registerItem(br.DISCONNECT, disconnect); 212 br.registerItem(br.PRINT, print); 213 br.registerItem(br.REFRESH_TREE, refreshTree); 214 } 215 216 public void connect() 217 { 218 CBCache.cleanCache(); 220 if (getConnection == null) 221 { 222 getConnection = new JXOpenConWin(jxplorer, jxplorer.displayLabel, 224 JXplorer.getProperty("option.ssl.clientcerts"), 225 JXplorer.getProperty("option.ssl.cacerts"), 226 JXplorer.getProperty("option.ldap.referral"), 227 JXplorer.getProperty("option.ldap.searchAliasBehaviour")); 228 getConnection.setSize(450,340); 229 CBUtility.center(getConnection, jxplorer); 230 } 231 else 232 { 233 getConnection.reinit( JXplorer.getProperty("option.ssl.clientcerts"), 234 JXplorer.getProperty("option.ssl.cacerts"), 235 JXplorer.getProperty("option.ldap.referral"), 236 JXplorer.getProperty("option.ldap.searchAliasBehaviour")); 237 238 } 239 240 getConnection.resetTitleAndPassword(); 241 getConnection.setVisible(true); 242 } 243 244 247 248 public void setConnected(boolean searchActive) 249 { 250 editMenu.setEnabled(true); 251 searchMenu.setEnabled(searchActive); 252 toolsMenu.setEnabled(true); 253 bookmarkMenu.setEnabled(true); 254 } 255 256 public void disconnect() 257 { 258 jxplorer.disconnect(); 259 } 260 261 public void setDisconnected() 262 { 263 editMenu.setEnabled(false); 264 searchMenu.setEnabled(false); 265 toolsMenu.setEnabled(false); 266 bookmarkMenu.setEnabled(false); 267 } 268 269 public void print() 270 { 271 jxplorer.pushStatus("Printing..."); 272 jxplorer.mainViewer.print(); 273 jxplorer.popStatus(); 274 } 275 276 public void setupEditMenu(JMenu editMenu) 277 { 278 280 ActionListener editListener = new ActionListener() 281 { 282 public void actionPerformed(ActionEvent e) 283 { 284 JMenuItem item = (JMenuItem)e.getSource(); 285 286 tree = jxplorer.getActiveTree(); 287 288 if (item == cut) 289 tree.getPopupTool().cut(); 290 else if (item == copy) 291 tree.getPopupTool().copy(); 292 else if (item == paste) 293 tree.getPopupTool().paste(); 294 else if (item == delete) 295 tree.getPopupTool().delete(); 296 else if (item == rename) 297 tree.getPopupTool().rename(); 298 else if (item == copyDN) 299 tree.getPopupTool().copyDN(); 300 else if (item == newEntry) 301 tree.getPopupTool().newEntry(); 302 else if (item == pasteAlias) 303 tree.getPopupTool().pasteAlias(); 304 } 305 }; 306 307 309 newEntry = setMenuItem(editMenu, editListener, 310 new String [] {CBIntText.get("New"), "Ctrl+N", CBIntText.get("Create a new entry."), "E", dirImages+"new.gif"} ); 311 312 copyDN = setMenuItem(editMenu, editListener, 313 new String [] {CBIntText.get("Copy DN"), "Ctrl+Y", CBIntText.get("Copy the Distinguished Name of an entry to the clipboard."), "E", dirImages+"copy_dn.gif"} ); 314 315 setMenuItem(editMenu, editListener, new String [] {"-", "", "", ""} ); 316 317 cut = setMenuItem(editMenu, editListener, 318 new String [] {CBIntText.get("Cut Branch"), "Ctrl+U", CBIntText.get("Select a subtree to move."), "E", dirImages+"cut.gif"} ); 319 320 copy = setMenuItem(editMenu, editListener, 321 new String [] {CBIntText.get("Copy Branch"), "Ctrl+O", CBIntText.get("Select a subtree to copy."), "E", dirImages+"copy.gif"}); 322 323 paste = setMenuItem(editMenu, editListener, 324 new String [] {CBIntText.get("Paste Branch"), "Ctrl+P", CBIntText.get("Paste a previously selected subtree."), "E", dirImages+"paste.gif"} ); 325 326 pasteAlias = setMenuItem(editMenu, editListener, 327 new String [] {CBIntText.get("Paste Alias"), "", CBIntText.get("Paste an Alias."), "E", dirIcons+"alias.gif"} ); 328 329 setMenuItem(editMenu, editListener, new String [] {"-", "", "", ""} ); 330 331 delete = setMenuItem(editMenu, editListener, 332 new String [] {CBIntText.get("Delete"), "Ctrl+D", CBIntText.get("Delete an entry."), "E", dirImages+"delete.gif"} ); 333 334 rename = setMenuItem(editMenu, editListener, 335 new String [] {CBIntText.get("Rename"), "Ctrl+M", CBIntText.get("Rename an entry."), "E", dirImages+"rename.gif"} ); 336 337 ButtonRegister br = JXplorer.getButtonRegister(); 338 br.registerItem(br.PASTE, paste); 339 br.registerItem(br.PASTE_ALIAS, pasteAlias); 340 br.registerItem(br.COPY, copy); 341 br.registerItem(br.COPY_DN, copyDN); 342 br.registerItem(br.CUT, cut); 343 br.registerItem(br.DELETE, delete); 344 br.registerItem(br.NEW, newEntry); 345 br.registerItem(br.RENAME, rename); 346 347 br.setItemEnabled(br.PASTE, false); 348 br.setItemEnabled(br.PASTE_ALIAS, false); 349 } 350 351 public void setupLdifMenu(JMenu ldifMenu) 352 { 353 355 ActionListener ldifListener = new ActionListener() 356 { 357 public void actionPerformed(ActionEvent e) 358 { 359 JMenuItem item = (JMenuItem)e.getSource(); 360 361 SmartTree activeTree = jxplorer.getActiveTree(); 362 boolean usingSearch = (activeTree == jxplorer.searchTree); 363 364 if (item == fullExport) 365 ldifFullExport(activeTree, usingSearch); 366 else if (item == subExport) 367 ldifSubExport(activeTree, usingSearch); 368 else if (item == importFile) 369 importFile(); 370 else if (item == viewOffline) 371 viewOffline(); 372 373 jxplorer.repaint(); 374 } 375 }; 376 377 379 fullExport = setMenuItem(ldifMenu, ldifListener, 380 new String [] {CBIntText.get("Export Full Tree"), "x", CBIntText.get("Export an LDIF file of the entire tree."), "E", ""} ); 381 382 subExport = setMenuItem(ldifMenu, ldifListener, 383 new String [] {CBIntText.get("Export Subtree"), "p", CBIntText.get("Export an LDIF file of the current subtree."), "E", ""} ); 384 385 importFile = setMenuItem(ldifMenu, ldifListener, 386 new String [] {CBIntText.get("Import File"), "I", CBIntText.get("Import an LDIF file into the directory."), "E", ""} ); 387 388 viewOffline = setMenuItem(ldifMenu, ldifListener, 389 new String [] {CBIntText.get("View Offline"), "w", CBIntText.get("View an LDIF file off-Line, without adding to a directory."), "E", ""} ); 390 391 ButtonRegister br = JXplorer.getButtonRegister(); 392 br.registerItem(br.LDIF, fullExport); 393 br.registerItem(br.LDIF, subExport); 394 br.registerItem(br.LDIF, importFile); 395 } 396 397 public void ldifFullExport(SmartTree activeTree, boolean usingSearch) 398 { 399 DN base = activeTree.getRootDN(); 400 DataSource datasource = activeTree.getDataSource(); 401 LdifExport export = new LdifExport(base, datasource, jxplorer.searchTree, usingSearch, jxplorer, HelpIDs.LDIF_EXPORT_TREE); 402 export.setSize(360,120); 403 export.setTitle(CBIntText.get("Export Full Tree")); 404 CBUtility.center(export, jxplorer); 405 export.setVisible(true); 406 } 407 408 public void ldifSubExport(SmartTree activeTree, boolean usingSearch) 409 { 410 DN base = activeTree.getCurrentDN(); 411 DataSource datasource = activeTree.getDataSource(); 412 LdifExport export = new LdifExport(base, datasource, jxplorer.searchTree, usingSearch, jxplorer, HelpIDs.LDIF_EXPORT_SUBTREE); 413 export.setSize(360,120); 414 export.setTitle(CBIntText.get("Export Subtree")); 415 CBUtility.center(export, jxplorer); 416 export.setVisible(true); 417 } 418 419 public void importFile() 420 { 421 DataSource datamodifier; 422 if (jxplorer.workOffline) 423 datamodifier = (DataSource)jxplorer.offlineBroker; 424 else 425 { 426 if (jxplorer.jndiBroker.isActive()) 427 datamodifier = (DataSource)jxplorer.jndiBroker; 428 else 429 { 430 CBUtility.error(jxplorer, "Error: Not Connected! (Did You Want to 'View Offline'?)"); 431 return; 432 } 433 } 434 LdifImport imp = new LdifImport(datamodifier, jxplorer.mrTree, jxplorer, null); 435 } 436 437 public void viewOffline() 438 { 439 disconnect(); 440 jxplorer.setStatus("Working Offline"); 441 jxplorer.workOffline = true ; 442 jxplorer.offlineBroker.clear(); 443 jxplorer.mrTree.registerDataSource(jxplorer.offlineBroker); 444 jxplorer.mrTree.setRoot(new DN(SmartTree.NODATA)); 445 LdifImport imp = new LdifImport(jxplorer.offlineBroker, jxplorer.mrTree, jxplorer, null); 446 447 451 ButtonRegister br = JXplorer.getButtonRegister(); 452 br.setItemEnabled(br.LDIF, true); 453 454 } 455 456 457 458 464 465 protected void setupSearchMenu(JMenu searchMenu) 466 { 467 final SearchModel sm = new SearchModel(); 468 469 searchMenu.removeAll(); 470 471 ArrayList list = sm.getFilterNames(SearchModel.FULLNAMES); Object names[] = list.toArray(); 473 Arrays.sort(names, new SearchModel.StringComparator()); 475 ActionListener searchListener = new ActionListener() 476 { 477 public void actionPerformed(ActionEvent e) 478 { 479 JMenuItem item = (JMenuItem)e.getSource(); 480 481 if (item == search) 482 { 483 tree = jxplorer.getActiveTree(); 484 tree.openSearch(); } 486 else if (item == deleteFilter) 487 { 488 if (sm.getFilterNames(SearchModel.ALLFILTERS).size()==0) 489 { 490 JOptionPane.showMessageDialog(jxplorer, CBIntText.get("There are no filters available to delete."), CBIntText.get("Nothing to Delete"), JOptionPane.INFORMATION_MESSAGE ); 491 return; 492 } 493 else 494 { 495 DeleteFilterGUI dfg = new DeleteFilterGUI(jxplorer); dfg.setVisible(true); 497 } 498 } 499 else if (item == attrList) 500 { 501 ReturnAttributesDialog rad = new ReturnAttributesDialog(jxplorer); 502 rad.setVisible(true); 503 } 504 else 505 { 506 doSearch(item.getText(), ((myJMenuItem)item).getToolTipText()); 507 } 508 509 jxplorer.repaint(); 510 } 511 }; 512 513 search = setMenuItem(searchMenu, searchListener, 514 new String [] {CBIntText.get("Search Dialog"), "Ctrl+F", CBIntText.get("Search the directory."), "E", dirImages+"find.gif"} ); 515 516 deleteFilter = setMenuItem(searchMenu, searchListener, 517 new String [] {CBIntText.get("Delete Filter"), "", CBIntText.get("Delete an existing filter."), "E", dirImages+"delete.gif"} ); 518 519 attrList = setMenuItem(searchMenu, searchListener, 520 new String [] {CBIntText.get("Return Attribute Lists"), "", CBIntText.get("Opens a dialog that lets you manage the attributes that you wish to be returned in a search."), "E", dirImages+"return_attrs.gif"} ); 521 522 if(names.length > 0) 523 setMenuItem(searchMenu, searchListener, new String [] {"-", "", "", "", ""} ); 524 525 ButtonRegister br = JXplorer.getButtonRegister(); 526 br.registerItem(br.SEARCH, search); 527 528 String [] searchValues = new String [names.length]; 529 String [] searchNames = new String [names.length]; 530 531 for(int i=0; i<names.length;i++) 532 { 533 String key = names[i].toString(); 534 searchNames[i] = key; 535 searchValues[i] = sm.getLDAPFilter(searchNames[i]); 536 searchNames[i] = searchNames[i].startsWith("JXFilter") ? searchNames[i].substring(9) : searchNames[i].substring(13); } 538 539 if (names.length>15) { 541 searchMenu.add(getScrollList(searchNames, searchValues, searchMenu)); 542 } 543 else 544 { 545 for(int i=0;i<names.length;i++) 546 { 547 myJMenuItem searchMenuItem = new myJMenuItem(searchNames[i]); 548 searchMenuItem.name = searchValues[i]; 549 setMenuItem(searchMenu, searchMenuItem, searchListener, new String [] {"", "", searchValues[i], "E", ""}); 550 } 551 } 552 } 553 554 555 556 562 563 public void doSearch(String name, String filter) 564 { 565 SearchModel sm = new SearchModel(); 566 567 String baseDN = sm.getValue(name+"."+SearchModel.BASEDN); 569 DN dn = (baseDN==null) ? jxplorer.getActiveTree().getCurrentDN() : new DN(baseDN); 570 571 int searchLevel = 2; 573 try 574 { 575 searchLevel = Integer.parseInt(sm.getValue(name+"."+SearchModel.SEARCHLEVEL)); 576 } 577 catch(NumberFormatException e) 578 { 579 searchLevel = 2; 580 } 581 582 String retAttrs = sm.getValue(name+"."+SearchModel.RETATTRS); 584 String [] retAttrsList = null; 585 586 if (retAttrs == null) { 588 retAttrsList = new String [] {"objectClass"}; 589 } 590 else if (retAttrs.equalsIgnoreCase(ReturnAttributesDialog.DEFAULT_RETURN_ATTRS)) { 592 retAttrs = null; 593 } 594 else { 596 retAttrsList = ReturnAttributesDialog.getReturnAttributes(retAttrs); 597 sm.openRetAttrDisplay(jxplorer, retAttrsList, (jxplorer.getSearchTree()).getDataSource()); 598 } 599 600 String find = name+"."+SearchModel.FIND; 602 String search = name+"."+SearchModel.SEARCH; 603 604 String aliasOption = "always"; 605 606 if (search.equalsIgnoreCase("false") && find.equalsIgnoreCase("false")) 607 aliasOption = "never"; 608 else if (search.equalsIgnoreCase("true") && find.equalsIgnoreCase("false")) 609 aliasOption = "searching"; 610 else if (search.equalsIgnoreCase("false") && find.equalsIgnoreCase("true")) 611 aliasOption = "finding"; 612 613 log.info("Setting search alias option to: ["+aliasOption+"]"); 614 JXplorer.setProperty("option.ldap.searchAliasBehaviour", aliasOption); 615 616 SearchExecute.run(jxplorer.getSearchTree(), 618 dn, 619 filter, 620 retAttrsList, 621 searchLevel, 622 jxplorer.getSearchBroker()); 623 624 jxplorer.getTreeTabPane().setSelectedComponent(jxplorer.getResultsPanel()); 626 } 627 628 629 630 634 635 public void setSearchEnabled(boolean state) 636 { 637 if(searchMenu==null) 638 return; 639 640 int items = searchMenu.getItemCount(); 641 642 for(int i=0;i<items;i++) 643 { 644 JMenuItem temp = searchMenu.getItem(i); 645 646 if(temp instanceof myJMenuItem) 647 temp.setEnabled(state); 648 } 649 searchMenu.repaint(); 650 } 651 652 653 654 657 658 public void updateSearchMenu() 659 { 660 setupSearchMenu(searchMenu); 661 } 662 663 664 665 672 673 protected JScrollPane getScrollList(Object [] items, String [] toolTips, JMenu menuType) 674 { 675 final Object [] names = items; 676 final String [] toolTps = toolTips; 677 final JMenu type = menuType; 678 679 final JList list = new JList(names) 680 { 681 public String getToolTipText(MouseEvent e) { 683 int index = locationToIndex(e.getPoint()); 684 if (-1 < index) 685 return toolTps[index]; 686 else 687 return null; 688 } 689 }; 690 list.setToolTipText(""); 691 list.setBackground(Color.lightGray); 692 693 list.addListSelectionListener(new ListSelectionListener (){ 694 public void valueChanged(ListSelectionEvent e){ 695 if (e.getSource() == list && !e.getValueIsAdjusting()) { 697 if (type==searchMenu) { 699 doSearch(names[list.getSelectedIndex()].toString(), toolTps[list.getSelectedIndex()]); 700 searchMenu.getPopupMenu().setVisible(false); searchMenu.setSelected(false); 704 } 705 else if (type==bookmarkMenu) { 707 jxplorer.getTreeTabPane().setSelectedIndex(0); 708 goToBookmark(toolTps[list.getSelectedIndex()].toString(), jxplorer.getActiveTree()); 709 bookmarkMenu.getPopupMenu().setVisible(false); bookmarkMenu.setSelected(false); 711 } 712 } 713 }}); 714 715 JScrollPane sp = new JScrollPane(list); 716 sp.setPreferredSize(new Dimension(100, 300)); 717 sp.setMinimumSize(new Dimension(100, 300)); 718 sp.setAlignmentX(LEFT_ALIGNMENT); 719 720 return sp; 721 } 722 723 724 725 731 732 protected void setupBookmarkMenu(JMenu bookmarkMenu) 733 { 734 bookmarkMenu.removeAll(); 735 736 ActionListener bookmarkListener = new ActionListener() 737 { 738 public void actionPerformed(ActionEvent e) 739 { 740 JMenuItem item = (JMenuItem)e.getSource(); 741 742 jxplorer.getTreeTabPane().setSelectedIndex(0); 743 744 tree = jxplorer.getActiveTree(); 745 746 if (item == editBookmark) 747 tree.openEditBookmarkDialog(); 748 else if (item == addBookmark) 749 tree.openAddBookmarkDialog(jxplorer.mrTree.getCurrentDN()); 750 else if (item == deleteBookmark) 751 tree.openDeleteBookmarkDialog(); 752 else 753 goToBookmark(((myJMenuItem)item).name, tree); 754 755 jxplorer.repaint(); 756 } 757 }; 758 759 addBookmark = setMenuItem(bookmarkMenu, bookmarkListener, 760 new String [] {CBIntText.get("Add Bookmark"), "Ctrl+B", CBIntText.get("Add a bookmark from the current DN."), "E", dirImages+"plus.gif"} ); 761 762 deleteBookmark = setMenuItem(bookmarkMenu, bookmarkListener, 763 new String [] {CBIntText.get("Delete Bookmark"),"d", CBIntText.get("Delete a bookmark."), "E", dirImages+"delete.gif"} ); 764 765 editBookmark = setMenuItem(bookmarkMenu, bookmarkListener, 766 new String [] {CBIntText.get("Edit Bookmark"),"i", CBIntText.get("Edit your bookmarks."), "E", dirImages+"edit.gif"} ); 767 768 769 ButtonRegister br = JXplorer.getButtonRegister(); 770 br.registerItem(br.BOOKMARKS, addBookmark); 771 772 Properties propertyList = CBUtility.readPropertyFile("bookmarks.txt"); 773 774 DXNamingEnumeration keys = new DXNamingEnumeration(propertyList.keys()); 775 776 if(keys.size() > 0) 777 setMenuItem(bookmarkMenu, bookmarkListener, new String [] {"-", "", "", "", ""} ); 778 779 Hashtable bookmarkTable = new Hashtable(); 780 781 while (keys.hasMoreElements()) 782 { 783 String key = keys.nextElement().toString(); 784 if (key.toLowerCase().startsWith("dn")) 785 bookmarkTable.put(key.substring(key.indexOf(".")+1), propertyList.getProperty(key)); 786 } 787 788 DXNamingEnumeration en = new DXNamingEnumeration(bookmarkTable.keys()); 789 en.sort(); 790 791 int size = en.size(); 792 793 String [] bookmarkVals = new String [size]; 794 String [] bookmarkNams = new String [size]; 795 796 int j=0; 797 while(en.hasMore()) 798 { 799 bookmarkNams[j] = (String )en.next(); 800 bookmarkVals[j] = (String )bookmarkTable.get(bookmarkNams[j]); 801 j++; 802 } 803 804 if (size>15) 805 { 806 bookmarkMenu.add(getScrollList(bookmarkNams, bookmarkVals, bookmarkMenu)); 807 } 808 else 809 { 810 for(int i=0; i<bookmarkVals.length; i++) 811 { 812 myJMenuItem bookmarkMenuItem = new myJMenuItem(bookmarkNams[i]); 813 bookmarkMenuItem.name = bookmarkVals[i]; 814 setMenuItem(bookmarkMenu, bookmarkMenuItem, bookmarkListener, new String [] {"", "", "Go to: " + bookmarkVals[i]+".", "E", ""}); 815 } 816 } 817 } 818 819 820 821 826 827 public void setBookmarksEnabled(boolean state) 828 { 829 if(bookmarkMenu==null) 830 return; 831 832 int items = bookmarkMenu.getItemCount(); 833 834 for(int i=0;i<items;i++) 835 { 836 JMenuItem temp = bookmarkMenu.getItem(i); 837 838 if(temp instanceof myJMenuItem) 839 temp.setEnabled(state); 840 } 841 bookmarkMenu.repaint(); 842 } 843 844 845 846 850 851 public class myJMenuItem extends JMenuItem 852 { 853 854 855 public String name; 856 857 858 861 862 public myJMenuItem(String s) { super(s); } 863 } 864 865 866 867 870 871 public void updateBookmarkMenu() 872 { 873 setupBookmarkMenu(bookmarkMenu); 874 } 875 876 877 878 886 887 public void goToBookmark(String dn, SmartTree tree) 888 { 889 tree.readAndExpandDN(new DN(dn)); 890 } 891 892 893 894 898 protected void setupLookAndFeelMenu(JMenu lookAndFeelMenu) 899 { 900 String status = ("false".equals(JXplorer.getProperty("gui.buttonbar")))?"U":"C"; 901 setCheckBoxMenu(lookAndFeelMenu, new String [][] {{CBIntText.get("Show Button Bar"),"B", CBIntText.get("Display the shortcut button toolbar."), "E", status, dirImages+"blank.gif"}}, 902 new ActionListener() 903 { 904 public void actionPerformed(ActionEvent e) 905 { 906 boolean selected = ((JCheckBoxMenuItem)e.getSource()).isSelected(); 907 jxplorer.buttonBar.setVisible(selected); 908 jxplorer.repaint(); 909 JXplorer.setProperty("gui.buttonbar", String.valueOf(selected)); 910 } 911 } 912 ); 913 914 915 status = ("false".equals(JXplorer.getProperty("gui.searchbar")))?"U":"C"; 916 917 setCheckBoxMenu(lookAndFeelMenu, new String [][] {{CBIntText.get("Show Search Bar"),"w", CBIntText.get("Show the quick search tool bar."), "E", status, dirImages+"blank.gif"}}, 918 new ActionListener() 919 { 920 public void actionPerformed(ActionEvent e) 921 { 922 boolean selected = ((JCheckBoxMenuItem)e.getSource()).isSelected(); 923 jxplorer.searchBar.setVisible(selected); 924 jxplorer.repaint(); 925 JXplorer.setProperty("gui.searchbar", String.valueOf(selected)); 926 } 927 } 928 ); 929 930 ActionListener viewListener = new ActionListener() 931 { 932 public void actionPerformed(ActionEvent e) 933 { 934 JMenuItem item = (JMenuItem)e.getSource(); 935 936 tree = jxplorer.getActiveTree(); 937 938 if (item == refresh) 939 tree.getPopupTool().refresh(); 940 941 jxplorer.repaint(); 942 } 943 }; 944 945 setMenuItem(lookAndFeelMenu, viewListener, new String [] {"-", "", "", "", ""} ); 946 947 refresh = setMenuItem(lookAndFeelMenu, viewListener, 948 new String [] {CBIntText.get("Refresh"), "Ctrl+R",CBIntText.get("Refreshes an Entry."), "E", dirImages+"refresh.gif"} ); 949 950 ButtonRegister br = JXplorer.getButtonRegister(); 951 br.registerItem(br.REFRESH, refresh); 952 } 953 954 955 956 962 protected void setupOptionsMenu(JMenu optionsMenu) 963 { 964 966 967 969 975 976 class PropertyCheckBoxMenuItem extends JCheckBoxMenuItem 977 { 978 final String propName; 979 980 public PropertyCheckBoxMenuItem(String s, String propertyName) 981 { 982 super(CBIntText.get(s), true); propName = propertyName; 984 985 addActionListener(new ActionListener() { 986 public void actionPerformed(ActionEvent e) { 987 JXplorer.myProperties.setProperty(propName, String.valueOf(getState())); 988 jxplorer.repaint(); 989 } 990 }); 991 } 992 993 public void paint(Graphics g) 995 { boolean state = !("false".equalsIgnoreCase(JXplorer.myProperties.getProperty(propName))); 997 if (state != getState()) setState(state); super.paint(g); 999 } 1000 } 1001 1002 final PropertyCheckBoxMenuItem confirmOps; 1003 final PropertyCheckBoxMenuItem confirmTableEditorUpdates; 1004 final PropertyCheckBoxMenuItem checkSchema; 1005 final JCheckBoxMenuItem browserSearchAliases; 1006 1007 confirmOps = 1008 new PropertyCheckBoxMenuItem(CBIntText.get("Confirm Tree Operations"), "option.confirmTreeOperations"); 1009 setMenuItemState(optionsMenu, confirmOps, "C", CBIntText.get("Prompt the user whenever the tree will be modified?"), true); 1010 1011 confirmTableEditorUpdates = 1012 new PropertyCheckBoxMenuItem(CBIntText.get("Confirm Table Editor Updates"), "option.confirmTableEditorUpdates"); 1013 setMenuItemState(optionsMenu, confirmTableEditorUpdates, "T", CBIntText.get("Display message to confirm successful updates in Table Editor?"), true); 1014 1015 checkSchema = 1016 new PropertyCheckBoxMenuItem(CBIntText.get("Ignore Schema Checking"), "option.ignoreSchemaOnSubmission"); 1017 setMenuItemState(optionsMenu, checkSchema, "g", CBIntText.get("Don't check entry consistency before submission."), true); 1018 1019 browserSearchAliases = 1020 new JCheckBoxMenuItem(CBIntText.get("Resolve Aliases while Browsing")); 1021 setMenuItemState(optionsMenu, browserSearchAliases, "A", CBIntText.get("Whether to browse the referenced object, or the alias entry itself."), true); 1022 browserSearchAliases.setState("finding".equals(JXplorer.getProperty("option.ldap.browseAliasBehaviour"))); 1023 1024 ActionListener optionsListener = new ActionListener() 1026 { 1027 public void actionPerformed(ActionEvent e) 1028 { 1029 JMenuItem item = (JMenuItem)e.getSource(); 1030 1031 if (item == advancedOptions) 1032 { 1033 setUpAdvancedOptions(); } 1035 jxplorer.repaint(); 1036 } 1037 }; 1038 1039 advancedOptions = setMenuItem(optionsMenu, optionsListener, 1040 new String [] {CBIntText.get("Advanced Options"), "d", CBIntText.get("Open the Advanced Options dialog."), "E", ""} ); 1041 1042 browserSearchAliases.addActionListener(new ActionListener() { 1044 public void actionPerformed(ActionEvent e) { 1045 try 1046 { 1047 if (browserSearchAliases.isSelected()) 1048 { 1049 JXplorer.setProperty("option.ldap.browseAliasBehaviour", "finding"); 1050 if (jxplorer.jndiBroker.getDirContext() != null) 1051 { 1052 jxplorer.jndiBroker.getDirContext().addToEnvironment("java.naming.ldap.derefAliases", "finding"); 1053 } 1055 } 1056 else 1057 { 1058 JXplorer.setProperty("option.ldap.browseAliasBehaviour", "never"); 1059 if (jxplorer.jndiBroker.getDirContext() != null) 1060 { 1061 jxplorer.jndiBroker.getDirContext().addToEnvironment("java.naming.ldap.derefAliases", "never"); 1062 } 1064 } 1065 } 1066 catch (Exception e2) {} } 1068 }); 1069 } 1070 1071 1072 1073 1079 1080 protected void setUpAdvancedOptions() 1081 { 1082 AdvancedOptions adOpt = new AdvancedOptions(jxplorer, this); 1083 CBUtility.center(adOpt, jxplorer); 1084 adOpt.setVisible(true); 1085 } 1086 1087 1088 protected void setupSSLMenu(JMenu sslMenu) 1089 { 1090 ActionListener sslListener = new ActionListener() 1091 { 1092 public void actionPerformed(ActionEvent e) 1093 { 1094 JMenuItem item = (JMenuItem)e.getSource(); 1095 1096 if (item == simpleSSL) 1097 { 1098 KeystoreGUI win = new KeystoreGUI(jxplorer, JXplorer.getMyProperties(), 1099 JXplorer.getProperty(JXplorer.CA_PATH_PROPERTY), 1100 null, 1101 JXplorer.getProperty(JXplorer.CA_TYPE_PROPERTY), 1102 CBIntText.get("Manage Your Trusted Server Certificates."), 1103 false, HelpIDs.SSL_CERTS); 1104 win.setSize(450,320); 1105 CBUtility.center(win, jxplorer); 1106 win.setVisible(true); } 1108 else if (item == authSSL) 1109 { 1110 KeystoreGUI win = new KeystoreGUI(jxplorer, JXplorer.getMyProperties(), 1111 JXplorer.getProperty(JXplorer.CLIENT_PATH_PROPERTY), 1112 null, 1113 JXplorer.getProperty(JXplorer.CLIENT_TYPE_PROPERTY), 1114 CBIntText.get("Manage Your Own Private Keys and Certificates."), 1115 true, HelpIDs.SSL_CERTS); 1116 win.setSize(450,440); 1117 CBUtility.center(win, jxplorer); 1118 win.setVisible(true); } 1120 1121 1124 1125 else if (item == keystoreOptions) 1126 { 1127 KeystoreOptions options = new KeystoreOptions(jxplorer, JXplorer.getMyProperties()); 1128 options.setSize(530,260); 1129 CBUtility.center(options, jxplorer); 1130 options.setVisible(true); 1131 } 1132 jxplorer.repaint(); 1133 } 1134 }; 1135 1136 simpleSSL = setMenuItem(sslMenu, sslListener, 1137 new String [] {CBIntText.get("Trusted Servers and CAs"),"u", 1138 CBIntText.get("Setup which servers you trust for SSL."), 1139 "E", dirImages+"sslcert.gif"} ); 1141 authSSL = setMenuItem(sslMenu, sslListener, 1142 new String [] {CBIntText.get("Client Certificates"),"C", 1143 CBIntText.get("Setup client authentication (if available)."), 1144 ("none".equals(JXplorer.getProperty("authprovider"))?"D":"E"), dirImages+"sslkeycert.gif"} ); 1145 1146 keystoreOptions = setMenuItem(sslMenu, sslListener, 1147 new String [] {CBIntText.get("Advanced Keystore Options"),"K", 1148 CBIntText.get("Select your keystore locations and the type of keystore to use."), 1149 "E", dirImages+"blankRec.gif"} ); 1150 1151 } 1152 1153 1154 protected void setupToolsMenu(JMenu toolsMenu) 1155 { 1156 String [][] toolsMenuItems = 1157 { {CBIntText.get("Stop Action"),"A", CBIntText.get("Stop the currently executing browser action."), "E", dirImages+"stop.gif"} }; 1158 1159 setMenu(toolsMenu, toolsMenuItems, new ActionListener() 1160 { 1161 public void actionPerformed(ActionEvent e) 1162 { 1163 String cmd = ((JMenuItem)e.getSource()).getName(); 1164 1165 if (cmd.equals(CBIntText.get("Stop Action"))) 1166 { 1167 jxplorer.getStopMonitor().show(); 1168 } 1169 jxplorer.repaint(); 1170 } 1171 }); 1172 1173 jxplorer.getStopMonitor().addWatcher(toolsMenu.getItem(0)); 1176 } 1177 1178 1179 protected void setupHelpMenu(JMenu helpMenu) 1180 { 1181 ActionListener helpListener = new ActionListener() 1182 { 1183 public void actionPerformed(ActionEvent e) 1184 { 1185 JMenuItem item = (JMenuItem)e.getSource(); 1186 1187 if (jxplorer.helpSystem == null && item != helpAbout) { CBUtility.error(jxplorer, "Unable to open Help System", null); 1190 return; 1191 } 1192 1193 if (item == helpContents) 1194 jxplorer.helpSystem.openTab(HelpIDs.TAB_TOC); else if (item == helpSearch) jxplorer.helpSystem.openTab(HelpIDs.TAB_SEARCH); 1197 else if (item == helpAbout) 1198 showAboutMessage(); 1199 1200 jxplorer.repaint(); 1201 } 1202 }; 1203 1204 helpContents = setMenuItem(helpMenu, helpListener, 1205 new String [] {CBIntText.get("Contents"), "C", CBIntText.get("Display the help index."), "E", dirImages+"content.gif" } ); 1206 1207 helpSearch = setMenuItem(helpMenu, helpListener, 1208 new String [] {CBIntText.get("Search"), "r", CBIntText.get("Search help for a keyword."), "E", dirImages+"search.gif" } ); 1209 1210 setMenuItem(helpMenu, helpListener, new String [] {"-", "", "", "", "" } ); 1212 helpAbout = setMenuItem(helpMenu, helpListener, 1213 new String [] {CBIntText.get("About"), "A", CBIntText.get("General information about JXplorer."), "E", dirImages+"about.gif" } ); 1214 1215 1216 1217 } 1218 1219 1223 public void showAboutMessage() 1224 { 1225 File licence = new File (System.getProperty("user.dir") + File.separator + "licence.txt"); 1227 if (licence.exists()) 1228 { 1229 String textBody = JXplorer.version+"\n\nCopyright \u00a9 2005 CA. All rights reserved."; 1230 1231 try 1232 { 1233 textBody = CBUtility.readTextFile(licence); 1234 textBody = JXplorer.version + "\n" + 1235 "\nWritten by: Chris Betts" + 1236 "\n Trudi Ersvaer\n" + 1237 "\nThanks to: Jason Paul" + 1238 "\n Lachlan O'Dea" + 1239 "\n Van Bui\n\n\n" + 1240 textBody; 1241 1242 } 1243 catch (IOException e) {} 1245 CBAbout about = new CBAbout(jxplorer, textBody, new ImageIcon(dirTemplates + "JXAboutBottom.gif"), 1246 new ImageIcon(dirTemplates + "JXAboutTop.gif"), CBIntText.get("OK"), CBIntText.get("Close this window"), CBIntText.get("About JXplorer")); 1247 1248 about.setSize(477, 350); 1249 about.setResizable(true); 1250 CBUtility.center(about, jxplorer); 1251 about.setVisible(true); 1252 } 1253 else 1254 { 1255 1271 } 1272 } 1273 1274 1275 1276 1289 1290 protected void setMenu(JMenu menu, String [][] menuItems, ActionListener listener) 1291 { 1292 for (int i=0;i<menuItems.length;i++) 1293 { 1294 JMenuItem item = setMenuItem(menu, listener, menuItems[i]); 1295 } 1296 } 1297 1298 1305 1306 protected JMenuItem setMenuItem(JMenu menu, ActionListener listener, String [] menuItems) 1307 { 1308 if (menuItems[0].equals("-")) 1309 { 1310 menu.add(new JSeparator()); 1311 return null; 1312 } 1313 else 1314 { 1315 JMenuItem item = new JMenuItem(CBIntText.get(menuItems[0]), new ImageIcon(menuItems[4])); 1316 item.setName(menuItems[0]); return setMenuItem(menu, item, listener, menuItems); 1318 } 1319 } 1320 1321 1322 1329 1330 protected JMenuItem setMenuItem(JMenu menu, JMenuItem item, ActionListener listener, String [] menuItems) 1331 { 1332 1334 setMenuItemState(menu, item, menuItems[1], menuItems[2], (menuItems[3].charAt(0)=='E')); 1335 if (listener != null) item.addActionListener(listener); 1336 return item; 1337 } 1338 1339 1350 1351 protected void setCheckBoxMenu(JMenu menu, String [][] menuItems, ActionListener listener) 1352 { 1353 for (int i=0;i<menuItems.length;i++) 1354 { 1355 if (menuItems[i][0].equals("-")) 1356 menu.add(new JSeparator()); 1357 else 1358 { 1359 JCheckBoxMenuItem tmp = new JCheckBoxMenuItem(menuItems[i][0], new ImageIcon(menuItems[i][5]), (menuItems[i][4].charAt(0)=='C')); 1360 setMenuItemState(menu, tmp, menuItems[i][1], menuItems[i][2], (menuItems[i][3].charAt(0)=='E')); 1361 if (listener != null) tmp.addActionListener(listener); 1362 } 1363 } 1364 } 1365 1366 1375 1376 protected void setMenuItemState(JMenu menu, JMenuItem menuItem, String mnemonic, String toolTipText, boolean enabled) 1377 { 1378 if (mnemonic.length()==1) 1379 { 1380 menuItem.setMnemonic(mnemonic.charAt(0)); 1381 } 1382 else if (mnemonic.startsWith("Cnt")||mnemonic.startsWith("cnt")||mnemonic.startsWith("Ctr")||mnemonic.startsWith("ctr")) 1383 { 1384 char C = mnemonic.charAt(mnemonic.length()-1); 1385 menuItem.setAccelerator(KeyStroke.getKeyStroke(C, java.awt.Event.CTRL_MASK, false)); 1386 } 1387 menuItem.setToolTipText(toolTipText); 1388 menuItem.setEnabled(enabled); 1389 menu.add(menuItem); 1390 } 1391 1392 1393 1394 1397 1398 public void setImageDirs() 1399 { 1400 dirImages = JXplorer.getProperty("dir.images"); 1401 dirIcons = JXplorer.getProperty("dir.icons"); 1402 dirTemplates = JXplorer.getProperty("dir.templates"); 1403 } 1404} | Popular Tags |