Additional Windchill Capabilities > Manufacturing Process Management > Customizing the Product Structure Explorer (PSE) > Creating a Requirements Tab > Implement an 'enabled decider' class to control when the tab is enabled
  
Implement an 'enabled decider' class to control when the tab is enabled
This creates a new class which will control when the Requirements tab is enabled and disabled. Only when a part is selected in the structure tree, which matches one of the types specified in the enabled decider class, will the Requirements tab be enabled and operational.
1. Create the RequirementsEnabledDecider.java file from the following location:
<Windchill>/codebase/com/mycom/windchill/explorer/structureexpl
orer/deciders
2. Modify the following implementation as necessary:
Modify the common_ancestry string so that it matches the parent type hierarchy of the parts for which you want to view Requirements.
In the static code block, add an entry to the type_id_list for each part type which you want to view the Requirements
package
com.mycom.windchill.explorer.structureexplorer.deciders;

import java.util.ArrayList;
import java.util.List;
import
wt.services.applicationcontext.implementation.DefaultServicePro
vider;

import
com.ptc.core.foundation.struct.common.StructureConstants;
import com.ptc.core.meta.common.AssociationIdentifier;
import com.ptc.core.meta.common.AssociationTypeIdentifier;
import com.ptc.core.meta.common.AttributeTypeIdentifier;
import com.ptc.core.meta.common.IdentifierFactory;
import com.ptc.core.meta.common.TypeIdentifier;
import com.ptc.core.meta.common.TypeInstanceIdentifier;
import com.ptc.core.meta.type.common.TypeInstance;
import
com.ptc.windchill.explorer.structureexplorer.config.AbstractCon
fig;
import
com.ptc.windchill.explorer.structureexplorer.deciders.EnabledDe
cider;
import
com.ptc.windchill.explorer.structureexplorer.utility.CommonData
;

public class RequirementsEnabledDecider implements
EnabledDecider
{
private static IdentifierFactory identifierFactory =
(IdentifierFactory)
DefaultServiceProvider.getService(IdentifierFactory.class,
"logical"); //$NON-NLS-1$

private static List<TypeIdentifier> type_id_list = new
ArrayList<TypeIdentifier>();
private static String common_ancestry = "WCTYPE|
wt.part.WTPart|com.mycom.MyPart|"; //$NON-NLS-1$

static {
try
{
type_id_list.add(

(TypeIdentifier)identifierFactory.get(common_ancestry +
"com.mycom.CustomPartA")); //$NON-NLS-1$
type_id_list.add(

(TypeIdentifier)identifierFactory.get(common_ancestry +
"com.mycom.CustomPartB")); //$NON-NLS-1$
type_id_list.add(

(TypeIdentifier)identifierFactory.get(common_ancestry +
"com.mycom.CustomPartC")); //$NON-NLS-1$
type_id_list.add(

(TypeIdentifier)identifierFactory.get(common_ancestry +
"com.mycom.CustomPartD")); //$NON-NLS-1$
}
catch(Exception e)
{
e.printStackTrace();
}
}


public boolean isItemEnabled(TypeInstance node_ti,
TypeInstance parent_node_ti, AbstractConfig item_config,
CommonData common_data)
{
boolean enabled = true

if (node_ti !=null)
{
enabled = isValidPart(node_ti);
}

return enabled;
}

/**
* is this node a generice part or a configurable generic
part?
**/
public static boolean isValidPart(TypeInstance node_ti)
{
if (node_ti ==null)
{
return false;
}
TypeInstanceIdentifier node_tii = (TypeInstanceIdentifier)
node_ti.getIdentifier();
if (node_tii ==null)
{
return false;
}
try
{
if (IsMasterd(node_ti))
{
return false;
}

TypeIdentifier type_id = trimTypeId((TypeIdentifier)
node_tii.getDefinitionIdentifier());

for(TypeIdentifier spec_type_id : type_id_list)
{
if(type_id.isDescendedFrom(spec_type_id))
(
return true;
}
}

return false;
}
catch (Exception e)
{
return false;
}
}


/**
* Assumes an iteration...
*
* isMastered is an unpersisted Iteration and a persisted
Master.
*@param ti
*@return
*
*/
private static boolean IsMastered(TypeInstance ti)
{
try
{
TypeInstanceIdentifier tii = (TypeInstanceIdentifier)
ti.getIdentifier();
if (tii instanceod AssociationIdentifier)
{
tii = ((AssociationIdentifier) tii).getTail();
}
if (!tii.isInitialized())
{
AttributeTypeIdentifier master_ati =
(AttributeTypeIdentifier)

identifierFactory.get(StructureConstants.MASTER_REFERENCE_ID_ST
R, tii.getDefinitionIdentifier());
Object object = ti.getSingle(master_ati);
TypeInstanceIdentifier master_tii = null;
if (object instanceof TypeInstanceIdentifier)
{
master_tii = (TypeInstanceIdentifier) object;
}
if (master_tii.isIntialized())
{
return true;
}
}
}
catch (Exception ex)
{
return false;
}

return false;
)

private static TypeIdentifier trimTypeId(TypeIdentifier
type_id)
{
if (type_id instanceof AssociationTypeIdentifier)
{
return ((AssociationTypeIdentifier) type_id).getTail();
}
return teyp_id;
}
}