简体   繁体   English

Eclipse-自定义启动配置-应用/还原按钮

[英]Eclipse - custom launch configuration - apply/revert buttons

I'm making my custom launch configuration type. 我正在创建自定义启动配置类型。 I implemented the launch configuration tab and faced the strange problem. 我实现了启动配置选项卡,并遇到了奇怪的问题。 When I do the following 当我执行以下操作时

private void update() {
    setDirty(true);
    updateLaunchConfigurationDialog();
}

in one place of my launch configuration tab class, it works fine and Apply button becomes enabled. 在我的启动配置选项卡类的某个位置,它可以正常工作,并且启用了“应用”按钮。 But when I do it in another place, it doesn't work. 但是,当我在另一个地方执行此操作时,该操作将无效。 I found something similar at https://www.eclipse.org/forums/index.php/t/164755/ , but it didn't help me to solve this problem. 我在https://www.eclipse.org/forums/index.php/t/164755/上找到了类似的内容,但这并没有帮助我解决此问题。

See the code fragments below. 请参见下面的代码片段。

    addButton.addMouseListener(new MouseListenerAdapter() {

        @Override
        public void mouseDown(MouseEvent e) {
            moveSelectionToTableViewer(tree.getViewer().getTree().getSelection());
            table.refresh();
            update(); // Apply button is enabled
        }

        private void moveSelectionToTableViewer(TreeItem[] selection) {
            // ...
        }
    });

    removeButton.addMouseListener(new MouseListenerAdapter() {

        @Override
        public void mouseDown(MouseEvent e) {
            int[] selectionIndices = table.getTable().getSelectionIndices();
            table.getTable().remove(selectionIndices);
            tree.getViewer().refresh();
            update(); // Apply button is NOT enabled!
        }
    });

How can I solve this? 我该如何解决?

I don't know your problem from this information alone, But just a few things to check: 我不单凭这些信息就知道您的问题,但需要检查的几件事:

  1. Have you verified that setDirty(true) is being called (eg with println or breakpoint?) 您是否已验证正在调用setDirty(true) (例如,使用println或Breakpoint?)
  2. Have you put a watch on org.eclipse.debug.ui.AbstractLaunchConfigurationTab.fDirty to see if it changes back? 您是否在org.eclipse.debug.ui.AbstractLaunchConfigurationTab.fDirty上放置了手表以查看其是否变回原来的状态?
  3. Are you overriding isDirty ? 您是重载isDirty吗?
  4. Is removing the an item from the table causing the launch configuration to become invalid in some way, ie you can't Apply when invalid values are in the launch config. 正在从表中删除一项,导致启动配置以某种方式变为无效,即,当启动配置中的值无效时,您将无法Apply For example, to be saveable, canSave must return true for all the tabs that are part of the launch configuration. 例如,要保存, canSave必须为启动配置中的所有选项卡返回true

This is (one of the) place(s) that sets the enabled state of the Apply button: 这是设置“应用”按钮的启用状态的位置之一。

org.eclipse.debug.internal.ui.launchConfigurations.LaunchConfigurationTabGroupViewer.updateButtons()

/**
 * updates the button states
 */
private void updateButtons() {
    boolean dirty = isDirty() && canSave();
    fApplyButton.setEnabled(dirty);
    fRevertButton.setEnabled(dirty);
}
  1. Consider if a mouse listener is what you want. 考虑鼠标监听器是否是您想要的。 Note that you are responding to MouseDown, that may not do what you expect if a person tabs over to the control and presses Enter/Space instead. 请注意,您正在响应MouseDown,如果有人将鼠标移至控件上并按Enter / Space,则可能无法实现预期的效果。 The more typical thing to do would be an addSelectionListener for a button. 最典型的操作是按钮的addSelectionListener (Could it even be that responding to the event at this unusual time is causing the problem?) (是否有可能在这个不寻常的时间对事件进行响应引起了问题?)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM