Eclipse RCP console - eclipse-rcp

I have integrated a console to my rcp application but I would like to display some important informations in red colour rather than in blue but I don't know how to do it(can I add some if conditions?)this the class for my console view .please help me to solve my problem.
public DebugConsole()
{
super("stdio/stderr", null);
outMessageStream = newMessageStream();
outMessageStream.setColor(Display.getCurrent().getSystemColor(
SWT.COLOR_BLUE));
errMessageStream = newMessageStream();
errMessageStream.setColor(Display.getCurrent().getSystemColor(
SWT.COLOR_RED));
System.setOut(new PrintStream(outMessageStream));
System.setErr(new PrintStream(errMessageStream));
}

Suggest the below.
From your code if newMessageStream() method returns valid MessageConsoleStream then all System.out.print messages will be displayed in BLUE colour and System.err.print messages will be displayed in RED colour
Use ConsolePatternListener to display matching messages in
different colour on console.
Change stream colour before you use System.out.print or System.err.print statements.
In the last two lines of you code make PrintSteam instances as class public fields(or private with getter and setters) and get these streams and set colour. Remember to reset the colour back after you used System.out.print or System.err.print statement.
public class DebugConsole {
private PrintStream outStream;
private PrintStream errStream;
public DebugConsole() {
super("stdio/stderr", null);
outMessageStream = newMessageStream();
outMessageStream.setColor(Display.getCurrent().getSystemColor(SWT.COLOR_BLUE));
errMessageStream = newMessageStream();
errMessageStream.setColor(Display.getCurrent().getSystemColor(SWT.COLOR_RED));
outStream = new PrintStream(outMessageStream);
errStream = new PrintStream(errMessageStream);
System.setOut(outStream);
System.setErr(errStream);
}
public PrintStream getOutStream() {
return outStream;
}
public void setOutStream(PrintStream outStream) {
this.outStream = outStream;
}
public PrintStream getErrStream() {
return errStream;
}
public void setErrStream(PrintStream errStream) {
this.errStream = errStream;
}
}
Test class:
public class TestConsole {
public static void main(String[] args) {
DebugConsole console = new DebugConsole();
MessageConsoleStream errStream = (MessageConsoleStream)console.getErrStream();
Color oldColor = errStream.getColor();
errStream.setColor(Display.getCurrent().getSystemColor(SWT.COLOR_DARK_GREEN));
//All the below message will be displayed in green color
System.err.println("This is in green color");
System.err.println("This is in green color");
//Reset color back
errStream.setColor(oldColor);
//Do the same for output stream
}
}
Or Use Grep console Plugin See
here

Related

Dynamic DataGrid in GWT

