Search in sources :

Example 6 with WorkspaceProjectContextChangeEvent

use of org.guvnor.common.services.project.context.WorkspaceProjectContextChangeEvent in project kie-wb-common by kiegroup.

the class ExamplesServiceImplTest method testSetupExamples_ProjectCopy.

@Test
public void testSetupExamples_ProjectCopy() {
    final ExampleOrganizationalUnit exOU = mock(ExampleOrganizationalUnit.class);
    final ExampleProject exProject1 = mock(ExampleProject.class);
    doReturn("project 1").when(exProject1).getName();
    final ExampleProject exProject2 = mock(ExampleProject.class);
    doReturn("project 2").when(exProject1).getName();
    final List<ExampleProject> exProjects = new ArrayList<ExampleProject>() {

        {
            add(exProject1);
            add(exProject2);
        }
    };
    final OrganizationalUnit ou = mock(OrganizationalUnit.class);
    doReturn("ou").when(ou).getName();
    final GitRepository repository1 = mock(GitRepository.class);
    final Path repositoryRoot = mock(Path.class);
    final Path module1Root = mock(Path.class);
    final Path module2Root = mock(Path.class);
    when(exOU.getName()).thenReturn("ou");
    when(exProject1.getName()).thenReturn("module1");
    when(exProject1.getRoot()).thenReturn(module1Root);
    when(exProject2.getName()).thenReturn("module2");
    when(exProject2.getRoot()).thenReturn(module2Root);
    when(repository1.getBranch("dev_branch")).thenReturn(Optional.of(new Branch("dev_branch", repositoryRoot)));
    final Optional<Branch> master = Optional.of(new Branch("master", PathFactory.newPath("testFile", "file:///")));
    when(repository1.getDefaultBranch()).thenReturn(master);
    when(repositoryRoot.toURI()).thenReturn("default:///");
    when(module1Root.toURI()).thenReturn("default:///module1");
    when(module2Root.toURI()).thenReturn("default:///module2");
    when(ouService.getOrganizationalUnit(eq("ou"))).thenReturn(ou);
    doReturn(repository1).when(repositoryCopier).copy(eq(ou), anyString(), eq(module1Root));
    doReturn(repository1).when(repositoryCopier).copy(eq(ou), anyString(), eq(module2Root));
    final WorkspaceProject project = spy(new WorkspaceProject());
    doReturn("project").when(project).getName();
    doReturn(project).when(projectService).resolveProject(repository1);
    final WorkspaceProjectContextChangeEvent event = service.setupExamples(exOU, exProjects);
    assertNull(event.getOrganizationalUnit());
    assertEquals(project, event.getWorkspaceProject());
    verify(ouService, never()).createOrganizationalUnit(eq("ou"), eq(""), eq(""));
    verify(repositoryCopier, times(2)).copy(eq(ou), anyString(), any(Path.class));
    verify(newProjectEvent, times(2)).fire(any(NewProjectEvent.class));
}
Also used : Path(org.uberfire.backend.vfs.Path) NewProjectEvent(org.guvnor.common.services.project.events.NewProjectEvent) GitRepository(org.guvnor.structure.repositories.impl.git.GitRepository) OrganizationalUnit(org.guvnor.structure.organizationalunit.OrganizationalUnit) ExampleOrganizationalUnit(org.kie.workbench.common.screens.examples.model.ExampleOrganizationalUnit) Branch(org.guvnor.structure.repositories.Branch) WorkspaceProject(org.guvnor.common.services.project.model.WorkspaceProject) ArrayList(java.util.ArrayList) ExampleOrganizationalUnit(org.kie.workbench.common.screens.examples.model.ExampleOrganizationalUnit) WorkspaceProjectContextChangeEvent(org.guvnor.common.services.project.context.WorkspaceProjectContextChangeEvent) ExampleProject(org.kie.workbench.common.screens.examples.model.ExampleProject) Test(org.junit.Test)

