Skip to main content
1-Visitor
January 17, 2017
Question

how do I programatically hide a tab on the Part Info page

  • January 17, 2017
  • 1 reply
  • 4601 views

I would like to have an attribute control the display of a custom tab on the Part info page.

So:

1) if I add a Boolean attribute called 'Is Pair'

2) if the 'Is Pair' = false  Then   the 'Pair' tab will NOT be displayed

a) After the part is checked in

b) When the Info page is navigated to

3) if the 'Is Pair' = true Then   the 'Pair' tab will be displayed

a) After the part is checked in

b) When the Info page is navigated to

Thanks for the help

SRM

1 reply

16-Pearl
January 19, 2017

Hi Scott,

Is the additional tab you created is added through Customization (action model) or created using New Tab > Customize option available out of the box?

Thanks,

Shirish

smorrison1-VisitorAuthor
1-Visitor
January 19, 2017

Good question.

It will be added through Customization (action model).

Scott

16-Pearl
January 19, 2017

Hi Scott Morrison,

To achieve this you can write your own validator which will first get IBA value from WTPart. Once you have IBA value you can then decide whether to display or hide custom tab.

Your validator code will looks something like below:

public class HideCustomTab extends  DefaultUIComponentValidator {

  /* (non-Javadoc)

  * @see com.ptc.core.ui.validation.DefaultUIComponentValidator#performFullPreValidation(com.ptc.core.ui.validation.UIValidationKey, com.ptc.core.ui.validation.UIValidationCriteria, java.util.Locale)

  */

  @Override

  public UIValidationResultSet performFullPreValidation(UIValidationKey vkey, UIValidationCriteria vcriteria, Locale locale) throws WTException {

  return validateCustomTab(vkey, vcriteria, locale);

  }

  /* (non-Javadoc)

  * @see com.ptc.core.ui.validation.DefaultUIComponentValidator#performLimitedPreValidation(com.ptc.core.ui.validation.UIValidationKey, com.ptc.core.ui.validation.UIValidationCriteria, java.util.Locale)

  */

  @Override

  public UIValidationResultSet performLimitedPreValidation(UIValidationKey vkey, UIValidationCriteria vcriteria, Locale locale) throws WTException {

  return validateCustomTab(vkey, vcriteria, locale);

  }

  public UIValidationResultSet validateCustomTab(UIValidationKey vkey, UIValidationCriteria vcriteria, Locale locale) throws WTException {

  UIValidationResultSet vrs = UIValidationResultSet.newInstance();

  UIValidationResult vr = UIValidationResult.newInstance();

  vr.setValidationKey(vkey);

  // Below API will give you the actual object.

  WTReference wref = vcriteria.getPageObject();

  Persistable PObj = wref.getObject();

  if (PObj instanceof WTPart) {

  WTPart prt = (WTPart) PObj;

  PersistableAdapter theIBAs = new PersistableAdapter(prt, null, java.util.Locale.US, new UpdateOperationIdentifier());

  theIBAs.load("EnumValue");

  java.lang.Boolean ibaObject = Boolean.parseBoolean(theIBAs.get("EnumValue").toString());

  if (ibaObject) {

  vrs.addResult(UIValidationResult.newInstance(vkey, UIValidationStatus.ENABLED));

  }else{

  vrs.addResult(UIValidationResult.newInstance(vkey, UIValidationStatus.HIDDEN));

  }

  }

  return vrs;

  }

}

To hook this validator you can add below entry to site.xconf file and propagate changes by "xconfmanager -p" command:

<Service context="default" name="com.ptc.core.ui.validation.UIComponentValidator"

            targetFile="codebase/service.properties">

      <Option cardinality="singleton" order="0" overridable="true" requestor="null"

              selector="CustomTab4Part"

              serviceClass="ext.Validators.HideCustomTab"/>

   </Service>

Restart MS server and you're all set.

If IBA has value true, then Custom Tab will be displayed otherwise it will be hidden.

     Custom Tab.png

I hope this helps you!

Regards,

Shirish