Java Code Examples for com.intellij.openapi.application.Application#isDisposed()

The following examples show how to use com.intellij.openapi.application.Application#isDisposed() . 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: VirtualFileManagerImpl.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Override
public void notifyPropertyChanged(@Nonnull final VirtualFile virtualFile, @Nonnull final String property, final Object oldValue, final Object newValue) {
  final Application application = ApplicationManager.getApplication();
  final Runnable runnable = new Runnable() {
    @Override
    public void run() {
      if (virtualFile.isValid() && !application.isDisposed()) {
        application.runWriteAction(new Runnable() {
          @Override
          public void run() {
            List<VFilePropertyChangeEvent> events = Collections.singletonList(new VFilePropertyChangeEvent(this, virtualFile, property, oldValue, newValue, false));
            BulkFileListener listener = application.getMessageBus().syncPublisher(VirtualFileManager.VFS_CHANGES);
            listener.before(events);
            listener.after(events);
          }
        });
      }
    }
  };
  application.invokeLater(runnable, ModalityState.NON_MODAL);
}
 
Example 2
Source File: IndexInfrastructure.java    From consulo with Apache License 2.0 6 votes vote down vote up
private void executeNestedInitializationTask(@Nonnull ThrowableRunnable<?> callable, CountDownLatch proceedLatch) {
  Application app = ApplicationManager.getApplication();
  try {
    // To correctly apply file removals in indices's shutdown hook we should process all initialization tasks
    // Todo: make processing removed files more robust because ignoring 'dispose in progress' delays application exit and
    // may cause memory leaks IDEA-183718, IDEA-169374,
    if (app.isDisposed() /*|| app.isDisposeInProgress()*/) return;
    callable.run();
  }
  catch (Throwable t) {
    onThrowable(t);
  }
  finally {
    proceedLatch.countDown();
  }
}
 
Example 3
Source File: HttpRequests.java    From leetcode-editor with Apache License 2.0 5 votes vote down vote up
@Override
public RequestBuilder productNameAsUserAgent() {
    Application app = ApplicationManager.getApplication();
    if (app != null && !app.isDisposed()) {
        String productName = ApplicationNamesInfo.getInstance().getFullProductName();
        String version = ApplicationInfo.getInstance().getBuild().asStringWithoutProductCode();
        return userAgent(productName + '/' + version);
    }
    else {
        return userAgent("IntelliJ");
    }
}
 
Example 4
Source File: IdeaWideAuthenticator.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public PasswordAuthentication getPasswordAuthentication() {
  final String host = CommonProxy.getHostNameReliably(getRequestingHost(), getRequestingSite(), getRequestingURL());
  final boolean isProxy = Authenticator.RequestorType.PROXY.equals(getRequestorType());
  final String prefix = isProxy ? "Proxy authentication: " : "Server authentication: ";
  Application application = ApplicationManager.getApplication();
  if (isProxy) {
    // according to idea-wide settings
    if (myHttpConfigurable.USE_HTTP_PROXY) {
      LOG.debug("CommonAuthenticator.getPasswordAuthentication will return common defined proxy");
      return myHttpConfigurable.getPromptedAuthentication(host + ":" + getRequestingPort(), getRequestingPrompt());
    }
    else if (myHttpConfigurable.USE_PROXY_PAC) {
      LOG.debug("CommonAuthenticator.getPasswordAuthentication will return autodetected proxy");
      if (myHttpConfigurable.isGenericPasswordCanceled(host, getRequestingPort())) return null;
      // same but without remembering the results..
      final PasswordAuthentication password = myHttpConfigurable.getGenericPassword(host, getRequestingPort());
      if (password != null) {
        return password;
      }
      // do not try to show any dialogs if application is exiting
      if (application == null || application.isDisposeInProgress() ||
          application.isDisposed()) {
        return null;
      }

      return myHttpConfigurable.getGenericPromptedAuthentication(prefix, host, getRequestingPrompt(), getRequestingPort(), true);
    }
  }

  // do not try to show any dialogs if application is exiting
  if (application == null || application.isDisposeInProgress() || application.isDisposed()) {
    return null;
  }

  LOG.debug("CommonAuthenticator.getPasswordAuthentication generic authentication will be asked");
  //return myHttpConfigurable.getGenericPromptedAuthentication(prefix, host, getRequestingPrompt(), getRequestingPort(), false);
  return null;
}
 