Example 7 with WorkspaceProjectContextChangeEvent

use of org.guvnor.common.services.project.context.WorkspaceProjectContextChangeEvent in project kie-wb-common by kiegroup.

the class LibraryPlaces method goToOrganizationalUnits.

public void goToOrganizationalUnits() {
    if (closeAllPlacesOrNothing()) {
        PortablePreconditions.checkNotNull("libraryPerspective.closeAllPlacesOrNothing", libraryPerspective);
        projectContextChangeEvent.fire(new WorkspaceProjectContextChangeEvent());
        final DefaultPlaceRequest placeRequest = new DefaultPlaceRequest(LibraryPlaces.ORGANIZATIONAL_UNITS_SCREEN);
        final PartDefinitionImpl part = new PartDefinitionImpl(placeRequest);
        part.setSelectable(false);
        placeManager.goTo(part, libraryPerspective.getRootPanel());
        setupLibraryBreadCrumbs();
    }
}
Also used : PartDefinitionImpl(org.uberfire.workbench.model.impl.PartDefinitionImpl) DefaultPlaceRequest(org.uberfire.mvp.impl.DefaultPlaceRequest) WorkspaceProjectContextChangeEvent(org.guvnor.common.services.project.context.WorkspaceProjectContextChangeEvent)

Example 8 with WorkspaceProjectContextChangeEvent

use of org.guvnor.common.services.project.context.WorkspaceProjectContextChangeEvent in project kie-wb-common by kiegroup.

the class LibraryPlaces method setupLibraryPerspective.

private void setupLibraryPerspective() {
    OrganizationalUnit activeOu = projectContext.getActiveOrganizationalUnit().orElseThrow(() -> new IllegalStateException("Cannot setup library perspective without active space."));
    PortablePreconditions.checkNotNull("libraryPerspective", libraryPerspective);
    final PlaceRequest placeRequest = new DefaultPlaceRequest(LibraryPlaces.LIBRARY_SCREEN);
    final PartDefinitionImpl part = new PartDefinitionImpl(placeRequest);
    part.setSelectable(false);
    if (!projectContext.getActiveWorkspaceProject().isPresent()) {
        projectContextChangeEvent.fire(new WorkspaceProjectContextChangeEvent(activeOu));
    }
    closeLibraryPlaces();
    placeManager.goTo(part, libraryPerspective.getRootPanel());
    setupLibraryBreadCrumbsWithoutProject();
    hideDocks();
}
Also used : PathPlaceRequest(org.uberfire.mvp.impl.PathPlaceRequest) DefaultPlaceRequest(org.uberfire.mvp.impl.DefaultPlaceRequest) PlaceRequest(org.uberfire.mvp.PlaceRequest) PartDefinitionImpl(org.uberfire.workbench.model.impl.PartDefinitionImpl) OrganizationalUnit(org.guvnor.structure.organizationalunit.OrganizationalUnit) DefaultPlaceRequest(org.uberfire.mvp.impl.DefaultPlaceRequest) WorkspaceProjectContextChangeEvent(org.guvnor.common.services.project.context.WorkspaceProjectContextChangeEvent)

Example 9 with WorkspaceProjectContextChangeEvent

use of org.guvnor.common.services.project.context.WorkspaceProjectContextChangeEvent in project kie-wb-common by kiegroup.

the class LibraryPlaces method goToAsset.

