View Javadoc

1   /***
2    * Created on Jan 9, 2006, Copyright UC Regents
3    */
4   package org.telscenter.pas.steps.quickEditors.qti.assessment;
5   
6   import java.awt.Component;
7   
8   import net.sf.sail.jaxb.extension.BlockInteractionType;
9   
10  import org.imsglobal.xsd.imsqti_v2p0.AssessmentItemType;
11  import org.telscenter.pas.ui.util.PasColors;
12  import org.telscenter.pas.util.JaxbQtiCreationUtils;
13  import org.telscenter.pas.util.QTIUtils;
14  
15  
16  /***
17   * Creates an interaction Card container
18   * 
19   * @author aperritano
20   *
21   */
22  public class InteractionCardContainerUI extends AbstractCardContainerUI<BlockInteractionType> implements CardShiftListener{
23  
24  	private AssessmentItemType assessmentItem;
25  	
26  	/***
27  	 * Default 
28  	 */
29  	public InteractionCardContainerUI() {
30  		super();
31  	}
32  	
33  	/***
34  	 * Create a interaction card
35  	 * 
36  	 * @param assessmentItemType
37  	 */
38  	public InteractionCardContainerUI(AssessmentItemType assessmentItemType) {
39  		this.assessmentItem = assessmentItemType;
40  		this.listOfObjects = assessmentItemType.getItemBody().getBlockElementGroup();
41  		init();
42  		
43  		this.setDefaultMessage("This Assessment has zero items");
44  		
45  	}
46  
47  	/***
48  	 * Intialize the ui
49  	 */
50  	protected void init() {
51  		// TODO Auto-generated method stub
52  		super.init();
53  		this.setBackground(PasColors.interactionCardContainerBackgroundColor);
54  	}
55  	
56  	/***
57  	 * Delete the card at the selected index
58  	 * 
59  	 * @param currentCardIndex - delete the card
60  	 */
61  	protected void trashCard(int currentCardIndex) {
62  		InteractionCardUI card = (InteractionCardUI) this.getComponent(currentCardIndex);
63  		if( card.getInteraction() == null )
64  			return;
65  		
66  		JaxbQtiCreationUtils.removeBlockInteraction(assessmentItem, card.getInteraction());
67  		
68  		this.remove(card);
69  		
70  		
71  		interactionCardIndex--;
72  		
73  		if( this.getComponents().length == 0 ) {
74  			this.add(noCardsLabel);
75  			this.repaint();
76  			this.revalidate();
77  			return;
78  		}
79  		//re index all of them
80  		Component[] components = this.getComponents();
81  		for (int i = 0; i < components.length; i++) {
82  			AbstractCardUI<BlockInteractionType> nc = (AbstractCardUI<BlockInteractionType>) components[i];
83  			nc.setIndex(i);
84  			
85  		}
86  		modButtons();
87  		this.revalidate();
88  	}
89  }