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; |