[hg] main-silver: moved opendocument and jumpto to bugtracking.b...

  • From: Tomas Stupka < >
  • To: , ,
  • Subject: [hg] main-silver: moved opendocument and jumpto to bugtracking.b...
  • Date: Mon, 22 Apr 2013 17:51:31 -0700

changeset 6e895ad5b6fa in main-silver ((none))
details: http://hg.netbeans.org/main-silver/rev/6e895ad5b6fa
description:
        moved opendocument and jumpto to bugtracking.bridge

diffstat:

 bugtracking.bridge/nbproject/project.xml                                     
                   |   26 ++
 
bugtracking.bridge/src/org/netbeans/modules/bugtracking/bridge/ideservices/IDEServicesImpl.java
 |  127 ++++++++++
 bugtracking/nbproject/project.xml                                            
                   |   25 +-
 bugtracking/src/org/netbeans/modules/bugtracking/BugtrackingManager.java     
                   |   10 +
 bugtracking/src/org/netbeans/modules/bugtracking/ide/spi/IDEServices.java    
                   |   64 +++++
 bugtracking/src/org/netbeans/modules/bugtracking/util/FindTypesSupport.java  
                   |   15 +-
 bugtracking/src/org/netbeans/modules/bugtracking/util/StackTraceSupport.java 
                   |   55 +--
 jumpto/nbproject/project.xml                                                 
                   |    2 +-
 8 files changed, 264 insertions(+), 60 deletions(-)

diffs (517 lines):

diff --git a/bugtracking.bridge/nbproject/project.xml 
b/bugtracking.bridge/nbproject/project.xml
--- a/bugtracking.bridge/nbproject/project.xml
+++ b/bugtracking.bridge/nbproject/project.xml
@@ -6,6 +6,24 @@
             
<code-name-base>org.netbeans.modules.bugtracking.bridge</code-name-base>
             <module-dependencies>
                 <dependency>
+                    
<code-name-base>org.netbeans.modules.jumpto</code-name-base>
+                    <build-prerequisite/>
+                    <compile-dependency/>
+                    <run-dependency>
+                        <release-version>1</release-version>
+                        <specification-version>1.25</specification-version>
+                    </run-dependency>
+                </dependency>
+                <dependency>
+                    
<code-name-base>org.netbeans.api.java.classpath</code-name-base>
+                    <build-prerequisite/>
+                    <compile-dependency/>
+                    <run-dependency>
+                        <release-version>1</release-version>
+                        <specification-version>1.19</specification-version>
+                    </run-dependency>
+                </dependency>                    
+                <dependency>
                     
<code-name-base>org.netbeans.api.progress</code-name-base>
                     <build-prerequisite/>
                     <compile-dependency/>
@@ -32,6 +50,14 @@
                     </run-dependency>
                 </dependency>
                 <dependency>
+                    <code-name-base>org.openide.text</code-name-base>
+                    <build-prerequisite/>
+                    <compile-dependency/>
+                    <run-dependency>
+                        <specification-version>6.46</specification-version>
+                    </run-dependency>
+                </dependency>                    
+                <dependency>
                     
<code-name-base>org.netbeans.modules.lexer</code-name-base>
                     <build-prerequisite/>
                     <compile-dependency/>
diff --git 
a/bugtracking.bridge/src/org/netbeans/modules/bugtracking/bridge/ideservices/IDEServicesImpl.java
 
