Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
rimasirich committed Jun 2, 2015
2 parents 3df9923 + 810b42e commit 6bfa531
Show file tree
Hide file tree
Showing 6 changed files with 124 additions and 25 deletions.
Expand Up @@ -10,13 +10,11 @@
*******************************************************************************/
package org.eclipse.che.ide.client;

import com.google.gwt.core.client.Callback;
import com.google.inject.Provider;

import elemental.client.Browser;
import elemental.events.Event;
import elemental.events.EventListener;

import com.google.gwt.core.client.Callback;
import com.google.gwt.core.client.Scheduler;
import com.google.gwt.core.client.Scheduler.ScheduledCommand;
import com.google.gwt.dom.client.Document;
Expand All @@ -26,6 +24,7 @@
import com.google.gwt.user.client.ui.RootLayoutPanel;
import com.google.gwt.user.client.ui.SimpleLayoutPanel;
import com.google.inject.Inject;
import com.google.inject.Provider;
import com.google.inject.Singleton;
import com.google.web.bindery.event.shared.EventBus;
import com.google.web.bindery.event.shared.HandlerRegistration;
Expand All @@ -50,7 +49,6 @@
import org.eclipse.che.ide.util.loging.Log;
import org.eclipse.che.ide.workspace.WorkspacePresenter;


