You can copy model elements and symbols either to another location in the same project or to another project. This must be done in the same session.
There are two modes of making copies:
- Deep copying (with new data)
- Shallow copying (with reused data)
Example #1: Copying an element
Element element = ...; // An element to copy/paste. Element parent = ...; // A parent to which the element has to be pasted: either the same project or another project. Project project = ...; SessionManager sessionManager = SessionManager.getInstance(); sessionManager.createSession(project, "Clone"); // A 3rd parameter indicates whether an element name uniqueness should be preserved in the parent. CopyPasting.copyPasteElement(element, parent, true); sessionManager.closeSession(project);
Example #2: Copying multiple elements and symbols
List elements = ...; // Elements to copy/paste. List views = ...; // Symbols to copy/paste. Element parent = ...; // A parent to which elements should be pasted: either the same project or another project. BaseElement symbolParent = ...; // A parent to which symbols should be pasted. Project project = ...; SessionManager sessionManager = SessionManager.getInstance(); sessionManager.createSession(project, "Clone"); // A 4th parameter indicates whether deep or shallow copy is applied. // A 5th parameter indicates whether an element name uniqueness should be preserved in the parent. List baseElements = CopyPasting.copyPasteElements(views, parent, symbolParent, true, true); sessionManager.closeSession(project);
You can find the code examples in <programinstallation directory>\openapi\examples\copypaste
Related pages