/** @see org.eclipse.bpel.ui.actions.BPELCopyAction#getCommand() */ @Override protected Command getCommand() { CompoundCommand cmd = new CompoundCommand(Messages.BPELCopyAction_Copy_3); final BPELEditor bpelEditor = (BPELEditor) getWorkbenchPart(); // 1. Restore selection cmd.add(new RestoreSelectionCommand(bpelEditor.getAdaptingSelectionProvider(), true, true)); // 2. Copy the objects that are selected. BPELCopyCommand copyCmd = new BPELCopyCommand(bpelEditor); if (fSelection.isEmpty()) { for (Object o : ((IStructuredSelection) bpelEditor.getSelection()).toList()) { if (o instanceof EObject) { fSelection.add((EObject) o); } } } if (fSelection.isEmpty()) { return null; } copyCmd.setObjectList(new ArrayList<EObject>(fSelection)); cmd.add(copyCmd); // 3. Immediately paste them BPELPasteCommand pasteCmd = new BPELPasteCommand(bpelEditor) { /** * We override the canDoExecute, because the compound command in GEF will check both of * the commands for canDoExecute() before running the compound command. Since the copy * command is a prerequisite for the paste here, this condition will never be true unless * we just allow it. * * @see org.eclipse.bpel.ui.commands.BPELPasteCommand#canDoExecute() */ @Override public boolean canDoExecute() { return true; } }; pasteCmd.setTargetObject(fSelection.get(0), true); cmd.add(pasteCmd); // 4. Add the command to select the pasted elements cmd.add(new SetSelectionCommand(pasteCmd, false)); return cmd; }