Beanshell:Chain Copy/Paste/Move using PlugIns and CursorTool

From OpenJUMP Wiki
Jump to: navigation, search

Here is how you can use existing PlugIns or CursorTools to chain actions in a simple script

// Import packages (you can also call classes directly using their full name)
import com.vividsolutions.jump.workbench.ui.plugin.clipboard.*;
import com.vividsolutions.jump.workbench.ui.cursortool.editing.*;

// Get PlugIn context from WorkbenchContext
context = wc.createPlugInContext();

// Execute CopySelectedItemsPlugIn
new CopySelectedItemsPlugIn().execute(context);

// Notify the system that you're starting an undoable action
// (needed by the PasteItemsPlugIn)
wc.layerManager.undoableEditReceiver.startReceiving();

// Execute PasteItemsPlugIn
new PasteItemsPlugIn().execute(context);

// Set a new MoveSelectedItemsTool as the current CursorTool
// of the layerViewPanel
wc.layerViewPanel.setCurrentCursorTool(new MoveSelectedItemsTool(context.checkFactory));