Search in sources :

Example 21 with BaseAction

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

the class NotificationFacetImpl method subscribeOnAction.

protected void subscribeOnAction(Frame owner) {
    Action action = ComponentsHelper.findAction(owner, actionId);
    if (!(action instanceof BaseAction)) {
        throw new GuiDevelopmentException(String.format("Unable to find Notification target action with id '%s'", actionId), owner.getId());
    }
    ((BaseAction) action).addActionPerformedListener(e -> show());
}
Also used : Action(io.jmix.ui.action.Action) BaseAction(io.jmix.ui.action.BaseAction) GuiDevelopmentException(io.jmix.ui.GuiDevelopmentException) BaseAction(io.jmix.ui.action.BaseAction)

Example 22 with BaseAction

use of io.jmix.ui.action.BaseAction in project jmix-docs by Haulmont.

the class TableScreen method onInit.

// end::inject-tableClick[]
// tag::onInit-start[]
@Subscribe
public void onInit(InitEvent event) {
    // end::onInit-start[]
    customersTable.addGeneratedColumn("aaa", entity -> null);
    // tag::add-base-action[]
    customersTable.addAction(new AboutSingleAction());
    // end::add-base-action[]
    // tag::add-ItemTrackingAction[]
    customersTable.addAction(new ItemTrackingAction("about") {

        @Nullable
        @Override
        public String getCaption() {
            return "About";
        }

        @Override
        public void actionPerform(Component component) {
            notifications.create().withCaption("Hello " + customersTable.getSelected().iterator().next()).withType(Notifications.NotificationType.TRAY).show();
        }
    });
    // end::add-ItemTrackingAction[]
    // tag::table-set-style-name[]
    tableBorderless.setStyleName(ThemeClassNames.TABLE_BORDERLESS);
    // end::table-set-style-name[]
    // tag::column-value-provider[]
    printableTableExcelExport.addColumnValueProvider("firstName", context -> {
        // <1>
        Customer customer = context.getEntity();
        return "Name: " + customer.getFirstName();
    });
    // end::column-value-provider[]
    printableTableExcelExport.addColumnValueProvider("fullName", context -> {
        Customer customer = context.getEntity();
        return customer.getFirstName() + " " + customer.getLastName();
    });
    // tag::table-add-printable[]
    /*printableTable.addPrintable("firstName", new Table.Printable<Customer, String>() {
            @Override
            public String getValue(Customer item) {
                return "Name: " + item.getFirstName();
            }
        });*/
    // end::table-add-printable[]
    // tag::printable-column-generator[]
    /*printableTable.addGeneratedColumn("fullName", new Table.PrintableColumnGenerator<Customer, String>() {
            @Override
            public String getValue(Customer item) {
                return item.getFirstName() + " " + item.getLastName();
            }

            @Override
            public Component generateCell(Customer entity) {
                Label label = uiComponents.create(Label.NAME);
                label.setValue(entity.getFirstName() + " " + entity.getLastName());
                return label;
            }
        });*/
    // end::printable-column-generator[]
    // tag::item-click-action[]
    tableClick.setItemClickAction(new BaseAction("itemClickAction").withHandler(actionPerformedEvent -> {
        Customer customer = tableClick.getSingleSelected();
        if (customer != null) {
            notifications.create().withCaption("Item clicked for: " + customer.getFirstName() + "" + customer.getLastName()).show();
        }
    }));
    // end::item-click-action[]
    // tag::enter-press-action[]
    tableClick.setEnterPressAction(new BaseAction("enterPressAction").withHandler(actionPerformedEvent -> {
        Customer customer = tableClick.getSingleSelected();
        if (customer != null) {
            notifications.create().withCaption("Enter pressed for: " + customer.getFirstName() + "" + customer.getLastName()).show();
        }
    }));
    // end::enter-press-action[]
    // tag::programmatic-binding[]
    customersTable1.setItems(new ContainerTableItems<>(customersDc));
// end::programmatic-binding[]
// tag::onInit-end[]
}
Also used : ItemTrackingAction(io.jmix.ui.action.ItemTrackingAction) Customer(ui.ex1.entity.Customer) ThemeClassNames(io.jmix.ui.theme.ThemeClassNames) CollectionContainer(io.jmix.ui.model.CollectionContainer) Collection(java.util.Collection) Autowired(org.springframework.beans.factory.annotation.Autowired) ExcelExportAction(io.jmix.uiexport.action.ExcelExportAction) Notifications(io.jmix.ui.Notifications) JmixIcon(io.jmix.ui.icon.JmixIcon) List(java.util.List) UiComponents(io.jmix.ui.UiComponents) io.jmix.ui.screen(io.jmix.ui.screen) ScreenBuilders(io.jmix.ui.ScreenBuilders) SendByEmailAction(ui.ex1.screen.actions.SendByEmailAction) EmailAttachment(io.jmix.email.EmailAttachment) BudgetItem(ui.ex1.entity.BudgetItem) Action(io.jmix.ui.action.Action) BaseAction(io.jmix.ui.action.BaseAction) Named(javax.inject.Named) ContainerTableItems(io.jmix.ui.component.data.table.ContainerTableItems) Collections(java.util.Collections) City(ui.ex1.entity.City) Nullable(javax.annotation.Nullable) io.jmix.ui.component(io.jmix.ui.component) Customer(ui.ex1.entity.Customer) ItemTrackingAction(io.jmix.ui.action.ItemTrackingAction) BaseAction(io.jmix.ui.action.BaseAction) Nullable(javax.annotation.Nullable)

