我正在尝试实现具有三个不同页面的导入向导, 我如何确保仅在单击下一个按钮时才能验证代码。
一旦输入了详细信息并按下了“下一步”按钮,便会执行一系列操作
我一直在使用
public IWizardPage getNextPage(IWizardPage page) {
转到下一页,但是使用此按钮,我可以看到多次调用到下一页。
要实施验证,即禁用“下一步”按钮,直到用户输入所有必要的详细信息,然后禁用“下一步”。当他们进入验证时,调用getNextPage(IWizardPage page)方法会不断引发错误对话。
如何确保仅在单击按钮时调用nextPage。
代码段:
检查验证的代码:如果是,则启用下一个按钮。
textIFServiceURL.addKeyListener(new KeyListener() {
@Override
public void keyPressed(KeyEvent e) {
}
@Override
public void keyReleased(KeyEvent e) {
keyReleasedImpl();
}
});
textIFServiceURL.addModifyListener(new ModifyListener() {
@Override
public void modifyText(ModifyEvent arg0) {
modifyTextImpl();
}
});
txtUserName.addKeyListener(new KeyListener() {
@Override
public void keyPressed(KeyEvent e) {
}
@Override
public void keyReleased(KeyEvent e) {
keyReleasedImpl();
}
});
txtUserName.addModifyListener(new ModifyListener() {
@Override
public void modifyText(ModifyEvent arg0) {
modifyTextImpl();
}
});
txtPassword.addKeyListener(new KeyListener() {
@Override
public void keyPressed(KeyEvent e) {
}
@Override
public void keyReleased(KeyEvent e) {
keyReleasedImpl();
}
});
txtPassword.addModifyListener(new ModifyListener() {
@Override
public void modifyText(ModifyEvent arg0) {
modifyTextImpl();
}
});
}
private void modifyTextImpl() {
// TODO Auto-generated method stub
if ((txtUserName.getText().isEmpty() || textIFServiceURL.getText().isEmpty() || txtPassword.getText().isEmpty())) {
consumerImportWizardPage.setPageComplete(false);
}
}
private void keyReleasedImpl() {
// TODO Auto-generated method stub
if (!(txtUserName.getText().isEmpty() || textIFServiceURL.getText().isEmpty() || txtPassword.getText().isEmpty())) {
consumerImportWizardPage.setPageComplete(true);
}
}
更新后的答案:
<?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>
导入向导
package com.myplugin.importWizards;
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 IWizardPage getNextPage(IWizardPage page) {
// TODO Auto-generated method stub
System.out.println("WE are in get NextPage");
return super.getNextPage(page);
}
@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;
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);
setPageComplete(false);
}
private void setPropertiesView(Composite twsPropertiesGroup) {
twsPropertiesView = new ImportPropertiesView(twsPropertiesGroup,this);
}
@Override
public void setPageComplete(boolean complete) {
// TODO Auto-generated method stub
super.setPageComplete(complete);
}
@Override
public void setVisible(final boolean visible)
{
if (visible)
{
System.out.println("Cool we are in the ");
}
super.setVisible(visible);
}
}
ImportPropertiesView
package com.myplugin.importWizards;
public class ImportPropertiesView {
private Link configureWorkspaceSettingsLink;
private Button projectSpecificSettingsButton;
private ServerDetailsImportView serverDetailsView;
private ConsumerImportWizardPage consumerImportWizardPage;
public ImportPropertiesView(Composite parent,ConsumerImportWizardPage consumerImportWizardPage) {
this.consumerImportWizardPage=consumerImportWizardPage;
parent.setLayout(new GridLayout(2, false));
addServerDetailsView(parent);
}
private void addServerDetailsView(Composite parent) {
serverDetailsView = new ServerDetailsImportView(parent,consumerImportWizardPage);
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();
}
public boolean getPageCompleteStatus() {
return serverDetailsView.getPageCompleteStatus();
}
/**
* 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
package com.myplugin.importWizards;
public class ServerDetailsImportView {
private final Label lblUserName;
private final Text txtUserName;
private final Label lblPassword;
private final Text txtPassword;
private final Group userCredentials;
private boolean pageCompleteStatus=false;
/** 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;
private ConsumerImportWizardPage consumerImportWizardPage;
public ServerDetailsImportView(Composite parent, ConsumerImportWizardPage consumerImportWizardPage) {
// connection choice group creation
this.consumerImportWizardPage=consumerImportWizardPage;
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);
textIFServiceURL.addKeyListener(new KeyListener() {
@Override
public void keyPressed(KeyEvent e) {
}
@Override
public void keyReleased(KeyEvent e) {
keyReleasedImpl();
}
});
textIFServiceURL.addModifyListener(new ModifyListener() {
@Override
public void modifyText(ModifyEvent arg0) {
modifyTextImpl();
}
});
txtUserName.addKeyListener(new KeyListener() {
@Override
public void keyPressed(KeyEvent e) {
}
@Override
public void keyReleased(KeyEvent e) {
keyReleasedImpl();
}
});
txtUserName.addModifyListener(new ModifyListener() {
@Override
public void modifyText(ModifyEvent arg0) {
modifyTextImpl();
}
});
txtPassword.addKeyListener(new KeyListener() {
@Override
public void keyPressed(KeyEvent e) {
}
@Override
public void keyReleased(KeyEvent e) {
keyReleasedImpl();
}
});
txtPassword.addModifyListener(new ModifyListener() {
@Override
public void modifyText(ModifyEvent arg0) {
modifyTextImpl();
}
});
}
private void modifyTextImpl() {
// TODO Auto-generated method stub
if ((txtUserName.getText().isEmpty() || textIFServiceURL.getText().isEmpty() || txtPassword.getText().isEmpty())) {
consumerImportWizardPage.setPageComplete(false);
}
}
private void keyReleasedImpl() {
// TODO Auto-generated method stub
if (!(txtUserName.getText().isEmpty() || textIFServiceURL.getText().isEmpty() || txtPassword.getText().isEmpty())) {
consumerImportWizardPage.setPageComplete(true);
}
}
/**
* get the entered value from {@link #textIFServiceURL}
*
* @return
*/
public String getComponentServiceURL() {
return textIFServiceURL.getText();
}
public String getPassword() {
return txtPassword.getText();
}
public boolean getPageCompleteStatus() {
return this.pageCompleteStatus;
}
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);
}
}
答案 0 :(得分:0)
通常,getNextPage
仅应返回下一页,因为在调用updateButtons
时向导setPageComplete
方法可能会多次调用下一页。
您可以通过覆盖向导页面的canFlipToNextPage
方法来停止发生的多个呼叫:
@Override
public boolean canFlipToNextPage()
{
// Default calls getNextPage(), just checking page complete is enough here
return isPageComplete();
}