b/bugtracking.bridge/src/org/netbeans/modules/bugtracking/bridge/ideservices/IDEServicesImpl.java
new file mode 100644
--- /dev/null
+++ 
b/bugtracking.bridge/src/org/netbeans/modules/bugtracking/bridge/ideservices/IDEServicesImpl.java
@@ -0,0 +1,127 @@
+/*
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
+ *
+ * Copyright 2013 Oracle and/or its affiliates. All rights reserved.
+ *
+ * Oracle and Java are registered trademarks of Oracle and/or its affiliates.
+ * Other names may be trademarks of their respective owners.
+ *
+ * The contents of this file are subject to the terms of either the GNU
+ * General Public License Version 2 only ("GPL") or the Common
+ * Development and Distribution License("CDDL") (collectively, the
+ * "License"). You may not use this file except in compliance with the
+ * License. You can obtain a copy of the License at
+ * http://www.netbeans.org/cddl-gplv2.html
+ * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
+ * specific language governing permissions and limitations under the
+ * License.  When distributing the software, include this License Header
+ * Notice in each file and include the License file at
+ * nbbuild/licenses/CDDL-GPL-2-CP.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the GPL Version 2 section of the License file that
+ * accompanied this code. If applicable, add the following below the
+ * License Header, with the fields enclosed by brackets [] replaced by
+ * your own identifying information:
+ * "Portions Copyrighted [year] [name of copyright owner]"
+ *
+ * If you wish your version of this file to be governed by only the CDDL
+ * or only the GPL Version 2, indicate your decision by adding
+ * "[Contributor] elects to include this software in this distribution
+ * under the [CDDL or GPL Version 2] license." If you do not indicate a
+ * single choice of license, a recipient has the option to distribute
+ * your version of this file under either the CDDL, the GPL Version 2 or
+ * to extend the choice of license to its licensees as provided above.
+ * However, if you add GPL Version 2 code and therefore, elected the GPL
+ * Version 2 license, then the option applies only if the new code is
+ * made subject to such option by the copyright holder.
+ *
+ * Contributor(s):
+ *
+ * Portions Copyrighted 2013 Sun Microsystems, Inc.
+ */
+
+package org.netbeans.modules.bugtracking.bridge.ideservices;
+
+import java.util.logging.Level;
+import java.util.logging.Logger;
+import javax.swing.SwingUtilities;
+import org.netbeans.api.java.classpath.GlobalPathRegistry;
+import org.netbeans.api.jumpto.type.TypeBrowser;
+import org.netbeans.modules.bugtracking.ide.spi.IDEServices;
+import org.netbeans.spi.jumpto.type.TypeDescriptor;
+import org.openide.DialogDisplayer;
+import org.openide.NotifyDescriptor;
+import org.openide.filesystems.FileObject;
+import org.openide.loaders.DataObject;
+import org.openide.loaders.DataObjectNotFoundException;
+import org.openide.text.Line;
+import org.openide.text.NbDocument;
+import org.openide.util.NbBundle;
+
+/**
+ *
+ * @author Tomas Stupka
+ */
+@org.openide.util.lookup.ServiceProvider(service=org.netbeans.modules.bugtracking.ide.spi.IDEServices.class)
+public class IDEServicesImpl implements IDEServices {
+    static final Logger LOG = 
Logger.getLogger(IDEServicesImpl.class.getName());
+    
+    @Override
+    public boolean providesOpenDocument() {
+        return true;
+    }
+    
+    @Override
+    @NbBundle.Messages({"LBL_OpenDocument=Open Document", 
+                        "# {0} - to be opened documents path",  
"MSG_CannotOpen=Couldn't open document for {0}",
+                        "# {0} - to be found documents path",  
"MSG_CannotFind=Couldn't find document for {0}"})
+    public void openDocument(final String path, final int offset) {
+        final FileObject fo = searchResource(path);
+        if ( fo != null ) {
+            SwingUtilities.invokeLater(new Runnable() {
+                @Override
+                public void run() {
+                    try {
+                        DataObject od = DataObject.find(fo);
+                        boolean ret = NbDocument.openDocument(od, offset, 
-1, Line.ShowOpenType.OPEN, Line.ShowVisibilityType.FOCUS);
+                        if(!ret) {
+                            notifyError(Bundle.LBL_OpenDocument(), 
Bundle.MSG_CannotOpen(path));
+                        }
+                    } catch (DataObjectNotFoundException e) {
+                        IDEServicesImpl.LOG.log(Level.SEVERE, null, e);
+                    }
+                }
+            });
+        } else {
+            notifyError(Bundle.LBL_OpenDocument(), 
Bundle.MSG_CannotFind(path));
+        }
+    }
+
+    @Override
+    public boolean providesSearchResource() {
+        return true;
+    }
+    
+    @Override
+    public FileObject searchResource(String path) {
+        return GlobalPathRegistry.getDefault().findResource(path);
+    }    
+
+    @Override
+    public boolean providesJumpTo() {
+        return true;
+    }
+
+    @Override
+    public void jumpTo(String label, String resource) {
+        TypeDescriptor td = TypeBrowser.browse(label, resource, null);
+        if(td != null) {
+            td.open();
+        }
+    }
+
+    private static void notifyError (final String title, final String 
message) {
+        NotifyDescriptor nd = new NotifyDescriptor(message, title, 
NotifyDescriptor.DEFAULT_OPTION, NotifyDescriptor.ERROR_MESSAGE, new Object[] 
{NotifyDescriptor.OK_OPTION}, NotifyDescriptor.OK_OPTION);
+        DialogDisplayer.getDefault().notifyLater(nd);
+    }      
+}
diff --git a/bugtracking/nbproject/project.xml 
b/bugtracking/nbproject/project.xml
--- a/bugtracking/nbproject/project.xml
+++ b/bugtracking/nbproject/project.xml
@@ -6,12 +6,11 @@
             <code-name-base>org.netbeans.modules.bugtracking</code-name-base>
             <module-dependencies>
                 <dependency>
