Ejemplo n.º 1
0
  @Override
  public ActionCallback show() {
    LOG.assertTrue(
        EventQueue.isDispatchThread(), "Access is allowed from event dispatch thread only");
    if (myTypeAheadCallback != null) {
      IdeFocusManager.getInstance(myProject).typeAheadUntil(myTypeAheadCallback);
    }
    LOG.assertTrue(
        EventQueue.isDispatchThread(), "Access is allowed from event dispatch thread only");
    final ActionCallback result = new ActionCallback();

    final AnCancelAction anCancelAction = new AnCancelAction();
    final JRootPane rootPane = getRootPane();
    anCancelAction.registerCustomShortcutSet(
        new CustomShortcutSet(KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0)), rootPane);
    myDisposeActions.add(
        new Runnable() {
          @Override
          public void run() {
            anCancelAction.unregisterCustomShortcutSet(rootPane);
          }
        });

    if (!myCanBeParent && myWindowManager != null) {
      myWindowManager.doNotSuggestAsParent(myDialog.getWindow());
    }

    final CommandProcessorEx commandProcessor =
        ApplicationManager.getApplication() != null
            ? (CommandProcessorEx) CommandProcessor.getInstance()
            : null;
    final boolean appStarted = commandProcessor != null;

    if (myDialog.isModal() && !isProgressDialog()) {
      if (appStarted) {
        commandProcessor.enterModal();
        LaterInvocator.enterModal(myDialog);
      }
    }

    if (appStarted) {
      hidePopupsIfNeeded();
    }

    try {
      myDialog.show();
    } finally {
      if (myDialog.isModal() && !isProgressDialog()) {
        if (appStarted) {
          commandProcessor.leaveModal();
          LaterInvocator.leaveModal(myDialog);
        }
      }

      myDialog.getFocusManager().doWhenFocusSettlesDown(result.createSetDoneRunnable());
    }

    return result;
  }
  private ActionCallback processAjusted(
      final Map<Object, Condition> adjusted, final Set<Object> originallySelected) {
    final ActionCallback result = new ActionCallback();

    final Set<Object> allSelected = myUi.getSelectedElements();

    Set<Object> toSelect = new HashSet<Object>();
    for (Map.Entry<Object, Condition> entry : adjusted.entrySet()) {
      if (entry.getValue().value(entry.getKey())) continue;

      for (final Object eachSelected : allSelected) {
        if (isParentOrSame(entry.getKey(), eachSelected)) continue;
        toSelect.add(entry.getKey());
      }
      if (allSelected.isEmpty()) {
        toSelect.add(entry.getKey());
      }
    }

    final Object[] newSelection = ArrayUtil.toObjectArray(toSelect);

    if (newSelection.length > 0) {
      myUi._select(
          newSelection,
          new Runnable() {
            @Override
            public void run() {
              final Set<Object> hangByParent = new HashSet<Object>();
              processUnsuccessfulSelections(
                  newSelection,
                  new Function<Object, Object>() {
                    @Override
                    public Object fun(final Object o) {
                      if (myUi.isInStructure(o) && !adjusted.get(o).value(o)) {
                        hangByParent.add(o);
                      } else {
                        addAdjustedSelection(o, adjusted.get(o), null);
                      }
                      return null;
                    }
                  },
                  originallySelected);

              processHangByParent(hangByParent).notify(result);
            }
          },
          false,
          true,
          true);
    } else {
      result.setDone();
    }

    return result;
  }
Ejemplo n.º 3
0
 @Override
 public ActionCallback restoreInGrid() {
   myRestoringNow = true;
   if (myActions.size() == 0) return ActionCallback.DONE;
   final ActionCallback topCallback = restore(0);
   return topCallback.doWhenDone(
       () -> {
         myActions.clear();
         myRestoringNow = false;
       });
 }
  private ActionCallback processHangByParent(Set<Object> elements) {
    if (elements.isEmpty()) return new ActionCallback.Done();

    ActionCallback result = new ActionCallback(elements.size());
    for (Object hangElement : elements) {
      if (!myAdjustmentCause2Adjustment.containsKey(hangElement)) {
        processHangByParent(hangElement).notify(result);
      } else {
        result.setDone();
      }
    }
    return result;
  }
