一、插件概述
一个插件(plug-in)是Eclipse平台中的最小功能单元,它可以被独立的开发和发布。
1)JAR中的Java代码
2)一些只读文件和其它资源(例如图片、web模板、消息资源文件、本地类库等)。
3)一个插件清单,用于声明它与其它插件之间的连接关系,一个插件的清单由几个文件表示:
①manifest.mf文件是一个OSGI bundle清单,它描述了插件间运行时的依赖关系;
②plugin.xml是一个XML文件,它描述了扩展和扩展点的信息
4、在Dependencies页签加入以下Required Plug-ins:
- com.teamcenter.rac.aifrcp:Teamcenter基础客户化插件,一些主要的接口以及抽象类,入口类等都在该插件中进行了定义。
- com.teamcenter.rac.common:Teamcenter的一些动作和菜单都在该插件包中进行了定义,如菜单栏,工具栏,以及右键菜单等。
- com.teamcenter.rac.external:Teamcenter插件中引用到的第三方类大部分都在该插件中进行了集成,可以说该插件为资源性插件。
- com.teamcenter.rac.kernel:Teamcenter核心插件包。
- com.teamcenter.rac.neva:`com.teamcenter.rac.neva` 是一个 Java 类库,属于 Siemens Teamcenter 集成平台(RAC)的一部分。NEVA 全称为 "New Enterprise Visualization Architecture",是一个用于将 3D 模型、工程图纸等企业内部数据类型进行可视化的技术。在 Teamcenter 系统中,NEVA 技术被用于支持 3D 模型可视化及交互式浏览操作,类库 `com.teamcenter.rac.neva` 就是 NEVA 技术的一项实现,它提供了相应的 API 接口供客户端应用程序调用。使用 `com.teamcenter.rac.neva` 类库,可以快速、轻松地构建出高效、灵活的 3D 可视化应用程序,满足各种企业或行业内部的需求。
- com.teamcenter.rac.tcapps:Teamcenter中部分应用的基础实现都在该类中进行了实现,这个主要是遗留问题,虽然现在的应用大 部分都是以相应的插件进行了区别与分类,但是大部分应用的业务逻辑都在该插件中进行实现,还有一些公共组件等
- com.teamcenter.rac.util:
(1)该插件是Teamcenter对大部分Swing组件进行了继承与重写。如: iTextField继承于JTextField; iComboBox类为Teamcenter自己定义的组件。
(2)该插件中还定义了一些公共工具类,如:TcLogger日志控制类,Registry注册控制类等。
- Debug配置文件:
- -Xms256m -Xmx1024m -Djava.library.path=C:\Siemens\Teamcenter11\tccs\lib -Dautologin.user=infodba -Dautologin.pass=infodba
Command:有一个唯一的ID号,它代表了一个动作的抽象意义,例如拷贝,粘贴,保存。它不代表一个动作的实施。
Menu contributions:代表一个特定的视图或者一个命令的视图话呈现。它创建了菜单和工具条的结构框架并且把他们插入到Eclipse的正确位置。每个位置都是用URI( Uniform Resource Identifier )来标识的。Menu contribution能够定义一个菜单的标签,助记符和图标。它和已经被定义的Command之间相互关联。一个菜单可以通过visibleWhen来控制它的显示。
Handlers:大多数是继承于AbstractHandler类。Handlers在它的execute(*)方法中提供了一个应用程序上下文。如果一个命令没有一个激活的handlers被定义,任何一个Menu contributions中定义的Command都不可见。一个Command可以定义一个默认的handler来确保它能够有一个可被激活的handler。handler可以通过ActiveWhen语句来被显示的激活声明或者被编程的形式激活。Handler也可以在任何一个Menu contributions中用enabledWhen表达式,显示的定义一个按钮什么时候可显示。
- <?xml version="1.0" encoding="UTF-8"?>
- <?eclipse version="3.4"?>
- <plugin>
- <extension point="org.eclipse.ui.commands">
- <!-- 2021年9月练习 -->
- <command id="com.dgt.hyl.ox.sept.commands.CreateComponenCommand" name="创建零部件"/>
- </extension>
- <extension point="org.eclipse.ui.handlers">
- <!-- 2021年9月练习 -->
- <handler commandId="com.dgt.hyl.ox.sept.commands.CreateComponenCommand" class="com.dgt.hyl.ox.sept.handlers.CreateComponenHandler"/>
- </extension>
- <extension point="org.eclipse.ui.menus">
- <!-- 主菜单 -->
- <menuContribution locationURI="menu:org.eclipse.ui.main.menu?after=additions">
- <menu id="Menu_202109" label="2021年九月练习">
- <command commandId="com.dgt.hyl.ox.sept.commands.CreateComponenCommand"/>
- <visibleWhen>
- <and>
- <or>
- <!-- 我的制造工艺规划器 -->
- <reference definitionId="com.teamcenter.rac.cme.mpp.inMainView"/>
- </or>
- </and>
- </visibleWhen>
- </menu>
- </menuContribution>
- </extension>
- </plugin>
主菜单栏:menu:org.eclipse.ui.main.menu
主工具栏:toolbar:org.eclipse.ui.main.toolbar
弹出菜单:popup:org.eclipse.ui.popup.any
Handler继承:Handler extends AbstractHandler;
Action继承:Action extends AbstractAIFAction;
Command继承:Command extends AbstractAIFCommand;
Dialog继承:Dialog extends AbstractAIFDialog;
Operation继承:Operation extends AbstractAIFOperation;
①handler继承于此类;
②public Object execute(*)方法是程序的执行入口。
①Action一般继承于此类;
②public void run( )是程序的入口,必须实现的方法(可在此初始化Command);
③executeModal( )执行Command。
①Command的继承于此类;
②setRunnable( )方法可以让来运行初始化对话框。
①Dialog继承于此类,用来定义对话框;
②此类中的事件监听器中,初始化Operation,即操作。
①Operation继承于此类,用于定义操作;
②executeOperation( )方法是程序必须执行的方法,里面主要定义具体的操作。
1)TCComponent
2)TCComponentItem——对应Item
3)TCComponentItemRevision——对应Item Revision
4)TCComponentItemType——对应Item类型
5)TCComponentFolderType——对应文件夹类型
6)TCComponentUser——对应用户
7)TCComponentPerson——对应人员
8)TCComponentGroup——对应组织
9)TCComponentRole——对应角色
10)TCComponentForm——对应表单
11、Teamcenter UI Components:TC页面元素
1)iTextField——文本框
2)JCheckBox——复选框
3)JButton——按钮
4)Jpanel——面板
5)Jlabel——标签
6)Jdialog——对话框
7)DateButton——日历
- /**
- * 根据零件版本,创建视图对象
- * @param tCPBOMItemRevision
- */
- public static TCComponentBOMLine createTCPBOMLine(TCComponentItemRevision tCPBOMItemRevision)
- {
- try {
- TCComponentRevisionRuleType revRuleType = (TCComponentRevisionRuleType) session.getTypeComponent("RevisionRule");
- TCComponentRevisionRule revRule = revRuleType.getDefaultRule();
- TCComponentBOMWindowType bomWindowType = (TCComponentBOMWindowType) session.getTypeComponent("BOMWindow");
- TCComponentBOMWindow bomWindow = bomWindowType.create(revRule);
- TCComponentBOMLine createBomLine = bomWindow.setWindowTopLine(tCPBOMItemRevision.getItem(), tCPBOMItemRevision, null, null);
- return createBomLine;
- } catch (Exception e) {
- e.printStackTrace();
- MessageBox.post(e.getMessage(),"提示",MessageBox.ERROR);
- }
- return null;
- }
- /**
- * 创建带有必填字段的Item对象
- * @param session
- * @param item_type 创建的对象类型
- * @param item_property_map 创建的Item需要设置的属性,<属性名,属性值>
- * @param itemRev_property_map 创建的ItemRevison需要设置的属性,<属性名,属性值>
- *
- * 2017-11-28
- */
- @SuppressWarnings("rawtypes")
- public static TCComponent performCreate_bak(TCSession session,String item_type,Map<String, String> item_property_map,Map<String, String> itemRev_property_map)throws TCException{
- IBOCreateDefinition IBOcreateDefinition = BOCreateDefinitionFactory.getInstance().getCreateDefinition(session, item_type);
- if (IBOcreateDefinition == null){
- MessageBox.post("IBOCreateDefinition获取失败","出错了",MessageBox.INFORMATION);
- return null;
- }
- List<ICreateInstanceInput> m_inputs = new ArrayList<>();
- CreateInstanceInput localCreateInstanceInput = new CreateInstanceInput(IBOcreateDefinition);
- for(Map.Entry<String, String> entry:item_property_map.entrySet()){
- localCreateInstanceInput.add(entry.getKey(), entry.getValue());
- }
- m_inputs.add(localCreateInstanceInput);
- List<IBOCreateDefinition> localList = IBOcreateDefinition.getSecondaryCreateDefinition("revision");
- if ((localList != null) && (localList.size() > 0)){
- IBOCreateDefinition localIBOCreateDefinition2 = (IBOCreateDefinition)localList.get(0);
- if (localIBOCreateDefinition2 != null){
- CreateInstanceInput localCreateInstanceInput2 = new CreateInstanceInput(localIBOCreateDefinition2);
- // localCreateInstanceInput2.add("item_revision_id", "");
- for(Map.Entry<String, String> entry:itemRev_property_map.entrySet()){
- // localCreateInstanceInput2.add("ca9_DocumentType", "HJFJGKB");
- // localCreateInstanceInput2.add("ca9_CarSeries", bomLine.parent().getItemRevision().getProperty("ca9_CarSeries"));
- // localCreateInstanceInput2.add("ca9_Profession", "HJ");
- localCreateInstanceInput2.add(entry.getKey(), entry.getValue());
- }
- m_inputs.add(localCreateInstanceInput2);
- }
- }
- Object localObject1 = null;
- List<TCComponent> localList2 = SOAGenericCreateHelper.create(session, IBOcreateDefinition, m_inputs);
- Object localObject2;
- Object localObject3;
- if ((localList2 != null) && (localList2.size() > 0)) {
- localObject2 = localList2.iterator();
- while (((Iterator)localObject2).hasNext())
- {
- localObject3 = (TCComponent)((Iterator)localObject2).next();
- if ((localObject3 instanceof TCComponentItem))
- {
- localObject1 = localObject3;
- break;
- }
- }
- }
- return (TCComponent)localObject1;
- }
- //1、创建没有必填属性的零件对象
- TCSession session =(TCSession)AIFUtility.getDefaultSession();
- TCComponentItemType tccomponentItemType = (TCComponentItemType)
- session.getTypeComponent("Item");//item、form、folder
- TCComponentItem item = tccomponentItemType.create(ITEMID, REV ID, ITEM TYPE, OBJECT NAME, DESC, null);
- //2、创建有必填属性的零件对象
- /**创建含有必填项的零件*/
- public void createItem() {
- (TCComponentItemType) itemType = (TCComponentItemType) session.getTypeComponent(ItemType);//根据类型获取类型对象
- DGTUtility dgtUtility = new DGTUtility(session);
- TCComponentItemRevisionType itemRevType = dgtUtility.getItemRevisionType(ItemType);//根据类型获取版本类型对象
- Map<String,Object> item_property_map = getPropertyMap(itemType,itemRev.getItem());//获取可显示输入的零件属性值列表
- Map<String,Object> itemRev_property_map = getPropertyMap(itemRevType,itemRev);//获取可显示输入的零件版本属性值列表
- Map<String, TCComponent> uomTagObject = getUomTagObject();//获取度量单位对象
- String property = itemRev.getItem().getProperty("uom_tag");//获取选中零件的度量单位
- item_property_map.put("uom_tag", uomTagObject.get(property));//复制度量单位属性
- ID = itemRev.getItem().getProperty("item_id")+"_REF";
- item_property_map.put("item_id", ID);//更改继承的ID
- //item_property_map.put("object_name", NAME);//更改继承的名称
- TCComponentItem docItem = (TCComponentItem) DGTUtility.performCreate_bak3(session, ItemType, item_property_map, itemRev_property_map);
- }
- /**
- * 根据零件类型获取零件版本类型
- * @param itemType:零件类型
- */
- public TCComponentItemRevisionType getItemRevisionType(String itemType) {
- TCComponentItemRevisionType tccomponentitemrevisiontype = null;
- try {
- TCComponentItemType typeComponent = (TCComponentItemType) session.getTypeComponent(itemType);
- if (typeComponent != null) {
- String s2 = typeComponent.getRevisionTypeName(itemType);
- tccomponentitemrevisiontype = (TCComponentItemRevisionType) session.getTypeComponent(s2);
- }
- } catch (TCException e) {
- e.printStackTrace();
- }
- return tccomponentitemrevisiontype;
- }
- /**
- * 获取可显示输入的属性对象列表
- * @param type:类型对象
- * @param item:选中的零件对象*/
- public Map<String,Object> getPropertyMap(TCComponentType type,TCComponent item) throws TCException{
- Map<String,Object> property_map = new HashMap<>();
- //获取获取可显示输入的属性对象
- BOCreateDefinition bocreatedefinition3 = (BOCreateDefinition)BOCreateDefinitionFactory.getInstance().getCreateDefinition(type.getSession(), type.getType());
- List<BOCreatePropertyDescriptor> createPropertyDescriptors = bocreatedefinition3.getCreatePropertyDescriptors();
- for(int i = 0;i<createPropertyDescriptors.size();i++) {
- TCPropertyDescriptor propertyDescriptor = createPropertyDescriptors.get(i).getPropertyDescriptor();
- String name2 = propertyDescriptor.getName();
- String property = item.getProperty(name2);
- if(DGTUtility.isEmpty(property)) {//判断选中零件的该属性是否有值
- //无值使用属性本身默认值
- property_map.put(name2, propertyDescriptor.getDefaultValue());
- }else {
- //获取属性LOV
- TCComponentListOfValues lov = propertyDescriptor.getLOV();
- if (lov != null) {//判断是否有LOV
- //获取LLOV对象
- Map<String, Object> lovObject = getLOVObject(lov);
- Object object = lovObject.get(property);
- property_map.put(name2, object);//写入LOV对象
- }else {
- property_map.put(name2, property);
- }
- }
- }
- return property_map;
- }
- /**
- * 创建带必填项的零件
- * @param session
- * @param item_type 创建的对象类型
- * @param item_property_map 创建的Item需要设置的属性,<属性名,属性值>
- * @param itemRev_property_map 创建的ItemRevison需要设置的属性,<属性名,属性值>
- */
- @SuppressWarnings("rawtypes")
- public static TCComponent performCreate_bak3(TCSession session, String item_type,
- Map<String, Object> item_property_map, Map<String, Object> itemRev_property_map) throws TCException {
- IBOCreateDefinition IBOcreateDefinition = BOCreateDefinitionFactory.getInstance().getCreateDefinition(session,item_type);
- if (IBOcreateDefinition == null) {
- MessageBox.post("IBOCreateDefinition获取失败", "出错了", MessageBox.INFORMATION);
- return null;
- }
- List<ICreateInstanceInput> m_inputs = new ArrayList<>();
- CreateInstanceInput localCreateInstanceInput = new CreateInstanceInput(IBOcreateDefinition);
- for (Map.Entry<String, Object> entry : item_property_map.entrySet()) {
- localCreateInstanceInput.add(entry.getKey(), entry.getValue());
- }
- m_inputs.add(localCreateInstanceInput);
- List<IBOCreateDefinition> localList = IBOcreateDefinition.getSecondaryCreateDefinition("revision");
- if ((localList != null) && (localList.size() > 0)) {
- IBOCreateDefinition localIBOCreateDefinition2 = (IBOCreateDefinition) localList.get(0);
- if (localIBOCreateDefinition2 != null) {
- CreateInstanceInput localCreateInstanceInput2 = new CreateInstanceInput(localIBOCreateDefinition2);
- for (Map.Entry<String, Object> entry : itemRev_property_map.entrySet()) {
- localCreateInstanceInput2.add(entry.getKey(), entry.getValue());
- }
- m_inputs.add(localCreateInstanceInput2);
- }
- }
- Object localObject1 = null;
- List<TCComponent> localList2 = SOAGenericCreateHelper.create(session, IBOcreateDefinition, m_inputs);
- Object localObject2;
- Object localObject3;
- if ((localList2 != null) && (localList2.size() > 0)) {
- localObject2 = localList2.iterator();
- while (((Iterator) localObject2).hasNext()) {
- localObject3 = (TCComponent) ((Iterator) localObject2).next();
- if ((localObject3 instanceof TCComponentItem)) {
- localObject1 = localObject3;
- break;
- }
- }
- }
- return (TCComponent) localObject1;
- }
- TCSession session =(TCSession)AIFUtility.getDefaultSession();
- TCComponentItemType tccomponentItemType = (TCComponentItemType)
- session.getTypeComponent("Item");//item、form、folder
- TCComponentItem item = tccomponentItemType.create(ITEMID, REV ID, ITEM TYPE, OBJECT NAME, DESC, null);
8、获取指定规则的零组件最新ID:根据零组件命名规则模式和零组件类型
- //包:TcSoaCoreRac
- /**
- * 根据零组件命名规则模式和零组件类型获取指定规则的零组件最新ID
- * @param String pattern:命名规则模式
- * @param String type:零组件类型
- * @return String 该pattern模式的零组件ID
- * huyanling 2021-10-14
- * */
- @SuppressWarnings({ "rawtypes" })
- public String getItemIdByPatternAndType(String pattern,String type) {
- String s = null;
- try {
- Object obj1;
- String result = "isTrue:"+type+":item_id:"+pattern;
- String as4[] = {result};
- TCPreferenceService tcPreferenceService = session.getPreferenceService();//获取当前会话设置模式的服务
- tcPreferenceService.setStringArray(1, "TC_LAST_USED_PATTERNS", as4);//根据模式设置最新生成ID的命名规则模式
- DataManagementService datamanagementservice = DataManagementService.getService(session);
- //创建有几个agenerateitemidsandinitialrevisionidsproperties对象的GenerateItemIdsAndInitialRevisionIdsProperties对象
- com.teamcenter.services.rac.core._2006_03.DataManagement.GenerateItemIdsAndInitialRevisionIdsProperties agenerateitemidsandinitialrevisionidsproperties[] = new com.teamcenter.services.rac.core._2006_03.DataManagement.GenerateItemIdsAndInitialRevisionIdsProperties[1];
- agenerateitemidsandinitialrevisionidsproperties[0] = new com.teamcenter.services.rac.core._2006_03.DataManagement.GenerateItemIdsAndInitialRevisionIdsProperties();
- agenerateitemidsandinitialrevisionidsproperties[0].item = null;
- agenerateitemidsandinitialrevisionidsproperties[0].itemType = type;//零组件类型
- agenerateitemidsandinitialrevisionidsproperties[0].count = 1;//获取几个最新ID
- //获取零组件类型的自增长零组件ID及零组件版本ID
- obj1 = datamanagementservice.generateItemIdsAndInitialRevisionIds(agenerateitemidsandinitialrevisionidsproperties);
- //获取obj1中的值
- Map map = ((com.teamcenter.services.rac.core._2006_03.DataManagement.GenerateItemIdsAndInitialRevisionIdsResponse) (obj1)).outputItemIdsAndInitialRevisionIds;
- Iterator iterator = map.entrySet().iterator();
- if(iterator.hasNext())//遍历提取出newItemId
- {
- java.util.Map.Entry entry = (java.util.Map.Entry)iterator.next();
- com.teamcenter.services.rac.core._2006_03.DataManagement.ItemIdsAndInitialRevisionIds aitemidsandinitialrevisionids[] = (com.teamcenter.services.rac.core._2006_03.DataManagement.ItemIdsAndInitialRevisionIds[])entry.getValue();
- com.teamcenter.services.rac.core._2006_03.DataManagement.ItemIdsAndInitialRevisionIds itemidsandinitialrevisionids = aitemidsandinitialrevisionids[0];
- s = itemidsandinitialrevisionids.newItemId;
- }
- } catch (TCException e) {
- e.printStackTrace();
- }
- return s;
- }
- /**
- * 根据零件类型查询其命名规则模式列表
- * String ITEMTYPE = "D2_GeneralDesign";
- * @param ITEMTYPE:零件类型
- * */
- public void getPatternsByItemType(String ITEMTYPE)
- {
- String as[] = {
- "item_id", "item_revision_id"
- };
- String as1[] = {
- ITEMTYPE, ITEMTYPE
- };
- //获取命名规则列表,包括item和itemRevision的命名规则
- NamingRule anamingrule[] = NamingRulesHelper.getInstance().getNamingRules(session, as1, as);
- String as2[] = anamingrule[0].getPatterns();//item命名规则
- String as3[] = anamingrule[1].getPatterns();//itemRevision命名规则
- String s1 = anamingrule[0].getPreferredPattern();//当零件未关联命名规则时,默认零件命名规则
- String s2 = anamingrule[1].getPreferredPattern();//当零件版本未关联命名规则时,默认版本命名规则
- String condition1 = anamingrule[0].getCondition();//命名规则判断条件
- String condition2 = anamingrule[1].getCondition();//版本命名规则判断条件
- }
- /**根据零件类型获取零件版本类型
- * @param itemType:零件类型*/
- public TCComponentItemRevisionType getItemRevisionType(String itemType) {
- TCComponentItemRevisionType tccomponentitemrevisiontype = null;
- try {
- TCComponentItemType typeComponent = (TCComponentItemType) session.getTypeComponent(itemType);
- if(typeComponent != null){
- String s2 = typeComponent.getRevisionTypeName(itemType);
- tccomponentitemrevisiontype = (TCComponentItemRevisionType)session.getTypeComponent(s2);
- }
- } catch (TCException e) {
- e.printStackTrace();
- }
- return tccomponentitemrevisiontype;
- }
- /**根据零件类型和属性,获取属性的LOV
- * @param typeComponent:零件对象类型,如"TCComponentItemType"
- * @param properName:属性名称,如"uom_tag":度量单位
- * @author huyanling
- * 2021-10-20
- * */
- public Map<Object, Object> getPropLOVMap(TCComponentType typeComponent,String properName){
- Map<Object, Object> maps = null;
- try {
- TCPropertyDescriptor tcpropertydescriptor = typeComponent.getPropertyDescriptor(properName);
- TCComponentListOfValues lov = tcpropertydescriptor.getLOV();
- if(lov == null) {
- MessageBox.post(properName+"属性没有LOV,请配置附加LOV!","提示",MessageBox.INFORMATION);
- return null;
- }
- maps = new HashMap<Object, Object>();
- ListOfValuesInfo listOfValues = lov.getListOfValues();
- Object[] lovbd1 = listOfValues.getListOfValues();//LOV值
- String[] lovs1 = listOfValues.getLOVDisplayValues();//LOV本地化值
- for(int i = 0;i<lovbd1.length;i++) {
- //真实名称与本地化名称不匹配时直接使用真实名称列表
- if(lovbd1.length > lovs1.length) {
- maps.put(lovbd1[i], lovbd1[i]);
- }else {
- maps.put(lovs1[i], lovbd1[i]);
- }
- }
- } catch (TCException e) {
- MessageBox.post(e.getMessage(),"提示",MessageBox.INFORMATION);
- return null;
- }
- return maps;
- }
- /**根据零件类型和属性,获取属性本地化的LOV列表
- * @param typeComponent:零件对象类型,如"TCComponentItemType"
- * @param properName:属性名称,如"uom_tag":度量单位
- * @author huyanling
- * 2021-10-20
- * */
- public Object[] getPropLOVDisList(TCComponentType typeComponent,String properName){
- try {
- TCPropertyDescriptor tcpropertydescriptor = typeComponent.getPropertyDescriptor(properName);
- TCComponentListOfValues lov = tcpropertydescriptor.getLOV();
- if(lov == null) {
- MessageBox.post(properName+"属性没有LOV,配置附加LOV!","提示",MessageBox.INFORMATION);
- return null;
- }
- ListOfValuesInfo listOfValues = lov.getListOfValues();
- Object[] lovbd1 = listOfValues.getListOfValues();//LOV值
- Object[] lovs1 = listOfValues.getLOVDisplayValues();//LOV本地化值
- //真实名称与本地化名称不匹配时直接使用真实名称列表
- if(lovbd1.length > lovs1.length) {
- lovs1 = lovbd1;
- }
- return lovs1;
- } catch (TCException e) {
- MessageBox.post(e.getMessage(),"提示",MessageBox.INFORMATION);
- return null;
- }
- }
- TCComponentFolderType folder = (TCComponentFolderType) session.getTypeComponent("Folder");
- folder.create("练习0825", "", null);
- TCSession session =(TCSession)AIFUtility.getDefaultSession();
- TCComponentFolder homeFolder = session.getUser().getHomeFolder();//获取的home文件夹
- TCComponentFolder newStuffFolder = session.getUser().getNewStuffFolder();
- homeFolder.add("contents", tcComponentItem);//以“contents”关系将item放入home
- TCComponentFolderType folder = (TCComponentFolderType) session.getTypeComponent("Folder");
- folder.create("练习0825", "", null);
- TCComponentItemType item = (TCComponentItemType) session.getTypeComponent("Item");
- //item.create(itemID, revID, 类型, 名称, 描述, null)
- TCComponentItem newItem = item.create("10009", "A", "QL2_Change", "test", "", null);
- TCComponentDatasetType typeComponent = (TCComponentDatasetType) session.getTypeComponent("Dataset");
- //创建数据集typeComponent.create(名称, 描述, 类型);
- //TCComponentDataset create1 = typeComponent.create("测试数据集", "", "MSExcel");
- //create1.setFiles(new String[]{"D:\\attributenew.xls"}, new String[]{"excel"});
- TCComponentDataset create = typeComponent.create("word测试", "", "MSWordX");
- create.setFiles(new String[]{"D:\\IP.docx"}, new String[]{"word"});
- addDatasetNewstuff(create);
- /**
- * 通过已有的流程模板发起一个流程
- * @throws TCException
- */
- public void startProcess(TCComponentItemRevision item) throws TCException{
- //获取session
- TCSession session = getSession();
- //获取流程模板类型对象
- TCComponentTaskTemplateType TaskTemplateT = (TCComponentTaskTemplateType) session.getTypeComponent("EPMTaskTemplate");
- //获取流程模板 arg:流程模板名称
- TCComponentTaskTemplate find = TaskTemplateT.find("TCM Release Process", 0);
- //获取流程类型对象
- TCComponentProcessType procesType = (TCComponentProcessType) session.getTypeComponent("Job");
- //获取零件名称
- String itemName = item.getProperty("object_name");
- //发起流程
- procesType.create(itemName, "", find, new TCComponent[]{item}, new int[]{1});
- }
- //方式一:获取选中的多个对象
- StructuredSelection str = (StructuredSelection)HandlerUtil.getCurrentSelection(event);
- Iterator iterator = str.iterator();//获取所有选择的对象
- while (iterator.hasNext()) {//遍历选择对象
- AIFComponentContext aif = (AIFComponentContext)iterator.next();}
- //方式二:获取选中的多个对象
- InterfaceAIFComponent[] targetComponents = application.getTargetComponents();
- for (InterfaceAIFComponent interfaceAIFComponent:targetComponents) {
- System.out.println("方式二多个对象:"+interfaceAIFComponent);}
- //方式三:获取选中的单个对象
- InterfaceAIFComponent targetComponent = application.getTargetComponent();
- TCComponentUserType type = (TCComponentUserType) session.getTypeComponent("User");
- TCComponentUser find = type.find(user);
- //1)常用
- TCComponentItem item = new TCComponentItem();
- item.setProperty("object_name", "hello");
- item.setProperty("item_id", "122222");
- item.getProperty("object_name");
- //2)当是大批量的properties要设定值时
- TCFormProperty[] ps = f.getAllFormProperties();
- ps[0].setStringValueData ( "abc" );
- ps[1].setStringValueData ( "def" );
- f.setTCProperties(ps); // Now is saved to the db
- //3)当properties数量不大时
- TCFormProperty p = f.getFormTCProperty("my_prop_name");
- p.setStringValue ( "abc" );
- InterfaceAIFComponent targetComponent = application.getTargetComponent();
- if(targetComponent instanceof TCComponentItem){
- TCComponentItem item = (TCComponentItem)targetComponent;
- //获取子对象:getRelationObject(item);
- }
- //1)获取所以子对象
- AIFComponentContext[] children = item.getChildren();
- for(AIFComponentContext aif:children){
- System.out.print(aif);
- }
- //2)根据关系获取最新对象
- TCComponent relatedComponent = item.getRelatedComponent("revision_list");
- if(relatedComponent instanceof TCComponentItemRevision){
- TCComponentItemRevision item1 = (TCComponentItemRevision)relatedComponent;
- System.out.print(item1);
- }
- //3)根据关系获取所有对象
- TCComponent[] relatedComponents = item.getRelatedComponents("revision_list");
- for(TCComponent tc:relatedComponents){
- if(tc instanceof TCComponentItemRevision){
- TCComponentItemRevision item2 = (TCComponentItemRevision)tc;
- System.out.print(item2);
- }
- }
- TCComponentDataset dataset = new TCComponentDataset();
- AIFComponentContext[] whereReferenced = dataset.whereReferenced();
- for (AIFComponentContext aif:whereReferenced) {
- System.out.print("数据集被"+aif+"对象引用。");
- }
- TCComponentDatasetType typeComponent = (TCComponentDatasetType) session.getTypeComponent("Dataset");
- //创建数据集typeComponent.create(名称, 描述, 类型);
- //TCComponentDataset create1 = typeComponent.create("测试数据集", "", "MSExcel");
- //create1.setFiles(new String[]{"D:\\attributenew.xls"}, new String[]{"excel"});
- TCComponentDataset create = typeComponent.create("word测试", "", "MSWordX");
- create.setFiles(new String[]{"D:\\IP.docx"}, new String[]{"word"});
- addDatasetNewstuff(create);
- InterfaceAIFComponent targetComponent = application.getTargetComponent();
- //运行时判断是否是他的类或者子类
- if(targetComponent instanceof TCComponentDataset){
- TCComponentDataset dataset = (TCComponentDataset)targetComponent;
- //方式一
- TCComponentTcFile[] files2 = dataset.getTcFiles();
- for (TCComponentTcFile tc:files2) {
- tc.getFile("D:\\");
- }
- //方式二:
- dataset.getFiles("excel");//下载进入默认路径C:\\temp
- }
- public void createExcel(){
- FileOutputStream fos=null;
- //创建工作簿
- HSSFWorkbook workbook = new HSSFWorkbook();
- //创建sheet
- HSSFSheet sheet = workbook.createSheet();
- //创建row
- HSSFRow row = sheet.createRow(0);
- //创建cell
- HSSFCell cell = row.createCell(0);
- //设置cell的值
- cell.setCellValue("hello");
- File file=new File("D:\\hello.xlsx");//指定写入路径
- try {
- fos=new FileOutputStream(file);
- } catch (FileNotFoundException e) {
- e.printStackTrace();
- }finally{
- try {
- workbook.write(fos);
- fos.close();
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
- }
- public void readExcel(){
- File f=new File("D:\\hello.xlsx"); //指定写入路径
- try {
- //创建输入流对象
- FileInputStream fileInput = new FileInputStream(f);
- //创建工作簿对象
- HSSFWorkbook workbook = new HSSFWorkbook(fileInput);
- //获取sheet
- HSSFSheet sheet = workbook.getSheet("Sheet0");
- //HSSFSheet sheetAt = workbook.getSheetAt(0);
- //获取row
- HSSFRow row = sheet.getRow(0);
- //获取cell
- HSSFCell cell = row.getCell(0);
- //查看cell的值
- String stringCellValue = cell.getStringCellValue();
- System.out.println(stringCellValue);
- } catch (FileNotFoundException e) {
- e.printStackTrace();
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
- public TCComponentDataset findDataBase(String findName){
- TCSession session =(TCSession)AIFUtility.getDefaultSession();
- try {
- TCComponentQueryType typeComponent = (TCComponentQueryType) session.getTypeComponent("ImanQuery");
- TCComponentQuery find = (TCComponentQuery) typeComponent.find("数据集...");
- if(find == null){
- return null;
- }
- TCQueryClause[] describe = find.describe();
- String[] userId = {findName};
- String[] strings = {"名称"};
- TCComponent[] execute = find.execute(strings, userId);
- if(execute.length>0){
- System.out.println(execute[0]);
- return (TCComponentDataset)execute[0];
- }
- } catch (TCException e) {
- e.printStackTrace();
- }
- return null;
- }
session.queueOperation(new ExportFastOperation(session, logger, findData));
- /**
- * 获取LOV列表
- * @param lov:LOV对象
- * */
- public Map<String, Object> getLOVObject(TCComponentListOfValues lov) throws TCException {
- Map<String, Object> maps = new HashMap<String, Object>();
- ListOfValuesInfo listOfValues = lov.getListOfValues();
- Object[] lovbd1 = listOfValues.getListOfValues();// LOV值
- String[] lovs1 = listOfValues.getLOVDisplayValues();// LOV本地化值
- for (int j = 0; j < lovbd1.length; j++) {
- // 真实名称与本地化名称不匹配时直接使用真实名称列表
- if (lovbd1.length > lovs1.length) {
- maps.put(lovbd1[j].toString(), lovbd1[j]);
- } else {
- maps.put(lovs1[j], lovbd1[j]);
- }
- }
- return maps;
- }
- /**
- * 度量单位对象
- * */
- public Map<String,TCComponent> getUomTagObject() throws TCException {
- Map<String,TCComponent> uom_tagMap = new HashMap<String,TCComponent>();
- TCComponentUnitOfMeasureType localTCComponentUnitOfMeasureType = (TCComponentUnitOfMeasureType)session.getTypeComponent("UnitOfMeasure");
- TCComponent[] arrayOfTCComponents = localTCComponentUnitOfMeasureType.extent();
- String uomtagStr = "";
- for(TCComponent arrayOfTCComponent:arrayOfTCComponents) {
- uomtagStr = arrayOfTCComponent.toString();
- uom_tagMap.put(uomtagStr, arrayOfTCComponent);
- }
- return uom_tagMap;
- }
- //1、使用类型创建信封,需要获取到用户的邮箱文件夹,将信封添加到下面
- /**测试创建信封邮件
- * @throws Exception */
- public void TestNewEnvelope() throws Exception {
- TCComponentEnvelopeType tccomponentenvelopetype = (TCComponentEnvelopeType) session.getTypeComponent("Envelope");
- TCComponentUserType user = (TCComponentUserType)session.getTypeComponent("User");
- TCComponentUser find = user.find("infodba");
- TCComponentUser find2 = user.find("huahua");
- String subject = "主题";
- String message = "邮件";
- TCComponent toReceivers[] = {find};
- TCComponent ccReceivers[] = {find2};
- String toExternalUsers[] = {"infodba"};
- String ccExternalUsers[] = {"huahua"};
- TCComponentFolder mailBox = find.getMailBox();
- TCComponentFolder mailBox2 = find2.getMailBox();
- TCComponent atccomponent1[] = validateAttachments();
- TCComponentEnvelope envelope = tccomponentenvelopetype.create(subject, message, toReceivers, ccReceivers, toExternalUsers, ccExternalUsers, atccomponent1);
- mailBox.add("contents", envelope);
- mailBox2.add("contents", envelope);
- }
- /**信封邮件附件对象解析*/
- @SuppressWarnings({ "unchecked", "rawtypes" })
- public TCComponent[] validateAttachments(){
- if(attachmentList == null || attachmentList.length == 0)
- return null;
- ArrayList arraylist = new ArrayList();
- ArrayList arraylist1 = new ArrayList();
- Object obj = null;
- Registry registry = Registry.getRegistry(this);
- for(int i = 0; i < attachmentList.length; i++){
- try{
- if(attachmentList[i].isTypeOf("BOMLine")){
- TCComponentBOMLine tccomponentbomline = (TCComponentBOMLine)attachmentList[i];
- arraylist.add(tccomponentbomline.getItemRevision());
- } else if(attachmentList[i].isTypeOf("PseudoFolder")) {
- TCException tcexception1 = new TCException((new StringBuilder(String.valueOf(attachmentList[i].toString()))).append("-").append(registry.getString("invalidAttach.MESSAGE")).toString());
- arraylist1.add(tcexception1);
- } else if(attachmentList[i] instanceof TCComponentMECfgLine) {
- TCComponentMECfgLine tccomponentmecfgline = (TCComponentMECfgLine)attachmentList[i];
- arraylist.add(tccomponentmecfgline.getUnderlyingComponent());
- } else {
- arraylist.add(attachmentList[i]);
- }
- }catch(TCException tcexception2){
- arraylist1.add(tcexception2);
- }
- }
- if(arraylist1.size() > 0) {
- StringBuffer stringbuffer = new StringBuffer();
- for(int j = 0; j < arraylist1.size(); j++) {
- TCException tcexception = (TCException)arraylist1.get(j);
- stringbuffer.append((new StringBuilder(String.valueOf(tcexception.getMessage()))).append("\n").toString());
- }
- }
- TCComponent atccomponent[] = (TCComponent[])arraylist.toArray(new TCComponent[arraylist.size()]);
- return atccomponent;
- }
- //2、调用系统的创建信封程序
- /**测试创建信封邮件
- * @throws Exception */
- public void TestNewEnvelope() throws Exception {
- AIFDesktop currentDesktop = AIFDesktop.getActiveDesktop().getDesktopManager().getCurrentDesktop();
- //1、传入用户
- TCComponentUserType user = (TCComponentUserType)session.getTypeComponent("User");
- TCComponentUser find = user.find("infodba");
- TCComponentUser find2 = user.find("huahua");
- Recipient recipient = new Recipient(find);
- Recipient recipient2 = new Recipient(find2);
- Recipient[] recipients = {recipient};
- Recipient[] recipients2 = {recipient2};
- //2、传入组
- TCComponentGroupType group = (TCComponentGroupType)session.getTypeComponent("Group");
- TCComponent[] extent = group.extent();
- TCComponentGroup find3 = group.find("dba");
- TCComponentGroup find4 = group.find("test.dba");
- Recipient recipient3 = new Recipient(find3);
- Recipient recipient4 = new Recipient(find4);
- Recipient[] recipients3 = {recipient3};
- Recipient[] recipients4 = {recipient4};
- String subject = "主题234";
- String message = "邮件";
- TCComponentEnvelope envelope = null;
- NewEnvelopeOperation newEnvelopeOperation = new NewEnvelopeOperation(session, null, recipients3, recipients4, subject, message, attachmentList, 0, envelope);
- session.queueOperation(newEnvelopeOperation);
- }
- /**获取应用ID*/
- public void getAppId() {
- String applicationId = AIFDesktop.getActiveDesktop().getDesktopManager().getCurrentDesktop().getCurrentApplication() .getApplicationId();
- System.out.println(applicationId);
- }
- /**调用外部dll文件的方法
- * @throws TCException */
- public void callExternalDLLFileMethod() throws TCException {
- TCUserService userService = session.getUserService();
- InterfaceAIFComponent targetComponent = application.getTargetComponent();
- TCComponent tcComponent = (TCComponent) targetComponent;
- userService.call("AssignZZItem", new Object[] { tcComponent });
- }
- /**显示Home树
- * @throws TCException */
- public void showHomeView() throws TCException {
- TCComponentFolder homeFolder = session.getUser().getHomeFolder();
- final Display display = Display.getDefault();
- AIFDesktop aifdesktop = AIFUtility.getActiveDesktop();
- Shell shell = aifdesktop.getShell();
- final Shell shell = new Shell();
- shell.setSize(500, 575);
- shell.setText("Home树结构");
- //树结构
- TreeViewer treeviewer = new TreeViewer(shell, SWT.BORDER|SWT.H_SCROLL);
- //带复选框的树结构
- //ContainerCheckedTreeViewer treeViewer = new ContainerCheckedTreeViewer(shell, SWT.BORDER|SWT.H_SCROLL);
- treeviewer.setLabelProvider(new TCComponentLabelProvider());
- treeviewer.setContentProvider(new TCComponentContentProvider());
- treeviewer.setInput(new ComponentRootNode(homeFolder));
- treeviewer.expandToLevel(2);
- shell.open();
- shell.setLayout(new FillLayout());
- shell.layout();
- while (!shell.isDisposed()) {
- if (!display.readAndDispatch())
- display.sleep();
- }
- }
- /**
- * 调用查询构建器
- *
- * @param findName:查询值,如查询5开头的零组件则findName=5*
- * @param findValue:查询条件真实名称,如object_name
- * @param name:查询名称,如"数据集名称"
- * @author huyanling
- */
- public TCComponent[] findData(String[] findName, String[] findValue, String name) {
- try {
- if (findName.length > findValue.length) {
- MessageBox.post("查询条件与查询值不对应,请检查!", "提示", 2);
- return null;
- }
- TCComponentQueryType typeComponent = (TCComponentQueryType) session.getTypeComponent("ImanQuery");
- TCComponentQuery find = (TCComponentQuery) typeComponent.find(name);
- if (find == null) {
- MessageBox.post("TC中没有【" + name + "】这个查询,请定义该查询后使用!", "提示", 2);
- return null;
- }
- TCQueryClause[] describe = find.describe();
- String[] strings = new String[findValue.length];
- String[] value = findName;
- for (int v = 0; v < findValue.length; v++) {
- strings[v] = describe[v].getUserEntryNameDisplay();
- }
- TCComponent[] execute = find.execute(strings, value);
- if (execute.length > 0) {
- return execute;
- } else {
- return execute;
- }
- } catch (TCException e) {
- e.printStackTrace();
- }
- return null;
- }
- //1、
- AbstractAIFUIApplication application = AIFUtility.getCurrentApplication();
- //2、
- AbstractAIFUIApplication application = AIFDesktop.getActiveDesktop().getCurrentApplication();
- /**获取对象属性的LOV*/
- public String[] getLOVByItemType(TCComponent find,String PROPERNAME) throws TCException {
- TCProperty tcProperty = find.getTCProperty(PROPERNAME);
- TCComponentListOfValues lov = tcProperty.getLOV();
- ListOfValuesInfo listOfValues = lov.getListOfValues();
- Object[] listOfValues2 = listOfValues.getListOfValues();//LOV值
- String[] lovDisplayValues = listOfValues.getLOVDisplayValues();//LOV本地化值
- return lovDisplayValues;
- }
- //1)第一种方式
- ISessionService sessionService = AifrcpPlugin.getSessionService();
- TCSession session = (TCSession)sessionService.getSession("com.teamcenter.rac.kernel.TCSession");
- //2)第二种方式
- AbstractAIFUIApplication application = AIFUtility.getCurrentApplication();
- TCSession session = (TCSession)application.getSession();
- //3)第三种方式
- TCSession session =(TCSession)AIFUtility.getDefaultSession();
- //1、
- NavigatorOpenService navigatorOpenService = new NavigatorOpenService();
- navigatorOpenService.open(aifComponent);
- //2、
- AifrcpPlugin.getDefault().openComponents("com.teamcenter.rac.ui.perspectives.navigatorPerspective",new InterfaceAIFComponent[] {aifComponent});
- //3、
- ComponentOpenHelper componentOpenHelper = new ComponentOpenHelper(AifrcpPlugin.getDefault());
- componentOpenHelper.openComponents(s, new InterfaceAIFComponent[] {aifComponent});
- //4、
- SearchOpenService searchOpenService = new SearchOpenService();
- InterfaceAIFComponent targetComponent = application.getTargetComponent();
- searchOpenService.open(targetComponent);
- //5、
- AIFDesktop desktop = AIFDesktop.getActiveDesktop().getDesktopManager().getActiveDesktop();
- InterfaceAIFComponent[] targetComponent = application.getTargetComponents();
- OpenCommand openCommand = new OpenCommand(desktop, targetComponent);
- openCommand.executeModal();
TCComponentItemType typeComponent = (TCComponentItemType) session.getTypeComponent(itemType);
- String s2 = typeComponent.getRevisionTypeName(itemType);
- tccomponentitemrevisiontype = (TCComponentItemRevisionType) session.getTypeComponent(s2);
TCPropertyDescriptor tcpropertydescriptor = typeComponent.getPropertyDescriptor(properName);
1、获取所有值列表
- TCComponentListOfValuesType ListOfValues = (TCComponentListOfValuesType) session.getTypeComponent("ListOfValues");
- TCComponent[] extent1 = ListOfValues.extent();
2、获取动态值列表
- TCComponentListOfValuesType Dynamic = (TCComponentListOfValuesType) session.getTypeComponent("Fnd0ListOfValuesDynamic");
- TCComponent[] extent2 = Dynamic.extent();
3、获取字符型值列表
- TCComponentListOfValuesType Char = (TCComponentListOfValuesType) session.getTypeComponent("ListOfValuesChar");
- TCComponent[] extent3 = Char.extent();
4、获取日期值型值列表
- TCComponentListOfValuesType Date = (TCComponentListOfValuesType) session.getTypeComponent("ListOfValuesDate");
- TCComponent[] extent4 = Date.extent();
5、获取双精度数值型值列表
- TCComponentListOfValuesType Double = (TCComponentListOfValuesType) session.getTypeComponent("ListOfValuesDouble");
- TCComponent[] extent5 = Double.extent();
6、获取过滤器型值列表
- TCComponentListOfValuesType Filter = (TCComponentListOfValuesType) session.getTypeComponent("ListOfValuesFilter");
- TCComponent[] extent6 = Filter.extent();
7、获取数值型值列表
- TCComponentListOfValuesType Integer = (TCComponentListOfValuesType) session.getTypeComponent("ListOfValuesInteger");
- TCComponent[] extent7 = Integer.extent();
8、获取字符串型值列表
- TCComponentListOfValuesType String = (TCComponentListOfValuesType) session.getTypeComponent("ListOfValuesString");
- TCComponent[] extent8 = String.extent();
9、获取标记值列表
- TCComponentListOfValuesType Tag = (TCComponentListOfValuesType) session.getTypeComponent("ListOfValuesTag");
- TCComponent[] extent9 = Tag.extent();
10、获取属性的值列表
- TCComponentItemType typeComponent = (TCComponentItemType) session.getTypeComponent(itemType);
- TCPropertyDescriptor tcpropertydescriptor = typeComponent.getPropertyDescriptor(properName);
- TCComponentListOfValues lov = tcpropertydescriptor.getLOV();
- String as[] = { "item_id", "item_revision_id" };
- String as1[] = { ITEMTYPE, ITEMTYPE};
- //获取命名规则列表,包括item和itemRevision的命名规则
- NamingRule anamingrule[] = NamingRulesHelper.getInstance().getNamingRules(session, as1, as);
- String as2[] = anamingrule[0].getPatterns();//item命名规则
- String as3[] = anamingrule[1].getPatterns();//itemRevision命名规则
- TCComponentUnitOfMeasureType localTCComponentUnitOfMeasureType = (TCComponentUnitOfMeasureType)session.getTypeComponent("UnitOfMeasure");
- TCComponent[] arrayOfTCComponents = localTCComponentUnitOfMeasureType.extent();
- TCComponentUserType user = (TCComponentUserType)session.getTypeComponent("User");
- TCComponent[] extent = user.extent();
- TCComponentStatusTypeType status = (TCComponentStatusTypeType)session.getTypeComponent("TaskType");
- TCComponent[] extent = status.extent();
- TCComponentGroupType group = (TCComponentGroupType)session.getTypeComponent("Group");
- TCComponent[] extent = group.extent();
TCComponentProcessType procesType = (TCComponentProcessType) session.getTypeComponent("Job");
TCComponentTaskTemplateType TaskTemplateT = (TCComponentTaskTemplateType) session.getTypeComponent("EPMTaskTemplate");
- TCComponentICOType icoType = (TCComponentICOType) session.getTypeComponent("icm0");
- TCComponent[] ico = icoType.extent();
- TCComponentToolType toolType = (TCComponentToolType) session.getTypeComponent("Tool");
- TCComponent[] extent = toolType.extent();
- TCComponentProjectType projectType = (TCComponentProjectType) session.getTypeComponent("TC_Project");
- TCComponent[] projects = projectType.extent();
- TCComponentNoteTypeType noteTypeType = (TCComponentNoteTypeType) session.getTypeComponent("NoteType");
- TCComponent[] noteTypes = noteTypeType.extent();
- TCComponentViewTypeType viewTypeType = (TCComponentViewTypeType) session.getTypeComponent("PSViewType");
- TCComponent[] viewTypes = viewTypeType.extent();
- TCComponentEventType eventType = (TCComponentEventType) session.getTypeComponent("ImanEventType");
- TCComponent[] events = eventType.extent();
- //根据零件获取零件对应版本
- TCComponentItem item = (TCComponentItem) targetComponent;
- //1、Item发布的版本
- TCComponentItemRevision[] releasedItemRevisions = item.getReleasedItemRevisions();
- //2、Item工作中的版本
- TCComponentItemRevision[] workingItemRevisions = item.getWorkingItemRevisions();
- //3、Item流程中的版本
- TCComponentItemRevision[] inProcessItemRevisions = item.getInProcessItemRevisions();
- /**根据引用属性获取引用属性所属对象(当属性值不为数组时使用)
- * 例:查询选中item对象的所有权项目
- * @param property:属性名称 ;例:(owning_project)
- * @param tcComponent:当前对象;(TCComponentItem)
- * @return TCComponent:引用对象
- * @throws TCException
- * */
- public TCComponent getReferenceTCComponent(String property,TCComponent tcComponent) throws TCException {
- TCComponent referenceProperty = tcComponent.getReferenceProperty(property);
- return tcComponent;
- }
- /**根据引用属性获取引用属性所属对象(当属性值为数组时使用)
- * 例:查询选中item对象的项目列表
- * @param property:属性名称 ;例:(project_list)
- * @param tcComponent:当前对象;(TCComponentItem)
- * @return TCComponent[]:引用对象列表(选中零件的项目列表)
- * @throws TCException
- * */
- public TCComponent[] getReferenceTCComponents(String property,TCComponent tcComponent) throws TCException {
- //1、直接获取
- TCComponent[] referenceListProperty = tcComponent.getReferenceListProperty(property);
- //2、根据属性获取
- TCProperty tcProperty = tcComponent.getTCProperty(property);
- TCComponent[] referenceValues = TCProperty.getReferenceValues(new TCProperty[]{tcProperty});
- return referenceValues;
- }
- /**获取系统中的用户*/
- public List<String> getUserList() throws TCException {
- TCComponentUserType user = (TCComponentUserType)session.getTypeComponent("User");
- TCComponent[] extent = user.extent();
- List<String> resultList = new ArrayList<String>(extent.length);
- resultList.add("");
- for(TCComponent tc:extent) {
- if (tc instanceof TCComponentUser) {
- TCComponentUser user1 = (TCComponentUser) tc;
- resultList.add(user1.toString());
- //resultList.add(user1.getUserId());
- }
- }
- return resultList;
- }
- /**获取系统中的组*/
- public List<String> getGroupList() throws TCException {
- TCComponentGroupType group = (TCComponentGroupType)session.getTypeComponent("Group");
- TCComponent[] extent = group.extent();
- List<String> resultList = new ArrayList<String>(extent.length);
- resultList.add("");
- for(TCComponent tc:extent) {
- resultList.add(tc.toString());
- }
- return resultList;
- }
- /**获取系统中的发布状态*/
- public List<String> getStatusList() throws TCException {
- TCComponentStatusTypeType status = (TCComponentStatusTypeType)session.getTypeComponent("TaskType");
- TCComponent[] extent = status.extent();
- List<String> resultList = new ArrayList<String>(extent.length);
- resultList.add("");
- for(TCComponent tc:extent) {
- resultList.add(tc.toString());
- }
- return resultList;
- }