-                    
<code-name-base>org.netbeans.api.java.classpath</code-name-base>
+                    <code-name-base>org.openide.dialogs</code-name-base>
                     <build-prerequisite/>
                     <compile-dependency/>
                     <run-dependency>
-                        <release-version>1</release-version>
-                        <specification-version>1.19</specification-version>
+                        <specification-version>7.9</specification-version>
                     </run-dependency>
                 </dependency>
                 <dependency>
@@ -58,15 +57,6 @@
                     </run-dependency>
                 </dependency>
                 <dependency>
-                    
<code-name-base>org.netbeans.modules.jumpto</code-name-base>
-                    <build-prerequisite/>
-                    <compile-dependency/>
-                    <run-dependency>
-                        <release-version>1</release-version>
-                        <specification-version>1.25</specification-version>
-                    </run-dependency>
-                </dependency>
-                <dependency>
                     
<code-name-base>org.netbeans.modules.keyring</code-name-base>
                     <build-prerequisite/>
                     <compile-dependency/>
@@ -192,14 +182,6 @@
                     </run-dependency>
                 </dependency>
                 <dependency>
-                    <code-name-base>org.openide.text</code-name-base>
-                    <build-prerequisite/>
-                    <compile-dependency/>
-                    <run-dependency>
-                        <specification-version>6.46</specification-version>
-                    </run-dependency>
-                </dependency>
-                <dependency>
                     <code-name-base>org.openide.util</code-name-base>
                     <build-prerequisite/>
                     <compile-dependency/>
@@ -255,10 +237,11 @@
                 <friend>org.netbeans.modules.tasks.ui</friend>
                 <friend>org.netbeans.modules.versioning.kenai</friend>
                 <package>org.netbeans.modules.bugtracking.api</package>
+                <package>org.netbeans.modules.bugtracking.cache</package>
+                <package>org.netbeans.modules.bugtracking.ide.spi</package>
                 
<package>org.netbeans.modules.bugtracking.issuetable</package>
                 <package>org.netbeans.modules.bugtracking.kenai.spi</package>
                 <package>org.netbeans.modules.bugtracking.spi</package>
-                <package>org.netbeans.modules.bugtracking.cache</package>
                 <package>org.netbeans.modules.bugtracking.util</package>
             </friend-packages>
         </data>
