zoukankan      html  css  js  c++  java
  • 关闭控制台的自动切换按钮

    使用launch创建一个控制台后,公司提出新需求希望初始化关闭下图两个按钮,一个是当别的控制发生变化是自动切换控制台,第二个是当出现错误时自动切换错误视图,找到源码之后其实改源码试最方便,但是考虑到之后版本的升级,最好不改动源码,所以使用了反射来完成(对我这种半路出家的 ,工作以来就没写过反射,其实也很简单,只是有时候自己把他想难了)

    插入部分代码:

    private static ProcessConsolePageParticipant getProcessConsolePageParticipant(){
            DebugContextManager mananger =(DebugContextManager) DebugUITools.getDebugContextManager();
            Map<IWorkbenchWindow, DebugWindowContextService> list =(Map<IWorkbenchWindow, DebugWindowContextService>)reflexField(mananger,"fServices");
            DebugWindowContextService service = null;
            for (Map.Entry<IWorkbenchWindow, DebugWindowContextService> entry : list.entrySet()) {
                service = entry.getValue();
            }
            Map<String, ListenerList<IDebugContextListener>> map = (Map<String, ListenerList<IDebugContextListener>>)reflexField(service,"fListenersByPartId");
            ProcessConsolePageParticipant process = null;
            for (Map.Entry<String, ListenerList<IDebugContextListener>> entry : map.entrySet()) {
                ListenerList<IDebugContextListener> list1 = entry.getValue();
                Iterator<IDebugContextListener> iter = list1.iterator();
                while(iter.hasNext()){
                    //如果存在,则调用next实现迭代
                    IDebugContextListener iListener=(IDebugContextListener)iter.next();  
                    if(iListener instanceof ProcessConsolePageParticipant){
                        process = (ProcessConsolePageParticipant)iListener;
                        break;
                    }
                }
            }
            
            return process;
        }
        
        private static void runRemoveAction(){
            ProcessConsolePageParticipant process = getProcessConsolePageParticipant();
            ConsoleRemoveLaunchAction removeAction =(ConsoleRemoveLaunchAction)reflexField(process,"fRemoveTerminated");
            removeAction.run();
        }
        /**
         * 修改Action的状态
         */
        private static void modifyActionState(){
            ProcessConsolePageParticipant process = getProcessConsolePageParticipant();
            ShowStandardOutAction outAction =(ShowStandardOutAction)reflexField(process,"fStdOut");
            outAction.setChecked(false);
            ShowStandardErrorAction errorAction =(ShowStandardErrorAction)reflexField(process,"fStdErr");
            errorAction.setChecked(false);
        }
        
        private static Object reflexField(Object obj,String fieldName){
            Object val = null;
             try {
                 Class clazz = obj.getClass(); 
                 Field field = clazz.getDeclaredField(fieldName);
                 field.setAccessible(true);
                 val = field.get(obj);
                
             } catch (NoSuchFieldException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
             } catch (SecurityException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
            } catch (IllegalArgumentException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            } catch (IllegalAccessException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
             return val;
        }
  • 相关阅读:
    hibernate关联关系映射
    java单例模式
    HTML如何给table添加滚动条
    jquery的几种ajax方式对比
    JQuery Selectors 方法说明
    jQuery遍历对象/数组/集合
    Jquery常用函数
    【刷题】【省选】ZJOI2017_仙人掌_LOJ2250/Luogu3687_圆方树/dp计数/树形dp
    【学习笔记】圆方树学习笔记
    【模板】【刷题】差分与前缀和_LuoguP5488_多项式
  • 原文地址:https://www.cnblogs.com/yaolei0422/p/10007958.html
Copyright © 2011-2022 走看看