parent
670784ab29
commit
6276640680
@ -0,0 +1,151 @@
|
|||||||
|
package com.langtech.plm.bg;
|
||||||
|
|
||||||
|
import java.awt.BorderLayout;
|
||||||
|
import java.awt.Dimension;
|
||||||
|
import java.awt.Toolkit;
|
||||||
|
import java.awt.event.ActionEvent;
|
||||||
|
import java.awt.event.ActionListener;
|
||||||
|
import java.text.SimpleDateFormat;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Date;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map.Entry;
|
||||||
|
|
||||||
|
import javax.swing.JButton;
|
||||||
|
import javax.swing.JComboBox;
|
||||||
|
import javax.swing.JFrame;
|
||||||
|
import javax.swing.JLabel;
|
||||||
|
import javax.swing.JPanel;
|
||||||
|
import javax.swing.border.EmptyBorder;
|
||||||
|
import javax.swing.table.DefaultTableModel;
|
||||||
|
|
||||||
|
import com.teamcenter.rac.aif.AbstractAIFUIApplication;
|
||||||
|
import com.teamcenter.rac.kernel.TCComponent;
|
||||||
|
import com.teamcenter.rac.kernel.TCComponentForm;
|
||||||
|
import com.teamcenter.rac.kernel.TCComponentItem;
|
||||||
|
import com.teamcenter.rac.kernel.TCComponentItemRevision;
|
||||||
|
import com.teamcenter.rac.kernel.TCException;
|
||||||
|
import com.teamcenter.rac.kernel.TCSession;
|
||||||
|
import com.teamcenter.rac.util.MessageBox;
|
||||||
|
import com.teamcenter.rac.util.PropertyLayout;
|
||||||
|
|
||||||
|
public class QDRWChooseDialog extends JFrame implements ActionListener {
|
||||||
|
|
||||||
|
|
||||||
|
private JComboBox<String> objectComboBox = new JComboBox<String>();
|
||||||
|
private JButton okButton = new JButton("确定");
|
||||||
|
private JButton concelButton = new JButton("取消");
|
||||||
|
private String[] strings;
|
||||||
|
private AbstractAIFUIApplication app;
|
||||||
|
private HashMap<String, ArrayList<String>> map = new HashMap<String, ArrayList<String>>();
|
||||||
|
public QDRWChooseDialog(String[] strings,AbstractAIFUIApplication app) {
|
||||||
|
// TODO Auto-generated constructor stub
|
||||||
|
this.strings = strings;
|
||||||
|
this.app = app;
|
||||||
|
initUI();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
public void initUI() {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
try {
|
||||||
|
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(350, 150));
|
||||||
|
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); // 获取屏幕尺寸
|
||||||
|
int screenWidth = screenSize.width; // 获取屏幕宽度
|
||||||
|
int screenHeight = screenSize.height; // 获取屏幕高度
|
||||||
|
int x = (screenWidth - 350) / 2; // 计算Frame的左上角x坐标
|
||||||
|
int y = (screenHeight - 150) / 2; // 计算Frame的左上角y坐标
|
||||||
|
this.setLocation(x, y); // 设置Frame的位置
|
||||||
|
|
||||||
|
// this.setLocationRelativeTo(null);
|
||||||
|
this.createActionEvent();
|
||||||
|
this.pack();
|
||||||
|
|
||||||
|
// this.validate();
|
||||||
|
this.setVisible(true);
|
||||||
|
|
||||||
|
// this.setAlwaysOnTop(true);
|
||||||
|
|
||||||
|
//设置下拉值
|
||||||
|
for (int i = 0; i < strings.length; i++) {
|
||||||
|
String[] split = strings[i].split("=");
|
||||||
|
objectComboBox.addItem(split[0]);
|
||||||
|
ArrayList<String> list = new ArrayList<String>();
|
||||||
|
list.add(split[1]);
|
||||||
|
list.add(split[2]);
|
||||||
|
map.put(split[0], list);
|
||||||
|
}
|
||||||
|
|
||||||
|
} 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 selectedItem = (String) objectComboBox.getSelectedItem();
|
||||||
|
ArrayList<String> arrayList = map.get(selectedItem);
|
||||||
|
new QDRWDialog((TCSession)app.getSession(),arrayList.get(0),arrayList.get(1));
|
||||||
|
this.dispose();
|
||||||
|
} 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);
|
||||||
|
topPanel.add("3.1.center", new JLabel(""));
|
||||||
|
topPanel.add("4.1.center", new JLabel(""));
|
||||||
|
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("5.1.left.center", new JLabel(" 变更模板:"));
|
||||||
|
topPanel.add("5.2.left.center", objectComboBox);
|
||||||
|
|
||||||
|
return topPanel;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -1,700 +0,0 @@
|
|||||||
package com.langtech.plm.project;
|
|
||||||
|
|
||||||
import java.awt.BasicStroke;
|
|
||||||
import java.awt.BorderLayout;
|
|
||||||
import java.awt.Color;
|
|
||||||
import java.awt.Component;
|
|
||||||
import java.awt.Cursor;
|
|
||||||
import java.awt.Dimension;
|
|
||||||
import java.awt.Font;
|
|
||||||
import java.awt.Graphics;
|
|
||||||
import java.awt.Graphics2D;
|
|
||||||
import java.awt.GridLayout;
|
|
||||||
import java.awt.Point;
|
|
||||||
import java.awt.Polygon;
|
|
||||||
import java.awt.Stroke;
|
|
||||||
import java.awt.Toolkit;
|
|
||||||
import java.awt.event.FocusEvent;
|
|
||||||
import java.awt.event.FocusListener;
|
|
||||||
import java.awt.event.MouseAdapter;
|
|
||||||
import java.awt.event.MouseEvent;
|
|
||||||
import java.awt.event.MouseListener;
|
|
||||||
import java.awt.event.MouseMotionListener;
|
|
||||||
import java.text.SimpleDateFormat;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Calendar;
|
|
||||||
import java.util.Comparator;
|
|
||||||
import java.util.Date;
|
|
||||||
import java.util.Iterator;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import javax.swing.BorderFactory;
|
|
||||||
import javax.swing.JComponent;
|
|
||||||
import javax.swing.JFrame;
|
|
||||||
import javax.swing.JLabel;
|
|
||||||
import javax.swing.JPanel;
|
|
||||||
import javax.swing.JTextField;
|
|
||||||
import javax.swing.Popup;
|
|
||||||
import javax.swing.PopupFactory;
|
|
||||||
import javax.swing.SwingUtilities;
|
|
||||||
import javax.swing.event.AncestorEvent;
|
|
||||||
import javax.swing.event.AncestorListener;
|
|
||||||
|
|
||||||
public class DateChooser extends JPanel {
|
|
||||||
private static final long serialVersionUID = 4529266044762990227L;
|
|
||||||
private Date initDate;
|
|
||||||
private Calendar now;
|
|
||||||
private Calendar select;
|
|
||||||
private JPanel monthPanel;
|
|
||||||
private DateChooser.JP1 jp1;
|
|
||||||
private DateChooser.JP2 jp2;
|
|
||||||
private DateChooser.JP3 jp3;
|
|
||||||
private DateChooser.JP4 jp4;
|
|
||||||
private Font font;
|
|
||||||
private final DateChooser.LabelManager lm;
|
|
||||||
private SimpleDateFormat sdf;
|
|
||||||
private boolean isShow;
|
|
||||||
private Popup pop;
|
|
||||||
private JComponent showDate;
|
|
||||||
|
|
||||||
public static DateChooser getInstance() {
|
|
||||||
return new DateChooser();
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public static DateChooser getInstance(Date date) {
|
|
||||||
return new DateChooser(date);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static DateChooser getInstance(String format) {
|
|
||||||
return new DateChooser(format);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static DateChooser getInstance(Date date, String format) {
|
|
||||||
return new DateChooser(date, format);
|
|
||||||
}
|
|
||||||
|
|
||||||
DateChooser() {
|
|
||||||
this(new Date());
|
|
||||||
}
|
|
||||||
|
|
||||||
private DateChooser(Date date) {
|
|
||||||
this(date, "yyyy年MM月dd日");
|
|
||||||
}
|
|
||||||
|
|
||||||
private DateChooser(String format) {
|
|
||||||
this(new Date(), format);
|
|
||||||
}
|
|
||||||
|
|
||||||
private DateChooser(Date date, String format) {
|
|
||||||
this.now = Calendar.getInstance();
|
|
||||||
this.font = new Font("宋体", 0, 12);
|
|
||||||
this.lm = new DateChooser.LabelManager();
|
|
||||||
this.isShow = false;
|
|
||||||
this.initDate = date;
|
|
||||||
this.sdf = new SimpleDateFormat(format);
|
|
||||||
this.select = Calendar.getInstance();
|
|
||||||
this.select.setTime(this.initDate);
|
|
||||||
this.initPanel();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setEnabled(boolean b) {
|
|
||||||
super.setEnabled(b);
|
|
||||||
this.showDate.setEnabled(b);
|
|
||||||
}
|
|
||||||
|
|
||||||
public Date getDate() {
|
|
||||||
return this.select.getTime();
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getStrDate() {
|
|
||||||
return this.sdf.format(this.select.getTime());
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getStrDate(String format) {
|
|
||||||
this.sdf = new SimpleDateFormat(format);
|
|
||||||
return this.sdf.format(this.select.getTime());
|
|
||||||
}
|
|
||||||
|
|
||||||
private void initPanel() {
|
|
||||||
this.monthPanel = new JPanel(new BorderLayout());
|
|
||||||
this.monthPanel.setBorder(BorderFactory.createLineBorder(Color.BLUE));
|
|
||||||
JPanel up = new JPanel(new BorderLayout());
|
|
||||||
up.add(this.jp1 = new DateChooser.JP1(), "North");
|
|
||||||
up.add(this.jp2 = new DateChooser.JP2(), "Center");
|
|
||||||
this.monthPanel.add(this.jp3 = new DateChooser.JP3(), "Center");
|
|
||||||
this.monthPanel.add(up, "North");
|
|
||||||
this.monthPanel.add(this.jp4 = new DateChooser.JP4(), "South");
|
|
||||||
this.addAncestorListener(new AncestorListener() {
|
|
||||||
public void ancestorAdded(AncestorEvent event) {
|
|
||||||
}
|
|
||||||
|
|
||||||
public void ancestorRemoved(AncestorEvent event) {
|
|
||||||
}
|
|
||||||
|
|
||||||
public void ancestorMoved(AncestorEvent event) {
|
|
||||||
DateChooser.this.hidePanel();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
public void register(final JComponent showDate) {
|
|
||||||
this.showDate = showDate;
|
|
||||||
showDate.setRequestFocusEnabled(true);
|
|
||||||
showDate.addMouseListener(new MouseAdapter() {
|
|
||||||
public void mousePressed(MouseEvent me) {
|
|
||||||
showDate.requestFocusInWindow();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
this.setBackground(Color.WHITE);
|
|
||||||
this.add(showDate, "Center");
|
|
||||||
this.setPreferredSize(new Dimension(90, 25));
|
|
||||||
this.setBorder(BorderFactory.createLineBorder(Color.GRAY));
|
|
||||||
showDate.addMouseListener(new MouseAdapter() {
|
|
||||||
public void mouseEntered(MouseEvent me) {
|
|
||||||
if (showDate.isEnabled()) {
|
|
||||||
showDate.setCursor(new Cursor(12));
|
|
||||||
showDate.setForeground(Color.RED);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public void mouseExited(MouseEvent me) {
|
|
||||||
if (showDate.isEnabled()) {
|
|
||||||
showDate.setCursor(new Cursor(0));
|
|
||||||
showDate.setForeground(Color.BLACK);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public void mousePressed(MouseEvent me) {
|
|
||||||
if (showDate.isEnabled()) {
|
|
||||||
showDate.setForeground(Color.CYAN);
|
|
||||||
if (DateChooser.this.isShow) {
|
|
||||||
DateChooser.this.hidePanel();
|
|
||||||
} else {
|
|
||||||
DateChooser.this.showPanel(showDate);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public void mouseReleased(MouseEvent me) {
|
|
||||||
if (showDate.isEnabled()) {
|
|
||||||
showDate.setForeground(Color.BLACK);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
});
|
|
||||||
showDate.addFocusListener(new FocusListener() {
|
|
||||||
public void focusLost(FocusEvent e) {
|
|
||||||
DateChooser.this.hidePanel();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void focusGained(FocusEvent e) {
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
private void refresh() {
|
|
||||||
this.jp1.updateDate();
|
|
||||||
this.jp2.updateDate();
|
|
||||||
this.jp3.updateDate();
|
|
||||||
this.jp4.updateDate();
|
|
||||||
SwingUtilities.updateComponentTreeUI(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void commit() {
|
|
||||||
if (this.showDate instanceof JTextField) {
|
|
||||||
((JTextField) this.showDate).setText(this.sdf.format(this.select.getTime()));
|
|
||||||
} else if (this.showDate instanceof JLabel) {
|
|
||||||
((JLabel) this.showDate).setText(this.sdf.format(this.select.getTime()));
|
|
||||||
}
|
|
||||||
|
|
||||||
this.hidePanel();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void hidePanel() {
|
|
||||||
if (this.pop != null) {
|
|
||||||
this.isShow = false;
|
|
||||||
this.pop.hide();
|
|
||||||
this.pop = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
private void showPanel(Component owner) {
|
|
||||||
if (this.pop != null) {
|
|
||||||
this.pop.hide();
|
|
||||||
}
|
|
||||||
|
|
||||||
Point show = new Point(0, this.showDate.getHeight());
|
|
||||||
SwingUtilities.convertPointToScreen(show, this.showDate);
|
|
||||||
Dimension size = Toolkit.getDefaultToolkit().getScreenSize();
|
|
||||||
int x = show.x;
|
|
||||||
int y = show.y;
|
|
||||||
if (x < 0) {
|
|
||||||
x = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (x > size.width - 295) {
|
|
||||||
x = size.width - 295;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (y >= size.height - 170) {
|
|
||||||
y -= 188;
|
|
||||||
}
|
|
||||||
|
|
||||||
this.pop = PopupFactory.getSharedInstance().getPopup(owner, this.monthPanel, x, y);
|
|
||||||
this.pop.show();
|
|
||||||
this.isShow = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void main(String[] args) {
|
|
||||||
DateChooser dateChooser1 = getInstance("yyyy-MM-dd HH:mm");
|
|
||||||
DateChooser dateChooser2 = getInstance("yyyy-MM-dd");
|
|
||||||
JTextField showDate1 = new JTextField("单击选择日期");
|
|
||||||
JLabel showDate2 = new JLabel("单击选择日期");
|
|
||||||
dateChooser1.register(showDate1);
|
|
||||||
dateChooser2.register(showDate2);
|
|
||||||
JFrame jf = new JFrame("测试日期选择器");
|
|
||||||
jf.add(showDate1, "North");
|
|
||||||
jf.add(showDate2, "South");
|
|
||||||
jf.pack();
|
|
||||||
jf.setLocationRelativeTo((Component) null);
|
|
||||||
jf.setVisible(true);
|
|
||||||
jf.setDefaultCloseOperation(3);
|
|
||||||
}
|
|
||||||
|
|
||||||
private class JP1 extends JPanel {
|
|
||||||
private static final long serialVersionUID = -5638853772805561174L;
|
|
||||||
JLabel yearleft;
|
|
||||||
JLabel yearright;
|
|
||||||
JLabel monthleft;
|
|
||||||
JLabel monthright;
|
|
||||||
JLabel center;
|
|
||||||
JLabel centercontainer;
|
|
||||||
|
|
||||||
public JP1() {
|
|
||||||
super(new BorderLayout());
|
|
||||||
this.setBackground(new Color(160, 185, 215));
|
|
||||||
this.initJP1();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void initJP1() {
|
|
||||||
this.yearleft = new JLabel(" <<", 0);
|
|
||||||
this.yearleft.setToolTipText("上一年");
|
|
||||||
this.yearright = new JLabel(">> ", 0);
|
|
||||||
this.yearright.setToolTipText("下一年");
|
|
||||||
this.yearleft.setBorder(BorderFactory.createEmptyBorder(2, 0, 0, 0));
|
|
||||||
this.yearright.setBorder(BorderFactory.createEmptyBorder(2, 0, 0, 0));
|
|
||||||
this.monthleft = new JLabel(" <", 4);
|
|
||||||
this.monthleft.setToolTipText("上一月");
|
|
||||||
this.monthright = new JLabel("> ", 2);
|
|
||||||
this.monthright.setToolTipText("下一月");
|
|
||||||
this.monthleft.setBorder(BorderFactory.createEmptyBorder(2, 30, 0, 0));
|
|
||||||
this.monthright.setBorder(BorderFactory.createEmptyBorder(2, 0, 0, 30));
|
|
||||||
this.centercontainer = new JLabel("", 0);
|
|
||||||
this.centercontainer.setLayout(new BorderLayout());
|
|
||||||
this.center = new JLabel("", 0);
|
|
||||||
this.centercontainer.add(this.monthleft, "West");
|
|
||||||
this.centercontainer.add(this.center, "Center");
|
|
||||||
this.centercontainer.add(this.monthright, "East");
|
|
||||||
this.add(this.yearleft, "West");
|
|
||||||
this.add(this.centercontainer, "Center");
|
|
||||||
this.add(this.yearright, "East");
|
|
||||||
this.setPreferredSize(new Dimension(295, 25));
|
|
||||||
this.updateDate();
|
|
||||||
this.yearleft.addMouseListener(new MouseAdapter() {
|
|
||||||
public void mouseEntered(MouseEvent me) {
|
|
||||||
JP1.this.yearleft.setCursor(new Cursor(12));
|
|
||||||
JP1.this.yearleft.setForeground(Color.RED);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void mouseExited(MouseEvent me) {
|
|
||||||
JP1.this.yearleft.setCursor(new Cursor(0));
|
|
||||||
JP1.this.yearleft.setForeground(Color.BLACK);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void mousePressed(MouseEvent me) {
|
|
||||||
DateChooser.this.select.add(1, -1);
|
|
||||||
JP1.this.yearleft.setForeground(Color.WHITE);
|
|
||||||
DateChooser.this.refresh();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void mouseReleased(MouseEvent me) {
|
|
||||||
JP1.this.yearleft.setForeground(Color.BLACK);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
this.yearright.addMouseListener(new MouseAdapter() {
|
|
||||||
public void mouseEntered(MouseEvent me) {
|
|
||||||
JP1.this.yearright.setCursor(new Cursor(12));
|
|
||||||
JP1.this.yearright.setForeground(Color.RED);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void mouseExited(MouseEvent me) {
|
|
||||||
JP1.this.yearright.setCursor(new Cursor(0));
|
|
||||||
JP1.this.yearright.setForeground(Color.BLACK);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void mousePressed(MouseEvent me) {
|
|
||||||
DateChooser.this.select.add(1, 1);
|
|
||||||
JP1.this.yearright.setForeground(Color.WHITE);
|
|
||||||
DateChooser.this.refresh();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void mouseReleased(MouseEvent me) {
|
|
||||||
JP1.this.yearright.setForeground(Color.BLACK);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
this.monthleft.addMouseListener(new MouseAdapter() {
|
|
||||||
public void mouseEntered(MouseEvent me) {
|
|
||||||
JP1.this.monthleft.setCursor(new Cursor(12));
|
|
||||||
JP1.this.monthleft.setForeground(Color.RED);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void mouseExited(MouseEvent me) {
|
|
||||||
JP1.this.monthleft.setCursor(new Cursor(0));
|
|
||||||
JP1.this.monthleft.setForeground(Color.BLACK);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void mousePressed(MouseEvent me) {
|
|
||||||
DateChooser.this.select.add(2, -1);
|
|
||||||
JP1.this.monthleft.setForeground(Color.WHITE);
|
|
||||||
DateChooser.this.refresh();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void mouseReleased(MouseEvent me) {
|
|
||||||
JP1.this.monthleft.setForeground(Color.BLACK);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
this.monthright.addMouseListener(new MouseAdapter() {
|
|
||||||
public void mouseEntered(MouseEvent me) {
|
|
||||||
JP1.this.monthright.setCursor(new Cursor(12));
|
|
||||||
JP1.this.monthright.setForeground(Color.RED);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void mouseExited(MouseEvent me) {
|
|
||||||
JP1.this.monthright.setCursor(new Cursor(0));
|
|
||||||
JP1.this.monthright.setForeground(Color.BLACK);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void mousePressed(MouseEvent me) {
|
|
||||||
DateChooser.this.select.add(2, 1);
|
|
||||||
JP1.this.monthright.setForeground(Color.WHITE);
|
|
||||||
DateChooser.this.refresh();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void mouseReleased(MouseEvent me) {
|
|
||||||
JP1.this.monthright.setForeground(Color.BLACK);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
private void updateDate() {
|
|
||||||
this.center.setText(DateChooser.this.select.get(1) + "年" + (DateChooser.this.select.get(2) + 1) + "月");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private class JP2 extends JPanel {
|
|
||||||
private static final long serialVersionUID = -8176264838786175724L;
|
|
||||||
|
|
||||||
public JP2() {
|
|
||||||
this.setPreferredSize(new Dimension(295, 20));
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void paintComponent(Graphics g) {
|
|
||||||
g.setFont(DateChooser.this.font);
|
|
||||||
g.drawString("星期日 星期一 星期二 星期三 星期四 星期五 星期六", 5, 10);
|
|
||||||
g.drawLine(0, 15, this.getWidth(), 15);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void updateDate() {
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private class JP3 extends JPanel {
|
|
||||||
private static final long serialVersionUID = 43157272447522985L;
|
|
||||||
|
|
||||||
public JP3() {
|
|
||||||
super(new GridLayout(6, 7));
|
|
||||||
this.setPreferredSize(new Dimension(295, 100));
|
|
||||||
this.initJP3();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void initJP3() {
|
|
||||||
this.updateDate();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void updateDate() {
|
|
||||||
this.removeAll();
|
|
||||||
DateChooser.this.lm.clear();
|
|
||||||
Date temp = DateChooser.this.select.getTime();
|
|
||||||
Calendar select = Calendar.getInstance();
|
|
||||||
select.setTime(temp);
|
|
||||||
select.set(5, 1);
|
|
||||||
int index = select.get(7);
|
|
||||||
int sum = index == 1 ? 8 : index;
|
|
||||||
select.add(5, 0 - sum);
|
|
||||||
|
|
||||||
for (int i = 0; i < 42; ++i) {
|
|
||||||
select.add(5, 1);
|
|
||||||
DateChooser.this.lm.addLabel(DateChooser.this.new MyLabel(select.get(1), select.get(2), select.get(5)));
|
|
||||||
}
|
|
||||||
|
|
||||||
Iterator var6 = DateChooser.this.lm.getLabels().iterator();
|
|
||||||
|
|
||||||
while (var6.hasNext()) {
|
|
||||||
DateChooser.MyLabel my = (DateChooser.MyLabel) var6.next();
|
|
||||||
this.add(my);
|
|
||||||
}
|
|
||||||
|
|
||||||
select.setTime(temp);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private class JP4 extends JPanel {
|
|
||||||
private static final long serialVersionUID = -6391305687575714469L;
|
|
||||||
|
|
||||||
public JP4() {
|
|
||||||
super(new BorderLayout());
|
|
||||||
this.setPreferredSize(new Dimension(295, 20));
|
|
||||||
this.setBackground(new Color(160, 185, 215));
|
|
||||||
SimpleDateFormat sdf = new SimpleDateFormat("yyyy年MM月dd日");
|
|
||||||
final JLabel jl = new JLabel("今天: " + sdf.format(new Date()));
|
|
||||||
jl.setToolTipText("点击选择今天日期");
|
|
||||||
this.add(jl, "Center");
|
|
||||||
jl.addMouseListener(new MouseAdapter() {
|
|
||||||
public void mouseEntered(MouseEvent me) {
|
|
||||||
jl.setCursor(new Cursor(12));
|
|
||||||
jl.setForeground(Color.RED);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void mouseExited(MouseEvent me) {
|
|
||||||
jl.setCursor(new Cursor(0));
|
|
||||||
jl.setForeground(Color.BLACK);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void mousePressed(MouseEvent me) {
|
|
||||||
jl.setForeground(Color.WHITE);
|
|
||||||
DateChooser.this.select.setTime(new Date());
|
|
||||||
DateChooser.this.refresh();
|
|
||||||
DateChooser.this.commit();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void mouseReleased(MouseEvent me) {
|
|
||||||
jl.setForeground(Color.BLACK);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
private void updateDate() {
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private class LabelManager {
|
|
||||||
private List<DateChooser.MyLabel> list = new ArrayList();
|
|
||||||
|
|
||||||
public LabelManager() {
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<DateChooser.MyLabel> getLabels() {
|
|
||||||
return this.list;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void addLabel(DateChooser.MyLabel my) {
|
|
||||||
this.list.add(my);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void clear() {
|
|
||||||
this.list.clear();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setSelect(DateChooser.MyLabel my, boolean b) {
|
|
||||||
Iterator var4 = this.list.iterator();
|
|
||||||
|
|
||||||
while (var4.hasNext()) {
|
|
||||||
DateChooser.MyLabel m = (DateChooser.MyLabel) var4.next();
|
|
||||||
if (m.equals(my)) {
|
|
||||||
m.setSelected(true, b);
|
|
||||||
} else {
|
|
||||||
m.setSelected(false, b);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setSelect(Point p, boolean b) {
|
|
||||||
if (b) {
|
|
||||||
boolean findPrevious = false;
|
|
||||||
boolean findNext = false;
|
|
||||||
Iterator var6 = this.list.iterator();
|
|
||||||
|
|
||||||
while (var6.hasNext()) {
|
|
||||||
DateChooser.MyLabel mx = (DateChooser.MyLabel) var6.next();
|
|
||||||
if (mx.contains(p)) {
|
|
||||||
findNext = true;
|
|
||||||
if (mx.getIsSelected()) {
|
|
||||||
findPrevious = true;
|
|
||||||
} else {
|
|
||||||
mx.setSelected(true, b);
|
|
||||||
}
|
|
||||||
} else if (mx.getIsSelected()) {
|
|
||||||
findPrevious = true;
|
|
||||||
mx.setSelected(false, b);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (findPrevious && findNext) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
DateChooser.MyLabel temp = null;
|
|
||||||
Iterator var9 = this.list.iterator();
|
|
||||||
|
|
||||||
while (var9.hasNext()) {
|
|
||||||
DateChooser.MyLabel m = (DateChooser.MyLabel) var9.next();
|
|
||||||
if (m.contains(p)) {
|
|
||||||
temp = m;
|
|
||||||
} else if (m.getIsSelected()) {
|
|
||||||
m.setSelected(false, b);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (temp != null) {
|
|
||||||
temp.setSelected(true, b);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private class MyLabel extends JLabel
|
|
||||||
implements Comparator<DateChooser.MyLabel>, MouseListener, MouseMotionListener {
|
|
||||||
private static final long serialVersionUID = 3668734399227577214L;
|
|
||||||
private int year;
|
|
||||||
private int month;
|
|
||||||
private int day;
|
|
||||||
private boolean isSelected;
|
|
||||||
|
|
||||||
public MyLabel(int year, int month, int day) {
|
|
||||||
super("" + day, 0);
|
|
||||||
this.year = year;
|
|
||||||
this.day = day;
|
|
||||||
this.month = month;
|
|
||||||
this.addMouseListener(this);
|
|
||||||
this.addMouseMotionListener(this);
|
|
||||||
this.setFont(DateChooser.this.font);
|
|
||||||
if (month == DateChooser.this.select.get(2)) {
|
|
||||||
this.setForeground(Color.BLACK);
|
|
||||||
} else {
|
|
||||||
this.setForeground(Color.LIGHT_GRAY);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (day == DateChooser.this.select.get(5)) {
|
|
||||||
this.setBackground(new Color(160, 185, 215));
|
|
||||||
} else {
|
|
||||||
this.setBackground(Color.WHITE);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean getIsSelected() {
|
|
||||||
return this.isSelected;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setSelected(boolean b, boolean isDrag) {
|
|
||||||
this.isSelected = b;
|
|
||||||
if (b && !isDrag) {
|
|
||||||
int temp = DateChooser.this.select.get(2);
|
|
||||||
DateChooser.this.select.set(this.year, this.month, this.day);
|
|
||||||
if (temp == this.month) {
|
|
||||||
SwingUtilities.updateComponentTreeUI(DateChooser.this.jp3);
|
|
||||||
} else {
|
|
||||||
DateChooser.this.refresh();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
this.repaint();
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void paintComponent(Graphics g) {
|
|
||||||
if (this.day == DateChooser.this.select.get(5) && this.month == DateChooser.this.select.get(2)) {
|
|
||||||
g.setColor(new Color(160, 185, 215));
|
|
||||||
g.fillRect(0, 0, this.getWidth(), this.getHeight());
|
|
||||||
}
|
|
||||||
|
|
||||||
if (this.year == DateChooser.this.now.get(1) && this.month == DateChooser.this.now.get(2)
|
|
||||||
&& this.day == DateChooser.this.now.get(5)) {
|
|
||||||
Graphics2D gdx = (Graphics2D) g;
|
|
||||||
gdx.setColor(Color.RED);
|
|
||||||
Polygon p = new Polygon();
|
|
||||||
p.addPoint(0, 0);
|
|
||||||
p.addPoint(this.getWidth() - 1, 0);
|
|
||||||
p.addPoint(this.getWidth() - 1, this.getHeight() - 1);
|
|
||||||
p.addPoint(0, this.getHeight() - 1);
|
|
||||||
gdx.drawPolygon(p);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (this.isSelected) {
|
|
||||||
Stroke s = new BasicStroke(1.0F, 2, 2, 1.0F, new float[] { 2.0F, 2.0F }, 1.0F);
|
|
||||||
Graphics2D gd = (Graphics2D) g;
|
|
||||||
gd.setStroke(s);
|
|
||||||
gd.setColor(Color.BLACK);
|
|
||||||
Polygon px = new Polygon();
|
|
||||||
px.addPoint(0, 0);
|
|
||||||
px.addPoint(this.getWidth() - 1, 0);
|
|
||||||
px.addPoint(this.getWidth() - 1, this.getHeight() - 1);
|
|
||||||
px.addPoint(0, this.getHeight() - 1);
|
|
||||||
gd.drawPolygon(px);
|
|
||||||
}
|
|
||||||
|
|
||||||
super.paintComponent(g);
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean contains(Point p) {
|
|
||||||
return this.getBounds().contains(p);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void update() {
|
|
||||||
this.repaint();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void mouseClicked(MouseEvent e) {
|
|
||||||
}
|
|
||||||
|
|
||||||
public void mousePressed(MouseEvent e) {
|
|
||||||
this.isSelected = true;
|
|
||||||
this.update();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void mouseReleased(MouseEvent e) {
|
|
||||||
Point p = SwingUtilities.convertPoint(this, e.getPoint(), DateChooser.this.jp3);
|
|
||||||
DateChooser.this.lm.setSelect(p, false);
|
|
||||||
DateChooser.this.commit();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void mouseEntered(MouseEvent e) {
|
|
||||||
}
|
|
||||||
|
|
||||||
public void mouseExited(MouseEvent e) {
|
|
||||||
}
|
|
||||||
|
|
||||||
public void mouseDragged(MouseEvent e) {
|
|
||||||
Point p = SwingUtilities.convertPoint(this, e.getPoint(), DateChooser.this.jp3);
|
|
||||||
DateChooser.this.lm.setSelect(p, true);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void mouseMoved(MouseEvent e) {
|
|
||||||
}
|
|
||||||
|
|
||||||
public int compare(DateChooser.MyLabel o1, DateChooser.MyLabel o2) {
|
|
||||||
Calendar c1 = Calendar.getInstance();
|
|
||||||
c1.set(o1.year, o2.month, o1.day);
|
|
||||||
Calendar c2 = Calendar.getInstance();
|
|
||||||
c2.set(o2.year, o2.month, o2.day);
|
|
||||||
return c1.compareTo(c2);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,35 +0,0 @@
|
|||||||
package com.langtech.plm.project;
|
|
||||||
|
|
||||||
import org.eclipse.core.commands.AbstractHandler;
|
|
||||||
import org.eclipse.core.commands.ExecutionEvent;
|
|
||||||
import org.eclipse.core.commands.ExecutionException;
|
|
||||||
import org.eclipse.core.commands.IHandler;
|
|
||||||
|
|
||||||
import com.teamcenter.rac.aif.AIFDesktop;
|
|
||||||
import com.teamcenter.rac.aifrcp.AIFUtility;
|
|
||||||
import com.teamcenter.rac.kernel.TCSession;
|
|
||||||
import com.teamcenter.rac.util.MessageBox;
|
|
||||||
|
|
||||||
//创建常规文件夹结构
|
|
||||||
public class ProjectECRHandler extends AbstractHandler implements IHandler {
|
|
||||||
|
|
||||||
public Object execute(ExecutionEvent arg0) throws ExecutionException {
|
|
||||||
System.out.println("ProjectECRHandler");
|
|
||||||
TCSession session = (TCSession) AIFUtility.getCurrentApplication().getSession();
|
|
||||||
AIFDesktop desktop = AIFUtility.getActiveDesktop();
|
|
||||||
try {
|
|
||||||
//获取首选项中的值:表头=查询数据源=列宽
|
|
||||||
String[] option = session.getPreferenceService().getStringValues("CONNOR_ProjectECR");//A3oJ8Bs_J19vPC
|
|
||||||
if(option==null || option.length<2) {
|
|
||||||
MessageBox.post(desktop, "首选项CONNOR_ProjectECR配置不正确", "ERROR", MessageBox.ERROR);
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
new ProjectECRDialog(session, option);
|
|
||||||
}catch(Exception e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
MessageBox.post(desktop, "错误:"+e.getMessage(), "ERROR", MessageBox.ERROR);
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,376 +0,0 @@
|
|||||||
package com.langtech.plm.project;
|
|
||||||
|
|
||||||
import java.awt.Dimension;
|
|
||||||
import java.awt.Frame;
|
|
||||||
import java.awt.Toolkit;
|
|
||||||
import java.io.BufferedReader;
|
|
||||||
import java.io.File;
|
|
||||||
import java.io.FileInputStream;
|
|
||||||
import java.io.FileOutputStream;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.io.InputStream;
|
|
||||||
import java.io.InputStreamReader;
|
|
||||||
import java.util.LinkedHashMap;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.Vector;
|
|
||||||
|
|
||||||
import javax.swing.JFileChooser;
|
|
||||||
import javax.swing.JTable;
|
|
||||||
import javax.swing.filechooser.FileNameExtensionFilter;
|
|
||||||
import javax.swing.filechooser.FileSystemView;
|
|
||||||
|
|
||||||
import org.apache.poi.xwpf.usermodel.XWPFDocument;
|
|
||||||
import com.teamcenter.rac.aif.AbstractAIFDialog;
|
|
||||||
import com.teamcenter.rac.aif.kernel.AIFComponentContext;
|
|
||||||
import com.teamcenter.rac.aif.kernel.InterfaceAIFComponent;
|
|
||||||
import com.teamcenter.rac.commands.open.OpenFormDialog;
|
|
||||||
import com.teamcenter.rac.kernel.ListOfValuesInfo;
|
|
||||||
import com.teamcenter.rac.kernel.TCComponent;
|
|
||||||
import com.teamcenter.rac.kernel.TCComponentBOMLine;
|
|
||||||
import com.teamcenter.rac.kernel.TCComponentBOMWindow;
|
|
||||||
import com.teamcenter.rac.kernel.TCComponentBOMWindowType;
|
|
||||||
import com.teamcenter.rac.kernel.TCComponentContextList;
|
|
||||||
import com.teamcenter.rac.kernel.TCComponentDataset;
|
|
||||||
import com.teamcenter.rac.kernel.TCComponentDatasetType;
|
|
||||||
import com.teamcenter.rac.kernel.TCComponentForm;
|
|
||||||
import com.teamcenter.rac.kernel.TCComponentItemRevision;
|
|
||||||
import com.teamcenter.rac.kernel.TCComponentListOfValues;
|
|
||||||
import com.teamcenter.rac.kernel.TCComponentListOfValuesType;
|
|
||||||
import com.teamcenter.rac.kernel.TCComponentPseudoFolder;
|
|
||||||
import com.teamcenter.rac.kernel.TCComponentQuery;
|
|
||||||
import com.teamcenter.rac.kernel.TCComponentQueryType;
|
|
||||||
import com.teamcenter.rac.kernel.TCException;
|
|
||||||
import com.teamcenter.rac.kernel.TCQueryClause;
|
|
||||||
import com.teamcenter.rac.kernel.TCSession;
|
|
||||||
import com.teamcenter.rac.util.MessageBox;
|
|
||||||
|
|
||||||
public class TCUtil {
|
|
||||||
public static final int MINWIDTH = 1280;
|
|
||||||
public static final int MINHEIGHT = 768;
|
|
||||||
|
|
||||||
public static void fitToScreen(AbstractAIFDialog abstractAIFDialog) {
|
|
||||||
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
|
|
||||||
double screenWidth = screenSize.getWidth();
|
|
||||||
double screenHeight = screenSize.getHeight();
|
|
||||||
Dimension dialogSize = abstractAIFDialog.getSize();
|
|
||||||
if (screenWidth < MINWIDTH && dialogSize.getWidth() > screenWidth) {
|
|
||||||
abstractAIFDialog.setSize(new Dimension((int) Math.floor(screenWidth - 20), (int) Math.floor(dialogSize.getHeight())));
|
|
||||||
abstractAIFDialog.setLocation(10, (int) Math.floor(abstractAIFDialog.getLocation().getY()));
|
|
||||||
}
|
|
||||||
if (screenHeight < MINHEIGHT && dialogSize.getHeight() > screenHeight) {
|
|
||||||
abstractAIFDialog.setSize(new Dimension((int) Math.floor(dialogSize.getWidth()), (int) Math.floor(screenHeight - 20)));
|
|
||||||
abstractAIFDialog.setLocation((int) Math.floor(abstractAIFDialog.getLocation().getX()), 10);
|
|
||||||
}
|
|
||||||
/*
|
|
||||||
* if((screenWidth<MINWIDTH||screenHeight<MINHEIGHT)&&(dialogSize.getWidth()>
|
|
||||||
* MINWIDTH||dialogSize.getHeight()>MINHEIGHT)) { abstractAIFDialog.setSize(new
|
|
||||||
* Dimension((int)Math.floor(screenWidth-20),(int)Math.floor(screenHeight-20)));
|
|
||||||
* abstractAIFDialog.setLocation(10, 10); }
|
|
||||||
*/
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void fitToScreen(OpenFormDialog openFormDialog) {
|
|
||||||
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
|
|
||||||
double screenWidth = screenSize.getWidth();
|
|
||||||
double screenHeight = screenSize.getHeight();
|
|
||||||
Dimension dialogSize = openFormDialog.getSize();
|
|
||||||
if (screenWidth < MINWIDTH && dialogSize.getWidth() > screenWidth) {
|
|
||||||
openFormDialog.setSize(new Dimension((int) Math.floor(screenWidth - 20), (int) Math.floor(dialogSize.getHeight())));
|
|
||||||
openFormDialog.setLocation(10, (int) Math.floor(openFormDialog.getLocation().getY()));
|
|
||||||
}
|
|
||||||
if (screenHeight < MINHEIGHT && dialogSize.getHeight() > screenHeight) {
|
|
||||||
openFormDialog.setSize(new Dimension((int) Math.floor(dialogSize.getWidth()), (int) Math.floor(screenHeight - 20)));
|
|
||||||
openFormDialog.setLocation((int) Math.floor(openFormDialog.getLocation().getX()), 10);
|
|
||||||
}
|
|
||||||
/*
|
|
||||||
* if((screenWidth<MINWIDTH||screenHeight<MINHEIGHT)&&(dialogSize.getWidth()>
|
|
||||||
* MINWIDTH||dialogSize.getHeight()>MINHEIGHT)) { openFormDialog.setSize(new
|
|
||||||
* Dimension((int)Math.floor(screenWidth-20),(int)Math.floor(screenHeight-20)));
|
|
||||||
* openFormDialog.setLocation(10, 10); }
|
|
||||||
*/
|
|
||||||
}
|
|
||||||
|
|
||||||
public static TCComponentBOMWindow getWindow(TCSession session) throws Exception{
|
|
||||||
TCComponentBOMWindow window = null;
|
|
||||||
TCComponentBOMWindowType bomWinType = (TCComponentBOMWindowType) session.getTypeComponent("BOMWindow");
|
|
||||||
window = bomWinType.create(null);
|
|
||||||
return window;
|
|
||||||
}
|
|
||||||
|
|
||||||
@SuppressWarnings("deprecation")
|
|
||||||
public static TCComponentBOMLine getBOMLine(TCSession session,TCComponentBOMWindow window, TCComponentItemRevision revision)
|
|
||||||
throws Exception {
|
|
||||||
window.lock();
|
|
||||||
TCComponentBOMLine bomLine = window.setWindowTopLine(null, revision, null, null);
|
|
||||||
window.save();
|
|
||||||
window.unlock();
|
|
||||||
return bomLine;
|
|
||||||
}
|
|
||||||
public static TCComponentPseudoFolder getPseudoFolder(TCComponent parent, String relation)
|
|
||||||
throws Exception {
|
|
||||||
TCComponentPseudoFolder pseudoFolder = null;
|
|
||||||
AIFComponentContext[] comps = parent.getChildren();
|
|
||||||
if (comps != null && comps.length > 0 && comps[0] != null) {
|
|
||||||
for (int i = 0; i < comps.length; i++) {
|
|
||||||
TCComponent comp = (TCComponent) comps[i].getComponent();
|
|
||||||
if (comp instanceof TCComponentPseudoFolder) {
|
|
||||||
if (comp.isTypeOf("PseudoFolder")) {
|
|
||||||
// System.out.println("PseudoFolder type:" + comp.getDefaultPasteRelation());
|
|
||||||
if (comp.getDefaultPasteRelation().equalsIgnoreCase(relation)) {
|
|
||||||
pseudoFolder = (TCComponentPseudoFolder) comp;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return pseudoFolder;
|
|
||||||
}
|
|
||||||
public static TCComponentForm getItemRevisionMasterForm(TCComponentItemRevision revision) throws Exception {
|
|
||||||
if (revision != null) {
|
|
||||||
AIFComponentContext[] contexts = revision.getChildren("IMAN_master_form_rev");
|
|
||||||
if (contexts != null && contexts.length > 0) {
|
|
||||||
InterfaceAIFComponent component = contexts[0].getComponent();
|
|
||||||
if (component instanceof TCComponentForm) {
|
|
||||||
return (TCComponentForm) component;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static LinkedHashMap<String, String> getlovValues(TCSession session, String lovName) throws TCException {
|
|
||||||
LinkedHashMap<String, String> lovVal = new LinkedHashMap<String, String>();
|
|
||||||
TCComponentListOfValuesType lovType = (TCComponentListOfValuesType) session.getTypeComponent("ListOfValues");
|
|
||||||
TCComponentListOfValues[] lovs = lovType.find(lovName);
|
|
||||||
if (lovs != null && lovs.length > 0) {
|
|
||||||
TCComponentListOfValues lov = lovs[0];
|
|
||||||
ListOfValuesInfo lovInfo = lov.getListOfValues();
|
|
||||||
String[] code = lovInfo.getStringListOfValues();
|
|
||||||
String[] name = lovInfo.getLOVDisplayValues();
|
|
||||||
if (code != null && name != null) {
|
|
||||||
for (int i = 0; i < code.length; i++) {
|
|
||||||
// System.out.printf("code[%d]=%s name[%d]=%s \n", i, code[i], i, name[i]);
|
|
||||||
lovVal.put(code[i], name[i]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return lovVal;
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static String getTableValue(JTable table, int row, int col){
|
|
||||||
Object val = table.getValueAt(row, col);
|
|
||||||
if(val==null)
|
|
||||||
return "";
|
|
||||||
else
|
|
||||||
return val.toString();
|
|
||||||
}
|
|
||||||
public static TCComponent[] query(TCSession session, String queryName, String[] aKey, String[] aVal) throws Exception {
|
|
||||||
TCComponentQueryType imanQueryType = (TCComponentQueryType) session.getTypeComponent("ImanQuery");
|
|
||||||
TCComponentQuery imancomponentquery = (TCComponentQuery) imanQueryType.find(queryName);
|
|
||||||
if (imancomponentquery == null) {
|
|
||||||
throw new Exception("未找到查询构建器 " + queryName + "!");
|
|
||||||
}
|
|
||||||
aKey = session.getTextService().getTextValues(aKey);
|
|
||||||
// for (int i = 0; i < aKey.length; i++) {
|
|
||||||
// System.out.println(aKey[i] + "===============" + aVal[i]);
|
|
||||||
// }
|
|
||||||
TCComponentContextList componentContextList = imancomponentquery.getExecuteResultsList(aKey, aVal);
|
|
||||||
return componentContextList.toTCComponentArray();
|
|
||||||
}
|
|
||||||
public static TCComponent[] query(TCSession session, String queryName, Vector<String> Keys, Vector<String> Vals) throws Exception {
|
|
||||||
TCComponentQueryType imanQueryType = (TCComponentQueryType) session.getTypeComponent("ImanQuery");
|
|
||||||
TCComponentQuery imancomponentquery = (TCComponentQuery) imanQueryType.find(queryName);
|
|
||||||
if (imancomponentquery == null) {
|
|
||||||
System.out.println("未找到查询构建器" + queryName);
|
|
||||||
throw new Exception("Query:"+queryName+" cannot find");
|
|
||||||
}
|
|
||||||
TCQueryClause[] qc = imancomponentquery.describe();
|
|
||||||
// Map<String, String> clauseMap = new HashMap<>();
|
|
||||||
for(TCQueryClause c : qc) {
|
|
||||||
String key = c.getUserEntryNameDisplay();
|
|
||||||
String value = c.getDefaultValue();
|
|
||||||
// System.out.println(key + "==>" + c.getAttributeName());
|
|
||||||
if(!value.trim().isEmpty() && !Keys.contains(key)) {
|
|
||||||
if(key.isEmpty())
|
|
||||||
Keys.add(c.getAttributeName());
|
|
||||||
else
|
|
||||||
Keys.add(key);
|
|
||||||
Vals.add(value);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
int size = Keys.size();
|
|
||||||
String[] keyA = new String[size];
|
|
||||||
String[] valueA = new String[size];
|
|
||||||
for(int i=0; i<size; i++) {
|
|
||||||
keyA[i] = Keys.get(i);
|
|
||||||
valueA[i] = Vals.get(i);
|
|
||||||
System.out.println(keyA[i] + ":" + valueA[i]);
|
|
||||||
}
|
|
||||||
TCComponentContextList componentContextList = imancomponentquery.getExecuteResultsList(keyA, valueA);
|
|
||||||
return componentContextList.toTCComponentArray();
|
|
||||||
}
|
|
||||||
public static String getSerialNo(TCSession session, String itemId, String objectType) throws Exception {
|
|
||||||
TCComponent[] comps = null;
|
|
||||||
if (objectType.equals("")) {
|
|
||||||
comps = query(session, "零组件 ID", new String[] { "ItemID" }, new String[] { itemId + "*" });
|
|
||||||
} else {
|
|
||||||
comps = query(session, "零组件...", new String[] { "ItemID", "Type" }, new String[] { itemId + "*", objectType });
|
|
||||||
}
|
|
||||||
// System.out.println("getSerialNo comps.len:" + (comps == null ? 0 : comps.length));
|
|
||||||
if (comps.length > 0) {
|
|
||||||
Integer maxId = 0;
|
|
||||||
for (TCComponent comp : comps) {
|
|
||||||
String pid = comp.getProperty("item_id");
|
|
||||||
System.out.println("pid:" + pid);
|
|
||||||
String pidSuffix = pid.substring(pid.length() - 3);
|
|
||||||
if (Integer.parseInt(pidSuffix) > maxId) {
|
|
||||||
maxId = Integer.parseInt(pidSuffix);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return String.format("%03d", maxId + 1);
|
|
||||||
}
|
|
||||||
return "001";
|
|
||||||
}
|
|
||||||
|
|
||||||
public static File saveExcelChooser() {
|
|
||||||
File dir = null;
|
|
||||||
JFileChooser chooser = new JFileChooser();
|
|
||||||
chooser.setAcceptAllFileFilterUsed(false);
|
|
||||||
// File currentDir = FileSystemView.getFileSystemView().getDefaultDirectory();
|
|
||||||
File desktopDir = FileSystemView.getFileSystemView().getHomeDirectory();
|
|
||||||
chooser.setCurrentDirectory(desktopDir);
|
|
||||||
String saveType[] = { "xlsx" };
|
|
||||||
chooser.setFileFilter(new FileNameExtensionFilter("Excel工作簿", saveType));
|
|
||||||
int returnVal = chooser.showSaveDialog(new Frame());
|
|
||||||
if (returnVal == JFileChooser.APPROVE_OPTION) {
|
|
||||||
dir = chooser.getSelectedFile();
|
|
||||||
String path = dir.getPath();
|
|
||||||
if(!path.toLowerCase().endsWith(".xlsx")) {
|
|
||||||
path += ".xlsx";
|
|
||||||
dir = new File(path);
|
|
||||||
}
|
|
||||||
System.out.println("saveExcelChooser1:" + path);
|
|
||||||
}
|
|
||||||
return dir;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static File saveExcelChooser(String defaultFile) {
|
|
||||||
File dir = null;
|
|
||||||
JFileChooser chooser = new JFileChooser();
|
|
||||||
chooser.setAcceptAllFileFilterUsed(false);
|
|
||||||
// File currentDir = FileSystemView.getFileSystemView().getDefaultDirectory();
|
|
||||||
File desktopDir = FileSystemView.getFileSystemView().getHomeDirectory();
|
|
||||||
chooser.setCurrentDirectory(desktopDir);
|
|
||||||
chooser.setSelectedFile(new File(defaultFile));
|
|
||||||
String saveType[] = { "xlsx" };
|
|
||||||
chooser.setFileFilter(new FileNameExtensionFilter("Excel工作簿", saveType));
|
|
||||||
int returnVal = chooser.showSaveDialog(new Frame());
|
|
||||||
if (returnVal == JFileChooser.APPROVE_OPTION) {
|
|
||||||
dir = chooser.getSelectedFile();
|
|
||||||
String path = dir.getPath();
|
|
||||||
if(!path.toLowerCase().endsWith(".xlsx")) {
|
|
||||||
path += ".xlsx";
|
|
||||||
dir = new File(path);
|
|
||||||
}
|
|
||||||
if(dir.exists())
|
|
||||||
dir.delete();
|
|
||||||
// System.out.println("saveExcelChooser1:" + dir.getPath());
|
|
||||||
}
|
|
||||||
return dir;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static boolean contains(String[] array, String str) {
|
|
||||||
for(String s : array) {
|
|
||||||
// System.out.println("contains:"+s+"="+str);
|
|
||||||
if(s.equals(str))
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Map<String, String> executeToMap(InputStream in){
|
|
||||||
System.out.println("Read properties file");
|
|
||||||
try {
|
|
||||||
BufferedReader reader = new BufferedReader(new InputStreamReader(in, "utf-8"));
|
|
||||||
String line = null;
|
|
||||||
Map<String, String> resultMap = new LinkedHashMap<>(16);
|
|
||||||
if (reader.ready()) {
|
|
||||||
while (null != (line = reader.readLine())) {
|
|
||||||
if (line.length() <= 0 || line.contains("#") || !line.contains("=")) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
resultMap.put(line.substring(0, line.indexOf("=")), line.substring(line.indexOf("=") + 1));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
in.close();
|
|
||||||
reader.close();
|
|
||||||
return resultMap;
|
|
||||||
} catch (Exception e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
MessageBox.post("Find properties file failed", "ERROR", MessageBox.ERROR);
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static TCComponentDataset createExcelDataset(TCSession session, File file, String datasetName) throws Exception {
|
|
||||||
String refType = null, objType = null, fileName = null;
|
|
||||||
fileName = file.getName().toLowerCase();
|
|
||||||
if (fileName.endsWith("xls")) {
|
|
||||||
refType = "excel";
|
|
||||||
objType = "MSExcel";
|
|
||||||
} else if (fileName.endsWith("xlsx")) {
|
|
||||||
refType = "excel";
|
|
||||||
objType = "MSExcelX";
|
|
||||||
}
|
|
||||||
TCComponentDatasetType compType = (TCComponentDatasetType) session.getTypeService().getTypeComponent("Dataset");
|
|
||||||
TCComponentDataset dataset = compType.create(datasetName, "description", objType);
|
|
||||||
dataset.setFiles(new String[] { file.getAbsolutePath() }, new String[] { refType });
|
|
||||||
return dataset;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void deleteWarning(File file) throws IOException {
|
|
||||||
FileInputStream input = null;
|
|
||||||
FileOutputStream output = null;
|
|
||||||
try {
|
|
||||||
input = new FileInputStream(file);
|
|
||||||
XWPFDocument doc = new XWPFDocument(input);
|
|
||||||
// XWPFParagraph para = doc.getParagraphs().get(0);
|
|
||||||
// System.out.println("para.getRuns:"+para.getRuns().size());
|
|
||||||
// for(XWPFRun run : para.getRuns()) {
|
|
||||||
// System.out.println("run:"+run.getText(0));
|
|
||||||
// }
|
|
||||||
doc.removeBodyElement(0);
|
|
||||||
// para.removeRun(0);
|
|
||||||
// System.out.println("para.getRuns:"+para.getRuns().size()+" getParagraphs:"+doc.getParagraphs().get(0).getText());
|
|
||||||
// para.setPageBreak(false);
|
|
||||||
output = new FileOutputStream(file.getPath());
|
|
||||||
doc.write(output);
|
|
||||||
doc.close();
|
|
||||||
}catch (Exception e) {
|
|
||||||
throw e;
|
|
||||||
}finally {
|
|
||||||
if(input!=null)
|
|
||||||
input.close();
|
|
||||||
if(output!=null)
|
|
||||||
output.close();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Vector<TCComponent> getChildren(TCComponent parent, String relation, String name) throws Exception {
|
|
||||||
Vector<TCComponent> result = new Vector<>();
|
|
||||||
AIFComponentContext[] children;
|
|
||||||
if(relation==null || relation.isEmpty())
|
|
||||||
children = parent.getChildren();
|
|
||||||
else
|
|
||||||
children = parent.getChildren(relation);
|
|
||||||
for(AIFComponentContext c : children) {
|
|
||||||
TCComponent comp = (TCComponent) c.getComponent();
|
|
||||||
if(comp.getProperty("object_name").equals(name))
|
|
||||||
result.add(comp);
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
Loading…
Reference in new issue