A股上市公司传智教育(股票代码 003032)旗下技术交流社区北京昌平校区

打开浏览器,点击网页中一个超链接,但却启动了另一个软件-eclipse的直接搜索功能,并找出搜到的结果,有这么怪吗?这么点击网页的链接缺操纵了eclipse的功能,奇葩吗?用了你就知道了。
有什么作用呢?
超链接的作用我想大家都知道吧,点一下就过去了,网页的魅力就是超链接的魅力,李彦宏在google已经证明了还拿了专利。但是我们做项目开发,一个小组一大堆人做项目,每天都是拷贝改,到处改,各处查,每次都需要输入,如果过几天忘了要找到的东西在哪里,就按ctrl+H在然后选范围,或是全部项目搜索,啊?全部?可怕。200M的项目文件夹啊,看到进度搜索列表显示区不断地刷着各种文件的名字,妈呀。为什么eclipse就不像网页一样让我们可以编辑一个超链接html文档啊,IBM你告诉我,(⊙_⊙?)没有,为什么没有,我们点开那些文件夹可比网页上点击美女图片的次数还要多啊,毕竟是上一天班,一天都在点啊;只是回到家我们才点别人的链接的啊,而且大部分是看,不是点。
没有办法,我写了个eclipse的插件Eclick, 大家一起来点,一个人建个文件自己点,发给别人,别人点,上传到svn大家一起点。把经验的关键字,都存在文件里了,不好看还可以css一下。不要让大脑去存了好吗要死多少脑细胞啊?难道你1或者2年后再来翻看你项目,你大脑还存起以前的经验关键字的啊?所以说我在这里插一根旗,上面写着:“web化互联网,也web化eclipse”

