启用下一个按钮的问题

时间:2018-08-09 09:55:59

标签: eclipse eclipse-plugin swt jface

我正在处理旧版代码,目前,它需要进行一些修改,并且需要添加一些其他页面。这里的问题是页面是在不同的类中构造的,然后将它们在WizardPage中分组为一个页面,因此,我无法启用或禁用下一个按钮。

我曾尝试使用按钮的侦听器,但无法将数据发送到向导页面。

Plugin.xml

<?xml version="1.0" encoding="UTF-8"?>
<?eclipse version="3.4"?>
<plugin>

   <extension
         point="org.eclipse.ui.importWizards">
      <category
            name="Sample File Import"
            id="com.myplugin.importWizards.sampleCategory">
      </category>
      <wizard
            name="Import File"
            icon="icons/sample.gif"
            category="com.myplugin.importWizards.sampleCategory"
            class="com.myplugin.importWizards.ImportWizard"
            id="com.myplugin.importWizards.ImportWizard">
         <description>
            Import a file from the local file system into the workspace.
         </description>
      </wizard>
   </extension>

</plugin>

importWizards.java

package com.myplugin.importWizards;

import org.eclipse.core.resources.IFile;
import org.eclipse.jface.dialogs.IDialogSettings;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.wizard.IWizardContainer;
import org.eclipse.jface.wizard.IWizardPage;
import org.eclipse.jface.wizard.Wizard;
import org.eclipse.jface.wizard.WizardPage;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.graphics.RGB;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Text;
import org.eclipse.ui.IImportWizard;
import org.eclipse.ui.IWorkbench;

public class ImportWizard extends Wizard implements IImportWizard {

    ConsumerImportWizardPage mainPage;
    PageThree three;

    public ImportWizard() {
        super();
        mainPage = new ConsumerImportWizardPage();
        three = new PageThree();
    }

    @Override
    public String getWindowTitle() {
        return "Import Integration Project";
    }

    @Override
    public void addPages() {
        addPage(mainPage);
        addPage(three);
    }




    @Override
    public void init(IWorkbench arg0, IStructuredSelection arg1) {
        // TODO Auto-generated method stub

    }

    @Override
    public boolean performFinish() {
        // TODO Auto-generated method stub
        return false;
    }


}

ConsumerImportWizardPage

package com.myplugin.importWizards;

import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.jface.wizard.IWizardPage;
import org.eclipse.jface.wizard.WizardPage;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.KeyEvent;
import org.eclipse.swt.events.KeyListener;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.DirectoryDialog;
import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.Group;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Listener;
import org.eclipse.swt.widgets.Text;


public class ConsumerImportWizardPage extends WizardPage  {

    private final static String  TITLE = "Import an existing Project";
    private ImportPropertiesView twsPropertiesView;

    public ConsumerImportWizardPage() {
        super(TITLE);
        setTitle(TITLE);

    }

    @Override
    public void createControl(Composite parent) {
        // TODO Auto-generated method stub

        Composite composite = new Composite(parent, SWT.NONE);
        GridLayout layout = new GridLayout(3, false);
        layout.horizontalSpacing = 5;
        layout.verticalSpacing = 15;
        composite.setLayout(layout);
        setControl(composite);
        setPropertiesView(composite);   


    }

     private void setPropertiesView(Composite twsPropertiesGroup) {
            twsPropertiesView = new ImportPropertiesView(twsPropertiesGroup);        
        }

     @Override
    public void setPageComplete(boolean complete) {
        // TODO Auto-generated method stub
        super.setPageComplete(complete);
    }

}

ImportPropertiesView.java

package com.myplugin.importWizards;



import org.eclipse.jface.preference.IPreferenceNode;
import org.eclipse.jface.preference.IPreferencePage;
import org.eclipse.jface.preference.PreferenceDialog;
import org.eclipse.jface.preference.PreferenceManager;
import org.eclipse.jface.preference.PreferenceNode;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.events.SelectionListener;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Link;
import org.eclipse.swt.widgets.Listener;
import org.eclipse.swt.widgets.Shell;

public class ImportPropertiesView {

    private Link configureWorkspaceSettingsLink;
    private Button projectSpecificSettingsButton;
    private ServerDetailsImportView serverDetailsView;

    public ImportPropertiesView(Composite parent) {

        parent.setLayout(new GridLayout(2, false));
        addServerDetailsView(parent);

    }

    private void addServerDetailsView(Composite parent) {
        serverDetailsView = new ServerDetailsImportView(parent);
        GridData gridData = new GridData();
        gridData.horizontalAlignment = GridData.FILL;
        gridData.grabExcessHorizontalSpace = true;
        gridData.horizontalSpan = 2;
    }


    /**
     * get the landscape url.
     *
     * @return
     */
    public String getComponentServiceURL() {
        return serverDetailsView.getComponentServiceURL();
    }



    public String getPassword() {
        return serverDetailsView.getPassword();
    }



    public String getUserName() {
        return serverDetailsView.getUserName();
    }




    /**
     * set the given landscape url to {@link ServerDetailsView}
     *
     * @param componentServiceURL
     */
    public void setComponentServiceURL(String componentServiceURL) {
        serverDetailsView.setComponentServiceURL(componentServiceURL);
    }


