示例#1
0
 public static void main(String[] args) {
   Display display = Display.getDefault();
   Shell shell = new Shell(display);
   @SuppressWarnings("unused")
   MainWindow inst = new MainWindow(shell, SWT.NULL);
   shell.setLayout(new FillLayout());
   shell.setImage(SWTResourceManager.getImage("images/16x16.png"));
   shell.setText("Change This Title");
   shell.setBackgroundImage(SWTResourceManager.getImage("images/ToolbarBackground.gif"));
   shell.layout();
   shell.open();
   while (!shell.isDisposed()) {
     if (!display.readAndDispatch()) display.sleep();
   }
 }
 /**
  * Opens the dialog and returns the input
  *
  * @return String
  */
 public String open() {
   // Create the dialog window
   Shell shell = new Shell(getParent(), getStyle());
   shell.setText(getText());
   shell.setImage(UIUtils.getImageRegistry().get("sfdc_icon")); // $NON-NLS-1$
   createContents(shell);
   shell.pack();
   shell.open();
   Display display = getParent().getDisplay();
   while (!shell.isDisposed()) {
     if (!display.readAndDispatch()) {
       display.sleep();
     }
   }
   // Return the entered value, or null
   return input;
 }
  public Shell open(Display display) {

    // Window dressing - the icon
    windowIcon =
        new Image(display, getClass().getClassLoader().getResourceAsStream("icons/joanju.gif"));

    shell = new Shell(display);
    shell.setLayout(new FillLayout());
    shell.addShellListener(
        new ShellAdapter() {
          public void shellClosed(ShellEvent e) {
            e.doit = closeAddressBook();
          }
        });

    shell.setImage(windowIcon);

    createMenuBar();

    searchDialog = new SearchDialog(shell);
    searchDialog.setSearchAreaNames(columnNames);
    searchDialog.setSearchAreaLabel(resMessages.getString("Column"));
    searchDialog.addFindListener(
        new FindListener() {
          public boolean find() {
            return findEntry();
          }
        });

    table = new Table(shell, SWT.SINGLE | SWT.BORDER | SWT.FULL_SELECTION);
    table.setHeaderVisible(true);
    table.setMenu(createPopUpMenu());
    table.addSelectionListener(
        new SelectionAdapter() {
          public void widgetDefaultSelected(SelectionEvent e) {
            TableItem[] items = table.getSelection();
            if (items.length > 0) launchEditor(items[0]);
          }
        });
    int[] widths = {150, 50, 200, 200};
    for (int i = 0; i < columnNames.length; i++) {
      TableColumn column = new TableColumn(table, SWT.NONE);
      column.setText(columnNames[i]);
      column.setWidth(widths[i]);
      final int columnIndex = i;
      column.addSelectionListener(
          new SelectionAdapter() {
            public void widgetSelected(SelectionEvent e) {
              sort(columnIndex);
            }
          });
    }

    newAddressBook();

    shell.addDisposeListener(
        new DisposeListener() {
          public void widgetDisposed(DisposeEvent e) {
            windowIcon.dispose();
          }
        });

    shell.setSize(table.computeSize(SWT.DEFAULT, SWT.DEFAULT).x, 300);
    shell.open();
    return shell;
  }