Esempio n. 1
0
 public static void main(String[] args) {
   Display display = new Display();
   AddressBook application = new AddressBook();
   Shell shell = application.open(display);
   while (!shell.isDisposed()) {
     if (!display.readAndDispatch()) display.sleep();
   }
   display.dispose();
 }
 public static void main(String[] args) {
   Display display = new Display();
   MessageWindow application = new MessageWindow();
   Shell shell = application.open(display);
   if (args.length != 0) {
     application.openAddressBook(args[0]);
   }
   while (!shell.isDisposed()) {
     if (!display.readAndDispatch()) display.sleep();
   }
   display.dispose();
 }
Esempio n. 3
0
 public static void main(String[] args) {
   Display display = new Display();
   Shell shell = new Shell(display);
   shell.setLayout(new FillLayout());
   final Table table = new Table(shell, SWT.BORDER);
   table.setHeaderVisible(true);
   final TableColumn column1 = new TableColumn(table, SWT.NONE);
   column1.setText("Column 1");
   final TableColumn column2 = new TableColumn(table, SWT.NONE);
   column2.setText("Column 2");
   TableItem item = new TableItem(table, SWT.NONE);
   item.setText(new String[] {"a", "3"});
   item = new TableItem(table, SWT.NONE);
   item.setText(new String[] {"b", "2"});
   item = new TableItem(table, SWT.NONE);
   item.setText(new String[] {"c", "1"});
   column1.setWidth(100);
   column2.setWidth(100);
   Listener sortListener =
       e -> {
         TableItem[] items = table.getItems();
         Collator collator = Collator.getInstance(Locale.getDefault());
         TableColumn column = (TableColumn) e.widget;
         int index = column == column1 ? 0 : 1;
         for (int i = 1; i < items.length; i++) {
           String value1 = items[i].getText(index);
           for (int j = 0; j < i; j++) {
             String value2 = items[j].getText(index);
             if (collator.compare(value1, value2) < 0) {
               String[] values = {items[i].getText(0), items[i].getText(1)};
               items[i].dispose();
               TableItem item1 = new TableItem(table, SWT.NONE, j);
               item1.setText(values);
               items = table.getItems();
               break;
             }
           }
         }
         table.setSortColumn(column);
       };
   column1.addListener(SWT.Selection, sortListener);
   column2.addListener(SWT.Selection, sortListener);
   table.setSortColumn(column1);
   table.setSortDirection(SWT.UP);
   shell.setSize(shell.computeSize(SWT.DEFAULT, SWT.DEFAULT).x, 300);
   shell.open();
   while (!shell.isDisposed()) {
     if (!display.readAndDispatch()) display.sleep();
   }
   display.dispose();
 }
 /** Invokes as a standalone program. */
 public static void main(String[] args) {
   Display display = new Display();
   Shell shell = new Shell(display, SWT.SHELL_TRIM);
   shell.setLayout(new FillLayout());
   ControlExample instance = new ControlExample(shell);
   shell.setText(getResourceString("window.title"));
   setShellSize(instance, shell);
   shell.open();
   while (!shell.isDisposed()) {
     if (!display.readAndDispatch()) display.sleep();
   }
   instance.dispose();
   display.dispose();
 }
