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();
}
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();
}
});
}
}
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()) : "";
}
});
}
}
}
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) {
}
}
}
Aggregations