ToolbarPool.isFinished
diff --git a/openide.loaders/manifest.mf b/openide.loaders/manifest.mf
--- a/openide.loaders/manifest.mf
+++ b/openide.loaders/manifest.mf
@@ -1,6 +1,6 @@
Manifest-Version: 1.0
OpenIDE-Module: org.openide.loaders
-OpenIDE-Module-Specification-Version: 7.33
+OpenIDE-Module-Specification-Version: 7.34
OpenIDE-Module-Localizing-Bundle: org/openide/loaders/Bundle.properties
OpenIDE-Module-Provides: org.netbeans.modules.templates.v1_0
OpenIDE-Module-Layer: org/netbeans/modules/openide/loaders/layer.xml
diff --git a/openide.loaders/src/org/openide/text/DataEditorSupport.java b/openide.loaders/src/org/openide/text/DataEditorSupport.java
--- a/openide.loaders/src/org/openide/text/DataEditorSupport.java
+++ b/openide.loaders/src/org/openide/text/DataEditorSupport.java
@@ -75,10 +75,12 @@
import java.util.concurrent.Callable;
import java.util.logging.Level;
import java.util.logging.Logger;
+import javax.swing.SwingUtilities;
import javax.swing.text.BadLocationException;
import javax.swing.text.Document;
import javax.swing.text.EditorKit;
import javax.swing.text.StyledDocument;
+import org.netbeans.api.actions.Openable;
import org.netbeans.api.annotations.common.NullAllowed;
import org.netbeans.api.queries.FileEncodingQuery;
import org.netbeans.modules.openide.loaders.DataObjectAccessor;
@@ -86,6 +88,7 @@
import org.openide.DialogDisplayer;
import org.openide.NotifyDescriptor;
import org.openide.cookies.EditorCookie;
+import org.openide.cookies.LineCookie;
import org.openide.cookies.OpenCookie;
import org.openide.filesystems.FileAttributeEvent;
import org.openide.filesystems.FileChangeAdapter;
@@ -121,6 +124,7 @@
* Support for associating an editor and a Swing {@link Document} to a data object.
* @author Jaroslav Tulach
*/
+@NbBundle.Messages("TXT_Question=Question")
public class DataEditorSupport extends CloneableEditorSupport {
/** error manager for CloneableEditorSupport logging and error reporting */
static final Logger ERR = Logger.getLogger("org.openide.text.DataEditorSupport"); // NOI18N
@@ -594,6 +598,176 @@
}
}
+ /**
+ * Get the document associated with a file.
+ *
+ * Method will throw {@link org.openide.util.UserQuestionException}
+ * exception if file size is too big. This exception is caught and its
+ * method {@link org.openide.util.UserQuestionException#confirmed} is used
+ * for confirmation.
+ *
+ *
+ * @param dobj the DataObject
+ * @return {@link javax.swing.text.StyledDocument} or null
+ * @since org.openide.loaders 7.34
+ */
+ public static StyledDocument getStyledDocument(DataObject dobj) {
+ try {
+ EditorCookie ec = dobj.getLookup().lookup(EditorCookie.class);
+ if (ec != null) {
+ StyledDocument doc = null;
+ try {
+ doc = ec.openDocument();
+ } catch (UserQuestionException uqe) {
+ final Object value = DialogDisplayer.getDefault().notify(
+ new NotifyDescriptor.Confirmation(uqe.getLocalizedMessage(),
+ "#TXT_Question",
+ NotifyDescriptor.YES_NO_OPTION));
+ if (value != NotifyDescriptor.YES_OPTION) {
+ return null;
+ }
+ uqe.confirmed();
+ doc = ec.openDocument();
+ }
+ return doc;
+ }
+ } catch (IOException ioe) {
+ Logger.getLogger(DataEditorSupport.class.getName()).log(Level.WARNING, null, ioe);
+ }
+ return null;
+ }
+
+ /**
+ * Open the document associated with a file in the Editor window in a
+ * position specified by the offset while controlling open and visibility behavior.
+ * This method can be called from any thread.
+ *
+ * @param dobj the DataObject
+ * @param offset the position the document should be opened (starting at 0)
+ * @param openType control open behavior, {@link org.openide.text.Line.ShowOpenType#OPEN}
+ * should be used
+ * @param visibilityType control visibility behavior, {@link org.openide.text.Line.ShowVisibilityType#FOCUS}
+ * should be used
+ * @return true if the Document is opened - false otherwise
+ * @see #getStyledDocument
+ * UserQuestionException handling
+ * @see org.openide.text.Line.ShowOpenType
+ * ShowOpenType
+ * @see org.openide.text.Line.ShowVisibilityType
+ * ShowVisibilityType
+ * @since org.openide.loaders 7.34
+ */
+ public static boolean openDocument(DataObject dobj, int offset, Line.ShowOpenType openType, Line.ShowVisibilityType visibilityType) {
+ assert dobj != null;
+ LineCookie lc = dobj.getLookup().lookup(LineCookie.class);
+ if ((lc != null) && (offset != -1)) {
+ StyledDocument doc = getStyledDocument(dobj);
+
+ if (doc != null) {
+ int line = NbDocument.findLineNumber(doc, offset);
+ int column = NbDocument.findLineColumn(doc, offset);
+
+ Line l = null;
+ try {
+ l = lc.getLineSet().getCurrent(line);
+ } catch (IndexOutOfBoundsException e) { // try to open at least the file (line no. is too high?)
+ l = lc.getLineSet().getCurrent(0);
+ }
+
+ if (l != null) {
+ doShow(l, column, openType, visibilityType);
+ return true;
+ }
+ }
+ }
+
+ Openable oc = dobj.getLookup().lookup(Openable.class);
+
+ if (oc != null) {
+ doOpen(oc);
+ return true;
+ }
+ return false;
+ }
+
+ /**
+ * Open the document associated with a file in the Editor window in a
+ * position specified by the line and column while controlling open and visibility behavior.
+ * This method can be called from any thread.
+ *
+ * @param dobj the DataObject
+ * @param line the line the document should be opened (starting at 0)
+ * @param column the column which should be selected (starting at 0), value
+ * -1 does not change previously selected column
+ * @param openType control open behavior, {@link org.openide.text.Line.ShowOpenType#OPEN}
+ * should be used
+ * @param visibilityType control visibility behavior, {@link org.openide.text.Line.ShowVisibilityType#FOCUS}
+ * should be used
+ * @return true if the Document is opened - false otherwise
+ * @see #getStyledDocument
+ * UserQuestionException handling
+ * @see org.openide.text.Line.ShowOpenType
+ * ShowOpenType
+ * @see org.openide.text.Line.ShowVisibilityType
+ * ShowVisibilityType
+ * @since org.openide.loaders 7.34
+ */
+ public static boolean openDocument(DataObject dobj, int line, int column, Line.ShowOpenType openType, Line.ShowVisibilityType visibilityType) {
+ assert dobj != null;
+ LineCookie lc = dobj.getLookup().lookup(LineCookie.class);
+ if ((lc != null) && (line >= 0) && (column >= -1)) {
+ StyledDocument doc = getStyledDocument(dobj);
+
+ if (doc != null) {
+ Line l = null;
+ try {
+ l = lc.getLineSet().getCurrent(line);
+ } catch (IndexOutOfBoundsException e) { // try to open at least the file (line no. is too high?)
+ l = lc.getLineSet().getCurrent(0);
+ }
+
+ if (l != null) {
+ doShow(l, column, openType, visibilityType);
+ return true;
+ }
+ }
+ }
+
+ Openable oc = dobj.getLookup().lookup(Openable.class);
+
+ if (oc != null) {
+ doOpen(oc);
+ return true;
+ }
+ return false;
+ }
+
+ private static void doShow(final Line l, final int column, final Line.ShowOpenType openType, final Line.ShowVisibilityType visibilityType) {
+ if (SwingUtilities.isEventDispatchThread()) {
+ l.show(openType, visibilityType, column);
+ } else {
+ SwingUtilities.invokeLater(new Runnable() {
+ @Override
+ public void run() {
+ l.show(openType, visibilityType, column);
+ }
+ });
+ }
+ }
+
+ private static void doOpen(final Openable oc) {
+ if (SwingUtilities.isEventDispatchThread()) {
+ oc.open();
+ } else {
+ SwingUtilities.invokeLater(new Runnable() {
+ @Override
+ public void run() {
+ oc.open();
+ }
+ });
+ }
+ }
+
/** Saves document. Overrides superclass method, adds checking
* for read-only property of saving file and warns user in that case. */
diff --git a/refactoring.java/src/org/netbeans/modules/refactoring/java/callhierarchy/Call.java b/refactoring.java/src/org/netbeans/modules/refactoring/java/callhierarchy/Call.java
--- a/refactoring.java/src/org/netbeans/modules/refactoring/java/callhierarchy/Call.java
+++ b/refactoring.java/src/org/netbeans/modules/refactoring/java/callhierarchy/Call.java
@@ -72,16 +72,13 @@
import org.netbeans.modules.refactoring.java.RetoucheUtils;
import org.openide.awt.StatusDisplayer;
import org.openide.cookies.EditorCookie;
-import org.openide.cookies.LineCookie;
-import org.openide.cookies.OpenCookie;
import org.openide.filesystems.FileObject;
import org.openide.filesystems.FileUtil;
import org.openide.loaders.DataObject;
import org.openide.loaders.DataObjectNotFoundException;
+import org.openide.text.DataEditorSupport;
import org.openide.text.Line;
-import org.openide.text.NbDocument;
import org.openide.text.PositionBounds;
-import org.openide.util.Exceptions;
import org.openide.util.ImageUtilities;
import org.openide.util.NbBundle;
@@ -400,46 +397,23 @@
final int begin = bounds.getBegin().getOffset();
final int end = bounds.getEnd().getOffset();
DataObject od = DataObject.find(fo);
- final EditorCookie ec = od.getCookie(org.openide.cookies.EditorCookie.class);
- LineCookie lc = od.getCookie(org.openide.cookies.LineCookie.class);
+ final EditorCookie ec = od.getLookup().lookup(org.openide.cookies.EditorCookie.class);
+ boolean opened = DataEditorSupport.openDocument(od, begin, Line.ShowOpenType.OPEN, Line.ShowVisibilityType.FOCUS);
+ if (opened) {
+ EventQueue.invokeLater(new Runnable() {
- if (ec != null && lc != null && begin != -1) {
- StyledDocument doc = ec.openDocument();
- if (doc != null) {
- int line = NbDocument.findLineNumber(doc, begin);
- int lineOffset = NbDocument.findLineOffset(doc, line);
- int column = begin - lineOffset;
-
- if (line != -1) {
- Line l = lc.getLineSet().getCurrent(line);
-
- if (l != null) {
- l.show(Line.ShowOpenType.OPEN, Line.ShowVisibilityType.FOCUS, column);
-
- EventQueue.invokeLater(new Runnable() {
-
- public void run() {
- ec.getOpenedPanes()[0].setSelectionStart(begin);
- ec.getOpenedPanes()[0].setSelectionEnd(end);
- }
- });
- return true;
- }
+ @Override
+ public void run() {
+ ec.getOpenedPanes()[0].setSelectionStart(begin);
+ ec.getOpenedPanes()[0].setSelectionEnd(end);
}
- }
- }
-
- OpenCookie oc = od.getCookie(org.openide.cookies.OpenCookie.class);
-
- if (oc != null) {
- oc.open();
+ });
return true;
}
+ return opened;
} catch (DataObjectNotFoundException e) {
StatusDisplayer.getDefault().setStatusText(NbBundle.getMessage(
Call.class, "Call.open.warning", FileUtil.getFileDisplayName(fo))); // NOI18N
- } catch (IOException e) {
- Exceptions.printStackTrace(e);
}
return false;
diff --git a/refactoring.java/src/org/netbeans/modules/refactoring/java/plugins/JavadocUtilities.java b/refactoring.java/src/org/netbeans/modules/refactoring/java/plugins/JavadocUtilities.java
--- a/refactoring.java/src/org/netbeans/modules/refactoring/java/plugins/JavadocUtilities.java
+++ b/refactoring.java/src/org/netbeans/modules/refactoring/java/plugins/JavadocUtilities.java
@@ -67,7 +67,6 @@
import javax.swing.text.BadLocationException;
import javax.swing.text.Document;
import javax.swing.text.Position;
-import javax.swing.text.StyledDocument;
import org.netbeans.api.java.lexer.JavaTokenId;
import org.netbeans.api.java.lexer.JavadocTokenId;
import org.netbeans.api.java.source.ClasspathInfo.PathKind;
@@ -75,12 +74,11 @@
import org.netbeans.api.lexer.Token;
import org.netbeans.api.lexer.TokenId;
import org.netbeans.api.lexer.TokenSequence;
-import org.openide.cookies.EditorCookie;
-import org.openide.cookies.LineCookie;
import org.openide.filesystems.FileObject;
import org.openide.loaders.DataObject;
-import org.openide.text.Line;
-import org.openide.text.NbDocument;
+import org.openide.text.DataEditorSupport;
+import org.openide.text.Line.ShowOpenType;
+import org.openide.text.Line.ShowVisibilityType;
/**
* copy paste from javadoc module
@@ -585,26 +583,7 @@
private static boolean doOpenImpl(FileObject fo, int offset) {
try {
DataObject od = DataObject.find(fo);
- EditorCookie ec = od.getCookie(EditorCookie.class);
- LineCookie lc = od.getCookie(LineCookie.class);
-
- if (ec != null && lc != null && offset != -1) {
- StyledDocument doc = ec.openDocument();
- if (doc != null) {
- int line = NbDocument.findLineNumber(doc, offset);
- int lineOffset = NbDocument.findLineOffset(doc, line);
- int column = offset - lineOffset;
-
- if (line != -1) {
- Line l = lc.getLineSet().getCurrent(line);
-
- if (l != null) {
- l.show(Line.ShowOpenType.OPEN, Line.ShowVisibilityType.FOCUS, column);
- return true;
- }
- }
- }
- }
+ return DataEditorSupport.openDocument(od, offset, ShowOpenType.OPEN, ShowVisibilityType.FOCUS);
} catch (IOException ex) {
Logger.getLogger(JavadocUtilities.class.getName()).log(Level.SEVERE, ex.getMessage(), ex);
}