/* * GeneView.java * * Created on March 26, 2008, 10:46 AM */ package org.genedb.jogra.plugins; import java.util.ArrayList; import java.util.List; import javax.swing.JButton; import javax.swing.JList; /** * * @author art */ public class GeneView extends javax.swing.JPanel { public GeneView(GeneViewModel model) { this.model = model; initComponents(); } /** Creates new form GeneView */ public GeneView() { initComponents(); } /** This method is called from within the constructor to * initialize the form. * WARNING: Do NOT modify this code. The content of this method is * always regenerated by the Form Editor. */ @SuppressWarnings("unchecked") // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents private void initComponents() { bindingGroup = new org.jdesktop.beansbinding.BindingGroup(); model = model; // model should be injected; sysIdLabel = new javax.swing.JLabel(); sysIdField = new javax.swing.JTextField(); nameLabel = new javax.swing.JLabel(); nameField = new javax.swing.JTextField(); synonymsLabel = new javax.swing.JLabel(); jScrollPane1 = new javax.swing.JScrollPane(); synonymsList = new org.jdesktop.swingx.JXList(); jScrollPane2 = new javax.swing.JScrollPane(); productsList = new org.jdesktop.swingx.JXList(); removeProductButton = new javax.swing.JButton(); addProductButton = new javax.swing.JButton(); jComboBox1 = new javax.swing.JComboBox(); removeSynonymButton = new javax.swing.JButton(); addSynonymButton = new javax.swing.JButton(); newSynonymField = new javax.swing.JTextField(); productLabel = new javax.swing.JLabel(); autoStorePreviousCheckBox = new javax.swing.JCheckBox(); locationField = new javax.swing.JTextField(); locationLabel = new javax.swing.JLabel(); okButton = new javax.swing.JButton(); cancelButton = new javax.swing.JButton(); oldNameLabel = new javax.swing.JLabel(); jScrollPane4 = new javax.swing.JScrollPane(); oldNamesList = new org.jdesktop.swingx.JXList(); addOldNameButton = new javax.swing.JButton(); removeOldNameButton = new javax.swing.JButton(); prevSystematicIdLabel = new javax.swing.JLabel(); jScrollPane5 = new javax.swing.JScrollPane(); prevSystematicIdsList = new org.jdesktop.swingx.JXList(); addPrevSystematicIdButton = new javax.swing.JButton(); removePrevSystematicIdButton = new javax.swing.JButton(); addPrevSystematicIdField = new javax.swing.JTextField(); addOldNameField = new javax.swing.JTextField(); refreshStateButton = new javax.swing.JButton(); jScrollPane3 = new javax.swing.JScrollPane(); changeArea = new javax.swing.JTextArea(); sysIdLabel.setText("Systematic Id"); org.jdesktop.beansbinding.Binding binding = org.jdesktop.beansbinding.Bindings.createAutoBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, model, org.jdesktop.beansbinding.ELProperty.create("${gene.uniqueName}"), sysIdField, org.jdesktop.beansbinding.BeanProperty.create("text")); bindingGroup.addBinding(binding); nameLabel.setText("Name"); synonymsLabel.setText("Synonyms"); synonymsList.setModel(new javax.swing.AbstractListModel() { String[] strings = { "Item 1", "Item 2", "Item 3", "Item 4", "Item 5" }; public int getSize() { return strings.length; } public Object getElementAt(int i) { return strings[i]; } }); synonymsList.addListSelectionListener(new javax.swing.event.ListSelectionListener() { public void valueChanged(javax.swing.event.ListSelectionEvent evt) { synonymsListValueChanged(evt); } }); jScrollPane1.setViewportView(synonymsList); productsList.addListSelectionListener(new javax.swing.event.ListSelectionListener() { public void valueChanged(javax.swing.event.ListSelectionEvent evt) { productsListValueChanged(evt); } }); jScrollPane2.setViewportView(productsList); removeProductButton.setText("Remove"); removeProductButton.setEnabled(false); addProductButton.setText("Add"); jComboBox1.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" })); removeSynonymButton.setText("Remove"); removeSynonymButton.setEnabled(false); removeSynonymButton.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { removeSynonymButtonActionPerformed(evt); } }); addSynonymButton.setText("Add"); binding = org.jdesktop.beansbinding.Bindings.createAutoBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, newSynonymField, org.jdesktop.beansbinding.ELProperty.create("${!empty text}"), addSynonymButton, org.jdesktop.beansbinding.BeanProperty.create("enabled")); bindingGroup.addBinding(binding); addSynonymButton.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { addSynonymButtonActionPerformed(evt); } }); productLabel.setText("Product"); autoStorePreviousCheckBox.setText("<html>Automatically store old values <br>of systematic id and name</html>"); binding = org.jdesktop.beansbinding.Bindings.createAutoBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, model, org.jdesktop.beansbinding.ELProperty.create("${autoAddOldNames}"), autoStorePreviousCheckBox, org.jdesktop.beansbinding.BeanProperty.create("selected")); bindingGroup.addBinding(binding); autoStorePreviousCheckBox.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { autoStorePreviousCheckBoxActionPerformed(evt); } }); locationField.setText(" "); locationField.setName("locationField"); // NOI18N locationLabel.setText("Location"); okButton.setText("OK"); cancelButton.setText("Cancel"); oldNameLabel.setText("Old names"); oldNamesList.setName("oldNamesList"); // NOI18N oldNamesList.addListSelectionListener(new javax.swing.event.ListSelectionListener() { public void valueChanged(javax.swing.event.ListSelectionEvent evt) { oldNamesListValueChanged(evt); } }); jScrollPane4.setViewportView(oldNamesList); addOldNameButton.setText("Add"); binding = org.jdesktop.beansbinding.Bindings.createAutoBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, addOldNameField, org.jdesktop.beansbinding.ELProperty.create("${!empty text}"), addOldNameButton, org.jdesktop.beansbinding.BeanProperty.create("enabled")); bindingGroup.addBinding(binding); removeOldNameButton.setText("Remove"); removeOldNameButton.setEnabled(false); prevSystematicIdLabel.setText("<html>Previous<br>systematic id</html>"); prevSystematicIdsList.setName("prevSystematicIdsList"); // NOI18N prevSystematicIdsList.addListSelectionListener(new javax.swing.event.ListSelectionListener() { public void valueChanged(javax.swing.event.ListSelectionEvent evt) { prevSystematicIdsListValueChanged(evt); } }); jScrollPane5.setViewportView(prevSystematicIdsList); addPrevSystematicIdButton.setText("Add"); binding = org.jdesktop.beansbinding.Bindings.createAutoBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, addPrevSystematicIdField, org.jdesktop.beansbinding.ELProperty.create("${!empty text}"), addPrevSystematicIdButton, org.jdesktop.beansbinding.BeanProperty.create("enabled")); bindingGroup.addBinding(binding); removePrevSystematicIdButton.setText("Remove"); removePrevSystematicIdButton.setEnabled(false); addPrevSystematicIdField.setName("newPrevSystematicId"); // NOI18N addOldNameField.setName("newOldNameField"); // NOI18N refreshStateButton.setText("Refresh Changes"); changeArea.setColumns(20); changeArea.setRows(5); binding = org.jdesktop.beansbinding.Bindings.createAutoBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, addPrevSystematicIdField, org.jdesktop.beansbinding.ELProperty.create("${text.length}"), changeArea, org.jdesktop.beansbinding.BeanProperty.create("text")); bindingGroup.addBinding(binding); jScrollPane3.setViewportView(changeArea); javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this); this.setLayout(layout); layout.setHorizontalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addGap(320, 320, 320) .addComponent(okButton) .addGap(18, 18, 18) .addComponent(cancelButton) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 210, Short.MAX_VALUE) .addComponent(refreshStateButton)) .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup() .addContainerGap() .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING) .addComponent(locationLabel) .addComponent(prevSystematicIdLabel) .addComponent(oldNameLabel) .addComponent(productLabel) .addComponent(nameLabel) .addComponent(sysIdLabel) .addComponent(synonymsLabel)) .addGap(12, 12, 12) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addComponent(jScrollPane5, javax.swing.GroupLayout.DEFAULT_SIZE, 336, Short.MAX_VALUE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)) .addComponent(jScrollPane4, javax.swing.GroupLayout.DEFAULT_SIZE, 336, Short.MAX_VALUE) .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 336, Short.MAX_VALUE) .addComponent(nameField, javax.swing.GroupLayout.DEFAULT_SIZE, 336, Short.MAX_VALUE) .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 336, Short.MAX_VALUE) .addComponent(sysIdField, javax.swing.GroupLayout.DEFAULT_SIZE, 336, Short.MAX_VALUE) .addGroup(layout.createSequentialGroup() .addComponent(locationField, javax.swing.GroupLayout.DEFAULT_SIZE, 336, Short.MAX_VALUE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED))) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addGap(7, 7, 7) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addGap(6, 6, 6) .addComponent(autoStorePreviousCheckBox, javax.swing.GroupLayout.DEFAULT_SIZE, 293, Short.MAX_VALUE)) .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup() .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(removeSynonymButton) .addGroup(layout.createSequentialGroup() .addComponent(addSynonymButton) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(newSynonymField, javax.swing.GroupLayout.DEFAULT_SIZE, 250, Short.MAX_VALUE)) .addComponent(removeProductButton) .addGroup(layout.createSequentialGroup() .addComponent(addProductButton) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(jComboBox1, 0, 250, Short.MAX_VALUE)) .addComponent(removeOldNameButton))))) .addGroup(layout.createSequentialGroup() .addGap(6, 6, 6) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(removePrevSystematicIdButton) .addGroup(layout.createSequentialGroup() .addComponent(addOldNameButton) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(addOldNameField, javax.swing.GroupLayout.DEFAULT_SIZE, 257, Short.MAX_VALUE)) .addGroup(layout.createSequentialGroup() .addComponent(addPrevSystematicIdButton) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(addPrevSystematicIdField, javax.swing.GroupLayout.DEFAULT_SIZE, 257, Short.MAX_VALUE)))))) .addGroup(layout.createSequentialGroup() .addGap(24, 24, 24) .addComponent(jScrollPane3, javax.swing.GroupLayout.DEFAULT_SIZE, 729, Short.MAX_VALUE))) .addContainerGap()) ); layout.setVerticalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addContainerGap() .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(sysIdLabel) .addComponent(sysIdField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(nameLabel) .addComponent(nameField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))) .addComponent(autoStorePreviousCheckBox, javax.swing.GroupLayout.PREFERRED_SIZE, 56, javax.swing.GroupLayout.PREFERRED_SIZE)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(synonymsLabel) .addGroup(layout.createSequentialGroup() .addComponent(removeSynonymButton) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(addSynonymButton) .addComponent(newSynonymField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))) .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 61, javax.swing.GroupLayout.PREFERRED_SIZE)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(productLabel) .addComponent(removeProductButton)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(addProductButton) .addComponent(jComboBox1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))) .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 63, javax.swing.GroupLayout.PREFERRED_SIZE)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false) .addGroup(layout.createSequentialGroup() .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(oldNameLabel) .addComponent(removeOldNameButton)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(addOldNameButton) .addComponent(addOldNameField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addGap(4, 4, 4)) .addComponent(jScrollPane4, javax.swing.GroupLayout.PREFERRED_SIZE, 63, javax.swing.GroupLayout.PREFERRED_SIZE)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false) .addComponent(jScrollPane5, javax.swing.GroupLayout.PREFERRED_SIZE, 63, javax.swing.GroupLayout.PREFERRED_SIZE) .addGroup(layout.createSequentialGroup() .addComponent(removePrevSystematicIdButton) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(addPrevSystematicIdButton) .addComponent(addPrevSystematicIdField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))) .addComponent(prevSystematicIdLabel)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(locationField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(locationLabel)) .addGap(67, 67, 67) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(cancelButton) .addComponent(okButton) .addComponent(refreshStateButton)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(jScrollPane3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addGap(16, 16, 16)) ); bindingGroup.bind(); }// </editor-fold>//GEN-END:initComponents private void removeSynonymButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_removeSynonymButtonActionPerformed Object[] toRemove = synonymsList.getSelectedValues(); List<String> newModel = new ArrayList<String>(); for (Object o : toRemove) { // gene.removeSynonym((String)o); int size = synonymsList.getModel().getSize(); for (int i = 0; i < toRemove.length; i++) { Object object = toRemove[i]; String s = (String) o; if (!synonymsList.getModel().getElementAt(i).equals(o)) { // newModel.add(synonymsList.getModel().getElementAt(i)); } else { break; } } //synonymsList.setModel(new DefaultListModel(newMo)) //synonymsList.getModel(). } }//GEN-LAST:event_removeSynonymButtonActionPerformed private void addSynonymButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_addSynonymButtonActionPerformed // TODO add your handling code here: }//GEN-LAST:event_addSynonymButtonActionPerformed private void autoStorePreviousCheckBoxActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_autoStorePreviousCheckBoxActionPerformed // TODO add your handling code here: }//GEN-LAST:event_autoStorePreviousCheckBoxActionPerformed private void enableButtonOnSelection(JList list, JButton target) { if (list.isSelectionEmpty()) { target.setEnabled(false); } else { target.setEnabled(true); } } private void synonymsListValueChanged(javax.swing.event.ListSelectionEvent evt) {//GEN-FIRST:event_synonymsListValueChanged enableButtonOnSelection(synonymsList, removeSynonymButton); }//GEN-LAST:event_synonymsListValueChanged private void productsListValueChanged(javax.swing.event.ListSelectionEvent evt) {//GEN-FIRST:event_productsListValueChanged enableButtonOnSelection(productsList, removeProductButton); }//GEN-LAST:event_productsListValueChanged private void oldNamesListValueChanged(javax.swing.event.ListSelectionEvent evt) {//GEN-FIRST:event_oldNamesListValueChanged enableButtonOnSelection(oldNamesList, removeOldNameButton); }//GEN-LAST:event_oldNamesListValueChanged private void prevSystematicIdsListValueChanged(javax.swing.event.ListSelectionEvent evt) {//GEN-FIRST:event_prevSystematicIdsListValueChanged enableButtonOnSelection(prevSystematicIdsList, removePrevSystematicIdButton); }//GEN-LAST:event_prevSystematicIdsListValueChanged // Variables declaration - do not modify//GEN-BEGIN:variables private javax.swing.JButton addOldNameButton; private javax.swing.JTextField addOldNameField; private javax.swing.JButton addPrevSystematicIdButton; private javax.swing.JTextField addPrevSystematicIdField; private javax.swing.JButton addProductButton; private javax.swing.JButton addSynonymButton; private javax.swing.JCheckBox autoStorePreviousCheckBox; private javax.swing.JButton cancelButton; private javax.swing.JTextArea changeArea; private javax.swing.JComboBox jComboBox1; private javax.swing.JScrollPane jScrollPane1; private javax.swing.JScrollPane jScrollPane2; private javax.swing.JScrollPane jScrollPane3; private javax.swing.JScrollPane jScrollPane4; private javax.swing.JScrollPane jScrollPane5; private javax.swing.JTextField locationField; private javax.swing.JLabel locationLabel; private org.genedb.jogra.plugins.GeneViewModel model; private javax.swing.JTextField nameField; private javax.swing.JLabel nameLabel; private javax.swing.JTextField newSynonymField; private javax.swing.JButton okButton; private javax.swing.JLabel oldNameLabel; private org.jdesktop.swingx.JXList oldNamesList; private javax.swing.JLabel prevSystematicIdLabel; private org.jdesktop.swingx.JXList prevSystematicIdsList; private javax.swing.JLabel productLabel; private org.jdesktop.swingx.JXList productsList; private javax.swing.JButton refreshStateButton; private javax.swing.JButton removeOldNameButton; private javax.swing.JButton removePrevSystematicIdButton; private javax.swing.JButton removeProductButton; private javax.swing.JButton removeSynonymButton; private javax.swing.JLabel synonymsLabel; private org.jdesktop.swingx.JXList synonymsList; private javax.swing.JTextField sysIdField; private javax.swing.JLabel sysIdLabel; private org.jdesktop.beansbinding.BindingGroup bindingGroup; // End of variables declaration//GEN-END:variables }