/**
   * Creates all the items located in the Search submenu and associate all the menu items with their
   * appropriate functions.
   *
   * @param menuBar Menu the <code>Menu</code> that file contain the Search submenu.
   */
  private void createSearchMenu(Menu menuBar) {
    // Search menu.
    MenuItem item = new MenuItem(menuBar, SWT.CASCADE);
    item.setText(resMessages.getString("Search_menu_title"));
    Menu searchMenu = new Menu(shell, SWT.DROP_DOWN);
    item.setMenu(searchMenu);

    // Search -> Find...
    item = new MenuItem(searchMenu, SWT.NULL);
    item.setText(resMessages.getString("Find"));
    item.setAccelerator(SWT.MOD1 + 'F');
    item.addSelectionListener(
        new SelectionAdapter() {
          public void widgetSelected(SelectionEvent e) {
            searchDialog.setMatchCase(false);
            searchDialog.setMatchWord(false);
            searchDialog.setSearchDown(true);
            searchDialog.setSearchString("");
            searchDialog.setSelectedSearchArea(0);
            searchDialog.open();
          }
        });

    // Search -> Find Next
    item = new MenuItem(searchMenu, SWT.NULL);
    item.setText(resMessages.getString("Find_next"));
    item.setAccelerator(SWT.F3);
    item.addSelectionListener(
        new SelectionAdapter() {
          public void widgetSelected(SelectionEvent e) {
            searchDialog.open();
          }
        });
  }
예제 #2
0
  /**
   * Creates all the items located in the Edit submenu and associate all the menu items with their
   * appropriate functions.
   *
   * @param menuBar Menu the <code>Menu</code> that file contain the Edit submenu.
   * @see #createSortMenu()
   */
  private MenuItem createEditMenu(Menu menuBar) {
    // Edit menu.
    MenuItem item = new MenuItem(menuBar, SWT.CASCADE);
    item.setText(resAddressBook.getString("Edit_menu_title"));
    Menu menu = new Menu(shell, SWT.DROP_DOWN);
    item.setMenu(menu);

    /** Add a listener to handle enabling and disabling some items in the Edit submenu. */
    menu.addMenuListener(
        new MenuAdapter() {
          @Override
          public void menuShown(MenuEvent e) {
            Menu menu = (Menu) e.widget;
            MenuItem[] items = menu.getItems();
            int count = table.getSelectionCount();
            items[0].setEnabled(count != 0); // edit
            items[1].setEnabled(count != 0); // copy
            items[2].setEnabled(copyBuffer != null); // paste
            items[3].setEnabled(count != 0); // delete
            items[5].setEnabled(table.getItemCount() != 0); // sort
          }
        });

    // Edit -> Edit
    MenuItem subItem = new MenuItem(menu, SWT.PUSH);
    subItem.setText(resAddressBook.getString("Edit"));
    subItem.setAccelerator(SWT.MOD1 + 'E');
    subItem.addSelectionListener(
        new SelectionAdapter() {
          @Override
          public void widgetSelected(SelectionEvent e) {
            TableItem[] items = table.getSelection();
            if (items.length == 0) return;
            editEntry(items[0]);
          }
        });

    // Edit -> Copy
    subItem = new MenuItem(menu, SWT.NONE);
    subItem.setText(resAddressBook.getString("Copy"));
    subItem.setAccelerator(SWT.MOD1 + 'C');
    subItem.addSelectionListener(
        new SelectionAdapter() {
          @Override
          public void widgetSelected(SelectionEvent e) {
            TableItem[] items = table.getSelection();
            if (items.length == 0) return;
            copyBuffer = new String[table.getColumnCount()];
            for (int i = 0; i < copyBuffer.length; i++) {
              copyBuffer[i] = items[0].getText(i);
            }
          }
        });

    // Edit -> Paste
    subItem = new MenuItem(menu, SWT.NONE);
    subItem.setText(resAddressBook.getString("Paste"));
    subItem.setAccelerator(SWT.MOD1 + 'V');
    subItem.addSelectionListener(
        new SelectionAdapter() {
          @Override
          public void widgetSelected(SelectionEvent e) {
            if (copyBuffer == null) return;
            TableItem item = new TableItem(table, SWT.NONE);
            item.setText(copyBuffer);
            isModified = true;
          }
        });

    // Edit -> Delete
    subItem = new MenuItem(menu, SWT.NONE);
    subItem.setText(resAddressBook.getString("Delete"));
    subItem.addSelectionListener(
        new SelectionAdapter() {
          @Override
          public void widgetSelected(SelectionEvent e) {
            TableItem[] items = table.getSelection();
            if (items.length == 0) return;
            items[0].dispose();
            isModified = true;
          }
        });

    new MenuItem(menu, SWT.SEPARATOR);

    // Edit -> Sort(Cascade)
    subItem = new MenuItem(menu, SWT.CASCADE);
    subItem.setText(resAddressBook.getString("Sort"));
    Menu submenu = createSortMenu();
    subItem.setMenu(submenu);

    return item;
  }
