Java Code Examples for com.intellij.openapi.util.Disposer#register()

The following examples show how to use com.intellij.openapi.util.Disposer#register() . 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: LatexEditorActionsLoaderComponent.java    From idea-latex with MIT License 6 votes vote down vote up
/**
 * Handles file opening event and attaches LaTeX editor component.
 *
 * @param source editor manager
 * @param file   current file
 */
@Override
public void fileOpened(@NotNull final FileEditorManager source, @NotNull final VirtualFile file) {
    FileType fileType = file.getFileType();
    if (!(fileType instanceof LatexFileType)) {
        return;
    }

    for (final FileEditor fileEditor : source.getEditors(file)) {
        if (fileEditor instanceof TextEditor) {
            final LatexEditorActionsWrapper wrapper = new LatexEditorActionsWrapper(fileEditor);
            final JComponent c = wrapper.getComponent();
            source.addTopComponent(fileEditor, c);

            Disposer.register(fileEditor, wrapper);
            Disposer.register(fileEditor, new Disposable() {
                @Override
                public void dispose() {
                    source.removeTopComponent(fileEditor, c);
                }
            });
        }
    }
}
 
Example 2
Source File: FlutterDartAnalysisServer.java    From flutter-intellij with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@VisibleForTesting
public FlutterDartAnalysisServer(@NotNull Project project) {
  analysisService = DartPlugin.getInstance().getAnalysisService(project);
  analysisService.addResponseListener(new CompatibleResponseListener());
  analysisService.addAnalysisServerListener(new AnalysisServerListenerAdapter() {
    @Override
    public void serverConnected(String s) {
      // If the server reconnected we need to let it know that we still care
      // about our subscriptions.
      if (!subscriptions.isEmpty()) {
        sendSubscriptions();
      }
    }
  });
  Disposer.register(project, this);
}
 
Example 3
Source File: SmRunnerUtils.java    From intellij with Apache License 2.0 6 votes vote down vote up
public static SMTRunnerConsoleView getConsoleView(
    Project project,
    BlazeCommandRunConfiguration configuration,
    Executor executor,
    BlazeTestUiSession testUiSession) {
  SMTRunnerConsoleProperties properties =
      new BlazeTestConsoleProperties(configuration, executor, testUiSession);
  SMTRunnerConsoleView console =
      (SMTRunnerConsoleView)
          SMTestRunnerConnectionUtil.createConsole(BLAZE_FRAMEWORK, properties);
  Disposer.register(project, console);
  console
      .getResultsViewer()
      .getTreeView()
      .getSelectionModel()
      .setSelectionMode(TreeSelectionModel.DISCONTIGUOUS_TREE_SELECTION);
  return console;
}
 
Example 4
Source File: FlutterConsole.java    From flutter-intellij with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@NotNull
static FlutterConsole create(@NotNull Project project, @Nullable Module module) {
  final TextConsoleBuilder builder = TextConsoleBuilderFactory.getInstance().createBuilder(project);
  builder.setViewer(true);
  if (module != null) {
    builder.addFilter(new FlutterConsoleFilter(module));
  }
  final ConsoleView view = builder.getConsole();

  final SimpleToolWindowPanel panel = new SimpleToolWindowPanel(false, true);
  panel.setContent(view.getComponent());

  final String title = module != null ? "[" + module.getName() + "] Flutter" : "Flutter";
  final Content content = ContentFactory.SERVICE.getInstance().createContent(panel.getComponent(), title, true);
  Disposer.register(content, view);

  return new FlutterConsole(view, content, project, module);
}
 
Example 5
Source File: ComponentStructureView.java    From litho with Apache License 2.0 5 votes vote down vote up
synchronized void setup(ToolWindow toolWindow) {
  contentManager = toolWindow.getContentManager();
  Disposer.register(contentManager, this);
  refreshButton = createButton("Update", this::update);
  contentContainer =
      ContentFactory.SERVICE
          .getInstance()
          .createContent(createView(refreshButton, STUB), "", false);
  contentManager.addContent(contentContainer);
  DumbService.getInstance(project).smartInvokeLater(this::update);
}
 
Example 6
Source File: ServiceHelper.java    From intellij with Apache License 2.0 5 votes vote down vote up
public static <T> void registerExtensionPoint(
    ExtensionPointName<T> name, Class<T> clazz, Disposable parentDisposable) {
  ExtensionsArea area = Extensions.getRootArea();
  String epName = name.getName();
  area.registerExtensionPoint(epName, clazz.getName());
  Disposer.register(parentDisposable, () -> area.unregisterExtensionPoint(epName));
}
 
