use of org.eclipse.che.ide.resource.Path in project che by eclipse.
the class EditorPartStackPresenterTest method tabShouldBeReturnedByPath.
@Test
public void tabShouldBeReturnedByPath() throws Exception {
Path path = new Path(SOME_TEXT);
when(editorTab1.getFile()).thenReturn(file1);
when(file1.getLocation()).thenReturn(path);
presenter.addPart(partPresenter1);
assertEquals(editorTab1, presenter.getTabByPath(path));
}
use of org.eclipse.che.ide.resource.Path in project che by eclipse.
the class ChangedListViewImpl method getTransitFolderName.
private String getTransitFolderName(List<String> allPaths, String comparedPath) {
Path path = Path.valueOf(comparedPath);
int segmentCount = path.segmentCount();
for (int i = segmentCount; i > 0; i--) {
if (allPaths.contains(path.removeLastSegments(segmentCount - i + 1).toString())) {
return path.removeFirstSegments(i - 1).toString();
}
}
return comparedPath;
}
use of org.eclipse.che.ide.resource.Path in project che by eclipse.
the class ChangedListViewImpl method getGroupedNodes.
private List<Node> getGroupedNodes(Map<String, Status> items) {
List<String> allFiles = new ArrayList<>(items.keySet());
List<String> allPaths = new ArrayList<>();
for (String file : allFiles) {
String path = file.substring(0, file.lastIndexOf("/"));
if (!allPaths.contains(path)) {
allPaths.add(path);
}
}
List<String> commonPaths = getCommonPaths(allPaths);
for (String commonPath : commonPaths) {
if (!allPaths.contains(commonPath)) {
allPaths.add(commonPath);
}
}
Map<String, Node> preparedNodes = new HashMap<>();
for (int i = getMaxNestedLevel(allFiles); i > 0; i--) {
//Collect child files of all folders of current nesting level
Map<String, List<Node>> currentChildNodes = new HashMap<>();
for (String file : allFiles) {
Path pathName = Path.valueOf(file);
if (pathName.segmentCount() != i) {
continue;
}
Node fileNode = new ChangedFileNode(file, items.get(file), nodesResources, delegate, true);
String filePath = pathName.removeLastSegments(1).toString();
if (currentChildNodes.keySet().contains(filePath)) {
currentChildNodes.get(filePath).add(fileNode);
} else {
List<Node> listFiles = new ArrayList<>();
listFiles.add(fileNode);
currentChildNodes.put(filePath, listFiles);
}
}
//Map child files to related folders of current nesting level or just create a common folder
for (String path : allPaths) {
if (!(Path.valueOf(path).segmentCount() == i - 1)) {
continue;
}
Node folder = new ChangedFolderNode(getTransitFolderName(allPaths, path), nodesResources);
if (currentChildNodes.keySet().contains(path)) {
folder.setChildren(currentChildNodes.get(path));
}
preparedNodes.put(path, folder);
}
//Take all child folders and nest them to related parent folders of current nesting level
List<String> currentPaths = new ArrayList<>(preparedNodes.keySet());
for (String parentPath : currentPaths) {
List<Node> nodesToNest = new ArrayList<>();
for (String nestedItem : currentPaths) {
if (!parentPath.equals(nestedItem) && (nestedItem.startsWith(parentPath + "/") || parentPath.isEmpty())) {
nodesToNest.add(preparedNodes.remove(nestedItem));
}
}
if (nodesToNest.isEmpty()) {
continue;
}
Collections.sort(nodesToNest, new NameComparator());
if (currentChildNodes.keySet().contains(parentPath)) {
nodesToNest.addAll(currentChildNodes.get(parentPath));
}
if (parentPath.isEmpty()) {
return nodesToNest;
} else {
preparedNodes.get(parentPath).setChildren(nodesToNest);
}
}
}
ArrayList<Node> nodes = new ArrayList<>(preparedNodes.values());
Collections.sort(nodes, new NameComparator());
return new ArrayList<>(nodes);
}
use of org.eclipse.che.ide.resource.Path in project che by eclipse.
the class AddToIndexPresenter method onAddClicked.
/** {@inheritDoc} */
@Override
public void onAddClicked() {
DevMachine devMachine = appContext.getDevMachine();
Resource[] resources = appContext.getResources();
Path projectLocation = appContext.getRootProject().getLocation();
Path[] paths = new Path[resources.length];
for (int i = 0; i < resources.length; i++) {
Path path = resources[i].getLocation().removeFirstSegments(projectLocation.segmentCount());
paths[i] = path.segmentCount() == 0 ? Path.EMPTY : path;
}
final GitOutputConsole console = gitOutputConsoleFactory.create(constant.addToIndexCommandName());
consolesPanelPresenter.addCommandOutput(devMachine.getId(), console);
service.add(devMachine, projectLocation, view.isUpdated(), paths).then(new Operation<Void>() {
@Override
public void apply(Void arg) throws OperationException {
console.print(constant.addSuccess());
notificationManager.notify(constant.addSuccess());
view.close();
}
}).catchError(new Operation<PromiseError>() {
@Override
public void apply(PromiseError arg) throws OperationException {
console.printError(constant.addFailed());
notificationManager.notify(constant.addFailed(), FAIL, FLOAT_MODE);
view.close();
}
});
}
use of org.eclipse.che.ide.resource.Path in project che by eclipse.
the class ComparePresenter method showCompareBetweenRevisions.
/**
*
* @param file
* path of the file
* @param status
* status of the file
* @param revisionA
* hash of the first revision or branch.
* If it is set to {@code null}, compare with empty repository state will be performed
* @param revisionB
* hash of the second revision or branch.
* If it is set to {@code null}, compare with latest repository state will be performed
*/
public void showCompareBetweenRevisions(final Path file, final Status status, @Nullable final String revisionA, @Nullable final String revisionB) {
this.compareWithLatest = false;
final DevMachine devMachine = appContext.getDevMachine();
final Path projectLocation = appContext.getRootProject().getLocation();
view.setTitle(file.toString());
if (status == Status.ADDED) {
service.showFileContent(devMachine, projectLocation, file, revisionB).then(new Operation<ShowFileContentResponse>() {
@Override
public void apply(ShowFileContentResponse response) throws OperationException {
view.setColumnTitles(revisionB + locale.compareReadOnlyTitle(), revisionA == null ? "" : revisionA + locale.compareReadOnlyTitle());
view.show("", response.getContent(), file.toString(), true);
}
}).catchError(new Operation<PromiseError>() {
@Override
public void apply(PromiseError error) throws OperationException {
notificationManager.notify(error.getMessage(), FAIL, NOT_EMERGE_MODE);
}
});
} else if (status == Status.DELETED) {
service.showFileContent(devMachine, projectLocation, file, revisionA).then(new Operation<ShowFileContentResponse>() {
@Override
public void apply(ShowFileContentResponse response) throws OperationException {
view.setColumnTitles(revisionB + locale.compareReadOnlyTitle(), revisionA + locale.compareReadOnlyTitle());
view.show(response.getContent(), "", file.toString(), true);
}
}).catchError(new Operation<PromiseError>() {
@Override
public void apply(PromiseError error) throws OperationException {
notificationManager.notify(error.getMessage(), FAIL, NOT_EMERGE_MODE);
}
});
} else {
service.showFileContent(devMachine, projectLocation, file, revisionA).then(new Operation<ShowFileContentResponse>() {
@Override
public void apply(final ShowFileContentResponse contentAResponse) throws OperationException {
service.showFileContent(devMachine, projectLocation, file, revisionB).then(new Operation<ShowFileContentResponse>() {
@Override
public void apply(ShowFileContentResponse contentBResponse) throws OperationException {
view.setColumnTitles(revisionB + locale.compareReadOnlyTitle(), revisionA + locale.compareReadOnlyTitle());
view.show(contentAResponse.getContent(), contentBResponse.getContent(), file.toString(), true);
}
}).catchError(new Operation<PromiseError>() {
@Override
public void apply(PromiseError error) throws OperationException {
notificationManager.notify(error.getMessage(), FAIL, NOT_EMERGE_MODE);
}
});
}
});
}
}
Aggregations