private void onTextChange() {
   if (!myIsInUpdate) {
     myUpdateAlarm.cancelAllRequests();
     myTextChanged = true;
     final String text = myPatternField.getText();
     myCurrentScope = new InvalidPackageSet(text);
     try {
       if (!StringUtil.isEmpty(text)) {
         myCurrentScope = PackageSetFactory.getInstance().compile(text);
       }
       myErrorMessage = null;
     } catch (Exception e) {
       myErrorMessage = e.getMessage();
       showErrorMessage();
     }
     rebuild(false);
   } else if (!invalidScopeInside(myCurrentScope)) {
     myErrorMessage = null;
   }
 }
  public ScopeEditorPanel(Project project, final NamedScopesHolder holder) {
    myProject = project;
    myHolder = holder;

    myPackageTree = new Tree(new RootNode(project));

    myButtonsPanel.add(createActionsPanel());

    myTreePanel.setLayout(new BorderLayout());
    myTreePanel.add(ScrollPaneFactory.createScrollPane(myPackageTree), BorderLayout.CENTER);

    myTreeToolbar.setLayout(new BorderLayout());
    myTreeToolbar.add(createTreeToolbar(), BorderLayout.WEST);

    myTreeExpansionMonitor = PackageTreeExpansionMonitor.install(myPackageTree, myProject);

    myTreeMarker =
        new Marker() {
          public boolean isMarked(VirtualFile file) {
            return myCurrentScope != null
                && (myCurrentScope instanceof PackageSetBase
                    ? ((PackageSetBase) myCurrentScope).contains(file, myHolder)
                    : myCurrentScope.contains(PackageSetBase.getPsiFile(file, myHolder), myHolder));
          }
        };

    myPatternField.setDialogCaption("Pattern");
    myPatternField
        .getDocument()
        .addDocumentListener(
            new DocumentAdapter() {
              public void textChanged(DocumentEvent event) {
                onTextChange();
              }
            });

    myPatternField
        .getTextField()
        .addCaretListener(
            new CaretListener() {
              public void caretUpdate(CaretEvent e) {
                myCaretPosition = e.getDot();
                updateCaretPositionText();
              }
            });

    myPatternField
        .getTextField()
        .addFocusListener(
            new FocusListener() {
              public void focusGained(FocusEvent e) {
                if (myErrorMessage != null) {
                  myPositionPanel.setVisible(true);
                  myPanel.revalidate();
                }
              }

              public void focusLost(FocusEvent e) {
                myPositionPanel.setVisible(false);
                myPanel.revalidate();
              }
            });

    initTree(myPackageTree);
    new UiNotifyConnector(
        myPanel,
        new Activatable() {
          @Override
          public void showNotify() {}

          @Override
          public void hideNotify() {
            cancelCurrentProgress();
          }
        });
    myPartiallyIncluded.setBackground(MyTreeCellRenderer.PARTIAL_INCLUDED);
    myRecursivelyIncluded.setBackground(MyTreeCellRenderer.WHOLE_INCLUDED);
  }
 public void reset(PackageSet packageSet, @Nullable Runnable runnable) {
   myCurrentScope = packageSet;
   myPatternField.setText(myCurrentScope == null ? "" : myCurrentScope.getText());
   rebuild(false, runnable, false, 0);
 }
 public String getPatternText() {
   return myPatternField.getText();
 }