package com.vci.client.uif.actions.client.chageowner; import java.awt.BorderLayout; import java.awt.Component; import java.awt.GridBagConstraints; import java.awt.GridBagLayout; import java.awt.Insets; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.SwingUtilities; import com.vci.client.portal.utility.PRMItem; import com.vci.client.ui.swing.VCISwingUtil; import com.vci.client.ui.swing.components.VCIJButton; import com.vci.client.ui.swing.components.VCIJCheckBox; import com.vci.client.ui.swing.components.VCIJDialog; import com.vci.client.ui.swing.components.VCIJLabel; import com.vci.client.ui.swing.components.VCIJOptionPane; import com.vci.client.ui.swing.components.VCIJPanel; import com.vci.client.uif.engine.client.controls.ControlFactory; import com.vci.client.uif.engine.client.controls.ICustomControl; import com.vci.common.portal.enums.ControlType; import com.vci.mw.ClientContextVariable; public class ChangeOwnerDialog extends VCIJDialog { /** * */ private static final long serialVersionUID = -6323720897093394827L; private boolean showCascadeCheckbox = false; private VCIJCheckBox cbxCascadeChild = new VCIJCheckBox("级联更改子对象的所有者", false); private VCIJButton btnOk = VCISwingUtil.createVCIJButton("ok", "确定", "确定", "accept.png", new ActionListener() { @Override public void actionPerformed(ActionEvent e) { ok(); } }); private VCIJButton btnCancel = VCISwingUtil.createVCIJButton("cancel", "取消", "取消", "cancel.png", new ActionListener() { @Override public void actionPerformed(ActionEvent e) { cancel(); } }); public ChangeOwnerDialog(){ super(ClientContextVariable.getFrame(), true); } public void buildDialog(){ init(); } private void init(){ setLayout(new BorderLayout()); setTitle("更改所有者"); add(getCenterContentPanel(), BorderLayout.CENTER); add(getSouthButtonPanel(), BorderLayout.SOUTH); } ICustomControl ctrl = null; private VCIJPanel getCenterContentPanel(){ VCIJPanel pal = new VCIJPanel(new GridBagLayout()); PRMItem item = new PRMItem(); item.setItemField("owner"); item.setItemType(ControlType.Custom.name()); item.setItemCustomClass("plm.uif.engine.client.controls.BaseCustomControl"); item.setItemValue("plm.uif.actions.client.SelectorUserAction"); item.setItemIsEditable("0"); item.setItemIsRequired("1"); VCIJLabel lbl = new VCIJLabel("所有者:"); pal.add(lbl, getGBC(0, 0, 1, 1, 0.0, 0.0, GridBagConstraints.NORTHWEST, GridBagConstraints.BOTH, 5)); Component compt = ControlFactory.createControl(item); if(compt instanceof ICustomControl){ ctrl = (ICustomControl) compt; } pal.add(compt, getGBC(1, 0, 1, 1, 1.0, 0.0, GridBagConstraints.NORTHWEST, GridBagConstraints.BOTH, 5)); if(isShowCascadeCheckbox()){ pal.add(cbxCascadeChild, getGBC(1, 1, 1, 1, 0.0, 0.0, GridBagConstraints.NORTHWEST, GridBagConstraints.BOTH, 5)); } pal.add(new VCIJLabel(""), getGBC(0, 2, 3, 1, 0.0, 0.0, GridBagConstraints.NORTHWEST, GridBagConstraints.BOTH, 5)); return pal; } private GridBagConstraints getGBC(int gridx, int gridy, int gridwidth, int gridheight, double weightx, double weighty, int anchor, int fill, int padxy) { return new GridBagConstraints(gridx, gridy, gridwidth, gridheight, weightx, weighty, anchor, fill, new Insets(padxy, padxy, padxy, padxy), padxy, padxy); } private VCIJPanel getSouthButtonPanel(){ VCIJPanel pal = new VCIJPanel(); pal.add(btnOk); pal.add(btnCancel); return pal; } private String newOwner = ""; private void ok(){ if(ctrl == null) { VCIJOptionPane.showMessage(this, "请选择所有者!"); return; } newOwner = ctrl.getValue(); if(newOwner == null || "".equals(newOwner)){ VCIJOptionPane.showMessage(this, "请选择所有者!"); return; } close(DialogResult.OK); } private void cancel(){ close(DialogResult.CANCEL); } private void close(DialogResult dialogResult){ setDialogResult(dialogResult); close(); } private void close(){ SwingUtilities.invokeLater(new Runnable() { @Override public void run() { ChangeOwnerDialog.this.setVisible(false); } }); } public boolean isShowCascadeCheckbox() { return showCascadeCheckbox; } public void setShowCascadeCheckbox(boolean showCascadeCheckbox) { this.showCascadeCheckbox = showCascadeCheckbox; } public String getNewOwner(){ return newOwner; } public boolean isCascade() { return cbxCascadeChild.isSelected(); } }