实现Launcher Framework - 禁用对话框上的Apply按钮

时间:2015-03-08 15:24:51

标签: eclipse-plugin eclipse-rcp

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

我已经实现了一个类BrowsersTab,它扩展了AbstractLaunchConfigurationTab并实现了所有方法。问题是当我调用updateLaunchConfigurationDialog()时;在选择活动中,“应用”#39;按钮保持禁用状态

代码:

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) {

    }

}

enter image description here

1 个答案:

答案 0 :(得分:0)

每当有任何可能更新“应用”按钮的更改时,您都必须调用updateLaunchConfigurationDialog() - 所有复选框和组合。

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