Compare commits
16 Commits
Author | SHA1 | Date |
---|---|---|
![]() |
fc7596dfae | 5 months ago |
|
04aff3093f | 5 months ago |
|
0dfbaeede6 | 5 months ago |
|
d535b6aa82 | 6 months ago |
|
01187105a5 | 6 months ago |
|
bf5a9a54f9 | 6 months ago |
|
fd63bc99fd | 6 months ago |
|
3952e9fd98 | 6 months ago |
|
07dfccd9b6 | 6 months ago |
|
6276640680 | 6 months ago |
|
670784ab29 | 6 months ago |
|
abac41c543 | 6 months ago |
|
c54c85f5ed | 7 months ago |
|
317c9cc1b5 | 7 months ago |
|
abc24fee89 | 7 months ago |
|
56cde5eaed | 7 months ago |
@ -0,0 +1,72 @@
|
||||
package com.langtech.plm.bg;
|
||||
|
||||
import java.awt.Component;
|
||||
import java.awt.event.MouseAdapter;
|
||||
import java.awt.event.MouseEvent;
|
||||
|
||||
import javax.swing.JCheckBox;
|
||||
import javax.swing.JComponent;
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.JTable;
|
||||
import javax.swing.SwingConstants;
|
||||
import javax.swing.UIManager;
|
||||
import javax.swing.table.DefaultTableModel;
|
||||
import javax.swing.table.JTableHeader;
|
||||
import javax.swing.table.TableCellRenderer;
|
||||
|
||||
public class CheckHeaderCellRenderer implements TableCellRenderer {
|
||||
DefaultTableModel tableModel;
|
||||
JTableHeader tableHeader;
|
||||
final JCheckBox selectBox;
|
||||
|
||||
public CheckHeaderCellRenderer(final JTable table) {
|
||||
this.tableModel = (DefaultTableModel) table.getModel();
|
||||
this.tableHeader = table.getTableHeader();
|
||||
selectBox = new JCheckBox(tableModel.getColumnName(0));
|
||||
selectBox.setSelected(false);
|
||||
tableHeader.addMouseListener(new MouseAdapter() {
|
||||
public void mouseClicked(MouseEvent e) {
|
||||
if (e.getClickCount() > 0) {
|
||||
// 获得选中列
|
||||
int selectColumn = tableHeader.columnAtPoint(e.getPoint());
|
||||
if (selectColumn == 0) {
|
||||
boolean value = !selectBox.isSelected();
|
||||
selectBox.setSelected(value);
|
||||
// tableModel.selectAllOrNull(value);
|
||||
tableHeader.repaint();
|
||||
if(value) {
|
||||
for(int i=0;i<table.getRowCount();i++) {
|
||||
table.setValueAt("1", i, 0);
|
||||
}
|
||||
}else {
|
||||
for(int i=0;i<table.getRowCount();i++) {
|
||||
table.setValueAt("0", i, 0);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus,
|
||||
int row, int column) {
|
||||
// TODO Auto-generated method stub
|
||||
String valueStr = (String) value;
|
||||
JLabel label = new JLabel(valueStr);
|
||||
label.setHorizontalAlignment(SwingConstants.CENTER); // 表头标签剧中
|
||||
selectBox.setHorizontalAlignment(SwingConstants.CENTER);// 表头标签剧中
|
||||
selectBox.setBorderPainted(true);
|
||||
JComponent component = (column == 0) ? selectBox : label;
|
||||
|
||||
component.setForeground(tableHeader.getForeground());
|
||||
component.setBackground(tableHeader.getBackground());
|
||||
component.setFont(tableHeader.getFont());
|
||||
component.setBorder(UIManager.getBorder("TableHeader.cellBorder"));
|
||||
|
||||
return component;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,153 @@
|
||||
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]);
|
||||
list.add(split[3]);
|
||||
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),selectedItem,arrayList.get(2));
|
||||
System.out.println("newnewnwenew");
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,93 @@
|
||||
package com.langtech.plm.bg;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.awt.Component;
|
||||
import java.time.LocalDate;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.time.format.DateTimeParseException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
import javax.swing.JTable;
|
||||
|
||||
|
||||
public class QDRWTableColorRender extends TableColorRender {
|
||||
public LinkedHashMap<String,LinkedHashMap<String, ArrayList<LinkedHashMap<String, String>>>> valueMap;
|
||||
public LinkedHashMap<Integer, String> colorMap;
|
||||
|
||||
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
|
||||
Component renderer = super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
|
||||
|
||||
|
||||
String id = (String)table.getValueAt(row, 1);
|
||||
LinkedHashMap<String, ArrayList<LinkedHashMap<String, String>>> linkedHashMap = valueMap.get(id);
|
||||
//System.out.println("colorMap======"+colorMap.toString());
|
||||
for (Entry<Integer, String> map : colorMap.entrySet()) {
|
||||
Integer columnColor = map.getKey();
|
||||
if(column == columnColor) {
|
||||
//System.out.println("columnColor========"+columnColor);
|
||||
String prefValue = map.getValue();
|
||||
String[] split = prefValue.split("\\.");
|
||||
ArrayList<LinkedHashMap<String, String>> arrayList = linkedHashMap.get(split[0]);
|
||||
String sjwcsj = "";
|
||||
String RWXDSJ = "";
|
||||
String jhjs = "";
|
||||
|
||||
for (int i = 0; i < arrayList.size(); i++) {
|
||||
|
||||
if(arrayList.get(i).containsKey("SJWCSJ")) {
|
||||
sjwcsj = arrayList.get(i).get("SJWCSJ");
|
||||
}
|
||||
if(arrayList.get(i).containsKey("RWXDSJ")) {
|
||||
RWXDSJ = arrayList.get(i).get("RWXDSJ");
|
||||
}
|
||||
if(arrayList.get(i).containsKey("JHJS")) {
|
||||
jhjs = arrayList.get(i).get("JHJS");
|
||||
}
|
||||
}
|
||||
//System.out.println("sjwcsj========"+sjwcsj);
|
||||
//System.out.println("jhks========"+jhks);
|
||||
//System.out.println("jhjs========"+jhjs);
|
||||
if(sjwcsj != null && !sjwcsj.isEmpty()) {
|
||||
renderer.setBackground(Color.GREEN);
|
||||
}else {
|
||||
if(jhjs != null && !jhjs.isEmpty() && RWXDSJ != null && !RWXDSJ.isEmpty()) {
|
||||
if(isNotAfterCurrentDate(jhjs)) {
|
||||
renderer.setBackground(Color.RED);
|
||||
|
||||
|
||||
// System.out.println("row==="+row+"===column==="+column);
|
||||
}else {
|
||||
//setBackground(Color.YELLOW);
|
||||
renderer.setBackground(Color.GRAY);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
return renderer;
|
||||
}
|
||||
|
||||
|
||||
public static boolean isNotAfterCurrentDate(String dateStr) {
|
||||
// 定义日期格式
|
||||
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
|
||||
|
||||
try {
|
||||
// 解析字符串为 LocalDate 对象
|
||||
LocalDate inputDate = LocalDate.parse(dateStr, formatter);
|
||||
// 获取当前日期
|
||||
LocalDate currentDate = LocalDate.now();
|
||||
|
||||
// 比较两个日期
|
||||
return !inputDate.isAfter(currentDate); // 返回 true 如果输入日期 <= 当前日期
|
||||
|
||||
} catch (DateTimeParseException e) {
|
||||
// 处理解析异常
|
||||
System.out.println("Invalid date format: " + e.getMessage());
|
||||
return false; // 或者你也可以选择抛出异常,或者根据需求做其他处理
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,114 @@
|
||||
package com.langtech.plm.bg;
|
||||
|
||||
import javax.swing.SwingUtilities;
|
||||
|
||||
import org.eclipse.core.commands.AbstractHandler;
|
||||
import org.eclipse.core.commands.ExecutionEvent;
|
||||
import org.eclipse.core.commands.ExecutionException;
|
||||
|
||||
import com.teamcenter.rac.aif.AbstractAIFUIApplication;
|
||||
import com.teamcenter.rac.aif.kernel.InterfaceAIFComponent;
|
||||
import com.teamcenter.rac.aifrcp.AIFUtility;
|
||||
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;
|
||||
|
||||
|
||||
public class RWFPHandler extends AbstractHandler {
|
||||
|
||||
private AbstractAIFUIApplication app;
|
||||
private TCSession session;
|
||||
// private InterfaceAIFComponent target;
|
||||
|
||||
@Override
|
||||
public Object execute(ExecutionEvent event) throws ExecutionException {
|
||||
app = AIFUtility.getCurrentApplication();
|
||||
session = (TCSession) app.getSession();
|
||||
// target = app.getTargetComponent();
|
||||
// if (target == null || !(target instanceof TCComponentFolder)) {
|
||||
// MessageBox.post(app.getDesktop(), "请选择系统总目录文件夹进行导入!", "导入位置选择", MessageBox.WARNING);
|
||||
// return null;
|
||||
// }
|
||||
|
||||
//判断是否可编辑
|
||||
boolean readOnly = true;
|
||||
String userId = "";
|
||||
try {
|
||||
userId = session.getUser().getUserId();
|
||||
} catch (TCException e3) {
|
||||
// TODO Auto-generated catch block
|
||||
e3.printStackTrace();
|
||||
}
|
||||
String[] templates = session.getPreferenceService().getStringValues("Connor_TaskForm_ChangeDateButton_User");
|
||||
if(templates != null && templates.length > 0 && userId != null && !userId.isEmpty()) {
|
||||
if(templates[0].contains(userId)) {
|
||||
readOnly = false;
|
||||
}
|
||||
}
|
||||
final boolean readOnlyFinal = readOnly;
|
||||
InterfaceAIFComponent target = app.getTargetComponent();
|
||||
if(target instanceof TCComponentItem) {
|
||||
TCComponentItem item = (TCComponentItem)target;
|
||||
String type = item.getType();
|
||||
try {
|
||||
String id = item.getStringProperty("item_id");
|
||||
String objectString = item.getStringProperty("object_string");
|
||||
SwingUtilities.invokeLater(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
new RWFPDialog(session,type,id,objectString,readOnlyFinal);
|
||||
//d.setModal(true);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
} catch (TCException e1) {
|
||||
// TODO Auto-generated catch block
|
||||
e1.printStackTrace();
|
||||
}
|
||||
}else if(target instanceof TCComponentItemRevision){
|
||||
|
||||
TCComponentItemRevision rev = (TCComponentItemRevision)target;
|
||||
TCComponentItem item = null;
|
||||
try {
|
||||
item = rev.getItem();
|
||||
} catch (TCException e2) {
|
||||
// TODO Auto-generated catch block
|
||||
e2.printStackTrace();
|
||||
}
|
||||
String type = item.getType();
|
||||
try {
|
||||
String id = item.getStringProperty("item_id");
|
||||
String objectString = item.getStringProperty("object_string");
|
||||
SwingUtilities.invokeLater(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
new RWFPDialog(session,type,id,objectString,readOnlyFinal);
|
||||
//d.setModal(true);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
} catch (TCException e1) {
|
||||
// TODO Auto-generated catch block
|
||||
e1.printStackTrace();
|
||||
}
|
||||
|
||||
}else {
|
||||
MessageBox.post(app.getDesktop(), "请选择正确对象!", "提示", MessageBox.WARNING);
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,54 @@
|
||||
package com.langtech.plm.bg;
|
||||
|
||||
import java.awt.Component;
|
||||
import java.util.List;
|
||||
|
||||
import javax.swing.JCheckBox;
|
||||
import javax.swing.JRadioButton;
|
||||
import javax.swing.JTable;
|
||||
import javax.swing.SwingConstants;
|
||||
import javax.swing.event.ChangeEvent;
|
||||
import javax.swing.event.EventListenerList;
|
||||
import javax.swing.table.TableCellRenderer;
|
||||
|
||||
import com.teamcenter.rac.treetable.JTreeTable;
|
||||
|
||||
|
||||
public class TableCellCheckboxRenderer extends JCheckBox implements
|
||||
TableCellRenderer {
|
||||
private List<Integer> processRows;
|
||||
protected EventListenerList listenerList = new EventListenerList();
|
||||
protected ChangeEvent changeEvent = new ChangeEvent(this);
|
||||
//private TestTreeTableModel tableModel;
|
||||
|
||||
public List<Integer> getProcessRows() {
|
||||
return processRows;
|
||||
}
|
||||
|
||||
public void setProcessRows(List<Integer> processRows) {
|
||||
this.processRows = processRows;
|
||||
|
||||
}
|
||||
public TableCellCheckboxRenderer(final JTable table) {
|
||||
}
|
||||
public TableCellCheckboxRenderer(final JTreeTable table) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Component getTableCellRendererComponent(JTable table, Object value,
|
||||
boolean isSelected, boolean hasFocus, int row, int column) {
|
||||
// TODO Auto-generated method stub
|
||||
this.setHorizontalAlignment(SwingConstants.CENTER);// ±íÍ·±êÇ©¾çÖÐ
|
||||
// this.setBorderPainted(true);
|
||||
|
||||
if(value != null)
|
||||
{
|
||||
this.setSelected(value.toString().equals("1"));
|
||||
}
|
||||
else
|
||||
{
|
||||
this.setSelected(false);
|
||||
}
|
||||
return this;
|
||||
}
|
||||
}
|
@ -0,0 +1,71 @@
|
||||
package com.langtech.plm.bg;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.awt.Component;
|
||||
import java.util.HashMap;
|
||||
|
||||
import javax.swing.JTable;
|
||||
import javax.swing.table.DefaultTableCellRenderer;
|
||||
import javax.swing.table.TableCellRenderer;
|
||||
|
||||
public class TableColorRender implements TableCellRenderer {
|
||||
//
|
||||
public static final DefaultTableCellRenderer DEFAULT_RENDERER = new DefaultTableCellRenderer();
|
||||
|
||||
//IntegerÁÐ String±êʶ ColorÑÕÉ«
|
||||
public HashMap<Integer, HashMap<String, Color>> allForegroundInfos = new HashMap<Integer, HashMap<String, Color>>();
|
||||
public HashMap<Integer, Integer> allFColorColumn = new HashMap<Integer, Integer>();
|
||||
|
||||
//IntegerÁÐ String±êʶ ColorÑÕÉ«
|
||||
public HashMap<Integer, HashMap<String, Color>> allBackgroundInfos = new HashMap<Integer, HashMap<String, Color>>();
|
||||
public HashMap<Integer, Integer> allBColorColumn = new HashMap<Integer, Integer>();
|
||||
|
||||
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
|
||||
Component renderer = DEFAULT_RENDERER.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
|
||||
|
||||
if (value != null && value instanceof String) {
|
||||
Color foreground = table.getForeground();
|
||||
Color background = table.getBackground();
|
||||
if (isSelected) {
|
||||
background = new Color(10, 36, 106);
|
||||
}
|
||||
|
||||
Boolean bSetFG = false;
|
||||
Integer infoCol = allFColorColumn.get(column);
|
||||
if (infoCol != null) {
|
||||
HashMap<String, Color> fgc = allForegroundInfos.get(infoCol);
|
||||
if (fgc != null) {
|
||||
String infoValue = table.getValueAt(row, infoCol).toString();
|
||||
Color color = fgc.get(infoValue);
|
||||
if (color != null) {
|
||||
foreground = color;
|
||||
bSetFG = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Boolean bSetBG = false;
|
||||
infoCol = allBColorColumn.get(column);
|
||||
if (infoCol != null) {
|
||||
HashMap<String, Color> bgc = allBackgroundInfos.get(infoCol);
|
||||
if (bgc != null) {
|
||||
String infoValue = table.getValueAt(row, infoCol).toString();
|
||||
Color color = bgc.get(infoValue);
|
||||
if (color != null) {
|
||||
background = color;
|
||||
bSetBG = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!bSetFG && !bSetBG && isSelected) {
|
||||
foreground = Color.WHITE;
|
||||
}
|
||||
|
||||
renderer.setForeground(foreground);
|
||||
renderer.setBackground(background);
|
||||
}
|
||||
|
||||
return renderer;
|
||||
}
|
||||
}
|
@ -0,0 +1,94 @@
|
||||
package com.langtech.plm.modifyEffectiveTime;
|
||||
|
||||
import org.jdesktop.swingx.JXDatePicker;
|
||||
|
||||
import javax.swing.*;
|
||||
import javax.swing.table.TableCellEditor;
|
||||
import java.awt.*;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
import java.util.EventObject;
|
||||
|
||||
public class DatePickerEditor extends AbstractCellEditor implements TableCellEditor {
|
||||
|
||||
private JXDatePicker datePicker;
|
||||
private JTable table;
|
||||
private int row;
|
||||
private int column;
|
||||
|
||||
public DatePickerEditor() {
|
||||
datePicker = new JXDatePicker();
|
||||
// 设置日期格式
|
||||
datePicker.setFormats(new SimpleDateFormat("yyyy-MM-dd"));
|
||||
datePicker.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
fireEditingStopped();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int row, int column) {
|
||||
this.table = table;
|
||||
this.row = row;
|
||||
this.column = column;
|
||||
|
||||
System.out.println("getTableCellEditorComponent: "+value);
|
||||
if (value instanceof Date) {
|
||||
datePicker.setDate((Date) value);
|
||||
} else {
|
||||
datePicker.setDate(null);
|
||||
}
|
||||
return datePicker;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getCellEditorValue() {
|
||||
try {
|
||||
// 获取用户输入的文本
|
||||
String text = datePicker.getEditor().getText();
|
||||
|
||||
if (text.trim().isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// 尝试将输入解析为日期
|
||||
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
|
||||
format.setLenient(false); // 严格解析日期格式
|
||||
return format.parse(text);
|
||||
} catch (Exception e) {
|
||||
// 如果解析失败,打印错误信息并返回当前日期选择器的值
|
||||
System.err.println("Invalid date format: " + e.getMessage());
|
||||
}
|
||||
|
||||
// 返回日期选择器当前的值
|
||||
return datePicker.getDate();
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public boolean isCellEditable(EventObject anEvent) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean stopCellEditing() {
|
||||
System.out.println("stopCellEditing: " + datePicker.getDate());
|
||||
fireEditingStopped();
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean shouldSelectCell(EventObject anEvent) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void cancelCellEditing() {
|
||||
super.cancelCellEditing();
|
||||
}
|
||||
}
|
@ -0,0 +1,265 @@
|
||||
package com.langtech.plm.modifyEffectiveTime;
|
||||
|
||||
import java.awt.BorderLayout;
|
||||
import java.awt.Component;
|
||||
import java.awt.Dimension;
|
||||
import java.awt.FlowLayout;
|
||||
import java.awt.Font;
|
||||
import java.text.ParseException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
import javax.swing.BorderFactory;
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.JScrollPane;
|
||||
import javax.swing.JTable;
|
||||
import javax.swing.SwingConstants;
|
||||
import javax.swing.border.EmptyBorder;
|
||||
import javax.swing.table.DefaultTableCellRenderer;
|
||||
import javax.swing.table.DefaultTableModel;
|
||||
import javax.swing.table.TableCellEditor;
|
||||
import javax.swing.table.TableCellRenderer;
|
||||
import javax.swing.table.TableColumnModel;
|
||||
|
||||
import org.jdesktop.swingx.JXDatePicker;
|
||||
|
||||
import com.teamcenter.rac.aifrcp.AIFUtility;
|
||||
import com.teamcenter.rac.kernel.TCComponentItemRevision;
|
||||
import com.teamcenter.rac.kernel.TCSession;
|
||||
import com.teamcenter.rac.kernel.TCUserService;
|
||||
import com.teamcenter.rac.util.MessageBox;
|
||||
|
||||
public class ModifyEffectiveTimeDialog extends JFrame implements Runnable {
|
||||
private JTable table;
|
||||
|
||||
private JButton okButton;
|
||||
private boolean flag;
|
||||
|
||||
private final String title;
|
||||
private final String[] columnNames;
|
||||
private Object[][] data;
|
||||
private int[] dateIndex;
|
||||
private boolean pass;
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
||||
}
|
||||
|
||||
public ModifyEffectiveTimeDialog(String title, Object... args) {
|
||||
this.title = title;
|
||||
this.columnNames = (String[]) args[0];
|
||||
this.data = (Object[][]) args[1];
|
||||
this.dateIndex = (int[]) args[2];
|
||||
this.pass = (boolean) args[3];
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
// TODO Auto-generated method stub
|
||||
initUI();
|
||||
}
|
||||
|
||||
public void setWithHeight(int with, int height) {
|
||||
this.setSize(with, height);
|
||||
}
|
||||
|
||||
public void initUI() {
|
||||
this.setTitle(title);
|
||||
// 初始化所有信息
|
||||
initializationComponent();
|
||||
|
||||
// 添加内容到JFrame 并设置它的位置
|
||||
JPanel bottomPanel = getBottomPanel();
|
||||
// 创建表格和滚动条
|
||||
JPanel tableScrollPane = createTable();
|
||||
tableScrollPane.setPreferredSize(new Dimension(700, 200)); // 设置滚动条的大小
|
||||
|
||||
this.getContentPane().add(tableScrollPane, BorderLayout.CENTER);
|
||||
this.getContentPane().add(bottomPanel, BorderLayout.SOUTH);
|
||||
// 设置窗口居中
|
||||
this.setLocationRelativeTo(null);
|
||||
this.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
|
||||
// 设置可见性
|
||||
this.setVisible(true);
|
||||
}
|
||||
|
||||
public void initializationComponent() {
|
||||
okButton = new JButton("应用");
|
||||
okButton.setEnabled(pass);
|
||||
}
|
||||
|
||||
public JPanel createTable() {
|
||||
JPanel panel = new JPanel(new BorderLayout(10, 10));
|
||||
panel.setBorder(new EmptyBorder(20, 20, 10, 20));
|
||||
|
||||
// 创建 DefaultTableModel 实例
|
||||
DefaultTableModel model = new DefaultTableModel(data, columnNames) {
|
||||
@Override
|
||||
public boolean isCellEditable(int row, int column) {
|
||||
if (column == 0) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class<?> getColumnClass(int columnIndex) {
|
||||
if (columnIndex == 1) {
|
||||
return Date.class;
|
||||
}
|
||||
return super.getColumnClass(columnIndex);
|
||||
}
|
||||
};
|
||||
table = new JTable(model);
|
||||
|
||||
// 设置行高
|
||||
table.setRowHeight(25); // 设置行高为30像素
|
||||
table.setFont(new Font("微软雅黑", Font.PLAIN, 12));
|
||||
// 禁用列重排序
|
||||
table.getTableHeader().setReorderingAllowed(false);
|
||||
// 禁用自动调整列宽
|
||||
// table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
|
||||
// 设置表格填满视口高度
|
||||
// table.setFillsViewportHeight(true);
|
||||
|
||||
// 设置列宽
|
||||
TableColumnModel columnModel = table.getColumnModel();
|
||||
columnModel.getColumn(0).setPreferredWidth(300);
|
||||
columnModel.getColumn(1).setPreferredWidth(143);
|
||||
|
||||
table.removeColumn(columnModel.getColumn(columnModel.getColumnCount() - 1));
|
||||
|
||||
// 自定义渲染器,使所有列居中对齐
|
||||
DefaultTableCellRenderer centerRenderer = new DefaultTableCellRenderer() {
|
||||
@Override
|
||||
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected,
|
||||
boolean hasFocus, int row, int column) {
|
||||
Component c = super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
|
||||
((JLabel) c).setHorizontalAlignment(SwingConstants.CENTER); // 设置文本居中对齐
|
||||
return c;
|
||||
}
|
||||
};
|
||||
|
||||
// 应用居中对齐渲染器
|
||||
for (int i = 0; i < columnModel.getColumnCount(); i++) {
|
||||
columnModel.getColumn(i).setCellRenderer(centerRenderer);
|
||||
}
|
||||
|
||||
// 自定义渲染器
|
||||
TableCellRenderer dateRenderer = (JTable table, Object value, boolean isSelected, boolean hasFocus, int row,
|
||||
int column) -> {
|
||||
JXDatePicker datePicker = new JXDatePicker();
|
||||
if (value instanceof Date) {
|
||||
datePicker.setFormats(new SimpleDateFormat("yyyy-MM-dd"));
|
||||
datePicker.setDate((Date) value);
|
||||
}
|
||||
return datePicker;
|
||||
};
|
||||
// 自定义编辑器
|
||||
TableCellEditor dateEditor = new DatePickerEditor();
|
||||
|
||||
// 为 IssueDate 和 MaterialDeliveryTime 列设置日期选择器
|
||||
for (int index : dateIndex) {
|
||||
// 设置渲染器和编辑器
|
||||
table.getColumnModel().getColumn(index).setCellRenderer(dateRenderer);
|
||||
table.getColumnModel().getColumn(index).setCellEditor(dateEditor);
|
||||
}
|
||||
|
||||
// 创建 JScrollPane 并设置水平滚动条始终可见
|
||||
JScrollPane scrollPane = new JScrollPane(table);
|
||||
// scrollPane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
|
||||
|
||||
// 添加表格到中心区域
|
||||
panel.add(scrollPane, BorderLayout.CENTER);
|
||||
return panel;
|
||||
}
|
||||
|
||||
public JPanel getBottomPanel() {
|
||||
// TODO Auto-generated method stub
|
||||
JPanel bottomPanel = new JPanel(new FlowLayout(FlowLayout.CENTER, 70, 10));
|
||||
bottomPanel.setBorder(BorderFactory.createEmptyBorder(-10, 0, 10, 0));
|
||||
bottomPanel.add(this.okButton);
|
||||
// 添加监听
|
||||
okButton.addActionListener(e -> {
|
||||
flag = true;
|
||||
List<String[]> tableData = getTableData();
|
||||
if (tableData != null) {
|
||||
tableData.forEach(rowData -> {
|
||||
System.out.println(Arrays.toString(rowData));
|
||||
});
|
||||
}
|
||||
|
||||
if (flag) {
|
||||
MessageBox.post("修改成功! ", "Info", MessageBox.INFORMATION);
|
||||
this.dispose(); // 关闭窗口
|
||||
} else {
|
||||
MessageBox.post("生效时间不允许超出两行", "Error", MessageBox.ERROR);
|
||||
}
|
||||
});
|
||||
return bottomPanel;
|
||||
}
|
||||
|
||||
public List<String[]> getTableData() {
|
||||
DefaultTableModel model = (DefaultTableModel) table.getModel();
|
||||
int rowCount = model.getRowCount();
|
||||
int columnCount = model.getColumnCount();
|
||||
|
||||
List<String[]> tableData = new ArrayList<>();
|
||||
|
||||
int count = 0;
|
||||
for (int row = 0; row < rowCount; row++) {
|
||||
Object obj = model.getValueAt(row, 1);
|
||||
if (obj instanceof Date && obj != null) {
|
||||
count++;
|
||||
if (count == 3) {
|
||||
flag = false;
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
setByPass(true);
|
||||
try {
|
||||
for (int row = 0; row < rowCount; row++) {
|
||||
String name = (String) model.getValueAt(row, 0);
|
||||
Object obj = model.getValueAt(row, 1);
|
||||
System.out.println("name: " + name + " || date: " + obj);
|
||||
TCComponentItemRevision rev = (TCComponentItemRevision) model.getValueAt(row, 2);
|
||||
rev.setDateProperty("ly6_deadline", (Date) obj);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
// TODO: handle exception
|
||||
e.printStackTrace();
|
||||
MessageBox.post(e.getMessage(), "Error", MessageBox.ERROR);
|
||||
}
|
||||
setByPass(false);
|
||||
return tableData;
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
public void setByPass(boolean pass) {
|
||||
TCUserService userservice = null;
|
||||
if (userservice == null) {
|
||||
userservice = ((TCSession) AIFUtility.getCurrentApplication().getSession()).getUserService();
|
||||
}
|
||||
Object[] obj = new Object[1];
|
||||
obj[0] = "origin";
|
||||
try {
|
||||
if (pass) {
|
||||
userservice.call("CONNOR_open_bypass", obj);
|
||||
System.out.println("旁路已开启");
|
||||
} else {
|
||||
userservice.call("CONNOR_close_bypass", obj);
|
||||
System.out.println("旁路已关闭");
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,165 @@
|
||||
package com.langtech.plm.modifyEffectiveTime;
|
||||
|
||||
import java.text.ParseException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
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.AIFComponentContext;
|
||||
import com.teamcenter.rac.aif.kernel.InterfaceAIFComponent;
|
||||
import com.teamcenter.rac.aifrcp.AIFUtility;
|
||||
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.TCComponentItemRevision;
|
||||
import com.teamcenter.rac.kernel.TCException;
|
||||
import com.teamcenter.rac.kernel.TCPreferenceService;
|
||||
import com.teamcenter.rac.kernel.TCSession;
|
||||
import com.teamcenter.rac.util.MessageBox;
|
||||
|
||||
public class ModifyEffectiveTimeHandler extends AbstractHandler {
|
||||
|
||||
@Override
|
||||
public Object execute(ExecutionEvent arg0) throws ExecutionException {
|
||||
AbstractAIFApplication app = AIFUtility.getCurrentApplication();
|
||||
TCSession session = (TCSession) app.getSession();
|
||||
|
||||
TCPreferenceService preferenceService = session.getPreferenceService();
|
||||
String[] preValues = preferenceService.getStringValues("LY__FormulaDeadLine_Config");
|
||||
if ((preValues != null && preValues.length < 3) || preValues == null) {
|
||||
MessageBox.post("LY__FormulaDeadLine_Config配置错误", "Error", MessageBox.ERROR);
|
||||
return null;
|
||||
}
|
||||
|
||||
String[] types = preValues[0].split(";");
|
||||
String[] childTypes = preValues[1].split(";");
|
||||
String[] permissionPeo = preValues[2].split(";");
|
||||
|
||||
TCComponent targetComponent = (TCComponent)app.getTargetComponent();
|
||||
|
||||
String targetType = "";
|
||||
try {
|
||||
if(targetComponent instanceof TCComponentItemRevision) {
|
||||
targetType = targetComponent.getType();
|
||||
}else if(targetComponent instanceof TCComponentBOMLine) {
|
||||
targetType = ((TCComponentBOMLine) targetComponent).getItemRevision().getType();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
boolean isExist = false;
|
||||
System.out.println("当前类型:" + targetType);
|
||||
for (String type : types) {
|
||||
System.out.println("当前配置类型:" + type);
|
||||
if (type.equals(targetType)) {
|
||||
isExist = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!isExist) {
|
||||
MessageBox.post("请选择指定类型的牌号版本执行修改配方生效日期功能", "Error", MessageBox.ERROR);
|
||||
return null;
|
||||
}
|
||||
|
||||
boolean pass = false;
|
||||
String userName = session.getUserName();
|
||||
System.out.println("当前用户:" + userName);
|
||||
for (String name : permissionPeo) {
|
||||
System.out.println("当前配置用户:" + name);
|
||||
if (userName.equals(name)) {
|
||||
pass = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
Object[][] data = null;
|
||||
try {
|
||||
List<TCComponentItemRevision> revList = getChildBom(session, targetComponent, childTypes);
|
||||
data = new Object[revList.size()][];
|
||||
|
||||
for (int i = 0; i < revList.size(); i++) {
|
||||
TCComponentItemRevision tempRev = revList.get(i);
|
||||
Object[] tempData = new Object[3];
|
||||
tempData[0] = tempRev.getProperty("object_string");
|
||||
tempData[1] = parseDate(tempRev.getProperty("ly6_deadline"));
|
||||
tempData[2] = tempRev;
|
||||
|
||||
data[i] = tempData;
|
||||
}
|
||||
} catch (TCException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
// 表格列标题
|
||||
String[] columnNames = new String[] { "对象", "生效时间", "TCComponent" };
|
||||
int[] dateIndex = new int[] { 1 };
|
||||
ModifyEffectiveTimeDialog dialog = new ModifyEffectiveTimeDialog("修改配方生效时间", columnNames, data, dateIndex,
|
||||
pass);
|
||||
dialog.setWithHeight(500, 300);
|
||||
|
||||
new Thread(dialog).start();
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public List<TCComponentItemRevision> getChildBom(TCSession session, TCComponent targetComponent,
|
||||
String[] childTypes) throws TCException {
|
||||
// TODO Auto-generated method stub
|
||||
TCComponentBOMLine topLine = null;
|
||||
if (targetComponent instanceof TCComponentItemRevision) {
|
||||
TCComponentItemRevision rev = (TCComponentItemRevision) targetComponent;
|
||||
TCComponentBOMWindowType winType = (TCComponentBOMWindowType) session.getTypeComponent("BOMWindow");
|
||||
TCComponentBOMWindow view = winType.create(null);
|
||||
topLine = view.setWindowTopLine(rev.getItem(), rev, null, null);
|
||||
} else if (targetComponent instanceof TCComponentBOMLine) {
|
||||
topLine = ((TCComponentBOMLine) targetComponent);
|
||||
}
|
||||
|
||||
boolean hasChildren = topLine.hasChildren();
|
||||
List<TCComponentItemRevision> revList = new ArrayList<TCComponentItemRevision>();
|
||||
if (!hasChildren) {
|
||||
return revList;
|
||||
}
|
||||
|
||||
String revType = "";
|
||||
AIFComponentContext[] childrena = topLine.getChildren();
|
||||
for (AIFComponentContext children : childrena) {
|
||||
TCComponentBOMLine component = (TCComponentBOMLine) children.getComponent();
|
||||
TCComponentItemRevision itemRevision = component.getItemRevision();
|
||||
// revType = itemRevision.getProperty("object_type");
|
||||
revType = itemRevision.getType();
|
||||
System.out.println("子类对象类型getType()获取的值:" + revType);
|
||||
for (String type : childTypes) {
|
||||
System.out.println("子类配置对象类型:" + type);
|
||||
if (revType.equals(type)) {
|
||||
revList.add(itemRevision);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
return revList;
|
||||
}
|
||||
|
||||
public Date parseDate(String dateString) {
|
||||
if (dateString == null || dateString.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
|
||||
try {
|
||||
return sdf.parse(dateString);
|
||||
} catch (ParseException e) {
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
File diff suppressed because it is too large
Load Diff
@ -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;
|
||||
}
|
||||
}
|
Loading…
Reference in new issue