Ejemplo n.º 5
0
  private ActionCallback processHangByParent(Set<Object> elements) {
    if (elements.size() == 0) return new ActionCallback.Done();

    ActionCallback result = new ActionCallback(elements.size());
    for (Iterator<Object> iterator = elements.iterator(); iterator.hasNext(); ) {
      Object hangElement = iterator.next();
      if (!myAdjustmentCause2Adjustment.containsKey(hangElement)) {
        processHangByParent(hangElement).notify(result);
      } else {
        result.setDone();
      }
    }
    return result;
  }
Ejemplo n.º 6
0
      private ActionCallback restore(final int index) {
        final ActionCallback result = new ActionCallback();
        final Restore action = myActions.get(index);
        final ActionCallback actionCalback = action.restoreInGrid();
        actionCalback.doWhenDone(
            () -> {
              if (index < myActions.size() - 1) {
                restore(index + 1).notifyWhenDone(result);
              } else {
                result.setDone();
              }
            });

        return result;
      }
Ejemplo n.º 7
0
 private void callClientAssert(VirtualFile file) throws IOException, InterruptedException {
   semaphore.down();
   ActionCallback callback =
       client.test(
           null,
           DocumentFactoryManager.getInstance().getId(file),
           getTestName(false),
           APP_TEST_CLASS_ID);
   callback.doWhenProcessed(
       new Runnable() {
         @Override
         public void run() {
           semaphore.up();
         }
       });
   await();
 }
Ejemplo n.º 8
0
 private void processNextHang(Object element, final ActionCallback callback) {
   if (element == null || myUi.getSelectedElements().contains(element)) {
     callback.setDone();
   } else {
     final Object nextElement = myUi.getTreeStructure().getParentElement(element);
     if (nextElement == null) {
       callback.setDone();
     } else {
       myUi.select(
           nextElement,
           new Runnable() {
             public void run() {
               processNextHang(nextElement, callback);
             }
           },
           true);
     }
   }
 }
  public void processUntil(ActionCallback callback) throws IOException {
    while (true) {
      final int command = reader.read();
      if (command == -1) {
        break;
      }

      processCommandAndNotifyFileBased(command);
      if (callback.isProcessed()) {
        break;
      }
    }
  }
Ejemplo n.º 10
0
  protected ActionCallback _execute(final PlaybackRunner.StatusCallback cb, Robot robot) {
    final ActionCallback result = new ActionCallback();

    String text = getText().substring(PREFIX.length()).trim();
    final Map<String, String> expected = new LinkedHashMap<String, String>();

    if (text.length() > 0) {
      final String[] keyValue = text.split(",");
      for (String each : keyValue) {
        final String[] eachPair = each.split("=");
        if (eachPair.length != 2) {
          cb.error("Syntax error, must be comma-separated pairs key=value", getLine());
          result.setRejected();
          return result;
        }

        expected.put(eachPair[0], eachPair[1]);
      }
    }

    IdeFocusManager.findInstance()
        .doWhenFocusSettlesDown(
            new Runnable() {
              public void run() {
                try {
                  doAssert(expected, cb);
                  result.setDone();
                } catch (AssertionError error) {
                  cb.error("Assertion failed: " + error.getMessage(), getLine());
                  result.setRejected();
                }
              }
            });

    return result;
  }
Ejemplo n.º 11
0
 @NotNull
 public static Promise<Void> wrapAsVoid(@NotNull ActionCallback asyncResult) {
   final AsyncPromise<Void> promise = new AsyncPromise<Void>();
   asyncResult
       .doWhenDone(
           new Runnable() {
             @Override
             public void run() {
               promise.setResult(null);
             }
           })
       .doWhenRejected(
           new Consumer<String>() {
             @Override
             public void consume(String error) {
               promise.setError(createError(error == null ? "Internal error" : error));
             }
           });
   return promise;
 }
