Search in sources :

Example 1 with FolderItem

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

the class BaseBreadcrumbNavigatorTest method testLoadContentFileAndFolder.

@Test
public void testLoadContentFileAndFolder() {
    final BreadcrumbNavigator navigator = spy(new BreadcrumbNavigator(activeOptions, hiddenTypeDef, user));
    final FolderItem item = new FolderItem(path, "item1", FolderItemType.FILE);
    final List<FolderItem> content = new ArrayList<FolderItem>() {

        {
            add(new FolderItem(mock(Path.class), "File1", FolderItemType.FILE));
            add(new FolderItem(mock(Path.class), "Folder1", FolderItemType.FOLDER));
        }
    };
    final List<FolderItem> segments = new ArrayList<FolderItem>();
    final FolderListing listing = new FolderListing(item, content, segments);
    navigator.loadContent(listing);
    verify(navigator).setupBreadcrumb(listing);
    verify(navigator).setupUpFolder(listing);
    verify(navigator).setupContent(listing);
    verify(navigator).showNavigatorPanel();
}
Also used : FolderItem(org.kie.workbench.common.screens.explorer.model.FolderItem) ArrayList(java.util.ArrayList) FolderListing(org.kie.workbench.common.screens.explorer.model.FolderListing) Test(org.junit.Test)

Example 2 with FolderItem

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

the class BaseBreadcrumbNavigatorTest method testLoadContentOnlyFolder.

@Test
public void testLoadContentOnlyFolder() {
    final BreadcrumbNavigator navigator = spy(new BreadcrumbNavigator(activeOptions, hiddenTypeDef, user));
    final FolderItem item = new FolderItem(path, "item1", FolderItemType.FILE);
    final List<FolderItem> content = new ArrayList<FolderItem>() {

        {
            add(new FolderItem(mock(Path.class), "Folder1", FolderItemType.FOLDER));
        }
    };
    final List<FolderItem> segments = new ArrayList<FolderItem>();
    final FolderListing listing = new FolderListing(item, content, segments);
    navigator.loadContent(listing);
    verify(navigator).setupBreadcrumb(listing);
    verify(navigator).setupUpFolder(listing);
    verify(navigator).setupContent(listing);
    verify(navigator).showNavigatorPanel();
}
Also used : FolderItem(org.kie.workbench.common.screens.explorer.model.FolderItem) ArrayList(java.util.ArrayList) FolderListing(org.kie.workbench.common.screens.explorer.model.FolderListing) Test(org.junit.Test)

Example 3 with FolderItem

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

the class BreadcrumbNavigator method setupBreadcrumb.

// Package protected for unit-testing
void setupBreadcrumb(final FolderListing content) {
    final NavigatorBreadcrumbs navigatorBreadcrumbs = new NavigatorBreadcrumbs(NavigatorBreadcrumbs.Mode.SECOND_LEVEL);
    navigatorBreadcrumbs.build(content.getSegments(), content.getItem(), new ParameterizedCommand<FolderItem>() {

        @Override
        public void execute(final FolderItem item) {
            presenter.onActiveFolderItemSelected(item);
        }
    });
    final Panel panel = new Panel();
    final PanelBody panelBody = new PanelBody();
    panelBody.getElement().getStyle().setPaddingLeft(10, Style.Unit.PX);
    panelBody.getElement().getStyle().setPaddingRight(10, Style.Unit.PX);
    panelBody.add(navigatorBreadcrumbs);
    panel.add(panelBody);
    container.add(panel);
}
Also used : Panel(org.gwtbootstrap3.client.ui.Panel) FlowPanel(com.google.gwt.user.client.ui.FlowPanel) FolderItem(org.kie.workbench.common.screens.explorer.model.FolderItem) PanelBody(org.gwtbootstrap3.client.ui.PanelBody)

Example 4 with FolderItem

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

the class ProjectExplorerContentResolver method setSiblings.

