Skip to content

Commit 546960a

Browse files
Merge remote-tracking branch 'origin/master' into Release_4.4.0
2 parents 4b69d85 + e52d855 commit 546960a

File tree

12 files changed

+166
-501
lines changed

12 files changed

+166
-501
lines changed
Lines changed: 76 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
package uk.ac.stfc.isis.ibex.configserver.configuration;
22

33

4+
import uk.ac.stfc.isis.ibex.configserver.AlarmState;
45
import uk.ac.stfc.isis.ibex.epics.observing.BaseObserver;
56
import uk.ac.stfc.isis.ibex.epics.observing.ForwardingObservable;
67
import uk.ac.stfc.isis.ibex.epics.switching.ObservableFactory;
78
import uk.ac.stfc.isis.ibex.epics.switching.OnInstrumentSwitch;
89
import uk.ac.stfc.isis.ibex.instrument.InstrumentUtils;
9-
import uk.ac.stfc.isis.ibex.instrument.channels.BooleanChannel;
10+
import uk.ac.stfc.isis.ibex.instrument.channels.DefaultChannel;
11+
import uk.ac.stfc.isis.ibex.instrument.channels.EnumChannel;
12+
import uk.ac.stfc.isis.ibex.logger.IsisLog;
1013
import uk.ac.stfc.isis.ibex.model.ModelObject;
1114

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

2023
private String name;
2124
private String pv;
22-
private String type;
23-
private BannerItemState true_state;
24-
private BannerItemState false_state;
25-
private BannerItemState unknown_state;
26-
private BannerItemState currentState;
25+
private Boolean local = true;
26+
27+
private String currentValue = null;
28+
private AlarmState currentAlarmState = AlarmState.UNDEFINED;
2729

28-
private ObservableFactory obsFactory = null;
29-
private ForwardingObservable<Boolean> pvObservable;
30+
private static final ObservableFactory OBSERVABLE_FACTORY = new ObservableFactory(OnInstrumentSwitch.CLOSE);
31+
private ForwardingObservable<String> pvObservable;
32+
private ForwardingObservable<AlarmState> alarmObservable;
3033

3134
/**
3235
* Creates an observable for the PV holding the current state of this banner
3336
* item.
3437
*/
3538
public void createPVObservable() {
36-
obsFactory = new ObservableFactory(OnInstrumentSwitch.CLOSE);
37-
38-
pvObservable = obsFactory.getSwitchableObservable(new BooleanChannel(),
39-
InstrumentUtils.addPrefix(this.pv));
40-
pvObservable.addObserver(stateAdapter);
39+
String pv = this.pv;
40+
if (local) {
41+
pv = InstrumentUtils.addPrefix(pv);
42+
}
43+
44+
pvObservable = OBSERVABLE_FACTORY.getSwitchableObservable(new DefaultChannel(), pv);
45+
alarmObservable = OBSERVABLE_FACTORY.getSwitchableObservable(new EnumChannel<>(AlarmState.class), pv + ".SEVR");
46+
pvObservable.addObserver(valueAdapter);
47+
alarmObservable.addObserver(alarmAdapter);
4148
}
4249