Ejemplo n.º 12
0
    public MyDialog(
        Window owner,
        DialogWrapper dialogWrapper,
        Project project,
        @NotNull ActionCallback focused,
        @NotNull ActionCallback typeAheadDone,
        ActionCallback typeAheadCallback) {
      super(owner);
      myDialogWrapper = new WeakReference<DialogWrapper>(dialogWrapper);
      myProject = project != null ? new WeakReference<Project>(project) : null;

      setFocusTraversalPolicy(
          new LayoutFocusTraversalPolicyExt() {
            @Override
            protected boolean accept(Component aComponent) {
              if (UIUtil.isFocusProxy(aComponent)) return false;
              return super.accept(aComponent);
            }
          });

      myFocusedCallback = focused;
      myTypeAheadDone = typeAheadDone;
      myTypeAheadCallback = typeAheadCallback;

      final long typeAhead = getDialogWrapper().getTypeAheadTimeoutMs();
      if (typeAhead <= 0) {
        myTypeAheadDone.setDone();
      }

      setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
      myWindowListener = new MyWindowListener();
      addWindowListener(myWindowListener);

      myComponentListener = new MyComponentListener();
      addComponentListener(myComponentListener);
    }
Ejemplo n.º 13
0
  public static ActionCallback showAndSelect(
      final JTree tree,
      int top,
      int bottom,
      final int row,
      final int previous,
      boolean addToSelection,
      final boolean scroll) {
    final TreePath path = tree.getPathForRow(row);

    if (path == null) return new ActionCallback.Done();

    final int size = tree.getRowCount();
    if (size == 0) {
      tree.clearSelection();
      return new ActionCallback.Done();
    }
    if (top < 0) {
      top = 0;
    }
    if (bottom >= size) {
      bottom = size - 1;
    }

    if (row >= tree.getRowCount()) return new ActionCallback.Done();

    if (!tree.isValid()) {
      tree.validate();
    }

    final Rectangle rowBounds = tree.getRowBounds(row);
    if (rowBounds == null) return new ActionCallback.Done();

    Rectangle topBounds = tree.getRowBounds(top);
    if (topBounds == null) {
      topBounds = rowBounds;
    }

    Rectangle bottomBounds = tree.getRowBounds(bottom);
    if (bottomBounds == null) {
      bottomBounds = rowBounds;
    }

    Rectangle bounds = topBounds.union(bottomBounds);
    bounds.x = rowBounds.x;
    bounds.width = rowBounds.width;

    final Rectangle visible = tree.getVisibleRect();
    if (visible.contains(bounds)) {
      bounds = null;
    } else {
      final Component comp =
          tree.getCellRenderer()
              .getTreeCellRendererComponent(
                  tree, path.getLastPathComponent(), true, true, false, row, false);

      if (comp instanceof SimpleColoredComponent) {
        final SimpleColoredComponent renderer = ((SimpleColoredComponent) comp);
        final Dimension scrollableSize = renderer.computePreferredSize(true);
        bounds.width = scrollableSize.width;
      }
    }

    final ActionCallback callback = new ActionCallback();

    if (!tree.isRowSelected(row)) {
      if (addToSelection) {
        tree.getSelectionModel().addSelectionPath(tree.getPathForRow(row));
      } else {
        tree.setSelectionRow(row);
      }
    }

    if (bounds != null) {
      final Range<Integer> range = getExpandControlRange(tree, path);
      if (range != null) {
        int delta = bounds.x - range.getFrom().intValue();
        bounds.x -= delta;
        bounds.width -= delta;
      }

      if (visible.width < bounds.width) {
        bounds.width = visible.width;
      }

      final Rectangle b1 = bounds;
      final Runnable runnable =
          new Runnable() {
            public void run() {
              if (scroll) {
                tree.scrollRectToVisible(b1);
              }
              callback.setDone();
            }
          };

      if (ApplicationManager.getApplication().isUnitTestMode()) {
        runnable.run();
      } else {
        SwingUtilities.invokeLater(runnable);
      }
    } else {
      callback.setDone();
    }

    return callback;
  }