KickJava   Java API By Example, From Geeks To Geeks.

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


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  * ModuleExtensionTablePanel - panel containing table for EJB references
29  *
30  *
31  * @author dlm198383
32  */

33 public class ModuleExtensionTablePanel extends DefaultTablePanel {
34     private ModuleExtensionTableModel model;
35     private WSAppExt appext;
36     private WSMultiViewDataObject dObj;
37     
38     /** Creates new form ContextParamPanel */
39     public ModuleExtensionTablePanel(final WSMultiViewDataObject dObj, final ModuleExtensionTableModel model) {
40         super(model);
41         this.model=model;
42         this.dObj=dObj;
43         removeButton.addActionListener(new java.awt.event.ActionListener JavaDoc() {
44             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
45         dObj.setChangedFromUI(true);
46                 model.removeRow(getTable().getSelectedRow());
47                 dObj.modelUpdatedFromUI();
48                 //dObj.setChangedFromUI(true);
49
dObj.setChangedFromUI(false);
50             }
51         });
52         editButton.addActionListener(new TableActionListener(false));
53         addButton.addActionListener(new TableActionListener(true));
54     }
55     
56     void setModel(WSAppExt appext, ModuleExtensionsType []params) {
57         this.appext=appext;
58         model.setData(appext,params);
59     }
60     
61     
62     private class TableActionListener implements java.awt.event.ActionListener JavaDoc {
63         private boolean add;
64         TableActionListener(boolean add) {
65             this.add=add;
66         }
67         public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
68             
69             final int row = (add?-1:getTable().getSelectedRow());
70             
71             final ModuleExtensionPanel dialogPanel = new ModuleExtensionPanel();
72             if(!add) {
73                 dialogPanel.getIdField().setText((String JavaDoc)model.getValueAt(row,0));
74                 dialogPanel.getHrefField().setText((String JavaDoc)model.getValueAt(row,1));
75                 dialogPanel.getAltRootField().setText((String JavaDoc)model.getValueAt(row,2));
76                 dialogPanel.getAltBindingsField().setText((String JavaDoc)model.getValueAt(row,3));
77                 dialogPanel.getAltExtensionsField().setText((String JavaDoc)model.getValueAt(row,4));
78                 dialogPanel.getTypeComboBox().setSelectedItem((String JavaDoc)model.getValueAt(row,5));
79             }
80             
81             EditDialog dialog = new EditDialog(dialogPanel,NbBundle.getMessage(ModuleExtensionTablePanel.class,"TTL_PageParam"),add) {
82                 protected String JavaDoc validate() {
83                     String JavaDoc id = dialogPanel.getIdField().getText().trim();
84                     String JavaDoc href = dialogPanel.getHrefField().getText().trim();
85                     String JavaDoc altRoot = dialogPanel.getAltRootField().getText().trim();
86                     String JavaDoc altBindings = dialogPanel.getAltBindingsField().getText().trim();
87                     String JavaDoc altExtensions = dialogPanel.getAltExtensionsField().getText().trim();
88                     String JavaDoc type = (String JavaDoc) dialogPanel.getTypeComboBox().getSelectedItem();
89                     
90                     if (id.length()==0) {
91                         return NbBundle.getMessage(ModuleExtensionTablePanel.class,"TXT_EmptyModuleExtensionId");
92                     } else {
93                         ModuleExtensionsType[] params = appext.getModuleExtensions();
94                         boolean exists=false;
95                         for (int i=0;i<params.length;i++) {
96                             if (row!=i && id.equals(params[i].getXmiId())) {
97                                 exists=true;
98                                 break;
99                             }
100                         }
101                         if (exists) {
102                             return NbBundle.getMessage(ModuleExtensionTablePanel.class,"TXT_ModuleExtensionIdExists");
103                         }
104                     }
105                     
106                     if (href.length()==0) {
107                         return NbBundle.getMessage(ModuleExtensionTablePanel.class,"TXT_EmptyModuleName");
108                     }
109                     
110                     
111                     return null;
112                 }
113             };
114             
115             if (add) dialog.setValid(false); // disable OK button
116
javax.swing.event.DocumentListener JavaDoc docListener = new EditDialog.DocListener(dialog);
117             dialogPanel.getIdField().getDocument().addDocumentListener(docListener);
118             dialogPanel.getHrefField().getDocument().addDocumentListener(docListener);
119             dialogPanel.getAltRootField().getDocument().addDocumentListener(docListener);
120             dialogPanel.getAltBindingsField().getDocument().addDocumentListener(docListener);
121             dialogPanel.getAltExtensionsField().getDocument().addDocumentListener(docListener);
122             
123             java.awt.Dialog JavaDoc d = org.openide.DialogDisplayer.getDefault().createDialog(dialog);
124             d.setVisible(true);
125             dialogPanel.getIdField().getDocument().removeDocumentListener(docListener);
126             dialogPanel.getHrefField().getDocument().removeDocumentListener(docListener);
127             dialogPanel.getAltRootField().getDocument().removeDocumentListener(docListener);
128             dialogPanel.getAltBindingsField().getDocument().removeDocumentListener(docListener);
129             dialogPanel.getAltExtensionsField().getDocument().removeDocumentListener(docListener);
130             
131             
132             if (dialog.getValue().equals(EditDialog.OK_OPTION)) {
133                 
134                 
135                 String JavaDoc id = dialogPanel.getIdField().getText().trim();
136                 String JavaDoc href = dialogPanel.getHrefField().getText().trim();
137                 String JavaDoc altRoot = dialogPanel.getAltRootField().getText().trim();
138                 String JavaDoc altBindings = dialogPanel.getAltBindingsField().getText().trim();
139                 String JavaDoc altExtensions = dialogPanel.getAltExtensionsField().getText().trim();
140                 String JavaDoc type = (String JavaDoc) dialogPanel.getTypeComboBox().getSelectedItem();
141                 
142                 dObj.setChangedFromUI(true);
143                 if (add) {
144                     model.addRow(new String JavaDoc[]{id,href,altRoot,altBindings,altExtensions,type});
145                 } else {
146                     String JavaDoc oldPageId=(String JavaDoc)model.getValueAt(row,0);
147                     model.editRow(row,new String JavaDoc[]{id,href,altRoot,altBindings,altExtensions,type});
148                 }
149                 dObj.modelUpdatedFromUI();
150                 //dObj.setChangedFromUI(true);
151
dObj.setChangedFromUI(false);
152             }
153         }
154     }
155 }
156
Popular Tags