cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Community Tip - Did you get an answer that solved your problem? Please mark it as an Accepted Solution so others with the same problem can find the answer easily. X

How to add a custom action to Windchill PSB where command is not a JSP, but a custom class?

ybulankou
8-Gravel

How to add a custom action to Windchill PSB where command is not a JSP, but a custom class?

Hi All

Trying to add a custom action to right-click menu in Part Structure Builder (PSB)

Uncommented:

<action name="customActionGWT" type="psb"/>

in psb-actionmodels.xml

and

<action name="customActionGWT" ajax="component">

            <command class="com.ptc.cat.ui.client.action.LaunchURLAction" method="execute" url="/ptc1/psb/customAction" windowType="popup"/>

                        <supportedTypes>

                                <type value="wt.part.WTPart"/>

                                <type value="wt.part.WTPartUsageLink"/>

                                <type value="wt.part.PartUsesOccurrence"/>

                                <type value="wt.part.RTPartPathOccurrence"/>

                        </supportedTypes>     

        </action>

in psb-actions.xml

The menu item appears.

When i change command:

<command class="com.ptc.cat.ui.client.action.LaunchURLAction" method="execute" url="/ptc1/psb/customAction" windowType="popup"/>

to :

<command class="com.myCompany.MySimpleAction"/>

menu item disappears.

MySimpleAction class looks like this:

package com.myCompany;

import com.google.gwt.user.client.rpc.AsyncCallback;

import com.ptc.cat.ops.client.OperationResult;

import com.ptc.cat.ui.client.action.AbstractAction;

import com.ptc.cat.ui.client.action.ActionDefinition;

public class MySimpleAction extends AbstractAction {

    public MySimpleAction(ActionDefinition ad) {

        super(ad);

    }

    @Override

    public void run(AsyncCallback<OperationResult> ac) {

        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.

    }

   

}

Tried adding my class through adding JAR to WC/lib

and .java to WC/src and building

It is Windchill 10.2 M030

no .xconfs and .properties added or modified

jcaDebug somehow doesn't work for PSB tree menus

Does anybody know how to add a custom action class properly?

Thanks in advance!

ACCEPTED SOLUTION

Accepted Solutions
HelesicPetr
22-Sapphire I
(To:ybulankou)

Hello, I found solution. 

I needed a button in the PBS with Wizard and some options. 

I search for a long time to solve it because I can not activate own Processor to achieve the results.

 

It is little bit tricky because Documentation is not clear for GWT actions. 

 

First create actionModel with JSP page. Class in the custom-Actions.xml must be LaunchURLAction or LaunchCustomURLAction (because the button in the PSB menu appears only with this two classes)

example:

Wizard

<action name="myOwnMenuActionGWT" ajax="component">
<label>Download data zip</label>
<icon>package_zipped.gif</icon>
<command class="com.ptc.cat.ui.client.action.LaunchCustomURLAction"
method="execute"
url="netmarkets/jsp/cz/aveng/DownloadZIP/DownloadZIPWizard.jsp"
windowType="popup" />
</action>

 

Step1

<action name="DownloadZIPWizardStep1" preloadWizardPage="true" resourceBundle="com.ptc.core.ui.actionsRB">
<command windowType="wizard_step"
url="netmarkets/jsp/cz/aveng/DownloadZIP/DownloadZIPWizardStep1.jsp"/>
</action>

 

the Wizard JSP page(DownloadZIPWizard) should contains wizard definition 

example

<jca:wizard formProcessorController="cz.aveng.PublcZip.ZipColectProcessorController"
title="Data Collector"
buttonList="DefaultWizardButtonsNoApply">
<jca:wizardStep action="DownloadZIPWizardStep1" type="psb" label="Data Collector"/>
</jca:wizard>

and here is the trick 

here you need to define own ProcessController class in 

formProcessorController=

example of formProcessorController

package cz.aveng.PublcZip;

import com.ptc.core.components.beans.ObjectBean;
import com.ptc.core.components.forms.DefaultFormProcessorController;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

