Creating a console view in the RCP Application [message #660096] |
Wed, 16 March 2011 19:11 |
Prithviraj Patil Messages: 10 Registered: February 2011 |
Junior Member |
|
|
Hi.
I am new to RCP and am trying to add a console view, similar to the one in Eclipse in my RCP Application. I am unable to add the console itself. I want to display the log contents generated by log4j in it.
Currently I have tried 2 methods to add a console view, however to no avail.
1. I added the following to my Perspective.java class
MessageConsole myConsole = new MessageConsole("Console", Activator
.getImageDescriptor("icons/book.png"));
ConsolePlugin.getDefault().getConsoleManager()
.addConsoles(new IConsole[] { myConsole });
final MessageConsoleStream stream = myConsole.newMessageStream();
final PrintStream myS = new PrintStream(stream);
System.setOut(myS);
System.setErr(myS);
2. This is a piece of code I came across on one forum. the displayConsoleView is returning 'false'.
error received : Could not create view: org.eclipse.ui.console.ConsoleView
Do I have to create a view in the extensions of my application first? or should this be created at runtime?
package org.taf.ui;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.jface.text.IDocument;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Display;
import org.eclipse.ui.IWorkbenchPage;
import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.ui.PartInitException;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.console.ConsolePlugin;
import org.eclipse.ui.console.IConsole;
import org.eclipse.ui.console.IConsoleConstants;
import org.eclipse.ui.console.MessageConsole;
import org.eclipse.ui.console.MessageConsoleStream;
/**
* Create an instance of this class in any of your plugin classes.
*
* Use it as follows ...
*
* ConsoleDisplayMgr.getDefault().println("Some error msg",
* ConsoleDisplayMgr.MSG_ERROR); ... ... ConsoleDisplayMgr.getDefault().clear();
* ...
*/
public class ConsoleDisplayMgr {
private static ConsoleDisplayMgr fDefault = null;
private String fTitle = null;
private MessageConsole fMessageConsole = null;
public static final int MSG_INFORMATION = 1;
public static final int MSG_ERROR = 2;
public static final int MSG_WARNING = 3;
public ConsoleDisplayMgr(String messageTitle) {
fDefault = this;
fTitle = messageTitle;
}
public static ConsoleDisplayMgr getDefault() {
return fDefault;
}
public void println(String msg, int msgKind) {
if (msg == null)
return;
if (!displayConsoleView()) {
MessageDialog.openError(PlatformUI.getWorkbench()
.getActiveWorkbenchWindow().getShell(), "Error", msg);
return;
}
getNewMessageConsoleStream(msgKind).println(msg);
}
public void clear() {
IDocument document = getMessageConsole().getDocument();
if (document != null) {
document.set("");
}
}
public boolean displayConsoleView() {
try {
IWorkbenchWindow activeWorkbenchWindow = PlatformUI.getWorkbench()
.getActiveWorkbenchWindow();
if (activeWorkbenchWindow != null) {
IWorkbenchPage activePage = activeWorkbenchWindow
.getActivePage();
PlatformUI
.getWorkbench()
.getActiveWorkbenchWindow()
.getActivePage()
.showView(IConsoleConstants.ID_CONSOLE_VIEW, null,
IWorkbenchPage.VIEW_VISIBLE);
if (activePage != null)
activePage.showView(IConsoleConstants.ID_CONSOLE_VIEW,
null, IWorkbenchPage.VIEW_VISIBLE);
}
} catch (PartInitException partEx) {
return false;
}
return true;
}
private MessageConsoleStream getNewMessageConsoleStream(int msgKind) {
int swtColorId = SWT.COLOR_DARK_GREEN;
switch (msgKind) {
case MSG_INFORMATION:
swtColorId = SWT.COLOR_DARK_GREEN;
break;
case MSG_ERROR:
swtColorId = SWT.COLOR_DARK_MAGENTA;
break;
case MSG_WARNING:
swtColorId = SWT.COLOR_DARK_BLUE;
break;
default:
}
MessageConsoleStream msgConsoleStream = getMessageConsole()
.newMessageStream();
msgConsoleStream.setColor(Display.getCurrent().getSystemColo r(
swtColorId));
return msgConsoleStream;
}
private MessageConsole getMessageConsole() {
if (fMessageConsole == null)
createMessageConsoleStream(fTitle);
return fMessageConsole;
}
private void createMessageConsoleStream(String title) {
fMessageConsole = new MessageConsole(title, null);
ConsolePlugin.getDefault().getConsoleManager()
.addConsoles(new IConsole[] { fMessageConsole });
}
}
|
|
|
|
|
|
|
|
Re: Creating a console view in the RCP Application [message #664180 is a reply to message #663794] |
Thu, 07 April 2011 18:12 |
Prithviraj Patil Messages: 10 Registered: February 2011 |
Junior Member |
|
|
Hi,
I am not adding the console to an already open perspective. I want the console present when the application gets loaded.
I did try the reset perspective method,however it still does not work
snippet of the perspective.java:
import org.eclipse.ui.IFolderLayout;
import org.eclipse.ui.IPageLayout;
import org.eclipse.ui.IPerspectiveFactory;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.console.IConsoleConstants;
public class Perspective implements IPerspectiveFactory {
static int count = 0;
public void createInitialLayout(IPageLayout layout) {
count++;
System.out.println("Perspective.createInitialLayout()");
layout.setEditorAreaVisible(false);
layout.addView("org.taf.ui.view.CatalogueBrowserVw", IPageLayout.LEFT,
0.23f, IPageLayout.ID_EDITOR_AREA);
layout.getViewLayout("org.taf.ui.view.CatalogueBrowserVw")
.setCloseable(false);
IFolderLayout consoleFolder = layout
.createFolder("console", IPageLayout.BOTTOM, 0.65f,
"org.taf.ui.view.CatalogueBrowserVw");
consoleFolder.addView(IConsoleConstants.ID_CONSOLE_VIEW);
if (count == 1) {
PlatformUI.getWorkbench().getActiveWorkbenchWindow()
.getActivePage().resetPerspective();
}
}
If i add the org.eclipse.ui.console to the dependencies, and then run, i get the following error:
!ENTRY org.eclipse.osgi 4 0 2011-04-07 23:41:22.858
!MESSAGE Application error
!STACK 1
java.lang.RuntimeException: No application id has been found.
at org.eclipse.equinox.internal.app.EclipseAppContainer.startDe faultApp(EclipseAppContainer.java:242)
at org.eclipse.equinox.internal.app.MainApplicationLauncher.run (MainApplicationLauncher.java:29)
at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher .runApplication(EclipseAppLauncher.java:110)
at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher .start(EclipseAppLauncher.java:79)
at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseS tarter.java:369)
at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseS tarter.java:179)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAcce ssorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMe thodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java: 619)
at org.eclipse.equinox.launcher.Main.basicRun(Main.java:574)
at org.eclipse.equinox.launcher.Main.run(Main.java:1407)
at org.eclipse.equinox.launcher.Main.main(Main.java:1383)
And if i add it in the runtime dependencies, i get :
!ENTRY org.eclipse.ui 4 4 2011-04-07 23:19:03.102
!MESSAGE Exception in org.eclipse.ui.internal.FolderLayout.addView(String): org.eclipse.ui.PartInitException: View descriptor not found: org.eclipse.ui.console.ConsoleView
!STACK 1
org.eclipse.ui.PartInitException: View descriptor not found: org.eclipse.ui.console.ConsoleView
at org.eclipse.ui.internal.FolderLayout.addView(FolderLayout.ja va:75)
at org.taf.ui.Perspective.createInitialLayout(Perspective.java: 29)
at org.eclipse.ui.internal.Perspective.loadPredefinedPersp(Pers pective.java:816)
at org.eclipse.ui.internal.Perspective.createPresentation(Persp ective.java:270)
at org.eclipse.ui.internal.Perspective.<init>(Perspective.java:156)
at org.eclipse.ui.internal.tweaklets.Workbench3xImplementation. createPerspective(Workbench3xImplementation.java:55)
at org.eclipse.ui.internal.WorkbenchPage.createPerspective(Work benchPage.java:1672)
at org.eclipse.ui.internal.WorkbenchPage.init(WorkbenchPage.jav a:2453)
at org.eclipse.ui.internal.WorkbenchPage.<init>(WorkbenchPage.java:563)
at org.eclipse.ui.internal.tweaklets.Workbench3xImplementation. createWorkbenchPage(Workbench3xImplementation.java:39)
at org.eclipse.ui.internal.WorkbenchWindow.busyOpenPage(Workben chWindow.java:768)
at org.eclipse.ui.internal.Workbench$23.runWithException(Workbe nch.java:1220)
at org.eclipse.ui.internal.StartupThreading$StartupRunnable.run (StartupThreading.java:31)
at org.eclipse.swt.widgets.RunnableLock.run(RunnableLock.java:3 5)
at org.eclipse.swt.widgets.Synchronizer.runAsyncMessages(Synchr onizer.java:134)
at org.eclipse.swt.widgets.Display.runAsyncMessages(Display.jav a:4041)
at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java :3660)
at org.eclipse.ui.application.WorkbenchAdvisor.openWindows(Work benchAdvisor.java:803)
at org.eclipse.ui.internal.Workbench$31.runWithException(Workbe nch.java:1566)
at org.eclipse.ui.internal.StartupThreading$StartupRunnable.run (StartupThreading.java:31)
at org.eclipse.swt.widgets.RunnableLock.run(RunnableLock.java:3 5)
at org.eclipse.swt.widgets.Synchronizer.runAsyncMessages(Synchr onizer.java:134)
at org.eclipse.swt.widgets.Display.runAsyncMessages(Display.jav a:4041)
at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java :3660)
at org.eclipse.ui.internal.Workbench.runUI(Workbench.java:2537)
at org.eclipse.ui.internal.Workbench.access$4(Workbench.java:24 27)
at org.eclipse.ui.internal.Workbench$7.run(Workbench.java:670)
at org.eclipse.core.databinding.observable.Realm.runWithDefault (Realm.java:332)
at org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Work bench.java:663)
at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.j ava:149)
at org.taf.ui.Application.start(Application.java:134)
at org.eclipse.equinox.internal.app.EclipseAppHandle.run(Eclips eAppHandle.java:196)
at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher .runApplication(EclipseAppLauncher.java:110)
at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher .start(EclipseAppLauncher.java:79)
at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseS tarter.java:369)
at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseS tarter.java:179)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAcce ssorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMe thodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java: 619)
at org.eclipse.equinox.launcher.Main.basicRun(Main.java:574)
at org.eclipse.equinox.launcher.Main.run(Main.java:1407)
at org.eclipse.equinox.launcher.Main.main(Main.java:1383)
!SUBENTRY 1 org.eclipse.ui 4 0 2011-04-07 23:19:03.104
!MESSAGE View descriptor not found: org.eclipse.ui.console.ConsoleView
!ENTRY org.eclipse.ui 4 0 2011-04-07 23:19:03.107
!MESSAGE Unhandled event loop exception
!STACK 0
java.lang.NullPointerException
at org.taf.ui.Perspective.createInitialLayout(Perspective.java: 33)
at org.eclipse.ui.internal.Perspective.loadPredefinedPersp(Pers pective.java:816)
at org.eclipse.ui.internal.Perspective.createPresentation(Persp ective.java:270)
at org.eclipse.ui.internal.Perspective.<init>(Perspective.java:156)
at org.eclipse.ui.internal.tweaklets.Workbench3xImplementation. createPerspective(Workbench3xImplementation.java:55)
at org.eclipse.ui.internal.WorkbenchPage.createPerspective(Work benchPage.java:1672)
at org.eclipse.ui.internal.WorkbenchPage.init(WorkbenchPage.jav a:2453)
at org.eclipse.ui.internal.WorkbenchPage.<init>(WorkbenchPage.java:563)
at org.eclipse.ui.internal.tweaklets.Workbench3xImplementation. createWorkbenchPage(Workbench3xImplementation.java:39)
at org.eclipse.ui.internal.WorkbenchWindow.busyOpenPage(Workben chWindow.java:768)
at org.eclipse.ui.internal.Workbench$23.runWithException(Workbe nch.java:1220)
at org.eclipse.ui.internal.StartupThreading$StartupRunnable.run (StartupThreading.java:31)
at org.eclipse.swt.widgets.RunnableLock.run(RunnableLock.java:3 5)
at org.eclipse.swt.widgets.Synchronizer.runAsyncMessages(Synchr onizer.java:134)
at org.eclipse.swt.widgets.Display.runAsyncMessages(Display.jav a:4041)
at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java :3660)
at org.eclipse.ui.application.WorkbenchAdvisor.openWindows(Work benchAdvisor.java:803)
at org.eclipse.ui.internal.Workbench$31.runWithException(Workbe nch.java:1566)
at org.eclipse.ui.internal.StartupThreading$StartupRunnable.run (StartupThreading.java:31)
at org.eclipse.swt.widgets.RunnableLock.run(RunnableLock.java:3 5)
at org.eclipse.swt.widgets.Synchronizer.runAsyncMessages(Synchr onizer.java:134)
at org.eclipse.swt.widgets.Display.runAsyncMessages(Display.jav a:4041)
at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java :3660)
at org.eclipse.ui.internal.Workbench.runUI(Workbench.java:2537)
at org.eclipse.ui.internal.Workbench.access$4(Workbench.java:24 27)
at org.eclipse.ui.internal.Workbench$7.run(Workbench.java:670)
at org.eclipse.core.databinding.observable.Realm.runWithDefault (Realm.java:332)
at org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Work bench.java:663)
at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.j ava:149)
at org.taf.ui.Application.start(Application.java:134)
at org.eclipse.equinox.internal.app.EclipseAppHandle.run(Eclips eAppHandle.java:196)
at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher .runApplication(EclipseAppLauncher.java:110)
at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher .start(EclipseAppLauncher.java:79)
at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseS tarter.java:369)
at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseS tarter.java:179)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAcce ssorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMe thodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java: 619)
at org.eclipse.equinox.launcher.Main.basicRun(Main.java:574)
at org.eclipse.equinox.launcher.Main.run(Main.java:1407)
at org.eclipse.equinox.launcher.Main.main(Main.java:1383)
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.04269 seconds