import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
Expand Down Expand Up @@ -121,7 +119,7 @@ private void startComponent(final Iterator<Map.Entry<String, Provider<Component>
@Override
public void onFailure(Exception reason) {
Log.error(BootstrapController.class, reason);
initializationFailed(reason.getMessage());
initializationFailed(reason);
}

@Override
Expand Down Expand Up @@ -356,12 +354,11 @@ private void performAction(String actionId, Map<String, String> parameters) {
* Handles any of initialization errors.
* Tries to call predefined IDE.eventHandlers.ideInitializationFailed function.
*
* @param message
* error message
* @param reason failure encountered
*/
private native void initializationFailed(String message) /*-{
private native void initializationFailed(Exception reason) /*-{
try {
$wnd.IDE.eventHandlers.initializationFailed(message);
$wnd.IDE.eventHandlers.initializationFailed(reason);
} catch (e) {
console.log(e.message);
}
Expand Down
Expand Up @@ -23,7 +23,7 @@
import org.eclipse.che.ide.api.project.tree.generic.FileNode;
import org.eclipse.che.ide.collections.Array;
import org.eclipse.che.ide.dto.DtoFactory;
import org.eclipse.che.ide.part.projectexplorer.ProjectExplorerViewImpl;
import org.eclipse.che.ide.part.projectexplorer.ProjectExplorerView;
import org.eclipse.che.ide.statepersistance.dto.ActionDescriptor;

import javax.validation.constraints.NotNull;
Expand All @@ -42,15 +42,15 @@ public class ActiveNodePersistentComponent implements PersistenceComponent {
private Provider<EditorAgent> editorAgentProvider;
private DtoFactory dtoFactory;
private ActionManager actionManager;
private SelectNodeAction selectNodeAction;
private ProjectExplorerViewImpl projectExplorerView;
private SelectNodeAction selectNodeAction;
private ProjectExplorerView projectExplorerView;

@Inject
public ActiveNodePersistentComponent(Provider<EditorAgent> editorAgentProvider,
DtoFactory dtoFactory,
ActionManager actionManager,
SelectNodeAction selectNodeAction,
ProjectExplorerViewImpl projectExplorerView) {
ProjectExplorerView projectExplorerView) {
this.editorAgentProvider = editorAgentProvider;
this.dtoFactory = dtoFactory;
this.actionManager = actionManager;
Expand Down
Expand Up @@ -20,7 +20,7 @@
import org.eclipse.che.ide.api.project.tree.TreeNode;
import org.eclipse.che.ide.api.project.tree.generic.StorableNode;
import org.eclipse.che.ide.collections.Array;
import org.eclipse.che.ide.part.projectexplorer.ProjectExplorerViewImpl;
import org.eclipse.che.ide.part.projectexplorer.ProjectExplorerView;
import org.eclipse.che.ide.statepersistance.dto.ActionDescriptor;

import java.util.ArrayList;
Expand All @@ -34,13 +34,13 @@
@Singleton
public class OpenedNodesPersistenceComponent implements PersistenceComponent {

private final ProjectExplorerViewImpl projectExplorerView;
private final ProjectExplorerView projectExplorerView;
private final OpenNodeAction openNodeAction;
private final ActionManager actionManager;
private final DtoFactory dtoFactory;

@Inject
public OpenedNodesPersistenceComponent(ProjectExplorerViewImpl projectExplorerView,
public OpenedNodesPersistenceComponent(ProjectExplorerView projectExplorerView,
ActionManager actionManager,
OpenNodeAction openNodeAction,
DtoFactory dtoFactory) {
Expand Down
Expand Up @@ -44,6 +44,13 @@ public boolean accept(VirtualFile file) {
}
};

private static final VirtualFileFilter FILE_FOLDER_FILTER = new VirtualFileFilter() {
@Override
public boolean accept(VirtualFile file) {
return (file.isFile() || file.isFolder());
}
};

public FolderEntry(String workspace, VirtualFile virtualFile) {
super(workspace, virtualFile);
}
Expand Down Expand Up @@ -116,6 +123,16 @@ public List<FolderEntry> getChildFolders() throws ServerException {
return children;
}

/**
* Gets child folders and files of this folder. If current user doesn't have read access to some child they aren't added in result list.
*
* @throws ServerException
* if an error occurs
*/
public List<VirtualFileEntry> getChildFoldersFiles() throws ServerException {
return getChildren(FILE_FOLDER_FILTER);
}

List<VirtualFileEntry> getChildren(VirtualFileFilter filter) throws ServerException {
final LazyIterator<VirtualFile> vfChildren = getVirtualFile().getChildren(filter);
final List<VirtualFileEntry> children = new ArrayList<>();
Expand Down
Expand Up @@ -1219,14 +1219,16 @@ public TreeElement getTree(@ApiParam(value = "Workspace ID", required = true)
@ApiParam(value = "Path to resource. Can be project or its folders", required = true)
@PathParam("parent") String path,
@ApiParam(value = "Tree depth. This parameter can be dropped. If not specified ?depth=1 is used by default")
@DefaultValue("1") @QueryParam("depth") int depth)
@DefaultValue("1") @QueryParam("depth") int depth,
@ApiParam(value = "include children files (in addition to children folders). This parameter can be dropped. If not specified ?includeFiles=false is used by default")
@DefaultValue("false") @QueryParam("includeFiles") boolean includeFiles)
throws NotFoundException, ForbiddenException, ServerException {
final FolderEntry folder = asFolder(workspace, path);
final UriBuilder uriBuilder = getServiceContext().getServiceUriBuilder();
final DtoFactory dtoFactory = DtoFactory.getInstance();
return dtoFactory.createDto(TreeElement.class)
.withNode(DtoConverter.toItemReferenceDto(folder, uriBuilder.clone()))
.withChildren(getTree(folder, depth, uriBuilder, dtoFactory));
.withChildren(getTree(folder, depth, includeFiles, uriBuilder, dtoFactory));
}

@ApiOperation(value = "Get file or folder",
Expand Down Expand Up @@ -1262,16 +1264,25 @@ public ItemReference getItem(@ApiParam(value = "Workspace ID", required = true)
return item;
}

private List<TreeElement> getTree(FolderEntry folder, int depth, UriBuilder uriBuilder, DtoFactory dtoFactory) throws ServerException {
private List<TreeElement> getTree(FolderEntry folder, int depth, boolean includeFiles, UriBuilder uriBuilder, DtoFactory dtoFactory) throws ServerException {
if (depth == 0) {
return null;
}
final List<FolderEntry> childFolders = folder.getChildFolders();
final List<TreeElement> nodes = new ArrayList<>(childFolders.size());
for (FolderEntry childFolder : childFolders) {
nodes.add(dtoFactory.createDto(TreeElement.class)
.withNode(DtoConverter.toItemReferenceDto(childFolder, uriBuilder.clone()))
.withChildren(getTree(childFolder, depth - 1, uriBuilder, dtoFactory)));
final List<? extends VirtualFileEntry> children;

if (includeFiles) {
children = folder.getChildFoldersFiles();
}else {
children = folder.getChildFolders();
}

final List<TreeElement> nodes = new ArrayList<>(children.size());
for (VirtualFileEntry child : children) {
if (child.isFolder()) {
nodes.add(dtoFactory.createDto(TreeElement.class).withNode(DtoConverter.toItemReferenceDto((FolderEntry)child, uriBuilder.clone())).withChildren(getTree((FolderEntry)child, depth - 1, includeFiles, uriBuilder, dtoFactory)));
} else { // child.isFile()
nodes.add(dtoFactory.createDto(TreeElement.class).withNode(DtoConverter.toItemReferenceDto((FileEntry)child, uriBuilder.clone())));
}
}
return nodes;
}
Expand Down
Expand Up @@ -1994,6 +1994,80 @@ public void testGetTreeWithDepth() throws Exception {
Assert.assertTrue(names.contains("x/y"));
}


@Test
public void testGetTreeWithDepthAndIncludeFiles() throws Exception {
Project myProject = pm.getProject(workspace, "my_project");
FolderEntry a = myProject.getBaseFolder().createFolder("a");
a.createFolder("b/c");
a.createFolder("x").createFile("test.txt", "test".getBytes(), "text/plain");
ContainerResponse response = launcher.service("GET",
String.format("http://localhost:8080/api/project/%s/tree/my_project/a?depth=100&includeFiles=true",
workspace),
"http://localhost:8080/api", null, null, null);
assertEquals(response.getStatus(), 200, "Error: " + response.getEntity());
TreeElement tree = (TreeElement)response.getEntity();
ItemReference a_node = tree.getNode();
assertEquals(a_node.getName(), "a");
List<TreeElement> children = tree.getChildren();
assertNotNull(children);
Set<String> names = new LinkedHashSet<>(4);
for (TreeElement subTree : children) {
ItemReference _node = subTree.getNode();
validateFolderLinks(_node);
String name = _node.getName();
names.add(name);
for (TreeElement subSubTree : subTree.getChildren()) {
ItemReference __node = subSubTree.getNode();
if (__node.getType().equals("folder")) {
validateFolderLinks(__node);
} else if (__node.getType().equals("file")){
validateFileLinks(__node);
}
names.add(name + "/" + __node.getName());
}
}
Assert.assertTrue(names.contains("b"));
Assert.assertTrue(names.contains("x"));
Assert.assertTrue(names.contains("b/c"));
Assert.assertTrue(names.contains("x/test.txt"));
}

@Test
public void testGetTreeWithDepthAndIncludeFilesNoFiles() throws Exception {
Project myProject = pm.getProject(workspace, "my_project");
FolderEntry a = myProject.getBaseFolder().createFolder("a");
a.createFolder("b/c");
a.createFolder("x");
ContainerResponse response = launcher.service("GET",
String.format("http://localhost:8080/api/project/%s/tree/my_project/a?depth=100&includeFiles=true",
workspace),
"http://localhost:8080/api", null, null, null);
assertEquals(response.getStatus(), 200, "Error: " + response.getEntity());
TreeElement tree = (TreeElement)response.getEntity();
ItemReference a_node = tree.getNode();
assertEquals(a_node.getName(), "a");
List<TreeElement> children = tree.getChildren();
assertNotNull(children);
Set<String> names = new LinkedHashSet<>(4);
for (TreeElement subTree : children) {
ItemReference _node = subTree.getNode();
validateFolderLinks(_node);
String name = _node.getName();
names.add(name);
for (TreeElement subSubTree : subTree.getChildren()) {
ItemReference __node = subSubTree.getNode();
validateFolderLinks(__node);
names.add(name + "/" + __node.getName());
}
}
Assert.assertTrue(names.contains("b"));
Assert.assertTrue(names.contains("x"));
Assert.assertTrue(names.contains("b/c"));
Assert.assertFalse(names.contains("x/test.txt"));
}


@Test
public void testSwitchProjectVisibilityToPrivate() throws Exception {
Project myProject = pm.getProject(workspace, "my_project");
Expand Down

0 comments on commit 6bfa531

Please sign in to comment.