コード例 #1
0
ファイル: PasteHandler.java プロジェクト: wholeplatform/whole
  @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);
  }
コード例 #2
0
ファイル: PasteHandler.java プロジェクト: wholeplatform/whole
 @Override
 @CanExecute
 public boolean canExecute(
     @Optional @Named(IServiceConstants.ACTIVE_SELECTION) IBindingManager bm) {
   try {
     if (bm.wIsSet("viewer") && Clipboard.instance().getInternalOrNativeEntityContents() == null) {
       IEntityPartViewer viewer = (IEntityPartViewer) bm.wGetValue("viewer");
       if (ClipboardUtils.hasTextFocus(viewer) || ClipboardUtils.hasTextSeletion(viewer))
         return true;
     }
     return super.canExecute(bm);
   } catch (Exception e) {
     return false;
   }
 }