KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > j2ee > websphere6 > dd > loaders > ui > PagesTablePanel


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.websphere6.dd.loaders.ui;
20
21 import org.netbeans.modules.j2ee.websphere6.dd.beans.*;
22 import org.netbeans.modules.j2ee.websphere6.dd.loaders.WSMultiViewDataObject;
23
24 import org.netbeans.modules.xml.multiview.ui.*;
25 import org.openide.util.NbBundle;
26 import javax.swing.JComboBox JavaDoc;
27 /**
28  * PagesTablePanel - panel containing table for EJB references
29  *
30  *
31  * @author dlm198383
32  */

33 public class PagesTablePanel extends DefaultTablePanel {
34     private PageTableModel model;
35     private MarkupLanguagesType markupLanguage;
36     private WSMultiViewDataObject dObj;
37     private final JComboBox JavaDoc errorPageComboBox;
38     private final JComboBox JavaDoc defaultPageComboBox;
39     /** Creates new form ContextParamPanel */
40     public PagesTablePanel(final WSMultiViewDataObject dObj, final PageTableModel model,final JComboBox JavaDoc errorPageComboBox,final JComboBox JavaDoc defaultPageComboBox) {
41         super(model);
42         this.model=model;
43         this.dObj=dObj;
44         this.errorPageComboBox=errorPageComboBox;
45         this.defaultPageComboBox=defaultPageComboBox;
46         removeButton.addActionListener(new java.awt.event.ActionListener JavaDoc() {
47             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
48                 dObj.setChangedFromUI(true);
49                 int row = getTable().getSelectedRow();
50                 
51                 String JavaDoc selectedItem=(String JavaDoc)errorPageComboBox.getSelectedItem();
52                 String JavaDoc deleteItem=(String JavaDoc)getModel().getValueAt(row,0);
53                 
54                 
55                 errorPageComboBox.removeItem(deleteItem);
56                 if(selectedItem.equals(deleteItem)) {
57                     errorPageComboBox.setSelectedIndex(-1);
58                 }
59                 errorPageComboBox.updateUI();
60                 
61                 selectedItem=(String JavaDoc)defaultPageComboBox.getSelectedItem();
62                 defaultPageComboBox.removeItem(getModel().getValueAt(row,0));
63                 if(selectedItem.equals(deleteItem)) {
64                     defaultPageComboBox.setSelectedIndex(-1);
65                 }
66                 defaultPageComboBox.updateUI();
67                 model.removeRow(row);
68                 dObj.modelUpdatedFromUI();
69                 //dObj.setChangedFromUI(true);
70
dObj.setChangedFromUI(false);
71             }
72         });
73         editButton.addActionListener(new TableActionListener(false));
74         addButton.addActionListener(new TableActionListener(true));
75     }
76     
77     void setModel(MarkupLanguagesType markupLanguage, PageType []params) {
78         this.markupLanguage=markupLanguage;
79         model.setData(markupLanguage,params);
80     }
81     
82     
83     private class TableActionListener implements java.awt.event.ActionListener JavaDoc {
84         private boolean add;
85         TableActionListener(boolean add) {
86             this.add=add;
87         }
88         public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
89             
90             final int row = (add?-1:getTable().getSelectedRow());
91             
92             final PagePanel dialogPanel = new PagePanel();
93             if(!add) {
94                 dialogPanel.getIdField().setText((String JavaDoc)model.getValueAt(row,0));
95                 dialogPanel.getNameField().setText((String JavaDoc)model.getValueAt(row,1));
96                 dialogPanel.getUriField().setText((String JavaDoc)model.getValueAt(row,2));
97             }
98             
99             EditDialog dialog = new EditDialog(dialogPanel,NbBundle.getMessage(PagesTablePanel.class,"TTL_PageParam"),add) {
100                 protected String JavaDoc validate() {
101                     String JavaDoc id = dialogPanel.getIdField().getText().trim();
102                     String JavaDoc name = dialogPanel.getNameField().getText().trim();
103                     String JavaDoc uri = dialogPanel.getUriField().getText().trim();
104                     if (id.length()==0) {
105                         return NbBundle.getMessage(PagesTablePanel.class,"TXT_EmptyPageId");
106                     } else {
107                         PageType[] params = markupLanguage.getPages();
108                         boolean exists=false;
109                         for (int i=0;i<params.length;i++) {
110                             if (row!=i && id.equals(params[i].getXmiId())) {
111                                 exists=true;
112                                 break;
113                             }
114                         }
115                         if (exists) {
116                             return NbBundle.getMessage(PagesTablePanel.class,"TXT_PageIdExists",name);
117                         }
118                     }
119                     
120                     if (name.length()==0) {
121                         return NbBundle.getMessage(PagesTablePanel.class,"TXT_EmptyPageName");
122                     }
123                     
124                     if (uri.length()==0) {
125                         return NbBundle.getMessage(PagesTablePanel.class,"TXT_EmptyPageUri");
126                     }
127                     return null;
128                 }
129             };
130             
131             if (add) dialog.setValid(false); // disable OK button
132
javax.swing.event.DocumentListener JavaDoc docListener = new EditDialog.DocListener(dialog);
133             dialogPanel.getNameField().getDocument().addDocumentListener(docListener);
134             dialogPanel.getIdField().getDocument().addDocumentListener(docListener);
135             dialogPanel.getUriField().getDocument().addDocumentListener(docListener);
136             
137             java.awt.Dialog JavaDoc d = org.openide.DialogDisplayer.getDefault().createDialog(dialog);
138             d.setVisible(true);
139             dialogPanel.getNameField().getDocument().removeDocumentListener(docListener);
140             dialogPanel.getIdField().getDocument().removeDocumentListener(docListener);
141             dialogPanel.getUriField().getDocument().removeDocumentListener(docListener);
142             
143             if (dialog.getValue().equals(EditDialog.OK_OPTION)) {
144                 
145                 
146                 String JavaDoc id = dialogPanel.getIdField().getText().trim();
147                 String JavaDoc name = dialogPanel.getNameField().getText().trim();
148                 String JavaDoc uri = dialogPanel.getUriField().getText().trim();
149                 dObj.setChangedFromUI(true);
150                 if (add) {
151                     model.addRow(new String JavaDoc[]{id,name,uri});
152                     int selectedIndex=errorPageComboBox.getSelectedIndex();
153                     errorPageComboBox.addItem(id);
154                     errorPageComboBox.setSelectedIndex(selectedIndex);
155                     selectedIndex=defaultPageComboBox.getSelectedIndex();
156                     defaultPageComboBox.addItem(id);
157                     defaultPageComboBox.setSelectedIndex(selectedIndex);
158                 } else {
159                     String JavaDoc oldPageId=(String JavaDoc)model.getValueAt(row,0);
160                     model.editRow(row,new String JavaDoc[]{id,name,uri});
161                     for(int i=0;i<errorPageComboBox.getItemCount();i++) {
162                         if(errorPageComboBox.getItemAt(i).equals(oldPageId)) {
163                             int selectedItem=errorPageComboBox.getSelectedIndex();
164                             errorPageComboBox.removeItemAt(i);
165                             errorPageComboBox.insertItemAt(id,i);
166                             errorPageComboBox.setSelectedIndex(selectedItem);
167                             errorPageComboBox.updateUI();
168                             
169                             selectedItem=defaultPageComboBox.getSelectedIndex();
170                             defaultPageComboBox.removeItemAt(i);
171                             defaultPageComboBox.insertItemAt(id,i);
172                             defaultPageComboBox.setSelectedIndex(selectedItem);
173                             defaultPageComboBox.updateUI();
174                             break;
175                         }
176                     }
177                 }
178                 dObj.modelUpdatedFromUI();
179                 //dObj.setChangedFromUI(true);
180
dObj.setChangedFromUI(false);
181             }
182         }
183     }
184 }
185
Popular Tags