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