You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
95 lines
3.3 KiB
95 lines
3.3 KiB
package com.connor.jd.plm.action;
|
|
|
|
import java.awt.BorderLayout;
|
|
import java.awt.Dimension;
|
|
import java.util.ArrayList;
|
|
import java.util.List;
|
|
|
|
import javax.swing.JLabel;
|
|
import javax.swing.JOptionPane;
|
|
import javax.swing.JPanel;
|
|
|
|
import com.connor.jd.plm.utils.DialogUtil;
|
|
import com.connor.jd.plm.utils.DialogUtil.TableMsg;
|
|
import com.teamcenter.rac.aif.AbstractAIFApplication;
|
|
import com.teamcenter.rac.aif.common.actions.AbstractAIFAction;
|
|
import com.teamcenter.rac.kernel.TCComponent;
|
|
import com.teamcenter.rac.kernel.TCComponentFolder;
|
|
import com.teamcenter.rac.kernel.TCComponentItemRevision;
|
|
import com.teamcenter.rac.kernel.TCSession;
|
|
|
|
public class BatchReviseAction extends AbstractAIFAction {
|
|
private TCSession session;
|
|
private TCComponentFolder folder;
|
|
|
|
public BatchReviseAction(AbstractAIFApplication arg0, String arg1) {
|
|
super(arg0, arg1);
|
|
this.session = (TCSession) arg0.getSession();
|
|
TCComponent target = (TCComponent) arg0.getTargetComponent();
|
|
System.out.println("类型===>" + target.getType());
|
|
if (target instanceof TCComponentFolder) {
|
|
this.folder = (TCComponentFolder) target;
|
|
}
|
|
}
|
|
|
|
@Override
|
|
public void run() {
|
|
if (folder == null) {
|
|
return;
|
|
}
|
|
try {
|
|
TCComponent[] comps = folder.getRelatedComponents("contents");
|
|
List<String[]> unpublished = new ArrayList<String[]>();
|
|
check(comps, unpublished);
|
|
if (unpublished.size() > 0) {
|
|
TableMsg msg = DialogUtil.createTableMsg(new String[] { "序号", "名称", "原因" }, unpublished);
|
|
JPanel content = new JPanel(new BorderLayout());
|
|
content.setSize(new Dimension(msg.panel.getWidth(), msg.panel.getHeight() + 50));
|
|
JLabel text = new JLabel("操作已取消,下列目标未满足要求:");
|
|
content.add(text, BorderLayout.NORTH);
|
|
content.add(msg.panel, BorderLayout.CENTER);
|
|
JOptionPane.showMessageDialog(null, content, "信息", JOptionPane.PLAIN_MESSAGE);
|
|
return;
|
|
}
|
|
List<TCComponentItemRevision> newRevs = new ArrayList<>();
|
|
for (TCComponent comp : comps) {
|
|
if (!(comp instanceof TCComponentItemRevision)) {
|
|
continue;
|
|
}
|
|
TCComponentItemRevision rev = (TCComponentItemRevision) comp;
|
|
newRevs.add(rev.saveAs(rev.getItem().getNewRev()));
|
|
}
|
|
if (comps.length > 0) {
|
|
folder.cutOperation("contents", comps);
|
|
folder.add("contents", newRevs);
|
|
folder.refresh();
|
|
JOptionPane.showMessageDialog(null, "升版成功", "信息", JOptionPane.WARNING_MESSAGE);
|
|
}
|
|
} catch (Exception e) {
|
|
// TODO Auto-generated catch block
|
|
e.printStackTrace();
|
|
}
|
|
}
|
|
|
|
private void check(TCComponent[] comps, List<String[]> unpublished) throws Exception {
|
|
for (TCComponent comp : comps) {
|
|
if (!(comp instanceof TCComponentItemRevision)) {
|
|
unpublished.add(
|
|
new String[] { unpublished.size() + 1 + "", comp.getProperty("object_string"), "目标类型错误,请放版本" });
|
|
continue;
|
|
}
|
|
boolean isAccess = session.getTCAccessControlService()
|
|
.checkPrivilege(((TCComponentItemRevision) comp).getItem(), "WRITE");
|
|
if (!isAccess) {
|
|
unpublished.add(new String[] { unpublished.size() + 1 + "", comp.getProperty("object_string"), "无权限" });
|
|
continue;
|
|
}
|
|
TCComponent[] status = comp.getRelatedComponents("release_status_list");
|
|
if (status.length == 0) {
|
|
unpublished.add(new String[] { unpublished.size() + 1 + "", comp.getProperty("object_string"), "未发布" });
|
|
}
|
|
}
|
|
}
|
|
|
|
}
|