public void flush() { currentValue = chain.getValue(subEditor); }
@Override public <Q> boolean visit(EditorContext<Q> ctx) { Q toSet = ctx.getFromModel(); @SuppressWarnings("unchecked") AbstractEditorDelegate<Q, ?> delegate = (AbstractEditorDelegate<Q, ?>) ctx.getEditorDelegate(); if (delegate != null) { delegate.setObject(delegate.ensureMutable(toSet)); delegate.setDirty(false); } ValueAwareEditor<Q> asValue = ctx.asValueAwareEditor(); if (asValue != null) { // Call setValue for ValueAware, non-leaf editors asValue.setValue(toSet); } else { LeafValueEditor<Q> asLeaf = ctx.asLeafValueEditor(); if (asLeaf != null) { // Call setvalue for LeafValueEditors. asLeaf.setValue(toSet); } } // CompositeEditor's setValue should create sub-editors and attach them to // the EditorChain, which will traverse them. Returning true here for a // CompositeEditor would then traverse it twice. See issue 7038. return ctx.asCompositeEditor() == null; } }
@Override public <T> boolean visit(EditorContext<T> ctx) { println(ctx.getAbsolutePath()); data(ctx.getEditedType().getName()); data(ctx.getEditor().getClass().getName()); data("Implements: " // + ctx.asCompositeEditor() == null ? "" : "CompositeEditor " // + ctx.asHasEditorDelegate() == null ? "" : "HasEditorDelegate " // + ctx.asHasEditorErrors() == null ? "" : "HasEditorErrors " // + ctx.asLeafValueEditor() == null ? "" : "LeafValueEditor " // + ctx.asValueAwareEditor() == null ? "" : "ValueAwareEditor "); level++; return true; }
@Override public <Q> void endVisit(EditorContext<Q> ctx) { // Flush ValueAware editors ValueAwareEditor<Q> asValue = ctx.asValueAwareEditor(); AbstractEditorDelegate<?, ?> delegate; if (ctx.getEditorDelegate() == null) { delegate = delegateStack.peek(); } else { delegate = delegateStack.pop(); } assert delegate != null; if (asValue != null) { if (delegate.shouldFlush()) { asValue.flush(); } } // Pull value from LeafValueEditors and update edited object LeafValueEditor<Q> asLeaf = ctx.asLeafValueEditor(); if (delegate.shouldFlush() && asLeaf != null && ctx.canSetInModel()) { ctx.setInModel(asLeaf.getValue()); } }
@Override public <Q> boolean visit(EditorContext<Q> ctx) { @SuppressWarnings("unchecked") AbstractEditorDelegate<Q, ?> delegate = (AbstractEditorDelegate<Q, ?>) ctx.getEditorDelegate(); // Pass in the EditorDelegate HasEditorDelegate<Q> asHasDelegate = ctx.asHasEditorDelegate(); if (asHasDelegate != null) { asHasDelegate.setDelegate(delegate); } // Set the EditorChain CompositeEditor<Q, ?, ?> asComposite = ctx.asCompositeEditor(); if (asComposite != null) { // Various javac generics compilation problems here @SuppressWarnings("rawtypes") EditorChain chain = delegate.getEditorChain(); asComposite.setEditorChain(chain); } return super.visit(ctx); } }
@Override public <T> void endVisit(EditorContext<T> ctx) { toReturn.put(ctx.getAbsolutePath(), ctx.getEditor()); @SuppressWarnings("unchecked") AbstractEditorDelegate<T, ?> delegate = (AbstractEditorDelegate<T, ?>) ctx.getEditorDelegate(); if (delegate != null) { toReturn.put(delegate.getObject(), delegate); } } });
@SuppressWarnings(value = {"rawtypes", "unchecked"}) public void doTraverseSyntheticCompositeEditor(EditorVisitor visitor) { Editor<?> sample = this.asCompositeEditor().createEditorForTraversal(); AbstractEditorDelegate subDelegate = delegate.createComposedDelegate(); delegate.addSubDelegate(subDelegate, path, sample); delegate.getEditorChain().traverse(visitor, subDelegate); }
@Override public <T> void endVisit(EditorContext<T> ctx) { LeafValueEditor<T> editor = ctx.asLeafValueEditor(); if (editor != null) { leafValues.put(editor, editor.getValue()); } @SuppressWarnings("unchecked") AbstractEditorDelegate<T, ?> delegate = (AbstractEditorDelegate<T, ?>) ctx.getEditorDelegate(); if (delegate != null) { dirty |= delegate.isDirty(); } }
@Override public <T> boolean visit(EditorContext<T> ctx) { RequestFactoryEditorDelegate<?, ?> delegate = (RequestFactoryEditorDelegate<?, ?>) ctx.getEditorDelegate(); if (delegate != null) { delegate.setRequestContext(request); } Editor<T> editor = ctx.getEditor(); if (editor instanceof HasRequestContext) { ((HasRequestContext<T>) editor).setRequestContext(request); } return super.visit(ctx); } }
/** * Must be called after construction. This is a two-phase initialization so * that ListEditor can assign its list field before any sub-editors might call * {@link ListEditor#getList()} */ void attach() { editors.addAll(editorSource.create(workingCopy.size(), 0)); for (int i = 0, j = workingCopy.size(); i < j; i++) { chain.attach(workingCopy.get(i), editors.get(i)); } }
public static DelegateMap of(EditorDriver<?> driver, KeyMethod key) { final DelegateMap toReturn = new DelegateMap(key); driver.accept(new EditorVisitor() { @Override public <T> void endVisit(EditorContext<T> ctx) { toReturn.put(ctx.getAbsolutePath(), ctx.getEditor()); @SuppressWarnings("unchecked") AbstractEditorDelegate<T, ?> delegate = (AbstractEditorDelegate<T, ?>) ctx.getEditorDelegate(); if (delegate != null) { toReturn.put(delegate.getObject(), delegate); } } }); return toReturn; }
/** * Produce a string representation of the Editor hierarchy being controlled by * {@code driver}. */ public static String toString(EditorDriver<?> driver) { StringBuilder sb = new StringBuilder(); driver.accept(new EditorHierarchyPrinter(sb)); return sb.toString(); }
@Override public <Q> boolean visit(EditorContext<Q> ctx) { EditorDelegate<Q> editorDelegate = ctx.getEditorDelegate(); if (editorDelegate != null) { delegateStack.push((AbstractEditorDelegate<?, ?>) editorDelegate); } return true; } }
@Override public T set(int index, T element) { T toReturn = workingCopy.set(index, element); chain.attach(element, editors.get(index)); return toReturn; }
void flush() { for (int i = 0, j = workingCopy.size(); i < j; i++) { E subEditor = editors.get(i); T value = chain.getValue(subEditor); // Use of object-identity intentional if (workingCopy.get(i) != value) { workingCopy.set(i, value); } } backing.clear(); backing.addAll(workingCopy); }