• <bdo id='rOB3B'></bdo><ul id='rOB3B'></ul>
      <legend id='rOB3B'><style id='rOB3B'><dir id='rOB3B'><q id='rOB3B'></q></dir></style></legend>
      <i id='rOB3B'><tr id='rOB3B'><dt id='rOB3B'><q id='rOB3B'><span id='rOB3B'><b id='rOB3B'><form id='rOB3B'><ins id='rOB3B'></ins><ul id='rOB3B'></ul><sub id='rOB3B'></sub></form><legend id='rOB3B'></legend><bdo id='rOB3B'><pre id='rOB3B'><center id='rOB3B'></center></pre></bdo></b><th id='rOB3B'></th></span></q></dt></tr></i><div id='rOB3B'><tfoot id='rOB3B'></tfoot><dl id='rOB3B'><fieldset id='rOB3B'></fieldset></dl></div>
    1. <small id='rOB3B'></small><noframes id='rOB3B'>

      1. <tfoot id='rOB3B'></tfoot>

        如何在 Eclipse 插件中添加 IResourceChangeListener?

        How to add IResourceChangeListener in eclipse plugin?(如何在 Eclipse 插件中添加 IResourceChangeListener?)

        1. <i id='RfdzC'><tr id='RfdzC'><dt id='RfdzC'><q id='RfdzC'><span id='RfdzC'><b id='RfdzC'><form id='RfdzC'><ins id='RfdzC'></ins><ul id='RfdzC'></ul><sub id='RfdzC'></sub></form><legend id='RfdzC'></legend><bdo id='RfdzC'><pre id='RfdzC'><center id='RfdzC'></center></pre></bdo></b><th id='RfdzC'></th></span></q></dt></tr></i><div id='RfdzC'><tfoot id='RfdzC'></tfoot><dl id='RfdzC'><fieldset id='RfdzC'></fieldset></dl></div>

            <tbody id='RfdzC'></tbody>
            • <bdo id='RfdzC'></bdo><ul id='RfdzC'></ul>
                  <legend id='RfdzC'><style id='RfdzC'><dir id='RfdzC'><q id='RfdzC'></q></dir></style></legend>

                  <tfoot id='RfdzC'></tfoot>

                  <small id='RfdzC'></small><noframes id='RfdzC'>

                  本文介绍了如何在 Eclipse 插件中添加 IResourceChangeListener?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我正在尝试在我的 Eclipse 插件中添加 IResourceChangeListener,使用以下教程:

                  https://eclipse.org/articles/Article-Resource-deltas/resource-deltas.html

                  但是,我从来没有找到任何地方,我应该在哪里添加这些侦听器代码.我发现他们只是在创建一个新类,在其中添加了侦听器代码.如果我将它添加到任何 java 类中,那么 eclipse 将如何知道事件发生时触发哪个类?我尝试将代码放在 activator.java 中,如下所示(我将其添加到那里是因为它维护了插件生命周期).

                  我修改了启动和停止方法.

                  package testPlugin;导入 org.eclipse.core.resources.IResourceChangeEvent;导入 org.eclipse.core.resources.IResourceChangeListener;导入 org.eclipse.core.resources.IWorkspace;导入 org.eclipse.core.resources.ResourcesPlugin;导入 org.eclipse.jface.resource.ImageDescriptor;导入 org.eclipse.ui.plugin.AbstractUIPlugin;导入 org.osgi.framework.BundleContext;/*** 激活器类控制插件生命周期*/公共类激活器扩展 AbstractUIPlugin {//插件IDpublic static final String PLUGIN_ID = "testPlugin";//$非NLS-1$/** URI 上的资源监听器改变 */IWorkspace 工作区 = ResourcesPlugin.getWorkspace();IResourceChangeListener 监听器;//共享实例私有静态激活器插件;/*** 构造函数**/公共激活器(){}/**(非 Javadoc)** @看* org.eclipse.ui.plugin.AbstractUIPlugin#start(org.osgi.framework.BundleContext* )*/公共无效开始(BundleContext上下文)抛出异常{超级开始(上下文);插件=这个;监听器 = 新的 IResourceChangeListener() {公共无效资源更改(IResourceChangeEvent 事件){System.out.println("有些东西改变了!");}};workspace.addResourceChangeListener(listener);}/**(非 Javadoc)** @看* org.eclipse.ui.plugin.AbstractUIPlugin#stop(org.osgi.framework.BundleContext* )*/公共无效停止(BundleContext上下文)抛出异常{如果(工作区!= null){workspace.removeResourceChangeListener(listener);}插件=空;超级停止(上下文);}/*** 返回共享实例** @return 共享实例*/公共静态激活器 getDefault() {返回插件;}/*** 返回给定插件的图像文件的图像描述符* 相对路径** @param 路径*            路径* @return 图像描述符*/公共静态ImageDescriptor getImageDescriptor(字符串路径){return imageDescriptorFromPlugin(PLUGIN_ID, path);}}

                  但它不起作用.当我通过外部 MKS 签出更改我当前的编辑器时,它没有将某些内容已更改"打印到 consol,或者根本无法正常工作.

                  我怎样才能让它工作?我应该在哪里实际添加代码?我想在 eclipse 中修改工作编辑器(可以是默认的 java 编辑器),而不用这个监听器创建任何新的编辑器.

                  非常感谢.

                  解决方案

                  有两种方法可以做到这一点.

                  1. 通过实现 IResourceChangeListener 编写您自己的类.这将提供良好的控制.
                  2. 使用下面的代码

                  <块引用>

                  workspace.addResourceChangeListener(listener,IResourceChangeEvent.POST_CHANGE|IResourceChangeEvent.PRE_BUILD);

                  I am trying to add IResourceChangeListener in my eclipse plugin, using following tutorial:

                  https://eclipse.org/articles/Article-Resource-deltas/resource-deltas.html

                  However, I never found anywhere, where should I add these listener code. I found that they are just creating a new class where they added the listener code. If I add it just in any java class, then how eclipse will know, which class to trigger when the events occur? I tried to put the code in activator.java as following (I added it there because it maintains the plugin life cycle).

                  I modified the start and stop method.

                  package testPlugin;
                  
                  import org.eclipse.core.resources.IResourceChangeEvent;
                  import org.eclipse.core.resources.IResourceChangeListener;
                  import org.eclipse.core.resources.IWorkspace;
                  import org.eclipse.core.resources.ResourcesPlugin;
                  import org.eclipse.jface.resource.ImageDescriptor;
                  import org.eclipse.ui.plugin.AbstractUIPlugin;
                  import org.osgi.framework.BundleContext;
                  
                  /**
                   * The activator class controls the plug-in life cycle
                   */
                  public class Activator extends AbstractUIPlugin {
                  
                      // The plug-in ID
                      public static final String PLUGIN_ID = "testPlugin"; //$NON-NLS-1$
                  
                      /** the resource listener on URI changes */
                      IWorkspace workspace = ResourcesPlugin.getWorkspace();
                      IResourceChangeListener listener;
                  
                      // The shared instance
                      private static Activator plugin;
                  
                      /**
                       * The constructor
                       * 
                       */
                  
                      public Activator() {
                  
                      }
                  
                      /*
                       * (non-Javadoc)
                       * 
                       * @see
                       * org.eclipse.ui.plugin.AbstractUIPlugin#start(org.osgi.framework.BundleContext
                       * )
                       */
                      public void start(BundleContext context) throws Exception {
                          super.start(context);
                          plugin = this;
                          listener = new IResourceChangeListener() {
                              public void resourceChanged(IResourceChangeEvent event) {
                                  System.out.println("Something changed!");
                              }
                          };
                  
                          workspace.addResourceChangeListener(listener);
                      }
                  
                      /*
                       * (non-Javadoc)
                       * 
                       * @see
                       * org.eclipse.ui.plugin.AbstractUIPlugin#stop(org.osgi.framework.BundleContext
                       * )
                       */
                      public void stop(BundleContext context) throws Exception {
                          if (workspace != null) {
                              workspace.removeResourceChangeListener(listener);
                          }
                          plugin = null;
                          super.stop(context);
                      }
                  
                      /**
                       * Returns the shared instance
                       *
                       * @return the shared instance
                       */
                      public static Activator getDefault() {
                  
                          return plugin;
                      }
                  
                      /**
                       * Returns an image descriptor for the image file at the given plug-in
                       * relative path
                       *
                       * @param path
                       *            the path
                       * @return the image descriptor
                       */
                      public static ImageDescriptor getImageDescriptor(String path) {
                          return imageDescriptorFromPlugin(PLUGIN_ID, path);
                      }
                  }
                  

                  But its not working. When I change my current editor by external MKS check out, its not printing "Something has changed" to consol, or simply its not working.

                  How can I make it working? Where should I add the code actually? I want to modify the working editor (can be default java editor) in eclipse without creating any new editor with this listener.

                  Thanks a lot in advance.

                  解决方案

                  There are 2 ways to do this.

                  1. Write your own class by implementing IResourceChangeListener. This will provide fine control.
                  2. Use below code

                  workspace.addResourceChangeListener(listener,IResourceChangeEvent.POST_CHANGE|IResourceChangeEvent.PRE_BUILD);

                  这篇关于如何在 Eclipse 插件中添加 IResourceChangeListener?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  Bytecode features not available in the Java language(Java 语言中不可用的字节码功能)
                  ClassCastException because of classloaders?(ClassCastException 因为类加载器?)
                  How can I add a Javaagent to a JVM without stopping the JVM?(如何在不停止 JVM 的情况下将 Javaagent 添加到 JVM?)
                  Cannot load 64-bit SWT libraries on 32-bit JVM ( replacing SWT file )(无法在 32 位 JVM 上加载 64 位 SWT 库(替换 SWT 文件))
                  Encourage the JVM to GC rather than grow the heap?(鼓励 JVM 进行 GC 而不是增加堆?)
                  Why a sawtooth shaped graph?(为什么是锯齿形图形?)

                        <tbody id='JEHaI'></tbody>
                    • <i id='JEHaI'><tr id='JEHaI'><dt id='JEHaI'><q id='JEHaI'><span id='JEHaI'><b id='JEHaI'><form id='JEHaI'><ins id='JEHaI'></ins><ul id='JEHaI'></ul><sub id='JEHaI'></sub></form><legend id='JEHaI'></legend><bdo id='JEHaI'><pre id='JEHaI'><center id='JEHaI'></center></pre></bdo></b><th id='JEHaI'></th></span></q></dt></tr></i><div id='JEHaI'><tfoot id='JEHaI'></tfoot><dl id='JEHaI'><fieldset id='JEHaI'></fieldset></dl></div>

                    • <legend id='JEHaI'><style id='JEHaI'><dir id='JEHaI'><q id='JEHaI'></q></dir></style></legend>

                      <small id='JEHaI'></small><noframes id='JEHaI'>

                        <tfoot id='JEHaI'></tfoot>

                            <bdo id='JEHaI'></bdo><ul id='JEHaI'></ul>