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 (-1 / +2 lines)
Lines 76-81 Link Here
76
import org.openide.text.DataEditorSupport;
76
import org.openide.text.DataEditorSupport;
77
import org.openide.text.Line.ShowOpenType;
77
import org.openide.text.Line.ShowOpenType;
78
import org.openide.text.Line.ShowVisibilityType;
78
import org.openide.text.Line.ShowVisibilityType;
79
import org.openide.text.NbDocument;
79
import org.openide.util.Lookup;
80
import org.openide.util.Lookup;
80
import org.openide.util.NbBundle;
81
import org.openide.util.NbBundle;
81
82
Lines 339-345 Link Here
339
    private static boolean doOpen(FileObject fo, int line) {
340
    private static boolean doOpen(FileObject fo, int line) {
340
        try {
341
        try {
341
            DataObject od = DataObject.find(fo);
342
            DataObject od = DataObject.find(fo);
342
            return DataEditorSupport.openDocument(od, line, -1, ShowOpenType.OPEN, ShowVisibilityType.FOCUS);
343
            return NbDocument.openDocument(od, line, -1, ShowOpenType.OPEN, ShowVisibilityType.FOCUS);
343
        } catch (IOException e) {
344
        } catch (IOException e) {
344
            BugtrackingManager.LOG.log(Level.SEVERE, null, e);
345
            BugtrackingManager.LOG.log(Level.SEVERE, null, e);
345
        }
346
        }
(-)a/csl.api/src/org/netbeans/modules/csl/api/UiUtils.java (-1 / +2 lines)
Lines 82-87 Link Here
82
import org.openide.loaders.DataObjectNotFoundException;
82
import org.openide.loaders.DataObjectNotFoundException;
83
import org.openide.text.DataEditorSupport;
83
import org.openide.text.DataEditorSupport;
84
import org.openide.text.Line;
84
import org.openide.text.Line;
85
import org.openide.text.NbDocument;
85
import org.openide.util.NbBundle;
86
import org.openide.util.NbBundle;
86
87
87
88
Lines 247-253 Link Here
247
    private static boolean doOpen(FileObject fo, int offset) {
248
    private static boolean doOpen(FileObject fo, int offset) {
248
        try {
249
        try {
249
            DataObject od = DataObject.find(fo);
250
            DataObject od = DataObject.find(fo);
250
            return DataEditorSupport.openDocument(od, offset, Line.ShowOpenType.OPEN, Line.ShowVisibilityType.FOCUS);
251
            return NbDocument.openDocument(od, offset, Line.ShowOpenType.OPEN, Line.ShowVisibilityType.FOCUS);
251
        } catch (DataObjectNotFoundException e) {
252
        } catch (DataObjectNotFoundException e) {
252
            LOG.log(Level.WARNING, null, e);
253
            LOG.log(Level.WARNING, null, e);
253
        }
254
        }
(-)a/csl.api/src/org/netbeans/modules/csl/spi/GsfUtilities.java (-2 / +3 lines)
Lines 84-89 Link Here
84
import org.openide.text.CloneableEditorSupport;
84
import org.openide.text.CloneableEditorSupport;
85
import org.openide.text.DataEditorSupport;
85
import org.openide.text.DataEditorSupport;
86
import org.openide.text.Line;
86
import org.openide.text.Line;
87
import org.openide.text.NbDocument;
87
import org.openide.util.Exceptions;
88
import org.openide.util.Exceptions;
88
import org.openide.util.UserQuestionException;
89
import org.openide.util.UserQuestionException;
89
90
Lines 284-290 Link Here
284
285
285
            // Simple text search if no known offset (e.g. broken/unparseable source)
286
            // Simple text search if no known offset (e.g. broken/unparseable source)
286
            if ((ec != null) && (search != null) && (offset == -1)) {
287
            if ((ec != null) && (search != null) && (offset == -1)) {
287
                StyledDocument doc = DataEditorSupport.getStyledDocument(od);
288
                StyledDocument doc = NbDocument.getDocument(od);
288
289
289
                try {
290
                try {
290
                    String text = doc.getText(0, doc.getLength());
291
                    String text = doc.getText(0, doc.getLength());
Lines 303-309 Link Here
303
                }
304
                }
304
            }
305
            }
305
            
306
            
306
            return DataEditorSupport.openDocument(od, offset, Line.ShowOpenType.OPEN, Line.ShowVisibilityType.FOCUS);
307
            return NbDocument.openDocument(od, offset, Line.ShowOpenType.OPEN, Line.ShowVisibilityType.FOCUS);
307
        } catch (IOException e) {
308
        } catch (IOException e) {
308
            ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, e);
309
            ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, e);
309
        }
310
        }
