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

Community Tip - New to the community? Learn how to post a question and get help from PTC and industry experts! X

where used tab custom column

rkayasth
10-Marble

where used tab custom column

Experts,

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

Pl help,

Thanks,

Ravin Kayasth

10 REPLIES 10

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.

‌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

Hi fellow devs,

 

I had to modify the same tree/table and got on the same path described by oliverfresse, however there are some additional things you have to do to achieve the expected. After you have everything oliverfresse described, you have to extend the TableBuilder attached to this TreeBuilder and reference that new class.

 

    public ConfigurableTable buildConfigurableTable(String paramString) throws WTException {
        ConfigurableTable table = null;
        if (paramString.equals(TABLEID)) {
            table = newCustomWhereUsedTableView();
        } else {
            table = super.buildConfigurableTable(paramString);
        }
        return table;
    }

In this custom table view you have to define your columns per view. Something like this:

 

 

@Override
    public List<TableViewDescriptor> getOOTBTableViews(String paramString, Locale paramLocale) throws WTException {
        ArrayList<TableViewDescriptor> localArrayList = new ArrayList<TableViewDescriptor>(1);
        Vector<TableColumnDefinition> localVector1 = new Vector<TableColumnDefinition>(6);
        Vector<TableColumnDefinition> localVector2 = new Vector<TableColumnDefinition>(6);
        try {
            localVector1.add(TableColumnDefinition.newTableColumnDefinition("number", true));
            localVector1.add(TableColumnDefinition.newTableColumnDefinition("orgid", true));
            localVector1.add(TableColumnDefinition.newTableColumnDefinition("groupedVersions", false));
            localVector1.add(TableColumnDefinition.newTableColumnDefinition("myCustomAttribute", false));
            localVector1.add(TableColumnDefinition.newTableColumnDefinition("name", false));
            localVector1.add(TableColumnDefinition.newTableColumnDefinition("containerName", false));
            String str1 = getViewResourceEntryKey(RESOURCE, "3");
            String str2 = getViewResourceEntryKey(RESOURCE, "3");
            TableViewDescriptor localTableViewDescriptor = TableViewDescriptor.newTableViewDescriptor(str1, paramString,
                    true, true, localVector1, null, true, str2);
            localTableViewDescriptor.setSystem(false);
            localArrayList.add(localTableViewDescriptor);

            localVector2.add(TableColumnDefinition.newTableColumnDefinition("number", true));
            localVector2.add(TableColumnDefinition.newTableColumnDefinition("orgid", true));
            localVector2.add(TableColumnDefinition.newTableColumnDefinition("groupedVersions", false));
            localVector2.add(TableColumnDefinition.newTableColumnDefinition("myCustomAttribute", false));
            localVector2.add(TableColumnDefinition.newTableColumnDefinition("name", false));
            localVector2.add(TableColumnDefinition.newTableColumnDefinition("containerName", false));
            str1 = getViewResourceEntryKey(RESOURCE, "2");
            str2 = getViewResourceEntryKey(RESOURCE, "2");
            localTableViewDescriptor = TableViewDescriptor.newTableViewDescriptor(str1, paramString, true, true,
                    localVector2, null, true, str2);
            localTableViewDescriptor.setSystem(false);
            localArrayList.add(localTableViewDescriptor);
        } catch (WTPropertyVetoException localWTPropertyVetoException) {
            throw new WTRuntimeException(localWTPropertyVetoException);
        }
        return localArrayList;
    }

Note the myCustomAttribute added. After this you have to create a dataUtility in which you add your value. In the treeBuilder you have to set your column as column.setTargetObject(""); so that you will get the WhereUsedDataItem type (mixture of PartMaster and Part info encapsulated in it) in the dataUtility. Personally I have overridden the grouppedVersions dataUtility and left the super class to construct the data and just went through the nmActions (for the respective WTParts) and changed the display value (description) of the nmAction from version to the custom attribute.

Until this point you will have the new column, however the view selection is dependent on the real whereUsed table. In order that your view selector to work you have to override the TreeHandler also.

 

@Override
    public void buildNodeData(Object paramObject, ComponentResultProcessor paramComponentResultProcessor)
            throws Exception {
        @SuppressWarnings("rawtypes")
        Map<Object, List> localMap;
        if (paramObject == TreeNode.RootNode) {
            treeHandler = new CustomWhereUsedTreeHandler(paramComponentResultProcessor.getParams());
            paramComponentResultProcessor.addElements(treeHandler.getRootNodes());
        } else {
            ArrayList<Object> localArrayList = new ArrayList<Object>();
            localArrayList.add(paramObject);
            if (treeHandler == null) {
                treeHandler = new CustomWhereUsedTreeHandler(paramComponentResultProcessor.getParams());
            }
            localMap = treeHandler.getNodes(localArrayList);
            Set<Object> localSet = localMap.keySet();
            for (Object localObject : localSet) {
                paramComponentResultProcessor.addElements(localMap.get(localObject));
            }
        }
    }

