KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > tasklist > usertasks > actions > ShowTaskAction


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.modules.tasklist.usertasks.actions;
21
22 import java.awt.Dialog JavaDoc;
23 import java.awt.Dimension JavaDoc;
24 import java.awt.event.ActionEvent JavaDoc;
25 import javax.swing.event.ListSelectionEvent JavaDoc;
26
27 import org.netbeans.modules.tasklist.usertasks.EditTaskPanel;
28 import org.netbeans.modules.tasklist.usertasks.UserTaskView;
29 import org.netbeans.modules.tasklist.usertasks.util.UTUtils;
30 import org.netbeans.modules.tasklist.usertasks.model.UserTask;
31 import org.openide.DialogDescriptor;
32 import org.openide.DialogDisplayer;
33 import org.openide.NotifyDescriptor;
34 import org.openide.nodes.Node;
35 import org.openide.text.Line;
36 import org.openide.util.HelpCtx;
37 import org.openide.util.NbBundle;
38
39 /**
40  * Show a given task to the user
41  *
42  * @author Tor Norbye
43  * @author Trond Norbye
44  * @author tl
45  */

46 public class ShowTaskAction extends UTViewAction {
47     private static final long serialVersionUID = 2;
48
49     /**
50      * Constructor.
51      *
52      * @param utv view for this action
53      */

54     public ShowTaskAction(UserTaskView utv) {
55         super(utv, NbBundle.getMessage(ShowTaskAction.class, "LBL_ShowTodo"));
56     }
57     
58     public void actionPerformed(ActionEvent JavaDoc ae) {
59         // safe - see enable-check above
60
UserTask item = getSingleSelectedTask();
61         
62         EditTaskPanel panel = new EditTaskPanel(true);
63         panel.setPreferredSize(new Dimension JavaDoc(600, 500));
64         panel.fillPanel(item);
65         
66         // find cursor position
67
if (item.getUrl() == null) {
68             Line cursor = UTUtils.findCursorPosition(null);
69             if (cursor == null) {
70                 Node[] editorNodes = UTUtils.getEditorNodes();
71                 if (editorNodes != null)
72                     cursor = UTUtils.findCursorPosition(editorNodes);
73             }
74             if (cursor == null) {
75                 panel.setUrl(null);
76                 panel.setLineNumber(0);
77             } else {
78                 panel.setUrl(UTUtils.getExternalURLForLine(cursor));
79                 panel.setLineNumber(cursor.getLineNumber());
80             }
81         }
82         
83         DialogDescriptor d = new DialogDescriptor(panel,
84             NbBundle.getMessage(ShowTaskAction.class, "TITLE_edit_todo")); // NOI18N
85
d.setModal(true);
86         d.setHelpCtx(new HelpCtx("org.netbeans.modules.tasklist.usertasks.NewTaskDialog")); // NOI18N
87
d.setMessageType(NotifyDescriptor.PLAIN_MESSAGE);
88         d.setOptionType(NotifyDescriptor.OK_CANCEL_OPTION);
89         Dialog JavaDoc dlg = DialogDisplayer.getDefault().createDialog(d);
90         dlg.pack();
91         dlg.setVisible(true);
92
93         if (d.getValue() == NotifyDescriptor.OK_OPTION) {
94             panel.fillObject(item);
95         }
96     }
97
98     public void valueChanged(ListSelectionEvent JavaDoc e) {
99         setEnabled(getSingleSelectedTask() != null);
100     }
101 }
102
Popular Tags