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

(-)bugtracking/src/org/netbeans/modules/bugtracking/util/StackTraceSupport.java (-32 / +2 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.DataEditorSupport;
80
import org.openide.util.Lookup;
77
import org.openide.util.Lookup;
81
import org.openide.util.NbBundle;
78
import org.openide.util.NbBundle;
82
79
Lines 340-373 Link Here
340
    private static boolean doOpen(FileObject fo, int line) {
337
    private static boolean doOpen(FileObject fo, int line) {
341
        try {
338
        try {
342
            DataObject od = DataObject.find(fo);
339
            DataObject od = DataObject.find(fo);
343
            EditorCookie ec = od.getCookie(org.openide.cookies.EditorCookie.class);
340
            return DataEditorSupport.openDocument(od, line, -1);
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) {
341
        } catch (IOException e) {
372
            BugtrackingManager.LOG.log(Level.SEVERE, null, e);
342
            BugtrackingManager.LOG.log(Level.SEVERE, null, e);
373
        }
343
        }
(-)csl.api/src/org/netbeans/modules/csl/api/UiUtils.java (-52 / +7 lines)
Lines 77-92 Link Here
77
import org.netbeans.modules.parsing.api.indexing.IndexingManager;
77
import org.netbeans.modules.parsing.api.indexing.IndexingManager;
78
import org.netbeans.modules.parsing.spi.ParseException;
78
import org.netbeans.modules.parsing.spi.ParseException;
79
import org.netbeans.modules.parsing.spi.Parser;
79
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;
80
import org.openide.filesystems.FileObject;
86
import org.openide.text.Line;
81
import org.openide.loaders.DataObject;
87
import org.openide.text.NbDocument;
82
import org.openide.loaders.DataObjectNotFoundException;
83
import org.openide.text.DataEditorSupport;
88
import org.openide.util.NbBundle;
84
import org.openide.util.NbBundle;
89
import org.openide.util.UserQuestionException;
90
85
91
86
92
/** 
87
/** 
Lines 250-300 Link Here
250
245
251
    private static boolean doOpen(FileObject fo, int offset) {
246
    private static boolean doOpen(FileObject fo, int offset) {
252
        try {
247
        try {
253
            EditorCookie ec = DataLoadersBridge.getDefault().getCookie(fo, EditorCookie.class);
248
            DataObject od = DataObject.find(fo);
254
            LineCookie lc = DataLoadersBridge.getDefault().getCookie(fo, LineCookie.class);
249
            return DataEditorSupport.openDocument(od, offset);
255
250
        } catch (DataObjectNotFoundException e) {
256
            if ((ec != null) && (lc != null) && (offset != -1)) {
251
            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
                    }
252
                    }
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
        }
297
298
        return false;
253
        return false;
299
    }
254
    }
300
255
(-)csl.api/src/org/netbeans/modules/csl/spi/GsfUtilities.java (-30 / +3 lines)
Lines 82-89 Link Here
82
import org.openide.loaders.DataObject;
82
import org.openide.loaders.DataObject;
83
import org.openide.loaders.DataObjectNotFoundException;
83
import org.openide.loaders.DataObjectNotFoundException;
84
import org.openide.text.CloneableEditorSupport;
84
import org.openide.text.CloneableEditorSupport;
85
import org.openide.text.Line;
85
import org.openide.text.DataEditorSupport;
86
import org.openide.text.NbDocument;
87
import org.openide.util.Exceptions;
86
import org.openide.util.Exceptions;
88
import org.openide.util.UserQuestionException;
87
import org.openide.util.UserQuestionException;
89
88
Lines 284-290 Link Here
284
283
285
            // Simple text search if no known offset (e.g. broken/unparseable source)
284
            // Simple text search if no known offset (e.g. broken/unparseable source)
286
            if ((ec != null) && (search != null) && (offset == -1)) {
285
            if ((ec != null) && (search != null) && (offset == -1)) {
287
                StyledDocument doc = ec.openDocument();
286
                StyledDocument doc = DataEditorSupport.getStyledDocument(od);
288
287
289
                try {
288
                try {
290
                    String text = doc.getText(0, doc.getLength());
289
                    String text = doc.getText(0, doc.getLength());
Lines 303-335 Link Here
303
                }
302
                }
304
            }
303
            }
305
304
306
            if ((ec != null) && (lc != null) && (offset != -1)) {
305
            return DataEditorSupport.openDocument(od, offset);
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) {
306
        } catch (IOException e) {
334
            ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, e);
307
            ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, e);
335
        }
308
        }
(-)gototest/src/org/netbeans/modules/gototest/GotoOppositeAction.java (-64 / +8 lines)
Lines 45-58 Link Here
45
package org.netbeans.modules.gototest;
45
package org.netbeans.modules.gototest;
46
46
47
import java.awt.EventQueue;
47
import java.awt.EventQueue;
48
import java.io.IOException;
49
import java.util.Collection;
48
import java.util.Collection;
50
import java.util.logging.Level;
49
import java.util.logging.Level;
51
import java.util.logging.Logger;
50
import java.util.logging.Logger;
52
import javax.swing.Action;
51
import javax.swing.Action;
53
import javax.swing.JEditorPane;
52
import javax.swing.JEditorPane;
54
import javax.swing.text.Document;
53
import javax.swing.text.Document;
55
import javax.swing.text.StyledDocument;
56
import org.netbeans.spi.gototest.TestLocator;
54
import org.netbeans.spi.gototest.TestLocator;
57
import org.netbeans.spi.gototest.TestLocator.FileType;
55
import org.netbeans.spi.gototest.TestLocator.FileType;
58
import org.netbeans.spi.gototest.TestLocator.LocationListener;
56
import org.netbeans.spi.gototest.TestLocator.LocationListener;
Lines 60-78 Link Here
60
import org.openide.DialogDisplayer;
58
import org.openide.DialogDisplayer;
61
import org.openide.NotifyDescriptor;
59
import org.openide.NotifyDescriptor;
62
import org.openide.cookies.EditorCookie;
60
import org.openide.cookies.EditorCookie;
63
import org.openide.cookies.LineCookie;
64
import org.openide.cookies.OpenCookie;
65
import org.openide.filesystems.FileObject;
61
import org.openide.filesystems.FileObject;
66
import org.openide.loaders.DataObject;
62
import org.openide.loaders.DataObject;
67
import org.openide.loaders.DataObjectNotFoundException;
63
import org.openide.loaders.DataObjectNotFoundException;
64
import org.openide.text.DataEditorSupport;
68
import org.openide.nodes.Node;
65
import org.openide.nodes.Node;
69
import org.openide.text.CloneableEditorSupport;
66
import org.openide.text.CloneableEditorSupport;
70
import org.openide.text.Line;
71
import org.openide.text.NbDocument;
67
import org.openide.text.NbDocument;
72
import org.openide.util.HelpCtx;
68
import org.openide.util.HelpCtx;
73
import org.openide.util.Lookup;
69
import org.openide.util.Lookup;
74
import org.openide.util.NbBundle;
70
import org.openide.util.NbBundle;
75
import org.openide.util.UserQuestionException;
76
import org.openide.util.Utilities;
71
import org.openide.util.Utilities;
77
import org.openide.util.actions.CallableSystemAction;
72
import org.openide.util.actions.CallableSystemAction;
78
import org.openide.windows.TopComponent;
73
import org.openide.windows.TopComponent;
Lines 172-178 Link Here
172
    private void handleResult(LocationResult opposite) {
167
    private void handleResult(LocationResult opposite) {
173
        FileObject fileObject = opposite.getFileObject();
168
        FileObject fileObject = opposite.getFileObject();
174
        if (fileObject != null) {
169
        if (fileObject != null) {
175
            doOpenDocument(fileObject, opposite.getOffset());
170
            DataObject dobj = null;
171
            try {
172
                dobj = DataObject.find(fileObject);
173
            } catch (DataObjectNotFoundException ex) {
174
                Logger.getLogger(DataEditorSupport.class.getName()).log(Level.WARNING, null, ex);
175
            }
176
            DataEditorSupport.openDocument(dobj, opposite.getOffset());
176
        } else if (opposite.getErrorMessage() != null) {
177
        } else if (opposite.getErrorMessage() != null) {
177
            String msg = opposite.getErrorMessage();
178
            String msg = opposite.getErrorMessage();
178
            NotifyDescriptor descr = new NotifyDescriptor.Message(msg, 
179
            NotifyDescriptor descr = new NotifyDescriptor.Message(msg, 
Lines 181-243 Link Here
181
        }
182
        }
182
    }
183
    }
183
    
184
    
184
    private boolean doOpenDocument(FileObject fo, int offset) {
185
        assert fo != null;
186
        DataObject dobj = null;
187
        try {
188
            dobj = DataObject.find(fo);
189
        } catch (DataObjectNotFoundException ex) {
190
            LOG.log(Level.WARNING, null, ex);
191
        }
192
        if (dobj != null) {
193
            try {
194
                EditorCookie ec = dobj.getLookup().lookup(EditorCookie.class);
195
                LineCookie lc = dobj.getLookup().lookup(LineCookie.class);
196
                if ((ec != null) && (lc != null) && (offset != -1)) {
197
                    StyledDocument doc = null;
198
                    try {
199
                        doc = ec.openDocument();
200
                    } catch (UserQuestionException uqe) {
201
                        final Object value = DialogDisplayer.getDefault().notify(
202
                                new NotifyDescriptor.Confirmation(uqe.getLocalizedMessage(),
203
                                NbBundle.getMessage(GotoOppositeAction.class, "TXT_Question"),
204
                                NotifyDescriptor.YES_NO_OPTION));
205
                        if (value != NotifyDescriptor.YES_OPTION) {
206
                            return false;
207
                        }
208
                        uqe.confirmed();
209
                        doc = ec.openDocument();
210
                    }
211
212
                    if (doc != null) {
213
                        int line = NbDocument.findLineNumber(doc, offset);
214
                        int lineOffset = NbDocument.findLineOffset(doc, line);
215
                        int column = offset - lineOffset;
216
217
                        if (line != -1) {
218
                            Line l = lc.getLineSet().getCurrent(line);
219
220
                            if (l != null) {
221
                                l.show(Line.ShowOpenType.OPEN, Line.ShowVisibilityType.FOCUS, column);
222
                                return true;
223
                            }
224
                        }
225
                    }
226
                }
227
228
                OpenCookie oc = dobj.getLookup().lookup(OpenCookie.class);
229
230
                if (oc != null) {
231
                    oc.open();
232
                    return true;
233
                }
234
            } catch (IOException ioe) {
235
                LOG.log(Level.WARNING, null, ioe);
236
            }
237
        }
238
        return false;
239
    }
240
    
241
    private TestLocator getLocatorFor(FileObject fo) {
185
    private TestLocator getLocatorFor(FileObject fo) {
242
        if (fo == cachedLocatorFo) {
186
        if (fo == cachedLocatorFo) {
243
            return cachedLocator;
187
            return cachedLocator;
(-)kenai.ui/src/org/netbeans/modules/kenai/collab/chat/ChatPanel.java (-28 / +2 lines)
Lines 108-113 Link Here
108
import org.openide.windows.TopComponent;
108
import org.openide.windows.TopComponent;
109
import org.openide.windows.WindowManager;
109
import org.openide.windows.WindowManager;
110
import static org.netbeans.modules.kenai.collab.chat.ChatTopComponent.*;
110
import static org.netbeans.modules.kenai.collab.chat.ChatTopComponent.*;
111
import org.openide.text.DataEditorSupport;
111
112
112
/**
113
/**
113
 * Panel representing single ChatRoom
114
 * Panel representing single ChatRoom
Lines 366-399 Link Here
366
    private static boolean doOpen(FileObject fo, int line) {
367
    private static boolean doOpen(FileObject fo, int line) {
367
        try {
368
        try {
368
            DataObject od = DataObject.find(fo);
369
            DataObject od = DataObject.find(fo);
369
            EditorCookie ec = (EditorCookie) od.getCookie(EditorCookie.class);
370
            return DataEditorSupport.openDocument(od, line, -1);
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) {
371
        } catch (IOException e) {
398
            Exceptions.printStackTrace(e);
372
            Exceptions.printStackTrace(e);
399
        }
373
        }
(-)openide.loaders/src/org/openide/text/DataEditorSupport.java (+134 lines)
Lines 79-84 Link Here
79
import javax.swing.text.Document;
79
import javax.swing.text.Document;
80
import javax.swing.text.EditorKit;
80
import javax.swing.text.EditorKit;
81
import javax.swing.text.StyledDocument;
81
import javax.swing.text.StyledDocument;
82
import org.netbeans.api.actions.Openable;
82
import org.netbeans.api.annotations.common.NullAllowed;
83
import org.netbeans.api.annotations.common.NullAllowed;
83
import org.netbeans.api.queries.FileEncodingQuery;
84
import org.netbeans.api.queries.FileEncodingQuery;
84
import org.netbeans.modules.openide.loaders.DataObjectAccessor;
85
import org.netbeans.modules.openide.loaders.DataObjectAccessor;
Lines 86-91 Link Here
86
import org.openide.DialogDisplayer;
87
import org.openide.DialogDisplayer;
87
import org.openide.NotifyDescriptor;
88
import org.openide.NotifyDescriptor;
88
import org.openide.cookies.EditorCookie;
89
import org.openide.cookies.EditorCookie;
90
import org.openide.cookies.LineCookie;
89
import org.openide.cookies.OpenCookie;
91
import org.openide.cookies.OpenCookie;
90
import org.openide.filesystems.FileAttributeEvent;
92
import org.openide.filesystems.FileAttributeEvent;
91
import org.openide.filesystems.FileChangeAdapter;
93
import org.openide.filesystems.FileChangeAdapter;
Lines 121-126 Link Here
121
 * Support for associating an editor and a Swing {@link Document} to a data object.
123
 * Support for associating an editor and a Swing {@link Document} to a data object.
122
 * @author Jaroslav Tulach
124
 * @author Jaroslav Tulach
123
 */
125
 */
126
@NbBundle.Messages("TXT_Question=Question")
124
public class DataEditorSupport extends CloneableEditorSupport {
127
public class DataEditorSupport extends CloneableEditorSupport {
125
    /** error manager for CloneableEditorSupport logging and error reporting */
128
    /** error manager for CloneableEditorSupport logging and error reporting */
126
    static final Logger ERR = Logger.getLogger("org.openide.text.DataEditorSupport"); // NOI18N
129
    static final Logger ERR = Logger.getLogger("org.openide.text.DataEditorSupport"); // NOI18N
Lines 594-599 Link Here
594
        }
597
        }
595
    }
598
    }
596
599
600
    /**
601
     * Get the document associated with this {@link org.openide.loaders.DataObject}.
602
     *
603
     * <p>Method will throw {@link org.openide.util.UserQuestionException}
604
     * exception if file size is too big. This exception is caught and its
605
     * method {@link org.openide.util.UserQuestionException#confirmed} is used
606
     * for confirmation.
607
     *
608
     *
609
     * @param dobj the DataObject
610
     * @return {@link javax.swing.text.StyledDocument} or null
611
     */
612
    public static StyledDocument getStyledDocument(DataObject dobj) {
613
        try {
614
            EditorCookie ec = dobj.getLookup().lookup(EditorCookie.class);
615
            if (ec != null) {
616
                StyledDocument doc = null;
617
                try {
618
                    doc = ec.openDocument();
619
                } catch (UserQuestionException uqe) {
620
                    final Object value = DialogDisplayer.getDefault().notify(
621
                            new NotifyDescriptor.Confirmation(uqe.getLocalizedMessage(),
622
                            "#TXT_Question",
623
                            NotifyDescriptor.YES_NO_OPTION));
624
                    if (value != NotifyDescriptor.YES_OPTION) {
625
                        return null;
626
                    }
627
                    uqe.confirmed();
628
                    doc = ec.openDocument();
629
                }
630
                return doc;
631
            }
632
        } catch (IOException ioe) {
633
            Logger.getLogger(DataEditorSupport.class.getName()).log(Level.WARNING, null, ioe);
634
        }
635
        return null;
636
    }
637
    
638
    /**
639
     * Open the document associated with this {@link org.openide.loaders.DataObject}
640
     * in the Editor window in a position specified by the offset.
641
     *
642
     * <p>Method will throw {@link org.openide.util.UserQuestionException}
643
     * exception if file size is too big. This exception is caught and its
644
     * method {@link org.openide.util.UserQuestionException#confirmed} is used
645
     * for confirmation.
646
     *
647
     *
648
     * @param dobj the DataObject
649
     * @param offset the position the document should be opened
650
     * @return true if the Document is opened - false otherwise
651
     */
652
    public static boolean openDocument(DataObject dobj, int offset) {
653
        assert dobj != null;
654
        LineCookie lc = dobj.getLookup().lookup(LineCookie.class);
655
        if ((lc != null) && (offset != -1)) {
656
            StyledDocument doc = getStyledDocument(dobj);
657
658
            if (doc != null) {
659
                int line = NbDocument.findLineNumber(doc, offset);
660
                int lineOffset = NbDocument.findLineOffset(doc, line);
661
                int column = offset - lineOffset;
662
663
                if (line != -1) {
664
                    Line l = lc.getLineSet().getCurrent(line);
665
666
                    if (l != null) {
667
                        l.show(Line.ShowOpenType.OPEN, Line.ShowVisibilityType.FOCUS, column);
668
                        return true;
669
                    }
670
                }
671
            }
672
        }
673
674
        Openable oc = dobj.getLookup().lookup(Openable.class);
675
676
        if (oc != null) {
677
            oc.open();
678
            return true;
679
        }
680
        return false;
681
    }
682
    
683
    /**
684
     * Open the document associated with this {@link org.openide.loaders.DataObject}
685
     * in the Editor window in a position specified by the line and column.
686
     *
687
     * <p>Method will throw {@link org.openide.util.UserQuestionException}
688
     * exception if file size is too big. This exception is caught and its
689
     * method {@link org.openide.util.UserQuestionException#confirmed} is used
690
     * for confirmation.
691
     *
692
     * @param dobj the DataObject
693
     * @param line the line the document should be opened
694
     * @param column the column inside the line. It can be -1
695
     * @return true if the Document is opened - false otherwise
696
     */
697
    public static boolean openDocument(DataObject dobj, int line, int column) {
698
        assert dobj != null;
699
        LineCookie lc = dobj.getLookup().lookup(LineCookie.class);
700
        if ((lc != null) && (line != -1)) {
701
            StyledDocument doc = getStyledDocument(dobj);
702
703
            if (doc != null) {
704
                Line l = null;
705
                try {
706
                    l = lc.getLineSet().getCurrent(line);
707
                } catch (IndexOutOfBoundsException e) { // try to open at least the file (line no. is too high?)
708
                    l = lc.getLineSet().getCurrent(0);
709
                }
710
711
                if (l != null) {
712
                    if(column == -1) {
713
                        l.show(Line.ShowOpenType.OPEN, Line.ShowVisibilityType.FOCUS);
714
                    } else {
715
                        l.show(Line.ShowOpenType.OPEN, Line.ShowVisibilityType.FOCUS, column);
716
                    }
717
                    return true;
718
                }
719
            }
720
        }
721
722
        Openable oc = dobj.getLookup().lookup(Openable.class);
723
724
        if (oc != null) {
725
            oc.open();
726
            return true;
727
        }
728
        return false;
729
    }
730
597
    /** Saves document. Overrides superclass method, adds checking
731
    /** Saves document. Overrides superclass method, adds checking
598
     * for read-only property of saving file and warns user in that case. */
732
     * for read-only property of saving file and warns user in that case. */
599
    @Override
733
    @Override
(-)refactoring.java/src/org/netbeans/modules/refactoring/java/callhierarchy/Call.java (-33 / +6 lines)
Lines 72-87 Link Here
72
import org.netbeans.modules.refactoring.java.RetoucheUtils;
72
import org.netbeans.modules.refactoring.java.RetoucheUtils;
73
import org.openide.awt.StatusDisplayer;
73
import org.openide.awt.StatusDisplayer;
74
import org.openide.cookies.EditorCookie;
74
import org.openide.cookies.EditorCookie;
75
import org.openide.cookies.LineCookie;
76
import org.openide.cookies.OpenCookie;
77
import org.openide.filesystems.FileObject;
75
import org.openide.filesystems.FileObject;
78
import org.openide.filesystems.FileUtil;
76
import org.openide.filesystems.FileUtil;
79
import org.openide.loaders.DataObject;
77
import org.openide.loaders.DataObject;
80
import org.openide.loaders.DataObjectNotFoundException;
78
import org.openide.loaders.DataObjectNotFoundException;
81
import org.openide.text.Line;
79
import org.openide.text.DataEditorSupport;
82
import org.openide.text.NbDocument;
83
import org.openide.text.PositionBounds;
80
import org.openide.text.PositionBounds;
84
import org.openide.util.Exceptions;
85
import org.openide.util.ImageUtilities;
81
import org.openide.util.ImageUtilities;
86
import org.openide.util.NbBundle;
82
import org.openide.util.NbBundle;
87
83
Lines 400-423 Link Here
400
            final int begin = bounds.getBegin().getOffset();
396
            final int begin = bounds.getBegin().getOffset();
401
            final int end = bounds.getEnd().getOffset();
397
            final int end = bounds.getEnd().getOffset();
402
            DataObject od = DataObject.find(fo);
398
            DataObject od = DataObject.find(fo);
403
            final EditorCookie ec = od.getCookie(org.openide.cookies.EditorCookie.class);
399
            final EditorCookie ec = od.getLookup().lookup(org.openide.cookies.EditorCookie.class);
404
            LineCookie lc = od.getCookie(org.openide.cookies.LineCookie.class);
400
            boolean opened = DataEditorSupport.openDocument(od, begin);
405
401
            if (opened) {
406
            if (ec != null && lc != null && begin != -1) {                
407
                StyledDocument doc = ec.openDocument();                
408
                if (doc != null) {
409
                    int line = NbDocument.findLineNumber(doc, begin);
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() {
402
                            EventQueue.invokeLater(new Runnable() {
420
403
404
                    @Override
421
                                public void run() {
405
                                public void run() {
422
                                    ec.getOpenedPanes()[0].setSelectionStart(begin);
406
                                    ec.getOpenedPanes()[0].setSelectionStart(begin);
423
                                    ec.getOpenedPanes()[0].setSelectionEnd(end);
407
                                    ec.getOpenedPanes()[0].setSelectionEnd(end);
Lines 425-445 Link Here
425
                            });
409
                            });
426
                            return true;
410
                            return true;
427
                        }
411
                        }
428
                    }
412
            return opened;
429
                }
430
            }