public void goToAsset(final Path path) {
    moduleService.call(new RemoteCallback<org.guvnor.common.services.project.model.Package>() {

        @Override
        public void callback(final org.guvnor.common.services.project.model.Package response) {
            projectContextChangeEvent.fire(new WorkspaceProjectContextChangeEvent(projectContext.getActiveWorkspaceProject().orElse(null), projectContext.getActiveModule().orElse(null), response));
            final PlaceRequest placeRequest = generatePlaceRequest(path);
            placeManager.goTo(placeRequest);
            if (path != null) {
                final ObservablePath observablePath = ((PathPlaceRequest) placeRequest).getPath();
                observablePath.onRename(() -> setupLibraryBreadCrumbsForAsset(observablePath));
            }
        }
    }).resolvePackage(path);
}
Also used : PathPlaceRequest(org.uberfire.mvp.impl.PathPlaceRequest) DefaultPlaceRequest(org.uberfire.mvp.impl.DefaultPlaceRequest) PlaceRequest(org.uberfire.mvp.PlaceRequest) PathPlaceRequest(org.uberfire.mvp.impl.PathPlaceRequest) WorkspaceProjectContextChangeEvent(org.guvnor.common.services.project.context.WorkspaceProjectContextChangeEvent) RemoteCallback(org.jboss.errai.common.client.api.RemoteCallback) ObservablePath(org.uberfire.backend.vfs.ObservablePath)

Example 10 with WorkspaceProjectContextChangeEvent

use of org.guvnor.common.services.project.context.WorkspaceProjectContextChangeEvent in project kie-wb-common by kiegroup.

the class LibraryPlaces method openBestSuitedScreen.

private void openBestSuitedScreen(final String eventType, final Path path, final WorkspaceProject project) {
    if (!projectContext.getActiveWorkspaceProject().map(active -> active.equals(project)).orElse(false)) {
        projectContextChangeEvent.fire(new WorkspaceProjectContextChangeEvent(project, project.getMainModule()));
    }
    final PlaceRequest libraryPerspectivePlace = getLibraryPlaceRequestWithoutRefresh();
    if (isRepositoryEvent(eventType)) {
        placeManager.goTo(REPOSITORY_STRUCTURE_SCREEN);
    } else if (isModuleEvent(eventType)) {
        placeManager.goTo(libraryPerspectivePlace);
        goToProject();
    } else if (path != null) {
        placeManager.goTo(libraryPerspectivePlace);
        goToProject(() -> goToAsset(path));
    }
}
Also used : PathPlaceRequest(org.uberfire.mvp.impl.PathPlaceRequest) DefaultPlaceRequest(org.uberfire.mvp.impl.DefaultPlaceRequest) PlaceRequest(org.uberfire.mvp.PlaceRequest) WorkspaceProjectContextChangeEvent(org.guvnor.common.services.project.context.WorkspaceProjectContextChangeEvent)

Aggregations

WorkspaceProjectContextChangeEvent (org.guvnor.common.services.project.context.WorkspaceProjectContextChangeEvent)19 OrganizationalUnit (org.guvnor.structure.organizationalunit.OrganizationalUnit)10 PathPlaceRequest (org.uberfire.mvp.impl.PathPlaceRequest)8 WorkspaceProject (org.guvnor.common.services.project.model.WorkspaceProject)7 Test (org.junit.Test)7 DefaultPlaceRequest (org.uberfire.mvp.impl.DefaultPlaceRequest)7 RemoteCallback (org.jboss.errai.common.client.api.RemoteCallback)6 ExampleOrganizationalUnit (org.kie.workbench.common.screens.examples.model.ExampleOrganizationalUnit)6 ExampleProject (org.kie.workbench.common.screens.examples.model.ExampleProject)6 PlaceRequest (org.uberfire.mvp.PlaceRequest)6 Path (org.uberfire.backend.vfs.Path)5 PartDefinitionImpl (org.uberfire.workbench.model.impl.PartDefinitionImpl)5 ArrayList (java.util.ArrayList)4 Repository (org.guvnor.structure.repositories.Repository)4 GitRepository (org.guvnor.structure.repositories.impl.git.GitRepository)4 ObservablePath (org.uberfire.backend.vfs.ObservablePath)4 NewProjectEvent (org.guvnor.common.services.project.events.NewProjectEvent)3 Package (org.guvnor.common.services.project.model.Package)3 Collections (java.util.Collections)2 HashMap (java.util.HashMap)2