use of org.csstudio.opibuilder.properties.IWidgetPropertyChangeHandler in project yamcs-studio by yamcs.
the class AbstractBoolControlEditPart method registerCommonPropertyChangeHandlers.
/**
* Registers property change handlers for the properties defined in
* {@link AbstractBoolWidgetModel}. This method is provided for the convenience
* of subclasses, which can call this method in their implementation of
* {@link #registerPropertyChangeHandlers()}.
*/
@Override
protected void registerCommonPropertyChangeHandlers() {
configureButtonListener((AbstractBoolControlFigure) getFigure());
super.registerCommonPropertyChangeHandlers();
// toggle button
final IWidgetPropertyChangeHandler toggleHandler = new IWidgetPropertyChangeHandler() {
@Override
public boolean handleChange(final Object oldValue, final Object newValue, final IFigure refreshableFigure) {
AbstractBoolControlFigure figure = (AbstractBoolControlFigure) refreshableFigure;
figure.setToggle((Boolean) newValue);
return true;
}
};
getWidgetModel().getProperty(AbstractBoolControlModel.PROP_TOGGLE_BUTTON).addPropertyChangeListener(new PropertyChangeListener() {
@Override
public void propertyChange(PropertyChangeEvent evt) {
toggleHandler.handleChange(evt.getOldValue(), evt.getNewValue(), getFigure());
}
});
// setPropertyChangeHandler(AbstractBoolControlModel.PROP_TOGGLE_BUTTON, handler);
// show confirm dialog
IWidgetPropertyChangeHandler handler = new IWidgetPropertyChangeHandler() {
@Override
public boolean handleChange(final Object oldValue, final Object newValue, final IFigure refreshableFigure) {
AbstractBoolControlFigure figure = (AbstractBoolControlFigure) refreshableFigure;
figure.setShowConfirmDialog(getWidgetModel().getShowConfirmDialog());
return true;
}
};
setPropertyChangeHandler(AbstractBoolControlModel.PROP_CONFIRM_DIALOG, handler);
// confirm tip
handler = new IWidgetPropertyChangeHandler() {
@Override
public boolean handleChange(final Object oldValue, final Object newValue, final IFigure refreshableFigure) {
AbstractBoolControlFigure figure = (AbstractBoolControlFigure) refreshableFigure;
figure.setConfirmTip((String) newValue);
return true;
}
};
setPropertyChangeHandler(AbstractBoolControlModel.PROP_CONFIRM_TIP, handler);
// password
handler = new IWidgetPropertyChangeHandler() {
@Override
public boolean handleChange(final Object oldValue, final Object newValue, final IFigure refreshableFigure) {
AbstractBoolControlFigure figure = (AbstractBoolControlFigure) refreshableFigure;
figure.setPassword((String) newValue);
return true;
}
};
setPropertyChangeHandler(AbstractBoolControlModel.PROP_PASSWORD, handler);
// enabled. WidgetBaseEditPart will force the widget as disabled in edit model,
// which is not the case for the bool control widget
IWidgetPropertyChangeHandler enableHandler = new IWidgetPropertyChangeHandler() {
@Override
public boolean handleChange(final Object oldValue, final Object newValue, final IFigure refreshableFigure) {
AbstractBoolControlFigure figure = (AbstractBoolControlFigure) refreshableFigure;
figure.setEnabled((Boolean) newValue);
return true;
}
};
setPropertyChangeHandler(AbstractBoolControlModel.PROP_ENABLED, enableHandler);
}
use of org.csstudio.opibuilder.properties.IWidgetPropertyChangeHandler in project yamcs-studio by yamcs.
the class AbstractPolyEditPart method registerPropertyChangeHandlers.
/**
* {@inheritDoc}
*/
@Override
protected void registerPropertyChangeHandlers() {
super.registerPropertyChangeHandlers();
// points
IWidgetPropertyChangeHandler pointsHandler = new IWidgetPropertyChangeHandler() {
@Override
public boolean handleChange(final Object oldValue, final Object newValue, final IFigure refreshableFigure) {
Polyline polyline = (Polyline) refreshableFigure;
PointList points = (PointList) newValue;
if (points.size() != polyline.getPoints().size()) {
anchorMap = null;
// delete connections on deleted points
if (points.size() < polyline.getPoints().size()) {
for (ConnectionModel conn : getWidgetModel().getSourceConnections()) {
if (Integer.parseInt(conn.getSourceTerminal()) >= points.size()) {
conn.disconnect();
}
}
for (ConnectionModel conn : getWidgetModel().getTargetConnections()) {
if (Integer.parseInt(conn.getTargetTerminal()) >= points.size()) {
conn.disconnect();
}
}
}
}
// deselect the widget (this refreshes the polypoint drag
// handles)
int selectionState = getSelected();
setSelected(EditPart.SELECTED_NONE);
polyline.setPoints(points);
doRefreshVisuals(polyline);
// restore the selection state
setSelected(selectionState);
return false;
}
};
setPropertyChangeHandler(AbstractPolyModel.PROP_POINTS, pointsHandler);
IWidgetPropertyChangeHandler rotationHandler = new IWidgetPropertyChangeHandler() {
@Override
public boolean handleChange(Object oldValue, Object newValue, IFigure figure) {
getWidgetModel().setPoints(PointsUtil.rotatePoints(getWidgetModel().getOriginalPoints().getCopy(), (Double) newValue), false);
return false;
}
};
setPropertyChangeHandler(AbstractPolyModel.PROP_ROTATION, rotationHandler);
}
use of org.csstudio.opibuilder.properties.IWidgetPropertyChangeHandler in project yamcs-studio by yamcs.
the class AbstractShapeEditPart method registerPropertyChangeHandlers.
/**
* {@inheritDoc}
*/
@Override
protected void registerPropertyChangeHandlers() {
// line width
IWidgetPropertyChangeHandler lineWidthHandler = new IWidgetPropertyChangeHandler() {
public boolean handleChange(final Object oldValue, final Object newValue, final IFigure refreshableFigure) {
Shape shape = (Shape) refreshableFigure;
if (((Integer) newValue).equals(0))
shape.setOutline(false);
else {
shape.setOutline(true);
shape.setLineWidth((Integer) newValue);
}
return true;
}
};
setPropertyChangeHandler(AbstractShapeModel.PROP_LINE_WIDTH, lineWidthHandler);
// line style
IWidgetPropertyChangeHandler handler = new IWidgetPropertyChangeHandler() {
@Override
public boolean handleChange(final Object oldValue, final Object newValue, final IFigure refreshableFigure) {
Shape shape = (Shape) refreshableFigure;
shape.setLineStyle(LineStyle.values()[(Integer) newValue].getStyle());
return true;
}
};
setPropertyChangeHandler(AbstractShapeModel.PROP_LINE_STYLE, handler);
handler = new IWidgetPropertyChangeHandler() {
@Override
public boolean handleChange(Object oldValue, Object newValue, IFigure figure) {
if (GraphicsUtil.useAdvancedGraphics())
((Shape) figure).setAntialias(((Boolean) newValue) ? SWT.ON : null);
return false;
}
};
setPropertyChangeHandler(AbstractShapeModel.PROP_ANTIALIAS, handler);
handler = new IWidgetPropertyChangeHandler() {
@Override
public boolean handleChange(Object oldValue, Object newValue, IFigure figure) {
if (GraphicsUtil.useAdvancedGraphics()) {
if ((Integer) newValue < 255)
((Shape) figure).setAlpha((Integer) newValue);
else
((Shape) figure).setAlpha(null);
}
return false;
}
};
setPropertyChangeHandler(AbstractShapeModel.PROP_ALPHA, handler);
}
use of org.csstudio.opibuilder.properties.IWidgetPropertyChangeHandler in project yamcs-studio by yamcs.
the class ArcEditpart method registerPropertyChangeHandlers.
@Override
protected void registerPropertyChangeHandlers() {
super.registerPropertyChangeHandlers();
// fill
IWidgetPropertyChangeHandler fillHandler = new IWidgetPropertyChangeHandler() {
@Override
public boolean handleChange(final Object oldValue, final Object newValue, final IFigure refreshableFigure) {
ArcFigure figure = (ArcFigure) refreshableFigure;
figure.setFill((Boolean) newValue);
return true;
}
};
setPropertyChangeHandler(ArcModel.PROP_FILL, fillHandler);
// start angle
IWidgetPropertyChangeHandler startAngleHandler = new IWidgetPropertyChangeHandler() {
@Override
public boolean handleChange(final Object oldValue, final Object newValue, final IFigure refreshableFigure) {
ArcFigure figure = (ArcFigure) refreshableFigure;
figure.setStartAngle((Integer) newValue);
return true;
}
};
setPropertyChangeHandler(ArcModel.PROP_START_ANGLE, startAngleHandler);
// total angle
IWidgetPropertyChangeHandler totalAngleHandler = new IWidgetPropertyChangeHandler() {
@Override
public boolean handleChange(final Object oldValue, final Object newValue, final IFigure refreshableFigure) {
ArcFigure figure = (ArcFigure) refreshableFigure;
figure.setTotalAngle((Integer) newValue);
return true;
}
};
setPropertyChangeHandler(ArcModel.PROP_TOTAL_ANGLE, totalAngleHandler);
}
use of org.csstudio.opibuilder.properties.IWidgetPropertyChangeHandler in project yamcs-studio by yamcs.
the class ArrayEditPart method registerPropertyChangeHandlers.
@Override
protected void registerPropertyChangeHandlers() {
IWidgetPropertyChangeHandler handler = new IWidgetPropertyChangeHandler() {
@Override
public boolean handleChange(Object oldValue, Object newValue, IFigure figure) {
for (AbstractWidgetModel child : getWidgetModel().getAllChildren()) {
child.setEnabled((Boolean) newValue);
}
return true;
}
};
setPropertyChangeHandler(AbstractWidgetModel.PROP_ENABLED, handler);
handler = new IWidgetPropertyChangeHandler() {
@Override
public boolean handleChange(Object oldValue, Object newValue, IFigure figure) {
VType value = (VType) newValue;
if (value instanceof VNumberArray) {
Object wrappedArray = VTypeHelper.getWrappedArray(((VNumberArray) 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(ArrayModel.PROP_PVVALUE, handler);
getWidgetModel().getProperty(ArrayModel.PROP_PVNAME).addPropertyChangeListener(new PropertyChangeListener() {
@Override
public void propertyChange(PropertyChangeEvent evt) {
updatePropSheet();
}
});
handler = new IWidgetPropertyChangeHandler() {
@Override
public boolean handleChange(Object oldValue, Object newValue, IFigure figure) {
registerLoadPVDataTypeListener();
return false;
}
};
setPropertyChangeHandler(ArrayModel.PROP_PVNAME, handler);
getWidgetModel().getProperty(ArrayModel.PROP_DATA_TYPE).addPropertyChangeListener(new PropertyChangeListener() {
@Override
public void propertyChange(PropertyChangeEvent evt) {
initValueArray();
}
});
handler = new IWidgetPropertyChangeHandler() {
@Override
public boolean handleChange(Object oldValue, Object newValue, IFigure figure) {
updateWidgetSize();
return false;
}
};
setPropertyChangeHandler(ArrayModel.PROP_BORDER_STYLE, handler);
setPropertyChangeHandler(ArrayModel.PROP_BORDER_WIDTH, handler);
handler = new IWidgetPropertyChangeHandler() {
@Override
public boolean handleChange(Object oldValue, Object newValue, IFigure figure) {
getArrayFigure().setArrayLength((Integer) newValue);
return false;
}
};
setPropertyChangeHandler(ArrayModel.PROP_ARRAY_LENGTH, handler);
handler = new IWidgetPropertyChangeHandler() {
@Override
public boolean handleChange(Object oldValue, Object newValue, IFigure figure) {
((ArrayFigure) figure).setSpinnerWidth((Integer) newValue);
keepElementSize = true;
getWidgetModel().setSize(((ArrayFigure) figure).getPreferredSize());
keepElementSize = false;
return false;
}
};
setPropertyChangeHandler(ArrayModel.PROP_SPINNER_WIDTH, handler);
handler = new IWidgetPropertyChangeHandler() {
@Override
public boolean handleChange(Object oldValue, Object newValue, IFigure figure) {
((ArrayFigure) figure).setHorizontal((Boolean) newValue);
keepElementSize = true;
getWidgetModel().setSize(((ArrayFigure) figure).getPreferredSize());
keepElementSize = false;
return false;
}
};
setPropertyChangeHandler(ArrayModel.PROP_HORIZONTAL, handler);
handler = new IWidgetPropertyChangeHandler() {
@Override
public boolean handleChange(Object oldValue, Object newValue, IFigure figure) {
((ArrayFigure) figure).setShowScrollbar((Boolean) newValue);
keepElementSize = true;
getWidgetModel().setSize(((ArrayFigure) figure).getPreferredSize());
keepElementSize = false;
return false;
}
};
setPropertyChangeHandler(ArrayModel.PROP_SHOW_SCROLLBAR, handler);
handler = new IWidgetPropertyChangeHandler() {
@Override
public boolean handleChange(Object oldValue, Object newValue, IFigure figure) {
((ArrayFigure) figure).setShowSpinner((Boolean) newValue);
keepElementSize = true;
getWidgetModel().setSize(((ArrayFigure) figure).getPreferredSize());
keepElementSize = false;
return false;
}
};
setPropertyChangeHandler(ArrayModel.PROP_SHOW_SPINNER, handler);
PropertyChangeListener sizePropertyChangeListener = new PropertyChangeListener() {
@Override
public void propertyChange(PropertyChangeEvent evt) {
if (getWidgetModel().getChildren().size() == 0 || inSync || keepElementSize)
return;
Dimension elementSize = getArrayFigure().getElementSize();
int delta = (Integer) evt.getNewValue() - (Integer) evt.getOldValue();
int elementWH = elementSize.height;
String propID = evt.getPropertyName();
boolean elementCountDirection = false;
if (getWidgetModel().isHorizontal() && propID.equals(AbstractWidgetModel.PROP_WIDTH)) {
elementWH = elementSize.width;
elementCountDirection = true;
} else if (!getWidgetModel().isHorizontal() && propID.equals(AbstractWidgetModel.PROP_HEIGHT)) {
elementWH = elementSize.height;
elementCountDirection = true;
}
if (elementCountDirection) {
int deltaElementsCount = Math.round((float) delta / elementWH);
int idelta = (Math.round((float) delta / elementWH) * elementWH);
setPropertyValue(propID, (Integer) evt.getOldValue() + idelta, false);
int visibleElementsCount = getArrayFigure().getVisibleElementsCount() + deltaElementsCount;
setPropertyValue(ArrayModel.PROP_VISIBLE_ELEMENTS_COUNT, visibleElementsCount);
setValue(getValue());
} else {
int wh;
if (propID.equals(AbstractWidgetModel.PROP_WIDTH))
wh = getArrayFigure().getElementSize().width;
else
wh = getArrayFigure().getElementSize().height;
syncAllChildrenProperties(propID, wh + delta);
}
}
};
getWidgetModel().getProperty(AbstractWidgetModel.PROP_WIDTH).addPropertyChangeListener(sizePropertyChangeListener);
getWidgetModel().getProperty(AbstractWidgetModel.PROP_HEIGHT).addPropertyChangeListener(sizePropertyChangeListener);
}
Aggregations