All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.diffplug.common.swt.jface.JFaceRx Maven / Gradle / Ivy

The newest version!
/*
 * Copyright 2020 DiffPlug
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     https://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.diffplug.common.swt.jface;


import com.diffplug.common.base.Preconditions;
import com.diffplug.common.rx.Rx;
import com.diffplug.common.rx.RxBox;
import com.diffplug.common.swt.SwtMisc;
import com.diffplug.common.swt.SwtThread;
import org.eclipse.jface.action.IAction;

/** Utilities that convert JFace events into Rx-friendly Observables. */
public class JFaceRx {
	/**
	 * Returns an `RxBox` for the toggle state of the given action as an RxBox.
	 * 

* Applicable to IAction.AS_CHECK_BOX and AS_RADIO_BUTTON. */ public static @SwtThread RxBox toggle(IAction action) { Preconditions.checkArgument(SwtMisc.flagIsSet(IAction.AS_CHECK_BOX, action.getStyle()) || SwtMisc.flagIsSet(IAction.AS_RADIO_BUTTON, action.getStyle())); RxBox box = RxBox.of(action.isChecked()); action.addPropertyChangeListener(e -> { if ("checked".equals(e.getProperty())) { box.set((Boolean) e.getNewValue()); } }); Rx.subscribe(box, isChecked -> { action.setChecked(isChecked); }); return box; } }





© 2015 - 2025 Weber Informatics LLC | Privacy Policy