/** * ------------------------------------------------------ Deletes and copies the parts that are * selected in the given to this clipboard. * * @param editor the editor that contians the selected parts to cut * @see MiEditor#getSelectedParts * @see MiPart#isSelected ------------------------------------------------------ */ public void cutSelectionToClipBoard(MiEditor editor) { MiParts selectedParts = new MiParts(); editor.getSelectedParts(selectedParts); for (int i = 0; i < selectedParts.size(); ++i) { if (!selectedParts.get(i).isCopyable()) { selectedParts.removeElementAt(i); --i; } } for (int i = 0; i < selectedParts.size(); ++i) { MiPart part = selectedParts.elementAt(i); editor.deSelect(part); } MiNestedTransaction nestedTransaction = new MiNestedTransaction(Mi_CUT_DISPLAY_NAME); MiSystem.getTransactionManager().startTransaction(nestedTransaction); // MiDeletePartsCommand deleteCmd = new MiDeletePartsCommand(editor, selectedParts, true); MiParts pastableSelectedParts = MiUtility.makeCopyOfNetwork(selectedParts); MiDeletePartsCommand deleteCmd = MiSystem.getCommandBuilder().getDeletePartsCommand().create(editor, selectedParts, true); MiChangeContentsTransaction replaceCmd = new MiChangeContentsTransaction(this, pastableSelectedParts); MiSystem.getTransactionManager().appendTransaction(Mi_CUT_DISPLAY_NAME, replaceCmd, deleteCmd); deleteCmd.doit(editor, true); replaceCmd.doit(this, pastableSelectedParts, true); dispatchAction(Mi_CLIPBOARD_NOW_HAS_DATA_ACTION); MiSystem.getTransactionManager().commitTransaction(nestedTransaction); }
/** * ------------------------------------------------------ Deletes the given part and then copies * the given part to this clipboard. * * @param part the part to cut to the clipboard * ------------------------------------------------------ */ public void cutToClipBoard(MiPart part) { MiParts parts = new MiParts(); parts.addElement(part); // MiDeletePartsCommand deleteCmd = new MiDeletePartsCommand(part.getContainingEditor(), parts, // true); MiDeletePartsCommand deleteCmd = MiSystem.getCommandBuilder() .getDeletePartsCommand() .create(part.getContainingEditor(), parts, true); MiChangeContentsTransaction replaceCmd = new MiChangeContentsTransaction(this, parts); MiiTransaction openTransaction = MiSystem.getTransactionManager() .startTransaction(new MiNestedTransaction(Mi_CUT_DISPLAY_NAME, replaceCmd, deleteCmd)); deleteCmd.doit(part.getContainingEditor(), true); replaceCmd.doit(this, parts, true); dispatchAction(Mi_CLIPBOARD_NOW_HAS_DATA_ACTION); MiSystem.getTransactionManager().commitTransaction(openTransaction); }