Search in sources :

Example 1 with ProjectManager

use of de.catma.project.ProjectManager in project catma by forTEXT.

the class ProjectCard method initComponents.

protected void initComponents() {
    addStyleName("projectlist__card");
    CssLayout preview = new CssLayout();
    preview.addStyleName("projectlist__card__preview");
    descriptionLabel = new Label(projectReference.getDescription());
    descriptionLabel.setWidth("100%");
    preview.addComponents(descriptionLabel);
    preview.addLayoutClickListener(evt -> handleOpenProjectRequest());
    addComponent(preview);
    HorizontalFlexLayout descriptionBar = new HorizontalFlexLayout();
    descriptionBar.addStyleName("projectlist__card__descriptionbar");
    descriptionBar.setAlignItems(FlexLayout.AlignItems.BASELINE);
    descriptionBar.setWidth("100%");
    nameLabel = new Label(projectReference.getName());
    nameLabel.setWidth("100%");
    descriptionBar.addComponent(nameLabel);
    IconButton btnRemove = new IconButton(VaadinIcons.TRASH);
    descriptionBar.addComponents(btnRemove);
    btnRemove.addClickListener((event -> {
        ConfirmDialog.show(UI.getCurrent(), "Delete Project", "Do you want to delete the whole Project '" + projectReference.getName() + "'?", "OK", "Cancel", (evt) -> {
            try {
                if (evt.isConfirmed()) {
                    projectManager.delete(projectReference.getProjectId());
                    eventBus.post(new ProjectChangedEvent(projectReference.getProjectId()));
                }
            } catch (Exception e) {
                errorLogger.showAndLogError("can't delete Project " + projectReference.getName(), e);
            }
        });
    }));
    IconButton btnEdit = new IconButton(VaadinIcons.PENCIL);
    btnEdit.addClickListener(click -> {
        new EditProjectDialog(projectReference, projectManager, result -> {
            try {
                projectManager.updateProject(result);
                descriptionLabel.setValue(result.getDescription());
                nameLabel.setValue(result.getName());
            } catch (IOException e) {
                errorLogger.showAndLogError("Failed to update Project", e);
                eventBus.post(new ProjectChangedEvent());
            }
        }).show();
    });
    descriptionBar.addComponent(btnEdit);
    IconButton btnLeave = new IconButton(VaadinIcons.EXIT);
    btnLeave.addClickListener((event -> {
        ConfirmDialog.show(UI.getCurrent(), "Leave Project", "Do you want to leave '" + projectReference.getName() + "'?", "OK", "Cancel", (evt) -> {
            try {
                if (evt.isConfirmed()) {
                    projectManager.leaveProject(projectReference.getProjectId());
                }
            } catch (Exception e) {
                errorLogger.showAndLogError("can't leave project " + projectReference.getName(), e);
            }
            eventBus.post(new ProjectChangedEvent());
        });
    }));
    descriptionBar.addComponent(btnLeave);
    rbacEnforcer.register(RBACConstraint.ifNotAuthorized((role) -> (rbacManager.hasPermission(role, RBACPermission.PROJECT_EDIT)), () -> {
        btnEdit.setVisible(false);
        btnEdit.setEnabled(false);
    }));
    rbacEnforcer.register(RBACConstraint.ifNotAuthorized((role) -> (rbacManager.hasPermission(role, RBACPermission.PROJECT_DELETE)), () -> {
        btnRemove.setVisible(false);
        btnRemove.setEnabled(false);
    }));
    rbacEnforcer.register(RBACConstraint.ifNotAuthorized((role) -> rbacManager.hasPermission(role, RBACPermission.PROJECT_LEAVE) && !rbacManager.hasPermission(role, RBACPermission.PROJECT_DELETE), () -> {
        btnLeave.setVisible(false);
        btnLeave.setEnabled(false);
    }));
    // IconButton buttonAction = new IconButton(VaadinIcons.ELLIPSIS_DOTS_V);
    // descriptionBar.addComponents(buttonAction);
    addComponents(descriptionBar);
}
Also used : FlexLayout(de.catma.ui.layout.FlexLayout) ProjectManager(de.catma.project.ProjectManager) RouteToProjectEvent(de.catma.ui.events.routing.RouteToProjectEvent) UI(com.vaadin.ui.UI) VerticalFlexLayout(de.catma.ui.layout.VerticalFlexLayout) RBACConstraint(de.catma.rbac.RBACConstraint) IOException(java.io.IOException) ConfirmDialog(org.vaadin.dialogs.ConfirmDialog) CssLayout(com.vaadin.ui.CssLayout) RBACRole(de.catma.rbac.RBACRole) ProjectReference(de.catma.project.ProjectReference) Objects(java.util.Objects) EventBus(com.google.common.eventbus.EventBus) HorizontalFlexLayout(de.catma.ui.layout.HorizontalFlexLayout) ErrorHandler(de.catma.ui.module.main.ErrorHandler) Label(com.vaadin.ui.Label) IRBACManager(de.catma.rbac.IRBACManager) RBACConstraintEnforcer(de.catma.rbac.RBACConstraintEnforcer) VaadinIcons(com.vaadin.icons.VaadinIcons) IconButton(de.catma.ui.component.IconButton) RBACPermission(de.catma.rbac.RBACPermission) ProjectChangedEvent(de.catma.ui.events.ProjectChangedEvent) CssLayout(com.vaadin.ui.CssLayout) IconButton(de.catma.ui.component.IconButton) Label(com.vaadin.ui.Label) IOException(java.io.IOException) HorizontalFlexLayout(de.catma.ui.layout.HorizontalFlexLayout) IOException(java.io.IOException) ProjectChangedEvent(de.catma.ui.events.ProjectChangedEvent)

