/** @generated */ @Override protected CommandResult doExecuteWithResult(IProgressMonitor monitor, IAdaptable info) throws ExecutionException { DurationObservation newElement = UMLFactory.eINSTANCE.createDurationObservation(); EObject target = getElementToEdit(); ModelAddData data = PolicyChecker.getCurrent().getChildAddData(diagram, target, newElement); if (data.isPermitted()) { if (data.isPathDefined()) { if (!data.execute(target, newElement)) { return CommandResult.newErrorCommandResult( "Failed to follow the policy-specified for the insertion of the new element"); } } else { Package qualifiedTarget = (Package) target; qualifiedTarget.getPackagedElements().add(newElement); } } else { return CommandResult.newErrorCommandResult( "The active policy restricts the addition of this element"); } ElementInitializers.getInstance().init_DurationObservation_8007(newElement); doConfigure(newElement, monitor, info); ((CreateElementRequest) getRequest()).setNewElement(newElement); return CommandResult.newOKCommandResult(newElement); }
/** * Retrieve an element via its qualified name within a package The segments of the package may be * non unique due to imports * * @return the found element, if it exists */ public static NamedElement getQualifiedElement( Package root, String remainingPath, String qualifiedName) { if (root == null) { return null; } if (!remainingPath.contains(nsSep)) { for (NamedElement candidate : root.getMembers()) { String name = candidate.getName(); if ((name != null) && name.equals(remainingPath)) { if (candidate.getQualifiedName().equals(qualifiedName)) { return candidate; } } } } else { String segment = remainingPath.split(nsSep)[0]; String remainder = remainingPath.substring(segment.length() + 2); for (Element element : root.getMembers()) { if (element instanceof Package) { if (((NamedElement) element).getName().equals(segment)) { NamedElement foundElement = getQualifiedElement((Package) element, remainder, qualifiedName); // return, if not found if (foundElement != null) { return foundElement; } } } } } return null; }
@SuppressWarnings("unchecked") public Collection getAllContents(Object element) { if (!(element instanceof Element)) { throw new IllegalArgumentException("The argument must be instance of Element"); // $NON-NLS-1$ } Collection result = new HashSet(); if (element instanceof Collaboration) { // TODO: implement } if (element instanceof Classifier) { result.addAll(((Classifier) element).allFeatures()); } if (element instanceof Namespace) { result.addAll(((Namespace) element).getMembers()); } if (element instanceof org.eclipse.uml2.uml.Package) { result.addAll(((org.eclipse.uml2.uml.Package) element).getPackagedElements()); org.eclipse.uml2.uml.Package p = ((org.eclipse.uml2.uml.Package) element).getNestingPackage(); while (p != null) { for (PackageableElement e : p.getPackagedElements()) { if (e.getVisibility() == VisibilityKind.PUBLIC_LITERAL) { result.add(e); } } p = p.getNestingPackage(); } } return result; }
/** * Returns the name of the type with its qualified name * * @param type a type * @return the name of the type with its qualified name */ public static String getTypeLabel(Type type, Namespace model) { String label = ""; // $NON-NLS-1$ List<Package> importedPackages = new ArrayList<Package>(model.getImportedPackages()); List<Package> visitedPackages = new ArrayList<Package>(); Package currentPackage = type.getNearestPackage(); boolean rootFound = false; while (currentPackage != null && !rootFound) { visitedPackages.add(currentPackage); if (importedPackages.contains(currentPackage) || currentPackage == model) { rootFound = true; } Element owner = currentPackage.getOwner(); while (owner != null && !(owner instanceof Package)) owner = owner.getOwner(); currentPackage = owner != null ? (Package) owner : null; } for (int i = visitedPackages.size() - 1; i >= 0; i--) { label += visitedPackages.get(i).getName() + "::"; // $NON-NLS-1$ } return label + type.getName(); }
/** * Returns the qualified name of the given type. * * @param type The type * @return The qualified name of the given type. */ private String qualifiedName(Type type) { String result = null; if (type != null && !(type instanceof PrimitiveType)) { List<String> packagesName = new ArrayList<String>(); EObject eContainer = type.eContainer(); while (eContainer != null && eContainer instanceof Package && !(eContainer instanceof Model)) { Package umlPackage = (Package) eContainer; packagesName.add(umlPackage.getName()); eContainer = umlPackage.eContainer(); } Collections.reverse(packagesName); StringBuilder stringBuilder = new StringBuilder(); for (String packageName : packagesName) { stringBuilder.append(packageName); stringBuilder.append('.'); } stringBuilder.append(type.getName()); result = stringBuilder.toString(); if (JAVA_LANG_TYPES.contains(type.getName())) { result = null; } else if (JAVA_UTIL_TYPES.contains(type.getName())) { result = "java.util." + type.getName(); } } return result; }
/** * return the root package from an element * * @param elem the element * @return the root package */ protected org.eclipse.uml2.uml.Package getToPackage(Element elem) { org.eclipse.uml2.uml.Package tmp = elem.getNearestPackage(); while (tmp.getOwner() != null && (tmp.getOwner() instanceof Package)) { tmp = (org.eclipse.uml2.uml.Package) tmp.getOwner(); } return tmp; }
/** * Provides custom completion for a path, taking into account the path which has already been * specified * * @see * org.eclipse.papyrus.uml.textedit.property.xtext.ui.contentassist.AbstractUmlPropertyProposalProvider#completeQualifiedName_Remaining(org.eclipse.emf.ecore.EObject, * org.eclipse.xtext.Assignment, * org.eclipse.xtext.ui.editor.contentassist.ContentAssistContext, * org.eclipse.xtext.ui.editor.contentassist.ICompletionProposalAcceptor) */ @Override public void completeQualifiedName_Remaining( EObject model, Assignment assignment, ContentAssistContext context, ICompletionProposalAcceptor acceptor) { QualifiedName path = (QualifiedName) model; for (NamedElement n : path.getPath().getOwnedMembers()) { if (n instanceof Package) { if (n.getName().toLowerCase().contains(context.getPrefix().toLowerCase())) { String completionString = n.getName() + "::"; String displayString = n.getName() + "::"; CustomCompletionProposal completionProposal = CompletionProposalUtils.createCompletionProposalWithReplacementOfPrefix( n, completionString, displayString, context); acceptor.accept(completionProposal); } } } for (Package p : path.getPath().getImportedPackages()) { if (p.getName().toLowerCase().contains(context.getPrefix().toLowerCase())) { String completionString = p.getName() + "::"; String displayString = p.getName() + "::"; CustomCompletionProposal completionProposal = CompletionProposalUtils.createCompletionProposalWithReplacementOfPrefix( p, completionString, displayString, context); acceptor.accept(completionProposal); } } }
// 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); }
/** @generated */ private String getPackage_1000Text(View view) { Package domainModelElement = (Package) view.getElement(); if (domainModelElement != null) { return String.valueOf(domainModelElement.getName()); } else { UMLDiagramEditorPlugin.getInstance() .logError("No domain element for view with visualID = " + 1000); // $NON-NLS-1$ return ""; //$NON-NLS-1$ } }
protected List<Type> getChoiceOfValues(org.eclipse.uml2.uml.Package package_) { List<Type> choiceOfValues = new ArrayList<Type>(); Resource eResource = package_.eResource(); ResourceSet resourceSet = eResource == null ? null : eResource.getResourceSet(); if (resourceSet != null) { try { resourceSet.getResource(URI.createURI(UMLResource.UML_PRIMITIVE_TYPES_LIBRARY_URI), true); } catch (Exception e) { // ignore } try { resourceSet.getResource(URI.createURI(UMLResource.JAVA_PRIMITIVE_TYPES_LIBRARY_URI), true); } catch (Exception e) { // ignore } try { resourceSet.getResource(URI.createURI(UMLResource.ECORE_PRIMITIVE_TYPES_LIBRARY_URI), true); } catch (Exception e) { // ignore } try { resourceSet.getResource(URI.createURI(UMLResource.XML_PRIMITIVE_TYPES_LIBRARY_URI), true); } catch (Exception e) { // ignore } } if (eResource != null) { EList<NamedElement> members = package_.getMembers(); TreeIterator<?> allContents = resourceSet == null ? eResource.getAllContents() : resourceSet.getAllContents(); while (allContents.hasNext()) { Object object = allContents.next(); if (object instanceof Type && !members.contains(object)) { Type type = (Type) object; if (type.getNearestPackage().makesVisible(type)) { choiceOfValues.add(type); } } } } Collections.<Type>sort(choiceOfValues, new TextComparator<Type>()); return choiceOfValues; }
/** {@inheritDoc} */ public boolean create(EObject selectedElement) { if (super.create(selectedElement)) { if (selectedElement instanceof org.eclipse.uml2.uml.Package) { org.eclipse.uml2.uml.Package pack = (org.eclipse.uml2.uml.Package) selectedElement; if (pack.getAppliedProfile(SysmlResource.BLOCKS_ID, true) != null) { return true; } } } return false; }
/** * Unapply profiles duplicated for control action * * @param selection * @param target the resource target */ private void unapplyDuplicateProfiles(final EObject selection, Resource target) { Package _package = (Package) selection; EList<Profile> allAppliedProfiles = _package.getAllAppliedProfiles(); if (!allAppliedProfiles.isEmpty()) { for (Profile profile : new ArrayList<Profile>(_package.getAppliedProfiles())) { if (allAppliedProfiles.contains(profile)) { // profile is duplicated, unapply it ProfileApplicationHelper.removeProfileApplicationDuplication(_package, profile, true); } } } }
/** @generated */ private static void loadDefaultImports(Package model) { ResourceSet resourceSet = model.eResource().getResourceSet(); Model umlLibrary = (Model) resourceSet .getResource(URI.createURI(UMLResource.UML_PRIMITIVE_TYPES_LIBRARY_URI), true) .getContents() .get(0); model.createElementImport(umlLibrary.getOwnedType("Boolean")); model.createElementImport(umlLibrary.getOwnedType("String")); model.createElementImport(umlLibrary.getOwnedType("UnlimitedNatural")); model.createElementImport(umlLibrary.getOwnedType("Integer")); }
/** * Synchronize the copy map, i.e. put the correspondences between existing source and target * elements into the map. Otherwise, a new binding would produce duplicates. TODO: A more * efficient way would be to cache the copy function and only re-sync, if a new model has been * loaded. On the other hand, the bound package is normally not very large * * @param sourcePkg The package template (source) * @param targetPkg The bound package (target) */ public void syncCopyMap(Package sourcePkg, Package targetPkg) { copier.put(sourcePkg, targetPkg); for (PackageableElement target : targetPkg.getPackagedElements()) { if (target instanceof NamedElement) { String targetName = ((NamedElement) target).getName(); PackageableElement source = sourcePkg.getPackagedElement(targetName); if ((source instanceof Package) && (target instanceof Package)) { syncCopyMap((Package) source, (Package) target); } else { copier.put(source, target); } } } }
/** @generated */ protected CommandResult doExecuteWithResult(IProgressMonitor monitor, IAdaptable info) throws ExecutionException { Stereotype newElement = UMLFactory.eINSTANCE.createStereotype(); Package owner = (Package) getElementToEdit(); owner.getPackagedElements().add(newElement); ElementInitializers.getInstance().init_Stereotype_2001(newElement); doConfigure(newElement, monitor, info); ((CreateElementRequest) getRequest()).setNewElement(newElement); return CommandResult.newOKCommandResult(newElement); }
@Override protected org.edna.datamodel.datamodel.Package configure( org.eclipse.uml2.uml.Package source, org.edna.datamodel.datamodel.Package newInstance) { newInstance.setName(NamingUtil.normalize(source.getName())); return null; }
protected String getViewName(Property property) { if (!(generator instanceof ProfileGenerator)) { return ""; } org.eclipse.uml2.uml.Property attribute = ((ProfileGenerator) generator).getAttribute(property); Package nearestPackage = attribute.getType().getNearestPackage(); Package rootPackage = nearestPackage; while (rootPackage.getNestingPackage() != null) { rootPackage = rootPackage.getNestingPackage(); } // TODO : We're assuming the rootPackage has the same name as the context... // This layout generator is really only compatible with ProfileGenerator return rootPackage.getName() + ":Single " + attribute.getType().getName(); }
/** * create package from exported Packages * * @param bundleComponent the description of the bundle * @param bundleProject */ public void fillExportedPackages(Component bundleComponent, Object bundleProject) { if (bundleProject instanceof IBundleProjectDescription) { IPackageExportDescription[] packageExportDescription = ((IBundleProjectDescription) bundleProject).getPackageExports(); if (packageExportDescription != null) { ArrayList<EObject> exportedPackages = new ArrayList<EObject>(); for (int i = 0; i < packageExportDescription.length; i++) { Package UMLPackage = UMLFactory.eINSTANCE.createPackage(); UMLPackage.setName(packageExportDescription[i].getName()); bundleComponent.getPackagedElements().add(UMLPackage); Stereotype exportedPackageStereotype = UMLPackage.getApplicableStereotype( IADL4ECLIPSE_Stereotype.ECLIPSEEXPORTEDPACKAGE_STEREOTYPE); UMLPackage.applyStereotype(exportedPackageStereotype); UMLPackage.setValue( exportedPackageStereotype, IADL4ECLIPSE_Stereotype.ECLIPSEEXPORTEDPACKAGE_ISINTERNAL_ATT, !packageExportDescription[i].isApi()); if (packageExportDescription[i].getVersion() != null) { UMLPackage.setValue( exportedPackageStereotype, IOSGIStereotype.VERSIONRANGE_ATLEAST_ATT, packageExportDescription[i].getVersion().toString()); } exportedPackages.add(UMLPackage.getStereotypeApplication(exportedPackageStereotype)); } Stereotype pluginStereotype = bundleComponent.getAppliedStereotype(IADL4ECLIPSE_Stereotype.PLUGIN_STEREOTYPE); bundleComponent.setValue( pluginStereotype, IOSGIStereotype.BUNDLE_EXPORTPACKAGE_ATT, exportedPackages); } } }
public static StateMachine loadStateMachine(URI modelUri) { org.eclipse.uml2.uml.Package model = UMLLoader.loadUMLModel(modelUri); StateMachine umlStateMachine = null; if (model != null) { umlStateMachine = (StateMachine) model.getPackagedElement(null, true, UMLPackage.Literals.STATE_MACHINE, false); } if (umlStateMachine != null && logger.isDebugEnabled()) { logger.debug( "loadStateMachine() loaded state machine with owned elements " + umlStateMachine.getOwnedElements()); } return umlStateMachine; }
private void loadProfilesFromUML2Registry(org.eclipse.uml2.uml.Package package_) { ResourceSet resourceSet = package_.eResource().getResourceSet(); for (URI profileURI : UMLPlugin.getEPackageNsURIToProfileLocationMap().values()) { try { resourceSet.getResource(profileURI.trimFragment(), true); } catch (Exception e) { // ignore } } }
private String getModelName(Model existingModel, InstanceSpecification node) { String modelName = existingModel.getName() + "_" + node.getName(); // $NON-NLS-1$ if (configuration != null) { modelName += "_" + configuration.getBase_Class().getName(); // $NON-NLS-1$ } else { modelName += "_" + srcModelComponentDeploymentPlan.getName(); // $NON-NLS-1$ } return modelName; }
@Override protected void setUp() { super.setUp(); instanceResource = resourceSet.createResource(URI.createFileURI("/tmp/instances.uml")); instancePackage = umlf.createPackage(); instancePackage.setName("instances"); instanceResource.getContents().add(instancePackage); }
public void instantiate(Package pkg, IProgressMonitor monitor, IProject project, int genOptions) { configuration = null; srcModelComponentDeploymentPlan = pkg; // this.project = project; if (project == null) { String projectName = pkg.eResource().getURI().toString(); this.project = ResourcesPlugin.getWorkspace().getRoot().getProject(projectName); } // instantiate(monitor, genOptions); }
/** * Provides custom completion for the root element in a qualified name * * @see * org.eclipse.papyrus.uml.textedit.property.xtext.ui.contentassist.AbstractUmlPropertyProposalProvider#completeTypeRule_Path(org.eclipse.emf.ecore.EObject, * org.eclipse.xtext.Assignment, * org.eclipse.xtext.ui.editor.contentassist.ContentAssistContext, * org.eclipse.xtext.ui.editor.contentassist.ICompletionProposalAcceptor) */ @Override public void completeTypeRule_Path( EObject model, Assignment assignment, ContentAssistContext context, ICompletionProposalAcceptor acceptor) { Namespace root = (Namespace) EcoreUtil.getRootContainer(ContextElementUtil.getContextElement(model.eResource())); if (root == null) { return; } // first accept the root Model String completionString = root.getName() + "::"; String displayString = root.getName() + "::"; // String displayString = c.getName() ; CustomCompletionProposal completionProposal = CompletionProposalUtils.createCompletionProposalWithReplacementOfPrefix( root, completionString, displayString, context); acceptor.accept(completionProposal); // then accepts all packages imported by Model List<Package> importedPackages = root.getImportedPackages(); for (Package p : importedPackages) { if (p.getName().toLowerCase().contains(context.getPrefix().toLowerCase())) { completionString = p.getName() + "::"; displayString = p.getName() + "::"; // String displayString = c.getName() ; completionProposal = CompletionProposalUtils.createCompletionProposalWithReplacementOfPrefix( root, completionString, displayString, context); acceptor.accept(completionProposal); } } }
private List<Profile> getProfiles(final org.eclipse.uml2.uml.Package package_) { // copy of code from // org.eclipse.uml2.uml.editor.actions.ApplyProfileAction final List<Profile> choiceOfValues = new ArrayList<Profile>(); ResourceSet resourceSet = package_.eResource().getResourceSet(); for (Resource resource : resourceSet.getResources()) { Profile profile = ProfileUtil.getProfile(resource); if (profile != null) { choiceOfValues.add(profile); } } return choiceOfValues; }
/** Tests that unrecognized data types are represented by themselves, not by OclAny. */ public void test_dataTypes_137158() { Package upackage = umlf.createPackage(); upackage.setName("mypkg"); Class uclass = upackage.createOwnedClass("B", false); DataType datatype = (DataType) pkg.createOwnedType("Thread", uml.getDataType()); Operation operation = uclass.createOwnedOperation("f", null, null, datatype); operation.setIsQuery(true); helper.setContext(uclass); try { OCLExpression<Classifier> expr = helper.createQuery("self.f()"); Classifier type = expr.getType(); assertSame(datatype, type); operation.setUpper(LiteralUnlimitedNatural.UNLIMITED); expr = helper.createQuery("self.f()"); type = expr.getType(); assertTrue(type instanceof CollectionType<?, ?>); type = ((org.eclipse.ocl.uml.CollectionType) type).getElementType(); assertSame(datatype, type); operation.setUpper(1); operation.setType(ocl.getEnvironment().getOCLStandardLibrary().getOclAny()); expr = helper.createQuery("self.f()"); type = expr.getType(); assertSame(getOCLStandardLibrary().getOclAny(), type); } catch (Exception e) { fail("Failed to parse or evaluate: " + e.getLocalizedMessage()); } }
/** * * <!-- begin-user-doc --> * <!-- end-user-doc --> * * @generated */ public org.eclipse.uml2.uml.Package getImportedPackage() { if (importedPackage != null && importedPackage.eIsProxy()) { InternalEObject oldImportedPackage = (InternalEObject) importedPackage; importedPackage = (org.eclipse.uml2.uml.Package) eResolveProxy(oldImportedPackage); if (importedPackage != oldImportedPackage) { if (eNotificationRequired()) eNotify( new ENotificationImpl( this, Notification.RESOLVE, UMLPackage.PACKAGE_IMPORT__IMPORTED_PACKAGE, oldImportedPackage, importedPackage)); } } return importedPackage; }
/** * * <!-- begin-user-doc --> * <!-- end-user-doc --> * * @generated */ public org.eclipse.uml2.uml.Package getBase_Package() { if (base_Package != null && base_Package.eIsProxy()) { InternalEObject oldBase_Package = (InternalEObject) base_Package; base_Package = (org.eclipse.uml2.uml.Package) eResolveProxy(oldBase_Package); if (base_Package != oldBase_Package) { if (eNotificationRequired()) eNotify( new ENotificationImpl( this, Notification.RESOLVE, GenericconstraintsPackage.GENERIC_CONSTRAINT_SET__BASE_PACKAGE, oldBase_Package, base_Package)); } } return base_Package; }
/** * * <!-- begin-user-doc --> * <!-- end-user-doc --> * * @generated */ public org.eclipse.uml2.uml.Package getBase_Package() { if (base_Package != null && base_Package.eIsProxy()) { InternalEObject oldBase_Package = (InternalEObject) base_Package; base_Package = (org.eclipse.uml2.uml.Package) eResolveProxy(oldBase_Package); if (base_Package != oldBase_Package) { if (eNotificationRequired()) eNotify( new ENotificationImpl( this, Notification.RESOLVE, TimingPackage.TIMING__BASE_PACKAGE, oldBase_Package, base_Package)); } } return base_Package; }
/** * Get the controlled children packages * * @param packageElement package to inspect children * @return set of children packages which are controlled */ private Set<Package> getControlledSubPackages(Package packageElement) { Set<Package> controlledPackages = new HashSet<Package>(); TreeIterator<EObject> iterator = packageElement.eAllContents(); while (iterator.hasNext()) { EObject child = iterator.next(); if (child instanceof Package) { // despite what AdapterFactoryEditingDomain#isControlled says, a not loaded child is // controlled if (AdapterFactoryEditingDomain.isControlled(child) || child.eIsProxy()) { controlledPackages.add((Package) child); } } else { iterator.prune(); } } return controlledPackages; }