Search in sources :

Example 1 with IdentityRequestEventHandler

use of org.whole.lang.events.IdentityRequestEventHandler in project whole by wholeplatform.

the class InterpreterOperation method interpret.

public static IBindingScope interpret(IEntity program, IBindingManager args, Reader in, Writer out) {
    final Set<String> newIONames = new HashSet<String>();
    if (!args.wIsSet("reader"))
        newIONames.add("reader");
    if (!args.wIsSet("writer"))
        newIONames.add("writer");
    if (!args.wIsSet("printWriter"))
        newIONames.add("printWriter");
    final InterpreterOperation op = new InterpreterOperation(args, null);
    if (in != null)
        args.wDefValue("reader", op.reader = in);
    else if (!args.wIsSet("reader")) {
        args.wDefValue("reader", (Object) null);
        args.wGet("reader").wAddRequestEventHandler(new IdentityRequestEventHandler() {

            public Object notifyRequested(IEntity source, FeatureDescriptor feature, Object value) {
                return op.getReader();
            }
        });
    } else
        op.reader = (Reader) args.wGetValue("reader");
    if (out != null) {
        args.wDefValue("writer", op.writer = out);
        if (out instanceof PrintWriter)
            args.wDefValue("printWriter", op.printWriter = (PrintWriter) out);
    } else {
        if (args.wIsSet("printWriter"))
            op.writer = op.printWriter = (PrintWriter) args.wGetValue("printWriter");
        if (args.wIsSet("writer"))
            op.writer = (Writer) args.wGetValue("writer");
        else {
            args.wDefValue("writer", (Object) null);
            args.wGet("writer").wAddRequestEventHandler(new IdentityRequestEventHandler() {

                public Object notifyRequested(IEntity source, FeatureDescriptor feature, Object value) {
                    return op.getWriter();
                }
            });
        }
    }
    if (!args.wIsSet("printWriter")) {
        args.wDefValue("printWriter", (Object) null);
        args.wGet("printWriter").wAddRequestEventHandler(new IdentityRequestEventHandler() {

            public Object notifyRequested(IEntity source, FeatureDescriptor feature, Object value) {
                return op.getPrintWriter();
            }
        });
    }
    op.stagedVisit(program);
    for (String name : newIONames) args.wUnset(name);
    op.flushPrintWriter();
    return op.getResultsScope();
}
Also used : IEntity(org.whole.lang.model.IEntity) FeatureDescriptor(org.whole.lang.reflect.FeatureDescriptor) PrintWriter(java.io.PrintWriter) Writer(java.io.Writer) OutputStreamWriter(java.io.OutputStreamWriter) HashSet(java.util.HashSet) IdentityRequestEventHandler(org.whole.lang.events.IdentityRequestEventHandler) PrintWriter(java.io.PrintWriter)

Example 2 with IdentityRequestEventHandler

use of org.whole.lang.events.IdentityRequestEventHandler in project whole by wholeplatform.

the class AbstractPersistenceProvider method initBindingManager.

public void initBindingManager() {
    bindingManager.wDefValue("inputStream", (Object) null);
    bindingManager.wGet("inputStream").wAddRequestEventHandler(new IdentityRequestEventHandler() {

        public Object notifyRequested(IEntity source, FeatureDescriptor feature, Object value) {
            return inputStream;
        }
    });
    bindingManager.wDefValue("outputStream", (Object) null);
    bindingManager.wGet("outputStream").wAddRequestEventHandler(new IdentityRequestEventHandler() {

        public Object notifyRequested(IEntity source, FeatureDescriptor feature, Object value) {
            return outputStream;
        }
    });
    if (!bindingManager.wIsSet("encoding")) {
        bindingManager.wDefValue("encoding", "");
        bindingManager.wGet("encoding").wAddRequestEventHandler(new IdentityRequestEventHandler() {

            public String notifyRequested(IEntity source, FeatureDescriptor feature, String value) {
                return getDefaultEncoding();
            }
        });
    }
}
Also used : IEntity(org.whole.lang.model.IEntity) FeatureDescriptor(org.whole.lang.reflect.FeatureDescriptor) IdentityRequestEventHandler(org.whole.lang.events.IdentityRequestEventHandler)

Example 3 with IdentityRequestEventHandler

use of org.whole.lang.events.IdentityRequestEventHandler 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)

Example 4 with IdentityRequestEventHandler

use of org.whole.lang.events.IdentityRequestEventHandler in project whole by wholeplatform.

the class E4ResourceBindingsContributor method addResourceBindings.

public void addResourceBindings(final IBindingManager bm) {
    if (bm.wIsSet("debug#breakpointsEnabled") && bm.wIsSet("eclipse#eclipseContext")) {
        try {
            EPartService partService = ((IEclipseContext) bm.wGetValue("eclipse#eclipseContext")).get(EPartService.class);
            final MPart debugPart = partService.findPart(IE4UIConstants.DEBUG_PART_ID);
            if (debugPart == null)
                return;
            IEntity breakpointsEnabled = BindingManagerFactory.instance.createValue(true);
            breakpointsEnabled.wAddRequestEventHandler(new IdentityRequestEventHandler() {

                public boolean notifyRequested(IEntity source, FeatureDescriptor feature, boolean value) {
                    Map<String, String> persistedState = debugPart.getPersistedState();
                    return Boolean.valueOf(persistedState.get("debug#breakpointsEnabled"));
                }
            });
            bm.wSet("debug#breakpointsEnabled", breakpointsEnabled);
        } catch (Exception e) {
        }
    }
}
Also used : MPart(org.eclipse.e4.ui.model.application.ui.basic.MPart) IEntity(org.whole.lang.model.IEntity) FeatureDescriptor(org.whole.lang.reflect.FeatureDescriptor) EPartService(org.eclipse.e4.ui.workbench.modeling.EPartService) IEclipseContext(org.eclipse.e4.core.contexts.IEclipseContext) Map(java.util.Map) IdentityRequestEventHandler(org.whole.lang.events.IdentityRequestEventHandler)

Aggregations

IdentityRequestEventHandler (org.whole.lang.events.IdentityRequestEventHandler)4 IEntity (org.whole.lang.model.IEntity)4 FeatureDescriptor (org.whole.lang.reflect.FeatureDescriptor)4 OutputStreamWriter (java.io.OutputStreamWriter)1 PrintWriter (java.io.PrintWriter)1 Writer (java.io.Writer)1 HashSet (java.util.HashSet)1 Map (java.util.Map)1 IEclipseContext (org.eclipse.e4.core.contexts.IEclipseContext)1 MPart (org.eclipse.e4.ui.model.application.ui.basic.MPart)1 EPartService (org.eclipse.e4.ui.workbench.modeling.EPartService)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