1 16 17 package com.jaspersoft.jasperserver.irplugin.gui.inputcontrols.ui; 18 19 import com.jaspersoft.jasperserver.api.metadata.xml.domain.impl.InputControlQueryDataRow; 20 import com.jaspersoft.jasperserver.irplugin.gui.inputcontrols.ListItemWrapper; 21 import com.jaspersoft.jasperserver.irplugin.gui.inputcontrols.ui.ItemRenderer; 22 import java.awt.Color ; 23 import java.awt.Component ; 24 import java.awt.GridLayout ; 25 import javax.swing.JLabel ; 26 import javax.swing.JList ; 27 import javax.swing.JPanel ; 28 import javax.swing.ListCellRenderer ; 29 30 31 35 public class MultiColumnListInputControlUI extends BasicInputControlUI { 36 37 40 public MultiColumnListInputControlUI() { 41 super(); 42 setComboEditable(false); 43 getJComboBoxValue().setMinimumSize(new java.awt.Dimension (400,26)); 44 } 45 46 public void setHistory(java.util.List values){ 47 48 getJComboBoxValue().removeAllItems(); 49 if (values == null) return; 50 51 int maxColumns = 1; 53 for (int i=0; i<values.size(); ++i) 54 { 55 InputControlQueryDataRow qd = (InputControlQueryDataRow)values.get(i); 56 maxColumns = (qd.getColumnValues().size()>maxColumns) ? qd.getColumnValues().size() : maxColumns; 57 } 58 getJComboBoxValue().setRenderer(new ItemRenderer(maxColumns)); 60 61 for (int i=0; i<values.size(); ++i) 62 { 63 getJComboBoxValue().addItem( values.get(i)); 64 } 65 66 if (getJComboBoxValue().getItemCount() > 0) 67 { 68 getJComboBoxValue().setSelectedIndex(0); 69 } 70 71 getJComboBoxValue().updateUI(); 72 } 73 74 public void setValue(Object v) 75 { 76 for (int i=0; i<getJComboBoxValue().getItemCount(); ++i) 77 { 78 Object val = getJComboBoxValue().getItemAt(i); 79 80 if (val instanceof InputControlQueryDataRow) 81 { 82 val = ((InputControlQueryDataRow)val).getValue(); 83 if ( ((val == null) ? val == v : val.equals(v)) ) 84 { 85 getJComboBoxValue().setSelectedIndex(i); 86 return; 87 } 88 } 89 } 90 91 getJComboBoxValue().setSelectedItem(v); 92 } 93 94 public Object getValue() 95 { 96 Object val = getJComboBoxValue().getSelectedItem(); 97 if (val == null) return null; 98 if (val instanceof InputControlQueryDataRow) 99 { 100 return ((InputControlQueryDataRow)val).getValue(); 101 } 102 103 return val; 104 } 105 106 107 108 } 109 | Popular Tags |