Search in sources :

Example 1 with IHilightable

use of org.whole.lang.ui.editpolicies.IHilightable in project whole by wholeplatform.

the class E4Utils method defineSelectionBindings.

public static void defineSelectionBindings(IBindingManager bm, List<IEntityPart> selectedEntityParts, IEntityPartViewer viewer) {
    IEntity selectedEntities = BindingManagerFactory.instance.createTuple();
    for (IEntityPart selectedEntityPart : selectedEntityParts) selectedEntities.wAdd(selectedEntityPart.getModelEntity());
    if (viewer != null) {
        bm.wDef("self", EntityUtils.getCompoundRoot(viewer.getEntityContents()));
        bm.wDefValue("viewer", viewer);
        IEntityPart focusEntityPart = viewer.getFocusEntityPart();
        bm.wDef("focusEntity", focusEntityPart.getModelEntity());
    }
    bm.wDef("selectedEntities", selectedEntities);
    IEntityIterator<IEntity> iterator = IteratorFactory.childIterator();
    iterator.reset(selectedEntities);
    if (iterator.hasNext()) {
        IEntity focusEntity = iterator.next();
        bm.wDef("primarySelectedEntity", focusEntity);
        if (!bm.wIsSet("focusEntity"))
            bm.wDef("focusEntity", focusEntity);
        IEntityPart primarySelectedEntityPart = selectedEntityParts.get(0);
        if (primarySelectedEntityPart instanceof IHilightable) {
            final IHilightable hilightable = (IHilightable) primarySelectedEntityPart;
            bm.wDefValue("hilightPosition", -1);
            bm.wGet("hilightPosition").wAddRequestEventHandler(new IdentityRequestEventHandler() {

                public int notifyRequested(IEntity source, FeatureDescriptor feature, int value) {
                    return hilightable.getHilightPosition();
                }
            });
        }
        if (primarySelectedEntityPart instanceof ITextualEntityPart) {
            final ITextualEntityPart textualEntityPart = (ITextualEntityPart) primarySelectedEntityPart;
            bm.wDefValue("selectedText", "");
            bm.wGet("selectedText").wAddRequestEventHandler(new IdentityRequestEventHandler() {

                public String notifyRequested(IEntity source, FeatureDescriptor feature, String value) {
                    return textualEntityPart.hasSelectionRange() ? DataTypeUtils.getAsPresentationString(textualEntityPart.getModelEntity()).substring(textualEntityPart.getSelectionStart(), textualEntityPart.getSelectionEnd()) : "";
                }
            });
        }
    }
}
Also used : ITextualEntityPart(org.whole.lang.ui.editparts.ITextualEntityPart) IEntity(org.whole.lang.model.IEntity) FeatureDescriptor(org.whole.lang.reflect.FeatureDescriptor) IHilightable(org.whole.lang.ui.editpolicies.IHilightable) IEntityPart(org.whole.lang.ui.editparts.IEntityPart) IdentityRequestEventHandler(org.whole.lang.events.IdentityRequestEventHandler)

Aggregations

IdentityRequestEventHandler (org.whole.lang.events.IdentityRequestEventHandler)1 IEntity (org.whole.lang.model.IEntity)1 FeatureDescriptor (org.whole.lang.reflect.FeatureDescriptor)1 IEntityPart (org.whole.lang.ui.editparts.IEntityPart)1 ITextualEntityPart (org.whole.lang.ui.editparts.ITextualEntityPart)1 IHilightable (org.whole.lang.ui.editpolicies.IHilightable)1