本文整理匯總了Java中com.intellij.openapi.application.ModalityState類的典型用法代碼示例。如果您正苦於以下問題:Java ModalityState類的具體用法?Java ModalityState怎麽用?Java ModalityState使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
ModalityState類屬於com.intellij.openapi.application包,在下文中一共展示了ModalityState類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: smartInvokeAndWait
import com.intellij.openapi.application.ModalityState; //導入依賴的package包/類
public static void smartInvokeAndWait(final Project p, final ModalityState state, final Runnable r) {
if (isNoBackgroundMode() || ApplicationManager.getApplication().isDispatchThread()) {
r.run();
} else {
final Semaphore semaphore = new Semaphore();
semaphore.down();
DumbService.getInstance(p).smartInvokeLater(() -> {
try {
r.run();
} finally {
semaphore.up();
}
}, state);
semaphore.waitFor();
}
}
示例2: asyncCheckErrors
import com.intellij.openapi.application.ModalityState; //導入依賴的package包/類
private void asyncCheckErrors(@NotNull final Collection<VirtualFile> files,
@NotNull final Consumer<Boolean> errorsFoundConsumer) {
ApplicationManager.getApplication().executeOnPooledThread(new Runnable() {
@Override
public void run() {
final boolean errorsFound = ApplicationManager.getApplication().runReadAction(new Computable<Boolean>() {
@Override
public Boolean compute() {
for (VirtualFile file : files) {
if (PsiErrorElementUtil.hasErrors(myProject, file)) {
return true;
}
}
return false;
}
});
ApplicationManager.getApplication().invokeLater(new Runnable() {
@Override
public void run() {
errorsFoundConsumer.consume(errorsFound);
}
}, ModalityState.any());
}
});
}
示例3: findCurrentDirectory
import com.intellij.openapi.application.ModalityState; //導入依賴的package包/類
public static PsiDirectory findCurrentDirectory(Project project, VirtualFile file) {
final PsiDirectory[] result = new PsiDirectory[1];
ApplicationManager.getApplication().invokeAndWait(() ->
result[0] = ApplicationManager.getApplication().runReadAction((Computable<PsiDirectory>) () -> {
if (file == null || project == null) {
return null;
}
if (file.isDirectory()) {
return PsiManager.getInstance(project).findDirectory(file);
} else {
return PsiManager.getInstance(project).findDirectory(file.getParent());
}
})
, ModalityState.defaultModalityState());
return result[0];
}
示例4: verifyServerHostKey
import com.intellij.openapi.application.ModalityState; //導入依賴的package包/類
public boolean verifyServerHostKey(final String hostname,
final int port,
final String serverHostKeyAlgorithm,
final String fingerprint,
final boolean isNew) {
final String message;
if (isNew) {
message = GitBundle.message("ssh.new.host.key", hostname, port, fingerprint, serverHostKeyAlgorithm);
}
else {
message = GitBundle.message("ssh.changed.host.key", hostname, port, fingerprint, serverHostKeyAlgorithm);
}
final AtomicBoolean rc = new AtomicBoolean();
ApplicationManager.getApplication().invokeAndWait(new Runnable() {
public void run() {
rc.set(Messages.YES == Messages.showYesNoDialog(myProject, message, GitBundle.getString("ssh.confirm.key.titile"), null));
}
}, ModalityState.any());
return rc.get();
}
示例5: setupSdkPaths
import com.intellij.openapi.application.ModalityState; //導入依賴的package包/類
public void setupSdkPaths(final Sdk sdk, @Nullable final Project project, @Nullable final Component ownerComponent) {
scheduledToRefresh.add(sdk.getHomePath());
ApplicationManager.getApplication().invokeLater(new Runnable() {
@Override
public void run() {
try {
final boolean success = doSetupSdkPaths(project, ownerComponent, PySdkUpdater.fromSdkPath(sdk.getHomePath()));
if (!success) {
Messages.showErrorDialog(
project,
PyBundle.message("MSG.cant.setup.sdk.$0", FileUtil.toSystemDependentName(sdk.getSdkModificator().getHomePath())),
PyBundle.message("MSG.title.bad.sdk")
);
}
}
catch (PySdkUpdater.PySdkNotFoundException e) {
// sdk was removed from sdk table so no need to setup paths
}
}
}, ModalityState.NON_MODAL);
}
示例6: addAlarmRequest
import com.intellij.openapi.application.ModalityState; //導入依賴的package包/類
private void addAlarmRequest(){
Runnable request = new Runnable(){
@Override
public void run(){
if (!myDisposed && !myProject.isDisposed()) {
DumbService.getInstance(myProject).withAlternativeResolveEnabled(new Runnable() {
@Override
public void run() {
updateComponent();
}
});
}
}
};
myAlarm.addRequest(request, DELAY, ModalityState.stateForComponent(myEditor.getComponent()));
}
示例7: FindDialog
import com.intellij.openapi.application.ModalityState; //導入依賴的package包/類
public FindDialog(@NotNull Project project, @NotNull FindModel model, @NotNull Consumer<FindModel> myOkHandler){
super(project, true);
myProject = project;
myModel = model;
this.myOkHandler = myOkHandler;
updateTitle();
setOKButtonText(FindBundle.message("find.button"));
init();
initByModel();
updateReplaceVisibility();
if (haveResultsPreview()) {
ApplicationManager.getApplication().invokeLater(new Runnable() {
@Override
public void run() {
scheduleResultsUpdate();
}
}, ModalityState.any());
}
}
示例8: addUpdateRequest
import com.intellij.openapi.application.ModalityState; //導入依賴的package包/類
public void addUpdateRequest(final boolean shouldRefreshSelection) {
final Runnable request = new Runnable() {
@Override
public void run() {
if (!myProject.isDisposed()) {
// Rely on project view to commit PSI and wait until it's updated.
if (myTreeStructure.hasSomethingToCommit() ) {
myUpdateAlarm.cancelAllRequests();
myUpdateAlarm.addRequest(this, 300, ModalityState.stateForComponent(myList));
return;
}
updateList(shouldRefreshSelection);
}
}
};
if (!ApplicationManager.getApplication().isUnitTestMode()) {
myUpdateAlarm.cancelAllRequests();
myUpdateAlarm.addRequest(request, 300, ModalityState.stateForComponent(myList));
}
else {
request.run();
}
}
示例9: switchToCommandMode
import com.intellij.openapi.application.ModalityState; //導入依賴的package包/類
/**
* Switches console to "command-mode" (see class doc for details)
*/
private void switchToCommandMode() {
// "upper" and "bottom" parts of console both need padding in command mode
myProcessHandler = null;
setPrompt(getTitle() + " > ");
ApplicationManager.getApplication().invokeAndWait(new Runnable() {
@Override
public void run() {
notifyStateChangeListeners();
configureLeftBorder(true, getConsoleEditor(), getHistoryViewer());
setLanguage(CommandLineLanguage.INSTANCE);
final CommandLineFile file = PyUtil.as(getFile(), CommandLineFile.class);
resetConsumer(null);
if (file == null || myCommandsAndDefaultExecutor == null) {
return;
}
file.setCommands(myCommandsAndDefaultExecutor.first);
final CommandConsole console = CommandConsole.this;
resetConsumer(new CommandModeConsumer(myCommandsAndDefaultExecutor.first, myModule, console, myCommandsAndDefaultExecutor.second));
}
}, ModalityState.NON_MODAL);
}
示例10: processClose
import com.intellij.openapi.application.ModalityState; //導入依賴的package包/類
private void processClose() {
if (Registry.getInstance().isRestartNeeded()) {
final ApplicationEx app = (ApplicationEx) ApplicationManager.getApplication();
final ApplicationInfo info = ApplicationInfo.getInstance();
final int r = Messages.showOkCancelDialog(myContent, "You need to restart " + info.getVersionName() + " for the changes to take effect", "Restart Required",
app.isRestartCapable() ? "Restart Now" : "Shutdown Now",
app.isRestartCapable() ? "Restart Later": "Shutdown Later"
, Messages.getQuestionIcon());
if (r == Messages.OK) {
ApplicationManager.getApplication().invokeLater(new Runnable() {
@Override
public void run() {
app.restart(true);
}
}, ModalityState.NON_MODAL);
}
}
}
示例11: setMouseSelectionState
import com.intellij.openapi.application.ModalityState; //導入依賴的package包/類
private void setMouseSelectionState(@MouseSelectionState int mouseSelectionState) {
if (getMouseSelectionState() == mouseSelectionState) return;
myMouseSelectionState = mouseSelectionState;
myMouseSelectionChangeTimestamp = System.currentTimeMillis();
myMouseSelectionStateAlarm.cancelAllRequests();
if (myMouseSelectionState != MOUSE_SELECTION_STATE_NONE) {
if (myMouseSelectionStateResetRunnable == null) {
myMouseSelectionStateResetRunnable = new Runnable() {
@Override
public void run() {
resetMouseSelectionState(null);
}
};
}
myMouseSelectionStateAlarm.addRequest(myMouseSelectionStateResetRunnable, Registry.intValue("editor.mouseSelectionStateResetTimeout"),
ModalityState.stateForComponent(myEditorComponent));
}
}
示例12: projectOpened
import com.intellij.openapi.application.ModalityState; //導入依賴的package包/類
@Override
public void projectOpened() {
MessageBusConnection connection = myProject.getMessageBus().connect(myProject);
connection.subscribe(ProjectTopics.PROJECT_ROOTS, new ModuleRootAdapter() {
@Override
public void rootsChanged(ModuleRootEvent event) {
ApplicationManager.getApplication().invokeLater(new Runnable() {
@Override
public void run() {
if (myProject.isDisposed()) return;
VcsDirtyScopeManager.getInstance(myProject).markEverythingDirty();
}
}, ModalityState.NON_MODAL);
}
});
final WolfTheProblemSolver.ProblemListener myProblemListener = new MyProblemListener();
WolfTheProblemSolver.getInstance(myProject).addProblemListener(myProblemListener,myProject);
}
示例13: selectLater
import com.intellij.openapi.application.ModalityState; //導入依賴的package包/類
private void selectLater(final ActionCallback callback, final K key) {
ApplicationManager.getApplication().executeOnPooledThread(new Runnable() {
@Override
public void run() {
if (!myDisposed) {
final UI ui = prepare(key);
ApplicationManager.getApplication().invokeLater(new Runnable() {
@Override
public void run() {
if (!myDisposed) {
select(callback, key, ui);
}
else callback.setRejected();
}
}, ModalityState.any());
}
else callback.setRejected();
}
});
}
示例14: loadModuleInternal
import com.intellij.openapi.application.ModalityState; //導入依賴的package包/類
@NotNull
private Module loadModuleInternal(@NotNull String filePath) throws ModuleWithNameAlreadyExists, IOException {
filePath = resolveShortWindowsName(filePath);
final VirtualFile moduleFile = StandardFileSystems.local().findFileByPath(filePath);
if (moduleFile == null || !moduleFile.exists()) {
throw new FileNotFoundException(ProjectBundle.message("module.file.does.not.exist.error", filePath));
}
String path = moduleFile.getPath();
ModuleEx module = getModuleByFilePath(path);
if (module == null) {
ApplicationManager.getApplication().invokeAndWait(new Runnable() {
@Override
public void run() {
moduleFile.refresh(false, false);
}
}, ModalityState.any());
module = createAndLoadModule(path);
initModule(module, path, null);
}
return module;
}
示例15: confirmUndeploy
import com.intellij.openapi.application.ModalityState; //導入依賴的package包/類
private boolean confirmUndeploy() {
final Ref<Boolean> confirmed = new Ref<Boolean>(false);
ApplicationManager.getApplication().invokeAndWait(new Runnable() {
@Override
public void run() {
String title = CloudBundle.getText("cloud.undeploy.confirm.title");
while (true) {
String password = Messages.showPasswordDialog(CloudBundle.getText("cloud.undeploy.confirm.message", getApplicationName()), title);
if (password == null) {
return;
}
if (password.equals(getServerRuntime().getConfiguration().getPassword())) {
confirmed.set(true);
return;
}
Messages.showErrorDialog(CloudBundle.getText("cloud.undeploy.confirm.password.incorrect"), title);
}
}
}, ModalityState.defaultModalityState());
return confirmed.get();
}