Search in sources :

Example 6 with FolderItem

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

the class ClassifierTest method successfullyFindResourceTypeByFolderItemTest.

@Test
public void successfullyFindResourceTypeByFolderItemTest() {
    final FolderItem folderItem = mock(FolderItem.class);
    final Path path = mock(Path.class);
    doReturn(path).when(folderItem).getItem();
    doReturn(true).when(clientResourceType).accept(path);
    final ClientResourceType resourceType = classifier.findResourceType(folderItem);
    assertNotNull(resourceType);
    assertEquals(clientResourceType, resourceType);
}
Also used : Path(org.uberfire.backend.vfs.Path) FolderItem(org.kie.workbench.common.screens.explorer.model.FolderItem) ClientResourceType(org.uberfire.client.workbench.type.ClientResourceType) Test(org.junit.Test)

Example 7 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 8 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 9 with FolderItem

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

the class ExplorerServiceHelper method store.

public void store(final WorkspaceProject project, final Module selectedModule, final FolderListing folderListing, final Package selectedPackage, final ActiveOptions options) {
    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");
    final Module _selectedModule = selectedModule;
    final FolderItem _selectedItem = folderListing.getItem();
    final org.guvnor.common.services.project.model.Package _selectedPackage;
    if (selectedPackage != null) {
        _selectedPackage = selectedPackage;
    } else if (folderListing.getItem().getItem() instanceof Package) {
        _selectedPackage = (Package) folderListing.getItem().getItem();
    } else {
        _selectedPackage = null;
    }
    this.executorService.execute(new DescriptiveRunnable() {

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

        @Override
        public void run() {
            try {
                store(userNavPath, lastUserNavPath, project, _selectedModule, _selectedPackage, _selectedItem, options);
            } catch (final Exception e) {
                LOGGER.error("Can't serialize user's state navigation", e);
            }
        }
    });
}
Also used : Package(org.guvnor.common.services.project.model.Package) FolderItem(org.kie.workbench.common.screens.explorer.model.FolderItem) Package(org.guvnor.common.services.project.model.Package) Module(org.guvnor.common.services.project.model.Module) DescriptiveRunnable(org.uberfire.commons.async.DescriptiveRunnable)

Example 10 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)

Aggregations

FolderItem (org.kie.workbench.common.screens.explorer.model.FolderItem)31 ArrayList (java.util.ArrayList)15 Path (org.uberfire.backend.vfs.Path)14 Test (org.junit.Test)13 Package (org.guvnor.common.services.project.model.Package)8 FolderListing (org.kie.workbench.common.screens.explorer.model.FolderListing)8 NotificationEvent (org.uberfire.workbench.events.NotificationEvent)5 List (java.util.List)4 Set (java.util.Set)3 Inject (javax.inject.Inject)3 Module (org.guvnor.common.services.project.model.Module)3 FolderItemType (org.kie.workbench.common.screens.explorer.model.FolderItemType)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 Event (javax.enterprise.event.Event)2