public class ZipColectProcessorController extends DefaultFormProcessorController
{
@Override
protected List<ObjectBean> getRootObjectBeans()
{
List objectBeanList = super.getRootObjectBeans();
Iterator next = objectBeanList.iterator();
List<String> delegate = new ArrayList<>();
//Processor delegagte (very important Delegate if is not set, then Processor is pushed to delegate which is not possible error can not catst Processor to ProcessorDelegate)
delegate.add("com.ptc.core.components.forms.DefaultObjectFormProcessorDelegate")
;
while (next.hasNext())
{
ObjectBean objectBean = (ObjectBean) next.next();
// Processor for managing action after OK button
objectBean.setProcessorClassName("cz.aveng.PublcZip.ZipColectProcessor");
// here is own Processor
objectBean.setDelegateClassNames(delegate); // add DefaultObjectFormProcessorDelegate
}
super.setRootObjectBeans(objectBeanList);
return super.getRootObjectBeans();
}
}

the processor ZipColectProcessor contains the code with the action and there you can do what you want :D.

preProcess, doOperation, postProcess.....

 

Hope it could be helpful.

 

Best Regards

PetrH

View solution in original post

11 REPLIES 11
Roshni
3-Newcomer
(To:ybulankou)

Hello,

 

I am also facing same issue. Does anyone know how to solve this.

Custom action went disable when use custom class in <command class=""/>

Benny_B
10-Marble
(To:Roshni)

Hello,

 

Same issue for me, with a JSP or with an existing action which calls a java class there is no problem and the menu item is visible.

When I use my own java class it went wrong.

 

@Roshni or @ybulankou did one of you found a solution?

baeNicholost
4-Participant
(To:Benny_B)

Add me to the stack of devs unable to add a custom action to the PSB context menu that uses a class other than com.ptc.cat.ui.client.action.LaunchURLAction.  I'm leveraging of the 25 custom report actions to fire my popup because we have more than one action to add.

<objecttype name="psb" resourceBundle="com.company.customResourceRB">
	<action name="psbCustomReportGWT19" ajax="component">
		<command class="com.ptc.cat.ui.client.action.LaunchURLAction" method="execute" url="/ptc1/part/awesomeCustomTool" windowType="popup" />
		<!-- filters -->
	</action>
</objecttype>

 

As soon as I change the command class to my custom class, the action disappears.  The command class extends com.ptc.cat.ui.client.action.LaunchURLAction.  Refactoring my custom class to the same package as LaunchURLAction has no effect.

 

If feels like the PSB leverages a white list of acceptable action definitions.  If a new action is introduced that does not match the object type + name + command class in the list, the action is rejected.

 

Anyone?

ntiwari-2
3-Newcomer
(To:Benny_B)

I am facing the exact same issue trying to use custom class for one custom right click action. The moment i give my custom class as command class, action disappears.

Did anyone find any solution?

I opened a case with PTC for our company.  It made it through R&D and is now closed.  Basically, to use a custom action class outside of the two provided -- LaunchURLAction and LaunchCustomURLAction -- requires recompilation of the GWT toolset from PTC, even if the custom class extends either base class.  So much for polymorphism.

 

PTC wrote:

Unfortunately, in order for you to control what the GWT action command class should do, it would need to be GWT compiled. The compilation of custom GWT code is not supported. R&D has no plans at this time to implement any changes for this issue.


@ntiwari-2I am not sure what you need your action class to do.  In my case, I needed to uniquely identify the parent of the WTPart the action was launched from.  LaunchCustomURLAction passes a parameter called "spaths" which concatenates all OIDs from the selected node up to the root, including links.  While having to parse a string generated by code that we do not control just to extract the immediate parent ID feels dirty, it does allow the tool to work and therefore the business is happy.

https://www.ptc.com/en/support/article/CS320109?&language=en&posno=1&q=SPR%209810813&source=search

 

There is an SPR  9810813 for this issue applies to Windchill PDMLink 11.0 to 11.2

