use of com.intellij.openapi.application.TransactionId in project intellij-community by JetBrains.
the class CheckRegExpForm method createUIComponents.
private void createUIComponents() {
myProject = myRegexpFile.getProject();
Document document = PsiDocumentManager.getInstance(myProject).getDocument(myRegexpFile);
final Language language = myRegexpFile.getLanguage();
final LanguageFileType fileType;
if (language instanceof RegExpLanguage) {
fileType = RegExpLanguage.INSTANCE.getAssociatedFileType();
} else {
// for correct syntax highlighting
fileType = new RegExpFileType(language);
}
myRegExp = new EditorTextField(document, myProject, fileType);
final String sampleText = PropertiesComponent.getInstance(myProject).getValue(LAST_EDITED_REGEXP, "Sample Text");
mySampleText = new EditorTextField(sampleText, myProject, PlainTextFileType.INSTANCE) {
@Override
protected void updateBorder(@NotNull EditorEx editor) {
setupBorder(editor);
}
};
mySampleText.setOneLineMode(false);
int preferredWidth = Math.max(JBUI.scale(250), myRegExp.getPreferredSize().width);
myRegExp.setPreferredWidth(preferredWidth);
mySampleText.setPreferredWidth(preferredWidth);
myRootPanel = new JPanel(new BorderLayout()) {
Disposable disposable;
Alarm updater;
@Override
public void addNotify() {
super.addNotify();
disposable = Disposer.newDisposable();
IdeFocusManager.getGlobalInstance().requestFocus(mySampleText, true);
new AnAction() {
@Override
public void actionPerformed(AnActionEvent e) {
IdeFocusManager.findInstance().requestFocus(myRegExp.getFocusTarget(), true);
}
}.registerCustomShortcutSet(CustomShortcutSet.fromString("shift TAB"), mySampleText);
updater = new Alarm(Alarm.ThreadToUse.POOLED_THREAD, disposable);
DocumentAdapter documentListener = new DocumentAdapter() {
@Override
public void documentChanged(DocumentEvent e) {
update();
}
};
myRegExp.addDocumentListener(documentListener);
mySampleText.addDocumentListener(documentListener);
update();
mySampleText.selectAll();
}
public void update() {
final TransactionId transactionId = TransactionGuard.getInstance().getContextTransaction();
updater.cancelAllRequests();
if (!updater.isDisposed()) {
updater.addRequest(() -> {
final RegExpMatchResult result = isMatchingText(myRegexpFile, mySampleText.getText());
TransactionGuard.getInstance().submitTransaction(myProject, transactionId, () -> setBalloonState(result));
}, 200);
}
}
@Override
public void removeNotify() {
super.removeNotify();
Disposer.dispose(disposable);
PropertiesComponent.getInstance(myProject).setValue(LAST_EDITED_REGEXP, mySampleText.getText());
}
};
myRootPanel.setBorder(JBUI.Borders.empty(UIUtil.DEFAULT_VGAP, UIUtil.DEFAULT_HGAP));
}
use of com.intellij.openapi.application.TransactionId in project intellij-community by JetBrains.
the class AutoPopupController method runTransactionWithEverythingCommitted.
public static void runTransactionWithEverythingCommitted(@NotNull final Project project, @NotNull final Runnable runnable) {
TransactionGuard guard = TransactionGuard.getInstance();
TransactionId id = guard.getContextTransaction();
final PsiDocumentManager pdm = PsiDocumentManager.getInstance(project);
pdm.performLaterWhenAllCommitted(() -> guard.submitTransaction(project, id, () -> {
if (pdm.hasUncommitedDocuments()) {
// no luck, will try later
runTransactionWithEverythingCommitted(project, runnable);
} else {
runnable.run();
}
}));
}
use of com.intellij.openapi.application.TransactionId in project intellij-community by JetBrains.
the class InferNullityAnnotationsAction method restartAnalysis.
protected void restartAnalysis(final Project project, final AnalysisScope scope) {
TransactionGuard guard = TransactionGuard.getInstance();
TransactionId id = guard.getContextTransaction();
DumbService.getInstance(project).smartInvokeLater(() -> TransactionGuard.getInstance().submitTransaction(project, id, () -> {
if (DumbService.isDumb(project)) {
restartAnalysis(project, scope);
} else {
analyze(project, scope);
}
}));
}
Aggregations