question

anilsingh avatar image
anilsingh asked anilsingh posted

How do I add a console page in a multi-page form editor as one separate page?

Hi,

This question is in continuation of my earlier question "How to support multi-page GUI editor"?

So now my multi-page editor is up and running, and I have added two pages to it.

I need to add a third page, which will be a console. I am not sure how exactly do I do this?


Right now I have created a separate plug-in, and I am able to run the console separately.

So somehow I need a way to integrate them both (and I should be able to access the other two form pages and the console in a single session). So probably I need to have a single SessionFactory class to instantiate them both.


 

To give some further insight,

This console class extends the SessionConsole provided by fanfare (i.e. com.fnfr.open.automation.tool.ui.console.SessionConsole).

The editor class implements the IToolView (provided by fanfare i.e. com.fnfr.open.automation.interfaces.tool.IToolView) and extends the FormEditor (org.eclipse.ui.forms.editor.FormEditor)


In case you need to look at our code to understand the question better::

I am adding my console plugin here (which works fine as a separate plugin).

To get a feeling of the editor class, use the code plug-in sample forwarded by anadgoud in the last question (i.e. "How to support multi-page GUI editor").


Thanks for your time.

Anil

 

  

iTestsdk
10 |950

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

1 Answer

·
AdamB avatar image
AdamB answered AdamB posted

Hi Anil,

 

The "SessionConsole" was not designed to run inside an editor.  It is designed to be displayed in the "console" section at the bottom of the screen.

 

Are you looking to just display "debug"/"status" information in this console?

 

If that is the case, you can simply add an IDocument or Array/LinkedList<String> to your ISessionModel and then just create another form page in your editor that simply displays the text coming from the model.   I would recomend using an IDocument as I believe that "TextViewer" will bind to it and deal with updating etc.  The only thing to be careful about is making sure that you don't have multiple threads writing to the IDocument w/o proper locking.

10 comments
10 |950

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

anilsingh avatar image anilsingh commented ·

Hi Adam,

I am not looking just to display debug or status information through this console.

 

Let me make the context and the requirement clearer::

There is an existing integration of iTest with Agilent N2X traffic, which is a vanilla console, sans SDK.

We are working on further integration of iTest with N2X, whereby I need to have an editor having three form pages

i) One GUI form page for N2X Traffic,

ii) Another GUI form page for N2X emulations, and

iii) The third page should appear as a console where users can type interactive commands. This third console page should be on the lines of existing iTest integration of Agilent N2X traffic. So when the user clicks on this third form page, a console needs to appear, where user can type all kinds of supported commands and see the results.

 

So in this context what will be the recommended way to proceed?

It will also be helpful, if you could direct to some existing code snippet, which does things like this.

 

Thanks for your help,

Anil

0 Likes 0 ·
KumarS avatar image KumarS anilsingh commented ·

Your use case is a good one - but now you are treading on advanced Eclipse Editor Programming. In my experience, there are no easy shortcuts to achieve this. You will have to write a full "console" editor yourself if you want to do that.

 

We had anticipated the need for this as well in our applications. For this reason, we decided that we will re-use Eclipse's console ability to let user have a commandline interface to the application. We decided to use the Eclipse's Console View together with the application's session editor. This works pretty well in most cases (especially if you are going to assume that user will rarely use console if the editor is providing most of the functionality).

 

If you really want to build your own commandline editor inside an Eclipse editor, it will require a lot of Eclipse UI programming knowledge and will be a lot more work.

0 Likes 0 ·
anadgoud avatar image anadgoud KumarS commented ·

Hi

 

We curretly have a multipage editor which implements IToolView, the idea would be to use the editor's NotifyNewRequests. I guess editor is running  in a different thred (UI thread).

 

Now suppose we use a console view (I assume you are suggeting not to implement IToolView here), we need to start new thread to listen to commands from console. So in such case  can we post requests using the editors NotifyNewRequest command??? Assuming this is possible we would get RequestResponse notification in editor, how do we send it to console as out put them.

 

I am not able to visualize the concept completely can you please explain a bit more. Some example would help.

 

Regards

**bleep** N

 

 

0 Likes 0 ·
KumarS avatar image KumarS anadgoud commented ·

I do not think threading has much to do here. We have designed our SDK with MVC (Model-View-Controller) architecture in mind. You will write your application in such a way that you have a model (which stores the data used by your application) and a controller (which processes requests). Now you may or may not have a view for your application or may have multiple views.  (This view concept has nothing to do with Eclipse Views). Typically, for our applications we have created two views for the model - first one is an Eclipse Editor and the second one is an Eclipse Console. Both of them show the data contained in the model in a different way. One can have only one view, 2 views, none or any number of UI elements to display the model.

 

Typical flow works this way when executing a testcase:

iTest sends the request to your controller to do something. Controller performs the request and changes the "model". Changing the model sends an event to views that model has changed and views (editors or console view or any other UI elements) update themselves.

 

