Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master' into Release_4.4.0
Browse files Browse the repository at this point in the history
  • Loading branch information
John-Holt-Tessella committed May 25, 2018
2 parents 4b69d85 + e52d855 commit 546960a
Show file tree
Hide file tree
Showing 12 changed files with 166 additions and 501 deletions.
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
package uk.ac.stfc.isis.ibex.configserver.configuration;


import uk.ac.stfc.isis.ibex.configserver.AlarmState;
import uk.ac.stfc.isis.ibex.epics.observing.BaseObserver;
import uk.ac.stfc.isis.ibex.epics.observing.ForwardingObservable;
import uk.ac.stfc.isis.ibex.epics.switching.ObservableFactory;
import uk.ac.stfc.isis.ibex.epics.switching.OnInstrumentSwitch;
import uk.ac.stfc.isis.ibex.instrument.InstrumentUtils;
import uk.ac.stfc.isis.ibex.instrument.channels.BooleanChannel;
import uk.ac.stfc.isis.ibex.instrument.channels.DefaultChannel;
import uk.ac.stfc.isis.ibex.instrument.channels.EnumChannel;
import uk.ac.stfc.isis.ibex.logger.IsisLog;
import uk.ac.stfc.isis.ibex.model.ModelObject;

/**
Expand All @@ -19,79 +22,115 @@ public class BannerItem extends ModelObject {

private String name;
private String pv;
private String type;
private BannerItemState true_state;
private BannerItemState false_state;
private BannerItemState unknown_state;
private BannerItemState currentState;
private Boolean local = true;

private String currentValue = null;
private AlarmState currentAlarmState = AlarmState.UNDEFINED;

private ObservableFactory obsFactory = null;
private ForwardingObservable<Boolean> pvObservable;
private static final ObservableFactory OBSERVABLE_FACTORY = new ObservableFactory(OnInstrumentSwitch.CLOSE);
private ForwardingObservable<String> pvObservable;
private ForwardingObservable<AlarmState> alarmObservable;

/**
* Creates an observable for the PV holding the current state of this banner
* item.
*/
public void createPVObservable() {
obsFactory = new ObservableFactory(OnInstrumentSwitch.CLOSE);

pvObservable = obsFactory.getSwitchableObservable(new BooleanChannel(),
InstrumentUtils.addPrefix(this.pv));
pvObservable.addObserver(stateAdapter);
String pv = this.pv;
if (local) {
pv = InstrumentUtils.addPrefix(pv);
}

pvObservable = OBSERVABLE_FACTORY.getSwitchableObservable(new DefaultChannel(), pv);
alarmObservable = OBSERVABLE_FACTORY.getSwitchableObservable(new EnumChannel<>(AlarmState.class), pv + ".SEVR");
pvObservable.addObserver(valueAdapter);
alarmObservable.addObserver(alarmAdapter);
}

