コード例 #1
0
  protected void createTestButton(Composite parent) {

    GridData gd = new GridData();
    gd.horizontalSpan = 1;
    testButton = new Button(parent, SWT.PUSH);
    testButton.setLayoutData(gd);

    testButton.setText("Test selected PHP executable");
    testButton.addSelectionListener(
        new SelectionAdapter() {

          @Override
          public void widgetSelected(SelectionEvent e) {
            try {
              String current = exes.getText();
              PHPexeItem phPexeItem = null;

              for (PHPexeItem i : phpExes.getAllItems()) {
                if (current.equals(i.getName())) {
                  phPexeItem = i;
                  break;
                }
              }

              if (phPexeItem == null) {
                Logger.log(Logger.WARNING, "No executable selected");
                return;
              }

              ExecutionResponseAdapter adapter =
                  new ExecutionResponseAdapter() {
                    public void executionFailed(final String response, Exception exception) {
                      getShell()
                          .getDisplay()
                          .asyncExec(
                              new Runnable() {
                                @Override
                                public void run() {
                                  String message = "PHP binary execution failed.";
                                  if (response != null && response.length() > 0) {
                                    message += " Reason: " + response;
                                  } else {
                                  }
                                  MessageDialog.openInformation(
                                      getShell(), "Execution test", message);
                                }
                              });
                    };

                    public void executionFinished(final String response, int exitValue) {
                      getShell()
                          .getDisplay()
                          .asyncExec(
                              new Runnable() {
                                @Override
                                public void run() {
                                  String message = "PHP binary executed successfully.";
                                  if (response != null && response.length() > 0) {
                                    message += " Detected PHP version: " + response;
                                  } else {
                                    message += " Unable to determine PHP version.";
                                  }
                                  MessageDialog.openInformation(
                                      getShell(), "Execution test", message);
                                }
                              });
                    };
                  };

              // TODO: refactor
              new Thread(new ExecutableTester(phPexeItem, adapter)).run();

            } catch (Exception ex) {
              Logger.logException(ex);
            }
          }
        });
  }
コード例 #2
0
  protected Composite createInnerContent(Composite folder) {

    Composite result = new Composite(folder, SWT.NONE);

    GridLayout layout = new GridLayout();
    layout.marginWidth = 0;
    result.setLayout(layout);

    GridData gd = new GridData(GridData.FILL_HORIZONTAL);
    gd.widthHint = 440;
    result.setLayoutData(gd);

    // php
    gd = new GridData(GridData.FILL_HORIZONTAL);
    Group sourceFolderGroup = new Group(result, SWT.NONE);
    sourceFolderGroup.setLayout(new GridLayout(3, false));
    sourceFolderGroup.setLayoutData(gd);
    sourceFolderGroup.setText("PHP executable");

    GridData gridData = new GridData(GridData.HORIZONTAL_ALIGN_FILL);
    gridData.horizontalSpan = 3;
    Link prefLink = new Link(sourceFolderGroup, SWT.WRAP);
    prefLink.setText("You can add PHP binaries in the <a>PHP Executables</a> preference page.");
    prefLink.setLayoutData(gridData);

    prefLink.addSelectionListener(
        new SelectionAdapter() {
          public void widgetSelected(SelectionEvent e) {
            IWorkbenchPreferenceContainer container =
                (IWorkbenchPreferenceContainer) getPreferenceContainer();
            container.openPage(PHPsPreferencePage.ID, null);
          };
        });

    Link helpLink = new Link(sourceFolderGroup, SWT.WRAP);
    helpLink.setLayoutData(gridData);
    helpLink.setText("See <a>phptherightway.com</a> if you need help installing the PHP CLI.");
    helpLink.addSelectionListener(
        new SelectionAdapter() {
          public void widgetSelected(SelectionEvent e) {
            try {
              PlatformUI.getWorkbench()
                  .getBrowserSupport()
                  .getExternalBrowser()
                  .openURL(new URL("http://www.phptherightway.com/#getting_started"));
            } catch (Exception e1) {
              Logger.logException(e1);
            }
          };
        });

    exes = new ComboDialogField(SWT.READ_ONLY);
    exes.setLabelText("PHP executable");
    exes.doFillIntoGrid(sourceFolderGroup, 2);
    exes.setDialogFieldListener(this);

    createTestButton(sourceFolderGroup);

    loadExecutables();

    createScriptGroup(result);
    loadPhar();

    if (phpExes.getAllItems().length == 0) {
      testButton.setEnabled(false);
    }

    createExtraContent(result);

    return result;
  }