1 /***
2 * Created on Jan 26, 2006, Copyright UC Regents
3 */
4 package org.telscenter.pas.steps.domain;
5
6 import java.awt.BorderLayout;
7 import java.awt.Component;
8 import java.awt.event.ActionEvent;
9 import java.awt.event.ActionListener;
10 import java.awt.event.WindowAdapter;
11 import java.awt.event.WindowEvent;
12 import java.beans.PropertyEditorSupport;
13
14 import javax.swing.JButton;
15 import javax.swing.JDialog;
16 import javax.swing.JLabel;
17 import javax.swing.JPanel;
18
19 import org.imsglobal.xsd.imsqti_v2p0.AssessmentItemType;
20 import org.telscenter.pas.common.ui.CreateNewDialog;
21 import org.telscenter.pas.steps.quickEditors.qti.assessment.AssessmentQuickEditorUI;
22
23
24 /***
25 * This editor is for the advanced properties editor
26 *
27 * @author turadg
28 */
29 public class AssessmentItemEditor extends PropertyEditorSupport {
30
31 private AssessmentQuickEditorUI editor;
32
33 public boolean supportsCustomEditor() {
34 return true;
35 }
36
37 public void setValue(Object value) {
38 super.setValue(value);
39 final AssessmentItemType assessmentItem = (AssessmentItemType) value;
40 AssessmentItemType newAssessmentItem;
41 try {
42
43 newAssessmentItem = (AssessmentItemType) org.apache.commons.beanutils.BeanUtils
44 .cloneBean(assessmentItem);
45 editor.setAssessmentItem(newAssessmentItem);
46 } catch (Exception e) {
47
48 e.printStackTrace();
49 }
50 }
51
52 public String getAsText() {
53 AssessmentItem item = (AssessmentItem) getValue();
54 return item.getItemBody().getInteractions().size() + " interactions";
55 }
56
57
58 public Component getCustomEditor() {
59 if (editor == null) {
60
61 }
62
63 JPanel longPanel = new JPanel(new BorderLayout(0,0));
64 longPanel.setOpaque(false);
65
66 String message = null;
67 if( editor.getAssessmentItem() == null ) {
68 message = "There are no assessments items.";
69 } else {
70 message = editor.getAssessmentItem().toString();
71 }
72
73 JLabel hintLabel = new JLabel(message);
74 hintLabel.setOpaque(false);
75
76 JButton hintButton = new JButton("...");
77 hintButton.addActionListener(new ActionListener() {
78
79 public void actionPerformed(ActionEvent e) {
80 JDialog assDialog = CreateNewDialog.createDialog(editor,"Assessment Editor","Add and remove Assessment cards","Assessment cards can be rearraged using the arrows", null, 450,450);
81 assDialog.setVisible(true);
82
83 assDialog.addWindowListener(new WindowAdapter() {
84
85 public void windowClosing(WindowEvent e) {
86 AssessmentItemEditor.this.setValue(editor.getAssessmentItem());
87 }
88
89 public void windowClosed(WindowEvent e) {
90
91 }
92 });
93
94 }});
95
96 longPanel.add(hintLabel,BorderLayout.CENTER);
97 longPanel.add(hintButton,BorderLayout.EAST);
98 return longPanel;
99 }
100
101 }