Friday, May 24, 2019

How to deploy Projects JAR to teamcenter


How to deploy Projects JAR to teamcenter

Copy the jar file which you want to deploy.

Paste it to:
Tc-Root(Teamcenter installed location) -> Portal -> Plugins

Now,Open registry folder

Run genregxml.bat file

Wait for sometime console will close automatically.

Thursday, May 16, 2019

Is Item Exist

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JTextField;

import com.teamcenter.rac.aif.AbstractAIFApplication;
import com.teamcenter.rac.aifrcp.AIFUtility;
import com.teamcenter.rac.kernel.TCComponent;
import com.teamcenter.rac.kernel.TCComponentQuery;
import com.teamcenter.rac.kernel.TCComponentQueryType;
import com.teamcenter.rac.kernel.TCException;
import com.teamcenter.rac.kernel.TCSession;

public class IsItemExist {

String msg="";
TCComponentQueryType qtype=null;
TCComponentQuery tcq=null;
JTextField text=new JTextField();
JFrame frame=new JFrame("Search Item");

AbstractAIFApplication app=AIFUtility.getCurrentApplication();
TCSession session=(TCSession) app.getSession();

public void Dialoge() throws TCException
{
text.setSize(100, 29);
frame.setSize(250, 130);

JPanel panel=new JPanel();
panel.setSize(250, 125);
panel.setLayout(null);

JLabel label1=new JLabel("Item Id");
JLabel label2=new JLabel("Enter Item Id to search");

JButton Search=new JButton("SEARCH");
label2.setBounds(50, 10, 150, 29);
label1.setBounds(30, 40, 80, 29);
text.setBounds(120,40, 100,29);
Search.setBounds(40, 70, 100, 29);

Search.addActionListener(new ActionListener() {

@Override
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
try {
isItemExist();
} catch (TCException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
}
});

panel.add(label2);
panel.add(label1);
panel.add(text);
panel.add(Search);
frame.add(panel);

frame.setVisible(true);
frame.repaint();

}
public void isItemExist() throws TCException
{
String ItemId=text.getText();
qtype=(TCComponentQueryType) session.getTypeComponent("ImanQuery");
tcq=(TCComponentQuery) qtype.find("Item...");

String[] entry={"Item ID"};
String[] value={ItemId};

TCComponent[] result=tcq.execute(entry, value);

if(result==null || result.length==0)
{
JOptionPane.showMessageDialog(frame, "No such Item found with Item ID "+ItemId);
//System.out.println("No such Item found with Item ID "+ItemId);
}
else
{
JOptionPane.showMessageDialog(frame, ItemId+" Item Found");
//System.out.println("Item Found");
}
}

}

Create Excel Report using Execute Query on selected Dates

import java.awt.Color;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Calendar;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;

import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.ss.usermodel.WorkbookFactory;

import com.teamcenter.rac.aif.AbstractAIFApplication;
import com.teamcenter.rac.aifrcp.AIFUtility;
import com.teamcenter.rac.kernel.TCComponent;
import com.teamcenter.rac.kernel.TCComponentQuery;
import com.teamcenter.rac.kernel.TCComponentQueryType;
import com.teamcenter.rac.kernel.TCProperty;
import com.teamcenter.rac.kernel.TCSession;
import com.teamcenter.rac.util.iTextField;

public class SearchDateItem {