http://www.oschina.net/p/eclick
大家可以试试:
  1. package webx.actions;

  2. import java.io.IOException;
  3. import java.io.InputStream;
  4. import java.io.OutputStream;
  5. import java.net.ServerSocket;
  6. import java.net.Socket;
  7. import java.util.ArrayList;

  8. import org.eclipse.core.resources.IResource;
  9. import org.eclipse.core.resources.ResourcesPlugin;
  10. import org.eclipse.core.runtime.CoreException;
  11. import org.eclipse.core.runtime.OperationCanceledException;
  12. import org.eclipse.core.runtime.Path;
  13. import org.eclipse.jface.dialogs.ErrorDialog;
  14. import org.eclipse.search.internal.ui.SearchPlugin;
  15. import org.eclipse.search.ui.ISearchQuery;
  16. import org.eclipse.search.ui.NewSearchUI;
  17. import org.eclipse.search.ui.text.TextSearchQueryProvider;
  18. import org.eclipse.search2.internal.ui.SearchMessages;
  19. import org.eclipse.swt.widgets.Display;
  20. import org.eclipse.swt.widgets.Shell;
  21. import org.eclipse.ui.IStartup;

  22. /**
  23. * 基于搜索项目和搜索关键字的WEB超链接搜索服务:
  24. * 解析网页超链接提交的字符串,获取参数"项目名称(scope)" 和 搜索"字符串(string)"
  25. * 并启动eclipse的文本搜索功能进行字符串搜索,用以替代CTRL+H然后手动输入.
  26. * html超链接代码:向插件内置服务 2014 socket端口提交要查找的项目和查找内容即是summery项目中的title noEmpty字符串:  
  27. *  <a href="http://localhost:2014/?scope=\\summery&string=title noEmpty">必输CSS样例</a>
  28. * @author 王华荣 2014.7.4
  29. *
  30. */
  31. class FindRun extends Thread{
  32.     // 搜索范围

  33.     static String scope="";
  34.      
  35.     // 搜索字符串

  36.     static String string = "";
  37.      
  38.     // 内置服务器端口2016

  39.     int port = 2016;

  40.     // 内置服务器

  41.     private ServerSocket ser;
  42.      
  43.     public void run() {
  44.         try {
  45.             ser = new ServerSocket(port);
  46.         }catch (IOException e) {
  47.             try {
  48.                 if(ser!=null)
  49.                 ser.close();
  50.             } catch (Exception e1) {e1.printStackTrace();}
  51.         }
  52.          
  53.         while(true){
  54.             InputStream ins = null;
  55.             Socket explor = null;
  56.             OutputStream os = null;
  57.             try {
  58.                 if(ser == null) break;
  59.                  
  60.                 System.out.println("等待读取1111url get:");
  61.                 explor = ser.accept();
  62.                 ins = explor.getInputStream();
  63.                 //os = explor.getOutputStream();

  64.                 //os.write(0);

  65.                 int xx= ins.available()==0?1000:ins.available();
  66.                 byte[] httprequest_data = new byte[xx];
  67.                 ins.read(httprequest_data);
  68.                 String rstr = new String(httprequest_data,"UTF-8");
  69.                 System.out.println("读取url get:["+rstr+"]");
  70.                 String[] arr = rstr.split(" ");
  71.                 if(arr.length<=1){
  72.                     continue;
  73.                 }
  74.                 rstr = rstr.split(" ")[1];
  75.                 String param = rstr.substring(rstr.indexOf("?")+1);
  76.                 String[] params = param.split("&");
  77.                 for(int i=0;i<params.length;i++){
  78.                     String name = params[i].split("=")[0];
  79.                     String vale = params[i].split("=")[1];
  80.                     vale = java.net.URLDecoder.decode(vale);
  81.                     if("scope".equals(name)){
  82.                         scope = vale;
  83.                     }
  84.                     if("string".equals(name)){
  85.                         string = vale;
  86.                     }
  87.                 }
  88.                 System.out.println("scope:"+scope);
  89.                 System.out.println("string:"+string);
  90.             
  91.                 Display.getDefault().syncExec(new Runnable() {
  92.                      public void run() {
  93.                         
  94.                         try{
  95.                            // searching...

  96.                            // 文本查找调度

  97.                            TextSearchQueryProvider provider = TextSearchQueryProvider.getPreferred();
  98.                            System.out.println("provider:"+provider);
  99.                             try
  100.                             {   // 文本查找器

  101.                                 ISearchQuery query = createQuery(provider,scope,string);
  102.                                  
  103.                                 if (query != null)
  104.                                     // 搜索

  105.                                     NewSearchUI.runQueryInBackground(query);
  106.                             }catch (OperationCanceledException _ex){
  107.                                 _ex.printStackTrace();
  108.                             }
  109.                             catch (CoreException e){  
  110.                                 e.printStackTrace();
  111.                                 try{
  112.                                     ErrorDialog.openError(getShell(), SearchMessages.RetrieverAction_error_title,
  113.                                         SearchMessages.RetrieverAction_error_message, e.getStatus());
  114.                                 }catch(Exception ex){
  115.                                     ex.printStackTrace();
  116.                                 }
  117.                             }
  118.                             // searching end

  119.                         }catch(Exception ex){
  120.                             ex.printStackTrace();
  121.                         }
  122.                         
  123.                       }
  124.                      }
  125.                   );
  126.             } catch (Exception e) {
  127.                 e.printStackTrace();
  128.             }
  129.             finally{
  130.                 if(ins!=null){
  131.                     try {
  132.                         ins.close();
  133.                     } catch (IOException e) {
  134.                         e.printStackTrace();
  135.                     }
  136.                 }
  137.                 if(os!=null){
  138.                     try {
  139.                         os.close();
  140.                     } catch (IOException e) {
  141.                         e.printStackTrace();
  142.                     }
  143.                 }
  144.             }   
  145.             
  146.         }
  147.     }
  148.      
  149.     private Shell getShell(){
  150.         return SearchPlugin.getActiveWorkbenchShell();
  151.     }
  152.      
  153.     /**
  154.      *
  155.      * @param provider
  156.      * @param scope 根据指定的资源搜索范围,进行搜索;多个路径以";"分割
  157.      * @param string 搜索字符串
  158.      * @return
  159.      * @throws CoreException
  160.      */
  161.     protected ISearchQuery createQuery(TextSearchQueryProvider provider,String scope, String string) throws CoreException
  162.     {
  163.         //IWorkspace resource = ResourcesPlugin.getWorkspace();

  164.         //IProject project = resource.getRoot().getProject(scope);

  165.         ArrayList list = new ArrayList();
  166.         String[] scopes = scope.split(";");
  167.         for(int i=0;i<scopes.length;i++){
  168.             IResource iresource = ResourcesPlugin.getWorkspace().getRoot().findMember(new Path(scopes[i]));
  169.             if(iresource!=null && iresource.exists()){
  170.                 list.add(iresource);
  171.             }
  172.         }
  173.          
  174.         //if (project != null)

  175.             return provider.createQuery(string,(IResource[])list.toArray(new IResource[0]));
  176.         //else

  177.         //  return provider.createQuery(string);

  178.     }
  179. }

  180. public class Startup implements IStartup {
  181.     public void earlyStartup() {
  182.         Display.getDefault().syncExec(new Runnable() {
  183.              public void run() {
  184.                  // start find server

  185.                  // 启动搜索服务

  186.                  new FindRun().start();
  187.              }
  188.           });
  189.        }
复制代码





11.png (99.32 KB, 下载次数: 6)

11.png

0 个回复

您需要登录后才可以回帖 登录 | 加入黑马