ManufacturerDatautility.zip
立即下载
资源介绍:
111
package ext.rwd.part.datautility;
import java.io.File;
import java.io.InputStream;
import java.util.ArrayList;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.ss.usermodel.WorkbookFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.ptc.core.components.beans.CreateAndEditWizBean;
import com.ptc.core.components.descriptor.ModelContext;
import com.ptc.core.components.factory.AbstractDataUtility;
import com.ptc.core.components.factory.dataUtilities.AttributeDataUtilityHelper;
import com.ptc.core.components.rendering.GuiComponent;
import com.ptc.core.components.rendering.guicomponents.ComboBox;
import com.ptc.core.meta.type.common.impl.DefaultTypeInstance;
import com.ptc.core.ui.resources.ComponentMode;
import com.ptc.netmarkets.util.beans.NmCommandBean;
import ext.lang.PIExcelUtils;
import ext.lang.PIStringUtils;
import ext.pi.PIException;
import ext.pi.core.PIAttributeHelper;
import ext.pi.core.PIContentHelper;
import ext.pi.core.PICoreHelper;
import ext.pi.core.PIDocumentHelper;
import wt.content.ApplicationData;
import wt.content.ContentItem;
import wt.content.ContentServerHelper;
import wt.doc.WTDocument;
import wt.fc.WTObject;
import wt.part.WTPart;
import wt.util.WTException;
public class ManufacturerDatautility extends AbstractDataUtility {
private static final String CLASSNAME = ManufacturerDatautility.class.getName();
private static final Logger logger = LoggerFactory.getLogger(CLASSNAME);
@Override
public Object getDataValue(String s, Object obj, ModelContext mc) throws WTException {
NmCommandBean nmCommandBean = mc.getNmCommandBean();
// 是否创建及编辑状态
boolean bool = CreateAndEditWizBean.isCreateEditWizard(nmCommandBean);
logger.debug(" >>>>>bool=" + bool);
if (bool) {
if (obj instanceof DefaultTypeInstance) {
DefaultTypeInstance instance = (DefaultTypeInstance) obj;
String oid = instance.getPersistenceIdentifier();
logger.debug(">>>oid=" + oid);
if (PIStringUtils.hasText(oid) && mc.getDescriptorMode().equals(ComponentMode.EDIT)) {
WTObject wtobj = PICoreHelper.service.getWTObjectByOid(oid);
if (wtobj != null && (wtobj instanceof WTPart)) {
WTPart part = (WTPart) wtobj;
String value = getValue(part, s);
value = value == null ? "" : value;
return getCom(s, obj, mc, value);
}
} else if (mc.getDescriptorMode().equals(ComponentMode.CREATE)) {
return getCom(s, obj, mc, "");
}
}
}
return null;
}
/**
* 构建文本框
*
* @param s
* @param obj
* @param mc
* @param value
* @return
* @throws WTException
*/
private ArrayList getCom(String s, Object obj, ModelContext mc, String value) throws WTException {
ArrayList excelData = getExcelData();
logger.debug(" >>>>excelData=" + excelData);
ArrayList component = new ArrayList();
if (excelData != null) {
ArrayList al = new ArrayList<>();
al.add("");
al.addAll(excelData);
ComboBox combobox = new ComboBox();
combobox.setId(s);
// combobox.setName(s);
combobox.setColumnName(AttributeDataUtilityHelper.getColumnName(s, obj, mc));
combobox.setValues(al);
combobox.setInternalValues(al);
combobox.setSelected(value);
combobox.setRequired(true);
component.add(combobox);
}
return component;
}
/**
* 获取属性值
*
* @param p
* @param compid
* @return
* @throws PIException
*/
public static String getValue(WTPart p, String compid) throws PIException {
return (String) PIAttributeHelper.service.getValue(p, compid);
}
/**
* 获取Excel数据
*
* @return
* @throws Exception
*/
public static ArrayList getExcelData() throws WTException {
ArrayList list = new ArrayList();
try {
WTDocument doc = PIDocumentHelper.service.findWTDocument("T000001");
if (doc == null) {
String templatePath = PICoreHelper.service.getCodebase()+ File.separator + "ext"
+ File.separator + "rwd" + File.separator + "template" + File.separator + "生产厂家配置表.xlsx";
File file = new File(templatePath);
Workbook book = WorkbookFactory.create(file);
Sheet sheet = book.getSheetAt(0);
int lastRowNum = sheet.getLastRowNum();
logger.debug(" >>>>lastRowNum=" + lastRowNum);
for (int i = 0; i <= lastRowNum; i++) {
Row row = PIExcelUtils.getRow(sheet, i + 1, true);
Cell cell = PIExcelUtils.getCell(row, 0, true);
String excelValue = PIExcelUtils.getCellValueAsString(cell, null);
if (!PIStringUtils.hasText(excelValue)) {
break;
}
list.add(excelValue);
}
if (book != null) {
book.close();
}
} else {
ContentItem content = PIContentHelper.service.findPrimaryContent(doc);
if (content != null) {
if (content instanceof ApplicationData) {
ApplicationData data = (ApplicationData) content;
InputStream is = ContentServerHelper.service.findContentStream(data);
Workbook book = WorkbookFactory.create(is);
Sheet sheet = book.getSheetAt(0);
int lastRowNum = sheet.getLastRowNum();
logger.debug(" >>>>lastRowNum=" + lastRowNum);
for (int i = 0; i <= lastRowNum; i++) {
Row row = PIExcelUtils.getRow(sheet, i + 1, true);
Cell cell = PIExcelUtils.getCell(row, 0, true);
String excelValue = PIExcelUtils.getCellValueAsString(cell, null);
if (!PIStringUtils.hasText(excelValue)) {
break;
}
list.add(excelValue);
}
if (book != null) {
book.close();
}
}
}
}
} catch (Exception e) {
e.printStackTrace();
}
return list;
}
}
资源文件列表:
ManufacturerDatautility.zip 大约有1个文件
- ManufacturerDatautility.java 5.84KB