1 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 ; 27 33 public class PagesTablePanel extends DefaultTablePanel { 34 private PageTableModel model; 35 private MarkupLanguagesType markupLanguage; 36 private WSMultiViewDataObject dObj; 37 private final JComboBox errorPageComboBox; 38 private final JComboBox defaultPageComboBox; 39 40 public PagesTablePanel(final WSMultiViewDataObject dObj, final PageTableModel model,final JComboBox errorPageComboBox,final JComboBox 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 () { 47 public void actionPerformed(java.awt.event.ActionEvent evt) { 48 dObj.setChangedFromUI(true); 49 int row = getTable().getSelectedRow(); 50 51 String selectedItem=(String )errorPageComboBox.getSelectedItem(); 52 String deleteItem=(String )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 )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(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 { 84 private boolean add; 85 TableActionListener(boolean add) { 86 this.add=add; 87 } 88 public void actionPerformed(java.awt.event.ActionEvent 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 )model.getValueAt(row,0)); 95 dialogPanel.getNameField().setText((String )model.getValueAt(row,1)); 96 dialogPanel.getUriField().setText((String )model.getValueAt(row,2)); 97 } 98 99 EditDialog dialog = new EditDialog(dialogPanel,NbBundle.getMessage(PagesTablePanel.class,"TTL_PageParam"),add) { 100 protected String validate() { 101 String id = dialogPanel.getIdField().getText().trim(); 102 String name = dialogPanel.getNameField().getText().trim(); 103 String 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); javax.swing.event.DocumentListener 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 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 id = dialogPanel.getIdField().getText().trim(); 147 String name = dialogPanel.getNameField().getText().trim(); 148 String uri = dialogPanel.getUriField().getText().trim(); 149 dObj.setChangedFromUI(true); 150 if (add) { 151 model.addRow(new String []{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 oldPageId=(String )model.getValueAt(row,0); 160 model.editRow(row,new String []{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(false); 181 } 182 } 183 } 184 } 185 | Popular Tags |