use of io.jmix.ui.action.list.EditAction in project jmix by jmix-framework.
the class MasterDetailScreen method initBrowseEditAction.
/**
* Adds an EditAction that enables controls for editing.
*/
protected void initBrowseEditAction() {
ListComponent<T> table = getTable();
EditAction editAction = (EditAction) table.getActionNN("edit");
editAction.withHandler(actionPerformedEvent -> {
T item = table.getSingleSelected();
if (item != null) {
if (lockIfNeeded(item)) {
refreshOptionsForLookupFields();
enableEditControls(false);
}
}
});
MetaClass entityMetaClass = getApplicationContext().getBean(Metadata.class).getClass(getEntityClass());
UiEntityContext entityContext = new UiEntityContext(entityMetaClass);
getApplicationContext().getBean(AccessManager.class).applyRegisteredConstraints(entityContext);
editAction.addEnabledRule(() -> table.getSelected().size() == 1 && entityContext.isEditPermitted());
}
use of io.jmix.ui.action.list.EditAction in project jmix by jmix-framework.
the class EntityInspectorBrowser method createEditAction.
private EditAction createEditAction(Table table) {
EditAction editAction = actions.create(EditAction.class);
editAction.setOpenMode(OpenMode.THIS_TAB);
editAction.setTarget(table);
editAction.setScreenClass(EntityInspectorEditor.class);
editAction.setShortcut(componentProperties.getTableInsertShortcut());
return editAction;
}
use of io.jmix.ui.action.list.EditAction in project jmix by jmix-framework.
the class EntityInspectorBrowser method createButtonsPanel.
protected void createButtonsPanel(Table table) {
ButtonsPanel buttonsPanel = table.getButtonsPanel();
Button createButton = uiComponents.create(Button.class);
CreateAction createAction = createCreateAction(table);
table.addAction(createAction);
createButton.setAction(createAction);
createButton.setIcon(icons.get(JmixIcon.CREATE_ACTION));
Button editButton = uiComponents.create(Button.class);
EditAction editAction = createEditAction(table);
table.addAction(editAction);
editButton.setAction(editAction);
editButton.setIcon(icons.get(JmixIcon.EDIT_ACTION));
Button removeButton = uiComponents.create(Button.class);
RemoveAction removeAction = createRemoveAction(table);
if (metadataTools.isSoftDeletable(selectedMeta.getJavaClass()) && ShowMode.ALL.equals(showMode.getValue())) {
removeAction.setAfterActionPerformedHandler(removedItems -> entitiesDl.load());
}
table.addAction(removeAction);
removeButton.setAction(removeAction);
removeButton.setIcon(icons.get(JmixIcon.REMOVE_ACTION));
removeButton.setFrame(getWindow().getFrame());
Button excelButton = uiComponents.create(Button.class);
ExcelExportAction excelExportAction = createExcelExportAction(table);
excelButton.setAction(excelExportAction);
excelButton.setFrame(getWindow().getFrame());
Button refreshButton = uiComponents.create(Button.class);
RefreshAction refreshAction = createRefreshAction(table);
refreshButton.setAction(refreshAction);
refreshButton.setIcon(icons.get(JmixIcon.REFRESH_ACTION));
refreshButton.setFrame(getWindow().getFrame());
PopupButton exportPopupButton = uiComponents.create(PopupButton.class);
exportPopupButton.setCaption(messages.getMessage(EntityInspectorBrowser.class, "export"));
exportPopupButton.setIcon(icons.get(JmixIcon.DOWNLOAD));
ExportAction exportJSONAction = new ExportAction("exportJSON");
exportJSONAction.setFormat(JSON);
exportJSONAction.setTable(table);
exportJSONAction.setMetaClass(selectedMeta);
exportPopupButton.addAction(exportJSONAction);
ExportAction exportZIPAction = new ExportAction("exportZIP");
exportZIPAction.setFormat(ZIP);
exportZIPAction.setTable(table);
exportZIPAction.setMetaClass(selectedMeta);
exportPopupButton.addAction(exportZIPAction);
FileUploadField importUpload = uiComponents.create(FileUploadField.class);
importUpload.setPasteZone(tableBox);
importUpload.setPermittedExtensions(Sets.newHashSet(".json", ".zip"));
importUpload.setUploadButtonIcon(icons.get(JmixIcon.UPLOAD));
importUpload.setUploadButtonCaption(messages.getMessage(EntityInspectorBrowser.class, "import"));
importUpload.addFileUploadSucceedListener(event -> {
byte[] fileBytes = importUpload.getValue();
String fileName = event.getFileName();
try {
Collection<Object> importedEntities;
if (JSON.getFileExt().equals(Files.getFileExtension(fileName))) {
String content = new String(fileBytes, StandardCharsets.UTF_8);
importedEntities = entityImportExport.importEntitiesFromJson(content, createEntityImportPlan(content, selectedMeta));
} else {
importedEntities = entityImportExport.importEntitiesFromZIP(fileBytes, createEntityImportPlan(selectedMeta));
}
notifications.create(Notifications.NotificationType.HUMANIZED).withDescription(messages.formatMessage(EntityInspectorBrowser.class, "importSuccessful", importedEntities.size())).show();
} catch (Exception e) {
notifications.create(Notifications.NotificationType.ERROR).withCaption(messages.getMessage(EntityInspectorBrowser.class, "importFailed")).withDescription(messages.formatMessage(EntityInspectorBrowser.class, "importFailedMessage", fileName, nullToEmpty(e.getMessage()))).show();
log.error("Entities import error", e);
}
entitiesDl.load();
});
Button restoreButton = uiComponents.create(Button.class);
Action restoreAction = createRestoreAction(table);
table.addAction(restoreAction);
restoreButton.setAction(restoreAction);
Action showEntityInfoAction = createShowEntityInfoAction(table);
table.addAction(showEntityInfoAction);
Button wipeOutButton = null;
if (metadataTools.isSoftDeletable(selectedMeta.getJavaClass())) {
wipeOutButton = uiComponents.create(Button.class);
Action wipeOutAction = createWipeOutAction(table);
table.addAction(wipeOutAction);
wipeOutButton.setAction(wipeOutAction);
}
buttonsPanel.add(createButton);
buttonsPanel.add(editButton);
buttonsPanel.add(removeButton);
buttonsPanel.add(refreshButton);
buttonsPanel.add(excelButton);
buttonsPanel.add(exportPopupButton);
buttonsPanel.add(importUpload);
buttonsPanel.add(restoreButton);
if (wipeOutButton != null) {
buttonsPanel.add(wipeOutButton);
}
}
Aggregations