@Override public void onFileSelected(Path path) { view.hidePopup(); appContext .getWorkspaceRoot() .getFile(path) .then( optFile -> { if (optFile.isPresent()) { editorAgent.openEditor(optFile.get()); } }); }
Promise<Optional<VirtualFile>> getResource(String path) { if (path.startsWith("commands/")) { final String commandName = path.substring(path.lastIndexOf('/') + 1); final Optional<CommandImpl> command = commandManager.getCommand(commandName); if (command.isPresent()) { CommandFileNode node = nodeFactory.newCommandFileNode(command.get()); return promiseProvider.resolve(Optional.of(node)); } else { return promiseProvider.reject(new Exception("Command " + commandName + " not found")); } } else { return appContext .getWorkspaceRoot() .getFile(path) .then( (Function<com.google.common.base.Optional<File>, Optional<VirtualFile>>) arg -> ofNullable(arg.orNull())); } } }
appContext .getWorkspaceRoot() .getFile(file) .then( optional -> {
protected void findInWorkspace( final Location location, final AsyncCallback<VirtualFile> callback) { appContext .getWorkspaceRoot() .getFile(location.getTarget()) .then( file -> { if (file.isPresent()) { callback.onSuccess(file.get()); } else { callback.onFailure(new IllegalArgumentException(location + " not found.")); } }) .catchError( error -> { callback.onFailure(new IllegalArgumentException(location + " not found.")); }); }
.getFile(resources.get(0).getPath()) .then( file -> {
private void updateContentInCompareWidget(PreviewNode selectedNode, List<TextEdit> edits) { String path = selectedNode.getUri(); Container workspaceRoot = appContext.getWorkspaceRoot(); Promise<Optional<File>> file = workspaceRoot.getFile(path); file.then( fileOptional -> { if (!fileOptional.isPresent()) { return; } File existingFile = fileOptional.get(); existingFile .getContent() .then( content -> { ChangePreview changePreview = new ChangePreview(); changePreview.setFileName(existingFile.getName()); changePreview.setOldContent(content); // apply all related TextEdit to show new content in compare widget StringBuilder output = new StringBuilder(); new StringStreamEditor(edits, content, output).transform(); String result = output.toString(); changePreview.setNewContent(result); view.showDiff(changePreview); }); }); }
@Override @SuppressWarnings("Duplicates") public void actionPerformed() { final EditorPartPresenter editorPartPresenter = editorAgent.getOpenedEditor(Path.valueOf(itemPath)); if (editorPartPresenter != null) { selectRange(editorPartPresenter); Scheduler.get().scheduleDeferred(() -> editorAgent.activateEditor(editorPartPresenter)); return; } appContext .getWorkspaceRoot() .getFile(itemPath) .then( file -> { if (file.isPresent()) { editorAgent.openEditor( file.get(), new OpenEditorCallbackImpl() { @Override public void onEditorOpened(EditorPartPresenter editor) { selectRange(editor); } }); } }); }
.getFile(pathToOpen) .then( optionalFile -> {
.getFile(Path.valueOf(view.getFileName())) .then( new Operation<Optional<File>>() {
appContext .getWorkspaceRoot() .getFile(file.getLocation()) .then( optional -> {