use of org.eclipse.che.ide.resources.tree.ResourceNode in project che by eclipse.
the class PlainJavaPagePresenterTest method selectedNodeShouldBeWithRelativePath.
@Test
public void selectedNodeShouldBeWithRelativePath() throws Exception {
when(view.getLibraryFolder()).thenReturn("lib1, lib2");
when(view.getSourceFolder()).thenReturn("src1, src2");
List<Node> selectedNodes = new ArrayList<>();
ResourceNode selectedNode1 = mock(ResourceNode.class);
ResourceNode selectedNode2 = mock(ResourceNode.class);
Resource resource1 = mock(Resource.class);
Resource resource2 = mock(Resource.class);
selectedNodes.add(selectedNode1);
selectedNodes.add(selectedNode2);
when(selectedNode1.getData()).thenReturn(resource1);
when(resource1.getLocation()).thenReturn(Path.valueOf("projectName/folder1/folder2"));
when(selectedNode2.getData()).thenReturn(resource2);
when(resource2.getLocation()).thenReturn(Path.valueOf("projectName/folder"));
when(dataObject.getName()).thenReturn("projectName");
page.setUpdateDelegate(updateDelegate);
page.init(dataObject);
page.onNodeSelected(selectedNodes);
verify(view).setLibraryFolder(eq("folder1/folder2, folder"));
}
use of org.eclipse.che.ide.resources.tree.ResourceNode in project che by eclipse.
the class ProjectExplorerStateComponent method getState.
@Override
public JsonObject getState() {
final List<Path> paths = new ArrayList<>();
outer: for (Node node : projectExplorer.getTree().getNodeStorage().getAll()) {
if (projectExplorer.getTree().isExpanded(node) && node instanceof ResourceNode) {
final List<Node> childrenToStore = projectExplorer.getTree().getNodeStorage().getChildren(node);
for (Node children : childrenToStore) {
if (children instanceof ResourceNode) {
paths.add(((ResourceNode) children).getData().getLocation());
continue outer;
}
}
}
}
JsonObject state = Json.createObject();
JsonArray array = Json.createArray();
state.put(PATH_PARAM_ID, array);
int i = 0;
for (Path path : paths) {
array.set(i++, path.toString());
}
state.put(SHOW_HIDDEN_FILES, projectExplorer.isShowHiddenFiles());
return state;
}
use of org.eclipse.che.ide.resources.tree.ResourceNode in project che by eclipse.
the class TreeResourceRevealer method expand.
protected void expand(final ResourceNode parent, final Path segment, final boolean select, final AsyncCallback<ResourceNode> callback) {
if (parent.getData().getLocation().equals(segment)) {
if (select) {
if (toSelect == null) {
toSelect = new Node[] { parent };
} else {
final int index = toSelect.length;
toSelect = copyOf(toSelect, index + 1);
toSelect[index] = parent;
}
selectTask.delay(200);
}
callback.onSuccess(parent);
return;
}
final HandlerRegistration[] handler = new HandlerRegistration[1];
handler[0] = tree.getNodeLoader().addPostLoadHandler(new PostLoadHandler() {
@Override
public void onPostLoad(PostLoadEvent event) {
if (!event.getRequestedNode().equals(parent)) {
return;
}
if (handler[0] != null) {
handler[0].removeHandler();
}
final List<Node> children = tree.getNodeStorage().getChildren(event.getRequestedNode());
for (Node child : children) {
if (child instanceof ResourceNode && ((ResourceNode) child).getData().getLocation().isPrefixOf(segment)) {
expand((ResourceNode) child, segment, select, callback);
return;
}
}
callback.onFailure(new IllegalStateException("Not found"));
}
});
tree.getNodeLoader().loadChildren(parent);
}
use of org.eclipse.che.ide.resources.tree.ResourceNode in project che by eclipse.
the class ExplorerCurrentProjectNameMacro method expand.
/** {@inheritDoc} */
@Override
public Promise<String> expand() {
List<Node> selectedNodes = projectExplorer.getTree().getSelectionModel().getSelectedNodes();
if (selectedNodes.isEmpty() || selectedNodes.size() > 1) {
return promises.resolve("");
}
final Node node = selectedNodes.get(0);
if (node instanceof ResourceNode) {
final Optional<Project> project = ((ResourceNode) node).getData().getRelatedProject();
if (!project.isPresent()) {
return promises.resolve("");
}
return promises.resolve(project.get().getName());
}
return promises.resolve("");
}
use of org.eclipse.che.ide.resources.tree.ResourceNode in project che by eclipse.
the class SelectNodeViewImpl method acceptButtonClicked.
private void acceptButtonClicked() {
List<Node> nodes = tree.getSelectionModel().getSelectedNodes();
if (nodes.isEmpty()) {
return;
}
Node selectedNode = nodes.get(0);
delegate.setSelectedNode(((ResourceNode) selectedNode).getData().getLocation().toString());
hide();
}
Aggregations