public void resetState() { formPanel.setReadOnly(true); saveButton.setVisible(false); cancelButton.setVisible(false); updateButton.setVisible(true); updateButton.disable(); resetButton.setVisible(true); resetButton.disable(); if (permitedEnterprise.getCanAdd()) { addButton.enable(); } else { addButton.disable(); } if (permitedEnterprise.getCanUpdate()) { editButton.enable(); } else { editButton.disable(); } if (permitedEnterprise.getCanDelete()) { deleteButton.enable(); } else { deleteButton.disable(); } formPanel.reset(); if (grid.getSelectionModel().getSelection().size() > 0) { formBindings.bind((BeanModel) grid.getSelectionModel().getSelection().get(0)); } else { formBindings.unbind(); if (permitedEnterprise.getCanAdd()) { addButton.enable(); } else { addButton.disable(); } editButton.disable(); deleteButton.disable(); } }
@Override public ToolBar initToolBar() { SubModuleToolbar toolbar = new SubModuleToolbar(getEventBus()); final Button importUser = new Button(); importUser.setText(I18nUtils.getMessages().user_button_importUsers()); importUser.setTitle(I18nUtils.getMessages().user_button_importUsers_tip()); importUser.setIcon(AbstractImagePrototype.create(Icons.INSTANCE.user())); importUser.enable(); importUser.addListener( Events.OnClick, new Listener<BaseEvent>() { public void handleEvent(BaseEvent be) { initUserImportView(); } }); toolbar.add(importUser); return toolbar; }
@Override protected void onRender(Element parent, int index) { super.onRender(parent, index); setLayout(new FitLayout()); containerSizeStore = getContainerSizeStore(); ironChestStore = getIronChestStore(); bracketStore = getBracketStore(); ContentPanel content = new ContentPanel(); content.setHeaderVisible(false); content.setBodyBorder(false); content.setLayout(new RowLayout(Orientation.VERTICAL)); LayoutContainer frame1 = new LayoutContainer(); frame1.setStyleAttribute("padding", "10px"); frame1.setStyleAttribute("backgroundColor", "#dfe8f6"); frame1.setLayout(new BorderLayout()); grid = createGrid(); grid.getSelectionModel() .addListener( Events.SelectionChange, new Listener<SelectionChangedEvent<BeanModel>>() { public void handleEvent(SelectionChangedEvent<BeanModel> be) { store.rejectChanges(); resetState(); } }); formPanel = createForm(); BorderLayoutData westData = new BorderLayoutData(LayoutRegion.WEST, 305); BorderLayoutData centerData = new BorderLayoutData(LayoutRegion.CENTER); frame1.add(grid, westData); frame1.add(formPanel, centerData); content.add(frame1); LayoutContainer frame2 = new LayoutContainer(); frame2.setStyleAttribute("backgroundColor", "#dfe8f6"); frame2.setLayout(new RowLayout(Orientation.HORIZONTAL)); RowData data1 = new RowData(.45, 1); data1.setMargins(new Margins(10)); RowData data2 = new RowData(.55, 1); data2.setMargins(new Margins(10)); frame2.add(createTypeGrid(), data1); frame2.add(createBracketGrid(), data2); RowData data = new RowData(1, 0.5); content.add(frame1, data); content.add(frame2, data); // 添加工具栏 ToolBar toolBar = new ToolBar(); addButton = new Button("添加", Resources.ICONS.add()); addButton.addSelectionListener( new SelectionListener<ButtonEvent>() { @Override public void componentSelected(ButtonEvent ce) { beanModel = beanModelFactory.createModel(new Container()); formPanel.reset(); formBindings.bind(beanModel); formBindings.addListener( Events.Bind, new Listener<BindingEvent>() { @Override public void handleEvent(BindingEvent be) { formBindings .getModel() .set("customsDeclarationHeadId", selectedCustomsDeclarationHead.getId()); for (Field<?> field : formPanel.getFields()) { field.clearInvalid(); } formBindings.removeAllListeners(); } }); formPanel.setReadOnly(false); formPanel.getFields().get(0).focus(); saveButton.setVisible(true); cancelButton.setVisible(true); updateButton.setVisible(false); resetButton.setVisible(false); addButton.disable(); } }); toolBar.add(addButton); toolBar.add(new SeparatorToolItem()); editButton = new Button("修改", Resources.ICONS.edit()); editButton.addSelectionListener( new SelectionListener<ButtonEvent>() { @Override public void componentSelected(ButtonEvent ce) { if (grid.getSelectionModel().getSelection().size() > 0) { formBindings.bind((BeanModel) grid.getSelectionModel().getSelection().get(0)); formPanel.setReadOnly(false); updateButton.enable(); resetButton.enable(); editButton.disable(); } else { formBindings.unbind(); } } }); toolBar.add(editButton); toolBar.add(new SeparatorToolItem()); deleteButton = new Button("删除", Resources.ICONS.delete()); toolBar.add(deleteButton); deleteButton.addSelectionListener( new SelectionListener<ButtonEvent>() { @Override public void componentSelected(ButtonEvent ce) { MessageBox.confirm( "确认", "确定要删除选中的条目吗?", new Listener<MessageBoxEvent>() { @Override public void handleEvent(MessageBoxEvent be) { if (be.getButtonClicked().getText() == GXT.MESSAGES.messageBox_yes()) { delete(); } } }); } }); if (permitedEnterprise != null) { if (permitedEnterprise.getCanAdd()) { addButton.enable(); } else { addButton.disable(); } if (permitedEnterprise.getCanUpdate()) { editButton.enable(); } else { editButton.disable(); } if (permitedEnterprise.getCanDelete()) { deleteButton.enable(); } else { deleteButton.disable(); } } content.setTopComponent(toolBar); add(content); }