HelesicPetr
22-Sapphire I
(To:ybulankou)

Hello, I found solution. 

I needed a button in the PBS with Wizard and some options. 

I search for a long time to solve it because I can not activate own Processor to achieve the results.

 

It is little bit tricky because Documentation is not clear for GWT actions. 

 

First create actionModel with JSP page. Class in the custom-Actions.xml must be LaunchURLAction or LaunchCustomURLAction (because the button in the PSB menu appears only with this two classes)

example:

Wizard

<action name="myOwnMenuActionGWT" ajax="component">
<label>Download data zip</label>
<icon>package_zipped.gif</icon>
<command class="com.ptc.cat.ui.client.action.LaunchCustomURLAction"
method="execute"
url="netmarkets/jsp/cz/aveng/DownloadZIP/DownloadZIPWizard.jsp"
windowType="popup" />
</action>

 

Step1

<action name="DownloadZIPWizardStep1" preloadWizardPage="true" resourceBundle="com.ptc.core.ui.actionsRB">
<command windowType="wizard_step"
url="netmarkets/jsp/cz/aveng/DownloadZIP/DownloadZIPWizardStep1.jsp"/>
</action>

 

the Wizard JSP page(DownloadZIPWizard) should contains wizard definition 

example

<jca:wizard formProcessorController="cz.aveng.PublcZip.ZipColectProcessorController"
title="Data Collector"
buttonList="DefaultWizardButtonsNoApply">
<jca:wizardStep action="DownloadZIPWizardStep1" type="psb" label="Data Collector"/>
</jca:wizard>

and here is the trick 

here you need to define own ProcessController class in 

formProcessorController=

example of formProcessorController

package cz.aveng.PublcZip;

import com.ptc.core.components.beans.ObjectBean;
import com.ptc.core.components.forms.DefaultFormProcessorController;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

public class ZipColectProcessorController extends DefaultFormProcessorController
{
@Override
protected List<ObjectBean> getRootObjectBeans()
{
List objectBeanList = super.getRootObjectBeans();
Iterator next = objectBeanList.iterator();
List<String> delegate = new ArrayList<>();
//Processor delegagte (very important Delegate if is not set, then Processor is pushed to delegate which is not possible error can not catst Processor to ProcessorDelegate)
delegate.add("com.ptc.core.components.forms.DefaultObjectFormProcessorDelegate")
;
while (next.hasNext())
{
ObjectBean objectBean = (ObjectBean) next.next();
// Processor for managing action after OK button
objectBean.setProcessorClassName("cz.aveng.PublcZip.ZipColectProcessor");
// here is own Processor
objectBean.setDelegateClassNames(delegate); // add DefaultObjectFormProcessorDelegate
}
super.setRootObjectBeans(objectBeanList);
return super.getRootObjectBeans();
}
}

the processor ZipColectProcessor contains the code with the action and there you can do what you want :D.

preProcess, doOperation, postProcess.....

 

Hope it could be helpful.

 

Best Regards

PetrH

it works! Thank you !

@_1647
13-Aquamarine
(To:HelesicPetr)

Hi @HelesicPetr,

In custom action what is this URL defines with path like /ptc1/........ 

Normally we use URL to call JSP page but here I am confused with this path /ptc1/......
in windchill where we get this folder named as /ptc1/....

 

HelesicPetr
22-Sapphire I
(To:@_1647)

Hi @_1647 

Why are you confided? this url is normally used in the Windchil and someone just tried to copy an OOTB URL from wizard opened from menu as an example.

But it does not work as I would expect

Check edit part wizard URL from PSB and you realized that the url with ptc1 is used

HelesicPetr_0-1727415030046.png

example of my custom function

HelesicPetr_2-1727417449149.png

 

I've never used the ptc1 in the action menu because it does not make sense.

 

also they can place their  jsp pages in the codebase/ptc1/.... folder...

PetrH

@_1647
13-Aquamarine
(To:HelesicPetr)

Thank you HelesicPetr for information.

And definitely I will check that.

Announcements


Top Tags