コード例 #1
0
 /* (non-Javadoc)
  * @see org.eclipse.jface.dialogs.Dialog#createDialogArea(org.eclipse.swt.widgets.Composite)
  */
 @Override
 protected Control createDialogArea(Composite parent) {
   setTitle(
       NLS.bind(
           SnippetMessages.getString(
               "SelectImportsDialog.Manage_the_Java_Snippet_Editor_Imports_for___{0}__1"),
           new String[] {fEditor.getEditorInput().getName()})); // $NON-NLS-1$
   setMessage(
       NLS.bind(
           SnippetMessages.getString("SelectImportsDialog.add_remove_imports"),
           new String[] {fEditor.getEditorInput().getName()})); // $NON-NLS-1$
   Composite outer = SWTFactory.createComposite(parent, 2, 1, GridData.FILL_BOTH);
   GridLayout gl = (GridLayout) outer.getLayout();
   gl.marginLeft = 7;
   gl.marginTop = 0;
   gl.marginBottom = 0;
   SWTFactory.createLabel(
       outer, SnippetMessages.getString("SelectImportsDialog.imports_heading"), 2); // $NON-NLS-1$
   fImportsTable = new Table(outer, SWT.BORDER | SWT.MULTI | SWT.FULL_SELECTION);
   GridData gd = new GridData(GridData.FILL_HORIZONTAL);
   gd.heightHint = 150;
   fImportsTable.setLayoutData(gd);
   fImportsViewer = new TableViewer(fImportsTable);
   fImportsViewer.setLabelProvider(new FilterLabelProvider());
   fImportsViewer.setComparator(new FilterViewerComparator());
   fImportContentProvider = new ImportsContentProvider(fImportsViewer);
   fImportsViewer.setContentProvider(fImportContentProvider);
   // input just needs to be non-null
   fImportsViewer.setInput(this);
   fImportsViewer.addSelectionChangedListener(
       new ISelectionChangedListener() {
         @Override
         public void selectionChanged(SelectionChangedEvent event) {
           ISelection selection = event.getSelection();
           if (selection.isEmpty()) {
             fRemoveImportsButton.setEnabled(false);
           } else {
             fRemoveImportsButton.setEnabled(true);
           }
         }
       });
   createImportButtons(outer);
   applyDialogFont(outer);
   return parent;
 }
コード例 #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);
  }