Esempio n. 5
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();
   }
 }
  /** Open the dialog */
  public QueryOptionsPack open(QueryOptionsPack opt) {
    createContents(opt);

    shell.setLocation(
        getParent().getLocation().x + (getParent().getSize().x / 2) - (shell.getSize().x / 2),
        getParent().getLocation().y + (getParent().getSize().y / 2) - (shell.getSize().y / 2));

    shell.open();

    shell.layout();
    Display display = getParent().getDisplay();
    while (!shell.isDisposed()) {
      if (!display.readAndDispatch()) display.sleep();
    }
    return opt;
  }
 /**
  * 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;
 }
  /**
   * This method is called by Spoon when the user opens the settings dialog of the step. It should
   * open the dialog and return only once the dialog has been closed by the user.
   *
   * <p>If the user confirms the dialog, the meta object (passed in the constructor) must be updated
   * to reflect the new step settings. The changed flag of the meta object must reflect whether the
   * step configuration was changed by the dialog.
   *
   * <p>If the user cancels the dialog, the meta object must not be updated, and its changed flag
   * must remain unaltered.
   *
   * <p>The open() method must return the name of the step after the user has confirmed the dialog,
   * or null if the user cancelled the dialog.
   */
  public String open() {

    // store some convenient SWT variables
    Shell parent = getParent();
    Display display = parent.getDisplay();

    // SWT code for preparing the dialog
    shell = new Shell(parent, SWT.DIALOG_TRIM | SWT.RESIZE | SWT.MIN | SWT.MAX);
    props.setLook(shell);
    setShellImage(shell, meta);

    // Save the value of the changed flag on the meta object. If the user cancels
    // the dialog, it will be restored to this saved value.
    // The "changed" variable is inherited from BaseStepDialog
    changed = meta.hasChanged();

    // The ModifyListener used on all controls. It will update the meta object to
    // indicate that changes are being made.
    ModifyListener lsMod =
        new ModifyListener() {
          public void modifyText(ModifyEvent e) {
            meta.setChanged();
          }
        };

    // ------------------------------------------------------- //
    // SWT code for building the actual settings dialog        //
    // ------------------------------------------------------- //
    FormLayout formLayout = new FormLayout();
    formLayout.marginWidth = Const.FORM_MARGIN;
    formLayout.marginHeight = Const.FORM_MARGIN;

    shell.setLayout(formLayout);
    shell.setText(BaseMessages.getString(PKG, "UniqueListStep.Shell.Title"));

    int middle = props.getMiddlePct();
    int margin = Const.MARGIN;

    // Stepname line
    wlStepname = new Label(shell, SWT.RIGHT);
    wlStepname.setText(BaseMessages.getString(PKG, "System.Label.StepName"));
    props.setLook(wlStepname);
    fdlStepname = new FormData();
    fdlStepname.left = new FormAttachment(0, 0);
    fdlStepname.right = new FormAttachment(middle, -margin);
    fdlStepname.top = new FormAttachment(0, margin);
    wlStepname.setLayoutData(fdlStepname);

    wStepname = new Text(shell, SWT.SINGLE | SWT.LEFT | SWT.BORDER);
    wStepname.setText(stepname);
    props.setLook(wStepname);
    wStepname.addModifyListener(lsMod);
    fdStepname = new FormData();
    fdStepname.left = new FormAttachment(middle, 0);
    fdStepname.top = new FormAttachment(0, margin);
    fdStepname.right = new FormAttachment(100, 0);
    wStepname.setLayoutData(fdStepname);

    // Treat Consecutive Delimiters as One
    //
    wlRemoveBlanks = new Label(shell, SWT.RIGHT);
    wlRemoveBlanks.setText("Treat Consecutive Delims as One");
    wlRemoveBlanks.setToolTipText(
        "Multiple delimiters in a row will be condensed. Essentially removes blank spaces");
    props.setLook(wlRemoveBlanks);
    fdlRemoveBlanks = new FormData();
    fdlRemoveBlanks.left = new FormAttachment(0, 0);
    fdlRemoveBlanks.top = new FormAttachment(wStepname, margin);
    fdlRemoveBlanks.right = new FormAttachment(middle, -margin);
    wlRemoveBlanks.setLayoutData(fdlRemoveBlanks);
    wRemoveBlanks = new Button(shell, SWT.CHECK);
    wRemoveBlanks.setToolTipText(
        "Multiple delimiters in a row will be condensed. Essentially removes blank spaces");
    props.setLook(wRemoveBlanks);
    wRemoveBlanks.addSelectionListener(
        new SelectionAdapter() {
          public void widgetSelected(SelectionEvent e) {
            meta.setChanged();
          }
        });
    fdRemoveBlanks = new FormData();
    fdRemoveBlanks.left = new FormAttachment(middle, 0);
    fdRemoveBlanks.top = new FormAttachment(wStepname, margin);
    fdRemoveBlanks.right = new FormAttachment(100, 0);
    wRemoveBlanks.setLayoutData(fdRemoveBlanks);

    // OK and cancel buttons
    wOK = new Button(shell, SWT.PUSH);
    wOK.setText(BaseMessages.getString(PKG, "System.Button.OK"));
    wGet = new Button(shell, SWT.PUSH);
    wGet.setText("Get");
    wCancel = new Button(shell, SWT.PUSH);
    wCancel.setText(BaseMessages.getString(PKG, "System.Button.Cancel"));

    setButtonPositions(new Button[] {wOK, wGet, wCancel}, margin, null);

    wlGroup = new Label(shell, SWT.NONE);
    wlGroup.setText("Fields");
    props.setLook(wlGroup);
    fdlGroup = new FormData();
    fdlGroup.left = new FormAttachment(0, 0);
    fdlGroup.top = new FormAttachment(wlRemoveBlanks, margin);
    wlGroup.setLayoutData(fdlGroup);

    // Fields
    colinf =
        new ColumnInfo[] {
          new ColumnInfo("Field Name", ColumnInfo.COLUMN_TYPE_CCOMBO, new String[] {""}, false),
          new ColumnInfo("Current Delimiter", ColumnInfo.COLUMN_TYPE_TEXT, false),
          new ColumnInfo("Output Field Name (Optional)", ColumnInfo.COLUMN_TYPE_TEXT, false),
          new ColumnInfo("Output Delimiter (Optional)", ColumnInfo.COLUMN_TYPE_TEXT, false)
        };

    int nrRows = (meta.getSourceFields() != null ? meta.getSourceFields().length : 1);

    wGroup =
        new TableView(
            transMeta,
            shell,
            SWT.BORDER | SWT.FULL_SELECTION | SWT.MULTI | SWT.V_SCROLL | SWT.H_SCROLL,
            colinf,
            nrRows,
            lsMod,
            props);

    fdGroup = new FormData();
    fdGroup.left = new FormAttachment(0, 0);
    fdGroup.top = new FormAttachment(wlGroup, margin);
    fdGroup.right = new FormAttachment(100, 0);
    fdGroup.bottom = new FormAttachment(wGet, -margin);
    wGroup.setLayoutData(fdGroup);

    final Runnable runnable =
        new Runnable() {
          public void run() {
            StepMeta stepMeta = transMeta.findStep(stepname);
            if (stepMeta != null) {
              try {
                RowMetaInterface row = transMeta.getPrevStepFields(stepMeta);

                // Remember these fields...
                for (int i = 0; i < row.size(); i++) {
                  inputFields.put(row.getValueMeta(i).getName(), i);
                }
                setComboBoxes();
              } catch (KettleException e) {
                logError(BaseMessages.getString(PKG, "System.Dialog.GetFieldsFailed.Message"));
              }
            }
          }
        };
    new Thread(runnable).start();

    // Add listeners for cancel and OK
    lsCancel =
        new Listener() {
          public void handleEvent(Event e) {
            cancel();
          }
        };
    lsOK =
        new Listener() {
          public void handleEvent(Event e) {
            ok();
          }
        };
    lsGet =
        new Listener() {
          public void handleEvent(Event event) {
            get();
          }
        };

    wCancel.addListener(SWT.Selection, lsCancel);
    wOK.addListener(SWT.Selection, lsOK);
    wGet.addListener(SWT.Selection, lsGet);

    // default listener (for hitting "enter")
    lsDef =
        new SelectionAdapter() {
          public void widgetDefaultSelected(SelectionEvent e) {
            ok();
          }
        };
    wStepname.addSelectionListener(lsDef);

    // Detect X or ALT-F4 or something that kills this window and cancel the dialog properly
    shell.addShellListener(
        new ShellAdapter() {
          public void shellClosed(ShellEvent e) {
            cancel();
          }
        });

    // Set/Restore the dialog size based on last position on screen
    // The setSize() method is inherited from BaseStepDialog
    setSize();

    // populate the dialog with the values from the meta object
    populateDialog();

    // restore the changed flag to original value, as the modify listeners fire during dialog
    // population
    meta.setChanged(changed);

    // open dialog and enter event loop
    shell.open();
    while (!shell.isDisposed()) {
      if (!display.readAndDispatch()) display.sleep();
    }

    // at this point the dialog has closed, so either ok() or cancel() have been executed
    // The "stepname" variable is inherited from BaseStepDialog
    return stepname;
  }
  protected String[] getAuthenticationDialog(final String realm, final String location) {
    final Display display = SWTThread.getInstance().getDisplay();

    if (display.isDisposed()) {

      return (null);
    }

    final AESemaphore sem = new AESemaphore("SWTAuth");

    final authDialog[] dialog = new authDialog[1];

    TOTorrent torrent = TorrentUtils.getTLSTorrent();

    final boolean is_tracker;
    final String details;

    if (torrent == null) {

      is_tracker = false;

      details = TorrentUtils.getTLSDescription();

    } else {

      details = TorrentUtils.getLocalisedName(torrent);
      is_tracker = true;
    }

    try {
      if (display.getThread() == Thread.currentThread()) {

        dialog[0] = new authDialog(sem, display, realm, is_tracker, location, details);

        while (!(display.isDisposed() || sem.isReleasedForever())) {

          if (!display.readAndDispatch()) {

            display.sleep();
          }
        }

        if (display.isDisposed()) {

          return (null);
        }
      } else {

        display.asyncExec(
            new AERunnable() {
              public void runSupport() {
                dialog[0] = new authDialog(sem, display, realm, is_tracker, location, details);
              }
            });
      }
    } catch (Throwable e) {

      Debug.printStackTrace(e);

      return (null);
    }

    sem.reserve();

    String user = dialog[0].getUsername();
    String pw = dialog[0].getPassword();
    String persist = dialog[0].savePassword() ? "true" : "false";

    if (user == null) {

      return (null);
    }

    return (new String[] {user, pw == null ? "" : pw, persist});
  }