예제 #3
0
  /**
   * Creates all the items located in the File submenu and associate all the menu items with their
   * appropriate functions.
   *
   * @param menuBar Menu the <code>Menu</code> that file contain the File submenu.
   */
  private void createFileMenu(Menu menuBar) {
    // File menu.
    MenuItem item = new MenuItem(menuBar, SWT.CASCADE);
    item.setText(resAddressBook.getString("File_menu_title"));
    Menu menu = new Menu(shell, SWT.DROP_DOWN);
    item.setMenu(menu);
    /** Adds a listener to handle enabling and disabling some items in the Edit submenu. */
    menu.addMenuListener(
        new MenuAdapter() {
          @Override
          public void menuShown(MenuEvent e) {
            Menu menu = (Menu) e.widget;
            MenuItem[] items = menu.getItems();
            items[1].setEnabled(table.getSelectionCount() != 0); // edit contact
            items[5].setEnabled((file != null) && isModified); // save
            items[6].setEnabled(table.getItemCount() != 0); // save as
          }
        });

    // File -> New Contact
    MenuItem subItem = new MenuItem(menu, SWT.NONE);
    subItem.setText(resAddressBook.getString("New_contact"));
    subItem.setAccelerator(SWT.MOD1 + 'N');
    subItem.addSelectionListener(
        new SelectionAdapter() {
          @Override
          public void widgetSelected(SelectionEvent e) {
            newEntry();
          }
        });
    subItem = new MenuItem(menu, SWT.NONE);
    subItem.setText(resAddressBook.getString("Edit_contact"));
    subItem.setAccelerator(SWT.MOD1 + 'E');
    subItem.addSelectionListener(
        new SelectionAdapter() {
          @Override
          public void widgetSelected(SelectionEvent e) {
            TableItem[] items = table.getSelection();
            if (items.length == 0) return;
            editEntry(items[0]);
          }
        });

    new MenuItem(menu, SWT.SEPARATOR);

    // File -> New Address Book
    subItem = new MenuItem(menu, SWT.NONE);
    subItem.setText(resAddressBook.getString("New_address_book"));
    subItem.setAccelerator(SWT.MOD1 + 'B');
    subItem.addSelectionListener(
        new SelectionAdapter() {
          @Override
          public void widgetSelected(SelectionEvent e) {
            if (closeAddressBook()) {
              newAddressBook();
            }
          }
        });

    // File -> Open
    subItem = new MenuItem(menu, SWT.NONE);
    subItem.setText(resAddressBook.getString("Open_address_book"));
    subItem.setAccelerator(SWT.MOD1 + 'O');
    subItem.addSelectionListener(
        new SelectionAdapter() {
          @Override
          public void widgetSelected(SelectionEvent e) {
            if (closeAddressBook()) {
              openAddressBook();
            }
          }
        });

    // File -> Save.
    subItem = new MenuItem(menu, SWT.NONE);
    subItem.setText(resAddressBook.getString("Save_address_book"));
    subItem.setAccelerator(SWT.MOD1 + 'S');
    subItem.addSelectionListener(
        new SelectionAdapter() {
          @Override
          public void widgetSelected(SelectionEvent e) {
            save();
          }
        });

    // File -> Save As.
    subItem = new MenuItem(menu, SWT.NONE);
    subItem.setText(resAddressBook.getString("Save_book_as"));
    subItem.setAccelerator(SWT.MOD1 + 'A');
    subItem.addSelectionListener(
        new SelectionAdapter() {
          @Override
          public void widgetSelected(SelectionEvent e) {
            saveAs();
          }
        });

    new MenuItem(menu, SWT.SEPARATOR);

    // File -> Exit.
    subItem = new MenuItem(menu, SWT.NONE);
    subItem.setText(resAddressBook.getString("Exit"));
    subItem.addSelectionListener(
        new SelectionAdapter() {
          @Override
          public void widgetSelected(SelectionEvent e) {
            shell.close();
          }
        });
  }