use of org.whole.lang.ui.commands.ITextCommand in project whole by wholeplatform.
the class TextualSelectionTool method handleTextRequest.
protected boolean handleTextRequest(TextualRequest edit) {
EditPart target = getFocusedPart();
if (target == null)
return false;
Command command = target.getCommand(edit);
if (command == null || !command.canExecute())
return false;
if (command instanceof ITextCommand) {
ITextCommand textCommand = (ITextCommand) command;
if (transactionCommand == null || !transactionCommand.canMerge(textCommand) || !getDomain().getCommandStack().isDirty()) {
transactionCommand = new TextTransactionCommand();
transactionCommand.setModel((IEntity) target.getModel());
transactionCommand.merge(textCommand);
executeCommand(transactionCommand);
} else
transactionCommand.merge(textCommand);
} else {
resetTransactionCommand();
executeCommand(command);
}
return true;
}
use of org.whole.lang.ui.commands.ITextCommand in project whole by wholeplatform.
the class PasteHandler method execute.
@Override
@Execute
public void execute(@Optional @Named(IServiceConstants.ACTIVE_SELECTION) IBindingManager bm) {
if (bm.wIsSet("viewer") && Clipboard.instance().getInternalOrNativeEntityContents() == null) {
IEntityPartViewer viewer = (IEntityPartViewer) bm.wGetValue("viewer");
if (ClipboardUtils.hasTextFocus(viewer) || ClipboardUtils.hasTextSeletion(viewer)) {
IEntity focusEntity = bm.wGet("focusEntity");
ITextualEntityPart focusPart = (ITextualEntityPart) viewer.getEditPartRegistry().get(focusEntity);
String textContents = Clipboard.instance().getTextContents();
Command command = focusPart.getCommand(TextualRequest.createInsertRequest(textContents));
CommandStack commandStack = viewer.getEditDomain().getCommandStack();
if (command instanceof ITextCommand) {
TextTransactionCommand transactionCommand = new TextTransactionCommand();
transactionCommand.setModel(focusEntity);
transactionCommand.merge((ITextCommand) command);
transactionCommand.setLabel(getLabel(bm));
commandStack.execute(transactionCommand);
} else {
command.setLabel(getLabel(bm) + " text");
commandStack.execute(command);
}
return;
}
}
super.execute(bm);
}
Aggregations