diff --git 
a/bugtracking/src/org/netbeans/modules/bugtracking/BugtrackingManager.java 
b/bugtracking/src/org/netbeans/modules/bugtracking/BugtrackingManager.java
--- a/bugtracking/src/org/netbeans/modules/bugtracking/BugtrackingManager.java
+++ b/bugtracking/src/org/netbeans/modules/bugtracking/BugtrackingManager.java
@@ -54,6 +54,7 @@
 import java.util.Map;
 import java.util.logging.Level;
 import java.util.logging.Logger;
+import org.netbeans.modules.bugtracking.ide.spi.IDEServices;
 import org.netbeans.modules.bugtracking.kenai.spi.KenaiAccessor;
 import org.netbeans.modules.bugtracking.spi.BugtrackingConnector;
 import org.netbeans.modules.bugtracking.kenai.spi.RecentIssue;
@@ -94,6 +95,7 @@
         }
         return instance;
     }
+    private IDEServices ideServices;
 
     private BugtrackingManager() { }
 
@@ -208,4 +210,12 @@
         }
         return null;
     }
+
+    public synchronized IDEServices getIDEServices() {
+        if(ideServices == null) {
+            ideServices = Lookup.getDefault().lookup(IDEServices.class);
 }
+        return ideServices;
+    }
+    
+}
diff --git 
a/bugtracking/src/org/netbeans/modules/bugtracking/ide/spi/IDEServices.java 
b/bugtracking/src/org/netbeans/modules/bugtracking/ide/spi/IDEServices.java
new file mode 100644
--- /dev/null
+++ 
b/bugtracking/src/org/netbeans/modules/bugtracking/ide/spi/IDEServices.java
@@ -0,0 +1,64 @@
+/*
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
+ *
+ * Copyright 2013 Oracle and/or its affiliates. All rights reserved.
+ *
+ * Oracle and Java are registered trademarks of Oracle and/or its affiliates.
+ * Other names may be trademarks of their respective owners.
+ *
+ * The contents of this file are subject to the terms of either the GNU
+ * General Public License Version 2 only ("GPL") or the Common
+ * Development and Distribution License("CDDL") (collectively, the
+ * "License"). You may not use this file except in compliance with the
+ * License. You can obtain a copy of the License at
+ * http://www.netbeans.org/cddl-gplv2.html
+ * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
+ * specific language governing permissions and limitations under the
+ * License.  When distributing the software, include this License Header
+ * Notice in each file and include the License file at
+ * nbbuild/licenses/CDDL-GPL-2-CP.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the GPL Version 2 section of the License file that
+ * accompanied this code. If applicable, add the following below the
+ * License Header, with the fields enclosed by brackets [] replaced by
+ * your own identifying information:
+ * "Portions Copyrighted [year] [name of copyright owner]"
+ *
+ * If you wish your version of this file to be governed by only the CDDL
+ * or only the GPL Version 2, indicate your decision by adding
+ * "[Contributor] elects to include this software in this distribution
+ * under the [CDDL or GPL Version 2] license." If you do not indicate a
+ * single choice of license, a recipient has the option to distribute
+ * your version of this file under either the CDDL, the GPL Version 2 or
+ * to extend the choice of license to its licensees as provided above.
+ * However, if you add GPL Version 2 code and therefore, elected the GPL
+ * Version 2 license, then the option applies only if the new code is
+ * made subject to such option by the copyright holder.
+ *
+ * Contributor(s):
+ *
+ * Portions Copyrighted 2013 Sun Microsystems, Inc.
+ */
+
+package org.netbeans.modules.bugtracking.ide.spi;
+
+import org.openide.filesystems.FileObject;
+
+/**
+ *
+ * @author Tomas Stupka
+ */
+public interface IDEServices {
+    
+    public boolean providesOpenDocument();
+    public void openDocument(String path, int offset);
+    
+    public boolean providesSearchResource();
+    public FileObject searchResource(String path);
+        
+    public boolean providesJumpTo();
+    public void jumpTo(String label, String resource);
+    
+    
+    
+}
diff --git 
a/bugtracking/src/org/netbeans/modules/bugtracking/util/FindTypesSupport.java 
b/bugtracking/src/org/netbeans/modules/bugtracking/util/FindTypesSupport.java
--- 
a/bugtracking/src/org/netbeans/modules/bugtracking/util/FindTypesSupport.java
+++ 
b/bugtracking/src/org/netbeans/modules/bugtracking/util/FindTypesSupport.java
@@ -41,7 +41,6 @@
  */
 package org.netbeans.modules.bugtracking.util;
 
