首页 > 解决方案 > e4 RCP 应用程序:如何禁用与对话框的窗口交互?

问题描述

我有一个带有表格的窗口,允许用户添加/编辑和删除条目。这些按钮将弹出一个对话框窗口以执行操作(使用窗口构建器编辑器制作)。但是,当对话框窗口打开时,用户仍然可以与表格进行交互,这可能会出现问题。在对话框窗口关闭之前,如何“禁用”与表格窗口的交互?

在此处输入图像描述

对话类

 public class RoleEditDialog {
        Text txtRoleName;
        Spinner spnrEksLvl;
        Spinner spnrLvl;

        @PostConstruct
        public void postConstruct(Composite parent) {
            parent.setLayout(null);

            Group group = new Group(parent, SWT.BORDER);
            group.setText("Role");
            group.setBackground(SWTResourceManager.getColor(SWT.COLOR_WIDGET_LIGHT_SHADOW));
            group.setBounds(29, 83, 236, 164);

            Label label = new Label(group, SWT.NONE);
            label.setText("Role Name");
            label.setBackground(SWTResourceManager.getColor(SWT.COLOR_WIDGET_LIGHT_SHADOW));
            label.setBounds(8, 30, 66, 14);

            txtRoleName = new Text(group, SWT.BORDER);
            txtRoleName.setBounds(74, 27, 152, 20);

            Label label_1 = new Label(group, SWT.NONE);
            label_1.setText("EKS Level");
            label_1.setBackground(SWTResourceManager.getColor(SWT.COLOR_WIDGET_LIGHT_SHADOW));
            label_1.setBounds(8, 67, 59, 14);

            spnrEksLvl = new Spinner(group, SWT.BORDER);
            spnrEksLvl.setBounds(74, 64, 152, 20);

            spnrLvl = new Spinner(group, SWT.BORDER);
            spnrLvl.setBounds(74, 101, 152, 20);

            Label label_2 = new Label(group, SWT.NONE);
            label_2.setText("Level");
            label_2.setBackground(SWTResourceManager.getColor(SWT.COLOR_WIDGET_LIGHT_SHADOW));
            label_2.setBounds(8, 104, 54, 14);

            Label label_3 = new Label(parent, SWT.NONE);
            label_3.setText("Role Administration");
            label_3.setFont(SWTResourceManager.getFont("Lucida Bright", 19, SWT.BOLD));
            label_3.setBounds(10, 10, 259, 29);

            Label label_4 = new Label(parent, SWT.NONE);
            label_4.setText("New/Update Role");
            label_4.setBounds(97, 38, 93, 15);      
        }

    }

处理程序类打开对话框

public class OpenEditRoleHandler {
    @Inject
    EModelService modelService;
    @Inject
    MApplication application;

    @Execute
    public void execute(MPart part) 
    {
        RoleController roleController = new RoleController();
        if(part!=null)
        {
            RolesFrame rolesFrame = (RolesFrame) part.getObject(); 
            int selecRow = rolesFrame.table.getSelectionIndex();
            if(selecRow!=-1)
            {
                RightController rightController = new RightController();

                //Dialog
                modelService.find("ats_usermanagement_rcp.dialog.RoleAdmin", application).setToBeRendered(true);
                //Dialog part (I have more than one part so depending on if Add/Edit was selected the appropriate part would be rendered)
                modelService.find("ats_usermanagement_rcp.part.RoleEditDialog", application).setToBeRendered(true);     

                Role selectedRole = roleController.getRole((long) Integer.parseInt(rolesFrame.table.getItem(selecRow).getText(0)));

                MPart editPart = (MPart) modelService.find("ats_usermanagement_rcp.part.RoleEditDialog", application);
                RoleEditDialog editRole = (RoleEditDialog) editPart.getObject();

                editRole.txtRoleName.setText(selectedRole.getRolename());
                editRole.spnrLvl.setSelection(selectedRole.getLevel());
                editRole.spnrEksLvl.setSelection(selectedRole.getEksLevel());   
            }   
        }       
    }       
}

标签: eclipse-rcpe4

解决方案


这并不是传统意义上的对话框——它是在单独窗口中打开的另一部分。e4 对使用 Application.e4xmi 完成的对话框并没有很好的支持。大多数对话框是使用 JFaceDialog类 ( org.eclipse.jface.dialogs.Dialog) 完成的,并且不在 Application.e4xmi 中。

您可以通过使用styleOverride(请参阅此处)指定SWT.APPLICATION_MODAL标志覆盖窗口样式来调整窗口的行为。对话框的覆盖值将是

styleOverride 68720

68720SWT.DIALOG_TRIM | SWT.APPLICATION_MODAL | SWT.MAX | SWT.RESIZE是标志的数值。


推荐阅读