@Override
public void doAction(UndoableEvent event) {
Widget itemToHold = (Widget) event.getData("itemToHold");
Object obj = event.getData("memory");
if (obj instanceof FBFormItem) {
FBFormItem itemToPaste = (FBFormItem) obj;
itemToPaste = itemToPaste.cloneItem();
if (itemToHold == null) {
getFormDisplay().add(itemToPaste);
} else {
if (itemToHold instanceof LayoutFormItem) {
LayoutFormItem parentPanel = (LayoutFormItem) itemToHold;
parentPanel.add(itemToPaste);
} else if (itemToHold instanceof HasOneWidget) {
HasOneWidget parentPanel = (HasOneWidget) itemToHold;
parentPanel.setWidget(itemToPaste);
} else if (itemToHold instanceof HasWidgets) {
HasWidgets parentPanel = (HasWidgets) itemToHold;
parentPanel.add(itemToPaste);
}
}
bus.fireEvent(new FormItemAddedEvent(itemToPaste, itemToHold == null ? getFormDisplay() : itemToHold));
}
}
@Override
public void onEvent(UndoableEvent event) { }
@Override
public void undoAction(UndoableEvent event) {
FBFormItem itemToHold = (FBFormItem) event.getData("itemToHold");
Object obj = event.getData("memory");
if (itemToHold != null && obj instanceof FBFormItem) {
FBFormItem itemToPaste = (FBFormItem) obj;
itemToPaste.removeFromParent();
bus.fireEvent(new FormItemRemovedEvent(itemToPaste));
}
}
});
}