gpt4 book ai didi

java - 如何避免在返回然后单击“下一步”时添加小部件?

转载 作者:行者123 更新时间:2023-12-02 08:56:12 24 4
gpt4 key购买 nike

我创建了一个向导。

它有3页-

@Override
public void addPages() {
super.addPages();
addPage(firstPage);
addPage(secondPage);
addPage(thirdPage);
}

对于第一页,我有一个简单的标签,其中有一个输入字段来收集用户输入的值-

    @Override
public void createControl(Composite parent) {
Composite page = new Composite(parent, SWT.NONE);
setControl(page);
setPageComplete(false);

// page.setLayout(new GridLayout(2, false));
GridLayout gridLayout = new GridLayout();
gridLayout.numColumns = 2;
gridLayout.makeColumnsEqualWidth = false;
page.setLayout(gridLayout);

page.setLayoutData(new GridData(GridData.FILL_BOTH));

Label label = new Label(page, SWT.NONE);
label.setText("Interface Id : ");

interfaceId = new Text(page, SWT.BORDER);
GridData interfaceIdGridData = new GridData(GridData.FILL_HORIZONTAL);
interfaceId.setLayoutData(interfaceIdGridData);



}

enter image description here

当用户单击上述向导页面上显示的“下一步”按钮时,会调用同一向导页面的 getNextPage 中的外部系统收集一些详细信息。

然后,用户登陆向导页面 2,并且在 step1 中获取的详细信息将显示在向导页面 2-

public class InterfaceDetailsPage extends WizardPage {

private Composite top;
private ScrolledComposite scrolledComposite;
private Composite page;

private Label responseCode;
private Label responseMsg;
private Label interfaceName;
private Label sourceSystem;
private Label targetSystem;
private Label domainName;
private Label serviceName;

private SelectedServerNode iServer;
private volatile boolean activityCancelled;
private CreateSkeletonResponseModel model;
private CreateSkeletonDisplayResultModel resultModel;

protected InterfaceDetailsPage(SelectedServerNode iServer) {
super("InterfaceDetailsPage");

this.iServer = iServer;
setTitle("Component Details");
setMessage("The requested Interface details are shown below : ");
}

@Override
public void createControl(Composite parent) {

top = new Composite(parent, SWT.NONE);
top.setLayout(new FillLayout());
setControl(top);
setPageComplete(false);


scrolledComposite = new ScrolledComposite(top, SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL);
scrolledComposite.setExpandHorizontal(true);
scrolledComposite.setExpandVertical(true);

page = new Composite(scrolledComposite, SWT.NONE);
//setControl(page);


GridLayout gridLayout = new GridLayout();
gridLayout.numColumns = 2;
//gridLayout.makeColumnsEqualWidth = true;
gridLayout.makeColumnsEqualWidth = false;
page.setLayout(gridLayout);
page.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));


scrolledComposite.setContent(page);
scrolledComposite.setSize(page.computeSize(SWT.DEFAULT, SWT.DEFAULT));


GridData gridData = null;

// Deals with the label response code and its value
Label responseCodeLbl = new Label(page, SWT.NONE);
//gridData = new GridData(GridData.FILL_HORIZONTAL);
//responseCodeLbl.setLayoutData(gridData);
responseCodeLbl.setText("Response Code : ");

responseCode = new Label(page, SWT.NONE);
gridData = new GridData(GridData.FILL_HORIZONTAL);
responseCode.setLayoutData(gridData);

// Deals with the label response message and its value
Label responseMsgLbl = new Label(page, SWT.NONE);
//gridData = new GridData(GridData.FILL_HORIZONTAL);
//responseMsgLbl.setLayoutData(gridData);
responseMsgLbl.setText("Response Message : ");

responseMsg = new Label(page, SWT.NONE);
gridData = new GridData(GridData.FILL_HORIZONTAL);
responseMsg.setLayoutData(gridData);



}

