e4 RCP应用程序:如何禁用与对话框的窗口交互?

时间:2018-12-06 13:12:13

标签: eclipse-rcp e4

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

enter image description here

对话框类

 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());   
            }   
        }       
    }       
}

1 个答案:

答案 0 :(得分:1)

这实际上不是传统上称为Dialog的对话框-它是在单独窗口中打开的另一部分。对于使用Application.e4xmi完成的对话框,e4确实没有很好的支持。大多数对话框是使用JFace Dialog类(org.eclipse.jface.dialogs.Dialog)完成的,不在Application.e4xmi中。

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

styleOverride 68720

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