question

AmeyaB avatar image
AmeyaB asked AmeyaB posted

SDK: How do I over-ride "open" request?

In my HelloWorld console-based tool, I want to over-ride the "open" request so that the console displays a custom message when the session starts, for example:

 

 

Hello World Console

Today's date is 10/05/2009

open project://my_project/session_profiles/hw.ffsp

Welcome!


Hello World>

 

I am trying to insert the lines in bold above; what class do I over-ride to accomplish this?


 

 

 

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

There is no "overriding" needed to do this. The controller is a "view", anything it displays needs to go through the model. In this case the easiest thing is to have your open handler just put the text it wants in its response.  This will then be shown by the view and it will show up in the test report.

 

If you want to have other means of displaying stuff in the view, you will need to customize the model to allow the controller to provide/set this information so the view can retrieve it.

 

Again, you aren't overriding anything, and your handlers are not directly writing to the console.  The importance of this last part cannot be overstated.  The controller and model cannot know anything about the view.  they need to function without views and they need to be able to use any view that is attached to them.

7 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.

AmeyaB avatar image AmeyaB ♦ commented ·

I may have missed something in the documentation - The Hello World walk through does not create any handlers for "open". If I were to create my own OpenHandler and attach it to the "open" request, the console does not open.

0 Likes 0 ·
AdamB avatar image AdamB AmeyaB ♦ commented ·

Are you setting open correctly in the open handler

 

From SessionController jdocs:

 

It is very important to handle open properly. If you have NO IRequestHandler defined for open, the controller will automatically open the session. If you have defined an IRequestHandler for open, then the model that you will be provided will be of type SessionModel you MUST call SessionModel.setOpen() to move the session into an open state. If the session is not open, then a ToolException should be thrown.

0 Likes 0 ·
AmeyaB avatar image AmeyaB ♦ AdamB commented ·

Great, that worked! However, the entire text gets printed after the "open project://..." line:

 

 

Hello World Console

open project://my_project/session_profiles/hw.ffsp

BEFOREAFTER

Hello World>

 

 

I want to display text before the "open project://..." line:

 

 

Hello World Console

BEFORE

open project://my_project/session_profiles/hw.ffsp

AFTER

Hello World>


Here is my OpenHandler.performRequest method:

@Override
public void performRequest(ISessionController controller,
ISessionModel model, IRequestResponse requestResponse,
IRequestContext context, IProgressMonitor monitor)
throws ToolException {

DocumentUtil.append(requestResponse.getResponse().getText(), "BEFORE");
SessionModel sessionModel = (SessionModel) model;
sessionModel.setOpen();
DocumentUtil.append(requestResponse.getResponse().getText(), "AFTER");
}

What do I need to change?

 

 

0 Likes 0 ·
AmeyaB avatar image AmeyaB ♦ AmeyaB ♦ commented ·

I guess I could extend the Console.getBanner() method to print information before the "open project://.." line. Is that the right place to do it?

0 Likes 0 ·
AdamB avatar image AdamB AmeyaB ♦ commented ·

The console is designed to allow you to enter a request and then to display the response.  The Open request starts with Open device:foo, you can't really have anythinig before.

 

One important thing to note, the console is designed for learning the SDK and is not the recomended way of interacting or displaying information.

 

Is there a reason that you want to display information about opening before the open step?

0 Likes 0 ·
AmeyaB avatar image AmeyaB ♦ AdamB commented ·

Displaying information before the "open" text in the response is purely for cosmetic reasons; in this specific case I want to display a copyright notice:

 

 

Hello World Console

Copyright (c) The Fanfare Group, Inc. All rights reserved.

open project://my_project/session_profiles/hw.ffsp

Welcome. Today's date is 10/05/2009


Hello World>

 

For now I have added this text to the getBanner() method.

 

0 Likes 0 ·
AdamB avatar image AdamB AmeyaB ♦ commented ·

Yeah, overriding the banner is the way to go for this.

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.