Search in sources :

Example 1 with MessageLoader

use of org.eclipse.che.ide.ui.loaders.request.MessageLoader in project che by eclipse.

the class ProjectExplorerStateComponent method loadState.

@Override
public void loadState(@NotNull JsonObject state) {
    if (state.hasKey(SHOW_HIDDEN_FILES)) {
        projectExplorer.showHiddenFiles(state.getBoolean(SHOW_HIDDEN_FILES));
    }
    JsonArray paths = state.hasKey(PATH_PARAM_ID) ? state.getArray(PATH_PARAM_ID) : Json.createArray();
    if (paths.length() == 0) {
        return;
    }
    Promise<Node> revealPromise = null;
    final MessageLoader loader = loaderFactory.newLoader("Restoring project structure...");
    loader.show();
    for (int i = 0; i < paths.length(); i++) {
        final String path = paths.getString(i);
        if (revealPromise == null) {
            revealPromise = revealer.reveal(Path.valueOf(path), false).thenPromise(new Function<Node, Promise<Node>>() {

                @Override
                public Promise<Node> apply(Node node) throws FunctionException {
                    if (node != null) {
                        projectExplorer.getTree().setExpanded(node, true, false);
                    }
                    return revealer.reveal(Path.valueOf(path), false);
                }
            });
            continue;
        }
        revealPromise.thenPromise(new Function<Node, Promise<Node>>() {

            @Override
            public Promise<Node> apply(Node node) throws FunctionException {
                if (node != null) {
                    projectExplorer.getTree().setExpanded(node, true, false);
                }
                return revealer.reveal(Path.valueOf(path), false);
            }
        }).catchError(new Function<PromiseError, Node>() {

            @Override
            public Node apply(PromiseError error) throws FunctionException {
                Log.info(getClass(), error.getMessage());
                return null;
            }
        });
    }
    if (revealPromise != null) {
        revealPromise.then(new Operation<Node>() {

            @Override
            public void apply(Node node) throws OperationException {
                loader.hide();
            }
        }).catchError(new Operation<PromiseError>() {

            @Override
            public void apply(PromiseError error) throws OperationException {
                loader.hide();
            }
        });
    }
}
Also used : Node(org.eclipse.che.ide.api.data.tree.Node) ResourceNode(org.eclipse.che.ide.resources.tree.ResourceNode) JsonArray(elemental.json.JsonArray) MessageLoader(org.eclipse.che.ide.ui.loaders.request.MessageLoader)

Example 2 with MessageLoader

use of org.eclipse.che.ide.ui.loaders.request.MessageLoader in project che by eclipse.

the class LanguageServerEditorProvider method createEditor.

@Override
public Promise<EditorPartPresenter> createEditor(VirtualFile file) {
    if (file instanceof File) {
        File resource = (File) file;
        Promise<InitializeResult> promise = registry.getOrInitializeServer(resource.getRelatedProject().get().getPath(), resource.getExtension(), resource.getLocation().toString());
        final MessageLoader loader = loaderFactory.newLoader("Initializing Language Server for " + resource.getExtension());
        loader.show();
        return promise.thenPromise(new Function<InitializeResult, Promise<EditorPartPresenter>>() {

            @Override
            public Promise<EditorPartPresenter> apply(InitializeResult arg) throws FunctionException {
                loader.hide();
                return Promises.<EditorPartPresenter>resolve(createEditor(editorConfigurationFactory.build(arg.getCapabilities())));
            }
        });
    }
    return null;
}
Also used : Promise(org.eclipse.che.api.promises.client.Promise) InitializeResult(io.typefox.lsapi.InitializeResult) MessageLoader(org.eclipse.che.ide.ui.loaders.request.MessageLoader) FunctionException(org.eclipse.che.api.promises.client.FunctionException) File(org.eclipse.che.ide.api.resources.File) VirtualFile(org.eclipse.che.ide.api.resources.VirtualFile)

Aggregations

MessageLoader (org.eclipse.che.ide.ui.loaders.request.MessageLoader)2 JsonArray (elemental.json.JsonArray)1 InitializeResult (io.typefox.lsapi.InitializeResult)1 FunctionException (org.eclipse.che.api.promises.client.FunctionException)1 Promise (org.eclipse.che.api.promises.client.Promise)1 Node (org.eclipse.che.ide.api.data.tree.Node)1 File (org.eclipse.che.ide.api.resources.File)1 VirtualFile (org.eclipse.che.ide.api.resources.VirtualFile)1 ResourceNode (org.eclipse.che.ide.resources.tree.ResourceNode)1