private final BaseObserver<Boolean> stateAdapter = new BaseObserver<Boolean>() {
private final BaseObserver<String> valueAdapter = new BaseObserver<String>() {

@Override
public void onValue(String value) {
setCurrentValue(value);
}

@Override
public void onError(Exception e) {
setCurrentValue(null);
IsisLog.getLogger(getClass()).error("Exception in banner item state adapter: " + e.getMessage());
}

@Override
public void onConnectionStatus(boolean isConnected) {
if (!isConnected) {
setCurrentValue(null);
}
}
};

private final BaseObserver<AlarmState> alarmAdapter = new BaseObserver<AlarmState>() {

@Override
public void onValue(Boolean value) {
setCurrentState(value);
public void onValue(AlarmState alarm) {
setCurrentAlarm(alarm);
}

@Override
public void onError(Exception e) {
setCurrentState(null);
setCurrentAlarm(AlarmState.INVALID);
IsisLog.getLogger(getClass()).error("Exception in banner item state adapter: " + e.getMessage());
}

@Override
public void onConnectionStatus(boolean isConnected) {
if (!isConnected) {
setCurrentState(null);
setCurrentAlarm(AlarmState.INVALID);
}
}
};

/**
* Returns the display name of this banner item.
* @return the display name of this banner item.
*/
public String name() {
return this.name;
return name;
}

/**
* Returns the current value of this banner item.
* @return the current value of this banner item.
*/
public String value() {
return currentValue;
}

/**
* Returns the alarm status of this banner item.
* @return the alarm status of this banner item.
*/
public AlarmState alarm() {
return currentAlarmState;
}

/**
* Returns the display specification for the banner item in its current
* state.
* Sets the current state of the property based on the PV value and fires a
* property change for listeners.
*
* @return the current state
* @param value the state value of the property.
*/
public BannerItemState getCurrentState() {
return currentState;
public synchronized void setCurrentValue(String value) {
firePropertyChange("value", this.currentValue, this.currentValue = value);
}

/**
* Sets the current state of the property based on the PV value and fires a
* property change for listeners.
*
* @param value the state value of the property.
*/
public void setCurrentState(Boolean value) {
BannerItemState newState;
if (value == null) {
newState = this.unknown_state;
} else {
if (value) {
newState = this.true_state;
} else {
newState = this.false_state;
}
}
firePropertyChange("currentState", this.currentState, this.currentState = newState);
public synchronized void setCurrentAlarm(AlarmState alarm) {
firePropertyChange("alarm", this.currentAlarmState, this.currentAlarmState = alarm);
}

}

This file was deleted.

3 changes: 2 additions & 1 deletion base/uk.ac.stfc.isis.ibex.ui.banner/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ Require-Bundle: org.eclipse.ui,
uk.ac.stfc.isis.ibex.epics;bundle-version="1.0.0",
uk.ac.stfc.isis.ibex.instrument;bundle-version="1.0.0",
uk.ac.stfc.isis.ibex.managermode;bundle-version="1.0.0",
uk.ac.stfc.isis.ibex.dae
uk.ac.stfc.isis.ibex.dae,
uk.ac.stfc.isis.ibex.configserver
Bundle-RequiredExecutionEnvironment: JavaSE-1.7
Bundle-ActivationPolicy: lazy
Export-Package: uk.ac.stfc.isis.ibex.ui.banner;uses:="org.eclipse.jface.resource,org.eclipse.ui.plugin,org.osgi.framework",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ public final class IndicatorColours {
public static final Color RED = SWTResourceManager.getColor(255, 0, 0);
public static final Color GREEN = SWTResourceManager.getColor(75, 150, 75);
public static final Color BLACK = SWTResourceManager.getColor(0, 0, 0);
public static final Color DEFAULT = SWTResourceManager.getColor(255, 0, 255);
public static final Color PURPLE = SWTResourceManager.getColor(255, 0, 255);
public static final Color ORANGE = SWTResourceManager.getColor(255, 120, 50);

private IndicatorColours() {
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,12 @@

import org.eclipse.swt.graphics.Color;

import uk.ac.stfc.isis.ibex.configserver.AlarmState;
import uk.ac.stfc.isis.ibex.configserver.configuration.BannerItem;
import uk.ac.stfc.isis.ibex.configserver.configuration.BannerItemState;
import uk.ac.stfc.isis.ibex.model.ModelObject;
import uk.ac.stfc.isis.ibex.model.SettableUpdatedValue;
import uk.ac.stfc.isis.ibex.model.UpdatedValue;
import uk.ac.stfc.isis.ibex.ui.banner.indicators.IndicatorColours;
import uk.ac.stfc.isis.ibex.ui.banner.indicators.IndicatorModel;

/**
Expand All @@ -37,57 +38,92 @@
*/
public class BannerItemModel extends ModelObject implements IndicatorModel {

private SettableUpdatedValue<String> text;
private SettableUpdatedValue<Color> color;
private SettableUpdatedValue<Boolean> availability;
private BannerItemViewState converter;

private final SettableUpdatedValue<String> text = new SettableUpdatedValue<>();
private final SettableUpdatedValue<Boolean> availability = new SettableUpdatedValue<>(true);
private final SettableUpdatedValue<Color> colour = new SettableUpdatedValue<>(IndicatorColours.BLACK);

private final BannerItem item;

private static final int MAX_TEXT_LENGTH = 30;
private static final String ELIPSES = "...";

/**
* Instantiates model and converter.
*
* @param item the banner item being observed
*/
public BannerItemModel(BannerItem item) {
converter = new BannerItemViewState(item);
text = new SettableUpdatedValue<>();
color = new SettableUpdatedValue<>();
availability = new SettableUpdatedValue<>(true);
public BannerItemModel(final BannerItem item) {
this.item = item;

item.addPropertyChangeListener(new PropertyChangeListener() {

@Override
public void propertyChange(PropertyChangeEvent evt) {
if (evt.getPropertyName().equals("currentState")) {
BannerItemState newstate = (BannerItemState) evt.getNewValue();
converter.setState(newstate);
update();
}
public void propertyChange(final PropertyChangeEvent evt) {
update();
}
});

update();
}

private synchronized void update() {
updateText();
updateColour();
}

private synchronized void updateText() {
String setText;

if (item.value() == null) {
setText = item.name() + " (disconnected)";
} else {
setText = item.name() + ": " + item.value();
}

if (setText.length() > MAX_TEXT_LENGTH) {
setText = setText.substring(0, MAX_TEXT_LENGTH - ELIPSES.length()) + ELIPSES;
}
text.setValue(setText);
}

private synchronized void updateColour() {
Color colour;
AlarmState alarm = item.alarm();

if (alarm == AlarmState.MAJOR) {
colour = IndicatorColours.RED;
} else if (alarm == AlarmState.MINOR) {
colour = IndicatorColours.ORANGE;
} else if (alarm == AlarmState.UNDEFINED || alarm == AlarmState.INVALID) {
colour = IndicatorColours.PURPLE;
} else {
colour = IndicatorColours.BLACK;
}

this.colour.setValue(colour);
}

/**
* Updates the display parameters of the status message in the GUI upon
* state change of the banner item.
* @return the text of this banner item.
*/
public void update() {
text.setValue(converter.getMessage());
color.setValue(converter.color());
}
@Override
public UpdatedValue<String> text() {
return text;
}

@Override
public UpdatedValue<String> text() {
return text;
}
/**
* @return the colour of this banner item.
*/
@Override
public UpdatedValue<Color> color() {
return colour;
}

@Override
public UpdatedValue<Color> color() {
return color;
}
/**
* @return the availability of this banner item.
*/
@Override
public UpdatedValue<Boolean> availability() {
return availability;
}

@Override
public UpdatedValue<Boolean> availability() {
return availability;
}
}
Loading

0 comments on commit 546960a

Please sign in to comment.