001: package org.objectweb.salome_tmf.ihm.main;
002:
003: import java.awt.BorderLayout;
004: import java.awt.Dimension;
005: import java.awt.FlowLayout;
006: import java.awt.Rectangle;
007: import java.awt.event.ActionEvent;
008: import java.awt.event.ActionListener;
009: import java.util.Vector;
010:
011: import javax.swing.BorderFactory;
012: import javax.swing.BoxLayout;
013: import javax.swing.JButton;
014: import javax.swing.JComboBox;
015: import javax.swing.JDialog;
016: import javax.swing.JLabel;
017: import javax.swing.JPanel;
018:
019: import org.objectweb.salome_tmf.api.data.UserWrapper;
020: import org.objectweb.salome_tmf.data.Project;
021: import org.objectweb.salome_tmf.data.SimpleData;
022: import org.objectweb.salome_tmf.data.User;
023: import org.objectweb.salome_tmf.ihm.languages.Language;
024: import org.objectweb.salome_tmf.ihm.main.datawrapper.DataModel;
025: import org.objectweb.salome_tmf.ihm.models.DynamicTree;
026: import org.objectweb.salome_tmf.ihm.tools.Tools;
027:
028: class AskChooseAssignedUser extends JDialog implements ActionListener {
029:
030: JPanel panel = new JPanel(new BorderLayout());
031: JButton validateButton;
032: JButton cancelButton;
033: JComboBox usersComboBox;
034:
035: Vector userList;
036: User selectedUser = null;
037: boolean doActionOnValidate = true;
038:
039: /** Creates a new instance of AskChooseEnvironment */
040: public AskChooseAssignedUser() {
041:
042: super (SalomeTMFContext.getInstance().ptrFrame, true);
043:
044: userList = new Vector();
045: Project current_project = DataModel.getCurrentProject();
046: try {
047: Vector users_wrapper = current_project.getAllUsersWrapper();
048: /*if (users_wrapper.size() == 0){
049: current_project.loadProjectInfo();
050: users_wrapper = current_project.getAllUsersWrapper();
051: }*/
052: for (int i = 0; i < users_wrapper.size(); i++) {
053: User user = new User((UserWrapper) users_wrapper
054: .elementAt(i));
055: userList.add(user);
056: }
057: } catch (Exception e) {
058: e.printStackTrace();
059: }
060: initComponent();
061: }
062:
063: public AskChooseAssignedUser(Vector userList,
064: boolean doActionOnValidate) {
065: super (SalomeTMFContext.getInstance().ptrFrame, true);
066: this .userList = userList;
067: this .doActionOnValidate = doActionOnValidate;
068: initComponent();
069: }
070:
071: void initComponent() {
072: usersComboBox = new JComboBox();
073: for (int i = 0; i < userList.size(); i++) {
074: User user = (User) userList.elementAt(i);
075: usersComboBox.addItem(user.getLoginFromModel());
076: }
077:
078: validateButton = new JButton(Language.getInstance().getText(
079: "Valider"));
080: validateButton.setToolTipText(Language.getInstance().getText(
081: "Valider"));
082: validateButton.addActionListener(this );
083:
084: cancelButton = new JButton(Language.getInstance().getText(
085: "Annuler"));
086: cancelButton.setToolTipText(Language.getInstance().getText(
087: "Annuler"));
088: cancelButton.addActionListener(this );
089:
090: JLabel envLabel = new JLabel(Language.getInstance().getText(
091: "Utilisateur")
092: + " : ");
093:
094: JPanel textFieldPane = new JPanel();
095: textFieldPane.setLayout(new BoxLayout(textFieldPane,
096: BoxLayout.Y_AXIS));
097: textFieldPane.add(usersComboBox);
098:
099: JPanel textPane = new JPanel();
100: textPane.setLayout(new BoxLayout(textPane, BoxLayout.Y_AXIS));
101: textPane.add(envLabel);
102:
103: JPanel textPaneAll = new JPanel(new FlowLayout(
104: FlowLayout.CENTER));
105: textPaneAll.add(textPane);
106: textPaneAll.add(textFieldPane);
107:
108: JPanel buttonPanel = new JPanel(new FlowLayout(
109: FlowLayout.CENTER));
110: buttonPanel.add(validateButton);
111: buttonPanel.add(cancelButton);
112:
113: JPanel labelSet = new JPanel();
114: labelSet.add(textPaneAll);
115:
116: panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS));
117: panel.add(labelSet);
118: panel.add(buttonPanel);
119: panel.setBorder(BorderFactory.createRaisedBevelBorder());
120:
121: this .getContentPane().add(panel);
122:
123: this .setTitle(Language.getInstance().getText("Utilisateur"));
124: //this.setLocation(300,300);
125: /* this.setLocationRelativeTo(this.getParent());
126: this.pack();*/
127: centerScreen();
128: }
129:
130: void centerScreen() {
131: Dimension dim = getToolkit().getScreenSize();
132: this .pack();
133: Rectangle abounds = getBounds();
134: setLocation((dim.width - abounds.width) / 2,
135: (dim.height - abounds.height) / 2);
136: this .setVisible(true);
137: requestFocus();
138: }
139:
140: public User getSelectedUser() {
141: return selectedUser;
142: }
143:
144: /********************************** Implements ActionListener *********************************/
145:
146: public void actionPerformed(ActionEvent e) {
147: if (e.getSource().equals(cancelButton)) {
148: cancelPerformed();
149: } else if (e.getSource().equals(validateButton)) {
150: validatePerformed();
151: }
152: }
153:
154: void cancelPerformed() {
155: selectedUser = null;
156: dispose();
157: }
158:
159: void validatePerformed() {
160: DynamicTree pDynamicTree = SalomeTMFPanels
161: .getCampaignDynamicTree();
162:
163: int user_index = usersComboBox.getSelectedIndex();
164: selectedUser = (User) userList.elementAt(user_index);
165: if (doActionOnValidate) {
166: try {
167:
168: DataModel.assignCampaignTo((SimpleData) pDynamicTree
169: .getSelectedNode().getUserObject(),
170: selectedUser);
171: SalomeTMFPanels.setCampPanelDetailsForTest(null, null,
172: null, selectedUser.getIdBdd());
173: IAssignedCampAction pIAssignedCampAction = DataModel
174: .getAssignedCampAction();
175: if (pIAssignedCampAction != null) {
176: if (DataModel.getCurrentCampaign() != null) {
177: pIAssignedCampAction.updateData(DataModel
178: .getCurrentCampaign());
179: }
180: }
181: } catch (Exception ex) {
182: Tools.ihmExceptionView(ex);
183: }
184: }
185: dispose();
186:
187: /*
188: String user_login = (String)usersComboBox.getSelectedItem();
189: User user = new User(user_login);
190: DataModel.assignCampaignTo((SimpleData)pDynamicTree.getSelectedNode().getUserObject(),user);
191: SalomeTMFPanels.setCampPanelDetailsForTest(null,null,null,user.getIdBdd());
192: } catch (Exception ex) {
193: Tools.ihmExceptionView(ex);
194: }
195: dispose();
196: */
197: }
198:
199: }
|