(-)a/gototest/src/org/netbeans/modules/gototest/GotoOppositeAction.java (-2 / +2 lines)
Lines 171-179 Link Here
171
            try {
171
            try {
172
                dobj = DataObject.find(fileObject);
172
                dobj = DataObject.find(fileObject);
173
            } catch (DataObjectNotFoundException ex) {
173
            } catch (DataObjectNotFoundException ex) {
174
                Logger.getLogger(DataEditorSupport.class.getName()).log(Level.WARNING, null, ex);
174
                Logger.getLogger(GotoOppositeAction.class.getName()).log(Level.WARNING, null, ex);
175
            }
175
            }
176
            DataEditorSupport.openDocument(dobj, opposite.getOffset(), Line.ShowOpenType.OPEN, Line.ShowVisibilityType.FOCUS);
176
            NbDocument.openDocument(dobj, opposite.getOffset(), Line.ShowOpenType.OPEN, Line.ShowVisibilityType.FOCUS);
177
        } else if (opposite.getErrorMessage() != null) {
177
        } else if (opposite.getErrorMessage() != null) {
178
            String msg = opposite.getErrorMessage();
178
            String msg = opposite.getErrorMessage();
179
            NotifyDescriptor descr = new NotifyDescriptor.Message(msg, 
179
            NotifyDescriptor descr = new NotifyDescriptor.Message(msg, 
(-)a/kenai.ui/src/org/netbeans/modules/kenai/collab/chat/ChatPanel.java (-1 / +2 lines)
Lines 109-114 Link Here
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
import org.openide.text.DataEditorSupport;
112
import org.openide.text.NbDocument;
112
113
113
/**
114
/**
114
 * Panel representing single ChatRoom
115
 * Panel representing single ChatRoom
Lines 367-373 Link Here
367
    private static boolean doOpen(FileObject fo, int line) {
368
    private static boolean doOpen(FileObject fo, int line) {
368
        try {
369
        try {
369
            DataObject od = DataObject.find(fo);
370
            DataObject od = DataObject.find(fo);
370
            return DataEditorSupport.openDocument(od, line, -1, Line.ShowOpenType.OPEN, Line.ShowVisibilityType.FOCUS);
371
            return NbDocument.openDocument(od, line, -1, Line.ShowOpenType.OPEN, Line.ShowVisibilityType.FOCUS);
371
        } catch (IOException e) {
372
        } catch (IOException e) {
372
            Exceptions.printStackTrace(e);
373
            Exceptions.printStackTrace(e);
373
        }
374
        }
(-)a/openide.loaders/apichanges.xml (-49 lines)
Lines 109-163 Link Here
109
<!-- ACTUAL CHANGES BEGIN HERE: -->
109
<!-- ACTUAL CHANGES BEGIN HERE: -->
110
110
111
  <changes>
111
  <changes>
112
      <change id="DataEditorSupport.getStyledDocument">
113
          <api name="loaders"/>
114
          <summary>Added method <code>DataEditorSupport.getStyledDocument</code></summary>
115
          <version major="7" minor="34"/>
116
          <date day="12" month="3" year="2012"/>
117
          <author login="theofanis"/>
118
          <compatibility addition="yes"/>
119
          <description>
120
              <p>
121
                  Get the StyledDocument associated with a file.
122
              </p>
123
          </description>
124
          <class package="org.openide.text" name="DataEditorSupport"/>
125
          <issue number="209058"/>
126
      </change>
127
      <change id="DataEditorSupport.openDocument">
128
          <api name="loaders"/>
129
          <summary>Added method <code>DataEditorSupport.openDocument</code> with offset parameter</summary>
130
          <version major="7" minor="34"/>
131
          <date day="12" month="3" year="2012"/>
132
          <author login="theofanis"/>
133
          <compatibility addition="yes"/>
134
          <description>
135
              <p>
136
                  Open the document associated with a file in the Editor window
137
                  in a position specified by the offset while controlling 
138
                  open and visibility behavior.
139
              </p>
140
          </description>
141
          <class package="org.openide.text" name="DataEditorSupport"/>
142
          <issue number="209058"/>
143
      </change>
144
      <change id="DataEditorSupport.openDocument2">
145
          <api name="loaders"/>
146
          <summary>Added method <code>DataEditorSupport.openDocument</code> with line and column parameter</summary>
147
          <version major="7" minor="34"/>
148
          <date day="12" month="3" year="2012"/>
149
          <author login="theofanis"/>
150
          <compatibility addition="yes"/>
151
          <description>
152
              <p>
153
                  Open the document associated with a file in the Editor window
154
                  in a position specified by the line and column while
155
                  controlling open and visibility behavior.
156
              </p>
157
          </description>
158
          <class package="org.openide.text" name="DataEditorSupport"/>
159
          <issue number="209058"/>
160
      </change>
161
      <change id="ToolbarPool.isFinished">
112
      <change id="ToolbarPool.isFinished">
162
          <api name="awt"/>
113
          <api name="awt"/>
163
          <summary><code>ToolbarPool.isFinished</code></summary>
114
          <summary><code>ToolbarPool.isFinished</code></summary>
(-)a/openide.loaders/manifest.mf (-1 / +1 lines)
Lines 1-6 Link Here
1
Manifest-Version: 1.0
1
Manifest-Version: 1.0
2
OpenIDE-Module: org.openide.loaders
2
OpenIDE-Module: org.openide.loaders
3
OpenIDE-Module-Specification-Version: 7.34
3
OpenIDE-Module-Specification-Version: 7.33
4
OpenIDE-Module-Localizing-Bundle: org/openide/loaders/Bundle.properties
4
OpenIDE-Module-Localizing-Bundle: org/openide/loaders/Bundle.properties
5
OpenIDE-Module-Provides: org.netbeans.modules.templates.v1_0
5
OpenIDE-Module-Provides: org.netbeans.modules.templates.v1_0
6
OpenIDE-Module-Layer: org/netbeans/modules/openide/loaders/layer.xml
6
OpenIDE-Module-Layer: org/netbeans/modules/openide/loaders/layer.xml
(-)a/openide.loaders/src/org/openide/text/DataEditorSupport.java (-198 lines)
Lines 119-131 Link Here
119
 * Support for associating an editor and a Swing {@link Document} to a data object.
119
 * Support for associating an editor and a Swing {@link Document} to a data object.
120
 * @author Jaroslav Tulach
120
 * @author Jaroslav Tulach
121
 */
121
 */
122
@NbBundle.Messages("TXT_Question=Question")
123
public class DataEditorSupport extends CloneableEditorSupport {
122
public class DataEditorSupport extends CloneableEditorSupport {
124
    /** error manager for CloneableEditorSupport logging and error reporting */
123
    /** error manager for CloneableEditorSupport logging and error reporting */
125
    static final Logger ERR = Logger.getLogger("org.openide.text.DataEditorSupport"); // NOI18N
124
    static final Logger ERR = Logger.getLogger("org.openide.text.DataEditorSupport"); // NOI18N
126
    
127
    private static Future<Boolean> openTask;
128
    private static ExecutorService executor = null;
129
125
130
    /** Which data object we are associated with */
126
    /** Which data object we are associated with */
131
    private final DataObject obj;
127
    private final DataObject obj;
Lines 595-794 Link Here
595
            ERR.finest("openDocument - charset removed");
591
            ERR.finest("openDocument - charset removed");
596
        }
592
        }
597
    }
593
    }
598
    
599
    /**
600
     * Get the document associated with a file.
601
     *
602
     * <p>Method will throw {@link org.openide.util.UserQuestionException}
603
     * exception if file size is too big. This exception is caught and its
604
     * method {@link org.openide.util.UserQuestionException#confirmed} is used
605
     * for confirmation.
606
     *
607
     *
608
     * @param provider the Lookup.Provider
609
     * @return {@link javax.swing.text.StyledDocument} or null
610
     * @since org.openide.loaders 7.34
611
     */
612
    public static StyledDocument getStyledDocument(Lookup.Provider provider) {
613
        try {
614
            EditorCookie ec = provider.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 a file in the Editor window in a
640
     * position specified by the offset while controlling open and visibility behavior.
641
     * This method can be called from any thread.
642
     *
643
     * @param provider the Lookup.Provider
644
     * @param offset the position the document should be opened (starting at 0)
645
     * @param openType control open behavior, {@link org.openide.text.Line.ShowOpenType#OPEN}
646
     * should be used
647
     * @param visibilityType control visibility behavior, {@link org.openide.text.Line.ShowVisibilityType#FOCUS}
648
     * should be used
649
     * @return true if the Document is opened - false otherwise
650
     * @see #getStyledDocument
651
     * <code>UserQuestionException handling</code>
652
     * @see org.openide.text.Line.ShowOpenType
653
     * <code>ShowOpenType</code>
654
     * @see org.openide.text.Line.ShowVisibilityType
655
     * <code>ShowVisibilityType</code>
656
     * @since org.openide.loaders 7.34
657
     */
658
    public static boolean openDocument(Lookup.Provider provider, int offset, Line.ShowOpenType openType, Line.ShowVisibilityType visibilityType) {
659
        assert provider != null;
660
        LineCookie lc = provider.getLookup().lookup(LineCookie.class);
661
        if ((lc != null) && (offset != -1)) {
662
            StyledDocument doc = getStyledDocument(provider);
663
664
            if (doc != null) {
665
                int line = NbDocument.findLineNumber(doc, offset);
666
                int column = NbDocument.findLineColumn(doc, offset);
667
                
668
                Line l = null;
669
                try {
670
                    l = lc.getLineSet().getCurrent(line);
671
                } catch (IndexOutOfBoundsException e) { // try to open at least the file (line no. is too high?)
672
                    l = lc.getLineSet().getCurrent(0);
673
                }
674
675
                if (l != null) {
676
                    return doShow(l, column, openType, visibilityType);
677
                }
678
            }
679
        }
680
681
        Openable oc = provider.getLookup().lookup(Openable.class);
682
683
        if (oc != null) {
684
            return doOpen(oc);
685
        }
686
        return false;
687
    }
688
    
689
    /**
690
     * Open the document associated with a file in the Editor window in a
691
     * position specified by the line and column while controlling open and visibility behavior.
692
     * This method can be called from any thread.
693
     *
694
     * @param provider the Lookup.Provider
695
     * @param line the line the document should be opened (starting at 0)
696
     * @param column the column which should be selected (starting at 0), value
697
     * -1 does not change previously selected column
698
     * @param openType control open behavior, {@link org.openide.text.Line.ShowOpenType#OPEN}
699
     * should be used
700
     * @param visibilityType control visibility behavior, {@link org.openide.text.Line.ShowVisibilityType#FOCUS}
701
     * should be used
702
     * @return true if the Document is opened - false otherwise
703
     * @see #getStyledDocument
704
     * <code>UserQuestionException handling</code>
705
     * @see org.openide.text.Line.ShowOpenType
706
     * <code>ShowOpenType</code>
707
     * @see org.openide.text.Line.ShowVisibilityType
708
     * <code>ShowVisibilityType</code>
709
     * @since org.openide.loaders 7.34
710
     */
711
    public static boolean openDocument(Lookup.Provider provider, int line, int column, Line.ShowOpenType openType, Line.ShowVisibilityType visibilityType) {
712
        assert provider != null;
713
        LineCookie lc = provider.getLookup().lookup(LineCookie.class);
714
        if ((lc != null) && (line >= 0) && (column >= -1)) {
715
            StyledDocument doc = getStyledDocument(provider);
716
717
            if (doc != null) {
718
                Line l = null;
719
                try {
720
                    l = lc.getLineSet().getCurrent(line);
721
                } catch (IndexOutOfBoundsException e) { // try to open at least the file (line no. is too high?)
722
                    l = lc.getLineSet().getCurrent(0);
723
                }
724
725
                if (l != null) {
726
                    return doShow(l, column, openType, visibilityType);
727
                }
728
            }
729
        }
730
731
        final Openable oc = provider.getLookup().lookup(Openable.class);
732
733
        if (oc != null) {
734
            return doOpen(oc);
735
        }
736
        
737
        return false;
738
    }
739
    
740
    private static ExecutorService getExecutorService () {
741
        if (executor == null || executor.isShutdown ()) {
742
            executor = Executors.newSingleThreadExecutor ();
743
        }
744
        return executor;
745
    }
746
    
747
    private static boolean doShow(final Line l, final int column, final Line.ShowOpenType openType, final Line.ShowVisibilityType visibilityType) {
748
        Callable<Boolean> callable = new Callable<Boolean>() {
749
750
            @Override
751
            public Boolean call() throws Exception {
752
                l.show(openType, visibilityType, column);
753
                return true;
754
            }
755
        };
756
        boolean retval = false;
757
        try {
758
            openTask = getExecutorService().submit(callable);
759
            retval = openTask.get();
760
        } catch (CancellationException ex) {
761
            ERR.log(Level.FINE, "DataEditorSupport.openDocument was cancelled ", ex); // NOI18N
762
        } catch (InterruptedException ex) {
763
            ERR.log(Level.FINE, "DataEditorSupport.openDocument was interupted ", ex); // NOI18N
764
        } catch (ExecutionException ex) {
765
            ERR.log(Level.FINE, "DataEditorSupport.openDocument exception ", ex); // NOI18N
766
        }
767
        return retval;
768
    }
769
770
    private static boolean doOpen(final Openable oc) {
771
        Callable<Boolean> callable = new Callable<Boolean>() {
772
773
            @Override
774
            public Boolean call() throws Exception {
775
                oc.open();
776
                return true;
777
            }
778
        };
779
        boolean retval = false;
780
        try {
781
            openTask = getExecutorService().submit(callable);
782
            retval = openTask.get();
783
        } catch (CancellationException ex) {
784
            ERR.log(Level.FINE, "DataEditorSupport.openDocument was cancelled ", ex); // NOI18N
785
        } catch (InterruptedException ex) {
786
            ERR.log(Level.FINE, "DataEditorSupport.openDocument was interupted ", ex); // NOI18N
787
        } catch (ExecutionException ex) {
788
            ERR.log(Level.FINE, "DataEditorSupport.openDocument exception ", ex); // NOI18N
789
        }
790
        return retval;
791
    }
792
594
793
    /** Saves document. Overrides superclass method, adds checking
595
    /** Saves document. Overrides superclass method, adds checking
794
     * for read-only property of saving file and warns user in that case. */
596
     * for read-only property of saving file and warns user in that case. */
(-)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="19" 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 (+174 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.NbBundle;
64
import org.openide.util.UserQuestionException;
55
65
56
66
57
/** Dummy class holding utility methods for working with NetBeans document conventions.
67
/** Dummy class holding utility methods for working with NetBeans document conventions.
Lines 518-523 Link Here
518
        }
528
        }
519
        ((Annotatable) doc).removeAnnotation(annotation);
529
        ((Annotatable) doc).removeAnnotation(annotation);
520
    }
530
    }
531
    
532
    /**
533
     * Get the document associated with a file.
534
     *
535
     * <p>Method will throw {@link org.openide.util.UserQuestionException}
536
     * exception if file size is too big. This exception is caught and its
537
     * method {@link org.openide.util.UserQuestionException#confirmed} is used
538
     * for confirmation.
539
     *
540
     *
541
     * @param provider for example a {@link DataObject}
542
     * @return {@link javax.swing.text.StyledDocument} or null
543
     * @since org.openide.text 6.45
544
     */
545
    @NbBundle.Messages("TXT_Question=Question")
546
    public static StyledDocument getDocument(Lookup.Provider provider) {
547
        try {
548
            EditorCookie ec = provider.getLookup().lookup(EditorCookie.class);
549
            if (ec != null) {
550
                StyledDocument doc = null;
551
                try {
552
                    doc = ec.openDocument();
553
                } catch (UserQuestionException uqe) {
554
                    final Object value = DialogDisplayer.getDefault().notify(
555
                            new NotifyDescriptor.Confirmation(uqe.getLocalizedMessage(),
556
                            Bundle.TXT_Question(),
557
                            NotifyDescriptor.YES_NO_OPTION));
558
                    if (value != NotifyDescriptor.YES_OPTION) {
559
                        return null;
560
                    }
561
                    uqe.confirmed();
562
                    doc = ec.openDocument();
563
                }
564
                return doc;
565
            }
566
        } catch (IOException ioe) {
567
            Logger.getLogger(NbDocument.class.getName()).log(Level.WARNING, null, ioe);
568
        }
569
        return null;
570
    }
571
    
572
    /**
573
     * Open the document associated with a file in the Editor window in a
574
     * position specified by the offset while controlling open and visibility behavior.
575
     * This method can be called from any thread but blocks until the document is opened.
576
     *
577
     * @param provider for example a {@link DataObject}
578
     * @param offset the position the document should be opened (starting at 0)
579
     * @param openType control open behavior, {@link org.openide.text.Line.ShowOpenType#OPEN}
580
     * would typically be used
581
     * @param visibilityType control visibility behavior, {@link org.openide.text.Line.ShowVisibilityType#FOCUS}
582
     * would typically be used
583
     * @return true if the Document is opened - false otherwise
584
     * @see #getDocument
585
     * <code>UserQuestionException handling</code>
586
     * @since org.openide.text 6.45
587
     */
588
    public static boolean openDocument(Lookup.Provider provider, int offset, Line.ShowOpenType openType, Line.ShowVisibilityType visibilityType) {
589
        assert provider != null;
590
        LineCookie lc = provider.getLookup().lookup(LineCookie.class);
591
        if ((lc != null) && (offset != -1)) {
592
            StyledDocument doc = getDocument(provider);
593
594
            if (doc != null) {
595
                int line = NbDocument.findLineNumber(doc, offset);
596
                int column = NbDocument.findLineColumn(doc, offset);
597
                
598
                Line l = null;
599
                try {
600
                    l = lc.getLineSet().getCurrent(line);
601
                } catch (IndexOutOfBoundsException e) { // try to open at least the file (line no. is too high?)
602
                    l = lc.getLineSet().getCurrent(0);
603
                }
604
605
                if (l != null) {
606
                    doShow(l, column, openType, visibilityType);
607
                    return true;
608
                }
609
            }
610
        }
611
612
        Openable oc = provider.getLookup().lookup(Openable.class);
613
614
        if (oc != null) {
615
            doOpen(oc);
616
            return true;
617
        }
618
        return false;
619
    }
620
    
621
    /**
622
     * Open the document associated with a file in the Editor window in a
623
     * position specified by the line and column while controlling open and visibility behavior.
624
     * This method can be called from any thread but blocks until the document is opened.
625
     *
626
     * @param provider for example a {@link DataObject}
627
     * @param line the line the document should be opened (starting at 0)
628
     * @param column the column which should be selected (starting at 0), value
629
     * -1 does not change previously selected column
630
     * @param openType control open behavior, {@link org.openide.text.Line.ShowOpenType#OPEN}
631
     * would typically be used
632
     * @param visibilityType control visibility behavior, {@link org.openide.text.Line.ShowVisibilityType#FOCUS}
633
     * would typically be used
634
     * @return true if the Document is opened - false otherwise
635
     * @see #getDocument
636
     * <code>UserQuestionException handling</code>
637
     * @since org.openide.text 6.45
638
     */
639
    public static boolean openDocument(Lookup.Provider provider, int line, int column, Line.ShowOpenType openType, Line.ShowVisibilityType visibilityType) {
640
        assert provider != null;
641
        LineCookie lc = provider.getLookup().lookup(LineCookie.class);
642
        if ((lc != null) && (line >= 0) && (column >= -1)) {
643
            StyledDocument doc = getDocument(provider);
644
645
            if (doc != null) {
646
                Line l = null;
647
                try {
648
                    l = lc.getLineSet().getCurrent(line);
649
                } catch (IndexOutOfBoundsException e) { // try to open at least the file (line no. is too high?)
650
                    l = lc.getLineSet().getCurrent(0);
651
                }
652
653
                if (l != null) {
654
                    doShow(l, column, openType, visibilityType);
655
                    return true;
656
                }
657
            }
658
        }
659
660
        final Openable oc = provider.getLookup().lookup(Openable.class);
661
662
        if (oc != null) {
663
            doOpen(oc);
664
            return true;
665
        }
666
        
667
        return false;
668
    }
669
    
670
    private static void doShow(final Line l, final int column, final Line.ShowOpenType openType, final Line.ShowVisibilityType visibilityType) {
671
        if (SwingUtilities.isEventDispatchThread()) {
672
            l.show(openType, visibilityType, column);
673
        } else {
674
            SwingUtilities.invokeLater(new Runnable() {
675
                @Override
676
                public void run() {
677
                    l.show(openType, visibilityType, column);
678
                }
679
            });
680
        }
681
    }
682
683
    private static void doOpen(final Openable oc) {
684
        if (SwingUtilities.isEventDispatchThread()) {
685
            oc.open();
686
        } else {
687
            SwingUtilities.invokeLater(new Runnable() {
688
                @Override
689
                public void run() {
690
                    oc.open();
691
                }
692
            });
693
        }
694
    }
521
695
522
    /** Specialized version of document that knows how to lock the document
696
    /** Specialized version of document that knows how to lock the document
523
    * for complex modifications.
697
    * for complex modifications.
(-)a/refactoring.java/src/org/netbeans/modules/refactoring/java/callhierarchy/Call.java (-1 / +2 lines)
Lines 78-83 Link Here
78
import org.openide.loaders.DataObjectNotFoundException;
78
import org.openide.loaders.DataObjectNotFoundException;
79
import org.openide.text.DataEditorSupport;
79
import org.openide.text.DataEditorSupport;
80
import org.openide.text.Line;
80
import org.openide.text.Line;
81
import org.openide.text.NbDocument;
81
import org.openide.text.PositionBounds;
82
import org.openide.text.PositionBounds;
82
import org.openide.util.ImageUtilities;
83
import org.openide.util.ImageUtilities;
83
import org.openide.util.NbBundle;
84
import org.openide.util.NbBundle;
Lines 398-404 Link Here
398
            final int end = bounds.getEnd().getOffset();
399
            final int end = bounds.getEnd().getOffset();
399
            DataObject od = DataObject.find(fo);
400
            DataObject od = DataObject.find(fo);
400
            final EditorCookie ec = od.getLookup().lookup(org.openide.cookies.EditorCookie.class);
401
            final EditorCookie ec = od.getLookup().lookup(org.openide.cookies.EditorCookie.class);
401
            boolean opened = DataEditorSupport.openDocument(od, begin, Line.ShowOpenType.OPEN, Line.ShowVisibilityType.FOCUS);
402
            boolean opened = NbDocument.openDocument(od, begin, Line.ShowOpenType.OPEN, Line.ShowVisibilityType.FOCUS);
402
            if (opened) {
403
            if (opened) {
403
                EventQueue.invokeLater(new Runnable() {
404
                EventQueue.invokeLater(new Runnable() {
404
405
(-)a/refactoring.java/src/org/netbeans/modules/refactoring/java/plugins/JavadocUtilities.java (-1 / +2 lines)
Lines 79-84 Link Here
79
import org.openide.text.DataEditorSupport;
79
import org.openide.text.DataEditorSupport;
80
import org.openide.text.Line.ShowOpenType;
80
import org.openide.text.Line.ShowOpenType;
81
import org.openide.text.Line.ShowVisibilityType;
81
import org.openide.text.Line.ShowVisibilityType;
82
import org.openide.text.NbDocument;
82
83
83
/**
84
/**
84
 * copy paste from javadoc module
85
 * copy paste from javadoc module
Lines 583-589 Link Here
583
    private static boolean doOpenImpl(FileObject fo, int offset) {
584
    private static boolean doOpenImpl(FileObject fo, int offset) {
584
        try {
585
        try {
585
            DataObject od = DataObject.find(fo);
586
            DataObject od = DataObject.find(fo);
586
            return DataEditorSupport.openDocument(od, offset, ShowOpenType.OPEN, ShowVisibilityType.FOCUS);
587
            return NbDocument.openDocument(od, offset, ShowOpenType.OPEN, ShowVisibilityType.FOCUS);
587
        } catch (IOException ex) {
588
        } catch (IOException ex) {
588
            Logger.getLogger(JavadocUtilities.class.getName()).log(Level.SEVERE, ex.getMessage(), ex);
589
            Logger.getLogger(JavadocUtilities.class.getName()).log(Level.SEVERE, ex.getMessage(), ex);
589
        }
590
        }

Return to bug 209058