package com.tem.rac.custom.
handlers;
import com.teamcenter.services.loose.core._2006_03.DataManagement.ItemProperties;
import com.teamcenter.rac.kernel.TCSession;
import com.teamcenter.schemas.soa._2006_03.base.ObjectPropertyPolicy;
import com.teamcenter.schemas.soa._2006_03.base.PolicyProperty;
import com.teamcenter.rac.kernel.TCComponentFolder;
import com.teamcenter.rac.kernel.TCComponentUser;
import com.teamcenter.rac.kernel.TCException;
import com.teamcenter.rac.aif.AbstractAIFUIApplication;
import com.teamcenter.rac.aifrcp.AIFUtility;
import com.teamcenter.services.loose.core.DataManagementService;
import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.ui.handlers.HandlerUtil;
public class SampleHandler extends AbstractHandler {
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
IWorkbenchWindow window =
HandlerUtil.getActiveWorkbenchWindowChecked(event);
AbstractAIFUIApplication app = AIFUtility.getCurrentApplication();
// Get the current Teamcenter session
TCSession session = (TCSession) app.getSession();
TCComponentUser user = session.getUser();
try {
// 1. Create Object Property Policy programmatically
ObjectPropertyPolicy policy = new ObjectPropertyPolicy();
// Add types and properties to the policy
policy.addType("WorkspaceObject", new String[] { "object_string",
"object_type" });
policy.addType("Folder", new String[] { "contents" });
policy.addType("BOMLine", new String[] { "bl_has_children",
"bl_is_variant" });
// Apply additional modifiers to properties if needed
// For example: WITH_PROPERTIES modifier can be used to include
associated objects' properties
policy.addType("Folder", new String[] { "contents" }, new String[]
{ PolicyProperty.WITH_PROPERTIES });
// 2. Set the policy for the current session
session.setObjectPropertyPolicy(policy);
// 3. Create an item using the defined policy
TCComponentFolder fl = user.getHomeFolder();
DataManagementService service =
DataManagementService.getService(session.getSoaConnection());
// Create the item properties
ItemProperties[] prop = new ItemProperties[1];
ItemProperties prop1 = new ItemProperties();
prop1.clientId = "TC014453";
prop1.itemId = "01954";
prop1.revId = "A";
prop1.type = "Item";
prop1.name = "Nexa1";
prop[0] = prop1;
// Call the service to create the item
service.createItems(prop, fl, "contents");
} catch (TCException e) {
// Handle errors and exceptions
e.printStackTrace();
}
return null;
}
}