Skip to content

Commit

Permalink
Add informative messages to the loaders it will helpful for error det… (
Browse files Browse the repository at this point in the history
#8613)

* Add informative messages to the loaders it will helpful for error detection

Signed-off-by: Vitalii Parfonov <vparfonov@redhat.com>
  • Loading branch information
vparfonov authored Feb 7, 2018
1 parent 083960e commit 9bd0d1c
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 87 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,32 +14,23 @@
import com.google.gwt.core.client.Scheduler;
import com.google.inject.Inject;
import com.google.inject.Singleton;
import org.eclipse.che.api.promises.client.Operation;
import org.eclipse.che.api.promises.client.OperationException;
import org.eclipse.che.api.promises.client.PromiseError;
import org.eclipse.che.ide.api.app.AppContext;
import org.eclipse.che.ide.api.editor.EditorAgent;
import org.eclipse.che.ide.api.editor.EditorPartPresenter;
import org.eclipse.che.ide.api.editor.OpenEditorCallbackImpl;
import org.eclipse.che.ide.api.editor.text.LinearRange;
import org.eclipse.che.ide.api.editor.texteditor.TextEditor;
import org.eclipse.che.ide.api.resources.Container;
import org.eclipse.che.ide.api.resources.File;
import org.eclipse.che.ide.api.resources.Project;
import org.eclipse.che.ide.api.resources.Resource;
import org.eclipse.che.ide.api.resources.SyntheticFile;
import org.eclipse.che.ide.api.resources.VirtualFile;
import org.eclipse.che.ide.ext.java.client.navigation.service.JavaNavigationService;
import org.eclipse.che.ide.ext.java.client.resource.SourceFolderMarker;
import org.eclipse.che.ide.ext.java.client.util.JavaUtil;
import org.eclipse.che.ide.ext.java.shared.JarEntry;
import org.eclipse.che.ide.ext.java.shared.dto.ClassContent;
import org.eclipse.che.ide.ext.java.shared.dto.Region;
import org.eclipse.che.ide.ext.java.shared.dto.model.CompilationUnit;
import org.eclipse.che.ide.ext.java.shared.dto.model.Member;
import org.eclipse.che.ide.resource.Path;
import org.eclipse.che.ide.ui.loaders.request.LoaderFactory;
import org.eclipse.che.ide.ui.loaders.request.MessageLoader;
import org.eclipse.che.ide.util.loging.Log;

/**
Expand All @@ -54,7 +45,6 @@ public class FileStructurePresenter implements FileStructure.ActionDelegate {
private final JavaNavigationService javaNavigationService;
private final AppContext context;
private final EditorAgent editorAgent;
private final MessageLoader loader;

private TextEditor activeEditor;
private boolean showInheritedMembers;
Expand All @@ -65,13 +55,11 @@ public FileStructurePresenter(
FileStructure view,
JavaNavigationService javaNavigationService,
AppContext context,
EditorAgent editorAgent,
LoaderFactory loaderFactory) {
EditorAgent editorAgent) {
this.view = view;
this.javaNavigationService = javaNavigationService;
this.context = context;
this.editorAgent = editorAgent;
this.loader = loaderFactory.newLoader();
this.view.setDelegate(this);
}

Expand All @@ -81,9 +69,6 @@ public FileStructurePresenter(
* @param editorPartPresenter the active editor
*/
public void show(EditorPartPresenter editorPartPresenter) {
loader.show();
view.setTitle(editorPartPresenter.getEditorInput().getFile().getName());

if (!(editorPartPresenter instanceof TextEditor)) {
Log.error(getClass(), "Open Declaration support only TextEditor as editor");
return;
Expand All @@ -103,26 +88,18 @@ public void show(EditorPartPresenter editorPartPresenter) {
}

final String fqn = JavaUtil.resolveFQN((Container) srcFolder.get(), (Resource) file);

javaNavigationService
.getCompilationUnit(project.get().getLocation(), fqn, showInheritedMembers)
.then(
new Operation<CompilationUnit>() {
@Override
public void apply(CompilationUnit unit) throws OperationException {
view.setStructure(unit, showInheritedMembers);
showInheritedMembers = !showInheritedMembers;
loader.hide();
view.show();
}
unit -> {
view.setTitle(editorPartPresenter.getEditorInput().getFile().getName());
view.setStructure(unit, showInheritedMembers);
view.show();
showInheritedMembers = !showInheritedMembers;
})
.catchError(
new Operation<PromiseError>() {
@Override
public void apply(PromiseError arg) throws OperationException {
Log.error(FileStructurePresenter.class, arg.getMessage());
loader.hide();
}
arg -> {
Log.error(FileStructurePresenter.class, arg.getMessage());
});
}
}
Expand All @@ -143,52 +120,43 @@ public void actionPerformed(final Member member) {
javaNavigationService
.getEntry(project.get().getLocation(), member.getLibId(), member.getRootPath())
.then(
new Operation<JarEntry>() {
@Override
public void apply(final JarEntry entry) throws OperationException {
javaNavigationService
.getContent(
project.get().getLocation(),
member.getLibId(),
Path.valueOf(entry.getPath()))
.then(
new Operation<ClassContent>() {
@Override
public void apply(ClassContent content) throws OperationException {
final String clazz =
entry.getName().substring(0, entry.getName().indexOf('.'));
final VirtualFile file =
new SyntheticFile(entry.getName(), clazz, content.getContent());
editorAgent.openEditor(
file,
new OpenEditorCallbackImpl() {
@Override
public void onEditorOpened(EditorPartPresenter editor) {
setCursor(editor, member.getFileRegion().getOffset());
}
});
}
});
}
entry -> {
javaNavigationService
.getContent(
project.get().getLocation(),
member.getLibId(),
Path.valueOf(entry.getPath()))
.then(
content -> {
final String clazz =
entry.getName().substring(0, entry.getName().indexOf('.'));
final VirtualFile file =
new SyntheticFile(entry.getName(), clazz, content.getContent());
editorAgent.openEditor(
file,
new OpenEditorCallbackImpl() {
@Override
public void onEditorOpened(EditorPartPresenter editor) {
setCursor(editor, member.getFileRegion().getOffset());
}
});
});
});
} else {
context
.getWorkspaceRoot()
.getFile(member.getRootPath())
.then(
new Operation<Optional<File>>() {
@Override
public void apply(Optional<File> file) throws OperationException {
if (file.isPresent()) {
editorAgent.openEditor(
file.get(),
new OpenEditorCallbackImpl() {
@Override
public void onEditorOpened(EditorPartPresenter editor) {
setCursor(editor, member.getFileRegion().getOffset());
}
});
}
file -> {
if (file.isPresent()) {
editorAgent.openEditor(
file.get(),
new OpenEditorCallbackImpl() {
@Override
public void onEditorOpened(EditorPartPresenter editor) {
setCursor(editor, member.getFileRegion().getOffset());
}
});
}
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,7 @@ public Promise<CompilationUnit> getCompilationUnit(
return requestFactory
.createGetRequest(url)
.header(ACCEPT, APPLICATION_JSON)
.loader(loaderFactory.newLoader("Getting information about ..."))
.send(unmarshallerFactory.newUnmarshaller(CompilationUnit.class));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@
import org.eclipse.che.ide.rest.DtoUnmarshallerFactory;
import org.eclipse.che.ide.rest.StringUnmarshaller;
import org.eclipse.che.ide.ui.loaders.request.LoaderFactory;
import org.eclipse.che.ide.ui.loaders.request.MessageLoader;

/**
* @author Dmitry Shnurenko
Expand All @@ -54,8 +53,8 @@ final class RefactoringServiceClientImpl implements RefactoringServiceClient {
private final AsyncRequestFactory asyncRequestFactory;
private final DtoUnmarshallerFactory unmarshallerFactory;
private final AppContext appContext;
private final LoaderFactory loaderFactory;
private final String pathToService;
private final MessageLoader loader;

@Inject
public RefactoringServiceClientImpl(
Expand All @@ -66,7 +65,7 @@ public RefactoringServiceClientImpl(
this.asyncRequestFactory = asyncRequestFactory;
this.unmarshallerFactory = unmarshallerFactory;
this.appContext = appContext;
this.loader = loaderFactory.newLoader();
this.loaderFactory = loaderFactory;
this.pathToService = "/java/refactoring/";
}

Expand All @@ -79,7 +78,7 @@ public Promise<String> createMoveRefactoring(final CreateMoveRefactoring moveRef
moveRefactoring)
.header(ACCEPT, TEXT_PLAIN)
.header(CONTENT_TYPE, APPLICATION_JSON)
.loader(loader)
.loader(loaderFactory.newLoader("Prepare for move refactoring ..."))
.send(new StringUnmarshaller());
}

Expand All @@ -92,7 +91,7 @@ public Promise<RenameRefactoringSession> createRenameRefactoring(
.createPostRequest(url, settings)
.header(ACCEPT, APPLICATION_JSON)
.header(CONTENT_TYPE, APPLICATION_JSON)
.loader(loader)
.loader(loaderFactory.newLoader("Prepare for rename refactoring ..."))
.send(unmarshallerFactory.newUnmarshaller(RenameRefactoringSession.class));
}

Expand All @@ -106,7 +105,7 @@ public Promise<RefactoringResult> applyLinkedModeRename(
.createPostRequest(url, refactoringApply)
.header(ACCEPT, APPLICATION_JSON)
.header(CONTENT_TYPE, APPLICATION_JSON)
.loader(loader)
.loader(loaderFactory.newLoader("Apply linked mode rename refactoring ..."))
.send(unmarshallerFactory.newUnmarshaller(RefactoringResult.class));
}

Expand All @@ -119,7 +118,7 @@ public Promise<RefactoringStatus> setDestination(final ReorgDestination destinat
.createPostRequest(url, destination)
.header(ACCEPT, APPLICATION_JSON)
.header(CONTENT_TYPE, APPLICATION_JSON)
.loader(loader)
.loader(loaderFactory.newLoader("Set move refactoring destination..."))
.send(unmarshallerFactory.newUnmarshaller(RefactoringStatus.class));
}

Expand All @@ -133,7 +132,7 @@ public Promise<Void> setMoveSettings(final MoveSettings settings) {
.createPostRequest(url, settings)
.header(ACCEPT, APPLICATION_JSON)
.header(CONTENT_TYPE, APPLICATION_JSON)
.loader(loader)
.loader(loaderFactory.newLoader("Set move refactoring settings ..."))
.send();
}

Expand All @@ -146,7 +145,7 @@ public Promise<ChangeCreationResult> createChange(final RefactoringSession sessi
.createPostRequest(url, session)
.header(ACCEPT, APPLICATION_JSON)
.header(CONTENT_TYPE, APPLICATION_JSON)
.loader(loader)
.loader(loaderFactory.newLoader("Creating refactoring changes"))
.send(unmarshallerFactory.newUnmarshaller(ChangeCreationResult.class));
}

Expand All @@ -159,7 +158,7 @@ public Promise<RefactoringPreview> getRefactoringPreview(final RefactoringSessio
.createPostRequest(url, session)
.header(ACCEPT, APPLICATION_JSON)
.header(CONTENT_TYPE, APPLICATION_JSON)
.loader(loader)
.loader(loaderFactory.newLoader("Getting preview ..."))
.send(unmarshallerFactory.newUnmarshaller(RefactoringPreview.class));
}

Expand All @@ -172,7 +171,7 @@ public Promise<RefactoringResult> applyRefactoring(final RefactoringSession sess
.createPostRequest(url, session)
.header(ACCEPT, APPLICATION_JSON)
.header(CONTENT_TYPE, APPLICATION_JSON)
.loader(loader)
.loader(loaderFactory.newLoader("Apply refactoring ... "))
.send(unmarshallerFactory.newUnmarshaller(RefactoringResult.class));
}

Expand All @@ -185,7 +184,7 @@ public Promise<Void> changeChangeEnabledState(final ChangeEnabledState state) {
.createPostRequest(url, state)
.header(ACCEPT, APPLICATION_JSON)
.header(CONTENT_TYPE, APPLICATION_JSON)
.loader(loader)
.loader(loaderFactory.newLoader("Choosing some change ..."))
.send();
}

Expand All @@ -198,7 +197,7 @@ public Promise<ChangePreview> getChangePreview(final RefactoringChange change) {
.createPostRequest(url, change)
.header(ACCEPT, APPLICATION_JSON)
.header(CONTENT_TYPE, APPLICATION_JSON)
.loader(loader)
.loader(loaderFactory.newLoader("Get refactoring change preview"))
.send(unmarshallerFactory.newUnmarshaller(ChangePreview.class));
}

Expand All @@ -212,7 +211,7 @@ public Promise<RefactoringStatus> validateNewName(final ValidateNewName newName)
.createPostRequest(url, newName)
.header(ACCEPT, APPLICATION_JSON)
.header(CONTENT_TYPE, APPLICATION_JSON)
.loader(loader)
.loader(loaderFactory.newLoader("Validates new name ..."))
.send(unmarshallerFactory.newUnmarshaller(RefactoringStatus.class));
}

Expand All @@ -226,7 +225,7 @@ public Promise<Void> setRenameSettings(final RenameSettings settings) {
.createPostRequest(url, settings)
.header(ACCEPT, APPLICATION_JSON)
.header(CONTENT_TYPE, APPLICATION_JSON)
.loader(loader)
.loader(loaderFactory.newLoader("Set rename refactoring settings"))
.send();
}

Expand All @@ -238,6 +237,9 @@ public Promise<Void> reindexProject(String projectPath) {
+ "reindex?projectpath="
+ encodePath(valueOf(projectPath));

return asyncRequestFactory.createGetRequest(url).loader(loader).send();
return asyncRequestFactory
.createGetRequest(url)
.loader(loaderFactory.newLoader("Reindexing project ..."))
.send();
}
}

0 comments on commit 9bd0d1c

Please sign in to comment.