Search in sources :

Example 1 with JsArrayMixed

use of com.google.gwt.core.client.JsArrayMixed in project che by eclipse.

the class DeleteResourceManager method onConfirm.

private ConfirmCallback onConfirm(final Resource[] resources, final AsyncCallback<Void> callback) {
    return new ConfirmCallback() {

        @Override
        public void accepted() {
            if (resources == null) {
                //sometimes we may occur NPE here while reading length
                callback.onFailure(new IllegalStateException());
                return;
            }
            Promise<?>[] deleteAll = new Promise<?>[resources.length];
            for (int i = 0; i < resources.length; i++) {
                final Resource resource = resources[i];
                deleteAll[i] = resource.delete().catchError(new Operation<PromiseError>() {

                    @Override
                    public void apply(PromiseError error) throws OperationException {
                        notificationManager.notify("Failed to delete '" + resource.getName() + "'", error.getMessage(), FAIL, StatusNotification.DisplayMode.FLOAT_MODE);
                    }
                });
            }
            promiseProvider.all(deleteAll).then(new Operation<JsArrayMixed>() {

                @Override
                public void apply(JsArrayMixed arg) throws OperationException {
                    callback.onSuccess(null);
                }
            });
        }
    };
}
Also used : Promise(org.eclipse.che.api.promises.client.Promise) ConfirmCallback(org.eclipse.che.ide.api.dialogs.ConfirmCallback) JsPromiseError(org.eclipse.che.api.promises.client.js.JsPromiseError) PromiseError(org.eclipse.che.api.promises.client.PromiseError) Resource(org.eclipse.che.ide.api.resources.Resource) Operation(org.eclipse.che.api.promises.client.Operation) JsArrayMixed(com.google.gwt.core.client.JsArrayMixed) OperationException(org.eclipse.che.api.promises.client.OperationException)

Example 2 with JsArrayMixed

use of com.google.gwt.core.client.JsArrayMixed in project rstudio by rstudio.

the class Fold method toJs.

public static JsArray<JsArrayMixed> toJs(ArrayList<Fold> folds) {
    JsArray<JsArrayMixed> results = JavaScriptObject.createArray().cast();
    for (Fold f : folds) {
        JsArrayMixed foldData = JavaScriptObject.createArray().cast();
        foldData.set(0, f.getStartRow());
        foldData.set(1, f.getStartColumn());
        foldData.set(2, f.getEndRow());
        foldData.set(3, f.getEndColumn());
        foldData.set(4, f.getPlaceholder());
        results.push(foldData);
    }
    return results;
}
Also used : AceFold(org.rstudio.studio.client.workbench.views.source.editors.text.ace.AceFold) JsArrayMixed(com.google.gwt.core.client.JsArrayMixed)

Example 3 with JsArrayMixed

use of com.google.gwt.core.client.JsArrayMixed in project rstudio by rstudio.

the class Fold method fromJs.

public static ArrayList<Fold> fromJs(JsArray<JsArrayMixed> folds) {
    ArrayList<Fold> results = new ArrayList<Fold>();
    for (int i = 0; i < folds.length(); i++) {
        JsArrayMixed foldData = folds.get(i);
        results.add(new Fold((int) foldData.getNumber(0), (int) foldData.getNumber(1), (int) foldData.getNumber(2), (int) foldData.getNumber(3), foldData.getString(4)));
    }
    return results;
}
Also used : AceFold(org.rstudio.studio.client.workbench.views.source.editors.text.ace.AceFold) ArrayList(java.util.ArrayList) JsArrayMixed(com.google.gwt.core.client.JsArrayMixed)

Example 4 with JsArrayMixed

use of com.google.gwt.core.client.JsArrayMixed in project che by eclipse.

the class DeleteResourceManager method delete.

/**
     * Deletes the given resources and its descendants in the standard manner from file system.
     * Method requires a confirmation from the user before resource will be removed.
     *
     * @param needConfirmation
     *         true if confirmation is need
     * @param resources
     *         the resources to delete
     * @return the {@link Promise} with void if removal has successfully completed
     * @see #delete(Resource...)
     */
public Promise<Void> delete(boolean needConfirmation, Resource... resources) {
    checkArgument(resources != null, "Null resource occurred");
    checkArgument(resources.length > 0, "No resources were provided to remove");
    final Resource[] filtered = filterDescendants(resources);
    if (!needConfirmation) {
        Promise<?>[] deleteAll = new Promise<?>[resources.length];
        for (int i = 0; i < resources.length; i++) {
            deleteAll[i] = resources[i].delete();
        }
        return promiseProvider.all(deleteAll).then(new Function<JsArrayMixed, Void>() {

            @Override
            public Void apply(JsArrayMixed arg) throws FunctionException {
                return null;
            }
        });
    }
    List<Resource> projectsList = newArrayList();
    for (Resource resource : filtered) {
        if (resource.getResourceType() == PROJECT) {
            projectsList.add(resource);
        }
    }
    Resource[] projects = projectsList.toArray(new Resource[projectsList.size()]);
    if (projectsList.isEmpty()) {
        //if no project were found in nodes list
        return promptUserToDelete(filtered);
    } else if (projects.length < filtered.length) {
        //inform user that we can't delete mixed list of the nodes
        return promiseProvider.reject(JsPromiseError.create(localization.mixedProjectDeleteMessage()));
    } else {
        //delete only project nodes
        return promptUserToDelete(projects);
    }
}
Also used : Promise(org.eclipse.che.api.promises.client.Promise) Resource(org.eclipse.che.ide.api.resources.Resource) FunctionException(org.eclipse.che.api.promises.client.FunctionException) JsArrayMixed(com.google.gwt.core.client.JsArrayMixed)

Example 5 with JsArrayMixed

use of com.google.gwt.core.client.JsArrayMixed in project rstudio by rstudio.

the class DomUtils method splice.

public static JavaScriptObject splice(JavaScriptObject array, int index, int howMany, String... elements) {
    JsArrayMixed args = JavaScriptObject.createArray().cast();
    args.push(index);
    args.push(howMany);
    for (String el : elements) args.push(el);
    return spliceInternal(array, args);
}
Also used : JsArrayMixed(com.google.gwt.core.client.JsArrayMixed) JsArrayString(com.google.gwt.core.client.JsArrayString)

Aggregations

JsArrayMixed (com.google.gwt.core.client.JsArrayMixed)5 Promise (org.eclipse.che.api.promises.client.Promise)2 Resource (org.eclipse.che.ide.api.resources.Resource)2 AceFold (org.rstudio.studio.client.workbench.views.source.editors.text.ace.AceFold)2 JsArrayString (com.google.gwt.core.client.JsArrayString)1 ArrayList (java.util.ArrayList)1 FunctionException (org.eclipse.che.api.promises.client.FunctionException)1 Operation (org.eclipse.che.api.promises.client.Operation)1 OperationException (org.eclipse.che.api.promises.client.OperationException)1 PromiseError (org.eclipse.che.api.promises.client.PromiseError)1 JsPromiseError (org.eclipse.che.api.promises.client.js.JsPromiseError)1 ConfirmCallback (org.eclipse.che.ide.api.dialogs.ConfirmCallback)1