1 19 20 package org.netbeans.modules.tasklist.usertasks.dependencies; 21 22 import java.awt.Image ; 23 import java.util.List ; 24 import java.util.ResourceBundle ; 25 import javax.swing.ImageIcon ; 26 import javax.swing.tree.DefaultTreeCellRenderer ; 27 import javax.swing.tree.TreePath ; 28 import org.netbeans.modules.tasklist.usertasks.model.UserTask; 29 import org.openide.DialogDescriptor; 30 31 import org.openide.util.Utilities; 32 import org.netbeans.modules.tasklist.usertasks.model.Dependency; 33 import org.openide.util.NbBundle; 34 35 38 public class DependencyPanel extends javax.swing.JPanel { 39 42 private static class UserTaskTreeCellRenderer extends DefaultTreeCellRenderer { 43 private static final Image IMAGE = 44 Utilities.loadImage("org/netbeans/modules/tasklist/core/task.gif"); private static final Image DONE = 46 Utilities.loadImage("org/netbeans/modules/tasklist/core/doneItem.gif"); private ImageIcon icon = new ImageIcon (); 48 49 public java.awt.Component getTreeCellRendererComponent( 50 javax.swing.JTree tree, Object value, boolean sel, boolean expanded, 51 boolean leaf, int row, boolean hasFocus) { 52 53 super.getTreeCellRendererComponent( 54 tree, value, sel, expanded, leaf, row, hasFocus); 55 if (value instanceof UserTask) { 56 UserTask ut = (UserTask) value; 57 this.setText(ut.getSummary()); 58 this.setIcon(icon); 59 60 if (ut.isDone()) 61 icon.setImage(DONE); 62 else 63 icon.setImage(IMAGE); 64 } 65 66 return this; 67 } 68 } 69 70 private UserTask ut; 71 private DialogDescriptor dd; 72 private List curDeps; 73 74 80 public DependencyPanel(UserTask ut, List curDeps) { 81 this.ut = ut; 82 this.curDeps = curDeps; 83 initComponents(); 84 jTree.setModel(new UserTaskTreeModel(ut.getList())); 85 jTree.setCellRenderer(new UserTaskTreeCellRenderer()); 86 jTreeValueChanged(null); 87 } 88 89 94 public void setDialogDescriptor(DialogDescriptor dd) { 95 this.dd = dd; 96 jTreeValueChanged(null); 97 } 98 99 104 public void setSelectedTask(UserTask ut) { 105 if (ut != null) 106 jTree.setSelectionPath(ut.getPathTo()); 107 else 108 jTree.setSelectionPath(null); 109 } 110 111 116 public UserTask getSelectedTask() { 117 TreePath tp = jTree.getSelectionPath(); 118 if (tp == null) 119 return null; 120 return (UserTask) tp.getLastPathComponent(); 121 } 122 123 128 public void setDependencyType(int type) { 129 if (type == Dependency.BEGIN_BEGIN) 130 jRadioButtonBeginBegin.setSelected(true); 131 else 132 jRadioButtonEndBegin.setSelected(true); 133 } 134 135 140 public int getDependencyType() { 141 if (jRadioButtonBeginBegin.isSelected()) 142 return Dependency.BEGIN_BEGIN; 143 else 144 return Dependency.END_BEGIN; 145 } 146 147 152 private void initComponents() { java.awt.GridBagConstraints gridBagConstraints; 154 155 buttonGroup = new javax.swing.ButtonGroup (); 156 jScrollPane1 = new javax.swing.JScrollPane (); 157 jTree = new javax.swing.JTree (); 158 jRadioButtonEndBegin = new javax.swing.JRadioButton (); 159 jRadioButtonBeginBegin = new javax.swing.JRadioButton (); 160 jLabelError = new javax.swing.JLabel (); 161 162 setLayout(new java.awt.GridBagLayout ()); 163 164 jTree.setRootVisible(false); 165 jTree.setShowsRootHandles(true); 166 jTree.addTreeSelectionListener(new javax.swing.event.TreeSelectionListener () { 167 public void valueChanged(javax.swing.event.TreeSelectionEvent evt) { 168 jTreeValueChanged(evt); 169 } 170 }); 171 172 jScrollPane1.setViewportView(jTree); 173 174 gridBagConstraints = new java.awt.GridBagConstraints (); 175 gridBagConstraints.gridx = 0; 176 gridBagConstraints.gridy = 1; 177 gridBagConstraints.gridwidth = 3; 178 gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; 179 gridBagConstraints.weightx = 1.0; 180 gridBagConstraints.weighty = 1.0; 181 gridBagConstraints.insets = new java.awt.Insets (0, 0, 11, 0); 182 add(jScrollPane1, gridBagConstraints); 183 184 buttonGroup.add(jRadioButtonEndBegin); 185 jRadioButtonEndBegin.setSelected(true); 186 org.openide.awt.Mnemonics.setLocalizedText(jRadioButtonEndBegin, org.openide.util.NbBundle.getBundle(DependencyPanel.class).getString("LBL_EndBegin")); 187 gridBagConstraints = new java.awt.GridBagConstraints (); 188 gridBagConstraints.insets = new java.awt.Insets (0, 0, 11, 12); 189 add(jRadioButtonEndBegin, gridBagConstraints); 190 191 buttonGroup.add(jRadioButtonBeginBegin); 192 org.openide.awt.Mnemonics.setLocalizedText(jRadioButtonBeginBegin, org.openide.util.NbBundle.getBundle(DependencyPanel.class).getString("LBL_BeginBegin")); 193 gridBagConstraints = new java.awt.GridBagConstraints (); 194 gridBagConstraints.insets = new java.awt.Insets (0, 0, 11, 0); 195 add(jRadioButtonBeginBegin, gridBagConstraints); 196 197 jLabelError.setMinimumSize(new java.awt.Dimension (0, 15)); 198 gridBagConstraints = new java.awt.GridBagConstraints (); 199 gridBagConstraints.gridx = 0; 200 gridBagConstraints.gridy = 2; 201 gridBagConstraints.gridwidth = 3; 202 gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; 203 add(jLabelError, gridBagConstraints); 204 205 } 207 private void jTreeValueChanged(javax.swing.event.TreeSelectionEvent evt) { String err = null; 209 210 ResourceBundle rb = NbBundle.getBundle(DependencyPanel.class); 211 212 TreePath tp = jTree.getSelectionPath(); 213 if (tp == null || !(tp.getLastPathComponent() instanceof UserTask)) { 214 err = org.openide.util.NbBundle.getBundle(DependencyPanel.class). 215 getString("NothingSelected"); } else { 217 UserTask task = (UserTask) tp.getLastPathComponent(); 218 219 if (task == ut) 220 err = rb.getString("TaskCannotDependOnItself."); else if (task == ut.getParent()) 222 err = rb.getString("TaskCannotDependOnParent"); else if (task.isAncestorOf(ut)) 224 err = rb.getString("TaskCannotDependOnAncestor"); else if (ut.isAncestorOf(task)) 226 err = rb.getString("TaskCannotDependOnChild"); 228 for (int i = 0; i < curDeps.size(); i++) { 229 Dependency d = (Dependency) curDeps.get(i); 230 if (d.getDependsOn() == task) 231 err = rb.getString("DependencyAlreadyExists"); else if (task.isAncestorOf(d.getDependsOn())) 233 err = rb.getString("DependencyOnChildAlreadyExists"); else if (d.getDependsOn().isAncestorOf(task)) 235 err = rb.getString("DependencyOnAncestorAlreadyExists"); 237 if (err != null) 238 break; 239 } 240 } 241 242 jLabelError.setText(err == null ? "" : err); if (dd != null) 244 dd.setValid(err == null); 245 } 247 248 private javax.swing.ButtonGroup buttonGroup; 250 private javax.swing.JLabel jLabelError; 251 private javax.swing.JRadioButton jRadioButtonBeginBegin; 252 private javax.swing.JRadioButton jRadioButtonEndBegin; 253 private javax.swing.JScrollPane jScrollPane1; 254 private javax.swing.JTree jTree; 255 257 } 258 | Popular Tags |