-import java.awt.Color;
 import java.awt.Component;
 import java.awt.Font;
 import java.awt.FontMetrics;
@@ -56,7 +55,6 @@
 import java.util.LinkedList;
 import java.util.List;
 import java.util.logging.Level;
-import java.util.logging.Logger;
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;
 import javax.swing.AbstractAction;
@@ -65,9 +63,8 @@
 import javax.swing.JTextPane;
 import javax.swing.SwingUtilities;
 import javax.swing.text.*;
-import org.netbeans.api.jumpto.type.TypeBrowser;
 import org.netbeans.modules.bugtracking.BugtrackingManager;
-import org.netbeans.spi.jumpto.type.TypeDescriptor;
+import org.netbeans.modules.bugtracking.ide.spi.IDEServices;
 import org.openide.util.Exceptions;
 import org.openide.util.NbBundle;
 
@@ -154,6 +151,10 @@
     }
     
     public void register(final JTextPane pane) {
+        IDEServices ideServices = 
BugtrackingManager.getInstance().getIDEServices();
+        if(ideServices == null || !ideServices.providesSearchResource() || 
!ideServices.providesJumpTo()) {
+            return;
+        }
         long t = System.currentTimeMillis();
         try {
             SwingUtilities.invokeLater(new Runnable() {
@@ -319,9 +320,9 @@
     
     private class TypeLink {
         public void jumpTo(String resource) {
-            TypeDescriptor td = 
TypeBrowser.browse(NbBundle.getMessage(FindTypesSupport.class, 
"LBL_FindType"), resource, null); // NOI18N
-            if(td != null) {
-                td.open();
+            IDEServices ideServices = 
BugtrackingManager.getInstance().getIDEServices();
+            if(ideServices != null) {
+                
ideServices.jumpTo(NbBundle.getMessage(FindTypesSupport.class, 
"LBL_FindType"), resource);  // NOI18N
             }
         }
     }
diff --git 
a/bugtracking/src/org/netbeans/modules/bugtracking/util/StackTraceSupport.java
 
b/bugtracking/src/org/netbeans/modules/bugtracking/util/StackTraceSupport.java
--- 
a/bugtracking/src/org/netbeans/modules/bugtracking/util/StackTraceSupport.java
+++ 
b/bugtracking/src/org/netbeans/modules/bugtracking/util/StackTraceSupport.java
@@ -42,11 +42,9 @@
 
 package org.netbeans.modules.bugtracking.util;
 
-import java.awt.Color;
 import java.awt.event.ActionEvent;
 import java.awt.event.MouseEvent;
 import java.io.File;
-import java.io.IOException;
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.LinkedList;
@@ -67,16 +65,11 @@
 import javax.swing.text.StyleConstants;
 import javax.swing.text.StyleContext;
 import javax.swing.text.StyledDocument;
-import org.netbeans.api.java.classpath.GlobalPathRegistry;
 import org.netbeans.modules.bugtracking.BugtrackingManager;
+import org.netbeans.modules.bugtracking.ide.spi.IDEServices;
 import org.netbeans.modules.bugtracking.spi.VCSAccessor;
 import org.openide.filesystems.FileObject;
 import org.openide.filesystems.FileUtil;
-import org.openide.loaders.DataObject;
-import org.openide.text.Line.ShowOpenType;
-import org.openide.text.Line.ShowVisibilityType;
-import org.openide.text.NbDocument;
-import org.openide.util.Exceptions;
 import org.openide.util.Lookup;
 import org.openide.util.NbBundle;
 
@@ -128,6 +121,9 @@
         return path;
     }
 
+    /**
+     * package private for test purposes
+     */
     static List<StackTracePosition> find(String text) {
 
        LinkedList<StackTracePosition> result = new 
LinkedList<StackTracePosition>();
@@ -135,11 +131,11 @@
            return result;
        }
 
-       List<Integer> lineBreaks = new ArrayList<Integer>();
-       int pos = -1;
-       while( (pos = text.indexOf("\n", pos + 1)) > -1) {
-           lineBreaks.add(pos);
-       }
+//       List<Integer> lineBreaks = new ArrayList<Integer>();
+//       int pos = -1;
+//       while( (pos = text.indexOf("\n", pos + 1)) > -1) {
+//           lineBreaks.add(pos);
+//       }
 
        String nt = removeAll( text, '\n');
        //String nt = text.replace('\n', ' ');
@@ -303,14 +299,15 @@
     }
 
     static void open(String path, final int line) {
-        final FileObject fo = search(path);
-        if ( fo != null ) {
-            SwingUtilities.invokeLater(new Runnable() {
-                public void run() {
-                    doOpen(fo, line);
+        IDEServices ideServices = 
BugtrackingManager.getInstance().getIDEServices();
+        if(ideServices != null) {
+            ideServices.openDocument(path, line);
                 }
-            });
         }
+
+    static boolean isAvailable() {
+        IDEServices ideServices = 
BugtrackingManager.getInstance().getIDEServices();
+        return ideServices != null && ideServices.providesOpenDocument() && 
ideServices.providesSearchResource();
     }
 
     private static void openSearchHistory(String path, final int line) {
@@ -337,22 +334,18 @@
         }
     }
 
-    private static boolean doOpen(FileObject fo, int line) {
-        try {
-            DataObject od = DataObject.find(fo);
-            return NbDocument.openDocument(od, line, -1, ShowOpenType.OPEN, 
ShowVisibilityType.FOCUS);
-        } catch (IOException e) {
-            BugtrackingManager.LOG.log(Level.SEVERE, null, e);
+    private static FileObject search(String path) {
+        IDEServices ideServices = 
BugtrackingManager.getInstance().getIDEServices();
+        if(ideServices != null) {
+            return ideServices.searchResource(path);
         }
-
-        return false;
-    }
-
-    static private FileObject search(String path) {
-        return GlobalPathRegistry.getDefault().findResource(path);
+        return null;
     }
 
     public static void register(final JTextPane textPane) {
+        if(!isAvailable()) {
+            return;
+        }
         final StyledDocument doc = textPane.getStyledDocument();
         String text = "";
         try {
diff --git a/jumpto/nbproject/project.xml b/jumpto/nbproject/project.xml
--- a/jumpto/nbproject/project.xml
+++ b/jumpto/nbproject/project.xml
@@ -232,7 +232,7 @@
                 <friend>org.netbeans.modules.java.sourceui</friend>
                 <friend>org.netbeans.modules.javafx.editor</friend>
                 <friend>org.netbeans.modules.spring.beans</friend>
-                <friend>org.netbeans.modules.bugtracking</friend>
+                <friend>org.netbeans.modules.bugtracking.bridge</friend>
                 <package>org.netbeans.api.jumpto.type</package>
                 <package>org.netbeans.spi.jumpto.file</package>
                 <package>org.netbeans.spi.jumpto.support</package>

[hg] main-silver: moved opendocument and jumpto to bugtracking.b...

Tomas Stupka 04/23/2013

Project Features

About this Project

Editor was started in November 2009, is owned by Martin Ryzl, and has 147 members.
By use of this website, you agree to the NetBeans Policies and Terms of Use (revision 20131025.e7cbc9d). © 2013, Oracle Corporation and/or its affiliates. Sponsored by Oracle logo
 
 
Close
loading
Please Confirm
Close