Search in sources :

Example 1 with ITextCommand

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;
}
Also used : ITextCommand(org.whole.lang.ui.commands.ITextCommand) ITextCommand(org.whole.lang.ui.commands.ITextCommand) TextTransactionCommand(org.whole.lang.ui.commands.TextTransactionCommand) Command(org.eclipse.gef.commands.Command) EditPart(org.eclipse.gef.EditPart) TextTransactionCommand(org.whole.lang.ui.commands.TextTransactionCommand)

Example 2 with ITextCommand

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);
}
Also used : CommandStack(org.eclipse.gef.commands.CommandStack) ITextCommand(org.whole.lang.ui.commands.ITextCommand) ITextualEntityPart(org.whole.lang.ui.editparts.ITextualEntityPart) IEntity(org.whole.lang.model.IEntity) ITextCommand(org.whole.lang.ui.commands.ITextCommand) TextTransactionCommand(org.whole.lang.ui.commands.TextTransactionCommand) Command(org.eclipse.gef.commands.Command) TextTransactionCommand(org.whole.lang.ui.commands.TextTransactionCommand) IEntityPartViewer(org.whole.lang.ui.viewers.IEntityPartViewer) CanExecute(org.eclipse.e4.core.di.annotations.CanExecute) Execute(org.eclipse.e4.core.di.annotations.Execute)

Aggregations

Command (org.eclipse.gef.commands.Command)2 ITextCommand (org.whole.lang.ui.commands.ITextCommand)2 TextTransactionCommand (org.whole.lang.ui.commands.TextTransactionCommand)2 CanExecute (org.eclipse.e4.core.di.annotations.CanExecute)1 Execute (org.eclipse.e4.core.di.annotations.Execute)1 EditPart (org.eclipse.gef.EditPart)1 CommandStack (org.eclipse.gef.commands.CommandStack)1 IEntity (org.whole.lang.model.IEntity)1 ITextualEntityPart (org.whole.lang.ui.editparts.ITextualEntityPart)1 IEntityPartViewer (org.whole.lang.ui.viewers.IEntityPartViewer)1