实现启动器框架 - 禁用对话框上应用按钮 [英] Implementing a Launcher Framework - disabled Apply button on dialog

查看:414
本文介绍了实现启动器框架 - 禁用对话框上应用按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用eclipse插件,并根据链接实现一个自定义启动器 https://eclipse.org/articles/Article-Launch-Framework/launch.html

I am working on a eclipse plugin and implementing a custom launcher as per the link https://eclipse.org/articles/Article-Launch-Framework/launch.html .

我已经实现了一个BrowsersTab类,它扩展了AbstractLaunchConfigurationTab并实现了所有的方法。问题是当我调用updateLaunchConfigurationDialog();在选择事件上,应用按钮保持禁用。

I have implemented a class BrowsersTab which extends AbstractLaunchConfigurationTab and implemented all the methods. The problem is that when I call the updateLaunchConfigurationDialog(); on the selection event , the 'Apply' Button remains disabled.

代码:

public class BrowsersTab extends AbstractLaunchConfigurationTab  {

    private Button chrome;
    private Button firefox;
    private Button safari;
    private Button ie;
    private Button opera;
    private Button android;
    private Button ios;



    @Override
    public void createControl(Composite parent) {

        Composite comp = new Composite(parent, SWT.NONE);
        setControl(comp);

        GridLayout topLayout = new GridLayout();
        comp.setLayout(topLayout);


        Group fGroup = new Group(comp, SWT.NONE);

        fGroup.setFont(parent.getFont());
        fGroup.setLayout(new GridLayout(2, true));
        fGroup.setText(DialogMessages.browserSelection);
        chrome = new Button(fGroup, SWT.CHECK);
        chrome.setText("Google Chrome");

        chrome.addSelectionListener(new SelectionListener() {

            public void widgetSelected(SelectionEvent e) {
                System.out.println("chrome selected");
                updateLaunchConfigurationDialog();
            }

            public void widgetDefaultSelected(SelectionEvent e) {
                // TODO Auto-generated method stub

            }
        });

        Image chromeIcon= getBrowserIcon("chrome-browser-24X24.png");
        if(null!=chromeIcon)
        chrome.setImage(chromeIcon);

        Combo comboDropDown = new Combo(fGroup, SWT.DROP_DOWN | SWT.BORDER);
        comboDropDown.setText("Version");


        firefox = new Button(fGroup, SWT.CHECK);
        firefox.setText("Mozilla Firefox");

        Image firefoxIcon= getBrowserIcon("Firefox-icon.png");
        if(null!=firefoxIcon)
            firefox.setImage(firefoxIcon);

        comboDropDown = new Combo(fGroup, SWT.DROP_DOWN | SWT.BORDER);
        comboDropDown.setText("Version");


        safari = new Button(fGroup, SWT.CHECK);
        safari.setText("Apple Safari");

        Image safariIcon= getBrowserIcon("Safari-icon.png");
        if(null!=safariIcon)
            safari.setImage(safariIcon);

        comboDropDown = new Combo(fGroup, SWT.DROP_DOWN | SWT.BORDER);
        comboDropDown.setText("Version");

        ie = new Button(fGroup, SWT.CHECK);
        ie.setText("Internet Explorer");

        Image ieIcon= getBrowserIcon("Internet-Explorer-icon.png");
        if(null!=ieIcon)
            ie.setImage(ieIcon);

        comboDropDown = new Combo(fGroup, SWT.DROP_DOWN | SWT.BORDER);
        comboDropDown.setText("Version");

        opera= new Button(fGroup, SWT.CHECK);
        opera.setText("Opera");

        Image operaIcon= getBrowserIcon("browser-opera-icon.png");
        if(null!=operaIcon)
            opera.setImage(operaIcon);

        comboDropDown = new Combo(fGroup, SWT.DROP_DOWN | SWT.BORDER);
        comboDropDown.setText("Version");

        android= new Button(fGroup, SWT.CHECK);
        android.setText("Android");

        Image androidIcon= getBrowserIcon("android-platform-icon.png");
        if(null!=androidIcon)
            android.setImage(androidIcon);

        comboDropDown = new Combo(fGroup, SWT.DROP_DOWN | SWT.BORDER);
        comboDropDown.setText("Version");

        ios= new Button(fGroup, SWT.CHECK);
        ios.setText("Mobile Safari");

        Image iosIcon= getBrowserIcon("Apple-grey-icon.png");
        if(null!=iosIcon)
            ios.setImage(iosIcon);

        comboDropDown = new Combo(fGroup, SWT.DROP_DOWN | SWT.BORDER);
        comboDropDown.setText("Version");



    }

    @Override
    public String getName() {
        return "Browsers";
    }

    public Image getBrowserIcon(String name){
        Image icon=null;
        try {
            icon = AbstractUIPlugin.imageDescriptorFromPlugin("SuitACore","icons/"+name).createImage();

        } catch (Exception e) {
            // Swallow it; we'll do without images
        }
        return icon;
    }

    public Image getImage() {
        Image tab=null;
        try {
            tab = AbstractUIPlugin.imageDescriptorFromPlugin("SuitACore","icons/browser.png").createImage();

        } catch (Exception e) {
            // Swallow it; we'll do without images
        }
        return tab;
    }


    public void initializeFrom(ILaunchConfiguration configuration) {
        try {
            List<String> browsersDefaults = new ArrayList<String>();
            browsersDefaults.add("chrome");
            List<String> browsers =configuration.getAttribute("browsers", browsersDefaults);
        } catch (CoreException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        chrome.setSelection(true);
    }


    public void performApply(ILaunchConfigurationWorkingCopy configuration) {
        List<String> browsers = new ArrayList<String>();
        browsers.add("chrome");
        configuration.setAttribute("browser",browsers );
    }


    public void setDefaults(ILaunchConfigurationWorkingCopy arg0) {

    }

}

推荐答案

只要有任何更改,您必须调用 updateLaunchConfigurationDialog()可能会更新应用按钮 - 所有复选框和组合。

You must call updateLaunchConfigurationDialog() whenever anything changes that might update the Apply button - so all checkboxes and combos.

您还必须将所有更改的内容保存在 ILaunchConfigurationWorkingCopy performApply 方法中。通过检查工作副本是否与原始配置不同,确定应用按钮状态。

You must also save everything that changes in the ILaunchConfigurationWorkingCopy in the performApply method. The Apply button state is determined by checking that the working copy is different from the original configuration.

这篇关于实现启动器框架 - 禁用对话框上应用按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