gpt4 book ai didi

java - 如何在自定义 View 上显示单独的控制台?

转载 作者:行者123 更新时间:2023-11-29 09:30:07 27 4
gpt4 key购买 nike

我已经创建了自定义 View ,并在 TextConsoleViewer 查看器的帮助下将控制台放到了它上面。

它出现在我的 View 中,但它也出现在主控制台 View 中,它也出现在布局中。

如何避免这种情况?如何将控制台仅放在我的 View 中,或者可能在控制台 View 中隐藏不需要的控制台?

View 部分代码:

public class ChatView extends ViewPart {

public static final String ID = "com.scisbo.eclipse.programw.ChatView";

private ShellMod shell;

private TextConsoleViewer textConsoleViewer;

@Override
public void createPartControl(Composite parent) {

ConsoleFinderService consoleFinderService = (ConsoleFinderService) PlatformUI.getWorkbench().getService(ConsoleFinderService.class);
MessageConsole console = consoleFinderService.findConsole("Chat");

textConsoleViewer = new TextConsoleViewer(parent, console);

shell = new ShellMod(
new PrintStream(console.newMessageStream()),
new PrintStream(console.newMessageStream())
);

}

@Override
public void setFocus() {
textConsoleViewer.getControl().setFocus();
}

}

控制台查找器服务代码

public class ConsoleFinderService {

public MessageConsole findConsole(String name) {
ConsolePlugin plugin = ConsolePlugin.getDefault();
IConsoleManager conMan = plugin.getConsoleManager();
IConsole[] existing = conMan.getConsoles();
for (int i = 0; i < existing.length; i++)
if (name.equals(existing[i].getName()))
return (MessageConsole) existing[i];
// no console found, so create a new one
MessageConsole myConsole = new MessageConsole(name, null);
conMan.addConsoles(new IConsole[] { myConsole });
return myConsole;
}
}

最佳答案

不要将控制台添加到控制台管理器。(如果您确实需要一个管理器,您可能希望实现一个单独的管理器。)

关于java - 如何在自定义 View 上显示单独的控制台?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21166866/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com