();
+
+ public TemplateDialog(TCSession session, TCComponentItemRevision rev) throws TCException {
+ // TODO Auto-generated constructor stub
+ this.session = session;
+ this.rev = rev;
+
+ initUI();
+ }
+
+ private void initUI() {
+ // TODO Auto-generated method stub
+ try {
+ company.setPreferredSize(new Dimension(200,30));
+ template.setPreferredSize(new Dimension(200,30));
+ this.setTitle("ģ");
+ this.setLayout(new BorderLayout());
+
+ JPanel topPanel = getTopPanel();
+
+ JPanel btnPanel = getBtnPanel();
+
+ this.add(topPanel, BorderLayout.NORTH);
+ // this.add(pane,BorderLayout.CENTER);
+ this.add(btnPanel, BorderLayout.SOUTH);
+ this.setPreferredSize(new Dimension(450, 200));
+ Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); // ȡĻߴ
+ int screenWidth = screenSize.width; // ȡĻ
+ int screenHeight = screenSize.height; // ȡĻ߶
+ int x = (screenWidth - 450) / 2; // FrameϽx
+ int y = (screenHeight - 200) / 2; // FrameϽy
+ this.setLocation(x, y); // Frameλ
+
+ // this.setLocationRelativeTo(null);
+ this.createActionEvent();
+ this.pack();
+
+ // this.validate();
+ this.setVisible(true);
+
+// this.setAlwaysOnTop(true);
+
+
+
+ String[] pref = session.getPreferenceService().getStringValues("LY6_MEOP_TemplateType");
+ for (int i = 0; i < pref.length; i++) {
+ String[] split = pref[i].split(":");
+ company.addItem(split[0]);
+ map.put(split[0], split[1]);
+ }
+
+ String mrselectitem = (String)company.getSelectedItem();
+ String mrValue = map.get(mrselectitem);
+ String[] split = mrValue.split(",");
+ for (int i = 0; i < split.length; i++) {
+ template.addItem(split[i]);
+ }
+
+ //ֵ
+ company.addItemListener(new ItemListener() {
+ @Override
+ public void itemStateChanged(ItemEvent e) {
+ if (e.getStateChange() == ItemEvent.SELECTED) {
+ template.removeAllItems();
+ String selectedItem = (String) company.getSelectedItem();
+ System.out.println("Selected Item: " + selectedItem);
+ // ִ
+ String value = map.get(selectedItem);
+ String[] split = value.split(",");
+ for (int i = 0; i < split.length; i++) {
+ template.addItem(split[i]);
+ }
+ }
+ }
+ });
+
+ } catch (Exception e) {
+ e.printStackTrace();
+ return;
+ }
+ }
+
+ // Ӽ
+ public void createActionEvent() {
+
+ this.okButton.addActionListener(this);
+ this.concelButton.addActionListener(this);
+ }
+
+ @Override
+ public void actionPerformed(ActionEvent e) {
+ // TODO Auto-generated method stub
+
+ Object source = e.getSource();
+ System.out.println("source==>+" + source);
+ if (this.okButton.equals(source)) {
+ String templateString = (String)template.getSelectedItem();
+ String companyString = (String)company.getSelectedItem();
+ System.out.println("templateString==="+templateString);
+ System.out.println("companyString==="+companyString);
+ if(companyString.isEmpty()) {
+ MessageBox.post("ѡ˾", "ʾ ", MessageBox.INFORMATION);
+ return;
+ }
+
+ if(templateString.isEmpty()) {
+ MessageBox.post("ѡģ壡", "ʾ ", MessageBox.INFORMATION);
+ return;
+ }
+
+ //òѯȡģdwgݼ
+ try {
+ TCComponent[] items = session.search("...", new String[] { " ID" }, new String[] {templateString});
+ System.out.println("items.length===="+items.length);
+ TCComponentItem item = null;
+ if(items.length > 0) {
+ item = (TCComponentItem)items[0];
+ }
+ TCComponentItemRevision latestItemRevision = item.getLatestItemRevision();
+ TCComponent[] relatedComponent = latestItemRevision.getRelatedComponents("IMAN_specification");
+ System.out.println("relatedComponent========"+relatedComponent.length);
+ for (int i = 0; i < relatedComponent.length; i++) {
+ rev.add("IMAN_specification",relatedComponent[i]);
+ }
+ MessageBox.post("ģɹ", "ʾ ", MessageBox.INFORMATION);
+ this.dispose();
+ return;
+ } catch (Exception e1) {
+ // TODO Auto-generated catch block
+ e1.printStackTrace();
+ }
+ //ݼ
+ } else if (this.concelButton.equals(source)) {
+ this.dispose();
+ }
+
+ }
+
+ private JPanel getBtnPanel() {
+ JPanel topPanel = new JPanel();
+ topPanel.setLayout(new PropertyLayout());
+ topPanel.add("1.1.center", new JLabel(""));
+ topPanel.add("2.1.center", new JLabel(" "));
+ topPanel.add("2.2.center", okButton);
+ topPanel.add("2.3.center", new JLabel(""));
+ topPanel.add("2.4.center", concelButton);
+
+ return topPanel;
+ }
+
+ // ѯ
+ private JPanel getTopPanel() {
+ // TODO Auto-generated method stub
+ JPanel topPanel = new JPanel();
+ topPanel.setLayout(new PropertyLayout());
+ topPanel.setBorder(new EmptyBorder(5, 5, 5, 5));
+
+ topPanel.add("1.1.left.center", new JLabel(""));
+ topPanel.add("2.1.left.center", new JLabel(""));
+ topPanel.add("3.1.left.center", new JLabel(""));
+ topPanel.add("4.1.left.center", new JLabel(" ˾"));
+ topPanel.add("4.2.left.center", company);
+
+ topPanel.add("5.1.left.center", new JLabel(""));
+ topPanel.add("6.1.left.center", new JLabel(""));
+ topPanel.add("7.1.left.center", new JLabel(""));
+ topPanel.add("8.1.left.center", new JLabel(" ģ壺"));
+
+ topPanel.add("8.2.left.center", template);
+
+ return topPanel;
+ }
+
+}
diff --git a/src/com/langtech/plm/template/TemplateHandler.java b/src/com/langtech/plm/template/TemplateHandler.java
new file mode 100644
index 0000000..4ced53a
--- /dev/null
+++ b/src/com/langtech/plm/template/TemplateHandler.java
@@ -0,0 +1,77 @@
+package com.langtech.plm.template;
+
+import org.eclipse.core.commands.AbstractHandler;
+import org.eclipse.core.commands.ExecutionEvent;
+import org.eclipse.core.commands.ExecutionException;
+
+import com.teamcenter.rac.aif.AbstractAIFApplication;
+import com.teamcenter.rac.aif.kernel.InterfaceAIFComponent;
+import com.teamcenter.rac.aifrcp.AIFUtility;
+import com.teamcenter.rac.kernel.TCComponentItemRevision;
+import com.teamcenter.rac.kernel.TCComponentSchedule;
+import com.teamcenter.rac.kernel.TCComponentScheduleTask;
+import com.teamcenter.rac.kernel.TCSession;
+import com.teamcenter.rac.util.MessageBox;
+
+public class TemplateHandler extends AbstractHandler{
+
+
+ @Override
+ public Object execute(ExecutionEvent arg0) throws ExecutionException {
+ AbstractAIFApplication app = AIFUtility.getCurrentApplication();
+ TCSession session = (TCSession) app.getSession();
+ try {
+
+
+
+ new Thread() {
+ @Override
+ public void run() {
+ InterfaceAIFComponent targetComponent = app.getTargetComponent();
+
+ if(targetComponent instanceof TCComponentItemRevision) {
+ try {
+ String[] pref = session.getPreferenceService().getStringValues("LY6_MEOP_TemplateObject");
+ String types = "";
+ if(pref.length > 0) {
+ types = pref[0];
+ }else {
+ MessageBox.post("ѡLY6_MEOP_TemplateObject","ʾ",2);
+ return;
+ }
+
+ TCComponentItemRevision rev = (TCComponentItemRevision)targetComponent;
+ String object_type = rev.getStringProperty("object_type");
+ if(types.contains(object_type)) {
+ new TemplateDialog(session,rev);
+ }else {
+ MessageBox.post("ѡѡLY6_MEOP_TemplateObjectƥĶ","ʾ",2);
+ return;
+ }
+
+
+
+
+ } catch (Exception e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ }else {
+ MessageBox.post("ѡ汾","ʾ",2);
+ return;
+ }
+
+
+ }
+ }.start();
+
+ } catch (Exception e) {
+ // TODO: handle exception
+ e.printStackTrace();
+ }
+
+ return null;
+ }
+
+
+}
diff --git a/src/com/langtech/plm/performancemanagement/Activator.java b/src/com/langtech/plm/tqsx/Activator.java
similarity index 83%
rename from src/com/langtech/plm/performancemanagement/Activator.java
rename to src/com/langtech/plm/tqsx/Activator.java
index 67636fc..303ada3 100644
--- a/src/com/langtech/plm/performancemanagement/Activator.java
+++ b/src/com/langtech/plm/tqsx/Activator.java
@@ -1,4 +1,4 @@
-package com.langtech.plm.performancemanagement;
+package com.langtech.plm.tqsx;
import org.eclipse.ui.plugin.AbstractUIPlugin;
import org.osgi.framework.BundleContext;
@@ -9,7 +9,7 @@ import org.osgi.framework.BundleContext;
public class Activator extends AbstractUIPlugin {
// The plug-in ID
- public static final String PLUGIN_ID = "com.langtech.plm.performancemanagement"; //$NON-NLS-1$
+ public static final String PLUGIN_ID = "cn.net.connor.ml.plm"; //$NON-NLS-1$
// The shared instance
private static Activator plugin;
diff --git a/src/com/langtech/plm/tqsx/DateUtil.java b/src/com/langtech/plm/tqsx/DateUtil.java
new file mode 100644
index 0000000..4585c06
--- /dev/null
+++ b/src/com/langtech/plm/tqsx/DateUtil.java
@@ -0,0 +1,603 @@
+package com.langtech.plm.tqsx;
+
+import java.time.*;
+import java.time.format.DateTimeFormatter;
+import java.util.Date;
+
+public class DateUtil {
+ private static final String HYPHEN = "-";
+ private static final String COLON = ":";
+
+ /* ʱʽ DateTimeFormatter (Java8) */
+ enum FormatEnum {
+ /**
+ * DateTimeFormatter "yyyy-MM-dd HH:mm:ss" ʱʽ
+ */
+ FORMAT_DATA_TIME(DateTimeFormatter.ofPattern(DATE_TIME_FORMAT)),
+
+ /**
+ * DateTimeFormatter "yyyyMMddHHmmss"ʱʽ
+ */
+ FORMAT_DATA_TIME_NO_SYMBOL(DateTimeFormatter.ofPattern(DATETIME_FORMAT)),
+
+ /**
+ * DateTimeFormatter "yyyy-MM-dd"ʱʽ
+ */
+ FORMAT_DATE(DateTimeFormatter.ofPattern(DATE_FORMAT)),
+
+ /**
+ * DateTimeFormatter "HH:mm:ss"ʱʽ
+ */
+ FORMAT_TIME(DateTimeFormatter.ofPattern(TIME_FORMAT));
+
+ private DateTimeFormatter value;
+
+ FormatEnum(DateTimeFormatter format) {
+ this.value = format;
+ }
+ }
+ /* ʱʽ DateTimeFormatter (Java8) */
+
+ /* ʱʽ ַ */
+
+ /**
+ * ʱʽ
+ *
+ * "yyyy" ַ
+ */
+ public static final String YEAR_FORMAT = "yyyy";
+
+ /**
+ * µʱʽ
+ *
+ * "MM" ַ
+ */
+ public static final String MONTH_FORMAT = "MM";
+
+ /**
+ * յʱʽ
+ *
+ * "dd" ַ
+ */
+ public static final String DAY_FORMAT = "dd";
+
+ /**
+ * ʱʱʽ
+ *
+ * "HH" ַ
+ */
+ public static final String HOUR_FORMAT = "HH";
+
+ /**
+ * ֵʱʽ
+ *
+ * "mm" ַ
+ */
+ public static final String MINUTE_FORMAT = "mm";
+
+ /**
+ * ʱʽ
+ *
+ * "ss" ַ
+ */
+ public static final String SECOND_FORMAT = "ss";
+
+ /**
+ * --ʱʽ
+ *
+ * "yyyy-MM-dd" ַ
+ */
+ public static final String DATE_FORMAT = YEAR_FORMAT + HYPHEN + MONTH_FORMAT + HYPHEN + DAY_FORMAT;
+
+ /**
+ * ʱ::ʱʽ
+ *
+ * "HH:mm:ss" ַ
+ */
+ public static final String TIME_FORMAT = HOUR_FORMAT + COLON + MINUTE_FORMAT + COLON + SECOND_FORMAT;
+
+ /**
+ * -- ʱ::ʱʽ
+ *
+ * "yyyy-MM-dd HH:mm:ss" ַ
+ */
+ public static final String DATE_TIME_FORMAT = DATE_FORMAT + " " + TIME_FORMAT;
+
+ /**
+ * ʱʱʽţ
+ *
+ * "yyyyMMddHHmmss" ַ
+ */
+ public static final String DATETIME_FORMAT = YEAR_FORMAT + MONTH_FORMAT + DAY_FORMAT + HOUR_FORMAT + MINUTE_FORMAT + SECOND_FORMAT;
+
+ /* ʱʽ ַ */
+
+
+
+ /* ʱ */
+
+ /**
+ * ȡ뼶ʱ
+ */
+ public static Long epochSecond() {
+ return localDateTime().toEpochSecond(ZoneOffset.of("+8"));
+ }
+
+ /**
+ * ȡ뼶ʱ
+ */
+ public static Long epochMilli() {
+ return localDateTime().toInstant(ZoneOffset.of("+8")).toEpochMilli();
+ }
+
+ /* ʱ */
+
+
+ /* ǰʱ */
+
+ /**
+ * ȡǰϸʱ䣬like 2018-08-27 17:20:06
+ */
+ public static String dateTime() {
+ return localDateTime().format(FormatEnum.FORMAT_DATA_TIME.value);
+ }
+
+ /**
+ * ȡǰϸʱ䣬like 20180827172006
+ */
+ public static String dateTimeNoSymbol() {
+ return localDateTime().format(FormatEnum.FORMAT_DATA_TIME_NO_SYMBOL.value);
+ }
+
+ /**
+ * ȡǰڣlike 2018-08-27
+ */
+ public static String date() {
+ return localDate() + "";
+ }
+
+ /**
+ * ȡǰʱ䣬like 17:20:06
+ */
+ public static String time() {
+ return localTime().format(FormatEnum.FORMAT_TIME.value);
+ }
+
+ /**
+ * ȡǰ
+ */
+ public static Integer year() {
+ return localDate().getYear();
+ }
+
+ /**
+ * ȡǰ
+ */
+ public static int month() {
+ return localDate().getMonthValue();
+ }
+
+ /**
+ * ȡǰе
+ */
+ public static Integer dayOfYear() {
+ return localDate().getDayOfYear();
+ }
+
+ /**
+ * ȡǰе
+ */
+ public static Integer dayOfMonth() {
+ return localDate().getDayOfMonth();
+ }
+
+ /**
+ * ȡǰе
+ */
+ public static Integer dayOfWeek() {
+ return localDate().getDayOfWeek().getValue();
+ }
+
+ /**
+ * ȡǰСʱ
+ */
+ public static Integer hour() {
+ return localTime().getHour();
+ }
+
+ /**
+ * ȡǰ
+ */
+ public static Integer minute() {
+ return localTime().getMinute();
+ }
+
+ /**
+ * ȡǰ
+ */
+ public static Integer second() {
+ return localTime().getSecond();
+ }
+
+ /* ǰʱ */
+
+
+
+ /* δʷʱ */
+
+ /**
+ * ȡǰ ǰ
+ *
+ *
+ * @param years ǰ
+ * @param formatEnum ʽ
+ * @return ǰ ǰ Ӧ ʽ
+ */
+ public static String minusYears(Long years, FormatEnum formatEnum) {
+ return minusOrPlusYears(-years, formatEnum);
+ }
+
+ /**
+ * ȡǰ
+ *
+ *
+ * @param years
+ * @param formatEnum ʽ
+ * @return ǰ Ӧ ʽ
+ */
+ public static String plusYears(Long years, FormatEnum formatEnum) {
+ return minusOrPlusYears(years, formatEnum);
+ }
+
+ /**
+ * ȡǰµ ǰ
+ *
+ * @param months ǰ
+ * @param formatEnum ʽ
+ * @return ǰµ ǰ Ӧ ʽ
+ */
+ public static String minusMonths(Long months, FormatEnum formatEnum) {
+ return minusOrPlusMonths(-months, formatEnum);
+ }
+
+ /**
+ * ȡǰµ
+ *
+ * @param months
+ * @param formatEnum ʽ
+ * @return ǰµ Ӧ ʽ
+ */
+ public static String plusMonths(Long months, FormatEnum formatEnum) {
+ return minusOrPlusMonths(months, formatEnum);
+ }
+
+ /**
+ * ȡǰյ ǰ
+ *
+ * @param days ǰ
+ * @param formatEnum ʽ
+ * @return ǰյ ǰ Ӧ ʽ
+ */
+ public static String minusDays(Long days, FormatEnum formatEnum) {
+ return minusOrPlusDays(-days, formatEnum);
+ }
+
+ /**
+ * ȡǰյ
+ *
+ * @param days
+ * @param formatEnum ʽ
+ * @return ǰյ Ӧ ʽ
+ */
+ public static String plusDays(Long days, FormatEnum formatEnum) {
+ return minusOrPlusDays(days, formatEnum);
+ }
+
+ /**
+ * ȡǰڵ ǰ
+ *
+ * @param weeks ǰ
+ * @param formatEnum ʽ
+ * @return ǰڵ ǰ Ӧ ʽ
+ */
+ public static String minusWeeks(Long weeks, FormatEnum formatEnum) {
+ return minusOrPlusWeeks(-weeks, formatEnum);
+ }
+
+ /**
+ * ȡǰڵ
+ *
+ * @param weeks
+ * @param formatEnum ʽ
+ * @return ǰڵ Ӧ ʽ
+ */
+ public static String plusWeeks(Long weeks, FormatEnum formatEnum) {
+ return minusOrPlusWeeks(weeks, formatEnum);
+ }
+
+ /**
+ * ȡǰСʱ ǰСʱ
+ *
+ * @param hours ǰСʱ
+ * @param formatEnum ʽ
+ * @return ǰСʱ ǰСʱ Ӧ ʽ
+ */
+ public static String minusHours(Long hours, FormatEnum formatEnum) {
+ return minusOrPlusHours(-hours, formatEnum);
+ }
+
+ /**
+ * ȡǰСʱ Сʱ
+ *
+ * @param hours Сʱ
+ * @param formatEnum ʽ
+ * @return ǰСʱ Сʱ Ӧ ʽ
+ */
+ public static String plusHours(Long hours, FormatEnum formatEnum) {
+ return minusOrPlusHours(hours, formatEnum);
+ }
+
+ /**
+ * ȡǰӵ ǰ
+ *
+ * @param minutes ǰ
+ * @param formatEnum ʽ
+ * @return ǰӵ ǰ Ӧ ʽ
+ */
+ public static String minusMinutes(Long minutes, FormatEnum formatEnum) {
+ return minusOrPlusMinutes(-minutes, formatEnum);
+ }
+
+ /**
+ * ȡǰӵ
+ *
+ * @param minutes
+ * @param formatEnum ʽ
+ * @return ǰӵ Ӧ ʽ
+ */
+ public static String plusMinutes(Long minutes, FormatEnum formatEnum) {
+ return minusOrPlusMinutes(minutes, formatEnum);
+ }
+
+ /**
+ * ȡǰ ǰ
+ *
+ * @param seconds ǰ
+ * @param formatEnum ʽ
+ * @return ǰ ǰ Ӧ ʽ
+ */
+ public static String minusSeconds(Long seconds, FormatEnum formatEnum) {
+ return minusOrPlusSeconds(-seconds, formatEnum);
+ }
+
+ /**
+ * ȡǰ ǰ/
+ *
+ * @param seconds
+ * @param formatEnum ʽ
+ * @return ǰ Ӧ ʽ
+ */
+ public static String plusSeconds(Long seconds, FormatEnum formatEnum) {
+ return minusOrPlusSeconds(seconds, formatEnum);
+ }
+
+ /* δʷʱ */
+
+
+ /* ʱת */
+
+ /**
+ * DateתLocalDateTime
+ *
+ *
+ * @param date dateʱ
+ * @return LocalDateTime
+ */
+ public static LocalDateTime toLocalDateTime(Date date) {
+ return LocalDateTime.ofInstant(date.toInstant(), ZoneId.systemDefault());
+ }
+
+ /**
+ * DateתLocalDate
+ *
+ *
+ * @param date dateʱ
+ * @return LocalDate
+ */
+ public static LocalDate toLocalDate(Date date) {
+ return toLocalDateTime(date).toLocalDate();
+ }
+
+ /**
+ * DateתLocalTime
+ *
+ *
+ * @param date dateʱ
+ * @return LocalTime
+ */
+ public static LocalTime toLocalTime(Date date) {
+ return toLocalDateTime(date).toLocalTime();
+ }
+
+ /**
+ * LocalDateTime ת Date
+ *
+ * @param localDateTime localDateTime
+ * @return תDate
+ */
+ public static Date toDate(LocalDateTime localDateTime) {
+ return Date.from(localDateTime.atZone(ZoneId.systemDefault()).toInstant());
+ }
+
+ /**
+ * LocalDateתDate
+ *
+ * @param localDate localDate
+ * @return תDate
+ */
+ public static Date toDate(LocalDate localDate) {
+ return toDate(localDate.atStartOfDay());
+ }
+
+ /**
+ * LocalTimeתDate
+ *
+ * @param localTime localTime
+ * @return תDate
+ */
+ public static Date toDate(LocalTime localTime) {
+ return toDate(LocalDateTime.of(localDate(), localTime));
+ }
+
+ /* ʱת */
+
+
+ /* ʱ */
+
+ /**
+ * ȡ endDate-startDate ʱ
+ *
ˣ leigq
+ *
ʱ䣺 2018-11-07 09:55
+ *
+ *
+ * @param startDate ʼʱ
+ * @param endDate ʱ
+ * @return ʱ
+ */
+ public static Long daysInterval(LocalDate startDate, LocalDate endDate) {
+ return endDate.toEpochDay() - startDate.toEpochDay();
+ }
+
+ /**
+ * ȡ endDate-startDate ʱ
+ *
ˣ leigq
+ *
ʱ䣺 2018-11-07 09:55
+ *
+ *
+ * @param startDate ʼʱ
+ * @param endDate ʱ
+ * @return ʱ
+ */
+ public static Long daysInterval(String startDate, String endDate) {
+ return daysInterval(LocalDateTime.parse(endDate, FormatEnum.FORMAT_DATA_TIME.value).toLocalDate(),
+ LocalDateTime.parse(startDate, FormatEnum.FORMAT_DATA_TIME.value).toLocalDate());
+ }
+
+ /**
+ * ȡ endDate-startDate ʱ
+ *
ˣ leigq
+ *
ʱ䣺 2018-11-07 09:55
+ *
+ *
+ * @param startDate ʼʱ
+ * @param endDate ʱ
+ * @return ʱ
+ */
+ public static Long daysInterval(LocalDateTime startDate, LocalDateTime endDate) {
+ return daysInterval(startDate.toLocalDate(), endDate.toLocalDate());
+ }
+
+ /* ʱ */
+
+ /*ֻá*/
+
+ /**
+ * ȡ ǰ ǰ/
+ *
+ *
+ * @param yearsToAddOrSubtract 괫ǰ괫
+ * @param formatEnum ʽ
+ * @return ǰǰ/ĶӦ ʽ
+ */
+ private static String minusOrPlusYears(Long yearsToAddOrSubtract, FormatEnum formatEnum) {
+ return localDateTime().plusYears(yearsToAddOrSubtract).format(formatEnum.value);
+ }
+
+ /**
+ * ȡ ǰ ǰ/µ
+ *
+ * @param monthsToAddOrSubtract ´ǰ´
+ * @param formatEnum ʽ
+ * @return ǰµǰ/µĶӦ ʽ
+ */
+ private static String minusOrPlusMonths(Long monthsToAddOrSubtract, FormatEnum formatEnum) {
+ return localDateTime().plusMonths(monthsToAddOrSubtract).format(formatEnum.value);
+ }
+
+ /**
+ * ȡ ǰ ǰ/յ
+ *
+ * @param daysToAddOrSubtract մǰմ
+ * @param formatEnum ʽ
+ * @return ǰյǰ/յ Ӧ ʽ
+ */
+ private static String minusOrPlusDays(Long daysToAddOrSubtract, FormatEnum formatEnum) {
+ return localDateTime().plusDays(daysToAddOrSubtract).format(formatEnum.value);
+ }
+
+ /**
+ * ȡǰڵǰ/ڵ
+ *
+ * @param weeksToAddOrSubtract ڴǰڴ
+ * @param formatEnum ʽ
+ * @return ǰڵǰ/ڵ Ӧ ʽ
+ */
+ private static String minusOrPlusWeeks(Long weeksToAddOrSubtract, FormatEnum formatEnum) {
+ return localDateTime().plusWeeks(weeksToAddOrSubtract).format(formatEnum.value);
+ }
+
+ /**
+ * ȡǰСʱǰСʱ/Сʱ
+ *
+ * @param hoursToAddOrSubtract СʱǰСʱ
+ * @param formatEnum ʽ
+ * @return ǰСʱǰСʱ/Сʱ Ӧ ʽ
+ */
+ private static String minusOrPlusHours(Long hoursToAddOrSubtract, FormatEnum formatEnum) {
+ return localDateTime().plusHours(hoursToAddOrSubtract).format(formatEnum.value);
+ }
+
+ /**
+ * ȡǰӵǰ/ӵ
+ *
+ * @param minutesToAddOrSubtract ӴǰӴ
+ * @param formatEnum ʽ
+ * @return ǰӵǰ/ӵ Ӧ ʽ
+ */
+ private static String minusOrPlusMinutes(Long minutesToAddOrSubtract, FormatEnum formatEnum) {
+ return localDateTime().plusMinutes(minutesToAddOrSubtract).format(formatEnum.value);
+ }
+
+ /**
+ * ȡǰǰ/
+ *
+ * @param secondsToAddOrSubtract 봫ǰ봫
+ * @param formatEnum ʽ
+ * @return ǰǰ/ Ӧ ʽ
+ */
+ private static String minusOrPlusSeconds(Long secondsToAddOrSubtract, FormatEnum formatEnum) {
+ return localDateTime().plusSeconds(secondsToAddOrSubtract).format(formatEnum.value);
+ }
+
+ /**
+ * ȡ LocalDate
+ */
+ private static LocalDate localDate() {
+ return localDateTime().toLocalDate();
+ }
+
+ /**
+ * ȡ LocalTime
+ */
+ private static LocalTime localTime() {
+ return localDateTime().toLocalTime();
+ }
+
+ /**
+ * ȡ LocalDateTime
+ */
+ private static LocalDateTime localDateTime() {
+ return LocalDateTime.now();
+ }
+
+}
diff --git a/src/com/langtech/plm/tqsx/KAction.java b/src/com/langtech/plm/tqsx/KAction.java
new file mode 100644
index 0000000..b2700d2
--- /dev/null
+++ b/src/com/langtech/plm/tqsx/KAction.java
@@ -0,0 +1,37 @@
+package com.langtech.plm.tqsx;
+
+import java.lang.reflect.Constructor;
+
+import com.teamcenter.rac.aif.AbstractAIFApplication;
+import com.teamcenter.rac.aif.AbstractAIFUIApplication;
+import com.teamcenter.rac.aif.common.actions.AbstractAIFAction;
+import com.teamcenter.rac.util.MessageBox;
+
+
+public class KAction extends AbstractAIFAction {
+
+
+ KAction(AbstractAIFUIApplication app, String string) {
+ super(app,string);
+ }
+
+ @Override
+ public void run() {
+ try {
+ int ind = actionName.indexOf('#');
+ String action=actionName;
+ String actionData="";
+ if(ind>0) {
+ action=actionName.substring(0,ind);
+ actionData=actionName.substring(ind+1);
+ }
+ Class> c = Class.forName(action);
+ Constructor> constructor = c.getConstructor(AbstractAIFApplication.class, String.class,String.class);
+ KCommand command = (KCommand) constructor.newInstance(this.application, action, actionData);
+ command.executeModal();
+ } catch (Exception e) {
+ e.printStackTrace();
+ MessageBox.post(e.toString(),KLocale.getString("error"),MessageBox.ERROR);
+ }
+ }
+}
diff --git a/src/com/langtech/plm/tqsx/KCommand.java b/src/com/langtech/plm/tqsx/KCommand.java
new file mode 100644
index 0000000..744f790
--- /dev/null
+++ b/src/com/langtech/plm/tqsx/KCommand.java
@@ -0,0 +1,16 @@
+package com.langtech.plm.tqsx;
+
+import com.teamcenter.rac.aif.AbstractAIFApplication;
+import com.teamcenter.rac.aif.AbstractAIFCommand;
+
+public abstract class KCommand extends AbstractAIFCommand {
+
+ protected AbstractAIFApplication app;
+ protected String actionInfo;
+
+ public KCommand(AbstractAIFApplication app, String commandId, String actionInfo) {
+ this.app = app;
+ this.actionInfo = actionInfo;
+ }
+
+}
diff --git a/src/com/langtech/plm/tqsx/KHandler.java b/src/com/langtech/plm/tqsx/KHandler.java
new file mode 100644
index 0000000..0d6563e
--- /dev/null
+++ b/src/com/langtech/plm/tqsx/KHandler.java
@@ -0,0 +1,24 @@
+package com.langtech.plm.tqsx;
+
+import org.eclipse.core.commands.AbstractHandler;
+import org.eclipse.core.commands.ExecutionEvent;
+
+import com.teamcenter.rac.aif.AbstractAIFUIApplication;
+import com.teamcenter.rac.aifrcp.AIFUtility;
+
+/**
+ * Add following config to MANIFEST.MF
+ * Eclipse-RegisterBuddy: k.util
+ * @author Administrator
+ *
+ */
+public class KHandler extends AbstractHandler {
+
+ @Override
+ public Object execute(ExecutionEvent arg0) {
+ AbstractAIFUIApplication app = AIFUtility.getCurrentApplication();
+ new Thread(new KAction(app,arg0.getCommand().getId())).start();
+ return null;
+ }
+
+}
diff --git a/src/com/langtech/plm/tqsx/KLocale.java b/src/com/langtech/plm/tqsx/KLocale.java
new file mode 100644
index 0000000..76adff7
--- /dev/null
+++ b/src/com/langtech/plm/tqsx/KLocale.java
@@ -0,0 +1,22 @@
+package com.langtech.plm.tqsx;
+
+import com.teamcenter.rac.util.Registry;
+
+
+public class KLocale {
+
+ public static final Registry reg = Registry.getRegistry(KLocale.class);
+
+ public static String getString(String title) {
+ if (isEmpty(title)) {
+ return "";
+ } else {
+ String res = reg.getString(title);
+ return isEmpty(res) ? title : res;
+ }
+ }
+
+ private static boolean isEmpty(String title) {
+ return title == null || "".equals(title.trim());
+ }
+}
diff --git a/src/com/langtech/plm/tqsx/KOperation.java b/src/com/langtech/plm/tqsx/KOperation.java
new file mode 100644
index 0000000..704bb53
--- /dev/null
+++ b/src/com/langtech/plm/tqsx/KOperation.java
@@ -0,0 +1,54 @@
+package com.langtech.plm.tqsx;
+
+import java.awt.Dimension;
+
+import com.teamcenter.rac.aif.AbstractAIFApplication;
+import com.teamcenter.rac.aif.AbstractAIFOperation;
+import com.teamcenter.rac.kernel.TCSession;
+
+import k.util.ProgressBar;
+
+/*
+ * do not call executeOperation yourself
+ * use session.performOperation
+ */
+public abstract class KOperation extends AbstractAIFOperation {
+
+ protected AbstractAIFApplication app;
+ protected TCSession session;
+ public String messageLabel;
+
+ public KOperation(AbstractAIFApplication app, String opName, String messageLabel) {
+ super(opName, true);
+ this.app = app;
+ this.session = (TCSession) app.getSession();
+ this.messageLabel = messageLabel;// Ϣ
+ setSession(session);
+ }
+
+ public abstract boolean init() throws Exception;
+
+ public abstract void execute() throws Exception;
+
+ @Override
+ public void executeOperation() {
+ ProgressBar pb = new ProgressBar(new Dimension(250, 50), true);
+ try {
+ pb.showDialog();
+ pb.setText(messageLabel);
+ setStatus("Checking Data...");
+ if (!init()) {
+ pb.disposeDialog();
+ return;
+ }
+ setStatus("Execute...");
+ pb.setText(messageLabel);
+ execute();
+ pb.disposeDialog();
+ } catch (Exception e) {
+ pb.disposeDialog();
+ KUtil.error(getCurrentDesktop(), "쳣\n" + e.getMessage());
+ e.printStackTrace();
+ }
+ }
+}
diff --git a/src/com/langtech/plm/tqsx/KOperation2.java b/src/com/langtech/plm/tqsx/KOperation2.java
new file mode 100644
index 0000000..f9f3b90
--- /dev/null
+++ b/src/com/langtech/plm/tqsx/KOperation2.java
@@ -0,0 +1,53 @@
+package com.langtech.plm.tqsx;
+
+import java.awt.Dimension;
+
+import com.teamcenter.rac.aif.AbstractAIFApplication;
+import com.teamcenter.rac.aif.AbstractAIFOperation;
+import com.teamcenter.rac.kernel.TCSession;
+
+import k.util.ProgressBar;
+
+/*
+ * do not call executeOperation yourself
+ * use session.performOperation
+ */
+public abstract class KOperation2 extends AbstractAIFOperation {
+
+ protected AbstractAIFApplication app;
+ protected TCSession session;
+ protected ProgressBar pb;
+
+ public KOperation2(AbstractAIFApplication app, String opName) {
+ super(opName, true);
+ this.app = app;
+ this.session = (TCSession) app.getSession();
+ setSession(session);
+ }
+
+ public abstract boolean init() throws Exception;
+
+ public abstract void execute() throws Exception;
+
+ @Override
+ public void executeOperation() {
+ pb = new ProgressBar(new Dimension(250, 50), true);
+ try {
+ pb.showDialog();
+ setStatus(KLocale.getString("initop.STATUS"));
+ if (!init()) {
+ pb.disposeDialog();
+ return;
+ }
+ setStatus(KLocale.getString("exeop.STATUS"));
+ execute();
+ KUtil.setByPass(false);
+ pb.disposeDialog();
+ } catch (Exception e) {
+ pb.disposeDialog();
+ KUtil.setByPass(false);
+ KUtil.error(getCurrentDesktop(), "쳣\n" + e);
+ e.printStackTrace();
+ }
+ }
+}
diff --git a/src/com/langtech/plm/tqsx/KUtil.java b/src/com/langtech/plm/tqsx/KUtil.java
new file mode 100644
index 0000000..21c5ee5
--- /dev/null
+++ b/src/com/langtech/plm/tqsx/KUtil.java
@@ -0,0 +1,2348 @@
+package com.langtech.plm.tqsx;
+
+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.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("δȡԣ" + 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://
+ value = (c.getNumericCellValue() + "").split("\\.")[0];
+ break;
+ case HSSFCell.CELL_TYPE_STRING:// ַ
+ value = c.getStringCellValue();
+ break;
+ case HSSFCell.CELL_TYPE_BOOLEAN:// boolean
+ value = c.getBooleanCellValue() + "";
+ break;
+ case HSSFCell.CELL_TYPE_FORMULA:// ʽ
+ value = c.getCellFormula() + "";
+ break;
+ case HSSFCell.CELL_TYPE_BLANK:// ֵ
+ value = "";
+ break;
+ case HSSFCell.CELL_TYPE_ERROR:
+ value = "Ƿַ";
+ break;
+ default:
+ value = "δ֪";
+ break;
+ }
+ return value;
+ }
+
+ /**
+ * õʵ
+ *
+ * @param sheet
+ * @param flag ҪдݿExcelԪöŸ Excel5еԪ4
+ * Ҫ⣬2вҪ⣬flagʹ [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();// ˴ͳд,
+ try {
+
+ for (int i = 1; i < rows; i++) {
+ Row row = sheet.getRow(i);
+ int total = 0;
+ ArrayList blank = new ArrayList();
+ 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 + "");
+ // 4жǿ˵÷
+ if (total == flag.length) {
+
+ return row_real;
+ } else if (total == 0) {
+ row_real++;
+
+ } else {
+ String h = "";
+ for (Integer b : blank) {
+
+ h = h + "" + (b + 1) + "" + " ";
+ }
+ throw new Exception("" + (i + 1) + "" + h + "Ϊ");
+ }
+
+ }
+ } catch (NullPointerException e) {
+ throw new Exception("excelʽ쳣,excelʽȱʧ,Ч!");
+ }
+ 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("ȡģ:" + file.getName());
+ try {
+ workbook = WorkbookFactory.create(in);
+ } catch (EOFException e) {
+ e.printStackTrace();
+ }
+// workbook = new XSSFWorkbook(in);
+ } else {
+ System.out.println("ʽ");
+ }
+ 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 list = new ArrayList();
+ 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 groups = new ArrayList();
+ List roles = new ArrayList();
+ 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 stringProps, Map 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 revPropMap = new HashMap<>();
+ if (!KUtil.isEmpty(revId)) {
+ revPropMap.put("item_revision_id", revId);
+ }
+ revInput.stringProps = revPropMap;
+ Map 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 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 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 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 getDatasets(TCComponent rev, String dsType, String rel) throws Exception {
+ if (rev == null) {
+ return null;
+ }
+ rev.refresh();
+ List res = new ArrayList();
+ TCComponent[] kids = rev.getRelatedComponents(rel);
+ for (TCComponent c : kids) {
+ if (c.getType().equals(dsType)) {
+ res.add((TCComponentDataset) c);
+ }
+ }
+ return res;
+ }
+
+ public static List getChildComponents(TCComponent rev, String dsType, String rel, String dsNamePrefix)
+ throws Exception {
+ if (rev == null) {
+ return null;
+ }
+ rev.refresh();
+ List res = new ArrayList();
+ 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 getChildComponentsContainsStr(TCComponent rev, String dsType, String rel,
+ String dsNameSubStr) throws Exception {
+ if (rev == null) {
+ return null;
+ }
+ if (dsNameSubStr == null) {
+ dsNameSubStr = "";
+ }
+ rev.refresh();
+ List res = new ArrayList();
+ 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 getChildComponents(TCComponent rev, String dsType, String rel) throws Exception {
+ if (rev == null) {
+ return null;
+ }
+ rev.refresh();
+ List res = new ArrayList();
+ 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 List> groupList(List originList, int maxCount, int gap, E gapFiller) {
+ List> res = new ArrayList>();
+ int cnt = originList == null ? 0 : originList.size();
+ List list = new ArrayList();
+ 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 cList = new ArrayList();
+ 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 List> groupListWithGapAdded(List list, int maxCount, E gapFiller) {
+ List> res = new ArrayList>();
+ int cnt = list == null ? 0 : list.size();
+ if (maxCount <= 0) {
+ maxCount = cnt;
+ }
+ int pageCounter = 0;
+ List cList = new ArrayList();
+ 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 List>> groupList(List