KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > j2ee > ddloaders > multiview > CmpFieldsNode


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

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 JavaDoc;
28 import java.util.List JavaDoc;
29 import java.util.LinkedList JavaDoc;
30 import java.beans.PropertyChangeListener JavaDoc;
31 import java.beans.PropertyChangeEvent JavaDoc;
32
33 /**
34  * @author pfiala
35  */

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 JavaDoc source, String JavaDoc propertyName, Object JavaDoc oldValue, Object JavaDoc newValue) {
53                 if (source == key) {
54                     model.refreshView();
55                     scheduleRefreshView();
56                 }
57             }
58
59             public void focusData(Object JavaDoc 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 JavaDoc() {
69             public void propertyChange(PropertyChangeEvent JavaDoc 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 JavaDoc)evt.getOldValue()).intValue();
75                     final int newRow = ((Integer JavaDoc)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 JavaDoc 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 JavaDoc list1 = Arrays.asList(cmpFields.getCmpFields());
93             final List JavaDoc list2 = new LinkedList JavaDoc(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