Example 2 with ProjectManager

use of de.catma.project.ProjectManager in project catma by forTEXT.

the class CreateProjectCard method initComponents.

private void initComponents() {
    addStyleName("projectlist__newproject");
    CssLayout newproject = new CssLayout();
    newproject.addStyleName("projectlist__newproject__link");
    Label labelDesc = new Label("create new project");
    labelDesc.setWidth("100%");
    newproject.addComponents(labelDesc);
    newproject.addLayoutClickListener(evt -> {
        new CreateProjectDialog(projectManager, result -> eventBus.post(new ProjectChangedEvent())).show();
    });
    addComponent(newproject);
    HorizontalFlexLayout descriptionBar = new HorizontalFlexLayout();
    descriptionBar.addStyleName("projectlist__card__descriptionbar");
    descriptionBar.setAlignItems(FlexLayout.AlignItems.BASELINE);
    descriptionBar.setWidth("100%");
    addComponents(descriptionBar);
}
Also used : Objects(java.util.Objects) EventBus(com.google.common.eventbus.EventBus) FlexLayout(de.catma.ui.layout.FlexLayout) ProjectManager(de.catma.project.ProjectManager) HorizontalFlexLayout(de.catma.ui.layout.HorizontalFlexLayout) Label(com.vaadin.ui.Label) VerticalFlexLayout(de.catma.ui.layout.VerticalFlexLayout) CssLayout(com.vaadin.ui.CssLayout) ProjectChangedEvent(de.catma.ui.events.ProjectChangedEvent) CssLayout(com.vaadin.ui.CssLayout) Label(com.vaadin.ui.Label) HorizontalFlexLayout(de.catma.ui.layout.HorizontalFlexLayout) ProjectChangedEvent(de.catma.ui.events.ProjectChangedEvent)

Aggregations

EventBus (com.google.common.eventbus.EventBus)2 CssLayout (com.vaadin.ui.CssLayout)2 Label (com.vaadin.ui.Label)2 ProjectManager (de.catma.project.ProjectManager)2 ProjectChangedEvent (de.catma.ui.events.ProjectChangedEvent)2 FlexLayout (de.catma.ui.layout.FlexLayout)2 HorizontalFlexLayout (de.catma.ui.layout.HorizontalFlexLayout)2 VerticalFlexLayout (de.catma.ui.layout.VerticalFlexLayout)2 Objects (java.util.Objects)2 VaadinIcons (com.vaadin.icons.VaadinIcons)1 UI (com.vaadin.ui.UI)1 ProjectReference (de.catma.project.ProjectReference)1 IRBACManager (de.catma.rbac.IRBACManager)1 RBACConstraint (de.catma.rbac.RBACConstraint)1 RBACConstraintEnforcer (de.catma.rbac.RBACConstraintEnforcer)1 RBACPermission (de.catma.rbac.RBACPermission)1 RBACRole (de.catma.rbac.RBACRole)1 IconButton (de.catma.ui.component.IconButton)1 RouteToProjectEvent (de.catma.ui.events.routing.RouteToProjectEvent)1 ErrorHandler (de.catma.ui.module.main.ErrorHandler)1