public Operation buildOperation2(final Object cls, final Object returnType, final String name) { if ((returnType != null && !(returnType instanceof Type)) || !(cls instanceof Type)) { throw new IllegalArgumentException( "cls and returnType must be instances of Type."); //$NON-NLS-1$ } if (UMLUtil.getOwnedOperations((Type) cls) == null) { throw new UnsupportedOperationException( "The type " + cls.getClass() // $NON-NLS-1$ + " does not support owning operations."); //$NON-NLS-1$ } RunnableClass run = new RunnableClass() { public void run() { Operation operation = createOperation(); UMLUtil.getOwnedOperations((Type) cls).add(operation); operation.createReturnResult("return", (Type) returnType); if (name != null) { operation.setName(name); } else { // TODO: Remove? Can't be localized operation.setName("newOperation"); } getParams().add(operation); } }; ChangeCommand cmd = new ChangeCommand(modelImpl, run, "Create the operation # owned by #"); editingDomain.getCommandStack().execute(cmd); cmd.setObjects(run.getParams().get(0), cls); return (Operation) run.getParams().get(0); }
// TODO: get/setRootModel aren't specific to the Model implementation // they could probably be moved elsewhere - tfm - 20070530 @Deprecated public void setRootModel(Object rootModel) { // TODO: Hook this creating of a new resource in to someplace more // more appropriate (perhaps createModel() ?) // Better yet add a new method to Model API to create a new top level // project/model/xmi file so we don't depend on side effects if (rootModel != null && !(rootModel instanceof org.eclipse.uml2.uml.Package)) { throw new IllegalArgumentException( "The rootModel supplied must be a Package. Got a " //$NON-NLS-1$ + rootModel.getClass().getName()); } List<EObject> restoreList = new ArrayList<EObject>(); if (theRootModel != null && theRootModel.eResource() != null) { if (theRootModel.eResource().getContents().contains(theRootModel) && rootModel == theRootModel) { for (EObject o : theRootModel.eResource().getContents()) { if (o != theRootModel) { restoreList.add(o); } } } EcoreUtil.remove(theRootModel); } theRootModel = (org.eclipse.uml2.uml.Package) rootModel; if (rootModel != null && theRootModel.eResource() == null) { restoreList.add(0, theRootModel); Resource r = UMLUtil.getResource(modelImpl, UMLUtil.DEFAULT_URI, Boolean.FALSE); r.getContents().addAll(restoreList); } modelImpl.getModelEventPump().setRootContainer(theRootModel); }
public Property buildAttribute2(final Object handle, final Object type) { if (!(handle instanceof Type)) { throw new IllegalArgumentException("handle must be instance of Type."); // $NON-NLS-1$ } if (type != null && !(type instanceof Type)) { throw new IllegalArgumentException("type must be instance of Type."); // $NON-NLS-1$ } if (UMLUtil.getOwnedAttributes((Type) handle) == null) { throw new UnsupportedOperationException( "The type " + handle.getClass() // $NON-NLS-1$ + " does not support owning attributes."); //$NON-NLS-1$ } RunnableClass run = new RunnableClass() { public void run() { Property property = createAttribute(); UMLUtil.getOwnedAttributes((Type) handle).add(property); if (type != null) { property.setType((Type) type); } property.setName("newAttr"); getParams().add(property); } }; ChangeCommand cmd = new ChangeCommand(modelImpl, run, "Create the attribute # of the type #"); editingDomain.getCommandStack().execute(cmd); cmd.setObjects(run.getParams().get(0), handle); return (Property) run.getParams().get(0); }
public ElementImport buildElementImport(final Object pack, final Object me) { UMLUtil.checkArgs( new Object[] {pack, me}, new Class[] {Namespace.class, PackageableElement.class}); RunnableClass run = new RunnableClass() { public void run() { ElementImport elementImport = createElementImport(); elementImport.setImportingNamespace((Namespace) pack); elementImport.setImportedElement((PackageableElement) me); getParams().add(elementImport); } }; editingDomain.getCommandStack().execute(new ChangeCommand(editingDomain, run)); return (ElementImport) run.getParams().get(0); }