  JFrame frame=new JFrame();
JPanel panel=new JPanel();

JLabel label1=new JLabel("Start Date");
JLabel label2=new JLabel("End Date");

JButton button1=new JButton("Search");

iTextField textfield1=new iTextField();
iTextField textfield2=new iTextField();

String s1;
String s2;

TCProperty Object_Name;
    TCProperty Type;
    TCProperty Owner;
    TCProperty GropupID;
    TCProperty DateModified;
   
 
public void search() throws InvalidFormatException, IOException
{
s1=textfield1.getText();
s2=textfield2.getText();
FileInputStream input=new FileInputStream(new File("C:\\Temp\\ExcelWorksheet.xlsx"));
Workbook workbook=WorkbookFactory.create(input);

Sheet sheet=(Sheet) workbook.getSheetAt(0);

AbstractAIFApplication app=AIFUtility.getCurrentApplication();
TCSession session=(TCSession) app.getSession();

try
{
TCComponentQueryType querytype=(TCComponentQueryType) session.getTypeComponent("ImanQuery");
TCComponentQuery query=(TCComponentQuery) querytype.find("Item...");

String[] EntryName={"Created After","Created Before"};
String[] EntryValue={s1,s2};
//Date formate
//dd-mmm-yyyy
//e.g- 19-may-2000

TCComponent[] comp=query.execute(EntryName, EntryValue);

int rowincr=1;
        int colincr=0;
     
        for(int i=0;i<comp.length;i++)
{
TCComponent taskcomp=(TCComponent) comp[i];
Object_Name=taskcomp.getTCProperty("object_name");
Type=taskcomp.getTCProperty("object_type");
Owner=taskcomp.getTCProperty("owning_user");
GropupID=taskcomp.getTCProperty("owning_group");
DateModified=taskcomp.getTCProperty("last_mod_date");


Cell cell1=sheet.getRow(rowincr).getCell(colincr);
cell1.setCellValue(Object_Name.toString());
colincr++;

Cell cell2=sheet.getRow(rowincr).getCell(colincr);
cell2.setCellValue(Type.toString());
colincr++;

Cell cell3=sheet.getRow(rowincr).getCell(colincr);
cell3.setCellValue(Owner.toString());
colincr++;

Cell cell4=sheet.getRow(rowincr).getCell(colincr);
cell4.setCellValue(GropupID.toString());
colincr++;

Cell cell5=sheet.getRow(rowincr).getCell(colincr);
cell5.setCellValue(DateModified.toString());
colincr++;

colincr=0;

rowincr++;

} catch (Exception e) {

}
FileOutputStream fos = new FileOutputStream("C:\\Temp\\ExcelWorksheet.xlsx");
workbook.write(fos);
fos.close();

}
public void createDialoge()
{
frame.setTitle("Report Generation");
    frame.getContentPane().setBackground(Color.WHITE);
    frame.setResizable(true);
    frame.setSize(400, 150);
 
    panel.setBounds(0, 0, 400, 150);
    panel.setBackground(Color.white);
panel.setLayout(null);
    panel.add(label1);
    label1.setBounds(20, 20, 100, 29);
 
    panel.add(label2);
    label2.setBounds(20, 50, 100, 29);
 
    panel.add(button1);
    button1.setBounds(150, 80, 150, 25);
 
    panel.add(textfield1);
    textfield1.setBounds(150, 20, 100, 25);
   
    panel.add(textfield2);
    textfield2.setBounds(150, 50, 100, 25);
 
    button1.addActionListener(new ActionListener() {

@Override
public void actionPerformed(ActionEvent e) {

SearchDateItem sdi=new SearchDateItem();
try {

sdi.search();
System.out.println("hi");
} catch (InvalidFormatException e1) {

e1.printStackTrace();
} catch (IOException e1) {

e1.printStackTrace();
}
}
});
 
    frame.add(panel);
    frame.setLayout(null);
    frame.setVisible(true);
    frame.revalidate();
    frame.repaint();
    frame.setVisible(true);
 
}
}

Wednesday, May 15, 2019

Create Excel Report of Multiple Schedule Task of Schedule Manager

//This will create excel report of mutliple schedule task stored in folder.

import java.io.FileOutputStream;

import org.apache.poi.hssf.util.HSSFColor;
import org.apache.poi.ss.usermodel.BorderStyle;
import org.apache.poi.ss.usermodel.CellStyle;
import org.apache.poi.xssf.usermodel.XSSFCellStyle;
import org.apache.poi.xssf.usermodel.XSSFFont;
import org.apache.poi.xssf.usermodel.XSSFRow;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;

import com.teamcenter.rac.aif.AbstractAIFApplication;
import com.teamcenter.rac.aif.kernel.AIFComponentContext;
import com.teamcenter.rac.aifrcp.AIFUtility;
import com.teamcenter.rac.kernel.TCComponent;
import com.teamcenter.rac.kernel.TCComponentFolder;
import com.teamcenter.rac.kernel.TCComponentQuery;
import com.teamcenter.rac.kernel.TCComponentQueryType;
import com.teamcenter.rac.kernel.TCComponentSchedule;
import com.teamcenter.rac.kernel.TCProperty;
import com.teamcenter.rac.kernel.TCSession;

public class CreateReport {
int count=1;
FileOutputStream fileOut ;

public CreateReport() throws Exception
{
AbstractAIFApplication app=AIFUtility.getCurrentApplication();
TCSession session=(TCSession) app.getSession();
session.getUser();

String filename="C:\\Temp\\ScheduleExcelReport.xlsx";
XSSFWorkbook workbook = new XSSFWorkbook();
        XSSFSheet sheet = workbook.createSheet("FirstSheet");  
        sheet.setColumnWidth(0, 6000);
        sheet.setColumnWidth(1, 6000);
        sheet.setColumnWidth(2, 6000);
        sheet.setColumnWidth(3, 6000);
        sheet.setColumnWidth(4, 6000);
        sheet.setColumnWidth(5, 6000);
        
        XSSFCellStyle mystyle=workbook.createCellStyle();
        XSSFFont myfont=workbook.createFont();
        myfont.setBold(true);
        mystyle.setFont(myfont);
        mystyle.setFillForegroundColor(HSSFColor.GOLD.index);
        mystyle.setFillPattern(CellStyle.SOLID_FOREGROUND);
        mystyle.setBorderBottom(BorderStyle.MEDIUM);
        
        XSSFRow rowhead = sheet.createRow((short)0);
                rowhead.createCell(0).setCellValue("TASK NAME");
                rowhead.getCell(0).setCellStyle(mystyle);
            
               rowhead.createCell(1).setCellValue("START DATE");
               rowhead.getCell(1).setCellStyle(mystyle);
               rowhead.createCell(2).setCellValue("FINISHED DATE");
               rowhead.getCell(2).setCellStyle(mystyle);
               rowhead.createCell(3).setCellValue("ACTUAL START DATE");
               rowhead.getCell(3).setCellStyle(mystyle);
               rowhead.createCell(4).setCellValue("ACTUAL FINISH DATE");
               rowhead.getCell(4).setCellStyle(mystyle);
               rowhead.createCell(5).setCellValue("RESOURCE ASSIGNMENT");
               rowhead.getCell(5).setCellStyle(mystyle);
            
              fileOut = new FileOutputStream(filename);

      TCComponentQueryType querytype=(TCComponentQueryType)                                                                                               session.getTypeComponent("ImanQuery");
          TCComponentQuery query=(TCComponentQuery) querytype.find("General...");

String[] EntryName={"Name","Type"};
String[] EntryValue={"ScheduleFolder","Folder"};

TCComponent[] comp=query.execute(EntryName, EntryValue);

if(comp[0] instanceof TCComponentFolder)
{
AIFComponentContext[] context=comp[0].getChildren();
TCProperty Object_Name;
        TCProperty Start_Date;
          TCProperty Finish_Date;
TCProperty Actual_Start_Date;
TCProperty Actual_finish_Date;
TCProperty Resource_Assignment;
    
for (int i = 0; i < context.length; i++)
{
TCComponent tcc=(TCComponent) context[i].getComponent();

if (tcc instanceof TCComponentSchedule)
{
AIFComponentContext[] children=tcc.getChildren();
AIFComponentContext[]                                                                                                                                             SecChi=children[0].getComponent().getChildren();

XSSFRow row1 = sheet.createRow((short)count);
row1.createCell(0).setCellValue("               ");
count++;
XSSFRow row2 = sheet.createRow((short)count);
                        row2.createCell(1).setCellValue(children[0].toString());
                        row2.getCell(1).setCellStyle(mystyle);
                        count++;
                        XSSFRow row3 = sheet.createRow((short)count);
                         row3.createCell(0).setCellValue("               ");
                        count++;
                for(int j=0;j<SecChi.length;j++)
{
         TCComponent taskcomp=(TCComponent) 
                                                                                                      SecChi[j].getComponent();
Object_Name=taskcomp.getTCProperty("object_name");
Start_Date=taskcomp.getTCProperty("start_date");
Finish_Date=taskcomp.getTCProperty("finish_date");
Actual_Start_Date=taskcomp.getTCProperty("actual_start_date");
Actual_finish_Date=taskcomp.getTCProperty("actual_finish_date Resource_Assignment=taskcomp.getTCProperty("ResourceAssignment");

XSSFRow row = sheet.createRow((short)count);
            row.createCell(0).setCellValue(Object_Name.toString());
            row.createCell(1).setCellValue(Start_Date.toString());
            row.createCell(2).setCellValue(Finish_Date.toString());
            row.createCell(3).setCellValue(Actual_Start_Date.toString());
            row.createCell(4).setCellValue(Actual_finish_Date.toString());
            row.createCell(5).setCellValue(Resource_Assignment.toString());
            count++;
}   
}
}
}
workbook.write(fileOut);
fileOut.flush();
fileOut.close();
}
}

Create Excel Report of Selected Single Schedule Task in Schedule Manager

import java.io.FileOutputStream;
import java.io.IOException;

import org.apache.poi.hssf.util.HSSFColor;
import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
import org.apache.poi.ss.usermodel.BorderStyle;
import org.apache.poi.ss.usermodel.CellStyle;
import org.apache.poi.xssf.usermodel.XSSFCellStyle;
import org.apache.poi.xssf.usermodel.XSSFFont;
import org.apache.poi.xssf.usermodel.XSSFRow;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;

import com.teamcenter.rac.aif.kernel.AIFComponentContext;
import com.teamcenter.rac.aifrcp.AIFUtility;
import com.teamcenter.rac.kernel.TCComponent;
import com.teamcenter.rac.kernel.TCException;
import com.teamcenter.rac.kernel.TCProperty;
import com.teamcenter.rac.kernel.TCSession;

public class SingleReport {

int count=1;
FileOutputStream fileOut ;
TCSession session;

public SingleReport() throws InvalidFormatException, IOException, TCException
{
TCComponent tcc=(TCComponent)                                                                                                                                          AIFUtility.getCurrentApplication().getTargetComponent();
session=tcc.getSession();
session.getUser();

String filename="C:\\Temp\\SingleScheduleExcelReport.xlsx";
XSSFWorkbook workbook = new XSSFWorkbook();
                XSSFSheet sheet = workbook.createSheet("FirstSheet");
     
                sheet.setColumnWidth(0, 6000);
                sheet.setColumnWidth(1, 6000);
                sheet.setColumnWidth(2, 6000);
                sheet.setColumnWidth(3, 6000);
               sheet.setColumnWidth(4, 6000);
               sheet.setColumnWidth(5, 6000);
     
              XSSFCellStyle mystyle=workbook.createCellStyle();
              XSSFFont myfont=workbook.createFont();
              myfont.setBold(true);
              mystyle.setFont(myfont);
              mystyle.setFillForegroundColor(HSSFColor.GOLD.index);
              mystyle.setFillPattern(CellStyle.SOLID_FOREGROUND);
              mystyle.setBorderBottom(BorderStyle.MEDIUM);
     
              XSSFRow rowhead = sheet.createRow((short)0);
              rowhead.createCell(0).setCellValue("TASK NAME");
              rowhead.getCell(0).setCellStyle(mystyle);
     
        rowhead.createCell(1).setCellValue("START DATE");
        rowhead.getCell(1).setCellStyle(mystyle);
        rowhead.createCell(2).setCellValue("FINISHED DATE");
        rowhead.getCell(2).setCellStyle(mystyle);
        rowhead.createCell(3).setCellValue("ACTUAL START DATE");
        rowhead.getCell(3).setCellStyle(mystyle);
        rowhead.createCell(4).setCellValue("ACTUAL FINISH DATE");
        rowhead.getCell(4).setCellStyle(mystyle);
        rowhead.createCell(5).setCellValue("RESOURCE ASSIGNMENT");
        rowhead.getCell(5).setCellStyle(mystyle);
     
        fileOut = new FileOutputStream(filename);

AIFComponentContext[] children=tcc.getChildren();

TCProperty Object_Name;
        TCProperty Start_Date;
TCProperty Finish_Date;
        TCProperty Actual_Start_Date;
        TCProperty Actual_finish_Date;
 TCProperty Resource_Assignment;
 
        XSSFRow row1 = sheet.createRow((short)count);
row1.createCell(0).setCellValue("               ");
count++;
XSSFRow row2 = sheet.createRow((short)count);
        row2.createCell(1).setCellValue(children[0].toString());
        row2.getCell(1).setCellStyle(mystyle);
        count++;
        XSSFRow row3 = sheet.createRow((short)count);
        row3.createCell(0).setCellValue("               ");
        count++;
     
            for(int j=0;j<children.length;j++)
{
TCComponent taskcomp=(TCComponent) children[j].getComponent();
Object_Name=taskcomp.getTCProperty("object_name");
Start_Date=taskcomp.getTCProperty("start_date");
Finish_Date=taskcomp.getTCProperty("finish_date");
Actual_Start_Date=taskcomp.getTCProperty("actual_start_date");
Actual_finish_Date=taskcomp.getTCProperty("actual_finish_date");
Resource_Assignment=taskcomp.getTCProperty("ResourceAssignment");


    XSSFRow row = sheet.createRow((short)count);
            row.createCell(0).setCellValue(Object_Name.toString());
            row.createCell(1).setCellValue(Start_Date.toString());
            row.createCell(2).setCellValue(Finish_Date.toString());
            row.createCell(3).setCellValue(Actual_Start_Date.toString());
            row.createCell(4).setCellValue(Actual_finish_Date.toString());
            row.createCell(5).setCellValue(Resource_Assignment.toString());
            count++;
}
            workbook.write(fileOut);
fileOut.flush();
fileOut.close();
}
}

Execute Query for search all ITEM

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;
import org.eclipse.jface.dialogs.MessageDialog;

import com.teamcenter.rac.aif.AbstractAIFApplication;
import com.teamcenter.rac.aif.kernel.AIFComponentContext;
import com.teamcenter.rac.aifrcp.AIFUtility;
import com.teamcenter.rac.kernel.TCComponent;
import com.teamcenter.rac.kernel.TCComponentQuery;
import com.teamcenter.rac.kernel.TCComponentQueryType;
import com.teamcenter.rac.kernel.TCProperty;
import com.teamcenter.rac.kernel.TCSession;

public class SampleHandler extends AbstractHandler {

public SampleHandler() {
}
public Object execute(ExecutionEvent event) throws ExecutionException {

AbstractAIFApplication app=AIFUtility.getCurrentApplication();
TCSession session=(TCSession) app.getSession();

try
{
TCComponentQueryType querytype=(TCComponentQueryType)                                                                                               session.getTypeComponent("ImanQuery");
TCComponentQuery query=(TCComponentQuery) querytype.find("Item...");

String[] EntryName={"Item ID","Type"};
String[] EntryValue={"*","*Item"};


TCComponent[] comp=query.execute(EntryName, EntryValue);

int count=comp.length;

if(count>0)
{
for (int i = 0; i < comp.length; i++) {
System.out.println(comp[i]);
System.out.println("");
}
}
else
{
System.out.println("no item found");
}
} catch (Exception e) {

}

IWorkbenchWindow window = HandlerUtil.getActiveWorkbenchWindowChecked(event);
MessageDialog.openInformation(
window.getShell(),
"ExecuteQuery",
"Item found");
return null;
}
}

Display secondary object of teamcenter

import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;

import org.eclipse.ui.handlers.HandlerUtil;

import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.IStructuredSelection;

import com.teamcenter.rac.aif.kernel.AIFComponentContext;
import com.teamcenter.rac.kernel.TCComponent;
import com.teamcenter.rac.kernel.TCComponentItem;
import com.teamcenter.rac.kernel.TCComponentItemRevision;


public class SampleHandler extends AbstractHandler {

TCComponentItemRevision rev;
TCComponentItem item;

public Object execute(ExecutionEvent event) throws ExecutionException {
ISelection selection=HandlerUtil.getCurrentSelection(event);
if(selection instanceof IStructuredSelection)
{
AIFComponentContext context=(AIFComponentContext)
((IStructuredSelection) selection).getFirstElement();
TCComponent comp=(TCComponent) context.getComponent();

if(comp instanceof TCComponentItem)
{
item=(TCComponentItem) context.getComponent();
}
try {
rev=item.getLatestItemRevision();
AIFComponentContext context1[]=rev.getChildren();
for (int i = 0; i < context1.length; i++) {
System.out.println("Name="+context1[i].getComponent().toString());
}
} catch (Exception e) {
e.getStackTrace();
}
}
return null;
}
}

Display Home Folder Contents

import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;


import com.teamcenter.rac.aif.AbstractAIFUIApplication;
import com.teamcenter.rac.aif.kernel.AIFComponentContext;
import com.teamcenter.rac.aifrcp.AIFUtility;
import com.teamcenter.rac.kernel.TCComponent;
import com.teamcenter.rac.kernel.TCComponentFolder;
import com.teamcenter.rac.kernel.TCComponentUser;
import com.teamcenter.rac.kernel.TCSession;

public class SampleHandler extends AbstractHandler {

public Object execute(ExecutionEvent event) throws ExecutionException {

AbstractAIFUIApplication app=AIFUtility.getCurrentApplication();
System.out.println("app="+app);

                TCSession session=(TCSession) app.getSession();
System.out.println("session="+session);

                TCComponentUser user=session.getUser();
System.out.println("user="+user);

                 try {
TCComponentFolder tf=user.getHomeFolder();

System.out.println("tf="+tf);
AIFComponentContext[] child=tf.getChildren();
for (int i = 0; i < child.length; i++) {
TCComponent ch=(TCComponent) child[i].getComponent();
System.out.println("child="+ch.toString());
}
} catch (Exception e)
                {
e.getStackTrace();
}

return null;
}
}

Display BOM Properties in Table

import java.awt.BorderLayout;

import javax.swing.JFrame;
import javax.swing.JScrollPane;
import javax.swing.ScrollPaneConstants;

import javax.swing.JTable;

import javax.swing.table.DefaultTableModel;

import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
import com.teamcenter.rac.aif.kernel.AIFComponentContext;
import com.teamcenter.rac.aifrcp.AIFUtility;
import com.teamcenter.rac.kernel.TCComponent;
import com.teamcenter.rac.kernel.TCException;
import com.teamcenter.rac.kernel.TCProperty;
import com.teamcenter.rac.kernel.TCSession;

public class SampleHandler extends AbstractHandler {
DefaultTableModel model=null;
JTable table=null;

public void DisplayProperties() throws TCException
{
JFrame frame=new JFrame();
TCComponent tcc=(TCComponent) AIFUtility.getCurrentApplication().getTargetComponent();
TCSession session = tcc.getSession();
session.getUser();
AIFComponentContext[] children=tcc.getChildren();
frame.setTitle("BOM PROPERTIES");

String[] columnNames={"BOM Line","ItemID","ItemName","RevisionId","ItemRevisionSate","ItemType"};

model=new DefaultTableModel(columnNames, children.length);
table=new JTable(model);
table.setBounds(20, 30, 200, 300);


TCProperty BOMLine;
    TCProperty ItemId;
    TCProperty ItemName;
    TCProperty RevisionId;
    TCProperty ItemRevisionState;
    TCProperty ItemType;
 
    for (int i = 0; i < children.length; i++)
    {
TCComponent tc=(TCComponent) children[i].getComponent();
BOMLine=tc.getTCProperty("bl_indented_title");
ItemId=tc.getTCProperty("bl_item_item_id");
ItemName=tc.getTCProperty("bl_item_object_name");
RevisionId=tc.getTCProperty("bl_rev_fnd0RevisionId");
ItemRevisionState=tc.getTCProperty("bl_rev_release_status_list");
ItemType=tc.getTCProperty("bl_item_object_type");

table.setValueAt(BOMLine, i,0 );

table.setValueAt(ItemId, i,1 );

table.setValueAt(ItemName, i,2 );

table.setValueAt(RevisionId, i,3 );

table.setValueAt(ItemRevisionState, i,4 );

table.setValueAt(ItemType, i,5 );
}

    JScrollPane scrollPane = new JScrollPane(table);
    scrollPane.setHorizontalScrollBarPolicy
                   (ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS);

    scrollPane.setVerticalScrollBarPolicy
                  (ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);

                frame.add(scrollPane, BorderLayout.CENTER);
frame.setSize(600,600);
frame.setVisible(true);
}
}

Display all Released Item

import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;

import com.teamcenter.rac.aif.AbstractAIFUIApplication;
import com.teamcenter.rac.aif.kernel.AIFComponentContext;
import com.teamcenter.rac.aifrcp.AIFUtility;
import com.teamcenter.rac.kernel.TCComponent;
import com.teamcenter.rac.kernel.TCComponentFolder;
import com.teamcenter.rac.kernel.TCComponentItem;
import com.teamcenter.rac.kernel.TCComponentItemRevision;
import com.teamcenter.rac.kernel.TCComponentUser;
import com.teamcenter.rac.kernel.TCProperty;
import com.teamcenter.rac.kernel.TCSession;



public class SampleHandler extends AbstractHandler {

public Object execute(ExecutionEvent event) throws ExecutionException {

AbstractAIFUIApplication app=AIFUtility.getCurrentApplication();
TCSession session=(TCSession) app.getSession();
TCComponentUser user=session.getUser();

try
{
TCComponentFolder tf=user.getHomeFolder();
AIFComponentContext[] child=tf.getChildren();

for (int i = 0; i < child.length; i++) {
TCComponent comp=(TCComponent) child[i].getComponent();
if(comp instanceof TCComponentItem )
{
TCComponentItemRevision item=((TCComponentItem) comp).getLatestItemRevision();

TCProperty releaseIR=item.getTCProperty("release_status_list");

String prop_value=releaseIR.toString();

if(prop_value.equals("TCM Released"))
{
AIFComponentContext[] secobj=item.getChildren();
for (int j = 0; j < secobj.length; j++) {

System.out.println("secondary object attached to released Item Revision="+secobj[i].getComponent().toString());
}
}
}
}
}
catch (Exception e)
{

}

return null;
}
}

HTML Report Generation of selected ItemRevision

import java.io.File;
import java.io.FileWriter;
import java.io.IOException;

import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;



import com.teamcenter.rac.aif.kernel.AIFComponentContext;
import com.teamcenter.rac.aifrcp.AIFUtility;
import com.teamcenter.rac.kernel.TCComponent;

import com.teamcenter.rac.kernel.TCException;
import com.teamcenter.rac.kernel.TCProperty;

import com.teamcenter.rac.kernel.TCSession;

public class SampleHandler extends AbstractHandler {

File f1;
TCComponent tccomponent=null;
TCSession session=null;
public void createReportHtml() throws TCException, IOException
{
tccomponent=(TCComponent) AIFUtility.getCurrentApplication().getTargetComponent();
session=(TCSession) tccomponent.getSession();
session.getUser();

String s1="<html>" +
"<head><title>Report</title>"+
"<style>thead{color:green;}tbody{color:blue;}" +
"table,th,td{border:1px solid black;}</style>" +
"</head>" +
"<body>" +
"<table ><thead><tr><th>OBJECT NAME</th><th>OBJECT TYPE</th>" +
"<th>RELATION</th><th>OWNER</th><th>GROUP ID<th>DATE                                                    MODIFIED</th></tr>";

                f1=new File("C:\\TEMP\\HTMLReport.html");

FileWriter write=new FileWriter(f1);

AIFComponentContext[] children=tccomponent.getChildren();
TCProperty Object_Name=null;
TCProperty Type=null;
TCProperty Owner=null;
TCProperty GropupID=null;
TCProperty DateModified=null;

write.write(s1);

for (int i = 0; i < children.length; i++) {

TCComponent taskcomp=(TCComponent) children[i].getComponent();
Object_Name=taskcomp.getTCProperty("object_name");
Type=taskcomp.getTCProperty("object_type");
Owner=taskcomp.getTCProperty("owning_user");
GropupID=taskcomp.getTCProperty("owning_group");
DateModified=taskcomp.getTCProperty("last_mod_date");
try
{
String str="<tbody><tr><th>"+Object_Name+"</th><td>"+Type+"</td><td>"+"Contents"+"</td><td>"+Owner+"</td><td>"+GropupID+"</td><td>"+    DateModified     +"</td></tr></tbody>" ;

                        write.write(str);
}
catch (IOException e1)
{
e1.printStackTrace();
}
}
write.close();
}
}

Create Excel report of selected item Revision

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;

import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.ss.usermodel.WorkbookFactory;
import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;

import com.teamcenter.rac.aif.kernel.AIFComponentContext;
import com.teamcenter.rac.aifrcp.AIFUtility;
import com.teamcenter.rac.kernel.TCComponent;
import com.teamcenter.rac.kernel.TCException;
import com.teamcenter.rac.kernel.TCProperty;
import com.teamcenter.rac.kernel.TCSession;


public class SampleHandler extends AbstractHandler {

TCSession session=null;;
TCComponent tcc=null;
public void CreateExcelReport() throws TCException, InvalidFormatException, IOException {

tcc=(TCComponent) AIFUtility.getCurrentApplication().getTargetComponent();
session=tcc.getSession();
session.getUser();

FileInputStream input=new FileInputStream(new File("C:\\Temp\\ExcelReport.xlsx"));
Workbook workbook=WorkbookFactory.create(input);
FileOutputStream fos = new FileOutputStream("C:\\Temp\\ExcelReport.xlsx");
Sheet sheet=(Sheet) workbook.getSheetAt(0);

AIFComponentContext[] children=tcc.getChildren();
TCProperty Object_Name;
       TCProperty Type;
       TCProperty Owner;
       TCProperty GropupID;
       TCProperty DateModified;
 
       int rowincr=1;
               int colincr=0;
     
               for(int i=0;i<children.length;i++)
{
TCComponent taskcomp=(TCComponent) children[i].getComponent();
Object_Name=taskcomp.getTCProperty("object_name");
Type=taskcomp.getTCProperty("object_type");
Owner=taskcomp.getTCProperty("owning_user");
GropupID=taskcomp.getTCProperty("owning_group");
DateModified=taskcomp.getTCProperty("last_mod_date");


Cell cell1=sheet.getRow(rowincr).getCell(colincr);
cell1.setCellValue(Object_Name.toString());
colincr++;

Cell cell2=sheet.getRow(rowincr).getCell(colincr);
cell2.setCellValue(Type.toString());
colincr++;

Cell cell3=sheet.getRow(rowincr).getCell(colincr);
cell3.setCellValue(Owner.toString());
colincr++;

Cell cell4=sheet.getRow(rowincr).getCell(colincr);
cell4.setCellValue(GropupID.toString());
colincr++;

Cell cell5=sheet.getRow(rowincr).getCell(colincr);
cell5.setCellValue(DateModified.toString());
colincr++;

colincr=0;

rowincr++;

     
workbook.write(fos);
fos.close();
}

Attach Folder to selected Item

import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
import com.teamcenter.rac.aifrcp.AIFUtility;
import com.teamcenter.rac.kernel.TCComponent;
import com.teamcenter.rac.kernel.TCComponentFolder;
import com.teamcenter.rac.kernel.TCComponentFolderType;
import com.teamcenter.rac.kernel.TCComponentItem;
import com.teamcenter.rac.kernel.TCException;
import com.teamcenter.rac.kernel.TCSession;

public class SampleHandler extends AbstractHandler {
        TCComponent tc=null;
        TCComponentFolder  folder=null;
        TCComponentFolderType foldertype=null;

public void  AttachFolder() throws TCException {
         tc=(TCComponent)AIFUtility.getCurrentApplication().getTargetComponent();
TCSession session=(TCSession) tc.getSession();
session.getUser();
TCComponentItem item=(TCComponentItem)tc;
               if(item instanceof TCComponentItem)
{
                        foldertype=(TCComponentFolderType) session.getTypeComponent("Folder");
folder=foldertype.create("NewFolder", "Description desc", "Folder");
item.add("IMAN_reference",folder);
}
}

Attach Dataset to selected item

import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;

import com.teamcenter.rac.aifrcp.AIFUtility;
import com.teamcenter.rac.kernel.TCComponent;
import com.teamcenter.rac.kernel.TCComponentDataset;
import com.teamcenter.rac.kernel.TCComponentDatasetType;
import com.teamcenter.rac.kernel.TCComponentItem;
import com.teamcenter.rac.kernel.TCComponentItemRevision;

import com.teamcenter.rac.kernel.TCException;
import com.teamcenter.rac.kernel.TCSession;

public class AttachDataset extends AbstractHandler {
public void AttachDataset() throws TCException {
TCComponent tc=null;
        tc= (TCComponent)AIFUtility.getCurrentApplication().getTargetComponent();
TCSession session=(TCSession) tc.getSession();
session.getUser();
TCComponentItem item=(TCComponentItem)tc;
TCComponent[] comp=item.getRelatedComponents();
int count=0;

for(int i=0;i<comp.length;i++)
{
if(comp[i] instanceof TCComponentItemRevision && count==0)
{
TCComponentDataset dataset;
TCComponentDatasetType datasettype=null;
    datasettype=(TCComponentDatasetType) session.getTypeComponent("PDF");
dataset=datasettype.create("Test", "test desc", "PDF");
comp[i].add("IMAN_specification",dataset);
}
}
}
x