Implementing a Launcher Framework - disabled Apply button on dialog

早过忘川 提交于 2020-01-17 08:16:10

问题


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 .

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.

Code :

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

    }

}


回答1:


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

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.



来源:https://stackoverflow.com/questions/28928146/implementing-a-launcher-framework-disabled-apply-button-on-dialog

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!