KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > tasklist > checkstyle > DeleteLineSuggestionPerformer


1 /*
2  * DeleteLineSuggestionPerformer.java
3  *
4  * Created on December 30, 2005, 9:06 AM
5  *
6  * To change this template, choose Tools | Template Manager
7  * and open the template in the editor.
8  */

9
10 package org.netbeans.modules.tasklist.checkstyle;
11
12
13 import javax.swing.text.BadLocationException JavaDoc;
14 import javax.swing.text.Document JavaDoc;
15 import javax.swing.text.Element JavaDoc;
16
17 import org.netbeans.modules.tasklist.client.Suggestion;
18
19 import org.openide.ErrorManager;
20
21 /** Simple. Removes the whole line.
22  *
23  * @author hair
24  */

25 public final class DeleteLineSuggestionPerformer extends AbstractSuggestionPerformer{
26     
27     /** Creates a new instance of TrailingSpacesSuggestionPerformer */
28     DeleteLineSuggestionPerformer(
29             final Document JavaDoc doc,
30             final int lineno) {
31         
32         super(doc,lineno,-1);
33     }
34
35     public void perform(final Suggestion suggestion) {
36         
37         // check line hasn't changed already
38
super.perform(suggestion);
39         
40         final Element JavaDoc elm = getElement(doc, lineno-1);
41         if (elm == null) {
42             ErrorManager.getDefault().log(ErrorManager.USER, "getElement was null");
43             return;
44         }
45         final int offset = elm.getStartOffset();
46         final int endOffset = elm.getEndOffset();
47         try {
48             doc.remove(offset,endOffset-offset);
49         } catch (BadLocationException JavaDoc ex) {
50             ErrorManager.getDefault().notify(ErrorManager.WARNING, ex);
51         }
52     }
53
54     /** Such a simple operation there's no need to ask for confirmation.
55      * Also a little tricky to display whitespace being deleted!
56      **/

57     public Object JavaDoc getConfirmation(final Suggestion suggestion) {
58         return null;
59     }
60
61     public boolean hasConfirmation() {
62         return false;
63     }
64
65     protected void performImpl(int docPosition) throws BadLocationException JavaDoc {
66     }
67
68 }
69
Popular Tags