Example 7
Source File: MessageBusClient.java    From p4ic4idea with Apache License 2.0 5 votes vote down vote up
@NotNull
public static ProjectClient forProject(@NotNull Project project, @NotNull Disposable owner) {
    ProjectClient ret = new ProjectClient(project.getMessageBus().connect(owner));
    // Just to be sure...
    Disposer.register(owner, ret::close);
    return ret;
}
 
Example 8
Source File: FlutterAppManager.java    From flutter-intellij with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private FlutterAppManager(@NotNull Project project) {
  this.project = project;

  Disposer.register(project, this);

  task = JobScheduler.getScheduler().scheduleWithFixedDelay(
    this::updateActiveApp, 1, 1, TimeUnit.SECONDS);
}
 
Example 9
Source File: DeviceChooserDialog.java    From ADBWIFI with Apache License 2.0 5 votes vote down vote up
public DeviceChooserDialog(@NotNull final AndroidFacet facet) {
    super(facet.getModule().getProject(), true);
    setTitle(AndroidBundle.message("choose.device.dialog.title"));

    myProject = facet.getModule().getProject();
    final PropertiesComponent properties = PropertiesComponent.getInstance(myProject);

    getOKAction().setEnabled(false);

    myDeviceChooser = new MyDeviceChooser(true, getOKAction(), facet, facet.getConfiguration().getAndroidTarget(), null);
    Disposer.register(myDisposable, myDeviceChooser);
    myDeviceChooser.addListener(new DeviceChooserListener() {
        @Override
        public void selectedDevicesChanged() {
                updateOkButton();
        }
    });

    myDeviceChooserWrapper.add(myDeviceChooser.getPanel());

    final String[] selectedSerials = getSelectedSerialsFromPreferences(properties);
    myDeviceChooser.init(selectedSerials);

    init();

    updateEnabled();
}
 
Example 10
Source File: DeviceService.java    From flutter-intellij with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private DeviceService(@NotNull final Project project) {
  this.project = project;

  deviceDaemon.setDisposeParent(project);
  deviceDaemon.subscribe(this::refreshDeviceSelection);
  refreshDeviceDaemon();

  // Watch for Flutter SDK changes.
  final FlutterSdkManager.Listener sdkListener = new FlutterSdkManager.Listener() {
    @Override
    public void flutterSdkAdded() {
      refreshDeviceDaemon();
    }

    @Override
    public void flutterSdkRemoved() {
      refreshDeviceDaemon();
    }
  };
  FlutterSdkManager.getInstance(project).addListener(sdkListener);
  Disposer.register(project, () -> FlutterSdkManager.getInstance(project).removeListener(sdkListener));

  // Watch for Bazel workspace changes.
  WorkspaceCache.getInstance(project).subscribe(this::refreshDeviceDaemon);

  // Watch for Java SDK changes. (Used to get the value of ANDROID_HOME.)
  ProjectRootManagerEx.getInstanceEx(project).addProjectJdkListener(this::refreshDeviceDaemon);
}
 
Example 11
Source File: ComponentStructureView.java    From litho with Apache License 2.0 5 votes vote down vote up
private static StructureView createStructureView(
    LayoutSpecModel model, FileEditor selectedEditor, PsiFile selectedFile, Project project) {
  final StructureViewModel viewModel = ComponentTreeModel.create(selectedFile, model);
  final StructureView view =
      StructureViewFactory.getInstance(project)
          .createStructureView(selectedEditor, viewModel, project, true);
  Disposer.register(view, viewModel);
  return view;
}
 
Example 12
Source File: SlingMavenModuleBuilder.java    From aem-ide-tooling-4-intellij with Apache License 2.0 5 votes vote down vote up
@Nullable
@Override
public ModuleWizardStep getCustomOptionsStep(WizardContext context, Disposable parentDisposable) {
    // Prepare the Sling / AEM Archetypes for IntelliJ
    if(archetypeTemplateList.isEmpty()) {
        archetypeTemplateList = obtainArchetypes();
    }
    List<ArchetypeTemplate> list = context.getProject() == null ? archetypeTemplateList : new ArrayList<ArchetypeTemplate>();
    // Instead of displaying a List of All Maven Archetypes we just show the ones applicable.
    SlingArchetypesStep step = new SlingArchetypesStep(this, list);
    Disposer.register(parentDisposable, step);
    return step;
}
 
Example 13
Source File: EsyToolWindowFactory.java    From reasonml-idea-plugin with MIT License 4 votes vote down vote up
@Override
public void createToolWindowContent(@NotNull final Project project, @NotNull ToolWindow window) {
    SimpleToolWindowPanel panel = new SimpleToolWindowPanel(false, true);

    BsConsole console = new BsConsole(project);
    panel.setContent(console.getComponent());

    ActionToolbar toolbar = createToolbar(console);
    panel.setToolbar(toolbar.getComponent());

    Content content = ContentFactory.SERVICE.getInstance().createContent(panel, "", true);

    window.getContentManager().addContent(content);

    Disposer.register(project, console);
}
 
