コード例 #1
0
  private void createImportButtons(Composite container) {
    PlatformUI.getWorkbench()
        .getHelpSystem()
        .setHelp(container, IJavaDebugHelpContextIds.SNIPPET_IMPORTS_DIALOG);
    Composite bcomp =
        SWTFactory.createComposite(
            container,
            container.getFont(),
            1,
            1,
            GridData.VERTICAL_ALIGN_BEGINNING | GridData.HORIZONTAL_ALIGN_FILL,
            0,
            0);
    GridLayout gl = (GridLayout) bcomp.getLayout();
    gl.verticalSpacing = 0;
    // Add type button
    fAddTypeButton =
        SWTFactory.createPushButton(
            bcomp,
            SnippetMessages.getString("SelectImportsDialog.Add_&Type_1"), // $NON-NLS-1$
            SnippetMessages.getString(
                "SelectImportsDialog.Choose_a_Type_to_Add_as_an_Import_2"), //$NON-NLS-1$
            null);
    fAddTypeButton.addSelectionListener(
        new SelectionListener() {
          @Override
          public void widgetSelected(SelectionEvent se) {
            addType();
          }

          @Override
          public void widgetDefaultSelected(SelectionEvent se) {}
        });

    // Add package button
    fAddPackageButton =
        SWTFactory.createPushButton(
            bcomp,
            SnippetMessages.getString("SelectImportsDialog.Add_&Package_3"), // $NON-NLS-1$
            SnippetMessages.getString(
                "SelectImportsDialog.Choose_a_Package_to_Add_as_an_Import_4"), //$NON-NLS-1$
            null);
    fAddPackageButton.addSelectionListener(
        new SelectionListener() {
          @Override
          public void widgetSelected(SelectionEvent se) {
            addPackage();
          }

          @Override
          public void widgetDefaultSelected(SelectionEvent se) {}
        });

    // Remove button
    fRemoveImportsButton =
        SWTFactory.createPushButton(
            bcomp,
            SnippetMessages.getString("SelectImportsDialog.&Remove_5"), // $NON-NLS-1$
            SnippetMessages.getString(
                "SelectImportsDialog.Remove_All_Selected_Imports_6"), //$NON-NLS-1$
            null);
    fRemoveImportsButton.addSelectionListener(
        new SelectionListener() {
          @Override
          public void widgetSelected(SelectionEvent se) {
            removeImports();
          }

          @Override
          public void widgetDefaultSelected(SelectionEvent se) {}
        });
    fRemoveImportsButton.setEnabled(false);
  }
