use of org.csstudio.opibuilder.widgets.model.ArrayModel.PROP_SHOW_SPINNER in project yamcs-studio by yamcs.
the class ArrayEditPart method registerPropertyChangeHandlers.
@Override
protected void registerPropertyChangeHandlers() {
IWidgetPropertyChangeHandler handler = (oldValue, newValue, figure) -> {
for (var child : getWidgetModel().getAllChildren()) {
child.setEnabled((Boolean) newValue);
}
return true;
};
setPropertyChangeHandler(AbstractWidgetModel.PROP_ENABLED, handler);
handler = (oldValue, newValue, figure) -> {
var value = (VType) newValue;
if (value instanceof VNumberArray) {
var wrappedArray = VTypeHelper.getWrappedArray((value));
if (wrappedArray != null) {
setValue(wrappedArray);
} else {
setValue(VTypeHelper.getDoubleArray(value));
}
} else {
if (value instanceof VEnum) {
setValue(new String[] { ((VEnum) value).getValue() });
} else if (value instanceof VString) {
setValue(new String[] { ((VString) value).getValue() });
} else if (value instanceof VStringArray) {
setValue(((VStringArray) value).getData().toArray());
} else {
setValue(VTypeHelper.getDoubleArray(value));
}
}
return false;
};
setPropertyChangeHandler(PROP_PVVALUE, handler);
getWidgetModel().getProperty(PROP_PVNAME).addPropertyChangeListener(evt -> updatePropSheet());
handler = (oldValue, newValue, figure) -> {
registerLoadPVDataTypeListener();
return false;
};
setPropertyChangeHandler(PROP_PVNAME, handler);
getWidgetModel().getProperty(PROP_DATA_TYPE).addPropertyChangeListener(evt -> initValueArray());
handler = (oldValue, newValue, figure) -> {
updateWidgetSize();
return false;
};
setPropertyChangeHandler(PROP_BORDER_STYLE, handler);
setPropertyChangeHandler(PROP_BORDER_WIDTH, handler);
handler = (oldValue, newValue, figure) -> {
getArrayFigure().setArrayLength((Integer) newValue);
return false;
};
setPropertyChangeHandler(PROP_ARRAY_LENGTH, handler);
handler = (oldValue, newValue, figure) -> {
((ArrayFigure) figure).setSpinnerWidth((Integer) newValue);
keepElementSize = true;
getWidgetModel().setSize(((ArrayFigure) figure).getPreferredSize());
keepElementSize = false;
return false;
};
setPropertyChangeHandler(PROP_SPINNER_WIDTH, handler);
handler = (oldValue, newValue, figure) -> {
((ArrayFigure) figure).setHorizontal((Boolean) newValue);
keepElementSize = true;
getWidgetModel().setSize(((ArrayFigure) figure).getPreferredSize());
keepElementSize = false;
return false;
};
setPropertyChangeHandler(PROP_HORIZONTAL, handler);
handler = (oldValue, newValue, figure) -> {
((ArrayFigure) figure).setShowScrollbar((Boolean) newValue);
keepElementSize = true;
getWidgetModel().setSize(((ArrayFigure) figure).getPreferredSize());
keepElementSize = false;
return false;
};
setPropertyChangeHandler(PROP_SHOW_SCROLLBAR, handler);
handler = (oldValue, newValue, figure) -> {
((ArrayFigure) figure).setShowSpinner((Boolean) newValue);
keepElementSize = true;
getWidgetModel().setSize(((ArrayFigure) figure).getPreferredSize());
keepElementSize = false;
return false;
};
setPropertyChangeHandler(PROP_SHOW_SPINNER, handler);
PropertyChangeListener sizePropertyChangeListener = evt -> {
if (getWidgetModel().getChildren().size() == 0 || inSync || keepElementSize) {
return;
}
var elementSize = getArrayFigure().getElementSize();
var delta = (Integer) evt.getNewValue() - (Integer) evt.getOldValue();
var elementWH = elementSize.height;
var propID = evt.getPropertyName();
var elementCountDirection = false;
if (getWidgetModel().isHorizontal() && propID.equals(PROP_WIDTH)) {
elementWH = elementSize.width;
elementCountDirection = true;
} else if (!getWidgetModel().isHorizontal() && propID.equals(PROP_HEIGHT)) {
elementWH = elementSize.height;
elementCountDirection = true;
}
if (elementCountDirection) {
var deltaElementsCount = Math.round((float) delta / elementWH);
var idelta = (Math.round((float) delta / elementWH) * elementWH);
setPropertyValue(propID, (Integer) evt.getOldValue() + idelta, false);
var visibleElementsCount = getArrayFigure().getVisibleElementsCount() + deltaElementsCount;
setPropertyValue(PROP_VISIBLE_ELEMENTS_COUNT, visibleElementsCount);
setValue(getValue());
} else {
int wh;
if (propID.equals(PROP_WIDTH)) {
wh = getArrayFigure().getElementSize().width;
} else {
wh = getArrayFigure().getElementSize().height;
}
syncAllChildrenProperties(propID, wh + delta);
}
};
getWidgetModel().getProperty(PROP_WIDTH).addPropertyChangeListener(sizePropertyChangeListener);
getWidgetModel().getProperty(PROP_HEIGHT).addPropertyChangeListener(sizePropertyChangeListener);
}
Aggregations