1 package org.netbeans.modules.tasklist.usertasks.dependencies; 2 3 import java.awt.Dialog ; 4 import java.awt.Dimension ; 5 import java.util.ArrayList ; 6 import java.util.Iterator ; 7 import java.util.List ; 8 import javax.swing.DefaultListModel ; 9 import javax.swing.border.EmptyBorder ; 10 import javax.swing.event.ListSelectionEvent ; 11 import javax.swing.event.ListSelectionListener ; 12 import org.netbeans.modules.tasklist.usertasks.model.UserTask; 13 import org.openide.DialogDescriptor; 14 import org.openide.DialogDisplayer; 15 import org.openide.util.NbBundle; 16 import org.openide.util.Utilities; 17 import org.netbeans.modules.tasklist.usertasks.model.Dependency; 18 19 24 public class DependenciesPanel extends javax.swing.JPanel { 25 private static final String BEGIN_BEGIN_MSG = 26 NbBundle.getMessage(DependenciesPanel.class, "BeginBeginDep"); private static final String END_BEGIN_MSG = 28 NbBundle.getMessage(DependenciesPanel.class, "EndBeginDep"); 30 private UserTask ut; 31 private List <Dependency> dependencies = new ArrayList <Dependency>(); 32 33 36 public DependenciesPanel() { 37 initComponents(); 38 jList.getSelectionModel().addListSelectionListener( 39 new ListSelectionListener () { 40 public void valueChanged(ListSelectionEvent e) { 41 jButtonRemove.setEnabled(jList.getSelectedIndex() >= 0); 42 } 43 } 44 ); 45 } 46 47 52 public void fillPanel(UserTask ut) { 53 this.ut = ut; 54 DefaultListModel dlm = new DefaultListModel (); 55 Iterator it = ut.getDependencies().iterator(); 56 while (it.hasNext()) { 57 Dependency d = (Dependency) it.next(); 58 dependencies.add(d); 59 dlm.addElement(createTaskDescription(d.getDependsOn(), d.getType())); 60 } 61 jList.setModel(dlm); 62 if (jList.getModel().getSize() > 0) 63 jList.setSelectedIndex(0); 64 } 65 66 73 private String createTaskDescription(UserTask ut, int type) { 74 StringBuffer sb = new StringBuffer (); 75 while (ut != null) { 76 if (sb.length() != 0) 77 sb.insert(0, '/'); 78 sb.insert(0, ut.getSummary()); 79 ut = ut.getParent(); 80 } 81 sb.append(" - "); if (type == Dependency.BEGIN_BEGIN) 83 sb.append(BEGIN_BEGIN_MSG); 84 else 85 sb.append(END_BEGIN_MSG); 86 return sb.toString(); 87 } 88 89 92 public void fillObject() { 93 this.ut.getDependencies().clear(); 94 this.ut.getDependencies().addAll(dependencies); 95 } 96 97 102 private void initComponents() { java.awt.GridBagConstraints gridBagConstraints; 104 105 jScrollPane1 = new javax.swing.JScrollPane (); 106 jList = new javax.swing.JList (); 107 jButtonRemove = new javax.swing.JButton (); 108 jButtonAdd = new javax.swing.JButton (); 109 110 setLayout(new java.awt.GridBagLayout ()); 111 112 jScrollPane1.setViewportView(jList); 113 114 gridBagConstraints = new java.awt.GridBagConstraints (); 115 gridBagConstraints.gridx = 0; 116 gridBagConstraints.gridy = 0; 117 gridBagConstraints.gridheight = 2; 118 gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; 119 gridBagConstraints.weightx = 1.0; 120 gridBagConstraints.weighty = 1.0; 121 gridBagConstraints.insets = new java.awt.Insets (0, 0, 0, 12); 122 add(jScrollPane1, gridBagConstraints); 123 124 org.openide.awt.Mnemonics.setLocalizedText(jButtonRemove, org.openide.util.NbBundle.getBundle(DependenciesPanel.class).getString("LBL_RemoveDependency")); 125 jButtonRemove.setEnabled(false); 126 jButtonRemove.addActionListener(new java.awt.event.ActionListener () { 127 public void actionPerformed(java.awt.event.ActionEvent evt) { 128 jButtonRemoveActionPerformed(evt); 129 } 130 }); 131 132 gridBagConstraints = new java.awt.GridBagConstraints (); 133 gridBagConstraints.gridx = 1; 134 gridBagConstraints.gridy = 1; 135 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 136 gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST; 137 add(jButtonRemove, gridBagConstraints); 138 139 org.openide.awt.Mnemonics.setLocalizedText(jButtonAdd, org.openide.util.NbBundle.getBundle(DependenciesPanel.class).getString("LBL_AddDependency")); 140 jButtonAdd.addActionListener(new java.awt.event.ActionListener () { 141 public void actionPerformed(java.awt.event.ActionEvent evt) { 142 jButtonAddActionPerformed(evt); 143 } 144 }); 145 146 gridBagConstraints = new java.awt.GridBagConstraints (); 147 gridBagConstraints.gridx = 1; 148 gridBagConstraints.gridy = 0; 149 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 150 gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST; 151 gridBagConstraints.insets = new java.awt.Insets (0, 0, 11, 0); 152 add(jButtonAdd, gridBagConstraints); 153 154 } 156 private void jButtonRemoveActionPerformed(java.awt.event.ActionEvent evt) { DialogDescriptor.Confirmation conf = new DialogDescriptor.Confirmation( 158 NbBundle.getMessage(DependenciesPanel.class, "DeleteDepConf"), DialogDescriptor.YES_NO_OPTION, DialogDescriptor.QUESTION_MESSAGE 160 ); 161 Object ret = DialogDisplayer.getDefault().notify(conf); 162 if (ret == DialogDescriptor.YES_OPTION) { 163 int index = jList.getSelectedIndex(); 164 ((DefaultListModel ) jList.getModel()).remove(index); 165 dependencies.remove(index); 166 if (jList.getModel().getSize() > index) 167 jList.setSelectedIndex(index); 168 else if (jList.getModel().getSize() > index - 1) 169 jList.setSelectedIndex(index - 1); 170 } 171 } 173 private void jButtonAddActionPerformed(java.awt.event.ActionEvent evt) { DependencyPanel dp = new DependencyPanel(ut, dependencies); 175 dp.setBorder(new EmptyBorder (11, 11, 12, 12)); 176 DialogDescriptor dd = new DialogDescriptor(dp, 177 NbBundle.getMessage( 178 DependenciesPanel.class, "AddDependency")); dp.setDialogDescriptor(dd); 180 Dialog d = DialogDisplayer.getDefault().createDialog(dd); 181 d.setBounds(Utilities.findCenterBounds(new Dimension (400, 400))); 182 d.setVisible(true); 183 if (dd.getValue() == DialogDescriptor.OK_OPTION) { 184 UserTask sel = dp.getSelectedTask(); 185 int type = dp.getDependencyType(); 186 dependencies.add(new Dependency(sel, type)); 187 ((DefaultListModel ) jList.getModel()).addElement( 188 createTaskDescription(sel, type)); 189 jList.setSelectedIndex(jList.getModel().getSize() - 1); 190 } 191 } 193 194 private javax.swing.JButton jButtonAdd; 196 private javax.swing.JButton jButtonRemove; 197 private javax.swing.JList jList; 198 private javax.swing.JScrollPane jScrollPane1; 199 201 } 202 | Popular Tags |