Example #1
0
  /** Create contents of the wizard. */
  @Override
  public void createControl(Composite parent) {
    Composite container = new Composite(parent, SWT.NULL);

    setControl(container);
    container.setLayout(new GridLayout(2, false));

    mCurrentRadioButton = new Button(container, SWT.RADIO);
    mCurrentRadioButton.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false, 2, 1));
    mCurrentRadioButton.setText("This project");
    mCurrentRadioButton.addSelectionListener(this);

    mExistingRadioButton = new Button(container, SWT.RADIO);
    mExistingRadioButton.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false, 2, 1));
    mExistingRadioButton.setText("An existing Android project:");
    mExistingRadioButton.addSelectionListener(this);

    ILabelProvider labelProvider =
        new JavaElementLabelProvider(JavaElementLabelProvider.SHOW_DEFAULT);
    mProjectList =
        new FilteredList(
            container,
            SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL | SWT.SINGLE,
            labelProvider,
            true /*ignoreCase*/,
            false /*allowDuplicates*/,
            true /* matchEmptyString*/);
    mProjectList.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 2, 1));
    mProjectList.addSelectionListener(this);
  }
Example #2
0
  @Override
  public void widgetSelected(SelectionEvent e) {
    if (mIgnore) {
      return;
    }

    Object source = e.getSource();
    if (source == mExistingRadioButton) {
      mProjectList.setEnabled(true);
      mValues.testingSelf = false;
      setExistingProject(getSelectedProject());
      mProjectList.setFocus();
    } else if (source == mCurrentRadioButton) {
      mProjectList.setEnabled(false);
      mValues.testingSelf = true;
      mValues.testedProject = null;
    } else {
      // The event must be from the project list, which unfortunately doesn't
      // pass itself as the selection event, it passes a reference to some internal
      // table widget that it uses, so we check for this case last
      IProject project = getSelectedProject();
      if (project != mValues.testedProject) {
        setExistingProject(project);
      }
    }

    validatePage();
  }
Example #3
0
  @Override
  public void setVisible(boolean visible) {
    super.setVisible(visible);
    mPageShown = true;

    if (visible) {
      try {
        mIgnore = true;
        mCurrentRadioButton.setSelection(mValues.testingSelf);
        mExistingRadioButton.setSelection(!mValues.testingSelf);
        mProjectList.setEnabled(!mValues.testingSelf);

        if (mProjectList.isEmpty()) {
          initializeList();
        }
        if (!mValues.testingSelf) {
          mProjectList.setFocus();
          IProject project = getSelectedProject();
          if (project != null) {
            // The FilteredList seems to -insist- on selecting the first item
            // in the list, even when the selection is explicitly set to an empty
            // array. This means the user is looking at a selection, so we need
            // to also go ahead and select this item in the model such that the
            // two agree, even if we would have preferred to have no initial
            // selection.
            mValues.testedProject = project;
          }
        }
      } finally {
        mIgnore = false;
      }
    }

    validatePage();
  }
Example #4
0
 private IProject getSelectedProject() {
   Object[] selection = mProjectList.getSelection();
   IProject project =
       selection != null && selection.length == 1
           ? ((IJavaProject) selection[0]).getProject()
           : null;
   return project;
 }
Example #5
0
 private void initializeList() {
   ProjectChooserHelper helper = new ProjectChooserHelper(getShell(), null /*filter*/);
   IWorkspaceRoot workspaceRoot = ResourcesPlugin.getWorkspace().getRoot();
   IJavaModel javaModel = JavaCore.create(workspaceRoot);
   IJavaProject[] androidProjects = helper.getAndroidProjects(javaModel);
   mProjectList.setElements(androidProjects);
   if (mValues.testedProject != null) {
     for (IJavaProject project : androidProjects) {
       if (project.getProject() == mValues.testedProject) {
         mProjectList.setSelection(new Object[] {project});
         break;
       }
     }
   } else {
     // No initial selection: force the user to choose
     mProjectList.setSelection(new int[0]);
   }
 }
 /* (non-Javadoc)
  * @see org.eclipse.ui.dialogs.AbstractElementListSelectionDialog#createFilteredList(org.eclipse.swt.widgets.Composite)
  */
 @Override
 protected FilteredList createFilteredList(Composite parent) {
   fNewFilteredList = super.createFilteredList(parent);
   fNewFilteredList.setFilterMatcher(fFilterMatcher);
   fNewFilteredList.setComparator(fStringComparator);
   // bug 189330 - adding label to element list for accessiblity
   if (fNewFilteredList != null) {
     fNewFilteredList
         .getAccessible()
         .addAccessibleListener(
             new AccessibleAdapter() {
               @Override
               public void getName(AccessibleEvent e) {
                 e.result = TypeInfoMessages.TypeSelectionDialog_upperLabel;
               }
             });
   }
   return fNewFilteredList;
 }
 /** Forces redraw of elements list. */
 void updateElements() {
   fNewFilteredList.setFilter(fTextWidget.getText());
   handleSelectionChanged();
 }