1 19 package org.netbeans.modules.j2ee.ddloaders.multiview; 20 21 import org.netbeans.modules.xml.multiview.ui.SectionNodeInnerPanel; 22 import org.netbeans.modules.xml.multiview.ui.SectionNodeView; 23 import org.netbeans.modules.xml.multiview.SectionNode; 24 import org.netbeans.modules.j2ee.dd.api.ejb.CmpField; 25 26 import javax.swing.*; 27 import java.util.Arrays ; 28 import java.util.List ; 29 import java.util.LinkedList ; 30 import java.beans.PropertyChangeListener ; 31 import java.beans.PropertyChangeEvent ; 32 33 36 public class CmpFieldsNode extends EjbSectionNode { 37 38 private EntityHelper.CmpFields cmpFields; 39 40 CmpFieldsNode(SectionNodeView sectionNodeView, EntityHelper.CmpFields cmpFields) { 41 super(sectionNodeView, true, cmpFields, Utils.getBundleMessage("LBL_CmpFields"), Utils.ICON_BASE_MISC_NODE); 42 this.cmpFields = cmpFields; 43 } 44 45 protected SectionNodeInnerPanel createNodeInnerPanel() { 46 final CmpFieldsTableModel model = cmpFields.getCmpFieldsTableModel(); 47 final InnerTablePanel innerTablePanel = new InnerTablePanel(getSectionNodeView(), model) { 48 protected void editCell(final int row, final int column) { 49 model.editRow(row); 50 } 51 52 public void dataModelPropertyChange(Object source, String propertyName, Object oldValue, Object newValue) { 53 if (source == key) { 54 model.refreshView(); 55 scheduleRefreshView(); 56 } 57 } 58 59 public void focusData(Object element) { 60 if (element instanceof CmpField) { 61 final int row = cmpFields.getFieldRow((CmpField) element); 62 if (row >= 0) { 63 getTable().getSelectionModel().setSelectionInterval(row, row); 64 } 65 } 66 } 67 }; 68 cmpFields.addPropertyChangeListener(new PropertyChangeListener () { 69 public void propertyChange(PropertyChangeEvent evt) { 70 if (evt != null && CmpFieldHelper.PROPERTY_FIELD_ROW_CHANGED.equals(evt.getPropertyName())) { 71 final ListSelectionModel selectionModel = innerTablePanel.getTable().getSelectionModel(); 72 final int selectedRow = selectionModel.getLeadSelectionIndex(); 73 model.refreshView(); 74 final int oldRow = ((Integer )evt.getOldValue()).intValue(); 75 final int newRow = ((Integer )evt.getNewValue()).intValue(); 76 if (selectedRow == oldRow) { 77 selectionModel.setSelectionInterval(newRow, newRow); 78 } 79 } 80 } 81 }); 82 return innerTablePanel; 83 84 } 85 86 public SectionNode getNodeForElement(Object element) { 87 if (element instanceof CmpField) { 88 if (cmpFields.getFieldRow((CmpField) element) >= 0) { 89 return this; 90 } 91 } else if (element instanceof CmpField[]) { 92 final List list1 = Arrays.asList(cmpFields.getCmpFields()); 93 final List list2 = new LinkedList (Arrays.asList((CmpField[]) element)); 94 if (list1.size() == list2.size()) { 95 list2.removeAll(list1); 96 if (list2.size() == 0) { 97 return this; 98 } 99 } 100 } 101 return super.getNodeForElement(element); 102 } 103 } 104 | Popular Tags |