Skip to main content
1-Visitor
Nov 3, 2021 1:32 PM UTC
Solved

DefaultUICommandBracketListener on user created command

 

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

sjurajAnswer
15-Moonstone
Dec 1, 2021 10:16 AM UTC

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();

 

8 replies

17-Peridot
Nov 16, 2021 10:29 AM UTC

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();

 

Translate
MichelH1-VisitorAuthor
1-Visitor
Nov 16, 2021 12:43 PM UTC

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!?

 

Translate
17-Peridot
Nov 16, 2021 1:02 PM UTC

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.

Translate
sjuraj15-MoonstoneAnswer
15-Moonstone
Dec 1, 2021 10:16 AM UTC

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();

 

Translate
MichelH1-VisitorAuthor
1-Visitor
Dec 1, 2021 10:50 AM UTC

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

Translate