Java Code Examples for com.intellij.openapi.application.ModalityState#stateForComponent()

The following examples show how to use com.intellij.openapi.application.ModalityState#stateForComponent() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: BackgroundUpdaterTaskBase.java    From consulo with Apache License 2.0 6 votes vote down vote up
/**
 * @deprecated Use {@link #BackgroundUpdaterTaskBase(Project, String, Comparator)} and {@link #updateComponent(T)} instead
 */
@Deprecated
public boolean updateComponent(@Nonnull T element, @Nullable Comparator comparator) {
  if (tryAppendUsage(element)) return true;
  if (myCanceled) return false;

  if (myPopup.isDisposed()) return false;
  ModalityState modalityState = ModalityState.stateForComponent(myPopup.getContent());

  synchronized (lock) {
    if (myData.contains(element)) return true;
    myData.add(element);
    if (comparator != null && myData instanceof List) {
      Collections.sort((List)myData, comparator);
    }
  }

  myAlarm.addRequest(() -> {
    myAlarm.cancelAllRequests();
    refreshModelImmediately();
  }, 200, modalityState);
  return true;
}
 
Example 2
Source File: LiveTemplateSettingsEditor.java    From consulo with Apache License 2.0 6 votes vote down vote up
public void focusKey() {
  myKeyField.selectAll();
  //todo[peter,kirillk] without these invokeLaters this requestFocus conflicts with com.intellij.openapi.ui.impl.DialogWrapperPeerImpl.MyDialog.MyWindowListener.windowOpened()
  IdeFocusManager.findInstanceByComponent(myKeyField).requestFocus(myKeyField, true);
  final ModalityState modalityState = ModalityState.stateForComponent(myKeyField);
  ApplicationManager.getApplication().invokeLater(new Runnable() {
    @Override
    public void run() {
      ApplicationManager.getApplication().invokeLater(new Runnable() {
        @Override
        public void run() {
          ApplicationManager.getApplication().invokeLater(new Runnable() {
            @Override
            public void run() {
              IdeFocusManager.findInstanceByComponent(myKeyField).requestFocus(myKeyField, true);
            }
          }, modalityState);
        }
      }, modalityState);
    }
  }, modalityState);
}
 
Example 3
Source File: DesktopDataManagerImpl.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Override
@Nullable
@SuppressWarnings("unchecked")
protected  <T> T doGetData(@Nonnull Key<T> dataId) {
  Component component = getComponent();
  if (PlatformDataKeys.IS_MODAL_CONTEXT == dataId) {
    if (component == null) {
      return null;
    }
    return (T)(Boolean)IdeKeyEventDispatcher.isModalContext(component);
  }
  if (PlatformDataKeys.CONTEXT_COMPONENT == dataId) {
    return (T)component;
  }
  if (PlatformDataKeys.MODALITY_STATE == dataId) {
    return (T)(component != null ? ModalityState.stateForComponent(component) : ModalityState.NON_MODAL);
  }

  Object data = calcData(dataId, component);
  if (CommonDataKeys.EDITOR == dataId || CommonDataKeys.HOST_EDITOR == dataId) {
    return (T)validateEditor((Editor)data);
  }
  return (T)data;
}
 
Example 4
Source File: MergingUpdateQueue.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nonnull
public ModalityState getModalityState() {
  if (myModalityStateComponent == null) {
    return ModalityState.NON_MODAL;
  }
  return ModalityState.stateForComponent(myModalityStateComponent);
}
 
Example 5
Source File: OnEventDispatchThread.java    From PhpMetrics-jetbrains with MIT License 4 votes vote down vote up
private ModalityState modalityStateFor(Component component) {
    return component != null
            ? ModalityState.stateForComponent(component)
            : ModalityState.any();
}
 
Example 6
Source File: JBTabsImpl.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Override
public ModalityState getModalityState() {
  return ModalityState.stateForComponent(this);
}
 
Example 7
Source File: IdeMenuBar.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Override
public ModalityState getModalityState() {
  return ModalityState.stateForComponent(IdeMenuBar.this);
}
 
Example 8
Source File: ToolbarUpdater.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Override
public ModalityState getModalityState() {
  return ModalityState.stateForComponent(myComponent);
}
 
Example 9
Source File: ButtonToolbarImpl.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Override
public ModalityState getModalityState() {
  return ModalityState.stateForComponent(ButtonToolbarImpl.this);
}
 
Example 10
Source File: AbstractCalledLater.java    From consulo with Apache License 2.0 4 votes vote down vote up
protected AbstractCalledLater(Project project, Component component) {
  myProject = project;
  myState = ModalityState.stateForComponent(component);
}
 
