ludc
2025-01-16 986aa62ed00bee39363bab41b4eeb8259d446efd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
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();
    }
}