43-
private final BaseObserver<Boolean> stateAdapter = new BaseObserver<Boolean>() {
50+
private final BaseObserver<String> valueAdapter = new BaseObserver<String>() {
51+
52+
@Override
53+
public void onValue(String value) {
54+
setCurrentValue(value);
55+
}
56+
57+
@Override
58+
public void onError(Exception e) {
59+
setCurrentValue(null);
60+
IsisLog.getLogger(getClass()).error("Exception in banner item state adapter: " + e.getMessage());
61+
}
62+
63+
@Override
64+
public void onConnectionStatus(boolean isConnected) {
65+
if (!isConnected) {
66+
setCurrentValue(null);
67+
}
68+
}
69+
};
70+
71+
private final BaseObserver<AlarmState> alarmAdapter = new BaseObserver<AlarmState>() {
4472

4573
@Override
46-
public void onValue(Boolean value) {
47-
setCurrentState(value);
74+
public void onValue(AlarmState alarm) {
75+
setCurrentAlarm(alarm);
4876
}
4977

5078
@Override
5179
public void onError(Exception e) {
52-
setCurrentState(null);
80+
setCurrentAlarm(AlarmState.INVALID);
81+
IsisLog.getLogger(getClass()).error("Exception in banner item state adapter: " + e.getMessage());
5382
}
5483

5584
@Override
5685
public void onConnectionStatus(boolean isConnected) {
5786
if (!isConnected) {
58-
setCurrentState(null);
87+
setCurrentAlarm(AlarmState.INVALID);
5988
}
6089
}
6190
};
6291

92+
/**
93+
* Returns the display name of this banner item.
94+
* @return the display name of this banner item.
95+
*/
6396
public String name() {
64-
return this.name;
97+
return name;
98+
}
99+
100+
/**
101+
* Returns the current value of this banner item.
102+
* @return the current value of this banner item.
103+
*/
104+
public String value() {
105+
return currentValue;
106+
}
107+
108+
/**
109+
* Returns the alarm status of this banner item.
110+
* @return the alarm status of this banner item.
111+
*/
112+
public AlarmState alarm() {
113+
return currentAlarmState;
65114
}
66115

67116
/**
68-
* Returns the display specification for the banner item in its current
69-
* state.
117+
* Sets the current state of the property based on the PV value and fires a
118+
* property change for listeners.
70119
*
71-
* @return the current state
120+
* @param value the state value of the property.
72121
*/
73-
public BannerItemState getCurrentState() {
74-
return currentState;
122+
public synchronized void setCurrentValue(String value) {
123+
firePropertyChange("value", this.currentValue, this.currentValue = value);
75124
}
76-
125+
77126
/**
78127
* Sets the current state of the property based on the PV value and fires a
79128
* property change for listeners.
80129
*
81130
* @param value the state value of the property.
82131
*/
83-
public void setCurrentState(Boolean value) {
84-
BannerItemState newState;
85-
if (value == null) {
86-
newState = this.unknown_state;
87-
} else {
88-
if (value) {
89-
newState = this.true_state;
90-
} else {
91-
newState = this.false_state;
92-
}
93-
}
94-
firePropertyChange("currentState", this.currentState, this.currentState = newState);
132+
public synchronized void setCurrentAlarm(AlarmState alarm) {
133+
firePropertyChange("alarm", this.currentAlarmState, this.currentAlarmState = alarm);
95134
}
96135

97136
}

base/uk.ac.stfc.isis.ibex.configserver/src/uk/ac/stfc/isis/ibex/configserver/configuration/BannerItemState.java

Lines changed: 0 additions & 27 deletions
This file was deleted.

base/uk.ac.stfc.isis.ibex.ui.banner/META-INF/MANIFEST.MF

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ Require-Bundle: org.eclipse.ui,
1313
uk.ac.stfc.isis.ibex.epics;bundle-version="1.0.0",
1414
uk.ac.stfc.isis.ibex.instrument;bundle-version="1.0.0",
1515
uk.ac.stfc.isis.ibex.managermode;bundle-version="1.0.0",
16-
uk.ac.stfc.isis.ibex.dae
16+
uk.ac.stfc.isis.ibex.dae,
17+
uk.ac.stfc.isis.ibex.configserver
1718
Bundle-RequiredExecutionEnvironment: JavaSE-1.7
1819
Bundle-ActivationPolicy: lazy
1920
Export-Package: uk.ac.stfc.isis.ibex.ui.banner;uses:="org.eclipse.jface.resource,org.eclipse.ui.plugin,org.osgi.framework",

base/uk.ac.stfc.isis.ibex.ui.banner/src/uk/ac/stfc/isis/ibex/ui/banner/indicators/IndicatorColours.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@ public final class IndicatorColours {
2626
public static final Color RED = SWTResourceManager.getColor(255, 0, 0);
2727
public static final Color GREEN = SWTResourceManager.getColor(75, 150, 75);
2828
public static final Color BLACK = SWTResourceManager.getColor(0, 0, 0);
29-
public static final Color DEFAULT = SWTResourceManager.getColor(255, 0, 255);
29+
public static final Color PURPLE = SWTResourceManager.getColor(255, 0, 255);
30+
public static final Color ORANGE = SWTResourceManager.getColor(255, 120, 50);
3031

3132
private IndicatorColours() {
3233
}

base/uk.ac.stfc.isis.ibex.ui.banner/src/uk/ac/stfc/isis/ibex/ui/banner/models/BannerItemModel.java

Lines changed: 73 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,12 @@
2424

2525
import org.eclipse.swt.graphics.Color;
2626

27+
import uk.ac.stfc.isis.ibex.configserver.AlarmState;
2728
import uk.ac.stfc.isis.ibex.configserver.configuration.BannerItem;
28-
import uk.ac.stfc.isis.ibex.configserver.configuration.BannerItemState;
2929
import uk.ac.stfc.isis.ibex.model.ModelObject;
3030
import uk.ac.stfc.isis.ibex.model.SettableUpdatedValue;
3131
import uk.ac.stfc.isis.ibex.model.UpdatedValue;
32+
import uk.ac.stfc.isis.ibex.ui.banner.indicators.IndicatorColours;
3233
import uk.ac.stfc.isis.ibex.ui.banner.indicators.IndicatorModel;
3334

3435
/**
@@ -37,57 +38,92 @@
3738
*/
3839
public class BannerItemModel extends ModelObject implements IndicatorModel {
3940

40-
private SettableUpdatedValue<String> text;
41-
private SettableUpdatedValue<Color> color;
42-
private SettableUpdatedValue<Boolean> availability;
43-
private BannerItemViewState converter;
44-
41+
private final SettableUpdatedValue<String> text = new SettableUpdatedValue<>();
42+
private final SettableUpdatedValue<Boolean> availability = new SettableUpdatedValue<>(true);
43+
private final SettableUpdatedValue<Color> colour = new SettableUpdatedValue<>(IndicatorColours.BLACK);
44+
45+
private final BannerItem item;
46+
47+
private static final int MAX_TEXT_LENGTH = 30;
48+
private static final String ELIPSES = "...";
49+
4550
/**
4651
* Instantiates model and converter.
4752
*
4853
* @param item the banner item being observed
4954
*/
50-
public BannerItemModel(BannerItem item) {
51-
converter = new BannerItemViewState(item);
52-
text = new SettableUpdatedValue<>();
53-
color = new SettableUpdatedValue<>();
54-
availability = new SettableUpdatedValue<>(true);
55+
public BannerItemModel(final BannerItem item) {
56+
this.item = item;
57+
5558
item.addPropertyChangeListener(new PropertyChangeListener() {
56-
5759
@Override
58-
public void propertyChange(PropertyChangeEvent evt) {
59-
if (evt.getPropertyName().equals("currentState")) {
60-
BannerItemState newstate = (BannerItemState) evt.getNewValue();
61-
converter.setState(newstate);
62-
update();
63-
}
60+
public void propertyChange(final PropertyChangeEvent evt) {
61+
update();
6462
}
6563
});
66-
64+
6765
update();
6866
}
67+
68+
private synchronized void update() {
69+
updateText();
70+
updateColour();
71+
}
72+
73+
private synchronized void updateText() {
74+
String setText;
75+
76+
if (item.value() == null) {
77+
setText = item.name() + " (disconnected)";
78+
} else {
79+
setText = item.name() + ": " + item.value();
80+
}
81+
82+
if (setText.length() > MAX_TEXT_LENGTH) {
83+
setText = setText.substring(0, MAX_TEXT_LENGTH - ELIPSES.length()) + ELIPSES;
84+
}
85+
text.setValue(setText);
86+
}
87+
88+
private synchronized void updateColour() {
89+
Color colour;
90+
AlarmState alarm = item.alarm();
91+
92+
if (alarm == AlarmState.MAJOR) {
93+
colour = IndicatorColours.RED;
94+
} else if (alarm == AlarmState.MINOR) {
95+
colour = IndicatorColours.ORANGE;
96+
} else if (alarm == AlarmState.UNDEFINED || alarm == AlarmState.INVALID) {
97+
colour = IndicatorColours.PURPLE;
98+
} else {
99+
colour = IndicatorColours.BLACK;
100+
}
101+
102+
this.colour.setValue(colour);
103+
}
69104

70105
/**
71-
* Updates the display parameters of the status message in the GUI upon
72-
* state change of the banner item.
106+
* @return the text of this banner item.
73107
*/
74-
public void update() {
75-
text.setValue(converter.getMessage());
76-
color.setValue(converter.color());
77-
}
108+
@Override
109+
public UpdatedValue<String> text() {
110+
return text;
111+
}
78112

79-
@Override
80-
public UpdatedValue<String> text() {
81-
return text;
82-
}
113+
/**
114+
* @return the colour of this banner item.
115+
*/
116+
@Override
117+
public UpdatedValue<Color> color() {
118+
return colour;
119+
}
83120

84-
@Override
85-
public UpdatedValue<Color> color() {
86-
return color;
87-
}
121+
/**
122+
* @return the availability of this banner item.
123+
*/
124+
@Override
125+
public UpdatedValue<Boolean> availability() {
126+
return availability;
127+
}
88128

89-
@Override
90-
public UpdatedValue<Boolean> availability() {
91-
return availability;
92-
}
93129
}

0 commit comments

Comments
 (0)