Example 23 with BaseAction

use of io.jmix.ui.action.BaseAction in project jmix-docs by Haulmont.

the class PopupButtonScreen method onInit.

// end::event[]
@Subscribe
protected void onInit(InitEvent event) {
    // end::listener[]
    popupButton.addAction(new BaseAction("saveAsDocAction").withCaption("Save as .doc").withHandler(actionPerformedEvent -> saveAsDoc()));
    popupButton.addAction(new BaseAction("saveAsPdfAction").withCaption("Save as .pdf").withHandler(actionPerformedEvent -> saveAsPdf()));
    // tag::listener[]
    popupButton.addPopupVisibilityListener(popupVisibilityEvent -> notifications.create().withCaption("Popup visibility changed").show());
}
Also used : Subscribe(io.jmix.ui.screen.Subscribe) Status(ui.ex1.entity.Status) UiController(io.jmix.ui.screen.UiController) Autowired(org.springframework.beans.factory.annotation.Autowired) Screen(io.jmix.ui.screen.Screen) UiDescriptor(io.jmix.ui.screen.UiDescriptor) Notifications(io.jmix.ui.Notifications) ComboBox(io.jmix.ui.component.ComboBox) PopupButton(io.jmix.ui.component.PopupButton) Action(io.jmix.ui.action.Action) BaseAction(io.jmix.ui.action.BaseAction) Button(io.jmix.ui.component.Button) TextField(io.jmix.ui.component.TextField) BaseAction(io.jmix.ui.action.BaseAction) Subscribe(io.jmix.ui.screen.Subscribe)

Example 24 with BaseAction

use of io.jmix.ui.action.BaseAction in project jmix-docs by Haulmont.

the class EntityPickerScreen method onInit.

// tag::on-init-start[]
@Subscribe
public void onInit(InitEvent event) {
    // end::on-init-start[]
    // tag::addAction2[]
    entityPicker.addAction(actions.create(EntityOpenAction.class));
    // end::addAction2[]
    // tag::set-entity-lookup-action[]
    entityLookupAction.setOpenMode(OpenMode.DIALOG);
    entityLookupAction.setScreenClass(CustomerBrowse.class);
    // end::set-entity-lookup-action[]
    // tag::set-entity-open-action[]
    openAction.setOpenMode(OpenMode.DIALOG);
    openAction.setScreenClass(CustomerEdit.class);
    // end::set-entity-open-action[]
    // tag::add-custom-action[]
    customerEp.addAction(new BaseAction("showLevel").withCaption(null).withDescription(null).withIcon(JmixIcon.VIEW_ACTION.source()).withHandler(e -> {
        Customer customer = customerEp.getValue();
        if (customer != null) {
            notifications.create().withCaption(customer.getFirstName() + " " + customer.getLastName() + "'s level is " + customer.getLevel()).show();
        } else {
            notifications.create().withCaption("Choose a customer").show();
        }
    }));
    // end::add-custom-action[]
    // tag::userPicker3[]
    EntityPicker<User> userPicker = uiComponents.create(EntityPicker.of(User.class));
    userPicker.setMetaClass(metadata.getClass(User.class));
    userPicker.addAction(actions.create(EntityLookupAction.class));
    userPicker.addAction(actions.create(EntityOpenAction.class));
    userPicker.addAction(actions.create(EntityClearAction.class));
    vbox.add(userPicker);
// tag::on-init-end[]
}
Also used : Customer(ui.ex1.entity.Customer) EntityOpenAction(io.jmix.ui.action.entitypicker.EntityOpenAction) Collection(java.util.Collection) Autowired(org.springframework.beans.factory.annotation.Autowired) Metadata(io.jmix.core.Metadata) ParamsMap(io.jmix.core.common.util.ParamsMap) CustomerEdit(ui.ex1.screen.entity.customer.CustomerEdit) JmixIcon(io.jmix.ui.icon.JmixIcon) HasValue(io.jmix.ui.component.HasValue) io.jmix.ui.screen(io.jmix.ui.screen) VBoxLayout(io.jmix.ui.component.VBoxLayout) CustomerBrowse(ui.ex1.screen.entity.customer.CustomerBrowse) User(ui.ex1.entity.User) Action(io.jmix.ui.action.Action) BaseAction(io.jmix.ui.action.BaseAction) EntityClearAction(io.jmix.ui.action.entitypicker.EntityClearAction) Named(javax.inject.Named) DialogAction(io.jmix.ui.action.DialogAction) MetadataTools(io.jmix.core.MetadataTools) io.jmix.ui(io.jmix.ui) EntityLookupAction(io.jmix.ui.action.entitypicker.EntityLookupAction) EntityPicker(io.jmix.ui.component.EntityPicker) User(ui.ex1.entity.User) EntityClearAction(io.jmix.ui.action.entitypicker.EntityClearAction) Customer(ui.ex1.entity.Customer) EntityLookupAction(io.jmix.ui.action.entitypicker.EntityLookupAction) BaseAction(io.jmix.ui.action.BaseAction) EntityOpenAction(io.jmix.ui.action.entitypicker.EntityOpenAction)

