You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

2351 lines
74 KiB

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

package cn.net.connor.ld.plm;
import java.awt.Component;
import java.awt.Dimension;
import java.awt.GridBagConstraints;
import java.awt.Window;
import java.io.BufferedWriter;
import java.io.EOFException;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileWriter;
import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
import java.text.DecimalFormat;
import java.text.SimpleDateFormat;
import java.time.Instant;
import java.time.LocalDate;
import java.time.ZoneId;
import java.time.ZonedDateTime;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JDialog;
import javax.swing.JFileChooser;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.filechooser.FileNameExtensionFilter;
import javax.swing.filechooser.FileSystemView;
import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.CellType;
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.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Shell;
import com.net.connor.ld.plm.ld06.ControlBean;
import com.teamcenter.rac.aif.commands.open.OpenCommand;
import com.teamcenter.rac.aif.kernel.AIFComponentContext;
import com.teamcenter.rac.aif.kernel.InterfaceAIFComponent;
import com.teamcenter.rac.aifrcp.AIFUtility;
import com.teamcenter.rac.common.lov.view.components.LOVDisplayer;
import com.teamcenter.rac.kernel.ListOfValuesInfo;
import com.teamcenter.rac.kernel.TCComponent;
import com.teamcenter.rac.kernel.TCComponentContextList;
import com.teamcenter.rac.kernel.TCComponentDataset;
import com.teamcenter.rac.kernel.TCComponentDatasetType;
import com.teamcenter.rac.kernel.TCComponentFolder;
import com.teamcenter.rac.kernel.TCComponentForm;
import com.teamcenter.rac.kernel.TCComponentGroup;
import com.teamcenter.rac.kernel.TCComponentGroupMember;
import com.teamcenter.rac.kernel.TCComponentItem;
import com.teamcenter.rac.kernel.TCComponentItemRevision;
import com.teamcenter.rac.kernel.TCComponentItemRevisionType;
import com.teamcenter.rac.kernel.TCComponentItemType;
import com.teamcenter.rac.kernel.TCComponentListOfValues;
import com.teamcenter.rac.kernel.TCComponentListOfValuesType;
import com.teamcenter.rac.kernel.TCComponentManager;
import com.teamcenter.rac.kernel.TCComponentQuery;
import com.teamcenter.rac.kernel.TCComponentQueryType;
import com.teamcenter.rac.kernel.TCComponentRole;
import com.teamcenter.rac.kernel.TCComponentSchedule;
import com.teamcenter.rac.kernel.TCComponentScheduleDeliverable;
import com.teamcenter.rac.kernel.TCComponentTCCalendar;
import com.teamcenter.rac.kernel.TCComponentTaskDeliverable;
import com.teamcenter.rac.kernel.TCComponentType;
import com.teamcenter.rac.kernel.TCComponentUser;
import com.teamcenter.rac.kernel.TCException;
import com.teamcenter.rac.kernel.TCProperty;
import com.teamcenter.rac.kernel.TCPropertyDescriptor;
import com.teamcenter.rac.kernel.TCSession;
import com.teamcenter.rac.kernel.TCTextService;
import com.teamcenter.rac.kernel.TCUserService;
import com.teamcenter.rac.schedule.calendar.TCCalendar;
import com.teamcenter.rac.schedule.componentutils.CalendarHelper;
import com.teamcenter.rac.ui.common.RACUIUtil;
import com.teamcenter.rac.util.MessageBox;
import com.teamcenter.rac.util.Registry;
import com.teamcenter.rac.util.UIUtilities;
import com.teamcenter.services.rac.core.DataManagementService;
import com.teamcenter.services.rac.core.LOVService;
import com.teamcenter.services.rac.core._2006_03.DataManagement.Relationship;
import com.teamcenter.services.rac.core._2007_01.DataManagement.WhereReferencedInfo;
import com.teamcenter.services.rac.core._2007_01.DataManagement.WhereReferencedOutput;
import com.teamcenter.services.rac.core._2007_01.DataManagement.WhereReferencedResponse;
import com.teamcenter.services.rac.core._2008_06.DataManagement.CreateIn;
import com.teamcenter.services.rac.core._2008_06.DataManagement.CreateInput;
import com.teamcenter.services.rac.core._2008_06.DataManagement.CreateOut;
import com.teamcenter.services.rac.core._2008_06.DataManagement.CreateResponse;
import com.teamcenter.services.rac.core._2013_05.LOV.InitialLovData;
import com.teamcenter.services.rac.core._2013_05.LOV.LOVSearchResults;
import com.teamcenter.services.rac.core._2013_05.LOV.LOVValueRow;
import com.teamcenter.services.rac.core._2013_05.LOV.LovFilterData;
import com.teamcenter.soa.client.model.LovValue;
import com.teamcenter.soa.client.model.ServiceData;
@SuppressWarnings("deprecation")
public class KUtil {
public static final TCSession session;
public static final TCTextService textService;
// public static final Registry REG = Registry.getRegistry(KUtil.class);
public static final ZoneId zoneId = ZoneId.systemDefault();
// public static final Registry reg = Registry.getRegistry(KUtil.class);
// public static String getRegString(String title) {
// String res = reg.getString(title);
// if (KUtil.isEmpty(res)) {
// return title;
// }
// return res;
// }
static {
session = (TCSession) AIFUtility.getCurrentApplication().getSession();
textService = session.getTextService();
}
public static void setTCPropertyValue(TCComponent item, String propertyName, Object value) {
try {
TCProperty tcProperty = item.getTCProperty(propertyName);
switch (tcProperty.getPropertyType()) {
case TCProperty.PROP_double:
if (value instanceof Double) {
tcProperty.setDoubleValue((double) value);
} else {
tcProperty.setDoubleValue(Double.parseDouble(value.toString()));
}
break;
case TCProperty.PROP_int:
if (value instanceof Integer) {
tcProperty.setDoubleValue((int) value);
} else {
tcProperty.setDoubleValue(Integer.parseInt(value.toString()));
}
break;
case TCProperty.PROP_string:
tcProperty.setStringValue(value.toString());
break;
case TCProperty.PROP_date:
if (value instanceof Date) {
tcProperty.setDateValue((Date) value);
} else {
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-M-dd HH:mm");
tcProperty.setDateValue(sdf.parse(value.toString()));
}
break;
default:
break;
}
} catch (Exception e) {
e.printStackTrace();
}
}
public static Object getTCPropertyValue(TCComponent item, String propertyName) {
Object result = "";
try {
TCProperty tcProperty = item.getTCProperty(propertyName);
if (tcProperty == null) {
System.out.println(<><CEB4>ȡ<EFBFBD><C8A1><EFBFBD>ԣ<EFBFBD>" + propertyName);
return result;
}
switch (tcProperty.getPropertyType()) {
case TCProperty.PROP_double:
result = tcProperty.getDoubleValue();
break;
case TCProperty.PROP_int:
result = tcProperty.getIntValue();
break;
case TCProperty.PROP_string:
result = tcProperty.getStringValue();
break;
case TCProperty.PROP_date:
result = tcProperty.getDateValue();
break;
case TCProperty.PROP_logical:
result = tcProperty.getLogicalValue();
break;
default:
break;
}
} catch (TCException e) {
e.printStackTrace();
}
return result;
}
public static String getCellValue(Cell c) {
if (c == null) {
return "";
}
String value = "";
if (c.getCellType() == CellType.NUMERIC.getCode()) {
DecimalFormat df = new DecimalFormat("0");
String whatYourWant = df.format(c.getNumericCellValue());
return whatYourWant;
}
switch (c.getCellType()) {
case HSSFCell.CELL_TYPE_NUMERIC:// <20><><EFBFBD><EFBFBD>
value = (c.getNumericCellValue() + "").split("\\.")[0];
break;
case HSSFCell.CELL_TYPE_STRING:// <20>ַ<EFBFBD><D6B7><EFBFBD>
value = c.getStringCellValue();
break;
case HSSFCell.CELL_TYPE_BOOLEAN:// boolean
value = c.getBooleanCellValue() + "";
break;
case HSSFCell.CELL_TYPE_FORMULA:// <20><>ʽ
value = c.getCellFormula() + "";
break;
case HSSFCell.CELL_TYPE_BLANK:// <20><>ֵ
value = "";
break;
case HSSFCell.CELL_TYPE_ERROR:
value = "<22>Ƿ<EFBFBD><C7B7>ַ<EFBFBD>";
break;
default:
value = "δ֪<CEB4><D6AA><EFBFBD><EFBFBD>";
break;
}
return value;
}
/**
* <20><><EFBFBD><EFBFBD><EFBFBD>õ<EFBFBD><C3B5><EFBFBD>ʵ<EFBFBD><CAB5><EFBFBD><EFBFBD>
*
* @param sheet
* @param flag <20><>Ҫд<D2AA><D0B4><EFBFBD><EFBFBD><EFBFBD>ݿ<EFBFBD><DDBF><EFBFBD>Excel<65><6C>Ԫ<EFBFBD><D4AA><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ö<EFBFBD><C3B6>Ÿ<EFBFBD><C5B8><EFBFBD> <20><><EFBFBD><EFBFBD>Excel<65><6C>5<EFBFBD>е<EFBFBD>Ԫ<EFBFBD><D4AA><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>4<EFBFBD><34>
* <20><>Ҫ<EFBFBD><D2AA><EFBFBD><EFBFBD><E2A3AC>2<EFBFBD>в<EFBFBD><D0B2><EFBFBD>Ҫ<EFBFBD><D2AA><EFBFBD><EFBFBD><E2A3AC><EFBFBD><EFBFBD>flag<61>ʹ<EFBFBD> [0,2,3,4]
* @return
* @throws Exception
*
*/
public static int findRealRows(Sheet sheet, int... flag) throws Exception {
int row_real = 0;
int rows = sheet.getPhysicalNumberOfRows();// <20>˴<EFBFBD><CBB4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͳ<EFBFBD><CDB3><EFBFBD>д<EFBFBD><D0B4><EFBFBD>,
try {
for (int i = 1; i < rows; i++) {
Row row = sheet.getRow(i);
int total = 0;
ArrayList<Integer> blank = new ArrayList<Integer>();
int type = -1;
String s = null;
for (int j : flag) {
if (!(row.getCell(j) == null) && row.getCell(j).getCellType() < 2) {
type = row.getCell(j).getCellType();
row.getCell(j).setCellType(1);
}
if (row.getCell(j) == null || row.getCell(j).getStringCellValue().matches("^\\s+$")
|| row.getCell(j).getCellType() > 2) {
total++;
if (!(row.getCell(j) == null) && row.getCell(j).getCellType() < 2) {
row.getCell(j).setCellType(type);
}
blank.add(j);
}
}
System.out.println(s + "<22><>");
// <20><><EFBFBD><EFBFBD>4<EFBFBD>ж<EFBFBD><D0B6>ǿ<EFBFBD>˵<EFBFBD><CBB5><EFBFBD>͸÷<CDB8><C3B7><EFBFBD>
if (total == flag.length) {
return row_real;
} else if (total == 0) {
row_real++;
} else {
String h = "";
for (Integer b : blank) {
h = h + "<22><>" + (b + 1) + "<22><>" + " ";
}
throw new Exception("<22><>" + (i + 1) + "<22><>" + h + "<22><><EFBFBD><EFBFBD>Ϊ<EFBFBD><CEAA>");
}
}
} catch (NullPointerException e) {
throw new Exception("excel<65><6C>ʽ<EFBFBD>쳣,<2C><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>excel<65><6C>ʽ<EFBFBD><CABD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ȱʧ,<2C><>Ч<EFBFBD><D0A7><EFBFBD><EFBFBD><EFBFBD><EFBFBD>!");
}
return row_real;
}
public static Workbook getWorkbook(File file) throws Exception {
Workbook workbook = null;
FileInputStream in = new FileInputStream(file);
if (file.getName().endsWith("xlsx")) {
System.out.println("<22><>ȡģ<C8A1><C4A3>:" + file.getName());
try {
workbook = WorkbookFactory.create(in);
} catch (EOFException e) {
e.printStackTrace();
}
// workbook = new XSSFWorkbook(in);
} else {
System.out.println("<22><>ʽ<EFBFBD><CABD><EFBFBD><EFBFBD>");
}
in.close();
return workbook;
}
public static void removeEnd(StringBuilder sb, int len) {
if (sb == null || len <= 0) {
return;
}
if (sb.length() >= len) {
sb.setLength(sb.length() - len);
}
}
public static TCComponent[] getComponentsByItemType(TCComponent comp, String type, String relation)
throws TCException {
TCComponent[] comps1 = comp.getRelatedComponents(relation);
if (comps1 == null || comps1.length < 1) {
return null;
}
ArrayList<TCComponent> list = new ArrayList<TCComponent>();
for (TCComponent comp1 : comps1) {
if (comp1.getType().equals(type)) {
list.add(comp1);
}
}
return list.toArray(new TCComponent[] {});
}
public static TCComponentContextList objectsInProject(String type, String projId) throws Exception {
if (KUtil.isEmpty(type) || KUtil.isEmpty(projId)) {
return null;
}
String queryName = "Objects in Projects";
String[] keys = new String[] { KUtil.getText("Type"), KUtil.getText("ProjectID") };
String[] vals = new String[] { type, projId };
return KUtil.query(KUtil.session, queryName, keys, vals);
}
public static TCComponentContextList objectsInProject(String type, String projId, String name) throws Exception {
if (KUtil.isEmpty(type) || KUtil.isEmpty(projId) || KUtil.isEmpty(name)) {
return null;
}
String queryName = "Objects in Projects";
String[] keys = new String[] { KUtil.getText("Name"), KUtil.getText("Type"), KUtil.getText("ProjectID") };
String[] vals = new String[] { name, type, projId };
return KUtil.query(KUtil.session, queryName, keys, vals);
}
public static boolean checkGMPrivilegeFromPref(String prefName) throws Exception {
boolean validityCanEdit = false;
String validRoles = KUtil.getPrefVal(KUtil.session, prefName);
System.out.println(">> Check GroupMember Priv: " + validRoles);
if (!KUtil.isEmpty(validRoles)) {
List<String> groups = new ArrayList<String>();
List<String> roles = new ArrayList<String>();
String[] split = validRoles.split(":");
for (String string : split) {
if (string.startsWith("G.")) {
groups.add(string.substring(2));
} else if (string.startsWith("R.")) {
roles.add(string.substring(2));
}
}
TCComponentUser currentUser = KUtil.session.getUser();
System.out.println(">> Current User: " + currentUser);
TCComponentGroupMember[] gms = currentUser.getGroupMembers();
System.out.println(">> Current GroupMembers: " + Arrays.toString(gms));
int len = KUtil.getLen(gms);
for (int i = 0; i < len; i++) {
TCComponentGroupMember gm = gms[i];
TCComponentGroup g = gm.getGroup();
TCComponentRole r = gm.getRole();
String gName = g.getGroupName();
String rName = r.getRoleName();
System.out.println((i + 1) + ". " + gName + " - " + rName);
if (groups.contains(gName) && roles.contains(rName)) {
validityCanEdit = true;
// break;
}
}
}
return validityCanEdit;
}
public static boolean compare(String str1, String str2) {
if (str1 == null) {
str1 = "";
}
if (str2 == null) {
str2 = "";
}
return str1.equals(str2);
}
public static boolean compare(Object str1, Object str2) {
if (str1 == null) {
return str2 == null;
}
return str1.equals(str2);
}
public static TCComponentItem createItem(TCComponentItemType itemType, String itemName) throws Exception {
if (itemType == null) {
return null;
}
String id = itemType.getNewID();
String rev = itemType.getNewRev(null);
return itemType.create(id, rev, itemType.getName(), itemName, "", null);
}
public static void setByPass(boolean val) {
try {
TCUserService userservice = session.getUserService();
userservice.call(val ? "CONNOR_open_bypass" : "CONNOR_close_bypass", new Object[] { "" });
System.out.println(val ? "Open Bypass" : "Close Bypass");
} catch (Exception e) {
e.printStackTrace();
}
}
public static TCComponentItem createItemBySOA(String itemTypeName, String revTypeName, String revMasterTypeName,
String itemId, String revId, String name, Map<String, String> stringProps, Map<String, Calendar> dateProps)
throws Exception {
if (KUtil.isEmpty(itemTypeName) || KUtil.isEmpty(revTypeName) || KUtil.isEmpty(revMasterTypeName)) {
return null;
}
CreateInput revMasterInput = new CreateInput();
revMasterInput.boName = revMasterTypeName;
if (stringProps != null) {
revMasterInput.stringProps = stringProps;
}
if (dateProps != null) {
revMasterInput.dateProps = dateProps;
}
CreateInput revInput = new CreateInput();
revInput.boName = revTypeName;
Map<String, String> revPropMap = new HashMap<>();
if (!KUtil.isEmpty(revId)) {
revPropMap.put("item_revision_id", revId);
}
revInput.stringProps = revPropMap;
Map<String, CreateInput[]> revMasterInfoMap = new HashMap<>();
revMasterInfoMap.put("IMAN_master_form_rev", new CreateInput[] { revMasterInput });
revInput.compoundCreateInput = revMasterInfoMap;
// create rev
CreateInput itemInput = new CreateInput();
itemInput.boName = itemTypeName;
Map<String, String> itemPropMap = new HashMap<>();
if (!KUtil.isEmpty(itemId)) {
itemPropMap.put("item_id", itemId);
}
if (!KUtil.isEmpty(name)) {
itemPropMap.put("object_name", name);
}
itemInput.stringProps = itemPropMap;
Map<String, CreateInput[]> revInfoMap = new HashMap<>();
revInfoMap.put("revision", new CreateInput[] { revInput });
itemInput.compoundCreateInput = revInfoMap;
// create info
CreateIn cI = new CreateIn();
cI.clientId = "CreateItem";
cI.data = itemInput;
// service
DataManagementService service = DataManagementService.getService(session);
// create
CreateResponse resp = service.createObjects(new CreateIn[] { cI });
throwServiceDataError(resp.serviceData);
CreateOut[] cOs = resp.output;
if (cOs.length > 0) {
for (TCComponent s : cOs[0].objects) {
if (s instanceof TCComponentItem) {
return (TCComponentItem) s;
}
}
}
return null;
}
public static TCComponentFolder createFolderBySOA(String folderTypeName, String folderName) throws Exception {
if (KUtil.isEmpty(folderTypeName)) {
return null;
}
CreateInput itemInput = new CreateInput();
itemInput.boName = folderTypeName;
Map<String, String> itemPropMap = new HashMap<>();
itemPropMap.put("object_name", folderName);
itemInput.stringProps = itemPropMap;
// create info
CreateIn cI = new CreateIn();
cI.clientId = "CreateFolder";
cI.data = itemInput;
// service
DataManagementService service = DataManagementService.getService(session);
// create
CreateResponse resp = service.createObjects(new CreateIn[] { cI });
throwServiceDataError(resp.serviceData);
CreateOut[] cOs = resp.output;
if (cOs.length > 0) {
for (TCComponent s : cOs[0].objects) {
if (s instanceof TCComponentFolder) {
return (TCComponentFolder) s;
}
}
}
return null;
}
public static void throwServiceDataError(ServiceData serviceData) throws Exception {
if (serviceData.sizeOfPartialErrors() > 0) {
StringBuilder errInfo = new StringBuilder();
for (int i = 0; i < serviceData.sizeOfPartialErrors(); i++) {
for (String msg : serviceData.getPartialError(i).getMessages()) {
errInfo.append(msg + "\n");
}
}
// System.out.println(errInfo.toString());
throw new Exception(errInfo.toString());
}
}
public static void throwServiceDataError(ServiceData serviceData, String defaultErrorMsg) throws Exception {
if (serviceData.sizeOfPartialErrors() > 0) {
StringBuilder errInfo = new StringBuilder();
for (int i = 0; i < serviceData.sizeOfPartialErrors(); i++) {
for (String msg : serviceData.getPartialError(i).getMessages()) {
errInfo.append(msg + "\n");
}
}
// System.out.println(errInfo.toString());
if (KUtil.isEmpty(errInfo.toString())) {
throw new Exception(defaultErrorMsg);
}
throw new Exception(errInfo.toString());
}
}
public static Date localDateToDate(LocalDate localDate) {
if (localDate == null) {
return null;
}
ZonedDateTime zdt = localDate.atStartOfDay(zoneId);
Date date = Date.from(zdt.toInstant());
return date;
}
public static LocalDate dateToLocalDate(Date date) {
if (date == null) {
return null;
}
Instant instant = date.toInstant();
LocalDate localDate = instant.atZone(zoneId).toLocalDate();
return localDate;
}
public static TCComponent stringToComponent(String uid) throws Exception {
if (KUtil.isEmpty(uid)) {
return null;
}
return session.stringToComponent(uid);
}
public static String getText(String str) throws Exception {
if (KUtil.isEmpty(str)) {
return str;
}
String res = textService.getTextValue(str);
if (!KUtil.isEmpty(res)) {
return res;
}
return str;
}
public static void sendTo(TCComponent comp, String perspectiveId) {
if (comp == null) {
return;
}
if (KUtil.isEmpty(perspectiveId)) {
perspectiveId = "com.teamcenter.rac.ui.perspectives.navigatorPerspective";
}
com.teamcenter.rac.common.Activator.getDefault().openPerspective(perspectiveId);
com.teamcenter.rac.common.Activator.getDefault().openComponents(perspectiveId, new TCComponent[] { comp });
}
public static void open(TCComponent comp) {
if (comp == null) {
return;
}
if (comp instanceof TCComponentScheduleDeliverable) {
System.out.println(">> Open Schedule Deliverable: " + comp);
try {
comp = comp.getReferenceProperty("deliverable_inst");
System.out.println(">> Open Schedule Deliverable Inst: " + comp);
if (comp == null) {
return;
}
} catch (Exception e) {
e.printStackTrace();
}
} else if (comp instanceof TCComponentTaskDeliverable) {
System.out.println(">> Open Task Deliverable: " + comp);
try {
comp = comp.getReferenceProperty("fnd0DeliverableInstance");
System.out.println(">> Open Task Deliverable Inst: " + comp);
if (comp == null) {
return;
}
} catch (Exception e) {
e.printStackTrace();
}
}
try {
Registry localRegistry = Registry.getRegistry("com.teamcenter.rac.commands.open.open");
OpenCommand localOpenCommand = (OpenCommand) localRegistry.newInstanceForEx("openCommand",
new Object[] { AIFUtility.getActiveDesktop(), comp });
localOpenCommand.executeModeless();
} catch (Exception e) {
e.printStackTrace();
}
}
public static JButton getImageBtn(String iconName) {
ImageIcon icon = new ImageIcon(KUtil.class.getResource("/icons/" + iconName));
JButton btn = new JButton(icon);
btn.setPreferredSize(new Dimension(26, 26));
btn.setContentAreaFilled(true);
btn.setFocusPainted(false);
btn.setBorderPainted(true);
// btn.setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
return btn;
}
public static void info(Window dialog, String msg) {
MessageBox.post(dialog, msg, "", MessageBox.INFORMATION);
}
public static void warn(Window dialog, String msg) {
MessageBox.post(dialog, msg, "", MessageBox.WARNING);
}
public static void error(Window dialog, String msg) {
MessageBox.post(dialog, msg, "", MessageBox.ERROR);
}
public static void error(Window dialog, String msg, String title) {
MessageBox.post(dialog, msg, title, MessageBox.ERROR);
}
public static void showScrollDialog(Window dialog, String text, String title) {
if (dialog == null) {
dialog = UIUtilities.getCurrentModalDialog();
}
JTextArea textArea = new JTextArea(text);
textArea.setEditable(false);
JScrollPane scrollPane = new JScrollPane(textArea);
textArea.setLineWrap(true);
textArea.setWrapStyleWord(true);
scrollPane.setPreferredSize(new Dimension(500, 300));
JOptionPane.showMessageDialog(dialog, scrollPane, title, JOptionPane.INFORMATION_MESSAGE);
}
public static void showScrollDialogWithExport(Window dialog, String text, String title, String exportFileName) {
if (dialog == null) {
dialog = UIUtilities.getCurrentModalDialog();
}
JTextArea textArea = new JTextArea(text);
textArea.setEditable(false);
JScrollPane scrollPane = new JScrollPane(textArea);
textArea.setLineWrap(true);
textArea.setWrapStyleWord(true);
scrollPane.setPreferredSize(new Dimension(500, 300));
String yesOption = KLocale.getString("ok");
String exportOption = KLocale.getString("export");
int op = JOptionPane.showOptionDialog(dialog, scrollPane, title, JOptionPane.YES_NO_OPTION,
JOptionPane.INFORMATION_MESSAGE, null, new String[] { yesOption, exportOption }, yesOption);
if (op == 1) {
System.out.println("Export");
File saveFile = KUtil.chooseSaveFile(dialog, exportFileName, "txt");
if (saveFile != null) {
try {
BufferedWriter writer = new BufferedWriter(new FileWriter(saveFile, false));
writer.write(text);
writer.flush();
writer.close();
} catch (Exception e) {
e.printStackTrace();
MessageBox.post(dialog, e);
}
}
}
}
public static void errorSWT(Shell shell, String message, String title) {
showDialog(shell, message, title, SWT.ICON_ERROR);
}
public static void showDialog(Shell shell, String message, String title, int type) {
org.eclipse.swt.widgets.MessageBox dialog = new org.eclipse.swt.widgets.MessageBox(shell, SWT.OK | type);
dialog.setText(title);
dialog.setMessage(message);
dialog.open();
}
public static String[] getPrefVals(TCSession session, String prefName) throws Exception {
if (KUtil.isEmpty(prefName)) {
return null;
}
return session.getPreferenceService().getStringValues(prefName);
}
public static String getPrefVal(TCSession session, String prefName) throws Exception {
if (KUtil.isEmpty(prefName)) {
return null;
}
return session.getPreferenceService().getStringValue(prefName);
}
public static String getReg(Registry reg, String name) {
String val = reg.getString(name);
// System.out.println("Read REG: " + name + " = " + val);
return val;
}
// public static String getReg(String name) {
// return getReg(REG, name);
// }
public static void newRow(JPanel panel, Component comp, GridBagConstraints s, int width) {
newRow(panel, comp, s, width, 0);
}
public static void newRow(JPanel panel, Component comp, GridBagConstraints s, int width, double weightx) {
s.weightx = weightx;
s.gridwidth = width;
s.gridx = 0;
s.gridy++;
panel.add(comp, s);
}
public static void newRow(JDialog panel, Component comp, GridBagConstraints s, int width) {
s.weightx = 0;
s.gridwidth = width;
s.gridx = 0;
s.gridy++;
panel.add(comp, s);
}
public static void addCol(JPanel panel, Component comp, GridBagConstraints s, int width, double weightx) {
s.gridx++;
s.gridwidth = width;
s.weightx = weightx;
panel.add(comp, s);
}
public static TCComponentDataset getDataset(TCComponent rev, String dsType, String dsName, String rel)
throws Exception {
if (rev == null || KUtil.isEmpty(dsName)) {
return null;
}
rev.refresh();
TCComponent[] kids = rev.getRelatedComponents(rel);
for (TCComponent c : kids) {
if (c.getType().equals(dsType) && c.toString().equals(dsName)) {
return (TCComponentDataset) c;
}
}
return null;
}
public static List<TCComponentDataset> getDatasets(TCComponent rev, String dsType, String rel) throws Exception {
if (rev == null) {
return null;
}
rev.refresh();
List<TCComponentDataset> res = new ArrayList<TCComponentDataset>();
TCComponent[] kids = rev.getRelatedComponents(rel);
for (TCComponent c : kids) {
if (c.getType().equals(dsType)) {
res.add((TCComponentDataset) c);
}
}
return res;
}
public static List<TCComponent> getChildComponents(TCComponent rev, String dsType, String rel, String dsNamePrefix)
throws Exception {
if (rev == null) {
return null;
}
rev.refresh();
List<TCComponent> res = new ArrayList<TCComponent>();
TCComponent[] kids = rev.getRelatedComponents(rel);
for (TCComponent c : kids) {
if (c.getType().equals(dsType) && c.getProperty("object_name").startsWith(dsNamePrefix)) {
res.add(c);
}
}
return res;
}
public static List<TCComponent> getChildComponentsContainsStr(TCComponent rev, String dsType, String rel,
String dsNameSubStr) throws Exception {
if (rev == null) {
return null;
}
if (dsNameSubStr == null) {
dsNameSubStr = "";
}
rev.refresh();
List<TCComponent> res = new ArrayList<TCComponent>();
TCComponent[] kids = rev.getRelatedComponents(rel);
for (TCComponent c : kids) {
if (c.getType().equals(dsType) && c.getProperty("object_name").contains(dsNameSubStr)) {
res.add(c);
}
}
return res;
}
public static List<TCComponent> getChildComponents(TCComponent rev, String dsType, String rel) throws Exception {
if (rev == null) {
return null;
}
rev.refresh();
List<TCComponent> res = new ArrayList<TCComponent>();
TCComponent[] kids = rev.getRelatedComponents(rel);
for (TCComponent c : kids) {
if (c.getType().equals(dsType)) {
res.add(c);
}
}
return res;
}
public static TCComponentFolder getChildFolder(TCComponentFolder folder, String cFolderName) throws Exception {
if (folder == null || cFolderName == null) {
return null;
}
AIFComponentContext[] cc = folder.getChildren();
int len = KUtil.getLen(cc);
for (int i = 0; i < len; i++) {
InterfaceAIFComponent c = cc[i].getComponent();
if ((c instanceof TCComponentFolder) && cFolderName.equals(c.getProperty("object_name"))) {
return (TCComponentFolder) c;
}
}
return null;
}
public static TCComponentDataset uploadFile(TCSession session, TCComponent rev, File newFile, String dsName,
String dsTypeName, String refName, String rel) throws Exception {
TCComponentDataset ds = getDataset(rev, dsTypeName, dsName, rel);
if (ds == null) {
TCComponentDatasetType dsType = (TCComponentDatasetType) session.getTypeComponent(dsTypeName);
ds = dsType.create(dsName, "", dsTypeName);
if (rev != null) {
rev.add(rel, ds);
rev.refresh();
}
}
setDsFile(ds, refName, newFile);
return ds;
}
public static void setDsFile(TCComponentDataset ds, String refName, File newFile) throws Exception {
if (ds.isCheckedOut()) {
throw new Exception(String.format(KLocale.getString("uploadfilewhencheckout.ERROR1"), ds.toString()));
}
String[] refs = new String[] { refName };
String[] files = new String[] { newFile.getAbsolutePath() };
ds.setFiles(files, refs);
// ds.save();
ds.refresh();
}
public static void setDsFile2(TCComponentDataset ds, String refName, File newFile) throws Exception {
String[] refs = new String[] { refName };
String[] files = new String[] { newFile.getAbsolutePath() };
ds.setFiles(files, refs);
// ds.save();
ds.refresh();
}
public static boolean isEmpty(String str) {
return str == null || "".equals(str.trim());
}
public static int inArray(int target, int[] arr) {
int len = arr == null ? 0 : arr.length;
for (int i = 0; i < len; i++) {
if (target == arr[i]) {
return i;
}
}
return -1;
}
public static boolean inArray(String str, String arr, String splitter) {
if (KUtil.isEmpty(arr) || KUtil.isEmpty(splitter)) {
return false;
}
if (KUtil.isEmpty(str)) {
return true;
}
return inArray(str, arr.split(splitter)) >= 0;
}
public static int inArray(String target, String[] arr) {
int len = arr == null ? 0 : arr.length;
for (int i = 0; i < len; i++) {
if (target.equals(arr[i])) {
return i;
}
}
return -1;
}
public static int getNextColNumber(int currentIndex, int[] skipColIndex, int cols) {
int res = currentIndex;
for (int i = 0; i < cols; i++) {
res++;
if (inArray(res, skipColIndex) >= 0) {
i--;
}
}
return res;
}
public static <E> List<List<E>> groupList(List<E> originList, int maxCount, int gap, E gapFiller) {
List<List<E>> res = new ArrayList<List<E>>();
int cnt = originList == null ? 0 : originList.size();
List<E> list = new ArrayList<E>();
for (int i = 0; i < cnt; i++) {
list.add(originList.get(i));
if (i != cnt - 1) {// add gap
for (int j = 0; j < gap; j++) {
list.add(gapFiller);
}
}
}
cnt = list == null ? 0 : list.size();
if (maxCount <= 0) {
maxCount = cnt;
}
int pageCounter = 0;
List<E> cList = new ArrayList<E>();
res.add(cList);
for (int i = 0; i < cnt; i++) {
if (pageCounter == maxCount) {
cList = new ArrayList<>();
res.add(cList);
pageCounter = 0;
}
if (cList != null) {
E item = list.get(i);
if (cList.size() == 0 && item == gapFiller) {
continue;
}
cList.add(list.get(i));
pageCounter++;
}
}
list.clear();
list = null;
return res;
}
public static <E> List<List<E>> groupListWithGapAdded(List<E> list, int maxCount, E gapFiller) {
List<List<E>> res = new ArrayList<List<E>>();
int cnt = list == null ? 0 : list.size();
if (maxCount <= 0) {
maxCount = cnt;
}
int pageCounter = 0;
List<E> cList = new ArrayList<E>();
res.add(cList);
for (int i = 0; i < cnt; i++) {
if (pageCounter == maxCount) {
cList = new ArrayList<>();
res.add(cList);
pageCounter = 0;
}
if (cList != null) {
E item = list.get(i);
if (cList.size() == 0 && item == gapFiller) {
continue;
}
cList.add(list.get(i));
pageCounter++;
}
}
list.clear();
list = null;
return res;
}
public static <E> List<List<Map<String, E>>> groupList(List<Map<String, E>> originList, int maxCount, int gap,
Map<String, E> gapFiller, String gapKey) {
List<List<Map<String, E>>> res = new ArrayList<List<Map<String, E>>>();
int cnt = originList == null ? 0 : originList.size();
List<Map<String, E>> list = new ArrayList<Map<String, E>>();
boolean addGap = false;
for (int i = 0; i < cnt; i++) {
Map<String, E> item = originList.get(i);
list.add(item);
if (i != cnt - 1) {// add gap
Map<String, E> nextItem = originList.get(i + 1);
addGap = KUtil.isEmpty(gapKey) || (nextItem != null && nextItem.containsKey(gapKey));
for (int j = 0; j < gap; j++) {
if (addGap) {
list.add(gapFiller);
}
}
}
}
cnt = list == null ? 0 : list.size();
if (maxCount <= 0) {
maxCount = cnt;
}
int pageCounter = 0;
List<Map<String, E>> cList = new ArrayList<Map<String, E>>();
res.add(cList);
for (int i = 0; i < cnt; i++) {
if (pageCounter == maxCount) {
cList = new ArrayList<>();
res.add(cList);
pageCounter = 0;
}
if (cList != null) {
Map<String, E> item = list.get(i);
if (cList.size() == 0 && item == gapFiller) {
continue;
}
cList.add(list.get(i));
pageCounter++;
}
}
list.clear();
list = null;
return res;
}
public static File getFileFromDataset(TCSession session, String dsType, String uid, String prefName)
throws Exception {
TCComponent comp = null;
try {
comp = session.stringToComponent(uid);
} catch (Exception e) {
e.printStackTrace();
}
if (comp == null) {
throw new Exception(String.format(KLocale.getString("dsuidinpref.ERROR1"), prefName));
}
String type = comp.getType();
System.out.println("Dataset: " + comp + "|Type: " + type);
if (!dsType.equals(type)) {
throw new Exception(String.format(KLocale.getString("dsuidinpref.ERROR1"), prefName));
}
TCComponentDataset tDataset = (TCComponentDataset) comp;
return getDatasetFile(tDataset);
}
public static File getDatasetFile(TCComponentDataset dataset) throws Exception {
File[] files = dataset.getFiles("", System.getenv("TEMP"));
if (files == null || files.length == 0) {
throw new Exception(String.format(KLocale.getString("norefindataset.ERROR1"), dataset.toString()));
}
System.out.println(">> Download file (" + files.length + "): " + files[0].getAbsolutePath());
return files[0];
}
public static File getDatasetFile(File dir, TCComponentDataset dataset) throws Exception {
if (dir == null || !dir.isDirectory()) {
throw new Exception("Directory not found.");
}
File[] files = dataset.getFiles("", dir.getAbsolutePath());
if (files == null || files.length == 0) {
throw new Exception(String.format(KLocale.getString("norefindataset.ERROR1"), dataset.toString()));
}
System.out.println(">> Download file (" + files.length + "): " + files[0].getAbsolutePath());
return files[0];
}
public static String[] getStringArrayProp(TCComponentForm form, String propName) throws Exception {
if (form == null) {
return null;
}
TCProperty prop = form.getFormTCProperty(propName);
if (prop == null) {
throw new java.lang.Exception(
String.format(KLocale.getString("nopropintype.ERROR2"), form.getDisplayType(), propName));
}
return prop.getStringArrayValue();
}
public static File chooseDirectory(Component parent) {
FileSystemView fsv = FileSystemView.getFileSystemView();
String deskPath = fsv.getHomeDirectory().getPath();
JFileChooser fileChooser = new JFileChooser();
fileChooser.setCurrentDirectory(new File(deskPath));
fileChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
int state = fileChooser.showOpenDialog(parent);
if (state == 1) {
return null;
}
return fileChooser.getSelectedFile();
}
public static boolean addReleaseStatus(TCSession session, String uid, String status) throws Exception {
TCUserService userservice = session.getUserService();
Object[] obj = new Object[2];
obj[0] = uid;
obj[1] = status;
Object res = userservice.call("K_add_release_status", obj);
if (res != null && res.toString().equalsIgnoreCase("true")) {
return true;
}
return false;
}
/**
* <20><><EFBFBD><EFBFBD>ֻ<EFBFBD><D6BB><EFBFBD><EFBFBD><EFBFBD>Ե<EFBFBD>ֵ
*
* @param session
* @param propName
* @param propValue
* @param comp
* @return
* @throws Exception
*/
public static boolean setPropValue(TCSession session, String propName, String propValue, TCComponent comp)
throws Exception {
TCUserService userservice = session.getUserService();
Object[] obj = new Object[3];
obj[0] = propName;
obj[1] = propValue;
obj[2] = comp;
Object res = userservice.call("Connor_Set_Prop_Value", obj);
if (res != null && res.toString().equalsIgnoreCase("true")) {
return true;
}
return false;
}
public static File chooseFile(Component parent) {
FileSystemView fsv = FileSystemView.getFileSystemView();
String deskPath = fsv.getHomeDirectory().getPath();
JFileChooser fileChooser = new JFileChooser();
fileChooser.setCurrentDirectory(new File(deskPath));
fileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
FileNameExtensionFilter filter = new FileNameExtensionFilter("*.xlsx", "xlsx");
fileChooser.setFileFilter(filter);
int state = fileChooser.showOpenDialog(parent);
if (state == 1) {
return null;
}
return fileChooser.getSelectedFile();
}
public static File chooseSaveFile(Component parent, String defaultFile) {
FileSystemView fsv = FileSystemView.getFileSystemView();
String deskPath = fsv.getHomeDirectory().getPath();
JFileChooser fileChooser = new JFileChooser();
fileChooser.setCurrentDirectory(new File(deskPath));
fileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
FileNameExtensionFilter filter = new FileNameExtensionFilter("*.xlsx", "xlsx");
fileChooser.setFileFilter(filter);
fileChooser.setSelectedFile(new File(defaultFile));
int state = fileChooser.showSaveDialog(parent);
if (state == 1) {
return null;
}
return fileChooser.getSelectedFile();
}
public static File chooseSaveFile(Component parent, String defaultFile, String ext) {
FileSystemView fsv = FileSystemView.getFileSystemView();
String deskPath = fsv.getHomeDirectory().getPath();
JFileChooser fileChooser = new JFileChooser();
fileChooser.setCurrentDirectory(new File(deskPath));
fileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
if (!KUtil.isEmpty(ext)) {
FileNameExtensionFilter filter = new FileNameExtensionFilter("*." + ext, ext);
fileChooser.setFileFilter(filter);
}
fileChooser.setSelectedFile(new File(defaultFile));
int state = fileChooser.showSaveDialog(parent);
if (state == 1) {
return null;
}
return fileChooser.getSelectedFile();
}
public static File getNewFile(File folder, String fileName, String ext) {
File file = new File(folder.getAbsolutePath() + "\\" + fileName + "." + ext);
int index = 1;
while (file.exists()) {
file = new File(folder.getAbsolutePath() + "\\" + fileName + "(" + (index++) + ")." + ext);
}
return file;
}
public static String getDateStr(Date date, String format) {
String res = "";
try {
SimpleDateFormat sdf = new SimpleDateFormat(format);
res = sdf.format(date);
} catch (Exception e) {
e.printStackTrace();
}
return res;
}
public static TCComponentContextList query(TCSession session, String queryName, Map<String, String> fields)
throws Exception {
String[] keys = fields.keySet().toArray(new String[] {});
String[] vals = fields.values().toArray(new String[] {});
return query(session, queryName, keys, vals);
}
public static TCComponentContextList query(TCSession session, String queryName, String[] keys, String[] vals)
throws Exception {
System.out.println("Query: " + queryName);
System.out.println("keys = " + Arrays.toString(keys));
System.out.println("vals = " + Arrays.toString(vals));
TCComponentQueryType queryType = (TCComponentQueryType) session.getTypeComponent("ImanQuery");
TCComponentQuery query = (TCComponentQuery) queryType.find(queryName);
if (query == null) {
throw new Exception(String.format(KLocale.getString("querynotexist.ERROR1"), queryName));
}
queryType.clearCache();
query.clearCache();
query.refresh();
return query.getExecuteResultsList(keys, vals);
}
public static TCComponent[] query2(TCSession session, String queryName, String[] keys, String[] vals)
throws Exception {
System.out.println("Query: " + queryName);
System.out.println("keys = " + Arrays.toString(keys));
System.out.println("vals = " + Arrays.toString(vals));
TCComponentQueryType queryType = (TCComponentQueryType) session.getTypeComponent("ImanQuery");
TCComponentQuery query = (TCComponentQuery) queryType.find(queryName);
if (query == null) {
throw new Exception(String.format(KLocale.getString("querynotexist.ERROR1"), queryName));
}
queryType.clearCache();
query.clearCache();
query.refresh();
return query.execute(keys, vals);
}
public static TCComponentContextList combineContext(TCSession session, TCComponentQuery query,
TCComponentContextList... contexts) throws Exception {
Class<TCComponentContextList> c = TCComponentContextList.class;
Field f1 = c.getDeclaredField("m_compUids");
f1.setAccessible(true);
List<String> compUids = new ArrayList<>();
for (TCComponentContextList cc : contexts) {
String[] u1 = (String[]) f1.get(cc);
System.out.println(Arrays.toString(u1));
compUids.addAll(Arrays.asList(u1));
}
Constructor<?> constructor = c.getDeclaredConstructor(TCComponentManager.class, TCComponent.class,
String[].class, String[].class, String.class);
constructor.setAccessible(true);
TCComponentContextList res = (TCComponentContextList) constructor.newInstance(new TCComponentManager(session),
query, compUids.toArray(new String[] {}), null, "");
return res;
}
public static int getLen(Object[] arr) {
return arr == null ? 0 : arr.length;
}
public static String getValueInArray(String[] arr, int index) {
int len = arr == null ? 0 : arr.length;
if (index >= len) {
return "";
}
return arr[index];
}
public static String getValueInArray(String arrStr, int index, String splitter) {
if (KUtil.isEmpty(arrStr)) {
return "";
}
String[] split = arrStr.split(splitter, -1);
int len = getLen(split);
if (len > index && index >= 0) {
return split[index];
}
return "";
}
public static String getTypeNames(TCSession session, Object[] types) {
int len = types == null ? 0 : types.length;
if (len == 0) {
return "";
}
String[] names = new String[len];
for (int i = 0; i < len; i++) {
try {
if ("TC_Project".equals(types[i].toString())) {
names[i] = KLocale.getString("project");
} else {
names[i] = session.getTypeComponent(types[i].toString()).getDisplayTypeName();
}
} catch (Exception e) {
e.printStackTrace();
}
if (names[i] == null) {
names[i] = types[i].toString();
}
}
return Arrays.toString(names);
}
public static String getTypeName(TCSession session, String type) {
if (KUtil.isEmpty(type)) {
return "";
}
try {
if ("TC_Project".equals(type)) {
return KLocale.getString("project");
} else {
return session.getTypeComponent(type).getDisplayTypeName();
}
} catch (Exception e) {
e.printStackTrace();
}
return type;
}
public static boolean isReleased(TCComponent comp) throws Exception {
TCComponent[] status = comp.getReferenceListProperty("release_status_list");
if (status == null || status.length == 0) {
return false;
}
return true;
}
public static TCComponentUser getUserFromStr(String str) throws Exception {
System.out.println("Search User: " + str);
if (KUtil.isEmpty(str)) {
return null;
}
int ind1 = str.lastIndexOf('(');
int ind2 = str.lastIndexOf(')');
TCComponentUser user = null;
if (ind1 > 0 && ind2 > ind1) {
String userId = str.substring(ind1 + 1, ind2);
if (KUtil.isEmpty(userId)) {
System.out.println("No Id between '(' and ')'");
user = null;
} else {
user = queryUserById(userId);
}
} else {
user = queryUserById(str);
if (user == null) {
user = queryUserByName(str);
}
}
return user;
}
public static TCComponentUser queryUserById(String userId) throws Exception {
System.out.println("Search User By Id: " + userId);
if (KUtil.isEmpty(userId)) {
return null;
}
String queryName = "Admin - Employee Information";
String[] keys = new String[] { KUtil.getText("UserId") };
String[] vals = new String[] { userId };
TCComponentContextList res = KUtil.query(KUtil.session, queryName, keys, vals);
if (res.getListCount() == 0) {
return null;
}
if (res.getListCount() > 1) {
throw new Exception(String.format(KLocale.getString("multiuserbyid.ERROR1"), userId));
}
return (TCComponentUser) res.get(0).getComponent();
}
public static TCComponentUser queryUserByName(String userName) throws Exception {
System.out.println("Search User By Name: " + userName);
if (KUtil.isEmpty(userName)) {
return null;
}
String queryName = "Admin - Employee Information";
String[] keys = new String[] { KUtil.getText("PersonName") };
String[] vals = new String[] { userName };
TCComponentContextList res = KUtil.query(KUtil.session, queryName, keys, vals);
if (res.getListCount() == 0) {
return null;
}
if (res.getListCount() > 1) {
throw new Exception(String.format(KLocale.getString("multiuserbyname.ERROR1"), userName));
}
return (TCComponentUser) res.get(0).getComponent();
}
public static TCComponent[] getGroupMember(List<TCComponentUser> privMembers) throws Exception {
if (privMembers == null) {
return null;
}
List<TCComponent> res = new ArrayList<>();
for (TCComponentUser user : privMembers) {
TCComponentGroupMember[] gms = user.getGroupMembers();
int len = KUtil.getLen(gms);
for (int i = 0; i < len; i++) {
TCComponentGroupMember gm = gms[i];
if (KUtil.isEmpty(gm.toString())) {
continue;
}
/*
* if(!gm.isActive()) { System.out.println("<22><><EFBFBD>Ա<EFBFBD>ǻ<C7BB><EEB6AF><EFBFBD>?"+gm); continue; }
*/
if (!res.contains(gm)) {
System.out.println("Add Group Member: " + gm);
res.add(gm);
} else {
System.out.println("Added: " + gm);
}
}
}
return res.toArray(new TCComponent[] {});
}
public static int compareWBS(String wbsCode, String wbsCode2) {
if (KUtil.isEmpty(wbsCode) && KUtil.isEmpty(wbsCode2)) {
return 0;
}
if (KUtil.isEmpty(wbsCode)) {
return -1;
}
if (KUtil.isEmpty(wbsCode2)) {
return 1;
}
String[] a = wbsCode.split("\\.");
String[] b = wbsCode2.split("\\.");
int lenA = a.length;
int lenB = b.length;
for (int i = 0; i < lenA && i < lenB; i++) {
String aa = a[i];
String bb = b[i];
int ai = 0;
int bi = 0;
try {
ai = Integer.parseInt(aa);
bi = Integer.parseInt(bb);
} catch (Exception e) {
e.printStackTrace();
}
if (ai != bi) {
return ai - bi;
}
}
return lenA - lenB;
}
public static TCComponentListOfValues getLov(String lovName) {
TCComponentListOfValuesType lovType;
try {
lovType = (TCComponentListOfValuesType) session.getTypeComponent("ListOfValues");
TCComponentListOfValues[] lov = lovType.find(lovName);
if (lov.length > 0)
return lov[0];
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
public static String[] getDynamicLOV(String s) {
TCComponentListOfValues lov = null;
List<String> lovDisplayValueList = new ArrayList<>();
lovDisplayValueList.add("");
List<String> lovValueList = new ArrayList<>();
lov = TCComponentListOfValuesType.findLOVByName(s);
try {
if ("Fnd0ListOfValuesDynamic".equals(lov.getProperty("lov_type"))) {
LOVService lovService = LOVService.getService(RACUIUtil.getTCSession());
InitialLovData input = new InitialLovData();
LovFilterData filter = new LovFilterData();
filter.sortPropertyName = "object_name";
filter.order = 1;
filter.numberToReturn = 100;
filter.maxResults = 100;
input.lov = lov;
input.filterData = filter;
LOVSearchResults result = lovService.getInitialLOVValues(input);
StringBuffer sb = new StringBuffer();
sb.append(">>");
for (LOVValueRow row : result.lovValues) {
Map<String, String[]> map = row.propDisplayValues;
Map<String, String[]> realmap = row.propInternalValues;
for (String key : map.keySet()) {
sb.append("UID:" + row.uid + ",key:" + key + "<22><>value:" + map.get(key)[0]);
sb.append("\n");
lovDisplayValueList.add(map.get(key)[0]);
lovValueList.add(realmap.get(key)[0]);
}
}
}
} catch (TCException e) {
e.printStackTrace();
}
return lovDisplayValueList.toArray(new String[lovDisplayValueList.size()]);
}
public static String getLovValue(TCComponentListOfValues lov, String str) throws Exception {
return getLovValue(lov, str, true);
}
public static String getLovValue(TCComponentListOfValues lov, String str, boolean translate) throws Exception {
if (lov == null || KUtil.isEmpty(str)) {
return str;
}
if (translate) {
String prefName = "LOV_TRANS_" + lov.getStringProperty(TCComponentListOfValues.PROP_LOV_NAME);
String[] prefVals = KUtil.getPrefVals(KUtil.session, prefName);
int len = KUtil.getLen(prefVals);
for (int i = 0; i < len; i++) {
String pref = prefVals[i];
int ind = pref.indexOf('=');
if (ind > 0) {
String realVal = pref.substring(0, ind);
String disVal = pref.substring(ind + 1);
if (str.equals(realVal) || str.equals(disVal)) {
return realVal;
}
}
}
}
ListOfValuesInfo info = lov.getListOfValues();
if (info == null) {
return str;
}
List<LovValue> v = info.getValues();
int size = v == null ? 0 : v.size();
for (int i = 0; i < size; i++) {
LovValue vv = v.get(i);
String realValue = vv.getValue() == null ? "" : vv.getValue().toString();
if (str.equals(realValue)) {
return str;
}
String disValue = vv.getDisplayValue();
if (str.equals(disValue)) {
return realValue;
}
}
throw new Exception(String.format(KLocale.getString("valuenotinlov.ERROR2"), lov.toString(), str));
}
public static String getLovDisplayableValue(TCComponentListOfValues lov, String str) throws Exception {
if (lov == null || KUtil.isEmpty(str)) {
return str;
}
ListOfValuesInfo info = lov.getListOfValues();
if (info == null) {
return str;
}
List<LovValue> v = info.getValues();
int size = v == null ? 0 : v.size();
for (int i = 0; i < size; i++) {
LovValue vv = v.get(i);
String realValue = vv.getValue() == null ? "" : vv.getValue().toString();
if (str.equals(realValue)) {
return vv.getDisplayValue();
}
String disValue = vv.getDisplayValue();
if (str.equals(disValue)) {
return str;
}
}
throw new Exception(String.format(KLocale.getString("valuenotinlov.ERROR2"), lov.toString(), str));
}
public static void openFile(File file) {
try {
if (file != null && file.exists()) {
Runtime.getRuntime().exec("cmd /c start /b call \"" + file.getAbsolutePath() + "\"");
}
} catch (Exception e) {
e.printStackTrace();
MessageBox.post(e);
}
}
public static void importDataset(TCComponent parent, String rel, File f, String dsType, String refName)
throws Exception {
if (f == null || !f.exists() || KUtil.isEmpty(dsType) || KUtil.isEmpty(refName)) {
return;
}
TCComponentDatasetType datasetType = (TCComponentDatasetType) session.getTypeComponent(dsType);
TCComponentDataset dataset = datasetType.create(f.getName(), "", dsType);
String paths[] = { f.getAbsolutePath() };
String refs[] = { refName };
dataset.setFiles(paths, refs);
if (parent != null && !KUtil.isEmpty(rel)) {
parent.add(rel, dataset);
}
}
public static void initPropMap(String propConfig, String value, Map<String, String> itemPropMap,
Map<String, String> itemMasterPropMap, Map<String, String> revPropMap, Map<String, String> revMasterPropMap)
throws Exception {
initPropMap(propConfig, value, itemPropMap, itemMasterPropMap, revPropMap, revMasterPropMap, null);
}
public static void initPropMap(String propConfig, String value, Map<String, String> itemPropMap,
Map<String, String> itemMasterPropMap, Map<String, String> revPropMap, Map<String, String> revMasterPropMap,
Map<String, String> bomlinePropMap) throws Exception {
if (KUtil.isEmpty(propConfig)) {
return;
}
String propFrom = null, propName = null;
String[] split = propConfig.split("\\.");
if (KUtil.getLen(split) == 2) {
propFrom = split[0].trim().toUpperCase();
propName = split[1].trim();
}
if (KUtil.isEmpty(propFrom) || KUtil.isEmpty(propName)) {
return;
}
Map<String, String> target;
if ("ITEM".equals(propFrom)) {
target = itemPropMap;
System.out.println(">> ITEM PROP: " + propName + " = " + value);
} else if ("REV".equals(propFrom)) {
System.out.println(">> REV PROP: " + propName + " = " + value);
target = revPropMap;
} else if ("ITEMMASTER".equals(propFrom)) {
System.out.println(">> ITEMMASTER PROP: " + propName + " = " + value);
target = itemMasterPropMap;
} else if ("REVMASTER".equals(propFrom)) {
System.out.println(">> REVMASTER PROP: " + propName + " = " + value);
target = revMasterPropMap;
} else if ("BOMLINE".equals(propFrom)) {
System.out.println(">> BOMLINE PROP: " + propName + " = " + value);
target = bomlinePropMap;
} else {
throw new Exception(String.format(KLocale.getString("proplocationnotdefined.ERROR1"), propFrom));
}
if (target == null) {
return;
}
target.put(propName, value);
}
public static String getMarkedPropValue(String config, Map<String, TCComponent> markedComponents) throws Exception {
return getMarkedPropValue(config, markedComponents, null);
}
public static String getMarkedPropValue(String config, Map<String, TCComponent> markedComponents,
Map<TCComponent, List<TCComponent>> relatedComponents) throws Exception {
if (markedComponents == null || KUtil.isEmpty(config)) {
return "";
}
StringBuilder res = new StringBuilder();
String[] propConfigSplit = config.split("\\+");
int len = KUtil.getLen(propConfigSplit);
for (int i = 0; i < len; i++) {
String propConfig = propConfigSplit[i];
String propFrom = null, propName = null;
String defaultValue = "";
String[] split = propConfig.split("\\.");
if (KUtil.getLen(split) >= 2) {
propFrom = split[0].trim().toUpperCase();
propName = split[1].trim();
}
if (KUtil.getLen(split) >= 3) {
defaultValue = split[2].trim();
}
if (KUtil.isEmpty(propFrom) || KUtil.isEmpty(propName)) {
if (propConfig.contains("\\n")) {
propConfig = propConfig.replace("\\n", "\n");
}
res.append(propConfig);
continue;
}
if (!markedComponents.containsKey(propFrom)) {
if (propFrom.startsWith("T")) {
return "";
}
continue;
}
TCComponent comp = markedComponents.get(propFrom);
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD>λ<EFBFBD><CEBB>.<2E><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>-<2D><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>[-<2D><><EFBFBD>ӷ<EFBFBD>]
int ind = propName.indexOf('-');
if (ind > 0) {
String tableProp = propName.substring(0, ind).trim();
String tableRowProp = propName.substring(ind + 1).trim();
if (!KUtil.isEmpty(tableProp) && !KUtil.isEmpty(tableRowProp)) {
TCProperty prop = comp.getTCProperty(tableProp.trim());
if (prop == null) {
throw new Exception(String.format(KLocale.getString("propnotdefinedintype.ERROR2"),
comp.getType(), propName));
}
String rowSplitter = "#ROW#";
ind = tableRowProp.indexOf('-');
if (ind > 0) {
rowSplitter = tableRowProp.substring(ind + 1);
tableRowProp = tableRowProp.substring(0, ind);
}
TCComponent[] tableRows = prop.getReferenceValueArray();
int rowCnt = KUtil.getLen(tableRows);
String[] value = new String[rowCnt];
for (int j = 0; j < rowCnt; j++) {
value[j] = tableRows[j].getPropertyDisplayableValue(tableRowProp);
}
res.append(String.join(rowSplitter, value));
}
continue;
}
TCProperty prop = comp.getTCProperty(propName.trim());
if (prop == null) {
throw new Exception(
String.format(KLocale.getString("propnotdefinedintype.ERROR2"), comp.getType(), propName));
}
String value = prop.getDisplayableValue();
if ("NAME".equalsIgnoreCase(defaultValue)) {
value = prop.getPropertyDisplayName();
} else if (value == null || "".equals(value)) {
value = defaultValue;
}
res.append(value);
}
return res.toString();
}
public static TCComponent getLatestComponent(List<TCComponent> comps) {
int size = comps == null ? 0 : comps.size();
if (size == 0) {
return null;
}
if (size == 1) {
return comps.get(0);
}
TCComponent res = comps.get(0);
try {
Date maxDate = res.getDateProperty("creation_date");
for (int i = 1; i < size; i++) {
TCComponent temp = comps.get(i);
Date tempDate = temp.getDateProperty("creation_date");
if (tempDate.after(maxDate)) {
maxDate = tempDate;
res = temp;
}
}
} catch (Exception e) {
e.printStackTrace();
}
return res;
}
public static TCComponentType[] getComponentTypes(String itemTypeName) throws Exception {
TCComponentItemType itemType = null;
try {
itemType = (TCComponentItemType) session.getTypeComponent(itemTypeName);
} catch (Exception e) {
e.printStackTrace();
}
if (itemType == null) {
throw new Exception(String.format(KLocale.getString("typenotfound.ERROR1"), itemTypeName));
}
TCComponentItemRevisionType revType = itemType.getItemRevisionType();
if (revType == null) {
throw new Exception(String.format(KLocale.getString("typenotfound.ERROR1"), itemTypeName + "Revision"));
}
TCComponentType itemMasterType = null;
try {
itemMasterType = session.getTypeComponent(itemTypeName + "Master");
} catch (Exception e) {
e.printStackTrace();
}
if (itemMasterType == null) {
try {
itemMasterType = session.getTypeComponent(itemTypeName + " Master");
} catch (Exception e) {
e.printStackTrace();
}
}
if (itemMasterType == null) {
throw new Exception(String.format(KLocale.getString("typenotfound.ERROR1"), itemTypeName + "Master"));
}
TCComponentType revMasterType = null;
try {
revMasterType = session.getTypeComponent(revType.getTypeName() + "Master");
} catch (Exception e) {
e.printStackTrace();
}
if (revMasterType == null) {
try {
revMasterType = session.getTypeComponent(revType.getTypeName() + " Master");
} catch (Exception e) {
e.printStackTrace();
}
}
if (revMasterType == null) {
throw new Exception(
String.format(KLocale.getString("typenotfound.ERROR1"), revType.getTypeName() + "Master"));
}
return new TCComponentType[] { itemType, revType, itemMasterType, revMasterType };
}
public static String getPropertyDisplayName(TCComponentType type, String propName) throws Exception {
if (type == null || KUtil.isEmpty(propName)) {
return propName;
}
TCPropertyDescriptor desc = type.getPropDesc(propName);
if (desc == null) {
throw new Exception(String.format(KLocale.getString("propnotdefinedintype.ERROR2"),
type.getDisplayTypeName(), propName));
}
return desc.getDisplayName();
}
public static String getConfigPropValue(TCComponentItemRevision rev, String propConfigStr) throws Exception {
if (rev == null || KUtil.isEmpty(propConfigStr)) {
return "";
}
StringBuilder res = new StringBuilder();
String[] propConfigSplit = propConfigStr.split("\\+");
int len = KUtil.getLen(propConfigSplit);
for (int i = 0; i < len; i++) {
String propConfig = propConfigSplit[i];
String propFrom = null, propName = null;
String[] split = propConfig.split("\\.");
if (KUtil.getLen(split) == 2) {
propFrom = split[0].trim().toUpperCase();
propName = split[1].trim();
}
if (KUtil.isEmpty(propFrom) || KUtil.isEmpty(propName)) {
res.append(propConfig);
continue;
}
TCComponent target;
if ("ITEM".equals(propFrom)) {
target = rev.getItem();
} else if ("REV".equals(propFrom)) {
target = rev;
} else if ("ITEMMASTER".equals(propFrom)) {
target = rev.getItem().getRelatedComponent("IMAN_master_form");
} else if ("REVMASTER".equals(propFrom)) {
target = rev.getRelatedComponent("IMAN_master_form_rev");
} else {
throw new Exception(String.format(KLocale.getString("proplocationnotdefined.ERROR1"), propFrom));
}
TCProperty prop = target.getTCProperty(propName.trim());
if (prop == null) {
throw new Exception(
String.format(KLocale.getString("propnotdefinedintype.ERROR2"), target.getType(), propName));
}
res.append(prop.getStringValue());
}
return res.toString();
}
public static String getConfigPropDisplayableValue(TCComponentItemRevision rev, String propConfigStr)
throws Exception {
if (rev == null || KUtil.isEmpty(propConfigStr)) {
return "";
}
StringBuilder res = new StringBuilder();
String[] propConfigSplit = propConfigStr.split("\\+");
int len = KUtil.getLen(propConfigSplit);
for (int i = 0; i < len; i++) {
String propConfig = propConfigSplit[i];
String propFrom = null, propName = null;
String[] split = propConfig.split("\\.");
if (KUtil.getLen(split) == 2) {
propFrom = split[0].trim().toUpperCase();
propName = split[1].trim();
}
if (KUtil.isEmpty(propFrom) || KUtil.isEmpty(propName)) {
res.append(propConfig);
continue;
}
TCComponent target;
if ("ITEM".equals(propFrom)) {
target = rev.getItem();
} else if ("REV".equals(propFrom)) {
target = rev;
} else if ("ITEMMASTER".equals(propFrom)) {
target = rev.getItem().getRelatedComponent("IMAN_master_form");
} else if ("REVMASTER".equals(propFrom)) {
target = rev.getRelatedComponent("IMAN_master_form_rev");
} else {
throw new Exception(String.format(KLocale.getString("proplocationnotdefined.ERROR1"), propFrom));
}
TCProperty prop = target.getTCProperty(propName.trim());
if (prop == null) {
throw new Exception(
String.format(KLocale.getString("propnotdefinedintype.ERROR2"), target.getType(), propName));
}
res.append(prop.getDisplayableValue());
}
return res.toString();
}
public static void removeAllParents(DataManagementService dm, TCComponent comp) throws Exception {
comp.refresh();
System.out.println("Remove from parent: " + comp);
WhereReferencedResponse refResp = dm.whereReferenced(new TCComponent[] { comp }, 1);
KUtil.throwServiceDataError(refResp.serviceData);
int len = KUtil.getLen(refResp.output);
List<Relationship> datas = new ArrayList<Relationship>();
for (int i = 0; i < len; i++) {
WhereReferencedOutput ref = refResp.output[i];
int cnt = KUtil.getLen(ref.info);
for (int j = 0; j < cnt; j++) {
WhereReferencedInfo info = ref.info[j];
Relationship data = new Relationship();
data.primaryObject = info.referencer;
data.secondaryObject = comp;
data.relationType = info.relation;
System.out.println(">> " + info.relation + " | " + info.referencer);
datas.add(data);
}
}
ServiceData resp = dm.deleteRelations(datas.toArray(new Relationship[] {}));
KUtil.throwServiceDataError(resp);
}
public static TCComponent newTableRow(DataManagementService dmService, String type,
Map<String, String> rowStringProps, Map<String, Calendar> rowDateProps) throws Exception {
CreateIn rowIn = new CreateIn();
CreateInput rowInput = new CreateInput();
rowInput.boName = type;
if (rowStringProps != null) {
rowInput.stringProps = rowStringProps;
}
if (rowDateProps != null) {
rowInput.dateProps = rowDateProps;
}
rowIn.data = rowInput;
CreateResponse res = dmService.createObjects(new CreateIn[] { rowIn });
KUtil.throwServiceDataError(res.serviceData);
if (res.serviceData.sizeOfCreatedObjects() > 0) {
return res.serviceData.getCreatedObject(0);
}
return null;
}
public static Date addDay(Date day, int cnt) {
if (day == null) {
return null;
}
Calendar c = Calendar.getInstance();
c.setTime(day);
c.add(Calendar.DATE, cnt);
return c.getTime();
}
public static Date calTime(TCCalendar calendar, Date date, int minutes) {
if (calendar == null || date == null) {
return null;
}
int diff = minutes > 0 ? 1 : -1;
if (minutes < 0) {
minutes = -minutes;
}
Calendar c = Calendar.getInstance();
c.setTime(date);
int counter = 0;
while (counter < minutes) {
counter += calendar.getMinutesOnDay(c);
c.add(Calendar.DATE, diff);
}
return c.getTime();
}
public static int getMinutesBetween(TCCalendar calendar, Date start, Date end) {
if (calendar == null || start == null || end == null) {
return 0;
}
Calendar c = Calendar.getInstance();
c.setTime(start);
int res = 0;
while (c.getTime().before(end)) {
res += calendar.getMinutesOnDay(c);
// System.out.println(calendar.getMinutesOnDay(c)+" > "+c.getTime());
c.add(Calendar.DATE, 1);
}
return res;
}
public static TCComponentTCCalendar getScheduleCalendar(TCComponentSchedule schedule) throws Exception {
if (schedule == null) {
return null;
}
return CalendarHelper.getScheduleCalendar(schedule, session);
}
public static void dealSpecialModelValue(ArrayList<Integer> specialList, String prefName, String prop, int ind) {
int index = 0;
try {
String[] prefVals = KUtil.getPrefVals(session, prefName);
String puid = prefVals[ind];
TCComponent component = session.stringToComponent(puid);
if (component instanceof TCComponentForm) {
TCComponentForm form = (TCComponentForm) component;
TCComponent[] tables = form.getReferenceListProperty("ld6_ChangeTable");
for (int j = 0; j < tables.length; j++) {
String change = tables[j].getStringProperty(prop);
System.out.println("change======================"+change);
if (change.equals("<22><>")) {
System.out.println("jjj==="+j);
specialList.add(j);
}
}
}
//
// Set<Entry<String,ArrayList<String>>> entrySet = map.entrySet();
// for (Entry<String, ArrayList<String>> entry : entrySet) {
// ArrayList<String> list = entry.getValue();
// String value = list.get(2);
// System.out.println("<22><>ǰֵΪ<D6B5><CEAA>" + value);
// if(value != null && value.equals("<22><>")) {
// specialList.add(index);
// }
// index++;
// }
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
/**
* <20>õ<EFBFBD>ģ<EFBFBD><C4A3><EFBFBD><EFBFBD>ֵ
*
* @param map
* @throws Exception
*/
// public static void getModelVale(LinkedHashMap<String, ArrayList<String>> map,String prefName,int index) throws Exception {
// AbstractAIFApplication application = AIFUtility.getCurrentApplication();
// TCSession session = (TCSession) application.getSession();
// String[] prefVals = KUtil.getPrefVals(session, prefName);
// String puid = prefVals[index];
// TCComponentDataset component = (TCComponentDataset) session.stringToComponent(puid);
// TCComponentTcFile[] tcFiles = component.getTcFiles();
// File datasetFile = null;
// String name = "";
// if (tcFiles != null && tcFiles.length != 0) {
// TCComponentTcFile tcComponentTcFile = tcFiles[0];
// File fmsFile = tcComponentTcFile.getFmsFile();
// name = tcComponentTcFile.getStringProperty("original_file_name");
// datasetFile = new File(System.getenv("TEMP")+"\\"+name);
// FileUtility.copyFile(fmsFile, datasetFile);
//
// }
// XSSFWorkbook wb = new XSSFWorkbook(new FileInputStream(datasetFile));
// XSSFSheet sheet = wb.getSheetAt(0);
// for (int i = 1; i < sheet.getPhysicalNumberOfRows(); i++) {
// XSSFRow row = sheet.getRow(i);
// for (int j = 0; j < 5; j++) {
// XSSFCell cell = row.getCell(j);
// if(cell != null) {
// String cellValue = KUtil.getCellValue(cell);
// if(j == 0 && cellValue.isEmpty()) {
// break;
// }
// if(j == 0 ) {
// if(map.containsKey(cellValue)) {
// break;
// }else {
// map.put(cellValue, null);
// }
// }else {
// String key = KUtil.getCellValue(row.getCell(0));
// ArrayList<String> arrayList = map.get(key);
// if(arrayList != null) {
// arrayList.add(cellValue);
// }else {
// ArrayList<String> list = new ArrayList<String>();
// list.add(cellValue);
// map.put(key, list);
// }
// }
//
// }
// }
// }
// wb.close();
// datasetFile.delete();
// }
/**
* <20>õ<EFBFBD>ģ<EFBFBD><C4A3><EFBFBD><EFBFBD>ֵ
*
* @param map
* @throws Exception
*/
public static void getModelVale(LinkedHashMap<String, ArrayList<String>> map, TCComponent forms,
ArrayList<Integer> specialList, String[] propNames) throws Exception {
// AbstractAIFApplication application = AIFUtility.getCurrentApplication();
// TCSession session = (TCSession) application.getSession();
// String[] prefVals = KUtil.getPrefVals(session, prefName);
// String puid = prefVals[index];
// TCComponent component = session.stringToComponent(puid);
int t = 1;
if (forms instanceof TCComponentForm) {
TCComponentForm form = (TCComponentForm) forms;
TCComponent[] tables = form.getReferenceListProperty("ld6_ChangeTable");
for (int j = 0; j < tables.length; j++) {
ArrayList<String> tableValue = new ArrayList<String>();
for (String propName : propNames) {
//System.out.println("<22><>ǰ<EFBFBD><C7B0><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϊ<EFBFBD><CEAA>" + propName);
String prop = tables[j].getTCProperty(propName).getDisplayableValue();
if (propName.equals("ld6_YNChange") && prop.equals("<22><>")) {
// specialList.add(j);
}
tableValue.add(prop == null ? "" : prop.trim());
}
map.put(String.valueOf(t), tableValue);
// tableValue
t = t + 1;
}
}
}
/**
* <20>õ<EFBFBD>lov<6F><76><EFBFBD><EFBFBD>ʵֵ<CAB5><D6B5><EFBFBD><EFBFBD>ʾֵ
*
* @param lovMap
* @param comboBox
* @throws TCException
*/
public static void getLov(HashMap<String, String> lovMap, String lovName, JComboBox<String> comboBox)
throws TCException {
if (comboBox != null) {
comboBox.addItem("");
}
// for (LovValue lovV : lovValueList) {
// map.put(lovV.getDisplayValue(), lovV.getStringValue());
// comboBox.addItem(lovV.getDisplayValue());
// System.out.println(lovV.getDisplayValue() + "===" + lovV.getStringValue());
// }
TCComponentListOfValues lov = TCComponentListOfValuesType.findLOVByName(lovName);
if ("Fnd0ListOfValuesDynamic".equals(lov.getProperty("lov_type"))) {
System.out.println("<22><>̬lovName=" + lovName);
LOVService lovService = LOVService.getService(RACUIUtil.getTCSession());
InitialLovData input = new InitialLovData();
LovFilterData filter = new LovFilterData();
if ("LD6_TecDoc_TypeLOV".equals(lovName)) {
filter.sortPropertyName = "fnd0StringValues"; // lov<6F>ĺ<EFBFBD>ֵ̨
} else {
filter.sortPropertyName = "object_name"; // lov<6F>ĺ<EFBFBD>ֵ̨
}
filter.order = 1;
filter.numberToReturn = 2000;
filter.maxResults = 2000;
input.lov = lov;
input.filterData = filter;
LOVSearchResults result = lovService.getInitialLOVValues(input);
// System.out.println("111==="+result.toString());
for (LOVValueRow row : result.lovValues) {
Map<String, String[]> map = row.propDisplayValues;
Map<String, String[]> realmap = row.propInternalValues;
// for (String key : map.keySet()) {
// System.out.println("key=" + key + ",value=" + map.get(key)[0]);
// }
// for (String key : realmap.keySet()) {
// System.out.println("key2=" + key + ",value2=" + map.get(key)[0]);
// }
String disval = "";
String val = "";
String key1 = "object_name";// <20><>ʵֵ <20><>ʾֵ<CABE><D6B5>һ<EFBFBD><D2BB>
if ("LD6_TecDoc_TypeLOV".equals(lovName)) {
key1 = "fnd0StringValues"; // lov<6F>ĺ<EFBFBD>ֵ̨
}
// String key2 = "object_desc";// <20><>ʾֵ<CABE>ڶ<EFBFBD><DAB6><EFBFBD>
if (map.containsKey(key1)) {
val = realmap.get(key1)[0];
disval = map.get(key1)[0];
}
if (!val.equals("")) {
lovMap.put(disval, val);
if (comboBox != null) {
comboBox.addItem(disval);
}
}
}
} else {
ListOfValuesInfo info = lov.getListOfValues();
info.getLOVDisplayValues();
List<LovValue> lovValueList = info.getValues();
for (LovValue lovV : lovValueList) {
lovMap.put(lovV.getDisplayValue(), lovV.getStringValue());
if (comboBox != null) {
comboBox.addItem(lovV.getDisplayValue());
}
}
}
}
public static void dealPref(String[] prefVals, InterfaceAIFComponent targetComponent,
ArrayList<ControlBean> beanList, StringBuffer newTypeBuffer) throws Exception {
/**
* LD6_PRRevision/LD6_CR|*[string]Item.item_id=;
* *[string]Item.object_name=;*[string]Rev.ld6_processNum=;*[string]Rev.ld6_productNum=Rev.ld6_proNum
*/
String type = targetComponent.getType();
TCComponentItemRevision rev = (TCComponentItemRevision) targetComponent;
for (String string : prefVals) {
String[] split = string.split("\\|");
if (split.length == 2) {
String[] split2 = split[0].split("/");
if (split2.length == 2 && type.equals(split2[0])) {
// <20>õ<EFBFBD><C3B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
newTypeBuffer.append(split2[1]);
// <20>õ<EFBFBD><C3B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ŀؼ<C4BF>
String[] split3 = split[1].split(";");
for (int i = 0; i < split3.length; i++) {
ControlBean bean = new ControlBean();
if (split3[i].contains("*[")) {
bean.setIfMust(true);
}
String[] split4 = split3[i].split("=");
// <20>ж<EFBFBD><D0B6><EFBFBD>ʲô<CAB2><C3B4><EFBFBD>͵<EFBFBD><CDB5><EFBFBD><EFBFBD><EFBFBD>
if (split4[0].contains("boolean")) {
bean.setPropType("boolean");
} else if (split4[0].contains("date")) {
bean.setPropType("date");
} else if (split4[0].contains("string:")) {
bean.setPropType("lov");
} else if (split4[0].contains("string") && !split4[0].contains("string:")) {
bean.setPropType("string");
}
if (split4.length == 2) {
bean.setDefaultValue(getTCPropertyValue(rev, split4[1], bean));
}
String[] split5 = split4[0].split("]");
if (split5.length == 2) {
String[] split6 = split5[1].split("\\.");
bean.setPropTo(split6[0]);
bean.setPropRelName(split6[1]);
bean.setPropName(split6[2]);
if ("lov".equals(bean.getPropType())) {
// <20>õ<EFBFBD>lov<6F><76><EFBFBD><EFBFBD>lovMap
String[] split7 = split5[0].split(":");
String lovName = split7[1];
HashMap<String, String> lovMap = new LinkedHashMap<String, String>();
// JComboBox<String> combox = new JComboBox<String>();
try {
String desType = newTypeBuffer.toString();
if ("Rev".equals(bean.getPropTo())) {
desType = desType + "Revision";
} else if ("Form".equals(bean.getPropTo())) {
desType = desType + "RevisionMaster";
}
TCComponentType localTCComponentType = session.getTypeComponent(desType);
TCPropertyDescriptor descriptor = localTCComponentType
.getPropertyDescriptor(bean.getPropRelName());
LOVDisplayer combo = new LOVDisplayer(descriptor);
getLov(lovMap, lovName, null);
bean.setCombox(combo);
} catch (TCException e) {
e.printStackTrace();
}
bean.setLovMap(lovMap);
// bean.setCombox(combox);
}
}
beanList.add(bean);
}
break;
}
}
}
}
public static String getTCPropertyValue(TCComponentItemRevision rev, String specialValue, ControlBean bean) {
try {
String[] split = specialValue.split("\\.");
TCComponent center = null;
if (split.length == 2 || split.length == 3) {
switch (split[0]) {
case "Rev":
center = rev;
break;
case "Item":
center = rev.getItem();
break;
case "Form":
center = rev.getRelatedComponent("IMAN_master_form_rev");
break;
default:
break;
}
String value = "";
if ("date".equals(bean.getPropType())) {
System.out.println("<22><>ǰ<EFBFBD><C7B0><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʵ<EFBFBD><CAB5>Ϊ<EFBFBD><CEAA>" + split[1]);
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-M-dd HH:mm");
if (center.getDateProperty(split[1]) != null) {
value = sdf.format(center.getDateProperty(split[1]));
}
} else {
value = center.getStringProperty(split[1]);
}
if (split.length == 3) {
bean.setPropName(split[2]);
}
return value;
}
} catch (Exception e) {
e.printStackTrace();
}
return "";
}
}