Skip to main content
1-Visitor
November 3, 2021
Solved

DefaultUICommandBracketListener on user created command

  • November 3, 2021
  • 2 replies
  • 3482 views
 

Dear community,

I am trying to use a pfcCommand.DefaultUICommandBracketListener to catch a call of a user defined command (SESSION.UICreateCommand). This works fine as long as the user interactively clicks that command. But I need to launch the command in my code (by using the OnCommand method). But then the bracket listener is not working.

Does anybody know if I have to trigger the command in a different way?

 

Thank you and kind regards

Michael

Best answer by sjuraj

Easy:

//Register your command (you do not even need to Designate command)
... some code with your listener
String cmdName = "MyCommandName";
UICommand cmd = session.UICreateCommand(cmdName, listener);
... another code

//Then call it at end of your first command
... some code
Session.RunMacro(~ Command `" + cmdName + "`;");

I have several commands using this technique. I is workaround for WSession.ExecuteMacro, which is part of paid Java toolkit. 

If you need some data to pass DOES NOT use static objects (you could but it is bad design), instead use same instance of object shared by both commands for in constructor eg:

Container container = new Container();
MyCmd1 cmd1 = new MyCmd1(container);
MyCmd2 cmd2 = new MyCmd2(container);

//in cmd1
container.setSomeField(model.GetFileName());

//in cmd2
String fileName = container.getSomeField();

 

2 replies

17-Peridot
November 16, 2021

Maybe, something like this

class CommandBracketListener extends DefaultUICommandBracketListener 		 
 {
	 public Session session;
 
	 public CommandBracketListener (Session currentSession)
	 {
		session = currentSession;
	 }	 /*====================================================================*\
 	 FUNCTION : OnAfterCommand() 
 PURPOSE : Function called after rename execution is complete.
	 \*====================================================================*/
	 public void OnAfterCommand()
	 {
	 }
}

CommandBracketListener deflistener = new CommandBracketListener(session); 

deflistener.OnAfterCommand();

 

MichelH1-VisitorAuthor
1-Visitor
November 16, 2021

Thank you ysinitsyn!

This is possible, but I would need to know which CommandBracketListeners are active. I wanted to emulate a click on a button triggering a command inside my code not knowing which BracketListeners are currently active.

 

Maybe the CommandBracketListener only work for real mouse clicks by the user!?

 

17-Peridot
November 16, 2021

Not sure that I clear understand you task.

But, you can write a Mapkey (a click on a button) and play this mapkey code from your otk app.

Not very elegant, but should work.

sjuraj15-MoonstoneAnswer
15-Moonstone
December 1, 2021

Easy:

//Register your command (you do not even need to Designate command)
... some code with your listener
String cmdName = "MyCommandName";
UICommand cmd = session.UICreateCommand(cmdName, listener);
... another code

//Then call it at end of your first command
... some code
Session.RunMacro(~ Command `" + cmdName + "`;");

I have several commands using this technique. I is workaround for WSession.ExecuteMacro, which is part of paid Java toolkit. 

If you need some data to pass DOES NOT use static objects (you could but it is bad design), instead use same instance of object shared by both commands for in constructor eg:

Container container = new Container();
MyCmd1 cmd1 = new MyCmd1(container);
MyCmd2 cmd2 = new MyCmd2(container);

//in cmd1
container.setSomeField(model.GetFileName());

//in cmd2
String fileName = container.getSomeField();

 

MichelH1-VisitorAuthor
1-Visitor
December 1, 2021

That's exactly what I was looking for! Thank you very much sjuraj!