1 19 20 package org.netbeans.modules.j2ee.ddloaders.multiview; 21 22 import org.netbeans.modules.j2ee.dd.api.common.ResourceRef; 23 import org.netbeans.modules.j2ee.dd.api.ejb.Ejb; 24 import org.netbeans.modules.xml.multiview.XmlMultiViewDataSynchronizer; 25 import org.openide.NotifyDescriptor; 26 import org.openide.DialogDisplayer; 27 28 import javax.swing.table.TableCellEditor ; 29 30 33 public class ResourceReferencesTableModel extends InnerTableModel { 34 35 private Ejb ejb; 36 private static final int COLUMN_AUTHENTICATION = 2; 37 private static final int COLUMN_SHAREABLE = 3; 38 private static final String [] COLUMN_NAMES = {Utils.getBundleMessage("LBL_Name"), 39 Utils.getBundleMessage("LBL_ResourceType"), 40 Utils.getBundleMessage("LBL_Authentication"), 41 Utils.getBundleMessage("LBL_Shareable"), 42 Utils.getBundleMessage("LBL_Description")}; 43 private static final int[] COLUMN_WIDTHS = new int[]{100, 200, 120, 80, 150}; 44 45 public ResourceReferencesTableModel(XmlMultiViewDataSynchronizer synchronizer, Ejb ejb) { 46 super(synchronizer, COLUMN_NAMES, COLUMN_WIDTHS); 47 this.ejb = ejb; 48 } 49 50 public void setValueAt(Object value, int rowIndex, int columnIndex) { 51 ResourceRef resourceRef = ejb.getResourceRef(rowIndex); 52 switch (columnIndex) { 53 case 0: 54 resourceRef.setResRefName((String ) value); 55 break; 56 case 1: 57 resourceRef.setResType((String ) value); 58 break; 59 case 2: 60 resourceRef.setResAuth((String ) value); 61 break; 62 case 3: 63 resourceRef.setResSharingScope((String ) value); 64 break; 65 case 4: 66 resourceRef.setDescription((String ) value); 67 break; 68 } 69 modelUpdatedFromUI(); 70 fireTableCellUpdated(rowIndex, columnIndex); 71 } 72 73 public int getRowCount() { 74 return ejb.getResourceRef().length; 75 } 76 77 public Object getValueAt(int rowIndex, int columnIndex) { 78 ResourceRef resourceRef = ejb.getResourceRef(rowIndex); 79 switch (columnIndex) { 80 case 0: 81 return resourceRef.getResRefName(); 82 case 1: 83 return resourceRef.getResType(); 84 case 2: 85 return resourceRef.getResAuth(); 86 case 3: 87 return resourceRef.getResSharingScope(); 88 case 4: 89 return resourceRef.getDefaultDescription(); 90 } 91 return null; 92 } 93 94 public int addRow() { 95 String text = Utils.getBundleMessage("LBL_ReferenceName_"); 96 String title = Utils.getBundleMessage("LBL_AddResourceReference"); 97 final NotifyDescriptor.InputLine inputLine = new NotifyDescriptor.InputLine(text, title); 98 DialogDisplayer.getDefault().notify(inputLine); 99 final String name = inputLine.getInputText(); 100 return addRow(name); 101 } 102 103 public int addRow(String name) { 104 if (name != null && name.trim().length() > 0) { 105 ResourceRef resourceRef = ejb.newResourceRef(); 106 resourceRef.setResRefName(name); 107 ejb.addResourceRef(resourceRef); 108 modelUpdatedFromUI(); 109 } 110 int row = getRowCount() - 1; 111 return row; 112 } 113 114 public void removeRow(int row) { 115 ejb.removeResourceRef(ejb.getResourceRef(row)); 116 modelUpdatedFromUI(); 117 } 118 119 public boolean isCellEditable(int rowIndex, int columnIndex) { 120 return columnIndex != 0; 121 } 122 123 public TableCellEditor getTableCellEditor(int column) { 124 if (column == COLUMN_AUTHENTICATION) { 125 return createComboBoxCellEditor(new Object []{"Application", "Container"}); 126 } else if (column == COLUMN_SHAREABLE) { 127 return createComboBoxCellEditor(new Object []{"Shareable", "Unshareable"}); 128 } else { 129 return null; 130 } 131 } 132 } 133 | Popular Tags |