use of com.intellij.openapi.wm.ToolWindow in project intellij-community by JetBrains.
the class RunContentManagerImpl method showRunContent.
private void showRunContent(@NotNull final Executor executor, @NotNull final RunContentDescriptor descriptor, final long executionId) {
if (ApplicationManager.getApplication().isUnitTestMode()) {
return;
}
final ContentManager contentManager = getContentManagerForRunner(executor, descriptor);
RunContentDescriptor oldDescriptor = chooseReuseContentForDescriptor(contentManager, descriptor, executionId, descriptor.getDisplayName());
final Content content;
if (oldDescriptor == null) {
content = createNewContent(descriptor, executor);
} else {
content = oldDescriptor.getAttachedContent();
LOG.assertTrue(content != null);
getSyncPublisher().contentRemoved(oldDescriptor, executor);
// is of the same category, can be reused
Disposer.dispose(oldDescriptor);
}
content.setExecutionId(executionId);
content.setComponent(descriptor.getComponent());
content.setPreferredFocusedComponent(descriptor.getPreferredFocusComputable());
content.putUserData(RunContentDescriptor.DESCRIPTOR_KEY, descriptor);
content.putUserData(EXECUTOR_KEY, executor);
content.setDisplayName(descriptor.getDisplayName());
descriptor.setAttachedContent(content);
String toolWindowId = getToolWindowIdForRunner(executor, descriptor);
final ToolWindow toolWindow = ToolWindowManager.getInstance(myProject).getToolWindow(toolWindowId);
final ProcessHandler processHandler = descriptor.getProcessHandler();
if (processHandler != null) {
final ProcessAdapter processAdapter = new ProcessAdapter() {
@Override
public void startNotified(final ProcessEvent event) {
UIUtil.invokeLaterIfNeeded(() -> {
content.setIcon(ExecutionUtil.getLiveIndicator(descriptor.getIcon()));
toolWindow.setIcon(ExecutionUtil.getLiveIndicator(myToolwindowIdToBaseIconMap.get(toolWindowId)));
});
}
@Override
public void processTerminated(final ProcessEvent event) {
ApplicationManager.getApplication().invokeLater(() -> {
boolean alive = false;
ContentManager manager = myToolwindowIdToContentManagerMap.get(toolWindowId);
if (manager == null)
return;
for (Content content1 : manager.getContents()) {
RunContentDescriptor descriptor1 = getRunContentDescriptorByContent(content1);
if (descriptor1 != null) {
ProcessHandler handler = descriptor1.getProcessHandler();
if (handler != null && !handler.isProcessTerminated()) {
alive = true;
break;
}
}
}
Icon base = myToolwindowIdToBaseIconMap.get(toolWindowId);
toolWindow.setIcon(alive ? ExecutionUtil.getLiveIndicator(base) : base);
Icon icon = descriptor.getIcon();
content.setIcon(icon == null ? executor.getDisabledIcon() : IconLoader.getTransparentIcon(icon));
});
}
};
processHandler.addProcessListener(processAdapter);
final Disposable disposer = content.getDisposer();
if (disposer != null) {
Disposer.register(disposer, new Disposable() {
@Override
public void dispose() {
processHandler.removeProcessListener(processAdapter);
}
});
}
}
if (oldDescriptor == null) {
contentManager.addContent(content);
new CloseListener(content, executor);
}
content.getManager().setSelectedContent(content);
if (!descriptor.isActivateToolWindowWhenAdded()) {
return;
}
ApplicationManager.getApplication().invokeLater(() -> {
ToolWindow window = ToolWindowManager.getInstance(myProject).getToolWindow(toolWindowId);
// let's activate tool window, but don't move focus
//
// window.show() isn't valid here, because it will not
// mark the window as "last activated" windows and thus
// some action like navigation up/down in stacktrace wont
// work correctly
descriptor.getPreferredFocusComputable();
window.activate(descriptor.getActivationCallback(), descriptor.isAutoFocusContent(), descriptor.isAutoFocusContent());
}, myProject.getDisposed());
}
use of com.intellij.openapi.wm.ToolWindow in project intellij-community by JetBrains.
the class RunContentManagerImpl method registerToolWindow.
private void registerToolWindow(@NotNull final Executor executor, @NotNull ToolWindowManagerEx toolWindowManager) {
final String toolWindowId = executor.getToolWindowId();
if (toolWindowManager.getToolWindow(toolWindowId) != null) {
return;
}
final ToolWindow toolWindow = toolWindowManager.registerToolWindow(toolWindowId, true, ToolWindowAnchor.BOTTOM, this, true);
final ContentManager contentManager = toolWindow.getContentManager();
contentManager.addDataProvider(new DataProvider() {
private int myInsideGetData = 0;
@Override
public Object getData(String dataId) {
myInsideGetData++;
try {
if (PlatformDataKeys.HELP_ID.is(dataId)) {
return executor.getHelpId();
} else {
return myInsideGetData == 1 ? DataManager.getInstance().getDataContext(contentManager.getComponent()).getData(dataId) : null;
}
} finally {
myInsideGetData--;
}
}
});
toolWindow.setIcon(executor.getToolWindowIcon());
new ContentManagerWatcher(toolWindow, contentManager);
initToolWindow(executor, toolWindowId, executor.getToolWindowIcon(), contentManager);
}
use of com.intellij.openapi.wm.ToolWindow in project intellij-community by JetBrains.
the class NavigateFromSourceTest method testAutoscrollFromSourceOnOpening.
public void testAutoscrollFromSourceOnOpening() throws Exception {
final PsiClass[] classes = JavaDirectoryService.getInstance().getClasses(getPackageDirectory());
PsiClass psiClass = classes[0];
FileEditorManager.getInstance(getProject()).openFile(psiClass.getContainingFile().getVirtualFile(), true);
ProjectView projectView = ProjectView.getInstance(getProject());
((ProjectViewImpl) projectView).setAutoscrollFromSource(true, ProjectViewPane.ID);
ToolWindow toolWindow = ToolWindowManager.getInstance(getProject()).getToolWindow(ToolWindowId.PROJECT_VIEW);
new ProjectViewToolWindowFactory().createToolWindowContent(getProject(), toolWindow);
projectView.changeView(ProjectViewPane.ID);
UIUtil.dispatchAllInvocationEvents();
JComponent component = ((ProjectViewImpl) projectView).getComponent();
DataContext context = DataManager.getInstance().getDataContext(component);
PsiElement element = CommonDataKeys.PSI_ELEMENT.getData(context);
assertEquals("Class1.java", ((PsiJavaFile) element).getName());
}
use of com.intellij.openapi.wm.ToolWindow in project intellij-community by JetBrains.
the class ProjectToolWindowTest method testProjectViewActivate.
public void testProjectViewActivate() throws Exception {
ToolWindowEP[] extensions = Extensions.getExtensions(ToolWindowEP.EP_NAME);
for (ToolWindowEP extension : extensions) {
if (ToolWindowId.PROJECT_VIEW.equals(extension.id)) {
myManager.initToolWindow(extension);
}
}
DesktopLayout layout = myManager.getLayout();
WindowInfoImpl info = layout.getInfo(ToolWindowId.PROJECT_VIEW, false);
assertFalse(info.isVisible());
info.setVisible(true);
ToolWindow window = myManager.getToolWindow(ToolWindowId.PROJECT_VIEW);
assertTrue(window.isVisible());
ProjectView.getInstance(getProject());
ProjectViewSharedSettings.Companion.getInstance().setAutoscrollFromSource(true);
try {
window.activate(null);
} finally {
// cleanup
info.setVisible(false);
}
}
use of com.intellij.openapi.wm.ToolWindow in project intellij-community by JetBrains.
the class UsageContextDataflowToPanel method createPanel.
@NotNull
protected JComponent createPanel(@NotNull PsiElement element, final boolean dataFlowToThis) {
ToolWindow toolWindow = ToolWindowManager.getInstance(myProject).getToolWindow(ToolWindowId.FIND);
SliceAnalysisParams params = createParams(element, dataFlowToThis);
SliceRootNode rootNode = new SliceRootNode(myProject, new DuplicateMap(), JavaSliceUsage.createRootUsage(element, params));
return new SlicePanel(myProject, dataFlowToThis, rootNode, false, toolWindow) {
@Override
public boolean isToShowAutoScrollButton() {
return false;
}
@Override
public boolean isToShowPreviewButton() {
return false;
}
@Override
public boolean isToShowCloseButton() {
return false;
}
@Override
public boolean isAutoScroll() {
return false;
}
@Override
public void setAutoScroll(boolean autoScroll) {
}
@Override
public boolean isPreview() {
return false;
}
@Override
public void setPreview(boolean preview) {
}
};
}
Aggregations