1 19 20 package org.netbeans.modules.j2ee.ddloaders.ejb; 21 22 import java.awt.Component ; 23 import java.util.List ; 24 import java.util.Iterator ; 25 26 import javax.swing.*; 27 import javax.swing.border.EmptyBorder ; 28 import javax.swing.event.ListSelectionListener ; 29 import javax.swing.event.ListSelectionEvent ; 30 31 import org.openide.util.NbBundle; 32 import org.openide.filesystems.FileStateInvalidException; 33 34 39 public class DDChangesPanel extends JPanel { 40 41 private JPanel changesPanel; 42 private JScrollPane jScrollPane1; 43 JList changesList; 44 45 DefaultListModel listModel; 46 47 48 public DDChangesPanel (String caption, final JButton processButton) { 49 setLayout (new java.awt.BorderLayout (0, 12)); 50 setBorder (new EmptyBorder (12, 12, 11, 0)); 51 52 JTextArea text = new JTextArea (); 53 text.setEnabled (false); 54 text.setEditable (false); 55 text.setDisabledTextColor (UIManager.getColor ("Label.foreground")); text.setBackground (UIManager.getColor ("Label.background")); text.setLineWrap (true); 58 text.setWrapStyleWord (true); 59 text.setText (caption); 60 add (text, "North"); 62 changesPanel = new JPanel (); 63 changesPanel.setLayout (new java.awt.BorderLayout (5, 5)); 64 65 JLabel changesLabel = new JLabel (); 66 changesLabel.setText (NbBundle.getMessage (DDChangesPanel.class, "LAB_ChangesList")); 67 changesLabel.getAccessibleContext ().setAccessibleDescription (NbBundle.getMessage (DDChangesPanel.class, "ACS_ChangesListA11yDesc")); changesPanel.add (changesLabel, "North"); 70 jScrollPane1 = new JScrollPane (); 71 72 listModel = new DefaultListModel (); 73 74 changesList = new JList (listModel); 75 changesList.setToolTipText (NbBundle.getMessage (DDChangesPanel.class, "HINT_ChangesList")); 76 changesList.setCellRenderer (new ChangesListCellRenderer ()); 77 changesList.addListSelectionListener (new ListSelectionListener () { 78 public void valueChanged (ListSelectionEvent e) { 79 processButton.setEnabled (!changesList.isSelectionEmpty ()); 80 } 81 }); 82 changesLabel.setLabelFor (changesList); 83 changesLabel.setDisplayedMnemonic (NbBundle.getMessage (DDChangesPanel.class, "LAB_ChangesList_Mnemonic").charAt (0)); 84 getAccessibleContext().setAccessibleDescription(NbBundle.getMessage (DDChangesPanel.class, "ACS_ChangesListA11yPanelDesc")); 85 86 jScrollPane1.setViewportView (changesList); 87 88 changesPanel.add (jScrollPane1, "Center"); 90 add (changesPanel, "Center"); } 92 93 public java.awt.Dimension getPreferredSize () { 94 return new java.awt.Dimension (600, 400); 95 } 96 97 public synchronized void setChanges (List changes) { 98 listModel.clear (); 99 if (changes != null) { 100 Iterator it = changes.iterator (); 101 while (it.hasNext ()) 102 listModel.addElement (it.next ()); 103 } 104 } 105 106 public DefaultListModel getListModel() { 107 return listModel; 108 } 109 110 public JList getChangesList() { 111 return changesList; 112 } 113 114 static class ChangesListCellRenderer extends DefaultListCellRenderer { 115 116 public Component getListCellRendererComponent(JList list, Object value, 117 int index, boolean isSelected, 118 boolean cellHasFocus) { 119 Component comp = super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus); 120 try { 121 if ((comp instanceof JLabel) && (value instanceof DDChangeEvent)) { 122 DDChangeEvent evt = (DDChangeEvent)value; 123 String label = ""; String clz = evt.getNewValue (); 125 if (evt.getType () == DDChangeEvent.EJB_ADDED) { 126 label = NbBundle.getMessage (DDChangesPanel.class, "LAB_addServletElement", clz); 127 } 128 else if (evt.getType() == DDChangeEvent.EJB_CLASS_CHANGED){ 129 label = NbBundle.getMessage(DDChangesPanel.class, 130 "LAB_changeEjbElement", evt.getOldValue (), evt.getNewValue()); 132 } 133 else if (evt.getType() == DDChangeEvent.EJB_CLASS_DELETED){ 134 label = NbBundle.getMessage(DDChangesPanel.class, 135 "LAB_deleteEjbElement", evt.getNewValue()); } 137 else if (evt.getType() == DDChangeEvent.EJB_HOME_CHANGED){ 138 label = NbBundle.getMessage(DDChangesPanel.class, 139 "LAB_changeHomeElement", evt.getOldValue(), evt.getNewValue()); 141 } 142 else if (evt.getType() == DDChangeEvent.EJB_REMOTE_CHANGED){ 143 label = NbBundle.getMessage(DDChangesPanel.class, 144 "LAB_changeRemoteElement", evt.getOldValue(), evt.getNewValue()); 146 } 147 else if (evt.getType() == 148 DDChangeEvent.EJB_LOCAL_HOME_CHANGED){ 149 label = NbBundle.getMessage(DDChangesPanel.class, 150 "LAB_changeLocalHomeElement", evt.getOldValue(), evt.getNewValue()); 152 } 153 else if (evt.getType() == DDChangeEvent.EJB_LOCAL_CHANGED){ 154 label = NbBundle.getMessage(DDChangesPanel.class, 155 "LAB_changeLocalElement", evt.getOldValue(), evt.getNewValue()); 157 } 158 else if (evt.getType() == DDChangeEvent.EJB_HOME_DELETED){ 159 label = NbBundle.getMessage(DDChangesPanel.class, 160 "LAB_deleteHomeElement", evt.getNewValue ()); 162 } 163 else if (evt.getType() == DDChangeEvent.EJB_REMOTE_DELETED){ 164 label = NbBundle.getMessage(DDChangesPanel.class, 165 "LAB_deleteRemoteElement", evt.getNewValue ()); 167 } 168 else if (evt.getType() == 169 DDChangeEvent.EJB_LOCAL_HOME_DELETED){ 170 label = NbBundle.getMessage(DDChangesPanel.class, 171 "LAB_deleteLocalHomeElement", evt.getNewValue()); 173 } 174 else if (evt.getType() == DDChangeEvent.EJB_LOCAL_DELETED){ 175 label = NbBundle.getMessage(DDChangesPanel.class, 176 "LAB_deleteLocalElement", evt.getNewValue ()); 178 } 179 else if (evt.getType () == DDChangeEvent.EJB_MOVED) { 180 String fsname; 181 try { 182 fsname = evt.getOldDD ().getPrimaryFile ().getFileSystem ().getDisplayName (); 183 } 184 catch (FileStateInvalidException e) { 185 fsname = ""; } 187 label = NbBundle.getMessage (DDChangesPanel.class, "LAB_moveServletElement", clz, fsname); 188 } 189 190 ((JLabel)comp).setText (label); 191 } 192 } 193 catch (Exception e) { 194 e.printStackTrace (); 195 } 196 return comp; 197 } 198 } 199 } 200 | Popular Tags |