This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

View | Details | Raw Unified | Return to bug 173691
Collapse All | Expand All

(-)xml.text/src/org/netbeans/modules/xml/text/completion/ValueResultItem.java (-1 / +33 lines)
Lines 1-7 Link Here
1
/*
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
3
 *
4
 * Copyright 1997-2009 Sun Microsystems, Inc. All rights reserved.
4
 * Copyright 1997-2010 Sun Microsystems, Inc. All rights reserved.
5
 *
5
 *
6
 * The contents of this file are subject to the terms of either the GNU
6
 * The contents of this file are subject to the terms of either the GNU
7
 * General Public License Version 2 only ("GPL") or the Common
7
 * General Public License Version 2 only ("GPL") or the Common
Lines 43-48 Link Here
43
import java.awt.Color;
43
import java.awt.Color;
44
44
45
import java.beans.BeanInfo;
45
import java.beans.BeanInfo;
46
import java.util.logging.Level;
47
import java.util.logging.Logger;
48
import javax.swing.text.BadLocationException;
49
import javax.swing.text.JTextComponent;
50
import org.netbeans.editor.BaseDocument;
46
import org.netbeans.modules.xml.api.model.*;
51
import org.netbeans.modules.xml.api.model.*;
47
52
48
53
Lines 60-65 Link Here
60
 * @author  Petr Kuzel
65
 * @author  Petr Kuzel
61
 */
66
 */
62
class ValueResultItem extends XMLResultItem {
67
class ValueResultItem extends XMLResultItem {
68
    private static final Logger _logger = Logger.getLogger(ValueResultItem.class.getName());
63
69
64
    private final String replacementText;
70
    private final String replacementText;
65
71
Lines 77-82 Link Here
77
    }
83
    }
78
    
84
    
79
    @Override
85
    @Override
86
    boolean replaceText(final JTextComponent component,
87
          final String replaceToText, final int offset, final int len) {
88
        //+++ fix for issue #173691
89
        //    (http://netbeans.org/bugzilla/show_bug.cgi?id=173691)
90
        final BaseDocument doc = (BaseDocument)component.getDocument();
91
        doc.runAtomic(new Runnable() {
92
            @Override
93
            public void run() {
94
                try {
95
                    int newLen = len;
96
                    if (component.getSelectedText() != null) {
97
                        newLen += component.getSelectionEnd() - component.
98
                              getCaretPosition();
99
                    }
100
                    doc.remove(offset, newLen);
101
                    doc.insertString(offset, replaceToText, null);
102
                } catch (BadLocationException e) {
103
                    _logger.log(Level.SEVERE, e.getMessage() == null ? e.
104
                          getClass().getName() : e.getMessage(), e);
105
                }
106
            }
107
        });
108
        return true;
109
    }
110
111
    @Override
80
    Color getPaintColor() { return Color.blue; }
112
    Color getPaintColor() { return Color.blue; }
81
113
82
}
114
}

Return to bug 173691