Example usage for com.vaadin.server FontAwesome DROPBOX

List of usage examples for com.vaadin.server FontAwesome DROPBOX

Introduction

In this page you can find the example usage for com.vaadin.server FontAwesome DROPBOX.

Prototype

FontAwesome DROPBOX

To view the source code for com.vaadin.server FontAwesome DROPBOX.

Click Source Link

Usage

From source file:com.mycollab.module.file.view.AbstractResourceMovingWindow.java

License:Open Source License

private void constructBody() {
    MVerticalLayout contentLayout = new MVerticalLayout();
    new Restrain(contentLayout).setMaxHeight("600px");
    this.setContent(contentLayout);

    folderTree = new Tree();
    folderTree.setMultiSelect(false);/*ww w.  ja v a2  s .co  m*/
    folderTree.setSelectable(true);
    folderTree.setImmediate(true);
    folderTree.setSizeFull();

    folderTree.addExpandListener(expandEvent -> {
        final Folder expandFolder = (Folder) expandEvent.getItemId();
        // load externalResource if currentExpandFolder is rootFolder
        if (baseFolder.getPath().equals(expandFolder.getPath())) {
            List<ExternalDrive> externalDrives = externalDriveService
                    .getExternalDrivesOfUser(UserUIContext.getUsername());
            for (ExternalDrive externalDrive : externalDrives) {
                ExternalFolder externalMapFolder = new ExternalFolder("/");
                externalMapFolder.setStorageName(externalDrive.getStoragename());
                externalMapFolder.setExternalDrive(externalDrive);
                externalMapFolder.setName(externalDrive.getFoldername());

                Calendar cal = GregorianCalendar.getInstance();
                cal.setTime(externalDrive.getCreatedtime());

                externalMapFolder.setCreated(cal);
                expandFolder.addChild(externalMapFolder);
                folderTree.addItem(externalMapFolder);
                folderTree.setItemIcon(externalMapFolder, FontAwesome.DROPBOX);
                folderTree.setItemCaption(externalMapFolder, externalMapFolder.getName());
                folderTree.setParent(externalMapFolder, expandFolder);
            }
        }
        if (expandFolder instanceof ExternalFolder) {
            List<ExternalFolder> subFolders = externalResourceService
                    .getSubFolders(((ExternalFolder) expandFolder).getExternalDrive(), expandFolder.getPath());
            for (final Folder subFolder : subFolders) {
                expandFolder.addChild(subFolder);
                folderTree.addItem(subFolder);
                folderTree.setItemIcon(subFolder, FontAwesome.DROPBOX);
                folderTree.setItemCaption(subFolder, subFolder.getName());
                folderTree.setParent(subFolder, expandFolder);
            }
        } else {
            final List<Folder> subFolders = resourceService.getSubFolders(expandFolder.getPath());
            folderTree.setItemIcon(expandFolder, FontAwesome.FOLDER_OPEN);

            if (subFolders != null) {
                for (final Folder subFolder : subFolders) {
                    String subFolderName = subFolder.getName();
                    if (!subFolderName.startsWith(".")) {
                        expandFolder.addChild(subFolder);
                        folderTree.addItem(subFolder);
                        folderTree.setItemIcon(subFolder, FontAwesome.FOLDER);
                        folderTree.setItemCaption(subFolder, subFolderName);
                        folderTree.setParent(subFolder, expandFolder);
                    }
                }
            }
        }
    });

    folderTree.addCollapseListener(new Tree.CollapseListener() {
        private static final long serialVersionUID = 1L;

        @Override
        public void nodeCollapse(final CollapseEvent event) {
            final Folder collapseFolder = (Folder) event.getItemId();
            if (collapseFolder instanceof ExternalFolder) {
                folderTree.setItemIcon(collapseFolder, FontAwesome.DROPBOX);
            } else {
                folderTree.setItemIcon(collapseFolder, FontAwesome.FOLDER);
            }
            collapseFolder.getChilds().forEach(this::recursiveRemoveSubItem);
        }

        private void recursiveRemoveSubItem(Folder collapseFolder) {
            List<Folder> childFolders = collapseFolder.getChilds();
            if (childFolders.size() > 0) {
                childFolders.forEach(this::recursiveRemoveSubItem);
                folderTree.removeItem(collapseFolder);
            } else {
                folderTree.removeItem(collapseFolder);
            }
        }
    });

    folderTree.addItemClickListener(itemClickEvent -> baseFolder = (Folder) itemClickEvent.getItemId());

    CssLayout treeWrapper = new CssLayout(folderTree);
    treeWrapper.setSizeFull();
    contentLayout.addComponent(treeWrapper);
    displayFiles();

    MButton moveBtn = new MButton(UserUIContext.getMessage(GenericI18Enum.ACTION_MOVE), clickEvent -> {
        if (!CollectionUtils.isEmpty(movedResources)) {
            boolean checkingFail = false;
            for (Resource res : movedResources) {
                try {
                    resourceMover.moveResource(res, baseFolder, UserUIContext.getUsername(),
                            MyCollabUI.getAccountId());
                } catch (Exception e) {
                    checkingFail = true;
                    LOG.error("Error", e);
                }
            }
            close();
            displayAfterMoveSuccess(baseFolder, checkingFail);
        }
    }).withIcon(FontAwesome.ARROWS).withStyleName(WebThemes.BUTTON_ACTION);

    MButton cancelBtn = new MButton(UserUIContext.getMessage(GenericI18Enum.BUTTON_CANCEL),
            clickEvent -> close()).withStyleName(WebThemes.BUTTON_OPTION);

    MHorizontalLayout controlGroupBtnLayout = new MHorizontalLayout(cancelBtn, moveBtn);
    contentLayout.with(controlGroupBtnLayout).withAlign(controlGroupBtnLayout, Alignment.MIDDLE_RIGHT);
}

