|
|
package com.langtech.plm.createProjectStruct;
|
|
|
|
|
|
|
|
|
import java.awt.BorderLayout;
|
|
|
import java.awt.Dimension;
|
|
|
import java.awt.event.ActionEvent;
|
|
|
import java.awt.event.ActionListener;
|
|
|
import java.awt.event.ItemEvent;
|
|
|
import java.awt.event.ItemListener;
|
|
|
import java.util.HashMap;
|
|
|
|
|
|
import javax.swing.JButton;
|
|
|
import javax.swing.JComboBox;
|
|
|
import javax.swing.JLabel;
|
|
|
import javax.swing.JPanel;
|
|
|
import javax.swing.JScrollPane;
|
|
|
import javax.swing.JTextField;
|
|
|
import javax.swing.JTree;
|
|
|
import javax.swing.UIManager;
|
|
|
import javax.swing.tree.DefaultTreeModel;
|
|
|
|
|
|
import com.teamcenter.rac.aif.AbstractAIFApplication;
|
|
|
import com.teamcenter.rac.aif.AbstractAIFDialog;
|
|
|
import com.teamcenter.rac.kernel.TCComponent;
|
|
|
import com.teamcenter.rac.kernel.TCComponentFolder;
|
|
|
import com.teamcenter.rac.kernel.TCComponentFolderType;
|
|
|
import com.teamcenter.rac.kernel.TCException;
|
|
|
import com.teamcenter.rac.kernel.TCSession;
|
|
|
import com.teamcenter.rac.util.MessageBox;
|
|
|
import com.teamcenter.services.rac.core.ReservationService;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@SuppressWarnings("serial")
|
|
|
public class CreateProjectStructDialog extends AbstractAIFDialog{
|
|
|
|
|
|
protected TCSession session;
|
|
|
private TCComponent target;
|
|
|
private JLabel modelLabel;
|
|
|
private JComboBox<String> modelBox;
|
|
|
private JTextField nameField;
|
|
|
private JLabel nameLabel;
|
|
|
private JTree jtree;
|
|
|
private JButton okButton;
|
|
|
private JButton celButton;
|
|
|
private HashMap<String, String> preMap = new HashMap<String, String>();
|
|
|
|
|
|
public static final String preName = "connor_LY6_FolderTemp";
|
|
|
|
|
|
public CreateProjectStructDialog(AbstractAIFApplication app) {
|
|
|
super(false);
|
|
|
this.session = (TCSession) app.getSession();
|
|
|
this.target = (TCComponent) app.getTargetComponent();
|
|
|
try {
|
|
|
initUI();
|
|
|
} catch (Exception e) {
|
|
|
// TODO Auto-generated catch block
|
|
|
e.printStackTrace();
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public void run() {
|
|
|
try {
|
|
|
initUI();
|
|
|
//UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
|
|
|
UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
|
|
|
} catch (Exception e) {
|
|
|
e.printStackTrace();
|
|
|
}
|
|
|
}
|
|
|
|
|
|
private void initUI() throws Exception {
|
|
|
this.setTitle("<22><><EFBFBD><EFBFBD>ģ<EFBFBD>崴<EFBFBD><E5B4B4><EFBFBD>ļ<EFBFBD><C4BC><EFBFBD>");
|
|
|
Dimension dim = new Dimension(950, 600);
|
|
|
this.setPreferredSize(new Dimension(1000, 600));
|
|
|
this.setMinimumSize(dim);
|
|
|
this.setLayout(new BorderLayout());
|
|
|
modelLabel = new JLabel("ģ<>壺");
|
|
|
modelBox = new JComboBox<String>();
|
|
|
modelBox.setPreferredSize(new Dimension(200,30));
|
|
|
String[] prefVals = KUtil.getPrefVals(session, preName);
|
|
|
if(prefVals == null) {
|
|
|
MessageBox.post("<22><>ѡ<EFBFBD><D1A1> <20><>" + preName + " <09><><EFBFBD><EFBFBD><EFBFBD>ڻ<EFBFBD>ֵΪ<D6B5><CEAA>", "<22><>ʾ ", MessageBox.INFORMATION);
|
|
|
return;
|
|
|
}
|
|
|
else {
|
|
|
for(String prefVal : prefVals) {
|
|
|
if(prefVal.contains("=")) {
|
|
|
String[] split = prefVal.split("=");
|
|
|
modelBox.addItem(split[0]);
|
|
|
preMap.put(split[0], split[1]);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
nameLabel = new JLabel("<22><>Ʒͼ<C6B7>ţ<EFBFBD>");
|
|
|
nameField = new JTextField();
|
|
|
nameField.setPreferredSize(new Dimension(200,30));
|
|
|
JPanel topPanel = new JPanel();
|
|
|
topPanel.add(modelLabel);
|
|
|
topPanel.add(modelBox);
|
|
|
topPanel.add(nameLabel);
|
|
|
topPanel.add(nameField);
|
|
|
|
|
|
//String lookAndFeel = "com.sun.java.swing.plaf.windows.WindowsClassicLookAndFeel";
|
|
|
//String lookAndFeel = "com.sun.java.swing.plaf.windows.WindowsLookAndFeel";
|
|
|
String lookAndFeel = "javax.swing.plaf.metal.MetalLookAndFeel";
|
|
|
UIManager.setLookAndFeel(lookAndFeel);
|
|
|
|
|
|
jtree = new JTree();
|
|
|
initTree(jtree);
|
|
|
JScrollPane centerPane = new JScrollPane(jtree);
|
|
|
|
|
|
JPanel buttonPanel = new JPanel();
|
|
|
okButton = new JButton("<22><><EFBFBD><EFBFBD>");
|
|
|
celButton = new JButton("ȡ<><C8A1>");
|
|
|
buttonPanel.add(okButton);
|
|
|
buttonPanel.add(celButton);
|
|
|
|
|
|
this.add(BorderLayout.NORTH,topPanel);
|
|
|
this.add(BorderLayout.CENTER,centerPane);
|
|
|
this.add(BorderLayout.SOUTH,buttonPanel);
|
|
|
|
|
|
addListeners();
|
|
|
showDialog();
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
* @param tree
|
|
|
*/
|
|
|
private void initTree(JTree tree){
|
|
|
String puid = preMap.get(modelBox.getSelectedItem());
|
|
|
TCComponent component;
|
|
|
try {
|
|
|
component = session.stringToComponent(puid);
|
|
|
if(component == null || !(component instanceof TCComponentFolder)) {
|
|
|
MessageBox.post(puid + " <20><>puid<69><64>TC<54>в<EFBFBD><D0B2><EFBFBD><EFBFBD>ڶ<EFBFBD><DAB6><EFBFBD><EFBFBD><EFBFBD><EFBFBD>߸<EFBFBD>puid<69><64>Ӧ<EFBFBD>IJ<EFBFBD><C4B2>ǡ<EFBFBD><C7A1>ļ<EFBFBD><C4BC>С<EFBFBD><D0A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>", "<22>쳣", MessageBox.ERROR);
|
|
|
return;
|
|
|
}
|
|
|
else {
|
|
|
CheckBoxTreeNode rootNode = new CheckBoxTreeNode(component.getStringProperty("object_name"));
|
|
|
buildTree(component,rootNode);
|
|
|
DefaultTreeModel model = new DefaultTreeModel(rootNode);
|
|
|
tree.addMouseListener(new CheckBoxTreeNodeSelectionListener());
|
|
|
tree.setModel(model);
|
|
|
tree.setCellRenderer(new CheckBoxTreeCellRenderer());
|
|
|
//չ<><D5B9><EFBFBD><EFBFBD><EFBFBD>нڵ㲢ѡ<E3B2A2><D1A1>
|
|
|
for (int i = 0; i < tree.getRowCount(); i++) {
|
|
|
tree.expandRow(i);
|
|
|
}
|
|
|
rootNode.setSelected(true);
|
|
|
}
|
|
|
} catch (TCException e) {
|
|
|
e.printStackTrace();
|
|
|
}
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* <20>ݹ鴴<DDB9><E9B4B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ӽڵ<D3BD>
|
|
|
* @param component
|
|
|
* @param rootNode
|
|
|
* @throws TCException
|
|
|
*/
|
|
|
private void buildTree(TCComponent component, CheckBoxTreeNode rootNode) throws TCException {
|
|
|
TCComponent[] relatedComponent = component.getRelatedComponents("contents");
|
|
|
if(relatedComponent != null) {
|
|
|
for (TCComponent child : relatedComponent) {
|
|
|
CheckBoxTreeNode childNode = new CheckBoxTreeNode(child.getStringProperty("object_name"));
|
|
|
rootNode.add(childNode);
|
|
|
buildTree(child,childNode);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* <20>ݹ<EFBFBD><DDB9>½<EFBFBD><C2BD>ļ<EFBFBD><C4BC>нṹ
|
|
|
* @param root <20><><EFBFBD>ڵ<EFBFBD>
|
|
|
* @param folder <20><><EFBFBD>ڵ<EFBFBD><DAB5><EFBFBD><EFBFBD>ɵ<EFBFBD><C9B5>ļ<EFBFBD><C4BC><EFBFBD>
|
|
|
* @param folderType
|
|
|
* @throws Exception
|
|
|
*/
|
|
|
private void createFolderStruct(CheckBoxTreeNode root, TCComponentFolder parentFolder,
|
|
|
TCComponentFolderType folderType,boolean ifTop) throws Exception {
|
|
|
if(root.isSelected()) {
|
|
|
if(ifTop) {
|
|
|
for (int i = 0; i < root.getChildCount(); i++) {
|
|
|
CheckBoxTreeNode child = (CheckBoxTreeNode) root.getChildAt(i);
|
|
|
createFolderStruct(child,parentFolder,folderType,false);
|
|
|
}
|
|
|
}
|
|
|
else {
|
|
|
TCComponentFolder folder = KUtil.createFolderBySOA(folderType.getTypeName(), root.toString());
|
|
|
parentFolder.add("contents", folder);
|
|
|
for (int i = 0; i < root.getChildCount(); i++) {
|
|
|
CheckBoxTreeNode child = (CheckBoxTreeNode) root.getChildAt(i);
|
|
|
createFolderStruct(child,folder,folderType,false);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
private void addListeners() {
|
|
|
this.celButton.addActionListener(new ActionListener() {
|
|
|
@Override
|
|
|
public void actionPerformed(ActionEvent e) {
|
|
|
disposeDialog();
|
|
|
}
|
|
|
});
|
|
|
this.okButton.addActionListener(new ActionListener() {
|
|
|
@Override
|
|
|
public void actionPerformed(ActionEvent e) {
|
|
|
String name = nameField.getText();
|
|
|
if (name.isEmpty()) {
|
|
|
MessageBox.post("<22><><EFBFBD><EFBFBD>д<EFBFBD><D0B4>Ʒͼ<C6B7>ţ<EFBFBD>", "<22><>ʾ ", MessageBox.INFORMATION);
|
|
|
} else {
|
|
|
TCComponentFolderType folderType;
|
|
|
try {
|
|
|
KUtil.setByPass(true);
|
|
|
folderType = (TCComponentFolderType) session.getTypeComponent("LD6_CusProdFolder");
|
|
|
TCComponentFolder folder = KUtil.createFolderBySOA(folderType.getTypeName(), name);
|
|
|
//TCComponentFolder folder = folderType.create(name, "", "LD6_CusProdFolder");
|
|
|
target.add("contents", folder);
|
|
|
CheckBoxTreeNode root = (CheckBoxTreeNode) jtree.getModel().getRoot();
|
|
|
createFolderStruct(root,folder,(TCComponentFolderType) session.getTypeComponent("LD6_ProjMaFolder"),true);
|
|
|
KUtil.setByPass(false);
|
|
|
disposeDialog();
|
|
|
} catch (Exception e1) {
|
|
|
e1.printStackTrace();
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
});
|
|
|
this.modelBox.addItemListener(new ItemListener() {
|
|
|
public void itemStateChanged(ItemEvent event) {
|
|
|
if(event.getStateChange() == ItemEvent.SELECTED) {
|
|
|
//<2F><><EFBFBD><EFBFBD>ˢ<EFBFBD><CBA2><EFBFBD><EFBFBD>
|
|
|
jtree.setModel(null);
|
|
|
initTree(jtree);
|
|
|
}else if(event.getStateChange() == ItemEvent.DESELECTED){
|
|
|
|
|
|
}
|
|
|
}
|
|
|
});
|
|
|
}
|
|
|
|
|
|
}
|