Typical flow works this way when one performs an action in a view:

Editor (one of the views) sends a request to your controller to do something.Controller performs the request and changes the "model". Changing the model sends an event to views that model has changed and views (editors or console view or any other UI elements) update themselves.

 

Our SDK plugins ship with source code. So you can take a look at how some our example tools use both an editor and console to display data from the model as well as send requests to the controller.

 

 

0 Likes 0 ·
anadgoud avatar image anadgoud KumarS commented ·

 

Hi  

 

I am able to provide a hook to a console through my editor and now both my editors and console view have same model. I have provided a EditorAction which basically shows my console in the console view using the following code.

 

 

ConsolePlugin.getDefault().getConsoleManager().showConsoleView(console);

 

 

But I have following problems to solve can someone please provide some guidance

 

 1) I want to install a Key listener where I can get key presses like up, down, tab etc. Can you please let me know how can I do it. (this to implement features like history, command completion etc).

 

2) I want to place my input cursor always after the cli prompt, how can I achieve this.

 

3) I am also seeing  few issues when I have 2 sessions opened. Following are the issues, can you please let me know if I am missing some thing obvious.

 

       -  When I open the second session first time the console of the first is getting replaced by the second. (But when I use Editor Action on first sessions editor, I can see the console back again).

 

       - Now suppose both the sessions are opened with their respective consoles and I close the console of first session and try to open it using EditorAction, then for the first time the console of second session is opened, subsequently when I use the editor action again the proper console is getting opened. The same behavior is not seen for the second session. I am not able to make out what is the problem.

 

 

is there a better way of viewing IoConsole??? How Agilent Traffic editor is implemented. Can I get to see some code snippets from Agilent Traffic??

 

 

Regards

A Nadgouda

 

0 Likes 0 ·
AdamB avatar image AdamB anadgoud commented ·

re: 1. Key listener

I don't know whether the eclipse console provides support for this or if it really just accepts whole commands.  It is the IOConsole, you may need to extend TextConsole instead of IOConsole and do some more work to create this behavior.

 

Re: 2. Putting cursor after prompt. 

 

Does it not do this already?  Or does it just do this when you start typing?

 

Re: 3 Multiple sessions

 

The console view has an icon in the upper right corner that looks like a monitor.  If you click the drop down, it will show you the different consoles that are open and allow you to switch between them.

 

Re: Access to source from other tools

 

You should contact your Sales Engineer/Support and I'm sure that something can be arranged.

0 Likes 0 ·
anadgoud avatar image anadgoud AdamB commented ·

1) It is a IOConsole and I guess IOCOnsole extends TextConsole. Test console has addPatternMatchListener which I am not aware how to use, also not sure if this is the right listener installer. Can you please let me know how AgilentTraffic application is doing it???

 

2) Only does when we start typing. Any solution for this.

 

3) Thansk this helps.

0 Likes 0 ·
PaulD avatar image PaulD anadgoud commented ·

1)  I don't think this is what you want.  While I haven't done it, I believe that if you don't want line-at-a-time, then you can get the underlying document representing the contents of the console (TextConsole.getDocument()) and can add a listener to it.  

 

2)  I'm not aware of any way to control the cursor position in the window.  I agree that it is annoying.

 

If you really want to have your own console with the exact behavior you want, you could do the work yourself inside your own application window using direct control over the SWT text controls.  The Eclipse console was really optimized for output, in my opinion.

 

 

0 Likes 0 ·
anadgoud avatar image anadgoud PaulD commented ·

Hi All,

 

Thanks for your support, but I have got some lead now. Just wanted to share it so that it will be useful other.

 

What I am now doign is use IoConsoleViewer. Using this you can show your console on the form page. And using IoConsoleViewer you can addKeyListner as follows. Using console viewer and IOConsole we can implment a complete command line interface.

 

console =  new IOConsole(name, icon);

consoleViewer = new IOConsoleViewer(composite, console);    // you need to pass the composite of your form page/view
consoleViewer.getControl().addKeyListener(new KeyAdapter() {
 public void keyPressed(KeyEvent e) {
  switch (e.keyCode) {
   case SWT.F1:
    System.out.println("F1 pressed");
    break;
   case SWT.UP:
    System.out.println("UP key");
    break;
   case SWT.DOWN:
    System.out.println("DOWN key");
    break;
   case SWT.ARROW_DOWN:
    System.out.println("arraow down key");
    break;
   case SWT.ARROW_UP:
    System.out.println("arraow UP key");
    break;
   case SWT.CR:
    System.out.println("Carriage return");
    break;
   case SWT.TAB:
    System.out.println("TAB");
    break;
    default:
    // ignore everything else
  }
 }
 });

0 Likes 0 ·
PaulD avatar image PaulD anadgoud commented ·

Creative idea!  I hadn't thought of using IOConsole outside of Eclipse's own Console view.  Cool!

0 Likes 0 ·

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.