Search in sources :

Example 1 with PreferencesManager

use of org.eclipse.che.ide.api.preferences.PreferencesManager in project che by eclipse.

the class PreferencesPresenter method onRefreshClicked.

@Override
public void onRefreshClicked() {
    Promise<Map<String, String>> promise = Promises.resolve(null);
    for (final PreferencesManager preferencesManager : managers) {
        promise = promise.thenPromise(new Function<Map<String, String>, Promise<Map<String, String>>>() {

            @Override
            public Promise<Map<String, String>> apply(Map<String, String> arg) throws FunctionException {
                return preferencesManager.loadPreferences().catchError(new Operation<PromiseError>() {

                    @Override
                    public void apply(PromiseError error) throws OperationException {
                        notificationManagerProvider.get().notify(locale.unableToLoadPreference(), error.getMessage(), FAIL, FLOAT_MODE);
                    }
                });
            }
        });
    }
    /**
         * Revert changes on every preference page
         */
    promise.then(new Operation<Map<String, String>>() {

        @Override
        public void apply(Map<String, String> arg) throws OperationException {
            for (PreferencePagePresenter p : PreferencesPresenter.this.preferences) {
                p.revertChanges();
            }
        }
    });
}
Also used : Function(org.eclipse.che.api.promises.client.Function) PromiseError(org.eclipse.che.api.promises.client.PromiseError) PreferencePagePresenter(org.eclipse.che.ide.api.preferences.PreferencePagePresenter) HashMap(java.util.HashMap) Map(java.util.Map) PreferencesManager(org.eclipse.che.ide.api.preferences.PreferencesManager) OperationException(org.eclipse.che.api.promises.client.OperationException)

Example 2 with PreferencesManager

use of org.eclipse.che.ide.api.preferences.PreferencesManager in project che by eclipse.

the class PreferencesPresenter method onSaveClicked.

@Override
public void onSaveClicked() {
    for (PreferencePagePresenter preference : preferences) {
        if (preference.isDirty()) {
            preference.storeChanges();
        }
    }
    Promise<Void> promise = Promises.resolve(null);
    final List<PromiseError> promiseErrorList = new ArrayList<>();
    for (final PreferencesManager preferencesManager : managers) {
        promise = promise.thenPromise(new Function<Void, Promise<Void>>() {

            @Override
            public Promise<Void> apply(Void arg) throws FunctionException {
                return preferencesManager.flushPreferences().catchError(new Operation<PromiseError>() {

                    @Override
                    public void apply(PromiseError error) throws OperationException {
                        notificationManagerProvider.get().notify(locale.unableToSavePreference(), error.getMessage(), FAIL, FLOAT_MODE);
                        promiseErrorList.add(error);
                    }
                });
            }
        });
    }
    promise.then(new Operation<Void>() {

        @Override
        public void apply(Void aVoid) throws OperationException {
            if (promiseErrorList.isEmpty()) {
                view.enableSaveButton(false);
            }
        }
    });
}
Also used : Function(org.eclipse.che.api.promises.client.Function) PreferencePagePresenter(org.eclipse.che.ide.api.preferences.PreferencePagePresenter) PromiseError(org.eclipse.che.api.promises.client.PromiseError) ArrayList(java.util.ArrayList) PreferencesManager(org.eclipse.che.ide.api.preferences.PreferencesManager) OperationException(org.eclipse.che.api.promises.client.OperationException)

Aggregations

Function (org.eclipse.che.api.promises.client.Function)2 OperationException (org.eclipse.che.api.promises.client.OperationException)2 PromiseError (org.eclipse.che.api.promises.client.PromiseError)2 PreferencePagePresenter (org.eclipse.che.ide.api.preferences.PreferencePagePresenter)2 PreferencesManager (org.eclipse.che.ide.api.preferences.PreferencesManager)2 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1