1 19 20 package org.netbeans.modules.j2ee.ddloaders.multiview; 21 22 import org.netbeans.modules.j2ee.ejbcore.api.ui.CallEjb; 23 import org.netbeans.modules.j2ee.dd.api.common.EjbLocalRef; 24 import org.netbeans.modules.j2ee.dd.api.common.EjbRef; 25 import org.netbeans.modules.j2ee.dd.api.ejb.Ejb; 26 import org.netbeans.modules.xml.multiview.XmlMultiViewDataObject; 27 import org.netbeans.modules.xml.multiview.ui.ConfirmDialog; 28 import org.openide.util.NbBundle; 29 30 33 public class EjbReferencesTableModel extends InnerTableModel { 34 35 private XmlMultiViewDataObject dataObject; 36 Ejb ejb; 37 private static final String [] COLUMN_NAMES = { 38 NbBundle.getBundle(EjbReferencesTableModel.class).getString("LBL_ReferenceName"), 39 NbBundle.getBundle(EjbReferencesTableModel.class).getString("LBL_LinkedEjb"), 40 NbBundle.getBundle(EjbReferencesTableModel.class).getString("LBL_Interface"), 41 NbBundle.getBundle(EjbReferencesTableModel.class).getString("LBL_Description")}; 42 private static final int[] COLUMN_WIDTHS = new int[]{170, 260, 70, 250}; 43 44 public EjbReferencesTableModel(XmlMultiViewDataObject dataObject, Ejb ejb) { 45 super(((EjbJarMultiViewDataObject)dataObject).getModelSynchronizer(), COLUMN_NAMES, COLUMN_WIDTHS); 46 this.dataObject = dataObject; 47 this.ejb = ejb; 48 } 49 50 public int getRowCount() { 51 return ejb.getEjbLocalRef().length + ejb.getEjbRef().length; 52 } 53 54 public boolean isCellEditable(int row, int column) { 55 return isColumnEditable(column); 56 } 57 58 public int addRow() { 59 return -1; 64 } 65 66 public void removeRow(int selectedRow) { 67 org.openide.DialogDescriptor desc = new ConfirmDialog(NbBundle.getMessage(EjbReferencesTableModel.class,"LBL_RemoveEjbRefWarning")); 68 java.awt.Dialog dialog = org.openide.DialogDisplayer.getDefault().createDialog(desc); 69 dialog.setVisible(true); 70 if (org.openide.DialogDescriptor.OK_OPTION.equals(desc.getValue())) { 71 EjbLocalRef localRef = ejb.getEjbLocalRef(selectedRow); 72 if (localRef != null){ 73 ejb.removeEjbLocalRef(localRef); 74 } else { 75 EjbRef ref = ejb.getEjbRef(selectedRow); 76 if (ref != null){ 77 ejb.removeEjbRef(ref); 78 } 79 } 80 modelUpdatedFromUI(); 81 } 82 } 83 84 85 86 public Object getValueAt(int rowIndex, int columnIndex) { 87 int n = ejb.getEjbLocalRef().length; 88 if (rowIndex < n) { 89 EjbLocalRef ref = ejb.getEjbLocalRef(rowIndex); 90 switch (columnIndex) { 91 case 0: 92 return ref.getEjbRefName(); 93 case 1: 94 return ref.getEjbLink(); 95 case 2: 96 return "local"; case 3: 98 return ref.getDefaultDescription(); 99 } 100 } else { 101 EjbRef ref = ejb.getEjbRef(rowIndex - n); 102 switch (columnIndex) { 103 case 0: 104 return ref.getEjbRefName(); 105 case 1: 106 return ref.getEjbLink(); 107 case 2: 108 return "remote"; case 3: 110 return ref.getDefaultDescription(); 111 } 112 } 113 return null; 114 } 115 116 public void setValueAt(Object aValue, int rowIndex, int columnIndex) { 117 if (!isColumnEditable(columnIndex)){ 118 return; 119 } 120 EjbRef ref = ejb.getEjbRef(rowIndex); 121 if (ref != null){ 122 ref.setDescription((String ) aValue); 123 } else { 124 EjbLocalRef localRef = ejb.getEjbLocalRef(rowIndex); 125 if (localRef != null){ 126 localRef.setDescription((String ) aValue); 127 } 128 } 129 modelUpdatedFromUI(); 130 } 131 132 133 private boolean isColumnEditable(int columnIndex){ 134 return columnIndex == 3; 136 } 137 138 } 139 | Popular Tags |