I am trying to construct a DataGrid in GWT that will show an arbitrary dataset taken from an rpc method.
I have done some progress as I get the fields from a method and the data from another.
I have managed to construct the Datagrid and add the columns from the rpc.getFields() method and fill the table using an AsyncDataProvider.
The problem is that when I refresh the browser, it duplicates all the columns at the Datagrid. I cannot figure out what to do. I tried to remove first all the columns but no luck.
I attach the code if anyone have an idea.
public class MyCallBack implements AsyncCallback<List<Field>> {
DataGrid<Record> dg;
public MyCallBack(DataGrid<Record> dgrid) {
this.dg=dgrid;
}
public void onFailure(Throwable caught) {
Window.alert(caught.getMessage());
}
public void onSuccess(List<Field> result) {
for (int i=0;i<=result.size();i++) {
IndexedColumn ic = new IndexedColumn(i);
dg.addColumn(ic, result.get(i).getLabel());
}
}
public AsyncCallback<List<Field>> getCb() {
return this;
}
public void onModuleLoad() {
final DataGrid<Record> dg = new DataGrid<Record>();
MyCallBack mcb = new MyCallBack(dg);
DataProvider dp = new DataProvider();
DBConnectionAsync rpcService = (DBConnectionAsync) GWT.create(DBConnection.class);
ServiceDefTarget target = (ServiceDefTarget) rpcService;
String moduleRelativeURL = GWT.getModuleBaseURL() + "MySQLConnection";
target.setServiceEntryPoint(moduleRelativeURL);
rpcService.getFields(mcb.getCb());
dp.addDataDisplay(dg);
dg.setVisibleRange(0, 200);
SplitLayoutPanel slp = new SplitLayoutPanel();
slp.setHeight("700px");
slp.setWidth("1500px");
slp.addWest(dg, 770);
RootPanel.get().add(slp);
}
When you refresh a browser, all UI is lost. There is no difference between (a) show the UI for the first time or (b) show the UI after browser refresh.
Your comment "Only if I restart tomcat it works" suggests that the problem is on the server side. Most likely, you return twice the number of data points on a second call.
Try clearing the table before filling it like this:
public void onSuccess(List<Field> result) {
clearTable();
for (int i=0;i<=result.size();i++) {
IndexedColumn ic = new IndexedColumn(i);
dg.addColumn(ic, result.get(i).getLabel());
}
}
private void clearTable(){
while (dg.getColumnCount() > 0) {
db.removeColumn(0);
}
}

Combo Box is not observed

I have the following Code:
public class GuiView extends Application {
private ObservableList<String> shareNames = FXCollections.observableArrayList();
public void start(Stage stage) {
...
ComboBox<String> comboBox = new ComboBox<String>();
comboBox.getItems().addAll(this.shareNames);
MenuItem open = new MenuItem("Open...");
open.setOnAction( e -> {
// FileChooser code...
if (selctedFile != null) {
this.shareNames.addAll("teststring");
}
});
}
}
When I run through the open dialog successfully the combo box doesn't update and shows the teststring. What is going wrong here?
You are updating shareNames, but that is not the list used by the combo box.
Either replace
comboBox.getItems().addAll(this.shareNames);
with
comboBox.setItems(this.shareNames);
or replace
this.shareNames.addAll("teststring");
with
comboBox.getItems().add("teststring");

Marker in Eclipse editor not showing message

I'm building a custom text editor plugin for a domain specific language in Eclipse.
I can detect errors in the format of the editor contents and want to use eclipse's marker's to point out the errors to the user.
I have the following code in the plugin:
public static void createMarkerForResource(int linenumber, String message) throws CoreException {
IResource resource = getFile();
createMarkerForResource(resource, linenumber, message);
}
public static void createMarkerForResource(IResource resource, int linenumber, String message)
throws CoreException {
HashMap<String, Object> map = new HashMap<String, Object>();
MarkerUtilities.setLineNumber(map, linenumber);
MarkerUtilities.setMessage(map, message);
MarkerUtilities.createMarker(resource, map, IMarker.PROBLEM);
IMarker[] markers = resource.findMarkers(null, true, IResource.DEPTH_INFINITE);
for (IMarker marker : markers){
System.out.println("Marker contents"+MarkerUtilities.getMessage(marker));
}
}
I run this code with the command:
createMarkerForResource(2, "hello");
This successfully gives me an image on the correct line
and if I hover over it, I get a 'you can click this thing' cursor. But I can't get the message to turn up.
The message has definitely been placed, because the:
for (IMarker marker : markers){
System.out.println("Marker contents"+MarkerUtilities.getMessage(marker));
}
code produces the "Marker contentshello" output as expected. What am I doing wrong?
EDIT:
The message is appearing in the problem view:
The answer of Njol is correct and works for me (Eclipse Neon.1).
But two additional recommendations:
I am reusing a created field, so annotation hoover is not always new created (getter... not create method)
Default annotation hoover does show all annotations. So when you want only markers to be shown (and no others - e.g. Diff annotations from GIT) you should override isIncluded as in my following example.
Example:
import org.eclipse.jface.text.source.SourceViewerConfiguration;
...
public class MySourceViewerConfiguration extends SourceViewerConfiguration {
...
private IAnnotationHover annotationHoover;
...
public MySourceViewerConfiguration(){
this.annotationHoover=new MyAnnotationHoover();
}
...
#Override
public IAnnotationHover getAnnotationHover(ISourceViewer sourceViewer) {
return annotationHoover;
}
}
And here the annotation hoover class
private class MyAnnotationHoover extends DefaultAnnotationHover{
#Override
protected boolean isIncluded(Annotation annotation) {
if (annotation instanceof MarkerAnnotation){
return true;
}
/* we do not support other annotations than markers*/
return false;
}
}
You need to use a proper IAnnotationHover, which can e.g. be defined in your SourceViewerConfiguration like this:
#Override
public IAnnotationHover getAnnotationHover(ISourceViewer sourceViewer) {
return new DefaultAnnotationHover(false);
}

Netbeans lookup not getting executed first time when the application is started

I have an application in which lookup provider is in explorer window and it is a jcomboBox. Its selected value is provided as lookup to other top components and displayed one in editor and one in output window area. The value of the jcombobox is saved at the time of closing the application and initialized into the jcombobox when the application is started.
When I clean and build the application and start the application, the initial value displayed in the jcombobox is not updated in the lookup and listner windows display uninitialized values. Once the new value is selected in the jcombobox it gets displayed in the other windows.
If I close the application without changing the value of the jcombobox and start the application, the lookup is not updated.
If I change the selection in the combobox, close the application and start again, the lookup gets updated.
I expect anytime when the application is started, the other windows will get the value of the lookup. Any help in this regards will be appreciated. Thanks in advance.
The code for the explorer window which provides the lookup is as follows:
public final class ProviderTopComponent extends TopComponent {
public ProviderTopComponent() {
initComponents();
setName(Bundle.CTL_ProviderTopComponent());
setToolTipText(Bundle.HINT_ProviderTopComponent());
associateLookup(new AbstractLookup(content));
}
private void initComponents() {
jComboBox1 = new javax.swing.JComboBox();
jComboBox1.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));
jComboBox1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jComboBox1ActionPerformed(evt);
}
});
private void jComboBox1ActionPerformed(java.awt.event.ActionEvent evt) {
str = (String) jComboBox1.getSelectedItem();
content.set(Collections.singleton(str), null);
}
private final InstanceContent content = new InstanceContent();
String str;
// Variables declaration - do not modify
private javax.swing.JComboBox jComboBox1;
void writeProperties(java.util.Properties p) {
// better to version settings since initial version as advocated at
// http://wiki.apidesign.org/wiki/PropertyFiles
p.setProperty("version", "1.0");
p.setProperty("val", (String) jComboBox1.getSelectedItem());
}
void readProperties(java.util.Properties p) {
String version = p.getProperty("version");
// TODO read your settings according to their version
String v = p.getProperty("val");
if(v != null) {
jComboBox1.setSelectedItem(v);
}
}
}
The code for the lookup listener window is as follows:
public final class Listner_1TopComponent extends TopComponent implements LookupListener{
public Listner_1TopComponent() {
initComponents();
setName(Bundle.CTL_editorTopComponent());
setToolTipText(Bundle.HINT_editorTopComponent());
}
...
private void initComponents() {
...
jLabel1 = new javax.swing.JLabel();
...
Collection<? extends String> str_collection;
private Lookup.Result<String> result = null;
String str;
// Variables declaration - do not modify
private javax.swing.JLabel jLabel1;
// End of variables declaration
#Override
public void componentOpened() {
result = org.openide.util.Utilities.actionsGlobalContext().lookupResult(String.class);
result.addLookupListener(this);
}
#Override
public void componentClosed() {
result.removeLookupListener(this);
}
#Override
public void resultChanged(LookupEvent le) {
str_collection = result.allInstances();
if (str_collection.isEmpty()) {
} else {
str = str_collection.iterator().next();
}
jLabel1.setText(str);
jLabel1.repaint();
}
}

Windows 8 UserControl Frame Object Navigation

Within a XAML user control, the Frame object is null:
this.Frame.Navigate(typeof(FaxPropertiesPage));
How do I navigate between pages with a Windows 8 XAML User Control? I have placed the control within a Callisto Flyout on a XAML page.
The search button below must navigate the user to another XAML page.
I've successfully used the code from app.xaml.cs
Frame frame = Window.Current.Content as Frame;
and then used the standard Navigate code.
There's the nice way and the not-so-nice way:
Both of them start with a navigation service:
public interface INavigationService
{
bool CanGoBack { get; }
void GoBack();
void GoForward();
bool Navigate<T>(object parameter = null);
bool Navigate(Type source, object parameter = null);
void ClearHistory();
event EventHandler<NavigatingCancelEventArgs> Navigating;
}
public class NavigationService : INavigationService
{
private readonly Frame _frame;
public NavigationService(Frame frame)
{
_frame = frame;
frame.Navigating += FrameNavigating;
}
#region INavigationService Members
public void GoBack()
{
_frame.GoBack();
}
public void GoForward()
{
_frame.GoForward();
}
public bool Navigate<T>(object parameter = null)
{
Type type = typeof (T);
return Navigate(type, parameter);
}
So, where do I get the Frame? In App.xaml.cs
protected async override void OnLaunched(LaunchActivatedEventArgs args)
{
// Do not repeat app initialization when already running, just ensure that
// the window is active
if (args.PreviousExecutionState == ApplicationExecutionState.Running)
{
Window.Current.Activate();
return;
}
// Create a Frame to act as the navigation context and navigate to the first page
var rootFrame = new Frame();
if (DesignMode.DesignModeEnabled)
SimpleIoc.Default.Register<INavigationService, DesignTimeNavigationService>();
else
SimpleIoc.Default.Register<INavigationService>(() => new NavigationService(rootFrame));
I'm using MVVM Light here. This makes life easy because all my viewmodels get created using dependency injection and have their services injected into them.
If you're not using something like MVVM Light and rely on code-behind then you can still make this work: Just make the navigation service static
public class NavigationService : INavigationService
{
public static INavigationService Current{
get;set;}
blah blah blah
}
And change App.xaml.cs to:
protected async override void OnLaunched(LaunchActivatedEventArgs args)
{
// Do not repeat app initialization when already running, just ensure that
// the window is active
if (args.PreviousExecutionState == ApplicationExecutionState.Running)
{
Window.Current.Activate();
return;
}
// Create a Frame to act as the navigation context and navigate to the first page
var rootFrame = new Frame();
NavigationService.Current= new NavigationService(rootFrame));
}
And you can then access your main Frame anywhere in the app by saying:
NavigationService.Current.Navigate<MyView>();
simple code ( may not be 100% efficient) is :
Frame frame = new Frame();
frame.Navigate(typeof(ExerciseAddPage)