@Override public void setDiffRequest(DiffRequest request) { final Map<String, DiffRequest> requestMap = myRequest.discloseRequest(request); final HashMap<String, DiffViewer> copy = new HashMap<String, DiffViewer>(myMap); for (Map.Entry<String, DiffRequest> entry : requestMap.entrySet()) { final String key = entry.getKey(); final DiffRequest diffRequest = entry.getValue(); diffRequest.getGenericData().put(PlatformDataKeys.COMPOSITE_DIFF_VIEWER.getName(), this); final DiffViewer viewer = copy.remove(key); if (viewer != null && viewer.acceptsType(diffRequest.getType())) { viewer.setDiffRequest(diffRequest); } else { if (viewer != null) { removeTab(myUi.getContentManager().getContents(), key); } final DiffViewer newViewer = myRequest.viewerForRequest(myWindow, myParentDisposable, key, diffRequest); if (newViewer == null) continue; myMap.put(key, newViewer); final Content content = myUi.createContent( key, newViewer.getComponent(), key, null, newViewer.getPreferredFocusedComponent()); content.setCloseable(false); content.setPinned(true); Disposer.register( myParentDisposable, new Disposable() { @Override public void dispose() { myMap.remove(key); myUi.removeContent(content, true); } }); myUi.addContent(content); } } final Content[] contents = myUi.getContentManager().getContents(); for (String s : copy.keySet()) { removeTab(contents, s); } if (myMap.isEmpty()) { final EmptyDiffViewer emptyDiffViewer = new EmptyDiffViewer(); myMap.put(FICTIVE_KEY, emptyDiffViewer); final Content content = myUi.createContent( FICTIVE_KEY, emptyDiffViewer.getComponent(), FICTIVE_KEY, null, emptyDiffViewer.getPreferredFocusedComponent()); content.setCloseable(false); content.setPinned(true); content.setDisposer(myParentDisposable); myUi.addContent(content); } }
private void initToolWindow() { myToolWindowForm = new AndroidLayoutPreviewToolWindowForm(this); final String toolWindowId = AndroidBundle.message("android.layout.preview.tool.window.title"); myToolWindow = ToolWindowManager.getInstance(myProject) .registerToolWindow(toolWindowId, false, ToolWindowAnchor.RIGHT, myProject, true); myToolWindow.setIcon(AndroidIcons.AndroidPreview); ((ToolWindowManagerEx) ToolWindowManager.getInstance(myProject)) .addToolWindowManagerListener( new ToolWindowManagerAdapter() { private boolean myVisible = false; @Override public void stateChanged() { if (myProject.isDisposed()) { return; } final ToolWindow window = ToolWindowManager.getInstance(myProject).getToolWindow(toolWindowId); if (window != null && window.isAvailable()) { final boolean visible = window.isVisible(); AndroidEditorSettings.getInstance().getGlobalState().setVisible(visible); if (visible && !myVisible) { render(); } myVisible = visible; } } }); final JPanel contentPanel = myToolWindowForm.getContentPanel(); final ContentManager contentManager = myToolWindow.getContentManager(); @SuppressWarnings("ConstantConditions") final Content content = contentManager.getFactory().createContent(contentPanel, null, false); content.setDisposer(myToolWindowForm); content.setCloseable(false); content.setPreferredFocusableComponent(contentPanel); contentManager.addContent(content); contentManager.setSelectedContent(content, true); myToolWindow.setAvailable(false, null); }
/** @return can be null if user cancelled operation */ @Nullable public static AntBuildMessageView openBuildMessageView( Project project, AntBuildFileBase buildFile, String[] targets) { final VirtualFile antFile = buildFile.getVirtualFile(); if (!LOG.assertTrue(antFile != null)) { return null; } // check if there are running instances of the same build file MessageView ijMessageView = MessageView.SERVICE.getInstance(project); Content[] contents = ijMessageView.getContentManager().getContents(); for (Content content : contents) { if (content.isPinned()) { continue; } AntBuildMessageView buildMessageView = content.getUserData(KEY); if (buildMessageView == null) { continue; } if (!antFile.equals(buildMessageView.getBuildFile().getVirtualFile())) { continue; } if (buildMessageView.isStopped()) { ijMessageView.getContentManager().removeContent(content, true); continue; } int result = Messages.showYesNoCancelDialog( AntBundle.message("ant.is.active.terminate.confirmation.text"), AntBundle.message("starting.ant.build.dialog.title"), Messages.getQuestionIcon()); switch (result) { case 0: // yes buildMessageView.stopProcess(); ijMessageView.getContentManager().removeContent(content, true); continue; case 1: // no continue; default: // cancel return null; } } final AntBuildMessageView messageView = new AntBuildMessageView(project, buildFile, targets); String contentName = buildFile.getPresentableName(); contentName = BUILD_CONTENT_NAME + " (" + contentName + ")"; final Content content = ContentFactory.SERVICE .getInstance() .createContent(messageView.getComponent(), contentName, true); content.putUserData(KEY, messageView); ijMessageView.getContentManager().addContent(content); ijMessageView.getContentManager().setSelectedContent(content); content.setDisposer( new Disposable() { @Override public void dispose() { Disposer.dispose(messageView.myAlarm); } }); new CloseListener(content, ijMessageView.getContentManager(), project); // Do not inline next two variabled. Seeking for NPE. ToolWindow messageToolWindow = ToolWindowManager.getInstance(project).getToolWindow(ToolWindowId.MESSAGES_WINDOW); messageToolWindow.activate(null, false); return messageView; }
public void setContent(@NotNull Content content) { myContent = content; content.setDisposer(this); }