private Promise<Void> synchronizeChanges(Container container, ResourceDelta... deltas) { Promise<?> promise; if (deltas == null || deltas.length == 0) { promise = container.synchronize(); } else { stream(deltas).filter(this::isProjectCreatedDelta).forEach(this::notifyProjectCreated); promise = container.synchronize(deltas); } return promise.thenPromise(this::resolvePromise); }
private void onProjectUpdated(String projectPath) { appContext .getWorkspaceRoot() .getContainer(projectPath) .then( container -> { if (container.isPresent()) { container.get().synchronize(); } }); }
@Override public void onFileSelected(Path path) { view.hidePopup(); appContext .getWorkspaceRoot() .getFile(path) .then( optFile -> { if (optFile.isPresent()) { editorAgent.openEditor(optFile.get()); } }); }
/** {@inheritDoc} */ @Override public Optional<Resource> getParentWithMarker(String type) { checkArgument(!isNullOrEmpty(type), "Invalid marker type occurred"); if (getMarker(type).isPresent()) { return Optional.<Resource>of(this); } Container optParent = getParent(); while (optParent != null) { Container parent = optParent; final Optional<Marker> marker = parent.getMarker(type); if (marker.isPresent()) { return Optional.<Resource>of(parent); } optParent = parent.getParent(); } return absent(); }
private String getPackageQualifier(String packageFragment) { final Optional<Resource> srcFolder = parent.getParentWithMarker(SourceFolderMarker.ID); if (!srcFolder.isPresent() && isNullOrEmpty(packageFragment)) { return "\n"; } final Path path = parent.getLocation().removeFirstSegments(srcFolder.get().getLocation().segmentCount()); String packageFQN = path.toString().replace('/', '.'); if (!packageFragment.isEmpty()) { packageFQN = packageFQN.isEmpty() ? packageFragment : packageFQN + '.' + packageFragment; } if (!packageFQN.isEmpty()) { return "package " + packageFQN + ";\n\n"; } else { return "\n"; } }
Promise<SourceEstimation> estimate(Container container, String projectType) { checkArgument(projectType != null, "Null project type"); checkArgument(!projectType.isEmpty(), "Empty project type"); return ps.estimate(container.getLocation(), projectType); }
@Override public void search(final String text) { final Path startPoint = isNullOrEmpty(view.getPathToSearch()) ? defaultStartPoint : Path.valueOf(view.getPathToSearch()); appContext .getWorkspaceRoot() .getContainer(startPoint) .then( optionalContainer -> { if (!optionalContainer.isPresent()) { view.showErrorMessage("Path '" + startPoint + "' doesn't exist"); return; } final Container container = optionalContainer.get(); QueryExpression queryExpression = container.createSearchQueryExpression(view.getFileMask(), prepareQuery(text)); queryExpression.setMaxItems(SEARCH_RESULT_ITEMS); container .search(queryExpression) .then( result -> { view.close(); findResultPresenter.handleResponse(result, queryExpression, text); }); }); }
private void updateResource(String path) { appContext .getWorkspaceRoot() .getResource(Path.valueOf(path)) .then( resource -> { if (resource.isPresent()) { resource.get().getProject().synchronize(); resource.get().getParent().synchronize(); } }); }
appContext .getWorkspaceRoot() .newProject() .withBody(dataObject) .send() .getContainer(Path.valueOf(path)) .then( optContainer -> { if (container.getResourceType() == PROJECT) { StatusNotification notification = notificationManager.notify( callback.onFailure(error.getCause()); }); } else if (container.getResourceType() == FOLDER) { ((Folder) container) .toProject() appContext .getWorkspaceRoot() .newProject() .withBody(dataObject) .send()
private void createSourceFile( final String nameWithoutExtension, String packageFragment, final String content) { if (!isNullOrEmpty(packageFragment)) { parent .newFolder(packageFragment.replace('.', '/')) .then( pkg -> { pkg.newFile(nameWithoutExtension + ".java", content) .then( file -> { editorAgent.openEditor(file); eventBus.fireEvent(new RevealResourceEvent(file)); }); }); } else { parent .newFile(nameWithoutExtension + ".java", content) .then( file -> { editorAgent.openEditor(file); eventBus.fireEvent(new RevealResourceEvent(file)); }); } } }
private Promise<Optional<Container>> getContainerByPath(Path path) { return ProjectTreeChangeHandler.this.appContext.getWorkspaceRoot().getContainer(path); }
/** {@inheritDoc} */ @Override public Optional<Project> getRelatedProject() { if (this instanceof Project) { return of((Project) this); } Container optionalParent = getParent(); if (optionalParent == null) { return absent(); } Container parent = optionalParent; while (!(parent instanceof Project)) { optionalParent = parent.getParent(); if (optionalParent == null) { return absent(); } parent = optionalParent; } return of((Project) parent); }
@Override protected Promise<List<Node>> getChildrenImpl() { checkState(getData() instanceof Container, "Not a container"); return ((Container) getData()) .getChildren() .then( (Function<Resource[], List<Node>>) children -> { if (children == null || children.length == 0) { return NO_CHILDREN; } final List<Node> nodes = newArrayListWithExpectedSize(children.length); for (Resource child : children) { nodes.add(createNode(child)); } return unmodifiableList(nodes); }); }
private void onAccepted(String value) { final Resource resource = appContext.getResource(); checkState(resource instanceof Container, "Parent should be a container"); ((Container) resource) .newFolder(value.replace('.', '/')) .then( new Operation<Folder>() { @Override public void apply(Folder pkg) throws OperationException { eventBus.fireEvent(new RevealResourceEvent(pkg)); } }) .catchError( new Operation<PromiseError>() { @Override public void apply(PromiseError error) throws OperationException { dialogFactory .createMessageDialog( coreLocalizationConstant.invalidName(), error.getMessage(), null) .show(); } }); }
final void createFile(String nameWithoutExtension) { final String name = getExtension().isEmpty() ? nameWithoutExtension : nameWithoutExtension + '.' + getExtension(); Resource resource = appContext.getResource(); if (!(resource instanceof Container)) { final Container parent = resource.getParent(); checkState(parent != null, "Parent should be a container"); resource = parent; } ((Container) resource) .newFile(name, getDefaultContent()) .then( new Operation<File>() { @Override public void apply(File newFile) throws OperationException { editorAgentProvider.get().openEditor(newFile); eventBus.fireEvent(new RevealResourceEvent(newFile)); } }) .catchError( new Operation<PromiseError>() { @Override public void apply(PromiseError error) throws OperationException { notificationManager.notify( "Failed to create resource", error.getMessage(), FAIL, FLOAT_MODE); } }); }
@Nullable @Override public String apply(@Nullable Resource input) { checkNotNull(input); final Container parent = input.getParent(); if (parent == null) { return ""; } return appContext.getProjectsRoot().append(parent.getLocation()).toString(); } };
private void estimateAndSetAttributes() { appContext .getWorkspaceRoot() .getContainer(dataObject.getPath()) .then( new Operation<Optional<Container>>() {
/** * Returns the root project for the given file resource or null if the file isn't in a project. */ @Nullable public static Container getRootProject(final File file) { Container project = file.getProject(); Container parentProject = file.getParent(); while (parentProject != null) { project = parentProject; parentProject = parentProject.getParent(); } return project; }
protected Promise<Container> getNonEmptyPackage(final Container source) { return source .getChildren() .thenPromise( new Function<Resource[], Promise<Container>>() { @Override public Promise<Container> apply(Resource[] children) throws FunctionException { if (children == null || children.length == 0 || children.length > 1) { return promises.resolve(source); } else { final Resource resource = children[0]; if (resource.getResourceType() == FILE) { return promises.resolve(source); } else { return getNonEmptyPackage((Container) resource); } } } }) .catchErrorPromise( new Function<PromiseError, Promise<Container>>() { @Override public Promise<Container> apply(PromiseError arg) throws FunctionException { return promises.resolve(source); } }); } }