コード例 #1
0
  private boolean ensureSelectionExists() {
    if (myList.getSelectedIndex() < 0 || myList.getSelectedIndex() >= myList.getModel().getSize()) {
      if (myList.getModel().getSize() >= 0) {
        myList.setSelectedIndex(0);
        return false;
      }
    }

    return true;
  }
コード例 #2
0
  private void suggestCompletion(final boolean selectReplacedText, final boolean isExplicitCall) {
    if (isExplicitCall) {
      myAutopopup = true;
    }

    if (!getField().isFocusOwner()) return;

    final CompletionResult result = new CompletionResult();
    if (myList != null && myCurrentCompletion != null) {
      int index = myList.getSelectedIndex();
      if (index >= 0 && index < myList.getModel().getSize()) {
        result.myPreselected = (LookupFile) myList.getSelectedValue();
      }
    }

    myUiUpdater.queue(
        new Update("textField.suggestCompletion") {
          public void run() {
            final String completionBase = getCompletionBase();
            if (completionBase != null) {
              final LookupFile file = myFinder.find(completionBase);
              if (file != null && !file.isDirectory()) {
                // we've entered a complete path already, no need to autopopup completion again
                // (IDEA-78996)
                return;
              }
            }
            result.myCompletionBase = completionBase;
            if (result.myCompletionBase == null) return;
            result.myFieldText = myPathTextField.getText();
            ApplicationManager.getApplication()
                .executeOnPooledThread(
                    new Runnable() {
                      public void run() {
                        processCompletion(result);
                        SwingUtilities.invokeLater(
                            new Runnable() {
                              public void run() {
                                if (!result.myCompletionBase.equals(getCompletionBase())) return;

                                int pos = selectCompletionRemoveText(result, selectReplacedText);

                                showCompletionPopup(result, pos, isExplicitCall);
                              }
                            });
                      }
                    });
          }
        });
  }