Example 11
Source File: LookupUi.java    From consulo with Apache License 2.0 4 votes vote down vote up
LookupUi(@Nonnull LookupImpl lookup, Advertiser advertiser, JBList list) {
  myLookup = lookup;
  myAdvertiser = advertiser;
  myList = list;

  myProcessIcon.setVisible(false);
  myLookup.resort(false);

  MenuAction menuAction = new MenuAction();
  menuAction.add(new ChangeSortingAction());
  menuAction.add(new DelegatedAction(ActionManager.getInstance().getAction(IdeActions.ACTION_QUICK_JAVADOC)) {
    @Override
    public void update(@Nonnull AnActionEvent e) {
      e.getPresentation().setVisible(!CodeInsightSettings.getInstance().AUTO_POPUP_JAVADOC_INFO);
    }
  });
  menuAction.add(new DelegatedAction(ActionManager.getInstance().getAction(IdeActions.ACTION_QUICK_IMPLEMENTATIONS)));

  Presentation presentation = new Presentation();
  presentation.setIcon(AllIcons.Actions.More);
  presentation.putClientProperty(ActionButton.HIDE_DROPDOWN_ICON, Boolean.TRUE);

  myMenuButton = new ActionButton(menuAction, presentation, ActionPlaces.EDITOR_POPUP, ActionToolbar.NAVBAR_MINIMUM_BUTTON_SIZE);

  AnAction hintAction = new HintAction();
  myHintButton = new ActionButton(hintAction, hintAction.getTemplatePresentation(), ActionPlaces.EDITOR_POPUP, ActionToolbar.NAVBAR_MINIMUM_BUTTON_SIZE);
  myHintButton.setVisible(false);

  myBottomPanel = new NonOpaquePanel(new LookupBottomLayout());
  myBottomPanel.add(myAdvertiser.getAdComponent());
  myBottomPanel.add(myProcessIcon);
  myBottomPanel.add(myHintButton);
  myBottomPanel.add(myMenuButton);

  LookupLayeredPane layeredPane = new LookupLayeredPane();
  layeredPane.mainPanel.add(myBottomPanel, BorderLayout.SOUTH);

  myScrollPane = ScrollPaneFactory.createScrollPane(lookup.getList(), true);
  myScrollPane.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
  UIUtil.putClientProperty(myScrollPane.getVerticalScrollBar(), JBScrollPane.IGNORE_SCROLLBAR_IN_INSETS, true);

  lookup.getComponent().add(layeredPane, BorderLayout.CENTER);

  layeredPane.mainPanel.add(myScrollPane, BorderLayout.CENTER);

  myModalityState = ModalityState.stateForComponent(lookup.getTopLevelEditor().getComponent());

  addListeners();

  Disposer.register(lookup, myProcessIcon);
  Disposer.register(lookup, myHintAlarm);
}
 
Example 12
Source File: AbstractTreeClassChooserDialog.java    From consulo with Apache License 2.0 4 votes vote down vote up
private ModalityState getModalityState() {
  return ModalityState.stateForComponent(getRootPane());
}
 
Example 13
Source File: StructureViewWrapperImpl.java    From consulo with Apache License 2.0 4 votes vote down vote up
public StructureViewWrapperImpl(Project project, ToolWindowEx toolWindow) {
  myProject = project;
  myToolWindow = toolWindow;

  myUpdateQueue = new MergingUpdateQueue("StructureView", Registry.intValue("structureView.coalesceTime"), false, myToolWindow.getComponent(), this, myToolWindow.getComponent(), true);
  myUpdateQueue.setRestartTimerOnAdd(true);

  final TimerListener timerListener = new TimerListener() {
    @Override
    public ModalityState getModalityState() {
      return ModalityState.stateForComponent(myToolWindow.getComponent());
    }

    @Override
    public void run() {
      checkUpdate();
    }
  };
  ActionManager.getInstance().addTimerListener(500, timerListener);
  Disposer.register(this, new Disposable() {
    @Override
    public void dispose() {
      ActionManager.getInstance().removeTimerListener(timerListener);
    }
  });

  myToolWindow.getComponent().addHierarchyListener(new HierarchyListener() {
    @Override
    public void hierarchyChanged(HierarchyEvent e) {
      if (BitUtil.isSet(e.getChangeFlags(), HierarchyEvent.DISPLAYABILITY_CHANGED)) {
        scheduleRebuild();
      }
    }
  });
  myToolWindow.getContentManager().addContentManagerListener(new ContentManagerAdapter() {
    @Override
    public void selectionChanged(ContentManagerEvent event) {
      if (myStructureView instanceof StructureViewComposite) {
        StructureViewComposite.StructureViewDescriptor[] views = ((StructureViewComposite)myStructureView).getStructureViews();
        for (StructureViewComposite.StructureViewDescriptor view : views) {
          if (view.title.equals(event.getContent().getTabName())) {
            updateHeaderActions(view.structureView);
            break;
          }
        }
      }
    }
  });
  Disposer.register(myToolWindow.getContentManager(), this);
}