From source file:com.mycollab.module.file.view.components.AbstractResourceMovingWindow.java

License:Open Source License

private void constructBody() {
    MVerticalLayout contentLayout = new MVerticalLayout();
    new Restrain(contentLayout).setMaxHeight("600px");
    this.setContent(contentLayout);

    folderTree = new Tree();
    folderTree.setMultiSelect(false);/*from w w w .  j  a  v a 2s.  com*/
    folderTree.setSelectable(true);
    folderTree.setImmediate(true);
    folderTree.setSizeFull();

    folderTree.addExpandListener(new Tree.ExpandListener() {
        private static final long serialVersionUID = 1L;

        @Override
        public void nodeExpand(final ExpandEvent event) {
            final Folder expandFolder = (Folder) event.getItemId();
            // load externalResource if currentExpandFolder is rootFolder
            if (baseFolder.getPath().equals(expandFolder.getPath())) {
                List<ExternalDrive> externalDrives = externalDriveService
                        .getExternalDrivesOfUser(AppContext.getUsername());
                for (ExternalDrive externalDrive : externalDrives) {
                    ExternalFolder externalMapFolder = new ExternalFolder("/");
                    externalMapFolder.setStorageName(externalDrive.getStoragename());
                    externalMapFolder.setExternalDrive(externalDrive);
                    externalMapFolder.setName(externalDrive.getFoldername());

                    Calendar cal = GregorianCalendar.getInstance();
                    cal.setTime(externalDrive.getCreatedtime());

                    externalMapFolder.setCreated(cal);
                    expandFolder.addChild(externalMapFolder);
                    folderTree.addItem(externalMapFolder);
                    folderTree.setItemIcon(externalMapFolder, FontAwesome.DROPBOX);
                    folderTree.setItemCaption(externalMapFolder, externalMapFolder.getName());
                    folderTree.setParent(externalMapFolder, expandFolder);
                }
            }
            if (expandFolder instanceof ExternalFolder) {
                List<ExternalFolder> subFolders = externalResourceService.getSubFolders(
                        ((ExternalFolder) expandFolder).getExternalDrive(), expandFolder.getPath());
                for (final Folder subFolder : subFolders) {
                    expandFolder.addChild(subFolder);
                    folderTree.addItem(subFolder);
                    folderTree.setItemIcon(subFolder, FontAwesome.DROPBOX);
                    folderTree.setItemCaption(subFolder, subFolder.getName());
                    folderTree.setParent(subFolder, expandFolder);
                }
            } else {
                final List<Folder> subFolders = resourceService.getSubFolders(expandFolder.getPath());
                folderTree.setItemIcon(expandFolder, FontAwesome.FOLDER_OPEN);

                if (subFolders != null) {
                    for (final Folder subFolder : subFolders) {
                        String subFolderName = subFolder.getName();
                        if (!subFolderName.startsWith(".")) {
                            expandFolder.addChild(subFolder);
                            folderTree.addItem(subFolder);
                            folderTree.setItemIcon(subFolder, FontAwesome.FOLDER);
                            folderTree.setItemCaption(subFolder, subFolderName);
                            folderTree.setParent(subFolder, expandFolder);
                        }
                    }
                }
            }
        }
    });

    folderTree.addCollapseListener(new Tree.CollapseListener() {
        private static final long serialVersionUID = 1L;

        @Override
        public void nodeCollapse(final CollapseEvent event) {
            final Folder collapseFolder = (Folder) event.getItemId();
            if (collapseFolder instanceof ExternalFolder) {
                folderTree.setItemIcon(collapseFolder, FontAwesome.DROPBOX);
            } else {
                folderTree.setItemIcon(collapseFolder, FontAwesome.FOLDER);
            }
            for (Folder folder : collapseFolder.getChilds()) {
                recursiveRemoveSubItem(folder);
            }
        }

        private void recursiveRemoveSubItem(Folder collapseFolder) {
            List<Folder> childFolders = collapseFolder.getChilds();
            if (childFolders.size() > 0) {
                for (Folder subFolder : childFolders) {
                    recursiveRemoveSubItem(subFolder);
                }
                folderTree.removeItem(collapseFolder);
            } else {
                folderTree.removeItem(collapseFolder);
            }
        }
    });

    folderTree.addItemClickListener(new ItemClickEvent.ItemClickListener() {
        private static final long serialVersionUID = 1L;

        @Override
        public void itemClick(final ItemClickEvent event) {
            baseFolder = (Folder) event.getItemId();
        }
    });

    CssLayout treeWrapper = new CssLayout(folderTree);
    treeWrapper.setSizeFull();
    contentLayout.addComponent(treeWrapper);
    displayFiles();

    MHorizontalLayout controlGroupBtnLayout = new MHorizontalLayout();

    Button moveBtn = new Button("Move", new ClickListener() {
        private static final long serialVersionUID = 1L;

        @Override
        public void buttonClick(ClickEvent event) {
            if (!CollectionUtils.isEmpty(movedResources)) {
                boolean checkingFail = false;
                for (Resource res : movedResources) {
                    try {
                        resourceMover.moveResource(res, baseFolder, AppContext.getUsername(),
                                AppContext.getAccountId());
                    } catch (Exception e) {
                        checkingFail = true;
                        LOG.error("Error", e);
                    }
                }
                close();
                displayAfterMoveSuccess(baseFolder, checkingFail);
            }
        }

    });
    moveBtn.setIcon(FontAwesome.ARROWS);
    moveBtn.addStyleName(UIConstants.BUTTON_ACTION);

    Button cancelBtn = new Button(AppContext.getMessage(GenericI18Enum.BUTTON_CANCEL), new ClickListener() {
        private static final long serialVersionUID = 1L;

        @Override
        public void buttonClick(ClickEvent event) {
            close();
        }
    });
    cancelBtn.addStyleName(UIConstants.BUTTON_OPTION);
    controlGroupBtnLayout.with(cancelBtn, moveBtn);

    contentLayout.with(controlGroupBtnLayout).withAlign(controlGroupBtnLayout, Alignment.MIDDLE_RIGHT);
}