Example 25 with BaseAction

use of io.jmix.ui.action.BaseAction in project jmix-docs by Haulmont.

the class AttachmentBrowse method attachmentsTableFileColumnGenerator.

@Install(to = "attachmentsTable.fileName", subject = "columnGenerator")
private Component attachmentsTableFileColumnGenerator(Attachment attachment) {
    if (attachment.getFile() != null) {
        LinkButton linkButton = uiComponents.create(LinkButton.class);
        linkButton.setAction(new BaseAction("download").withCaption(attachment.getFile().getFileName()).withHandler(actionPerformedEvent -> downloader.download(attachment.getFile())));
        return linkButton;
    } else {
        return new Table.PlainTextCell("<empty>");
    }
}
Also used : HttpURLConnection(java.net.HttpURLConnection) URL(java.net.URL) Autowired(org.springframework.beans.factory.annotation.Autowired) FileStorage(io.jmix.core.FileStorage) FileRef(io.jmix.core.FileRef) StandardCopyOption(java.nio.file.StandardCopyOption) UiComponents(io.jmix.ui.UiComponents) LookupComponent(io.jmix.ui.screen.LookupComponent) URLConnection(java.net.URLConnection) BaseAction(io.jmix.ui.action.BaseAction) Qualifier(org.springframework.beans.factory.annotation.Qualifier) Path(java.nio.file.Path) RestTemplate(org.springframework.web.client.RestTemplate) Resource(org.springframework.core.io.Resource) DataManager(io.jmix.core.DataManager) Files(java.nio.file.Files) FileStorageLocator(io.jmix.core.FileStorageLocator) IOException(java.io.IOException) File(java.io.File) HttpStatus(org.springframework.http.HttpStatus) io.jmix.ui.screen(io.jmix.ui.screen) Attachment(files.ex1.entity.Attachment) Paths(java.nio.file.Paths) Downloader(io.jmix.ui.download.Downloader) ResponseEntity(org.springframework.http.ResponseEntity) io.jmix.ui.component(io.jmix.ui.component) InputStream(java.io.InputStream) BaseAction(io.jmix.ui.action.BaseAction)

Aggregations

BaseAction (io.jmix.ui.action.BaseAction)49 Action (io.jmix.ui.action.Action)30 Autowired (org.springframework.beans.factory.annotation.Autowired)12 Icons (io.jmix.ui.icon.Icons)11 io.jmix.ui.screen (io.jmix.ui.screen)9 DialogAction (io.jmix.ui.action.DialogAction)8 Window (io.jmix.ui.component.Window)8 UiScreenProperties (io.jmix.ui.UiScreenProperties)7 io.jmix.ui.component (io.jmix.ui.component)7 JmixIcon (io.jmix.ui.icon.JmixIcon)7 GuiDevelopmentException (io.jmix.ui.GuiDevelopmentException)6 Notifications (io.jmix.ui.Notifications)6 Component (io.jmix.ui.component.Component)6 Collection (java.util.Collection)6 Messages (io.jmix.core.Messages)5 UiComponents (io.jmix.ui.UiComponents)5 Nullable (javax.annotation.Nullable)5 Strings (com.google.common.base.Strings)4 Dialogs (io.jmix.ui.Dialogs)4 ItemTrackingAction (io.jmix.ui.action.ItemTrackingAction)4