And in this custom tree handler you have to change the name of the tableID that you set in the treeBuilder.

 

public CustomWhereUsedTreeHandler(ComponentParams paramComponentParams) throws WTException {
        super(paramComponentParams);
        currentView = TableViewUtils.getCurrentView(TABLEID);
    }

 Also in the treeBuilder buildComponentConfig you have to set these properties of the tree:

treeConfig.setLabel("Custom Where Used");
treeConfig.setId(TABLEID);
compParams.setAttribute("whereUsedTableID", TABLEID);

If anyone is interested in any further details, you can send me a pm.

 

BR,
Tamás 

 

 

mmedeiros
6-Contributor
(To:TamasBiro)

Hi TamasBiro,

I tried to deploy your solution in Windchill 11.0 and I did not succeed.

I encountered some difficulties, for example could not find the TableBuilder Class.

whereUsed.png

Can you share the source code?

Hi,

 

sorry for replying this late, I did not check my account since a while. I don't think this is still relevant for you, however for future devs might come in handy. I had a mistake in my explanation. There is no tableBuilder, instead you have to extend only the mentioned treeBuilder to assign a different tableView to it. Consider where I say tableBuilder I'm still talking about the WhereUsedTreeBuilder which I extended and registered the TableView that I was describing afterwards. Note that everywhere I use the same TABLEID, which is set also for the treeConfig ( 

treeConfig.setLabel(messageCustomerWhereUsedResource.getMessage(TABLEID));
treeConfig.setId(TABLEID);
compParams.setAttribute("whereUsedTableID", TABLEID);

)

Tamas - Can you please give further details about this customization? we would like to apply it to our WNC 11.0 M030 CPS16/CPS17 Instance...

 

TIA&VBR/H

Hi,

 

please explain where you are stuck, then I could give some more details, however if you follow the steps oliverfresse described and extend it with the code I posted above, you should be able to figure it out.

 

BR,

Tamás

 

Hello TamasBiro.

Could you explane this point

You write
"you have to create a dataUtility in which you add your value. In the treeBuilder you have to set your column as column.setTargetObject("")"


I need to add colum whereUsedQuantity to this table.
Could you tell more about dataUtility for new colum.

import java.util.Locale;

import com.ptc.core.components.descriptor.ModelContext;
import com.ptc.core.components.rendering.GuiComponent;
import com.ptc.core.components.rendering.guicomponents.GUIComponentArray;
import com.ptc.core.components.rendering.guicomponents.NmActionGuiComponent;
import com.ptc.netmarkets.util.misc.NmAction;
import com.ptc.windchill.enterprise.object.dataUtilities.GroupedVersionsDataUtility;

import wt.lifecycle.LifeCycleManaged;
import wt.lifecycle._LifeCycleManaged;
import wt.util.WTException;
import wt.util.WTMessage;

/**
 * 
 * @author tamas.biro
 *
 */
public class GroupedStatesDataUtility extends GroupedVersionsDataUtility {

    private static final String COLUMNID = "groupedStates";
    protected static final String RESOURCE = "ext.whereused.resource.CustomRB";

    @Override
    protected String getColumnId() {
        return COLUMNID;
    }

    @Override
    public Object getDataValue(String paramString, Object paramObject, ModelContext paramModelContext)
            throws WTException {
        GUIComponentArray grouppedVersions = (GUIComponentArray) super.getDataValue(paramString, paramObject,
                paramModelContext);
        GUIComponentArray grouppedStates = new GUIComponentArray();

        for (int i = 0; i < grouppedVersions.size(); i++) {
            GuiComponent comp = grouppedVersions.get(i);
            if (comp instanceof NmActionGuiComponent) {
                NmAction action = ((NmActionGuiComponent) comp).getAction();
                Object contextObject = action.getContextObject().getRefObject();
                if (contextObject instanceof LifeCycleManaged) {
                    action.setDesc(((_LifeCycleManaged) contextObject).getState().getState().getDisplay());
                }
            }
            grouppedStates.addGUIComponent(comp);
        }

        return grouppedStates;

    }

    @Override
    public String getLabel(String paramString, ModelContext paramModelContext) throws WTException {
        String str = null;
        Locale localLocale = getLocale();
        str = WTMessage.getLocalizedMessage(RESOURCE, "GROUPPED_STATES", null, localLocale);
        if (str == null) {
            str = paramString;
        }
        return str;
    }
}
HelesicPetr
22-Sapphire I
(To:TamasBiro)

Hi all.

You can check another solution described on a following thread How-to-Customize-where-used-panel

PetrH

Announcements

Top Tags