private void setSiblings(final Content content) {
    if (content.getFolderListing().getSegments().size() > 1) {
        final ListIterator<FolderItem> li = content.getFolderListing().getSegments().listIterator(content.getFolderListing().getSegments().size());
        while (li.hasPrevious()) {
            final FolderItem currentItem = li.previous();
            final List<FolderItem> result = new ArrayList<>();
            result.add(currentItem);
            if (currentItem.getItem() instanceof Package) {
                result.addAll(getSegmentSiblings((Package) currentItem.getItem()));
            } else if (currentItem.getItem() instanceof Path) {
                result.addAll(getSegmentSiblings((Path) currentItem.getItem()));
            }
            content.getSiblings().put(currentItem, result);
        }
    }
    if (content.getSelectedItem() != null && content.getSelectedItem().getType().equals(FolderItemType.FOLDER) && !content.getSiblings().containsKey(content.getSelectedItem())) {
        final List<FolderItem> result = new ArrayList<>();
        result.add(content.getSelectedItem());
        if (content.getSelectedItem().getItem() instanceof Package) {
            result.addAll(getSegmentSiblings((Package) content.getSelectedItem().getItem()));
        } else if (content.getSelectedItem().getItem() instanceof Path) {
            result.addAll(getSegmentSiblings((Path) content.getSelectedItem().getItem()));
        }
        content.getSiblings().put(content.getSelectedItem(), result);
    }
    if (content.getFolderListing().getItem().getType().equals(FolderItemType.FOLDER) && !content.getSiblings().containsKey(content.getFolderListing().getItem())) {
        final List<FolderItem> result = new ArrayList<>();
        result.add(content.getFolderListing().getItem());
        if (content.getFolderListing().getItem().getItem() instanceof Package) {
            result.addAll(getSegmentSiblings((Package) content.getFolderListing().getItem().getItem()));
        } else if (content.getFolderListing().getItem().getItem() instanceof Path) {
            result.addAll(getSegmentSiblings((Path) content.getFolderListing().getItem().getItem()));
        }
        if (!result.isEmpty()) {
            content.getSiblings().put(content.getFolderListing().getItem(), result);
        }
    }
    // Sort sibling lists before returning to client
    for (Map.Entry<FolderItem, List<FolderItem>> e : content.getSiblings().entrySet()) {
        Collections.sort(e.getValue(), Sorters.ITEM_SORTER);
    }
}
Also used : Path(org.uberfire.backend.vfs.Path) FolderItem(org.kie.workbench.common.screens.explorer.model.FolderItem) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) Collections.emptyList(java.util.Collections.emptyList) List(java.util.List) Package(org.guvnor.common.services.project.model.Package) Map(java.util.Map)

Example 5 with FolderItem

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

the class ProjectExplorerContentResolver method getSegmentSiblings.

private List<FolderItem> getSegmentSiblings(final Package pkg) {
    final List<FolderItem> result = new ArrayList<>();
    final Package parentPkg = moduleService.resolveParentPackage(pkg);
    if (parentPkg == null) {
        return emptyList();
    }
    final Set<Package> siblings = moduleService.resolvePackages(parentPkg);
    if (siblings != null && !siblings.isEmpty()) {
        for (final Package sibling : siblings) {
            if (!sibling.equals(pkg)) {
                result.add(explorerServiceHelper.toFolderItem(sibling));
            }
        }
    }
    return result;
}
Also used : FolderItem(org.kie.workbench.common.screens.explorer.model.FolderItem) ArrayList(java.util.ArrayList) Package(org.guvnor.common.services.project.model.Package)

Aggregations

FolderItem (org.kie.workbench.common.screens.explorer.model.FolderItem)33 ArrayList (java.util.ArrayList)15 Path (org.uberfire.backend.vfs.Path)15 Test (org.junit.Test)13 Package (org.guvnor.common.services.project.model.Package)8 FolderListing (org.kie.workbench.common.screens.explorer.model.FolderListing)8 List (java.util.List)4 Set (java.util.Set)3 Inject (javax.inject.Inject)3 Module (org.guvnor.common.services.project.model.Module)3 User (org.jboss.errai.security.shared.api.identity.User)3 FolderItemType (org.kie.workbench.common.screens.explorer.model.FolderItemType)3 AssetInfo (org.kie.workbench.common.screens.library.api.AssetInfo)3 ClientResourceType (org.uberfire.client.workbench.type.ClientResourceType)3 Window (com.google.gwt.user.client.Window)2 Collection (java.util.Collection)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2 TreeSet (java.util.TreeSet)2 PostConstruct (javax.annotation.PostConstruct)2