Search in sources :

Example 1 with RemoveAction

use of io.jmix.ui.action.list.RemoveAction in project jmix by jmix-framework.

the class EntityInspectorBrowser method addSelectionListener.

private void addSelectionListener() {
    entitiesTable.addSelectionListener(event -> {
        Table.SelectionEvent selectionEvent = (Table.SelectionEvent) event;
        boolean removeEnabled = true;
        boolean restoreEnabled = true;
        if (!selectionEvent.getSelected().isEmpty()) {
            for (Object o : selectionEvent.getSelected()) {
                if (o instanceof Entity) {
                    if (EntityValues.isSoftDeleted(o)) {
                        removeEnabled = false;
                    } else {
                        restoreEnabled = false;
                    }
                    if (!removeEnabled && !restoreEnabled) {
                        break;
                    }
                }
            }
        }
        Action removeAction = entitiesTable.getAction(RemoveAction.ID);
        if (removeAction != null) {
            removeAction.setEnabled(removeEnabled);
        }
        Action restoreAction = entitiesTable.getAction(RESTORE_ACTION_ID);
        if (restoreAction != null) {
            restoreAction.setEnabled(restoreEnabled);
        }
    });
}
Also used : ItemTrackingAction(io.jmix.ui.action.ItemTrackingAction) CreateAction(io.jmix.ui.action.list.CreateAction) EditAction(io.jmix.ui.action.list.EditAction) Action(io.jmix.ui.action.Action) DialogAction(io.jmix.ui.action.DialogAction) RefreshAction(io.jmix.ui.action.list.RefreshAction) ListAction(io.jmix.ui.action.ListAction) ShowEntityInfoAction(io.jmix.datatoolsui.action.ShowEntityInfoAction) ExcelExportAction(io.jmix.uiexport.action.ExcelExportAction) RemoveAction(io.jmix.ui.action.list.RemoveAction)

Example 2 with RemoveAction

use of io.jmix.ui.action.list.RemoveAction in project jmix by jmix-framework.

the class EntityInspectorBrowser method createRemoveAction.

private RemoveAction createRemoveAction(Table table) {
    RemoveAction removeAction = actions.create(RemoveAction.class);
    removeAction.setTarget(table);
    return removeAction;
}
Also used : RemoveAction(io.jmix.ui.action.list.RemoveAction)

Example 3 with RemoveAction

use of io.jmix.ui.action.list.RemoveAction 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);
    }
}
Also used : ItemTrackingAction(io.jmix.ui.action.ItemTrackingAction) CreateAction(io.jmix.ui.action.list.CreateAction) EditAction(io.jmix.ui.action.list.EditAction) Action(io.jmix.ui.action.Action) DialogAction(io.jmix.ui.action.DialogAction) RefreshAction(io.jmix.ui.action.list.RefreshAction) ListAction(io.jmix.ui.action.ListAction) ShowEntityInfoAction(io.jmix.datatoolsui.action.ShowEntityInfoAction) ExcelExportAction(io.jmix.uiexport.action.ExcelExportAction) RemoveAction(io.jmix.ui.action.list.RemoveAction) EditAction(io.jmix.ui.action.list.EditAction) RefreshAction(io.jmix.ui.action.list.RefreshAction) ExcelExportAction(io.jmix.uiexport.action.ExcelExportAction) ExcelExportAction(io.jmix.uiexport.action.ExcelExportAction) CreateAction(io.jmix.ui.action.list.CreateAction) RemoveAction(io.jmix.ui.action.list.RemoveAction)

Aggregations

RemoveAction (io.jmix.ui.action.list.RemoveAction)3 ShowEntityInfoAction (io.jmix.datatoolsui.action.ShowEntityInfoAction)2 Action (io.jmix.ui.action.Action)2 DialogAction (io.jmix.ui.action.DialogAction)2 ItemTrackingAction (io.jmix.ui.action.ItemTrackingAction)2 ListAction (io.jmix.ui.action.ListAction)2 CreateAction (io.jmix.ui.action.list.CreateAction)2 EditAction (io.jmix.ui.action.list.EditAction)2 RefreshAction (io.jmix.ui.action.list.RefreshAction)2 ExcelExportAction (io.jmix.uiexport.action.ExcelExportAction)2