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.DataEditorSupport;
77
import org.openide.text.Line.ShowOpenType;
78
import org.openide.text.Line.ShowVisibilityType;
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 DataEditorSupport.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 (-51 / +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;
81
import org.openide.loaders.DataObject;
82
import org.openide.loaders.DataObjectNotFoundException;
83
import org.openide.text.DataEditorSupport;
86
import org.openide.text.Line;
84
import org.openide.text.Line;
87
import org.openide.text.NbDocument;
88
import org.openide.util.NbBundle;
85
import org.openide.util.NbBundle;
89
import org.openide.util.UserQuestionException;
90
86
91
87
92
/** 
88
/** 
Lines 250-300 Link Here
250
246
251
    private static boolean doOpen(FileObject fo, int offset) {
247
    private static boolean doOpen(FileObject fo, int offset) {
252
        try {
248
        try {
253
            EditorCookie ec = DataLoadersBridge.getDefault().getCookie(fo, EditorCookie.class);
249
            DataObject od = DataObject.find(fo);
254
            LineCookie lc = DataLoadersBridge.getDefault().getCookie(fo, LineCookie.class);
250
            return DataEditorSupport.openDocument(od, offset, Line.ShowOpenType.OPEN, Line.ShowVisibilityType.FOCUS);
255
251
        } catch (DataObjectNotFoundException e) {
256
            if ((ec != null) && (lc != null) && (offset != -1)) {
252
            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
        }
253
        }
297
298
        return false;
254
        return false;
299
    }
255
    }
300
256
(-)a/csl.api/src/org/netbeans/modules/csl/spi/GsfUtilities.java (-30 / +4 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.DataEditorSupport;
85
import org.openide.text.Line;
86
import org.openide.text.Line;
86
import org.openide.text.NbDocument;
87
import org.openide.util.Exceptions;
87
import org.openide.util.Exceptions;
88
import org.openide.util.UserQuestionException;
88
import org.openide.util.UserQuestionException;
89
89
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 = DataEditorSupport.getStyledDocument(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 DataEditorSupport.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 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/>
(-)a/gototest/src/org/netbeans/modules/gototest/GotoOppositeAction.java (-2 / +12 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;
64
import org.openide.text.DataEditorSupport;
62
import org.openide.nodes.Node;
65
import org.openide.nodes.Node;
63
import org.openide.text.CloneableEditorSupport;
66
import org.openide.text.CloneableEditorSupport;
67
import org.openide.text.Line;
64
import org.openide.text.NbDocument;
68
import org.openide.text.NbDocument;
65
import org.openide.util.HelpCtx;
69
import org.openide.util.HelpCtx;
66
import org.openide.util.Lookup;
70
import org.openide.util.Lookup;
Lines 163-169 Link Here
163
    private void handleResult(LocationResult opposite) {
167
    private void handleResult(LocationResult opposite) {
164
        FileObject fileObject = opposite.getFileObject();
168
        FileObject fileObject = opposite.getFileObject();
165
        if (fileObject != null) {
169
        if (fileObject != null) {
166
            UiUtils.open(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(), Line.ShowOpenType.OPEN, Line.ShowVisibilityType.FOCUS);
167
        } else if (opposite.getErrorMessage() != null) {
177
        } else if (opposite.getErrorMessage() != null) {
168
            String msg = opposite.getErrorMessage();
178
            String msg = opposite.getErrorMessage();
169
            NotifyDescriptor descr = new NotifyDescriptor.Message(msg, 
179
            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 (-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, 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) {
371
        } catch (IOException e) {
398
            Exceptions.printStackTrace(e);
372
            Exceptions.printStackTrace(e);
399
        }
373
        }
(-)a/openide.loaders/apichanges.xml (+49 lines)
Lines 109-114 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>
112
      <change id="ToolbarPool.isFinished">
161
      <change id="ToolbarPool.isFinished">
113
          <api name="awt"/>
162
          <api name="awt"/>
114
          <summary><code>ToolbarPool.isFinished</code></summary>
163
          <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.33
3
OpenIDE-Module-Specification-Version: 7.34
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 (+145 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 593-598 Link Here
593
            ERR.finest("openDocument - charset removed");
596
            ERR.finest("openDocument - charset removed");
594
        }
597
        }
595
    }
598
    }
599
    
600
    /**
601
     * Get the document associated with a file.
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
     * @since org.openide.loaders 7.34
612
     */
613
    public static StyledDocument getStyledDocument(DataObject dobj) {
614
        try {
615
            EditorCookie ec = dobj.getLookup().lookup(EditorCookie.class);
616
            if (ec != null) {
617
                StyledDocument doc = null;
618
                try {
619
                    doc = ec.openDocument();
620
                } catch (UserQuestionException uqe) {
621
                    final Object value = DialogDisplayer.getDefault().notify(
622
                            new NotifyDescriptor.Confirmation(uqe.getLocalizedMessage(),
623
                            "#TXT_Question",
624
                            NotifyDescriptor.YES_NO_OPTION));
625
                    if (value != NotifyDescriptor.YES_OPTION) {
626
                        return null;
627
                    }
628
                    uqe.confirmed();
629
                    doc = ec.openDocument();
630
                }
631
                return doc;
632
            }
633
        } catch (IOException ioe) {
634
            Logger.getLogger(DataEditorSupport.class.getName()).log(Level.WARNING, null, ioe);
635
        }
636
        return null;
637
    }
638
    
639
    /**
640
     * Open the document associated with a file in the Editor window in a
641
     * position specified by the offset while controlling open and visibility behavior.
642
     *
643
     * @param dobj the DataObject
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(DataObject dobj, int offset, Line.ShowOpenType openType, Line.ShowVisibilityType visibilityType) {
659
        assert dobj != null;
660
        LineCookie lc = dobj.getLookup().lookup(LineCookie.class);
661
        if ((lc != null) && (offset != -1)) {
662
            StyledDocument doc = getStyledDocument(dobj);
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
                    l.show(openType, visibilityType, column);
677
                    return true;
678
                }
679
            }
680
        }
681
682
        Openable oc = dobj.getLookup().lookup(Openable.class);
683
684
        if (oc != null) {
685
            oc.open();
686
            return true;
687
        }
688
        return false;
689
    }
690
    
691
    /**
692
     * Open the document associated with a file in the Editor window in a
693
     * position specified by the line and column while controlling open and visibility behavior.
694
     *
695
     * @param dobj the DataObject
696
     * @param line the line the document should be opened (starting at 0)
697
     * @param column the column which should be selected (starting at 0), value
698
     * -1 does not change previously selected column
699
     * @param openType control open behavior, {@link org.openide.text.Line.ShowOpenType#OPEN}
700
     * should be used
701
     * @param visibilityType control visibility behavior, {@link org.openide.text.Line.ShowVisibilityType#FOCUS}
702
     * should be used
703
     * @return true if the Document is opened - false otherwise
704
     * @see #getStyledDocument
705
     * <code>UserQuestionException handling</code>
706
     * @see org.openide.text.Line.ShowOpenType
707
     * <code>ShowOpenType</code>
708
     * @see org.openide.text.Line.ShowVisibilityType
709
     * <code>ShowVisibilityType</code>
710
     * @since org.openide.loaders 7.34
711
     */
712
    public static boolean openDocument(DataObject dobj, int line, int column, Line.ShowOpenType openType, Line.ShowVisibilityType visibilityType) {
713
        assert dobj != null;
714
        LineCookie lc = dobj.getLookup().lookup(LineCookie.class);
715
        if ((lc != null) && (line >= 0) && (column >= -1)) {
716
            StyledDocument doc = getStyledDocument(dobj);
717
718
            if (doc != null) {
719
                Line l = null;
720
                try {
721
                    l = lc.getLineSet().getCurrent(line);
722
                } catch (IndexOutOfBoundsException e) { // try to open at least the file (line no. is too high?)
723
                    l = lc.getLineSet().getCurrent(0);
724
                }
725
726
                if (l != null) {
727
                    l.show(openType, visibilityType, column);
728
                    return true;
729
                }
730
            }
731
        }
732
733
        Openable oc = dobj.getLookup().lookup(Openable.class);
734
735
        if (oc != null) {
736
            oc.open();
737
            return true;
738
        }
739
        return false;
740
    }
596
741
597
    /** Saves document. Overrides superclass method, adds checking
742
    /** Saves document. Overrides superclass method, adds checking
598
     * for read-only property of saving file and warns user in that case. */
743
     * for read-only property of saving file and warns user in that case. */
(-)a/refactoring.java/src/org/netbeans/modules/refactoring/java/callhierarchy/Call.java (-37 / +11 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;
79
import org.openide.text.DataEditorSupport;
81
import org.openide.text.Line;
80
import org.openide.text.Line;
82
import org.openide.text.NbDocument;
83
import org.openide.text.PositionBounds;
81
import org.openide.text.PositionBounds;
84
import org.openide.util.Exceptions;
85
import org.openide.util.ImageUtilities;
82
import org.openide.util.ImageUtilities;
86
import org.openide.util.NbBundle;
83
import org.openide.util.NbBundle;
87
84
Lines 400-445 Link Here
400
            final int begin = bounds.getBegin().getOffset();
397
            final int begin = bounds.getBegin().getOffset();
401
            final int end = bounds.getEnd().getOffset();
398
            final int end = bounds.getEnd().getOffset();
402
            DataObject od = DataObject.find(fo);
399
            DataObject od = DataObject.find(fo);
403
            final EditorCookie ec = od.getCookie(org.openide.cookies.EditorCookie.class);
400
            final EditorCookie ec = od.getLookup().lookup(org.openide.cookies.EditorCookie.class);
404
            LineCookie lc = od.getCookie(org.openide.cookies.LineCookie.class);
401
            boolean opened = DataEditorSupport.openDocument(od, begin, Line.ShowOpenType.OPEN, Line.ShowVisibilityType.FOCUS);
402
            if (opened) {
403
                EventQueue.invokeLater(new Runnable() {
405
404
406
            if (ec != null && lc != null && begin != -1) {                
405
                    @Override
407
                StyledDocument doc = ec.openDocument();                
406
                    public void run() {
408
                if (doc != null) {
407
                        ec.getOpenedPanes()[0].setSelectionStart(begin);
409
                    int line = NbDocument.findLineNumber(doc, begin);
408
                        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
                    }
409
                    }
429
                }
410
                });
430
            }
431
432
            OpenCookie oc = od.getCookie(org.openide.cookies.OpenCookie.class);
433
434
            if (oc != null) {
435
                oc.open();                
436
                return true;
411
                return true;
437
            }
412
            }
413
            return opened;
438
        } catch (DataObjectNotFoundException e) {
414
        } catch (DataObjectNotFoundException e) {
439
            StatusDisplayer.getDefault().setStatusText(NbBundle.getMessage(
415
            StatusDisplayer.getDefault().setStatusText(NbBundle.getMessage(
440
                    Call.class, "Call.open.warning", FileUtil.getFileDisplayName(fo))); // NOI18N
416
                    Call.class, "Call.open.warning", FileUtil.getFileDisplayName(fo))); // NOI18N
441
        } catch (IOException e) {
442
            Exceptions.printStackTrace(e);
443
        }
417
        }
444
418
445
        return false;
419
        return false;
(-)a/refactoring.java/src/org/netbeans/modules/refactoring/java/plugins/JavadocUtilities.java (-25 / +4 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-86 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.DataEditorSupport;
83
import org.openide.text.NbDocument;
80
import org.openide.text.Line.ShowOpenType;
81
import org.openide.text.Line.ShowVisibilityType;
84
82
85
/**
83
/**
86
 * copy paste from javadoc module
84
 * copy paste from javadoc module
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 DataEditorSupport.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