fix hole in commit-groups about empty commit group
diff --git a/openide.text/manifest.mf b/openide.text/manifest.mf
--- a/openide.text/manifest.mf
+++ b/openide.text/manifest.mf
@@ -1,7 +1,7 @@
Manifest-Version: 1.0
OpenIDE-Module: org.openide.text
OpenIDE-Module-Install: org/netbeans/modules/openide/text/Installer.class
-OpenIDE-Module-Specification-Version: 6.44
+OpenIDE-Module-Specification-Version: 6.45
OpenIDE-Module-Localizing-Bundle: org/openide/text/Bundle.properties
AutoUpdate-Essential-Module: true
diff --git a/openide.text/src/org/openide/text/NbDocument.java b/openide.text/src/org/openide/text/NbDocument.java
--- a/openide.text/src/org/openide/text/NbDocument.java
+++ b/openide.text/src/org/openide/text/NbDocument.java
@@ -45,13 +45,24 @@
import java.awt.Color;
import java.awt.Component;
+import java.io.IOException;
+import java.util.logging.Level;
+import java.util.logging.Logger;
import javax.swing.JEditorPane;
import javax.swing.JToolBar;
import javax.swing.SwingUtilities;
import javax.swing.text.*;
+import org.netbeans.api.actions.Openable;
+import org.openide.DialogDisplayer;
+import org.openide.NotifyDescriptor;
import org.openide.cookies.EditorCookie;
+import org.openide.cookies.LineCookie;
+import org.openide.util.Lookup;
+import org.openide.util.Mutex;
+import org.openide.util.NbBundle;
+import org.openide.util.UserQuestionException;
/** Dummy class holding utility methods for working with NetBeans document conventions.
@@ -518,6 +529,164 @@
}
((Annotatable) doc).removeAnnotation(annotation);
}
+
+ /**
+ * 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 provider for example a {@link DataObject}
+ * @return {@link javax.swing.text.StyledDocument} or null
+ * @since org.openide.text 6.45
+ */
+ @NbBundle.Messages("TXT_Question=Question")
+ public static StyledDocument getDocument(Lookup.Provider provider) {
+ try {
+ EditorCookie ec = provider.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(),
+ Bundle.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(NbDocument.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 but blocks until the document is opened.
+ *
+ * @param provider for example a {@link 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}
+ * would typically be used
+ * @param visibilityType control visibility behavior, {@link org.openide.text.Line.ShowVisibilityType#FOCUS}
+ * would typically be used
+ * @return true if the Document is opened - false otherwise
+ * @see #getDocument
+ * UserQuestionException handling
+ * @since org.openide.text 6.45
+ */
+ public static boolean openDocument(Lookup.Provider provider, int offset, Line.ShowOpenType openType, Line.ShowVisibilityType visibilityType) {
+ assert provider != null;
+ LineCookie lc = provider.getLookup().lookup(LineCookie.class);
+ if ((lc != null) && (offset != -1)) {
+ StyledDocument doc = getDocument(provider);
+
+ 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 = provider.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 but blocks until the document is opened.
+ *
+ * @param provider for example a {@link 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}
+ * would typically be used
+ * @param visibilityType control visibility behavior, {@link org.openide.text.Line.ShowVisibilityType#FOCUS}
+ * would typically be used
+ * @return true if the Document is opened - false otherwise
+ * @see #getDocument
+ * UserQuestionException handling
+ * @since org.openide.text 6.45
+ */
+ public static boolean openDocument(Lookup.Provider provider, int line, int column, Line.ShowOpenType openType, Line.ShowVisibilityType visibilityType) {
+ assert provider != null;
+ LineCookie lc = provider.getLookup().lookup(LineCookie.class);
+ if ((lc != null) && (line >= 0) && (column >= -1)) {
+ StyledDocument doc = getDocument(provider);
+
+ 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;
+ }
+ }
+ }
+
+ final Openable oc = provider.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) {
+ Mutex.EVENT.writeAccess(new Runnable() {
+
+ @Override
+ public void run() {
+ l.show(openType, visibilityType, column);
+ }
+ });
+ }
+
+ private static void doOpen(final Openable oc) {
+ Mutex.EVENT.writeAccess(new Runnable() {
+
+ @Override
+ public void run() {
+ oc.open();
+ }
+ });
+ }
/** Specialized version of document that knows how to lock the document
* for complex modifications.
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
@@ -45,7 +45,6 @@
import com.sun.source.util.TreePath;
import java.awt.EventQueue;
import java.awt.Image;
-import java.io.IOException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
@@ -63,7 +62,6 @@
import javax.lang.model.type.TypeVariable;
import javax.lang.model.type.WildcardType;
import javax.swing.Icon;
-import javax.swing.text.StyledDocument;
import org.netbeans.api.java.source.CompilationInfo;
import org.netbeans.api.java.source.ElementHandle;
import org.netbeans.api.java.source.TreePathHandle;
@@ -72,8 +70,6 @@
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;
@@ -81,7 +77,6 @@
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 +395,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 = NbDocument.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,11 +74,10 @@
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.Line.ShowOpenType;
+import org.openide.text.Line.ShowVisibilityType;
import org.openide.text.NbDocument;
/**
@@ -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 NbDocument.openDocument(od, offset, ShowOpenType.OPEN, ShowVisibilityType.FOCUS);
} catch (IOException ex) {
Logger.getLogger(JavadocUtilities.class.getName()).log(Level.SEVERE, ex.getMessage(), ex);
}