431
432
            OpenCookie oc = od.getCookie(org.openide.cookies.OpenCookie.class);
433
434
            if (oc != null) {
435
                oc.open();                
436
                return true;
437
            }
438
        } catch (DataObjectNotFoundException e) {
413
        } catch (DataObjectNotFoundException e) {
439
            StatusDisplayer.getDefault().setStatusText(NbBundle.getMessage(
414
            StatusDisplayer.getDefault().setStatusText(NbBundle.getMessage(
440
                    Call.class, "Call.open.warning", FileUtil.getFileDisplayName(fo))); // NOI18N
415
                    Call.class, "Call.open.warning", FileUtil.getFileDisplayName(fo))); // NOI18N
441
        } catch (IOException e) {
442
            Exceptions.printStackTrace(e);
443
        }
416
        }
444
417
445
        return false;
418
        return false;
(-)refactoring.java/src/org/netbeans/modules/refactoring/java/plugins/JavadocUtilities.java (-24 / +2 lines)
Lines 75-86 Link Here
75
import org.netbeans.api.lexer.Token;
75
import org.netbeans.api.lexer.Token;
76
import org.netbeans.api.lexer.TokenId;
76
import org.netbeans.api.lexer.TokenId;
77
import org.netbeans.api.lexer.TokenSequence;
77
import org.netbeans.api.lexer.TokenSequence;
78
import org.openide.cookies.EditorCookie;
79
import org.openide.cookies.LineCookie;
80
import org.openide.filesystems.FileObject;
78
import org.openide.filesystems.FileObject;
81
import org.openide.loaders.DataObject;
79
import org.openide.loaders.DataObject;
82
import org.openide.text.Line;
80
import org.openide.text.DataEditorSupport;
83
import org.openide.text.NbDocument;
84
81
85
/**
82
/**
86
 * copy paste from javadoc module
83
 * copy paste from javadoc module
Lines 585-610 Link Here
585
    private static boolean doOpenImpl(FileObject fo, int offset) {
582
    private static boolean doOpenImpl(FileObject fo, int offset) {
586
        try {
583
        try {
587
            DataObject od = DataObject.find(fo);
584
            DataObject od = DataObject.find(fo);
588
            EditorCookie ec = od.getCookie(EditorCookie.class);
585
            return DataEditorSupport.openDocument(od, offset);
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) {
586
        } catch (IOException ex) {
609
            Logger.getLogger(JavadocUtilities.class.getName()).log(Level.SEVERE, ex.getMessage(), ex);
587
            Logger.getLogger(JavadocUtilities.class.getName()).log(Level.SEVERE, ex.getMessage(), ex);
610
        }
588
        }

Return to bug 209058