@Override
public void setVisible(boolean visible) {
if (visible) {

InterfacePage interfacePage = (InterfacePage) (getWizard().getPage("InterfacePage"));
ModelObject model = interfacePage.getModelObject();

GridData gridData = null;

// Deals with the label interface name and its value
Label interfaceNameLbl = new Label(page, SWT.NONE);
//gridData = new GridData(GridData.FILL_HORIZONTAL);
//interfaceNameLbl.setLayoutData(gridData);
interfaceNameLbl.setText("Interface Id : ");

interfaceName = new Label(page, SWT.NONE);
gridData = new GridData(GridData.FILL_HORIZONTAL);
interfaceName.setLayoutData(gridData);

// Deals with the label source system and its value
Label sourceSystemLbl = new Label(page, SWT.NONE);
//gridData = new GridData(GridData.FILL_HORIZONTAL);
//sourceSystemLbl.setLayoutData(gridData);
sourceSystemLbl.setText("Source System : ");

sourceSystem = new Label(page, SWT.NONE);
gridData = new GridData(GridData.FILL_HORIZONTAL);
sourceSystem.setLayoutData(gridData);

// Deals with the label target system and its value
Label targetSystemLbl = new Label(page, SWT.NONE);
//gridData = new GridData(GridData.FILL_HORIZONTAL);
//targetSystemLbl.setLayoutData(gridData);
targetSystemLbl.setText("Target System : ");

targetSystem = new Label(page, SWT.NONE);
gridData = new GridData(GridData.FILL_HORIZONTAL);
targetSystem.setLayoutData(gridData);

// Deals with the label domain name and its value
Label domainNameLbl = new Label(page, SWT.NONE);
//gridData = new GridData(GridData.FILL_HORIZONTAL);
//domainNameLbl.setLayoutData(gridData);
domainNameLbl.setText("Domain Name : ");

domainName = new Label(page, SWT.NONE);
gridData = new GridData(GridData.FILL_HORIZONTAL);
domainName.setLayoutData(gridData);

// Deals with the label service name and its value
Label serviceNameLbl = new Label(page, SWT.NONE);
//gridData = new GridData(GridData.FILL_HORIZONTAL);
//serviceNameLbl.setLayoutData(gridData);
serviceNameLbl.setText("Service Name : ");

serviceName = new Label(page, SWT.NONE);
gridData = new GridData(GridData.FILL_HORIZONTAL);
serviceName.setLayoutData(gridData);




interfaceName.setText(null != model.getInterfaceName() ? model.getInterfaceName() : "");
// setTitle(model.getInterfaceID1() +" details");

sourceSystem.setText(null != model.getSourceSystem() ? model.getSourceSystem() : "");
targetSystem.setText(null != model.getTargetSystem() ? model.getTargetSystem() : "");
domainName.setText(null != model.getDomainName() ? model.getDomainName() : "");
serviceName.setText(null != model.getServiceName() ? model.getServiceName() : "");

responseCode.setText(String.valueOf(model.getResponseCode()));
responseMsg.setText(null != model.getResponseMessage() ? model.getResponseMessage() : "");

page.layout();
scrolledComposite.layout(true, true);
scrolledComposite.setMinSize(page.computeSize(SWT.DEFAULT, SWT.DEFAULT));
top.layout();
setPageComplete(true);


}
super.setVisible(visible);
} ...

enter image description here

正如所见,显示的最后 5 个标签是在 setVisible 方法内生成的

如果现在我通过按后退按钮返回,然后单击下一步,我会看到新标签添加在前几行下方,因此显示两次。我怎样才能防止这种行为?

enter image description here

最佳答案

setVisible中创建控件是错误的。您应该只在页面的 createControl 方法中创建控件。

setVisible 方法只能在由 createControls 创建的控件中设置值

如果某些控件并不总是显示,请在 createControls 中创建它们并调用 setVisible(false) 以不显示它们。

如果要显示的变量值很多,请使用Table或TableViewer并在setVisible中设置内容。

最后,如果您确实需要,您可以在 setVisible 中创建内容,但您必须记住您已经完成了此操作,并且在第二次调用 setVisible 时不要再次执行此操作。

关于java - 如何避免在返回然后单击“下一步”时添加小部件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60478239/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com