    public void setPassword(String password) {
        serverDetailsView.setPassword(password);
    }


    public void setUserName(String userName) {
        serverDetailsView.setUserName(userName);
    }
}

ServerDetailsImportView.java

package com.myplugin.importWizards;



import org.eclipse.swt.SWT;
import org.eclipse.swt.events.KeyEvent;
import org.eclipse.swt.events.KeyListener;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.layout.RowLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Group;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Text;

public class ServerDetailsImportView {
    private final Label lblUserName;
    private final Text txtUserName;
    private final Label lblPassword;
    private final Text txtPassword;
    private final Group userCredentials;
    /** connection choice group */

    /** web connection group */
    private final Group webConnection;
    /** landscape url text box */
    private final Text textIFServiceURL;
    /** landscape url label */
    private final Label labelIFServiceURL;

    public ServerDetailsImportView(Composite parent) {
        // connection choice group creation
        GridData gridData = new GridData();
        gridData.horizontalAlignment = GridData.FILL;
        gridData.grabExcessHorizontalSpace = true;
        gridData.horizontalSpan = 2;

        // web connection group creation
        webConnection = new Group(parent, SWT.SHADOW_IN);
        webConnection.setText("Connection Details");
        webConnection.setLayout(new GridLayout(2, false));
        webConnection.setLayoutData(gridData);

        gridData = new GridData();
        gridData.horizontalAlignment = GridData.FILL;
        gridData.grabExcessHorizontalSpace = true;

        labelIFServiceURL = new Label(webConnection, SWT.RIGHT);
        labelIFServiceURL.setText("Server IP : ");

        textIFServiceURL = new Text(webConnection, SWT.SINGLE | SWT.BORDER);
        textIFServiceURL.setLayoutData(gridData);

        gridData = new GridData();
        gridData.horizontalAlignment = GridData.FILL;
        gridData.grabExcessHorizontalSpace = true;
        gridData.horizontalSpan = 2;

        userCredentials = new Group(parent, SWT.SHADOW_IN);
        userCredentials.setText("User Credentials");
        userCredentials.setLayout(new GridLayout(2, false));
        userCredentials.setLayoutData(gridData);

        gridData = new GridData();
        gridData.horizontalAlignment = GridData.FILL;
        gridData.grabExcessHorizontalSpace = true;

        lblUserName = new Label(userCredentials, SWT.LEFT);
        lblUserName.setText("User Name:");

        txtUserName = new Text(userCredentials, SWT.SINGLE | SWT.BORDER);
        txtUserName.setLayoutData(gridData);

        lblPassword = new Label(userCredentials, SWT.LEFT);
        lblPassword.setText("Password:");

        txtPassword = new Text(userCredentials, SWT.SINGLE | SWT.BORDER | SWT.PASSWORD);
        txtPassword.setEchoChar('*');
        txtPassword.setLayoutData(gridData);       

        txtPassword.addKeyListener(new KeyListener() {

            @Override
            public void keyPressed(KeyEvent e) {
            }

            @Override
            public void keyReleased(KeyEvent e) {
                if (!txtPassword.getText().isEmpty()) {
                    //setPageComplete(true);
                }
            }
        });
    }



    /**
     * get the entered value from {@link #textIFServiceURL}
     *
     * @return
     */
    public String getComponentServiceURL() {
        return textIFServiceURL.getText();
    }

       public String getPassword() {
        return txtPassword.getText();
    }


    public String getUserName() {
        return txtUserName.getText();
    }



    /**
     * set the given value to the text box {@link #textIFServiceURL}
     *
     * @param componentServiceURL
     */
    public void setComponentServiceURL(String componentServiceURL) {
        textIFServiceURL.setText(componentServiceURL);
    }



    public void setPassword(String password) {
        txtPassword.setText(password);
    }


    public void setUserName(String userName) {
        txtUserName.setText(userName);
    }


}

PageThree .java

package com.myplugin.importWizards;


import org.eclipse.jface.wizard.WizardPage;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.KeyEvent;
import org.eclipse.swt.events.KeyListener;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Text;

public class PageThree extends WizardPage {
    private Text text1;
    private Composite container;

    public PageThree() {
        super("Third Page");
        setTitle("Third Page");
        setDescription("Fake Wizard: Third page");
    }

    @Override
    public void createControl(Composite parent) {
        container = new Composite(parent, SWT.NONE);
        GridLayout layout = new GridLayout();
        container.setLayout(layout);
        layout.numColumns = 2;
        Label label1 = new Label(container, SWT.NONE);
        label1.setText("Put a value here.");

       /* text1 = new Text(container, SWT.BORDER | SWT.SINGLE);
        text1.setText("");
        text1.addKeyListener(new KeyListener() {

            @Override
            public void keyPressed(KeyEvent e) {
            }

            @Override
            public void keyReleased(KeyEvent e) {
                if (!text1.getText().isEmpty()) {
                    setPageComplete(true);
                }
            }
        });
        GridData gd = new GridData(GridData.FILL_HORIZONTAL);
        text1.setLayoutData(gd);*/
        setControl(container);
        setPageComplete(false);
    }

    public String getText1() {
        return text1.getText();
    }
}

0 个答案:

没有答案