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 ModuleExtensionTablePanel extends DefaultTablePanel { 34 private ModuleExtensionTableModel model; 35 private WSAppExt appext; 36 private WSMultiViewDataObject dObj; 37 38 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 () { 44 public void actionPerformed(java.awt.event.ActionEvent evt) { 45 dObj.setChangedFromUI(true); 46 model.removeRow(getTable().getSelectedRow()); 47 dObj.modelUpdatedFromUI(); 48 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 { 63 private boolean add; 64 TableActionListener(boolean add) { 65 this.add=add; 66 } 67 public void actionPerformed(java.awt.event.ActionEvent 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 )model.getValueAt(row,0)); 74 dialogPanel.getHrefField().setText((String )model.getValueAt(row,1)); 75 dialogPanel.getAltRootField().setText((String )model.getValueAt(row,2)); 76 dialogPanel.getAltBindingsField().setText((String )model.getValueAt(row,3)); 77 dialogPanel.getAltExtensionsField().setText((String )model.getValueAt(row,4)); 78 dialogPanel.getTypeComboBox().setSelectedItem((String )model.getValueAt(row,5)); 79 } 80 81 EditDialog dialog = new EditDialog(dialogPanel,NbBundle.getMessage(ModuleExtensionTablePanel.class,"TTL_PageParam"),add) { 82 protected String validate() { 83 String id = dialogPanel.getIdField().getText().trim(); 84 String href = dialogPanel.getHrefField().getText().trim(); 85 String altRoot = dialogPanel.getAltRootField().getText().trim(); 86 String altBindings = dialogPanel.getAltBindingsField().getText().trim(); 87 String altExtensions = dialogPanel.getAltExtensionsField().getText().trim(); 88 String type = (String ) 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); javax.swing.event.DocumentListener 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 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 id = dialogPanel.getIdField().getText().trim(); 136 String href = dialogPanel.getHrefField().getText().trim(); 137 String altRoot = dialogPanel.getAltRootField().getText().trim(); 138 String altBindings = dialogPanel.getAltBindingsField().getText().trim(); 139 String altExtensions = dialogPanel.getAltExtensionsField().getText().trim(); 140 String type = (String ) dialogPanel.getTypeComboBox().getSelectedItem(); 141 142 dObj.setChangedFromUI(true); 143 if (add) { 144 model.addRow(new String []{id,href,altRoot,altBindings,altExtensions,type}); 145 } else { 146 String oldPageId=(String )model.getValueAt(row,0); 147 model.editRow(row,new String []{id,href,altRoot,altBindings,altExtensions,type}); 148 } 149 dObj.modelUpdatedFromUI(); 150 dObj.setChangedFromUI(false); 152 } 153 } 154 } 155 } 156 | Popular Tags |