コード例 #2
0
  /**
   * Creates this block's control in the given control.
   *
   * @param ancestor containing control
   * @param useManageButton whether to present a single 'manage...' button to the user that opens
   *     the installed JREs pref page for JRE management, or to provide 'add, remove, edit, and
   *     search' buttons.
   */
  public void createControl(Composite ancestor) {
    Font font = ancestor.getFont();
    Composite parent = SWTFactory.createComposite(ancestor, font, 2, 1, GridData.FILL_BOTH);
    fControl = parent;

    SWTFactory.createLabel(parent, JREMessages.InstalledJREsBlock_15, 2);

    fTable = new Table(parent, SWT.CHECK | SWT.BORDER | SWT.MULTI | SWT.FULL_SELECTION);
    GridData gd = new GridData(GridData.FILL_BOTH);
    gd.heightHint = 250;
    gd.widthHint = 350;
    fTable.setLayoutData(gd);
    fTable.setFont(font);
    fTable.setHeaderVisible(true);
    fTable.setLinesVisible(true);

    TableColumn column = new TableColumn(fTable, SWT.NULL);
    column.setText(JREMessages.InstalledJREsBlock_0);
    column.addSelectionListener(
        new SelectionAdapter() {
          @Override
          public void widgetSelected(SelectionEvent e) {
            sortByName();
            fVMList.refresh(true);
          }
        });
    int defaultwidth = 350 / 3 + 1;
    column.setWidth(defaultwidth);

    column = new TableColumn(fTable, SWT.NULL);
    column.setText(JREMessages.InstalledJREsBlock_1);
    column.addSelectionListener(
        new SelectionAdapter() {
          @Override
          public void widgetSelected(SelectionEvent e) {
            sortByLocation();
            fVMList.refresh(true);
          }
        });
    column.setWidth(defaultwidth);

    column = new TableColumn(fTable, SWT.NULL);
    column.setText(JREMessages.InstalledJREsBlock_2);
    column.addSelectionListener(
        new SelectionAdapter() {
          @Override
          public void widgetSelected(SelectionEvent e) {
            sortByType();
            fVMList.refresh(true);
          }
        });
    column.setWidth(defaultwidth);

    fVMList = new CheckboxTableViewer(fTable);
    fVMList.setLabelProvider(new VMLabelProvider());
    fVMList.setContentProvider(new JREsContentProvider());
    fVMList.setUseHashlookup(true);
    // by default, sort by name
    sortByName();

    fVMList.addSelectionChangedListener(
        new ISelectionChangedListener() {
          @Override
          public void selectionChanged(SelectionChangedEvent evt) {
            enableButtons();
          }
        });

    fVMList.addCheckStateListener(
        new ICheckStateListener() {
          @Override
          public void checkStateChanged(CheckStateChangedEvent event) {
            if (event.getChecked()) {
              setCheckedJRE((IVMInstall) event.getElement());
            } else {
              setCheckedJRE(null);
            }
          }
        });

    fVMList.addDoubleClickListener(
        new IDoubleClickListener() {
          @Override
          public void doubleClick(DoubleClickEvent e) {
            if (!fVMList.getSelection().isEmpty()) {
              editVM();
            }
          }
        });
    fTable.addKeyListener(
        new KeyAdapter() {
          @Override
          public void keyPressed(KeyEvent event) {
            if (event.character == SWT.DEL && event.stateMask == 0) {
              if (fRemoveButton.isEnabled()) {
                removeVMs();
              }
            }
          }
        });

    Composite buttons =
        SWTFactory.createComposite(parent, font, 1, 1, GridData.VERTICAL_ALIGN_BEGINNING, 0, 0);

    fAddButton = SWTFactory.createPushButton(buttons, JREMessages.InstalledJREsBlock_3, null);
    fAddButton.addListener(
        SWT.Selection,
        new Listener() {
          @Override
          public void handleEvent(Event evt) {
            addVM();
          }
        });

    fEditButton = SWTFactory.createPushButton(buttons, JREMessages.InstalledJREsBlock_4, null);
    fEditButton.addListener(
        SWT.Selection,
        new Listener() {
          @Override
          public void handleEvent(Event evt) {
            editVM();
          }
        });

    fCopyButton = SWTFactory.createPushButton(buttons, JREMessages.InstalledJREsBlock_16, null);
    fCopyButton.addListener(
        SWT.Selection,
        new Listener() {
          @Override
          public void handleEvent(Event evt) {
            copyVM();
          }
        });

    fRemoveButton = SWTFactory.createPushButton(buttons, JREMessages.InstalledJREsBlock_5, null);
    fRemoveButton.addListener(
        SWT.Selection,
        new Listener() {
          @Override
          public void handleEvent(Event evt) {
            removeVMs();
          }
        });

    SWTFactory.createVerticalSpacer(parent, 1);

    fSearchButton = SWTFactory.createPushButton(buttons, JREMessages.InstalledJREsBlock_6, null);
    fSearchButton.addListener(
        SWT.Selection,
        new Listener() {
          @Override
          public void handleEvent(Event evt) {
            search();
          }
        });

    fillWithWorkspaceJREs();
    enableButtons();
    fAddButton.setEnabled(JavaRuntime.getVMInstallTypes().length > 0);

    JavaRuntime.addVMInstallChangedListener(fListener);
  }