use of com.intellij.openapi.application.ModalityState in project intellij-community by JetBrains.
the class GotoActionAction method createPopup.
@Nullable
private static ChooseByNamePopup createPopup(@Nullable Project project, @NotNull final GotoActionModel model, String initialText, int initialIndex, final Component component, final AnActionEvent e) {
ChooseByNamePopup oldPopup = project == null ? null : project.getUserData(ChooseByNamePopup.CHOOSE_BY_NAME_POPUP_IN_PROJECT_KEY);
if (oldPopup != null) {
oldPopup.close(false);
}
final Disposable disposable = Disposer.newDisposable();
final ChooseByNamePopup popup = new ChooseByNamePopup(project, model, new GotoActionItemProvider(model), oldPopup, initialText, false, initialIndex) {
private boolean myPaintInternalInfo;
@Override
protected void initUI(Callback callback, ModalityState modalityState, boolean allowMultipleSelection) {
super.initUI(callback, modalityState, allowMultipleSelection);
myList.addListSelectionListener(new ListSelectionListener() {
@Override
public void valueChanged(ListSelectionEvent e) {
Object value = myList.getSelectedValue();
String text = getText(value);
if (text != null && myDropdownPopup != null) {
myDropdownPopup.setAdText(text, SwingConstants.LEFT);
}
String description = getValueDescription(value);
ActionMenu.showDescriptionInStatusBar(true, myList, description);
}
@Nullable
private String getText(@Nullable Object o) {
if (o instanceof GotoActionModel.MatchedValue) {
GotoActionModel.MatchedValue mv = (GotoActionModel.MatchedValue) o;
if (myPaintInternalInfo) {
if (mv.value instanceof GotoActionModel.ActionWrapper) {
AnAction action = ((GotoActionModel.ActionWrapper) mv.value).getAction();
String actionId = ActionManager.getInstance().getId(action);
return StringUtil.notNullize(actionId, "class: " + action.getClass().getName());
}
}
if (mv.value instanceof BooleanOptionDescription || mv.value instanceof GotoActionModel.ActionWrapper && ((GotoActionModel.ActionWrapper) mv.value).getAction() instanceof ToggleAction) {
return "Press " + KeymapUtil.getKeystrokeText(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0)) + " to toggle option";
}
}
return getAdText();
}
});
myList.addMouseMotionListener(new MouseMotionAdapter() {
@Override
public void mouseMoved(MouseEvent e) {
int index = myList.locationToIndex(e.getPoint());
if (index == -1)
return;
Object value = myList.getModel().getElementAt(index);
String description = getValueDescription(value);
ActionMenu.showDescriptionInStatusBar(true, myList, description);
}
});
if (Registry.is("show.configurables.ids.in.settings")) {
new HeldDownKeyListener() {
@Override
protected void heldKeyTriggered(JComponent component, boolean pressed) {
myPaintInternalInfo = pressed;
// an easy way to repaint the AdText
ListSelectionEvent event = new ListSelectionEvent(this, -1, -1, false);
for (ListSelectionListener listener : myList.getListSelectionListeners()) {
listener.valueChanged(event);
}
}
}.installOn(myTextField);
}
}
@Nullable
private String getValueDescription(@Nullable Object value) {
if (value instanceof GotoActionModel.MatchedValue) {
GotoActionModel.MatchedValue mv = (GotoActionModel.MatchedValue) value;
if (mv.value instanceof GotoActionModel.ActionWrapper) {
AnAction action = ((GotoActionModel.ActionWrapper) mv.value).getAction();
return action.getTemplatePresentation().getDescription();
}
}
return null;
}
@NotNull
@Override
protected Set<Object> filter(@NotNull Set<Object> elements) {
return super.filter(model.sortItems(elements));
}
@Override
protected boolean closeForbidden(boolean ok) {
if (!ok)
return false;
Object element = getChosenElement();
return element instanceof GotoActionModel.MatchedValue && processOptionInplace(((GotoActionModel.MatchedValue) element).value, this, component, e) || super.closeForbidden(true);
}
@Override
public void setDisposed(boolean disposedFlag) {
super.setDisposed(disposedFlag);
Disposer.dispose(disposable);
ActionMenu.showDescriptionInStatusBar(true, myList, null);
for (ListSelectionListener listener : myList.getListSelectionListeners()) {
myList.removeListSelectionListener(listener);
}
UIUtil.dispose(myList);
}
};
ApplicationManager.getApplication().getMessageBus().connect(disposable).subscribe(ProgressWindow.TOPIC, new ProgressWindow.Listener() {
@Override
public void progressWindowCreated(ProgressWindow pw) {
Disposer.register(pw, new Disposable() {
@Override
public void dispose() {
if (!popup.checkDisposed()) {
popup.repaintList();
}
}
});
}
});
if (project != null) {
project.putUserData(ChooseByNamePopup.CHOOSE_BY_NAME_POPUP_IN_PROJECT_KEY, popup);
}
popup.addMouseClickListener(new MouseAdapter() {
@Override
public void mouseClicked(@NotNull MouseEvent me) {
Object element = popup.getSelectionByPoint(me.getPoint());
if (element instanceof GotoActionModel.MatchedValue) {
if (processOptionInplace(((GotoActionModel.MatchedValue) element).value, popup, component, e)) {
me.consume();
}
}
}
});
CustomShortcutSet shortcutSet = new CustomShortcutSet(KeymapManager.getInstance().getActiveKeymap().getShortcuts(IdeActions.ACTION_SHOW_INTENTION_ACTIONS));
new DumbAwareAction() {
@Override
public void actionPerformed(AnActionEvent e) {
Object o = popup.getChosenElement();
if (o instanceof GotoActionModel.MatchedValue) {
Comparable value = ((GotoActionModel.MatchedValue) o).value;
if (value instanceof GotoActionModel.ActionWrapper) {
GotoActionModel.ActionWrapper aw = (GotoActionModel.ActionWrapper) value;
boolean available = aw.isAvailable();
if (available) {
AnAction action = aw.getAction();
String id = ActionManager.getInstance().getId(action);
KeymapManagerImpl km = ((KeymapManagerImpl) KeymapManager.getInstance());
Keymap k = km.getActiveKeymap();
if (!k.canModify())
return;
KeymapPanel.addKeyboardShortcut(id, ActionShortcutRestrictions.getInstance().getForActionId(id), k, component);
popup.repaintListImmediate();
}
}
}
}
}.registerCustomShortcutSet(shortcutSet, popup.getTextField(), disposable);
return popup;
}
use of com.intellij.openapi.application.ModalityState in project intellij-community by JetBrains.
the class AbstractTreeClassChooserDialog method createCenterPanel.
@Override
protected JComponent createCenterPanel() {
final DefaultTreeModel model = new DefaultTreeModel(new DefaultMutableTreeNode());
myTree = new Tree(model);
ProjectAbstractTreeStructureBase treeStructure = new AbstractProjectTreeStructure(myProject) {
@Override
public boolean isFlattenPackages() {
return false;
}
@Override
public boolean isShowMembers() {
return myIsShowMembers;
}
@Override
public boolean isHideEmptyMiddlePackages() {
return true;
}
@Override
public boolean isAbbreviatePackageNames() {
return false;
}
@Override
public boolean isShowLibraryContents() {
return myIsShowLibraryContents;
}
@Override
public boolean isShowModules() {
return false;
}
};
myBuilder = new ProjectTreeBuilder(myProject, myTree, model, AlphaComparator.INSTANCE, treeStructure);
myTree.setRootVisible(false);
myTree.setShowsRootHandles(true);
myTree.expandRow(0);
myTree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
myTree.setCellRenderer(new NodeRenderer());
UIUtil.setLineStyleAngled(myTree);
JScrollPane scrollPane = ScrollPaneFactory.createScrollPane(myTree);
scrollPane.setPreferredSize(JBUI.size(500, 300));
myTree.addKeyListener(new KeyAdapter() {
@Override
public void keyPressed(KeyEvent e) {
if (KeyEvent.VK_ENTER == e.getKeyCode()) {
doOKAction();
}
}
});
new DoubleClickListener() {
@Override
protected boolean onDoubleClick(MouseEvent event) {
TreePath path = myTree.getPathForLocation(event.getX(), event.getY());
if (path != null && myTree.isPathSelected(path)) {
doOKAction();
return true;
}
return false;
}
}.installOn(myTree);
myTree.addTreeSelectionListener(new TreeSelectionListener() {
@Override
public void valueChanged(TreeSelectionEvent e) {
handleSelectionChanged();
}
});
new TreeSpeedSearch(myTree);
myTabbedPane = new TabbedPaneWrapper(getDisposable());
final JPanel dummyPanel = new JPanel(new BorderLayout());
String name = null;
/*
if (myInitialClass != null) {
name = myInitialClass.getName();
}
*/
myGotoByNamePanel = new ChooseByNamePanel(myProject, createChooseByNameModel(), name, myScope.isSearchInLibraries(), getContext()) {
@Override
protected void showTextFieldPanel() {
}
@Override
protected void close(boolean isOk) {
super.close(isOk);
if (isOk) {
doOKAction();
} else {
doCancelAction();
}
}
@NotNull
@Override
protected Set<Object> filter(@NotNull Set<Object> elements) {
return doFilter(elements);
}
@Override
protected void initUI(ChooseByNamePopupComponent.Callback callback, ModalityState modalityState, boolean allowMultipleSelection) {
super.initUI(callback, modalityState, allowMultipleSelection);
dummyPanel.add(myGotoByNamePanel.getPanel(), BorderLayout.CENTER);
IdeFocusManager.getGlobalInstance().doWhenFocusSettlesDown(() -> {
IdeFocusManager.getGlobalInstance().requestFocus(IdeFocusTraversalPolicy.getPreferredFocusedComponent(myGotoByNamePanel.getPanel()), true);
});
}
@Override
protected void showList() {
super.showList();
if (myInitialClass != null && myList.getModel().getSize() > 0) {
myList.setSelectedValue(myInitialClass, true);
myInitialClass = null;
}
}
@Override
protected void chosenElementMightChange() {
handleSelectionChanged();
}
};
Disposer.register(myDisposable, myGotoByNamePanel);
myTabbedPane.addTab(IdeBundle.message("tab.chooser.search.by.name"), dummyPanel);
myTabbedPane.addTab(IdeBundle.message("tab.chooser.project"), scrollPane);
myGotoByNamePanel.invoke(new MyCallback(), getModalityState(), false);
myTabbedPane.addChangeListener(new ChangeListener() {
@Override
public void stateChanged(ChangeEvent e) {
handleSelectionChanged();
}
});
return myTabbedPane.getComponent();
}
use of com.intellij.openapi.application.ModalityState in project intellij-community by JetBrains.
the class LiveTemplateSettingsEditor method focusKey.
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(() -> ApplicationManager.getApplication().invokeLater(() -> ApplicationManager.getApplication().invokeLater(() -> IdeFocusManager.findInstanceByComponent(myKeyField).requestFocus(myKeyField, true), modalityState), modalityState), modalityState);
}
use of com.intellij.openapi.application.ModalityState in project intellij-community by JetBrains.
the class FindPopupPanel method findSettingsChanged.
private void findSettingsChanged() {
if (isShowing()) {
ScrollingUtil.ensureSelectionExists(myResultsPreviewTable);
}
final ModalityState state = ModalityState.current();
finishPreviousPreviewSearch();
mySearchRescheduleOnCancellationsAlarm.cancelAllRequests();
applyTo(myHelper.getModel(), false);
myHelper.updateFindSettings();
FindModel findInProjectModel = FindManager.getInstance(myProject).getFindInProjectModel();
FindModel copy = new FindModel();
copy.copyFrom(findInProjectModel);
findInProjectModel.copyFrom(myHelper.getModel());
//todo check if we really need to do it now
((FindManagerImpl) FindManager.getInstance(myProject)).changeGlobalSettings(myHelper.getModel());
FindSettings findSettings = FindSettings.getInstance();
myScopeUI.applyTo(findSettings, mySelectedScope);
findSettings.setFileMask(myHelper.getModel().getFileFilter());
ValidationInfo result = getValidationInfo(myHelper.getModel());
final ProgressIndicatorBase progressIndicatorWhenSearchStarted = new ProgressIndicatorBase();
myResultsPreviewSearchProgress = progressIndicatorWhenSearchStarted;
final DefaultTableModel model = new DefaultTableModel() {
@Override
public boolean isCellEditable(int row, int column) {
return false;
}
};
model.addColumn("Usages");
// Use previously shown usage files as hint for faster search and better usage preview performance if pattern length increased
final LinkedHashSet<VirtualFile> filesToScanInitially = new LinkedHashSet<>();
if (myHelper.myPreviousModel != null && myHelper.myPreviousModel.getStringToFind().length() < myHelper.getModel().getStringToFind().length()) {
final DefaultTableModel previousModel = (DefaultTableModel) myResultsPreviewTable.getModel();
for (int i = 0, len = previousModel.getRowCount(); i < len; ++i) {
final UsageInfo2UsageAdapter usage = (UsageInfo2UsageAdapter) previousModel.getValueAt(i, 0);
final VirtualFile file = usage.getFile();
if (file != null)
filesToScanInitially.add(file);
}
}
myHelper.myPreviousModel = myHelper.getModel().clone();
myCodePreviewComponent.setVisible(false);
mySearchTextArea.setInfoText(null);
myResultsPreviewTable.setModel(model);
if (result != null) {
myResultsPreviewTable.getEmptyText().setText(UIBundle.message("message.nothingToShow") + " (" + result.message + ")");
return;
}
myResultsPreviewTable.getColumnModel().getColumn(0).setCellRenderer(new FindDialog.UsageTableCellRenderer(myCbFileFilter.isSelected(), false));
myResultsPreviewTable.getEmptyText().setText("Searching...");
final AtomicInteger resultsCount = new AtomicInteger();
final AtomicInteger resultsFilesCount = new AtomicInteger();
ProgressIndicatorUtils.scheduleWithWriteActionPriority(myResultsPreviewSearchProgress, new ReadTask() {
@Override
public void computeInReadAction(@NotNull ProgressIndicator indicator) {
final UsageViewPresentation presentation = FindInProjectUtil.setupViewPresentation(findSettings.isShowResultsInSeparateView(), /*findModel*/
myHelper.getModel().clone());
final boolean showPanelIfOnlyOneUsage = !findSettings.isSkipResultsWithOneUsage();
final FindUsagesProcessPresentation processPresentation = FindInProjectUtil.setupProcessPresentation(myProject, showPanelIfOnlyOneUsage, presentation);
Ref<VirtualFile> lastUsageFileRef = new Ref<>();
FindInProjectUtil.findUsages(myHelper.getModel().clone(), myProject, info -> {
final Usage usage = UsageInfo2UsageAdapter.CONVERTER.fun(info);
usage.getPresentation().getIcon();
VirtualFile file = lastUsageFileRef.get();
VirtualFile usageFile = info.getVirtualFile();
if (file == null || !file.equals(usageFile)) {
resultsFilesCount.incrementAndGet();
lastUsageFileRef.set(usageFile);
}
ApplicationManager.getApplication().invokeLater(() -> {
model.addRow(new Object[] { usage });
myCodePreviewComponent.setVisible(true);
if (model.getRowCount() == 1 && myResultsPreviewTable.getModel() == model) {
myResultsPreviewTable.setRowSelectionInterval(0, 0);
}
}, state);
return resultsCount.incrementAndGet() < ShowUsagesAction.USAGES_PAGE_SIZE;
}, processPresentation, filesToScanInitially);
boolean succeeded = !progressIndicatorWhenSearchStarted.isCanceled();
if (succeeded) {
ApplicationManager.getApplication().invokeLater(() -> {
if (progressIndicatorWhenSearchStarted == myResultsPreviewSearchProgress && !myResultsPreviewSearchProgress.isCanceled()) {
int occurrences = resultsCount.get();
int filesWithOccurrences = resultsFilesCount.get();
if (occurrences == 0)
myResultsPreviewTable.getEmptyText().setText(UIBundle.message("message.nothingToShow"));
myCodePreviewComponent.setVisible(occurrences > 0);
StringBuilder info = new StringBuilder();
if (occurrences > 0) {
info.append(Math.min(ShowUsagesAction.USAGES_PAGE_SIZE, occurrences));
boolean foundAllUsages = occurrences < ShowUsagesAction.USAGES_PAGE_SIZE;
if (!foundAllUsages) {
info.append("+");
}
info.append(UIBundle.message("message.matches", occurrences));
info.append(" in ");
info.append(filesWithOccurrences);
if (!foundAllUsages) {
info.append("+");
}
info.append(UIBundle.message("message.files", filesWithOccurrences));
}
mySearchTextArea.setInfoText(info.toString());
}
}, state);
}
}
@Override
public void onCanceled(@NotNull ProgressIndicator indicator) {
if (isShowing() && progressIndicatorWhenSearchStarted == myResultsPreviewSearchProgress) {
scheduleResultsUpdate();
}
}
});
}
use of com.intellij.openapi.application.ModalityState in project intellij-community by JetBrains.
the class LibrariesDownloadUiUtil method loadItems.
private static void loadItems(@NotNull final JComboBox jComboBox, final List<Object> items, final String groupId, final URL... localUrls) {
final ModalityState state = ModalityState.current();
ApplicationManager.getApplication().executeOnPooledThread(() -> {
final List<Object> newItems = new ArrayList<>();
newItems.addAll(Arrays.asList(LibrariesDownloadAssistant.getVersions(groupId, localUrls)));
ApplicationManager.getApplication().invokeLater(() -> {
items.clear();
if (!newItems.isEmpty()) {
items.addAll(newItems);
final CollectionComboBoxModel model = (CollectionComboBoxModel) jComboBox.getModel();
model.update();
jComboBox.setSelectedIndex(0);
}
jComboBox.setEnabled(true);
}, state);
});
}
Aggregations