Example 14
Source File: ServiceHelper.java    From intellij with Apache License 2.0 4 votes vote down vote up
public static <T> void registerExtension(
    ExtensionPointName<T> name, T instance, Disposable parentDisposable) {
  ExtensionPoint<T> ep = Extensions.getRootArea().getExtensionPoint(name);
  ep.registerExtension(instance);
  Disposer.register(parentDisposable, () -> ep.unregisterExtension(instance));
}
 
Example 15
Source File: PantsConsoleManager.java    From intellij-pants-plugin with Apache License 2.0 4 votes vote down vote up
public PantsConsoleManager(Project project) {
  myConsole = createNewConsole(project);

  Disposer.register(project, myConsole); // for some reason extending Disposable results in leaked resources
  initializeConsolePanel(project, myConsole);
}
 
Example 16
Source File: InspectorGroupManagerService.java    From flutter-intellij with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
public InspectorGroupManagerService(Project project) {
  FlutterAppManager.getInstance(project).getActiveAppAsStream().listen(
    this::updateActiveApp, true);
  Disposer.register(project, this);
}
 
Example 17
Source File: WorkspacePathResolverProviderImpl.java    From intellij with Apache License 2.0 4 votes vote down vote up
@Override
public void setTemporaryOverride(WorkspacePathResolver resolver, Disposable parentDisposable) {
  tempOverride = resolver;
  Disposer.register(parentDisposable, () -> tempOverride = null);
}
 
Example 18
Source File: FlutterApp.java    From flutter-intellij with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
/**
 * Creates a process that will launch the flutter app.
 * <p>
 * (Assumes we are launching it in --machine mode.)
 */
@NotNull
public static FlutterApp start(@NotNull ExecutionEnvironment env,
                               @NotNull Project project,
                               @Nullable Module module,
                               @NotNull RunMode mode,
                               @NotNull FlutterDevice device,
                               @NotNull GeneralCommandLine command,
                               @Nullable String analyticsStart,
                               @Nullable String analyticsStop)
  throws ExecutionException {
  LOG.info(analyticsStart + " " + project.getName() + " (" + mode.mode() + ")");
  LOG.info(command.toString());

  final ProcessHandler process = new MostlySilentOsProcessHandler(command);
  Disposer.register(project, process::destroyProcess);

  // Send analytics for the start and stop events.
  if (analyticsStart != null) {
    FlutterInitializer.sendAnalyticsAction(analyticsStart);
  }

  final DaemonApi api = new DaemonApi(process);
  final FlutterApp app = new FlutterApp(project, module, mode, device, process, env, api, command);

  process.addProcessListener(new ProcessAdapter() {
    @Override
    public void processTerminated(@NotNull ProcessEvent event) {
      LOG.info(analyticsStop + " " + project.getName() + " (" + mode.mode() + ")");
      if (analyticsStop != null) {
        FlutterInitializer.sendAnalyticsAction(analyticsStop);
      }

      // Send analytics about whether this session used the reload workflow, the restart workflow, or neither.
      final String workflowType = app.reloadCount > 0 ? "reload" : (app.restartCount > 0 ? "restart" : "none");
      FlutterInitializer.getAnalytics().sendEvent("workflow", workflowType);

      // Send the ratio of reloads to restarts.
      int reloadfraction = 0;
      if ((app.reloadCount + app.restartCount) > 0) {
        final double fraction = (app.reloadCount * 100.0) / (app.reloadCount + app.restartCount);
        reloadfraction = (int)Math.round(fraction);
      }
      FlutterInitializer.getAnalytics().sendEventMetric("workflow", "reloadFraction", reloadfraction);

      Disposer.dispose(app);
    }
  });

  api.listen(process, new FlutterAppDaemonEventListener(app, project));

  return app;
}
 
Example 19
Source File: EditorEventServiceBase.java    From flutter-intellij with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
public EditorEventServiceBase(Project project) {
  this.project = project;
  Disposer.register(project, this);
}
 
Example 20
Source File: AsposeMavenModuleBuilder.java    From Aspose.OCR-for-Java with MIT License 4 votes vote down vote up
@Nullable
public ModuleWizardStep getCustomOptionsStep(WizardContext context, Disposable parentDisposable) {
    AsposeIntroWizardStep step = new AsposeIntroWizardStep();
    Disposer.register(parentDisposable, step);
    return step;
}