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 209058
Collapse All | Expand All

(-)a/bugtracking/src/org/netbeans/modules/bugtracking/util/StackTraceSupport.java (-32 / +4 lines)
Lines 70-82 Link Here
70
import org.netbeans.api.java.classpath.GlobalPathRegistry;
70
import org.netbeans.api.java.classpath.GlobalPathRegistry;
71
import org.netbeans.modules.bugtracking.BugtrackingManager;
71
import org.netbeans.modules.bugtracking.BugtrackingManager;
72
import org.netbeans.modules.bugtracking.spi.VCSAccessor;
72
import org.netbeans.modules.bugtracking.spi.VCSAccessor;
73
import org.openide.cookies.EditorCookie;
74
import org.openide.cookies.LineCookie;
75
import org.openide.cookies.OpenCookie;
76
import org.openide.filesystems.FileObject;
73
import org.openide.filesystems.FileObject;
77
import org.openide.filesystems.FileUtil;
74
import org.openide.filesystems.FileUtil;
78
import org.openide.loaders.DataObject;
75
import org.openide.loaders.DataObject;
79
import org.openide.text.Line;
76
import org.openide.text.Line.ShowOpenType;
77
import org.openide.text.Line.ShowVisibilityType;
78
import org.openide.text.NbDocument;
80
import org.openide.util.Lookup;
79
import org.openide.util.Lookup;
81
import org.openide.util.NbBundle;
80
import org.openide.util.NbBundle;
82
81
Lines 340-373 Link Here
340
    private static boolean doOpen(FileObject fo, int line) {
339
    private static boolean doOpen(FileObject fo, int line) {
341
        try {
340
        try {
342
            DataObject od = DataObject.find(fo);
341
            DataObject od = DataObject.find(fo);
343
            EditorCookie ec = od.getCookie(org.openide.cookies.EditorCookie.class);
342
            return NbDocument.openDocument(od, line, -1, ShowOpenType.OPEN, ShowVisibilityType.FOCUS);
344
            LineCookie lc = od.getCookie(org.openide.cookies.LineCookie.class);
345
346
            if (ec != null && lc != null && line != -1) {
347
                StyledDocument doc = ec.openDocument();
348
                if (doc != null) {
349
                    if (line != -1) {
350
                        Line l = null;
351
                        try {
352
                            l = lc.getLineSet().getCurrent(line);
353
                        } catch (IndexOutOfBoundsException e) {
354
                            BugtrackingManager.LOG.log(Level.FINE, null, e);
355
                            ec.open();
356
                            return false;
357
                        }
358
                        if (l != null) {
359
                            l.show(Line.ShowOpenType.OPEN, Line.ShowVisibilityType.FOCUS);
360
                            return true;
361
                        }
362
                    }
363
                 }
364
            }
365
366
            OpenCookie oc = od.getCookie(org.openide.cookies.OpenCookie.class);
367
            if (oc != null) {
368
                oc.open();
369
                return true;
370
            }
371
        } catch (IOException e) {
343
        } catch (IOException e) {
372
            BugtrackingManager.LOG.log(Level.SEVERE, null, e);
344
            BugtrackingManager.LOG.log(Level.SEVERE, null, e);
373
        }
345
        }
(-)a/csl.api/src/org/netbeans/modules/csl/api/UiUtils.java (-52 / +6 lines)
Lines 43-49 Link Here
43
 */
43
 */
44
package org.netbeans.modules.csl.api;
44
package org.netbeans.modules.csl.api;
45
45
46
import java.io.IOException;
47
import java.util.Collection;
46
import java.util.Collection;
48
import java.util.Collections;
47
import java.util.Collections;
49
import java.util.List;
48
import java.util.List;
Lines 60-66 Link Here
60
import javax.swing.text.BadLocationException;
59
import javax.swing.text.BadLocationException;
61
import javax.swing.text.Document;
60
import javax.swing.text.Document;
62
import javax.swing.text.JTextComponent;
61
import javax.swing.text.JTextComponent;
63
import javax.swing.text.StyledDocument;
64
import org.netbeans.api.lexer.TokenHierarchy;
62
import org.netbeans.api.lexer.TokenHierarchy;
65
import org.netbeans.api.lexer.TokenSequence;
63
import org.netbeans.api.lexer.TokenSequence;
66
import org.netbeans.api.progress.ProgressUtils;
64
import org.netbeans.api.progress.ProgressUtils;
Lines 77-92 Link Here
77
import org.netbeans.modules.parsing.api.indexing.IndexingManager;
75
import org.netbeans.modules.parsing.api.indexing.IndexingManager;
78
import org.netbeans.modules.parsing.spi.ParseException;
76
import org.netbeans.modules.parsing.spi.ParseException;
79
import org.netbeans.modules.parsing.spi.Parser;
77
import org.netbeans.modules.parsing.spi.Parser;
80
import org.openide.DialogDisplayer;
81
import org.openide.NotifyDescriptor;
82
import org.openide.cookies.EditorCookie;
83
import org.openide.cookies.LineCookie;
84
import org.openide.cookies.OpenCookie;
85
import org.openide.filesystems.FileObject;
78
import org.openide.filesystems.FileObject;
79
import org.openide.loaders.DataObject;
80
import org.openide.loaders.DataObjectNotFoundException;
86
import org.openide.text.Line;
81
import org.openide.text.Line;
87
import org.openide.text.NbDocument;
82
import org.openide.text.NbDocument;
88
import org.openide.util.NbBundle;
83
import org.openide.util.NbBundle;
89
import org.openide.util.UserQuestionException;
90
84
91
85
92
/** 
86
/** 
Lines 250-300 Link Here
250
244
251
    private static boolean doOpen(FileObject fo, int offset) {
245
    private static boolean doOpen(FileObject fo, int offset) {
252
        try {
246
        try {
253
            EditorCookie ec = DataLoadersBridge.getDefault().getCookie(fo, EditorCookie.class);
247
            DataObject od = DataObject.find(fo);
254
            LineCookie lc = DataLoadersBridge.getDefault().getCookie(fo, LineCookie.class);
248
            return NbDocument.openDocument(od, offset, Line.ShowOpenType.OPEN, Line.ShowVisibilityType.FOCUS);
255
249
        } catch (DataObjectNotFoundException e) {
256
            if ((ec != null) && (lc != null) && (offset != -1)) {
250
            LOG.log(Level.WARNING, null, e);
257
                StyledDocument doc = null;
258
                try {
259
                    doc = ec.openDocument();
260
                } catch (UserQuestionException uqe) {
261
                    final Object value = DialogDisplayer.getDefault().notify(
262
                            new NotifyDescriptor.Confirmation(uqe.getLocalizedMessage(),
263
                            NbBundle.getMessage(UiUtils.class, "TXT_Question"),
264
                            NotifyDescriptor.YES_NO_OPTION));
265
                    if (value != NotifyDescriptor.YES_OPTION) {
266
                        return false;
267
                    }
268
                    uqe.confirmed();
269
                    doc = ec.openDocument();
270
                }
271
272
                if (doc != null) {
273
                    int line = NbDocument.findLineNumber(doc, offset);
274
                    int lineOffset = NbDocument.findLineOffset(doc, line);
275
                    int column = offset - lineOffset;
276
277
                    if (line != -1) {
278
                        Line l = lc.getLineSet().getCurrent(line);
279
280
                        if (l != null) {
281
                            l.show(Line.ShowOpenType.OPEN, Line.ShowVisibilityType.FOCUS, column);
282
                            return true;
283
                        }
284
                    }
285
                }
286
            }
287
288
            OpenCookie oc = DataLoadersBridge.getDefault().getCookie(fo, OpenCookie.class);
289
290
            if (oc != null) {
291
                oc.open();
292
                return true;
293
            }
294
        } catch (IOException ioe) {
295
            LOG.log(Level.WARNING, null, ioe);
296
        }
251
        }
297
298
        return false;
252
        return false;
299
    }
253
    }
300
254
(-)a/csl.api/src/org/netbeans/modules/csl/spi/GsfUtilities.java (-29 / +3 lines)
Lines 284-290 Link Here
284
284
285
            // Simple text search if no known offset (e.g. broken/unparseable source)
285
            // Simple text search if no known offset (e.g. broken/unparseable source)
286
            if ((ec != null) && (search != null) && (offset == -1)) {
286
            if ((ec != null) && (search != null) && (offset == -1)) {
287
                StyledDocument doc = ec.openDocument();
287
                StyledDocument doc = NbDocument.getDocument(od);
288
288
289
                try {
289
                try {
290
                    String text = doc.getText(0, doc.getLength());
290
                    String text = doc.getText(0, doc.getLength());
Lines 302-335 Link Here
302
                    LOG.log(Level.WARNING, null, ble);
302
                    LOG.log(Level.WARNING, null, ble);
303
                }
303
                }
304
            }
304
            }
305
305
            
306
            if ((ec != null) && (lc != null) && (offset != -1)) {
306
            return NbDocument.openDocument(od, offset, Line.ShowOpenType.OPEN, Line.ShowVisibilityType.FOCUS);
307
                StyledDocument doc = ec.openDocument();
308
309
                if (doc != null) {
310
                    int line = NbDocument.findLineNumber(doc, offset);
311
                    int lineOffset = NbDocument.findLineOffset(doc, line);
312
                    int column = offset - lineOffset;
313
314
                    if (line != -1) {
315
                        Line l = lc.getLineSet().getCurrent(line);
316
317
                        if (l != null) {
318
                            l.show(Line.ShowOpenType.OPEN, Line.ShowVisibilityType.FOCUS, column);
319
320
                            return true;
321
                        }
322
                    }
323
                }
324
            }
325
326
            OpenCookie oc = od.getCookie(OpenCookie.class);
327
328
            if (oc != null) {
329
                oc.open();
330
331
                return true;
332
            }
333
        } catch (IOException e) {
307
        } catch (IOException e) {
334
            ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, e);
308
            ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, e);
335
        }
309
        }
(-)a/gototest/nbproject/project.xml (-53 / +1 lines)
Lines 50-108 Link Here
50
            <code-name-base>org.netbeans.modules.gototest</code-name-base>
50
            <code-name-base>org.netbeans.modules.gototest</code-name-base>
51
            <module-dependencies>
51
            <module-dependencies>
52
                <dependency>
52
                <dependency>
53
                    <code-name-base>org.netbeans.modules.csl.api</code-name-base>
54
                    <build-prerequisite/>
55
                    <compile-dependency/>
56
                    <run-dependency>
57
                        <release-version>2</release-version>
58
                        <specification-version>2.6</specification-version>
59
                    </run-dependency>
60
                </dependency>
61
                <dependency>
62
                    <code-name-base>org.netbeans.modules.editor.lib</code-name-base>
63
                    <build-prerequisite/>
64
                    <compile-dependency/>
65
                    <run-dependency>
66
                        <release-version>3</release-version>
67
                        <specification-version>3.1</specification-version>
68
                    </run-dependency>
69
                </dependency>
70
                <dependency>
71
                    <code-name-base>org.netbeans.modules.parsing.api</code-name-base>
72
                    <build-prerequisite/>
73
                    <compile-dependency/>
74
                    <run-dependency>
75
                        <release-version>1</release-version>
76
                        <specification-version>1.34</specification-version>
77
                    </run-dependency>
78
                </dependency>
79
                <dependency>
80
                    <code-name-base>org.netbeans.modules.projectapi</code-name-base>
81
                    <build-prerequisite/>
82
                    <compile-dependency/>
83
                    <run-dependency>
84
                        <release-version>1</release-version>
85
                        <specification-version>1.3</specification-version>
86
                    </run-dependency>
87
                </dependency>
88
                <dependency>
89
                    <code-name-base>org.netbeans.modules.projectuiapi</code-name-base>
90
                    <build-prerequisite/>
91
                    <compile-dependency/>
92
                    <run-dependency>
93
                        <release-version>1</release-version>
94
                    </run-dependency>
95
                </dependency>
96
                <dependency>
97
                    <code-name-base>org.netbeans.modules.queries</code-name-base>
98
                    <build-prerequisite/>
99
                    <compile-dependency/>
100
                    <run-dependency>
101
                        <release-version>1</release-version>
102
                        <specification-version>1.5</specification-version>
103
                    </run-dependency>
104
                </dependency>
105
                <dependency>
106
                    <code-name-base>org.openide.awt</code-name-base>
53
                    <code-name-base>org.openide.awt</code-name-base>
107
                    <build-prerequisite/>
54
                    <build-prerequisite/>
108
                    <compile-dependency/>
55
                    <compile-dependency/>
Lines 183-188 Link Here
183
                <friend>org.netbeans.modules.python.project</friend>
130
                <friend>org.netbeans.modules.python.project</friend>
184
                <friend>org.netbeans.modules.refactoring.java</friend>
131
                <friend>org.netbeans.modules.refactoring.java</friend>
185
                <friend>org.netbeans.modules.ruby.project</friend>
132
                <friend>org.netbeans.modules.ruby.project</friend>
133
                <friend>org.netbeans.modules.testng</friend>
186
                <package>org.netbeans.spi.gototest</package>
134
                <package>org.netbeans.spi.gototest</package>
187
            </friend-packages>
135
            </friend-packages>
188
        </data>
136
        </data>
(-)a/gototest/src/org/netbeans/modules/gototest/GotoOppositeAction.java (-2 / +11 lines)
Lines 46-55 Link Here
46
46
47
import java.awt.EventQueue;
47
import java.awt.EventQueue;
48
import java.util.Collection;
48
import java.util.Collection;
49
import java.util.logging.Level;
50
import java.util.logging.Logger;
49
import javax.swing.Action;
51
import javax.swing.Action;
50
import javax.swing.JEditorPane;
52
import javax.swing.JEditorPane;
51
import javax.swing.text.Document;
53
import javax.swing.text.Document;
52
import org.netbeans.modules.csl.api.UiUtils;
53
import org.netbeans.spi.gototest.TestLocator;
54
import org.netbeans.spi.gototest.TestLocator;
54
import org.netbeans.spi.gototest.TestLocator.FileType;
55
import org.netbeans.spi.gototest.TestLocator.FileType;
55
import org.netbeans.spi.gototest.TestLocator.LocationListener;
56
import org.netbeans.spi.gototest.TestLocator.LocationListener;
Lines 59-66 Link Here
59
import org.openide.cookies.EditorCookie;
60
import org.openide.cookies.EditorCookie;
60
import org.openide.filesystems.FileObject;
61
import org.openide.filesystems.FileObject;
61
import org.openide.loaders.DataObject;
62
import org.openide.loaders.DataObject;
63
import org.openide.loaders.DataObjectNotFoundException;
62
import org.openide.nodes.Node;
64
import org.openide.nodes.Node;
63
import org.openide.text.CloneableEditorSupport;
65
import org.openide.text.CloneableEditorSupport;
66
import org.openide.text.Line;
64
import org.openide.text.NbDocument;
67
import org.openide.text.NbDocument;
65
import org.openide.util.HelpCtx;
68
import org.openide.util.HelpCtx;
66
import org.openide.util.Lookup;
69
import org.openide.util.Lookup;
Lines 163-169 Link Here
163
    private void handleResult(LocationResult opposite) {
166
    private void handleResult(LocationResult opposite) {
164
        FileObject fileObject = opposite.getFileObject();
167
        FileObject fileObject = opposite.getFileObject();
165
        if (fileObject != null) {
168
        if (fileObject != null) {
166
            UiUtils.open(fileObject, opposite.getOffset());
169
            DataObject dobj = null;
170
            try {
171
                dobj = DataObject.find(fileObject);
172
            } catch (DataObjectNotFoundException ex) {
173
                Logger.getLogger(GotoOppositeAction.class.getName()).log(Level.WARNING, null, ex);
174
            }
175
            NbDocument.openDocument(dobj, opposite.getOffset(), Line.ShowOpenType.OPEN, Line.ShowVisibilityType.FOCUS);
167
        } else if (opposite.getErrorMessage() != null) {
176
        } else if (opposite.getErrorMessage() != null) {
168
            String msg = opposite.getErrorMessage();
177
            String msg = opposite.getErrorMessage();
169
            NotifyDescriptor descr = new NotifyDescriptor.Message(msg, 
178
            NotifyDescriptor descr = new NotifyDescriptor.Message(msg, 
(-)a/kenai.ui/src/org/netbeans/modules/kenai/collab/chat/ChatPanel.form (-2 / +2 lines)
Lines 1-4 Link Here
1
<?xml version="1.1" encoding="UTF-8" ?>
1
<?xml version="1.0" encoding="UTF-8" ?>
2
2
3
<Form version="1.5" maxVersion="1.7" type="org.netbeans.modules.form.forminfo.JPanelFormInfo">
3
<Form version="1.5" maxVersion="1.7" type="org.netbeans.modules.form.forminfo.JPanelFormInfo">
4
  <NonVisualComponents>
4
  <NonVisualComponents>
Lines 77-83 Link Here
77
                  <Group type="103" groupAlignment="0" attributes="0">
77
                  <Group type="103" groupAlignment="0" attributes="0">
78
                      <Group type="102" alignment="1" attributes="0">
78
                      <Group type="102" alignment="1" attributes="0">
79
                          <Component id="sendLinkButton" min="-2" max="-2" attributes="0"/>
79
                          <Component id="sendLinkButton" min="-2" max="-2" attributes="0"/>
80
                          <EmptySpace pref="140" max="32767" attributes="0"/>
80
                          <EmptySpace pref="187" max="32767" attributes="0"/>
81
                          <Component id="sendButton" min="-2" max="-2" attributes="0"/>
81
                          <Component id="sendButton" min="-2" max="-2" attributes="0"/>
82
                      </Group>
82
                      </Group>
83
                  </Group>
83
                  </Group>
(-)a/kenai.ui/src/org/netbeans/modules/kenai/collab/chat/ChatPanel.java (-32 / +2 lines)
Lines 94-102 Link Here
94
import org.netbeans.spi.java.classpath.support.ClassPathSupport;
94
import org.netbeans.spi.java.classpath.support.ClassPathSupport;
95
import org.openide.awt.DropDownButtonFactory;
95
import org.openide.awt.DropDownButtonFactory;
96
import org.openide.awt.HtmlBrowser.URLDisplayer;
96
import org.openide.awt.HtmlBrowser.URLDisplayer;
97
import org.openide.cookies.EditorCookie;
98
import org.openide.cookies.LineCookie;
99
import org.openide.cookies.OpenCookie;
100
import org.openide.filesystems.FileObject;
97
import org.openide.filesystems.FileObject;
101
import org.openide.filesystems.FileUtil;
98
import org.openide.filesystems.FileUtil;
102
import org.openide.loaders.DataObject;
99
import org.openide.loaders.DataObject;
Lines 107-113 Link Here
107
import org.openide.windows.Mode;
104
import org.openide.windows.Mode;
108
import org.openide.windows.TopComponent;
105
import org.openide.windows.TopComponent;
109
import org.openide.windows.WindowManager;
106
import org.openide.windows.WindowManager;
110
import static org.netbeans.modules.kenai.collab.chat.ChatTopComponent.*;
107
import org.openide.text.NbDocument;
111
108
112
/**
109
/**
113
 * Panel representing single ChatRoom
110
 * Panel representing single ChatRoom
Lines 366-399 Link Here
366
    private static boolean doOpen(FileObject fo, int line) {
363
    private static boolean doOpen(FileObject fo, int line) {
367
        try {
364
        try {
368
            DataObject od = DataObject.find(fo);
365
            DataObject od = DataObject.find(fo);
369
            EditorCookie ec = (EditorCookie) od.getCookie(EditorCookie.class);
366
            return NbDocument.openDocument(od, line, -1, Line.ShowOpenType.OPEN, Line.ShowVisibilityType.FOCUS);
370
            LineCookie lc = (LineCookie) od.getCookie(LineCookie.class);
371
372
            if (ec != null && lc != null && line != -1) {
373
                StyledDocument doc = ec.openDocument();
374
                if (doc != null) {
375
                    if (line != -1) {
376
                        Line l = null;
377
                        try {
378
                            l = lc.getLineSet().getCurrent(line - 1);
379
                        } catch (IndexOutOfBoundsException e) { // try to open at least the file (line no. is too high?)
380
                            l = lc.getLineSet().getCurrent(0);
381
                        }
382
383
                        if (l != null) {
384
                            l.show(Line.ShowOpenType.OPEN, Line.ShowVisibilityType.FOCUS);
385
                            return true;
386
                        }
387
                    }
388
                }
389
            }
390
391
            OpenCookie oc = (OpenCookie) od.getCookie(OpenCookie.class);
392
393
            if (oc != null) {
394
                oc.open();
395
                return true;
396
            }
397
        } catch (IOException e) {
367
        } catch (IOException e) {
398
            Exceptions.printStackTrace(e);
368
            Exceptions.printStackTrace(e);
399
        }
369
        }
(-)a/openide.text/apichanges.xml (+20 lines)
Lines 49-54 Link Here
49
<apidef name="text">Text API</apidef>
49
<apidef name="text">Text API</apidef>
50
</apidefs>
50
</apidefs>
51
<changes>
51
<changes>
52
      <change id="NbDocument.openDocument">
53
          <api name="text"/>
54
          <summary>Added methods <code>NbDocument.getDocument</code>, 
55
          <code>NbDocument.openDocument</code> with offset parameter and 
56
          <code>NbDocument.openDocument</code> with line and column parameter</summary>
57
          <version major="6" minor="45"/>
58
          <date day="21" month="3" year="2012"/>
59
          <author login="theofanis"/>
60
          <compatibility addition="yes"/>
61
          <description>
62
              <p>
63
                  First method gets the StyledDocument associated with a file while the other two 
64
                  are used to open the document associated with a file in the Editor window
65
                  in a position specified by the offset or line and column while
66
                  controlling open and visibility behavior.
67
              </p>
68
          </description>
69
          <class package="org.openide.text" name="NbDocument"/>
70
          <issue number="209058"/>
71
      </change>
52
    <change id="mark-commit-group">
72
    <change id="mark-commit-group">
53
        <api name="text"/>
73
        <api name="text"/>
54
        <summary>fix hole in commit-groups about empty commit group</summary>
74
        <summary>fix hole in commit-groups about empty commit group</summary>
(-)a/openide.text/manifest.mf (-1 / +1 lines)
Lines 1-7 Link Here
1
Manifest-Version: 1.0
1
Manifest-Version: 1.0
2
OpenIDE-Module: org.openide.text
2
OpenIDE-Module: org.openide.text
3
OpenIDE-Module-Install: org/netbeans/modules/openide/text/Installer.class
3
OpenIDE-Module-Install: org/netbeans/modules/openide/text/Installer.class
4
OpenIDE-Module-Specification-Version: 6.44
4
OpenIDE-Module-Specification-Version: 6.45
5
OpenIDE-Module-Localizing-Bundle: org/openide/text/Bundle.properties
5
OpenIDE-Module-Localizing-Bundle: org/openide/text/Bundle.properties
6
AutoUpdate-Essential-Module: true
6
AutoUpdate-Essential-Module: true
7
7
(-)a/openide.text/src/org/openide/text/NbDocument.java (+169 lines)
Lines 45-57 Link Here
45
45
46
import java.awt.Color;
46
import java.awt.Color;
47
import java.awt.Component;
47
import java.awt.Component;
48
import java.io.IOException;
49
import java.util.logging.Level;
50
import java.util.logging.Logger;
48
51
49
52
50
import javax.swing.JEditorPane;
53
import javax.swing.JEditorPane;
51
import javax.swing.JToolBar;
54
import javax.swing.JToolBar;
52
import javax.swing.SwingUtilities;
55
import javax.swing.SwingUtilities;
53
import javax.swing.text.*;
56
import javax.swing.text.*;
57
import org.netbeans.api.actions.Openable;
58
import org.openide.DialogDisplayer;
59
import org.openide.NotifyDescriptor;
54
import org.openide.cookies.EditorCookie;
60
import org.openide.cookies.EditorCookie;
61
import org.openide.cookies.LineCookie;
62
import org.openide.util.Lookup;
63
import org.openide.util.Mutex;
64
import org.openide.util.NbBundle;
65
import org.openide.util.UserQuestionException;
55
66
56
67
57
/** Dummy class holding utility methods for working with NetBeans document conventions.
68
/** Dummy class holding utility methods for working with NetBeans document conventions.
Lines 518-523 Link Here
518
        }
529
        }
519
        ((Annotatable) doc).removeAnnotation(annotation);
530
        ((Annotatable) doc).removeAnnotation(annotation);
520
    }
531
    }
532
    
533
    /**
534
     * Get the document associated with a file.
535
     *
536
     * <p>Method will throw {@link org.openide.util.UserQuestionException}
537
     * exception if file size is too big. This exception is caught and its
538
     * method {@link org.openide.util.UserQuestionException#confirmed} is used
539
     * for confirmation.
540
     *
541
     *
542
     * @param provider for example a {@link DataObject}
543
     * @return {@link javax.swing.text.StyledDocument} or null
544
     * @since org.openide.text 6.45
545
     */
546
    @NbBundle.Messages("TXT_Question=Question")
547
    public static StyledDocument getDocument(Lookup.Provider provider) {
548
        try {
549
            EditorCookie ec = provider.getLookup().lookup(EditorCookie.class);
550
            if (ec != null) {
551
                StyledDocument doc = null;
552
                try {
553
                    doc = ec.openDocument();
554
                } catch (UserQuestionException uqe) {
555
                    final Object value = DialogDisplayer.getDefault().notify(
556
                            new NotifyDescriptor.Confirmation(uqe.getLocalizedMessage(),
557
                            Bundle.TXT_Question(),
558
                            NotifyDescriptor.YES_NO_OPTION));
559
                    if (value != NotifyDescriptor.YES_OPTION) {
560
                        return null;
561
                    }
562
                    uqe.confirmed();
563
                    doc = ec.openDocument();
564
                }
565
                return doc;
566
            }
567
        } catch (IOException ioe) {
568
            Logger.getLogger(NbDocument.class.getName()).log(Level.WARNING, null, ioe);
569
        }
570
        return null;
571
    }
572
    
573
    /**
574
     * Open the document associated with a file in the Editor window in a
575
     * position specified by the offset while controlling open and visibility behavior.
576
     * This method can be called from any thread but blocks until the document is opened.
577
     *
578
     * @param provider for example a {@link DataObject}
579
     * @param offset the position the document should be opened (starting at 0)
580
     * @param openType control open behavior, {@link org.openide.text.Line.ShowOpenType#OPEN}
581
     * would typically be used
582
     * @param visibilityType control visibility behavior, {@link org.openide.text.Line.ShowVisibilityType#FOCUS}
583
     * would typically be used
584
     * @return true if the Document is opened - false otherwise
585
     * @see #getDocument
586
     * <code>UserQuestionException handling</code>
587
     * @since org.openide.text 6.45
588
     */
589
    public static boolean openDocument(Lookup.Provider provider, int offset, Line.ShowOpenType openType, Line.ShowVisibilityType visibilityType) {
590
        assert provider != null;
591
        LineCookie lc = provider.getLookup().lookup(LineCookie.class);
592
        if ((lc != null) && (offset != -1)) {
593
            StyledDocument doc = getDocument(provider);
594
595
            if (doc != null) {
596
                int line = NbDocument.findLineNumber(doc, offset);
597
                int column = NbDocument.findLineColumn(doc, offset);
598
                
599
                Line l = null;
600
                try {
601
                    l = lc.getLineSet().getCurrent(line);
602
                } catch (IndexOutOfBoundsException e) { // try to open at least the file (line no. is too high?)
603
                    l = lc.getLineSet().getCurrent(0);
604
                }
605
606
                if (l != null) {
607
                    doShow(l, column, openType, visibilityType);
608
                    return true;
609
                }
610
            }
611
        }
612
613
        Openable oc = provider.getLookup().lookup(Openable.class);
614
615
        if (oc != null) {
616
            doOpen(oc);
617
            return true;
618
        }
619
        return false;
620
    }
621
    
622
    /**
623
     * Open the document associated with a file in the Editor window in a
624
     * position specified by the line and column while controlling open and visibility behavior.
625
     * This method can be called from any thread but blocks until the document is opened.
626
     *
627
     * @param provider for example a {@link DataObject}
628
     * @param line the line the document should be opened (starting at 0)
629
     * @param column the column which should be selected (starting at 0), value
630
     * -1 does not change previously selected column
631
     * @param openType control open behavior, {@link org.openide.text.Line.ShowOpenType#OPEN}
632
     * would typically be used
633
     * @param visibilityType control visibility behavior, {@link org.openide.text.Line.ShowVisibilityType#FOCUS}
634
     * would typically be used
635
     * @return true if the Document is opened - false otherwise
636
     * @see #getDocument
637
     * <code>UserQuestionException handling</code>
638
     * @since org.openide.text 6.45
639
     */
640
    public static boolean openDocument(Lookup.Provider provider, int line, int column, Line.ShowOpenType openType, Line.ShowVisibilityType visibilityType) {
641
        assert provider != null;
642
        LineCookie lc = provider.getLookup().lookup(LineCookie.class);
643
        if ((lc != null) && (line >= 0) && (column >= -1)) {
644
            StyledDocument doc = getDocument(provider);
645
646
            if (doc != null) {
647
                Line l = null;
648
                try {
649
                    l = lc.getLineSet().getCurrent(line);
650
                } catch (IndexOutOfBoundsException e) { // try to open at least the file (line no. is too high?)
651
                    l = lc.getLineSet().getCurrent(0);
652
                }
653
654
                if (l != null) {
655
                    doShow(l, column, openType, visibilityType);
656
                    return true;
657
                }
658
            }
659
        }
660
661
        final Openable oc = provider.getLookup().lookup(Openable.class);
662
663
        if (oc != null) {
664
            doOpen(oc);
665
            return true;
666
        }
667
        
668
        return false;
669
    }
670
    
671
    private static void doShow(final Line l, final int column, final Line.ShowOpenType openType, final Line.ShowVisibilityType visibilityType) {
672
        Mutex.EVENT.writeAccess(new Runnable() {
673
674
            @Override
675
            public void run() {
676
                l.show(openType, visibilityType, column);
677
            }
678
        });
679
    }
680
681
    private static void doOpen(final Openable oc) {
682
        Mutex.EVENT.writeAccess(new Runnable() {
683
684
            @Override
685
            public void run() {
686
                oc.open();
687
            }
688
        });
689
    }
521
690
522
    /** Specialized version of document that knows how to lock the document
691
    /** Specialized version of document that knows how to lock the document
523
    * for complex modifications.
692
    * for complex modifications.
(-)a/refactoring.java/src/org/netbeans/modules/refactoring/java/callhierarchy/Call.java (-38 / +10 lines)
Lines 45-51 Link Here
45
import com.sun.source.util.TreePath;
45
import com.sun.source.util.TreePath;
46
import java.awt.EventQueue;
46
import java.awt.EventQueue;
47
import java.awt.Image;
47
import java.awt.Image;
48
import java.io.IOException;
49
import java.util.ArrayList;
48
import java.util.ArrayList;
50
import java.util.Collection;
49
import java.util.Collection;
51
import java.util.Collections;
50
import java.util.Collections;
Lines 63-69 Link Here
63
import javax.lang.model.type.TypeVariable;
62
import javax.lang.model.type.TypeVariable;
64
import javax.lang.model.type.WildcardType;
63
import javax.lang.model.type.WildcardType;
65
import javax.swing.Icon;
64
import javax.swing.Icon;
66
import javax.swing.text.StyledDocument;
67
import org.netbeans.api.java.source.CompilationInfo;
65
import org.netbeans.api.java.source.CompilationInfo;
68
import org.netbeans.api.java.source.ElementHandle;
66
import org.netbeans.api.java.source.ElementHandle;
69
import org.netbeans.api.java.source.TreePathHandle;
67
import org.netbeans.api.java.source.TreePathHandle;
Lines 72-79 Link Here
72
import org.netbeans.modules.refactoring.java.RetoucheUtils;
70
import org.netbeans.modules.refactoring.java.RetoucheUtils;
73
import org.openide.awt.StatusDisplayer;
71
import org.openide.awt.StatusDisplayer;
74
import org.openide.cookies.EditorCookie;
72
import org.openide.cookies.EditorCookie;
75
import org.openide.cookies.LineCookie;
76
import org.openide.cookies.OpenCookie;
77
import org.openide.filesystems.FileObject;
73
import org.openide.filesystems.FileObject;
78
import org.openide.filesystems.FileUtil;
74
import org.openide.filesystems.FileUtil;
79
import org.openide.loaders.DataObject;
75
import org.openide.loaders.DataObject;
Lines 81-87 Link Here
81
import org.openide.text.Line;
77
import org.openide.text.Line;
82
import org.openide.text.NbDocument;
78
import org.openide.text.NbDocument;
83
import org.openide.text.PositionBounds;
79
import org.openide.text.PositionBounds;
84
import org.openide.util.Exceptions;
85
import org.openide.util.ImageUtilities;
80
import org.openide.util.ImageUtilities;
86
import org.openide.util.NbBundle;
81
import org.openide.util.NbBundle;
87
82
Lines 400-445 Link Here
400
            final int begin = bounds.getBegin().getOffset();
395
            final int begin = bounds.getBegin().getOffset();
401
            final int end = bounds.getEnd().getOffset();
396
            final int end = bounds.getEnd().getOffset();
402
            DataObject od = DataObject.find(fo);
397
            DataObject od = DataObject.find(fo);
403
            final EditorCookie ec = od.getCookie(org.openide.cookies.EditorCookie.class);
398
            final EditorCookie ec = od.getLookup().lookup(org.openide.cookies.EditorCookie.class);
404
            LineCookie lc = od.getCookie(org.openide.cookies.LineCookie.class);
399
            boolean opened = NbDocument.openDocument(od, begin, Line.ShowOpenType.OPEN, Line.ShowVisibilityType.FOCUS);
400
            if (opened) {
401
                EventQueue.invokeLater(new Runnable() {
405
402
406
            if (ec != null && lc != null && begin != -1) {                
403
                    @Override
407
                StyledDocument doc = ec.openDocument();                
404
                    public void run() {
408
                if (doc != null) {
405
                        ec.getOpenedPanes()[0].setSelectionStart(begin);
409
                    int line = NbDocument.findLineNumber(doc, begin);
406
                        ec.getOpenedPanes()[0].setSelectionEnd(end);
410
                    int lineOffset = NbDocument.findLineOffset(doc, line);
411
                    int column = begin - lineOffset;
412
413
                    if (line != -1) {
414
                        Line l = lc.getLineSet().getCurrent(line);
415
416
                        if (l != null) {
417
                            l.show(Line.ShowOpenType.OPEN, Line.ShowVisibilityType.FOCUS, column);
418
419
                            EventQueue.invokeLater(new Runnable() {
420
421
                                public void run() {
422
                                    ec.getOpenedPanes()[0].setSelectionStart(begin);
423
                                    ec.getOpenedPanes()[0].setSelectionEnd(end);
424
                                }
425
                            });
426
                            return true;
427
                        }
428
                    }
407
                    }
429
                }
408
                });
430
            }
431
432
            OpenCookie oc = od.getCookie(org.openide.cookies.OpenCookie.class);
433
434
            if (oc != null) {
435
                oc.open();                
436
                return true;
409
                return true;
437
            }
410
            }
411
            return opened;
438
        } catch (DataObjectNotFoundException e) {
412
        } catch (DataObjectNotFoundException e) {
439
            StatusDisplayer.getDefault().setStatusText(NbBundle.getMessage(
413
            StatusDisplayer.getDefault().setStatusText(NbBundle.getMessage(
440
                    Call.class, "Call.open.warning", FileUtil.getFileDisplayName(fo))); // NOI18N
414
                    Call.class, "Call.open.warning", FileUtil.getFileDisplayName(fo))); // NOI18N
441
        } catch (IOException e) {
442
            Exceptions.printStackTrace(e);
443
        }
415
        }
444
416
445
        return false;
417
        return false;
(-)a/refactoring.java/src/org/netbeans/modules/refactoring/java/plugins/JavadocUtilities.java (-24 / +3 lines)
Lines 67-73 Link Here
67
import javax.swing.text.BadLocationException;
67
import javax.swing.text.BadLocationException;
68
import javax.swing.text.Document;
68
import javax.swing.text.Document;
69
import javax.swing.text.Position;
69
import javax.swing.text.Position;
70
import javax.swing.text.StyledDocument;
71
import org.netbeans.api.java.lexer.JavaTokenId;
70
import org.netbeans.api.java.lexer.JavaTokenId;
72
import org.netbeans.api.java.lexer.JavadocTokenId;
71
import org.netbeans.api.java.lexer.JavadocTokenId;
73
import org.netbeans.api.java.source.ClasspathInfo.PathKind;
72
import org.netbeans.api.java.source.ClasspathInfo.PathKind;
Lines 75-85 Link Here
75
import org.netbeans.api.lexer.Token;
74
import org.netbeans.api.lexer.Token;
76
import org.netbeans.api.lexer.TokenId;
75
import org.netbeans.api.lexer.TokenId;
77
import org.netbeans.api.lexer.TokenSequence;
76
import org.netbeans.api.lexer.TokenSequence;
78
import org.openide.cookies.EditorCookie;
79
import org.openide.cookies.LineCookie;
80
import org.openide.filesystems.FileObject;
77
import org.openide.filesystems.FileObject;
81
import org.openide.loaders.DataObject;
78
import org.openide.loaders.DataObject;
82
import org.openide.text.Line;
79
import org.openide.text.Line.ShowOpenType;
80
import org.openide.text.Line.ShowVisibilityType;
83
import org.openide.text.NbDocument;
81
import org.openide.text.NbDocument;
84
82
85
/**
83
/**
Lines 585-610 Link Here
585
    private static boolean doOpenImpl(FileObject fo, int offset) {
583
    private static boolean doOpenImpl(FileObject fo, int offset) {
586
        try {
584
        try {
587
            DataObject od = DataObject.find(fo);
585
            DataObject od = DataObject.find(fo);
588
            EditorCookie ec = od.getCookie(EditorCookie.class);
586
            return NbDocument.openDocument(od, offset, ShowOpenType.OPEN, ShowVisibilityType.FOCUS);
589
            LineCookie lc = od.getCookie(LineCookie.class);
590
591
            if (ec != null && lc != null && offset != -1) {
592
                StyledDocument doc = ec.openDocument();
593
                if (doc != null) {
594
                    int line = NbDocument.findLineNumber(doc, offset);
595
                    int lineOffset = NbDocument.findLineOffset(doc, line);
596
                    int column = offset - lineOffset;
597
598
                    if (line != -1) {
599
                        Line l = lc.getLineSet().getCurrent(line);
600
601
                        if (l != null) {
602
                            l.show(Line.ShowOpenType.OPEN, Line.ShowVisibilityType.FOCUS, column);
603
                            return true;
604
                        }
605
                    }
606
                }
607
            }
608
        } catch (IOException ex) {
587
        } catch (IOException ex) {
609
            Logger.getLogger(JavadocUtilities.class.getName()).log(Level.SEVERE, ex.getMessage(), ex);
588
            Logger.getLogger(JavadocUtilities.class.getName()).log(Level.SEVERE, ex.getMessage(), ex);
610
        }
589
        }

Return to bug 209058