Java 如何在自定义视图上显示单独的控制台?
我已经创建了我的自定义视图,并在TextConsoleViewer的帮助下将控制台放在上面 它出现在我的视图中,但也出现在主控制台视图中,主控制台视图也出现在布局中 如何避免这种情况?如何将控制台仅放在我的视图上,或者,可能是,可以在控制台视图上隐藏不需要的控制台 查看部件的代码:Java 如何在自定义视图上显示单独的控制台?,java,eclipse,eclipse-plugin,console,eclipse-rcp,Java,Eclipse,Eclipse Plugin,Console,Eclipse Rcp,我已经创建了我的自定义视图,并在TextConsoleViewer的帮助下将控制台放在上面 它出现在我的视图中,但也出现在主控制台视图中,主控制台视图也出现在布局中 如何避免这种情况?如何将控制台仅放在我的视图上,或者,可能是,可以在控制台视图上隐藏不需要的控制台 查看部件的代码: public class ChatView extends ViewPart { public static final String ID = "com.scisbo.eclipse.programw.C
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;
}
}
不要将控制台添加到控制台管理器。
如果您确实需要一个管理器,您可能需要实现一个单独的管理器。不要将控制台添加到控制台管理器中。
如果您确实需要一个管理器,您可能希望实现一个单独的管理器。添加屏幕截图以更好地理解添加屏幕截图以更好地理解