Search in sources :

Example 11 with FolderListing

use of org.kie.workbench.common.screens.explorer.model.FolderListing in project kie-wb-common by kiegroup.

the class ExplorerServiceHelper method getFolderListing.

public FolderListing getFolderListing(final Path path, final ActiveOptions options) {
    // Get list of files and folders contained in the path
    final List<FolderItem> folderItems = new ArrayList<FolderItem>();
    final boolean includeTags = options.contains(Option.SHOW_TAG_FILTER);
    // Scan upwards until the path exists (as the current path could have been deleted)
    org.uberfire.java.nio.file.Path nioPath = Paths.convert(path);
    while (!Files.exists(nioPath)) {
        nioPath = nioPath.getParent();
    }
    final Path basePath = Paths.convert(nioPath);
    final DirectoryStream<org.uberfire.java.nio.file.Path> nioPaths = ioService.newDirectoryStream(nioPath, dotFileFilter);
    for (org.uberfire.java.nio.file.Path np : nioPaths) {
        if (Files.isRegularFile(np)) {
            final org.uberfire.backend.vfs.Path p = Paths.convert(np);
            final String lockedBy = Paths.readLockedBy(p);
            final FolderItem folderItem = new FolderItem(p, p.getFileName(), FolderItemType.FILE, false, lockedBy, includeTags ? metadataService.getTags(p) : Collections.<String>emptyList(), getRestrictedOperations(p));
            folderItems.add(folderItem);
        } else if (Files.isDirectory(np)) {
            final org.uberfire.backend.vfs.Path p = Paths.convert(np);
            boolean lockedItems = !lockService.retrieveLockInfos(Paths.convert(np), true).isEmpty();
            final FolderItem folderItem = new FolderItem(p, p.getFileName(), FolderItemType.FOLDER, lockedItems, null, Collections.<String>emptyList(), getRestrictedOperations(p));
            folderItems.add(folderItem);
        }
    }
    Collections.sort(folderItems, Sorters.ITEM_SORTER);
    return new FolderListing(toFolderItem(nioPath), folderItems, getPathSegments(basePath));
}
Also used : Path(org.uberfire.backend.vfs.Path) ArrayList(java.util.ArrayList) FolderListing(org.kie.workbench.common.screens.explorer.model.FolderListing) FolderItem(org.kie.workbench.common.screens.explorer.model.FolderItem) Path(org.uberfire.backend.vfs.Path)

Example 12 with FolderListing

use of org.kie.workbench.common.screens.explorer.model.FolderListing in project kie-wb-common by kiegroup.

the class ExplorerServiceImpl method getFolderListing.

@Override
public FolderListing getFolderListing(final WorkspaceProject project, final Module module, final FolderItem item, final ActiveOptions options) {
    // TODO: BUSINESS_CONTENT, TECHNICAL_CONTENT
    final FolderListing result = helper.getFolderListing(item, options);
    if (result != null) {
        final org.uberfire.java.nio.file.Path userNavPath = userServices.buildPath("explorer", "user.nav");
        final org.uberfire.java.nio.file.Path lastUserNavPath = userServices.buildPath("explorer", "last.user.nav");
        this.executorService.execute(new DescriptiveRunnable() {

            @Override
            public String getDescription() {
                return "Serialize Navigation State";
            }

            @Override
            public void run() {
                try {
                    Package pkg = null;
                    if (item.getItem() instanceof Package) {
                        pkg = (Package) item.getItem();
                    }
                    helper.store(userNavPath, lastUserNavPath, project, module, pkg, item, options);
                } catch (final Exception e) {
                    LOGGER.error("Can't serialize user's state navigation", e);
                }
            }
        });
    }
    return result;
}
Also used : FolderListing(org.kie.workbench.common.screens.explorer.model.FolderListing) Package(org.guvnor.common.services.project.model.Package) DescriptiveRunnable(org.uberfire.commons.async.DescriptiveRunnable)

Aggregations

FolderListing (org.kie.workbench.common.screens.explorer.model.FolderListing)12 FolderItem (org.kie.workbench.common.screens.explorer.model.FolderItem)8 ArrayList (java.util.ArrayList)6 Test (org.junit.Test)5 Package (org.guvnor.common.services.project.model.Package)4 Module (org.guvnor.common.services.project.model.Module)2 Before (org.junit.Before)2 ActiveOptions (org.kie.workbench.common.screens.explorer.service.ActiveOptions)2 KieModuleService (org.kie.workbench.common.services.shared.project.KieModuleService)2 InvocationOnMock (org.mockito.invocation.InvocationOnMock)2 Path (org.uberfire.backend.vfs.Path)2 RemoteCallback (org.jboss.errai.common.client.api.RemoteCallback)1 DescriptiveRunnable (org.uberfire.commons.async.DescriptiveRunnable)1 Space (org.uberfire.spaces.Space)1