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

where used tab custom column

  • January 20, 2017
  • 1 reply
  • 8062 views

Experts,

Need to add a couple of custom column (for custom attributes) in the where used tab.

Pl help,

Thanks,

Ravin Kayasth

1 reply

15-Moonstone
January 20, 2017

You need to write some java code, and have some JCA skills :

If you add &jcaDebug=1 at the end of the URL, you'll see this.

Sélection_151.png

What you need to do is to create a new class to extends WhereUsedTreeBuilder

and override    public ComponentConfig buildComponentConfig(ComponentParams componentParams) throws WTException

The existing code is

    public ComponentConfig buildComponentConfig(ComponentParams componentParams) throws WTException {
        if (log.isDebugEnabled()) {
            log.debug((Object)"WhereUsedTreeBuilder - Entering buildComponentConfig");
        }
        if (log.isTraceEnabled()) {
            log.trace((Object)("WhereUsedTreeBuilder.buildComponentConfig input params " + (Object)componentParams));
        }
        String string = "";
        NmHelperBean nmHelperBean = ((JcaComponentParams)componentParams).getHelperBean();
        NmCommandBean nmCommandBean = nmHelperBean.getNmCommandBean();
        NmSessionBean nmSessionBean = nmHelperBean.getNmSessionBean();
        ComponentConfigFactory componentConfigFactory = this.getComponentConfigFactory();
        JcaTreeConfig jcaTreeConfig = (JcaTreeConfig)componentConfigFactory.newTreeConfig();
        Object object = nmCommandBean.getPageOid().getRef();
        string = EnterpriseHelper.isProjectLink((Persistable)object) ? "whereUsed" : "whereUsed.view";
        if (nmCommandBean.getTextParameter("viewchange") != null) {
            nmSessionBean.removeAllNodes(nmCommandBean, "whereUsed.view");
        }
        componentParams.setAttribute("whereUsedTableID", (Object)string);
        jcaTreeConfig.setId(string);
        jcaTreeConfig.setShowCustomViewLink(false);
        jcaTreeConfig.setNodeColumn("number");
        jcaTreeConfig.setExpansionLevel("one");
        jcaTreeConfig.setTargetObject("contextObject");
        jcaTreeConfig.setLabel(this.messageWhereUsedResource.getMessage("1"));
        jcaTreeConfig.setSelectable(true);
        jcaTreeConfig.setActionModel("whereUsedTablePart");
        ColumnConfig columnConfig = componentConfigFactory.newColumnConfig("number", true);
        columnConfig.setInfoPageLink(false);
        columnConfig.setDataUtilityId("whereUsedNumber");
        jcaTreeConfig.addComponent((ComponentConfig)columnConfig);
        jcaTreeConfig.addComponent((ComponentConfig)componentConfigFactory.newColumnConfig("orgid", false));
        columnConfig = componentConfigFactory.newColumnConfig("groupedVersions", false);
        columnConfig.setTargetObject("");
        columnConfig.setVariableHeight(true);
        jcaTreeConfig.addComponent((ComponentConfig)columnConfig);
        jcaTreeConfig.addComponent((ComponentConfig)componentConfigFactory.newColumnConfig("name", true));
        columnConfig = componentConfigFactory.newColumnConfig("containerName", true);
        columnConfig.setTargetObject("contained");
        jcaTreeConfig.addComponent((ComponentConfig)columnConfig);
        columnConfig = componentConfigFactory.newColumnConfig("nmActions", false);
        ((JcaColumnConfig)columnConfig).setDescriptorProperty((Object)"actionModel", (Object)"EMPTY_ACTION_MODEL");
        jcaTreeConfig.addComponent((ComponentConfig)columnConfig);
        jcaTreeConfig.setHelpContext("WhereUsedTableHelp");
        jcaTreeConfig.setDataSourceMode(DataSourceMode.ASYNCHRONOUS);
        if (log.isDebugEnabled()) {
            log.debug((Object)("Tree Id is   :-- " + jcaTreeConfig.getId()));
        }
        return jcaTreeConfig;
    }

So, you should end with something like this :

package ext.myProject.jca;

import com.ptc.jca.mvc.components.JcaTreeConfig;
import com.ptc.mvc.components.ComponentConfig;
import com.ptc.mvc.components.ComponentConfig;
import com.ptc.mvc.components.ComponentConfigFactory;
import com.ptc.mvc.components.ComponentParams;
import com.ptc.windchill.enterprise.object.mvc.builders.WhereUsedTreeBuilder;
import wt.util.WTException;

/**
* $Rev::                                                                                                   $:  Version
* $Author::                                                                                                $:  Dernier modificateur
* $Date::                                                                                                  $:  Date du dernier commit
* Url de la version la plus recente
* $HeadURL$
**/
public class MyCustomWhereUsedTreeBuilder extends WhereUsedTreeBuilder {

    @Override
    public ComponentConfig buildComponentConfig(ComponentParams componentParams) throws WTException {
        JcaTreeConfig jcaTreeConfig = (JcaTreeConfig) super.buildComponentConfig(componentParams);

        ComponentConfigFactory componentConfigFactory = this.getComponentConfigFactory();
        jcaTreeConfig.addComponent((ComponentConfig)componentConfigFactory.newColumnConfig("myCustomAttribute", false));
       
        return jcaTreeConfig;                                                                                   
    }
}

And to replace the existing table by yours, you need to declare it in Windchill/codebase/config/mvc/custom.xml

by adding

<bean class="ext.myProject.jca.MyCustomWhereUsedTreeBuilder"/>

This should be enough.

Data are queried in buildComponentData, and uses com.ptc.windchill.enterprise.object.WhereUsedTreeHandler.

Normally, you new attributes in jcaTreeConfig should be queried.

17-Peridot
January 21, 2017

‌If you change or even create a new table view, you need to delete the views in the DB.

Check first if a view already exists:

select * from TABLEVIEWDESCRIPTOR where TABLEID = 'whereUsed.view';select * from ACTIVEVIEWLINK where TABLEID='whereUsed.view';

If so, do a backup of the table and delete them:

Delete from TABLEVIEWDESCRIPTOR where TABLEID='whereUsed.view';Delete from ACTIVEVIEWLINK where TABLEID='whereUsed.view';commit;

Then restart Windchill

Have fun