Skip to content

Commit

Permalink
#1814: Synchronize project instead of parent directory
Browse files Browse the repository at this point in the history
Project synchronization is more reasonable, because we also retrieve project properties and with actual values we can redraw project correctly in the UI.
  • Loading branch information
Vladyslav Zhukovskii authored and Anatoliy Bazko committed Aug 1, 2016
1 parent 02bbab6 commit 53177c2
Showing 1 changed file with 15 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
package org.eclipse.che.ide.ext.java.client.project.classpath;

import com.google.common.base.Optional;
import com.google.common.base.Preconditions;
import com.google.inject.Inject;
import com.google.inject.Singleton;
import com.google.web.bindery.event.shared.EventBus;
Expand All @@ -22,7 +21,6 @@
import org.eclipse.che.api.promises.client.PromiseError;
import org.eclipse.che.ide.api.app.AppContext;
import org.eclipse.che.ide.api.notification.NotificationManager;
import org.eclipse.che.ide.api.resources.Container;
import org.eclipse.che.ide.api.resources.Project;
import org.eclipse.che.ide.api.resources.Resource;
import org.eclipse.che.ide.dto.DtoFactory;
Expand All @@ -35,6 +33,7 @@
import java.util.List;
import java.util.Set;

import static com.google.common.base.Preconditions.checkState;
import static org.eclipse.che.ide.api.notification.StatusNotification.DisplayMode.EMERGE_MODE;
import static org.eclipse.che.ide.api.notification.StatusNotification.Status.FAIL;
import static org.eclipse.che.ide.ext.java.shared.ClasspathEntryKind.LIBRARY;
Expand Down Expand Up @@ -105,9 +104,11 @@ public Promise<Void> updateClasspath() {

final Resource resource = appContext.getResource();

Preconditions.checkState(resource != null);
checkState(resource != null);

final Optional<Project> project = resource.getRelatedProject();
final Optional<Project> optProject = resource.getRelatedProject();

checkState(optProject.isPresent());

final List<ClasspathEntryDto> entries = new ArrayList<>();
for (String path : libs) {
Expand All @@ -122,16 +123,20 @@ public Promise<Void> updateClasspath() {
for (String path : projects) {
entries.add(dtoFactory.createDto(ClasspathEntryDto.class).withPath(path).withEntryKind(PROJECT));
}
Promise<Void> promise = classpathUpdater.setRawClasspath(project.get().getLocation().toString(), entries);

final Project project = optProject.get();

Promise<Void> promise = classpathUpdater.setRawClasspath(project.getLocation().toString(), entries);

promise.then(new Operation<Void>() {
@Override
public void apply(Void arg) throws OperationException {
eventBus.fireEvent(new ClasspathChangedEvent(project.get().getLocation().toString(), entries));
final Optional<Container> parent = resource.getParent();
if (parent.isPresent()) {
parent.get().synchronize();
}
project.synchronize().then(new Operation<Resource[]>() {
@Override
public void apply(Resource[] arg) throws OperationException {
eventBus.fireEvent(new ClasspathChangedEvent(project.getLocation().toString(), entries));
}
});
}
}).catchError(new Operation<PromiseError>() {
@Override
Expand Down

0 comments on commit 53177c2

Please sign in to comment.