Example 5
Source File: HttpRequests.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public RequestBuilder productNameAsUserAgent() {
  Application app = ApplicationManager.getApplication();
  if (app != null && !app.isDisposed()) {
    ApplicationInfo info = ApplicationInfo.getInstance();
    return userAgent(info.getVersionName() + '/' + info.getBuild().asString());
  }
  else {
    return userAgent("Consulo");
  }
}
 
Example 6
Source File: Notifications.java    From consulo with Apache License 2.0 5 votes vote down vote up
private static void doNotify(Notification notification, @Nullable Project project) {
  if (project != null && !project.isDisposed()) {
    project.getMessageBus().syncPublisher(TOPIC).notify(notification);
  } else {
    Application app = Application.get();
    if (!app.isDisposed()) {
      app.getMessageBus().syncPublisher(TOPIC).notify(notification);
    }
  }
}
 
Example 7
Source File: Responses.java    From consulo with Apache License 2.0 5 votes vote down vote up
private static String getServerHeaderValue() {
  if (SERVER_HEADER_VALUE == null) {
    Application app = ApplicationManager.getApplication();
    if (app != null && !app.isDisposed()) {
      SERVER_HEADER_VALUE = ApplicationNamesInfo.getInstance().getFullProductName();
    }
  }
  return SERVER_HEADER_VALUE;
}
 
Example 8
Source File: Responses.java    From consulo with Apache License 2.0 5 votes vote down vote up
public static void addServer(HttpResponse response) {
  if (SERVER_HEADER_VALUE == null) {
    Application app = ApplicationManager.getApplication();
    if (app != null && !app.isDisposed()) {
      SERVER_HEADER_VALUE = ApplicationNamesInfo.getInstance().getFullProductName();
    }
  }
  if (SERVER_HEADER_VALUE != null) {
    response.headers().set("Server", SERVER_HEADER_VALUE);
  }
}
 
Example 9
Source File: DesktopSaveAndSyncHandlerImpl.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public void saveProjectsAndDocuments() {
  Application app = ApplicationManager.getApplication();
  if (!app.isDisposed() &&
      mySettings.isSaveOnFrameDeactivation() &&
      myBlockSaveOnFrameDeactivationCount.get() == 0) {
    app.saveAll();
  }
}
 
Example 10
Source File: ChangelistConflictTracker.java    From consulo with Apache License 2.0 4 votes vote down vote up
public ChangelistConflictTracker(@Nonnull Project project,
                                 @Nonnull ChangeListManager changeListManager,
                                 @Nonnull FileStatusManager fileStatusManager,
                                 @Nonnull EditorNotifications editorNotifications) {
  myProject = project;

  myChangeListManager = changeListManager;
  myEditorNotifications = editorNotifications;
  myDocumentManager = FileDocumentManager.getInstance();
  myFileStatusManager = fileStatusManager;
  myCheckSetLock = new Object();
  myCheckSet = new HashSet<>();

  final Application application = ApplicationManager.getApplication();
  final ZipperUpdater zipperUpdater = new ZipperUpdater(300, Alarm.ThreadToUse.SWING_THREAD, project);
  final Runnable runnable = () -> {
    if (application.isDisposed() || myProject.isDisposed() || !myProject.isOpen()) {
      return;
    }
    final Set<VirtualFile> localSet;
    synchronized (myCheckSetLock) {
      localSet = new HashSet<>();
      localSet.addAll(myCheckSet);
      myCheckSet.clear();
    }
    checkFiles(localSet);
  };
  myDocumentListener = new DocumentAdapter() {
    @Override
    public void documentChanged(DocumentEvent e) {
      if (!myOptions.TRACKING_ENABLED) {
        return;
      }
      Document document = e.getDocument();
      VirtualFile file = myDocumentManager.getFile(document);
      if (ProjectUtil.guessProjectForFile(file) == myProject) {
        synchronized (myCheckSetLock) {
          myCheckSet.add(file);
        }
        zipperUpdater.queue(runnable);
      }
    }
  };

  myChangeListListener = new ChangeListAdapter() {
    @Override
    public void changeListChanged(ChangeList list) {
      if (myChangeListManager.isDefaultChangeList(list)) {
        clearChanges(list.getChanges());
      }
    }

    @Override
    public void changesMoved(Collection<Change> changes, ChangeList fromList, ChangeList toList) {
      if (myChangeListManager.isDefaultChangeList(toList)) {
        clearChanges(changes);
      }
    }

    @Override
    public void changesRemoved(Collection<Change> changes, ChangeList fromList) {
      clearChanges(changes);
    }

    @Override
    public void defaultListChanged(ChangeList oldDefaultList, ChangeList newDefaultList) {
      clearChanges(newDefaultList.getChanges());
    }
  };
}