// TODO : In some cases, we may have a filter based on both a UML Metaclass and a Stereotype // In such a specific case, a specific implementation is probably needed // // This case may especially occur in the case of dynamic creation of stereotype associations. @Override public Object getAdaptedValue(Object containerElement) { Object semanticElement = super.getAdaptedValue(containerElement); if (semanticElement instanceof Element) { Element element = (Element) semanticElement; // Looks for a compatible Stereotype application for (Object metaclassWanted : getWantedMetaclasses()) { if (metaclassWanted instanceof Stereotype) { EObject stereotypeApplication = null; stereotypeApplication = element.getStereotypeApplication((Stereotype) metaclassWanted); if (stereotypeApplication == null) { List<Stereotype> subStereotypes = element.getAppliedSubstereotypes((Stereotype) metaclassWanted); for (Stereotype subSteretoype : subStereotypes) { stereotypeApplication = element.getStereotypeApplication(subSteretoype); if (stereotypeApplication != null) { break; } } } if (stereotypeApplication != null) { return stereotypeApplication; } } } } // If no stereotype application is found, return the UML Element return semanticElement; }
public Collection getAllModelElementsOfKind(Object nsa, Object type) { if (!(nsa instanceof Element)) { return new ArrayList<Element>(); } Class theType = null; if (type instanceof String) { try { theType = Class.forName((String) type); } catch (ClassNotFoundException e) { throw new IllegalArgumentException(e); } } else if (type instanceof Class) { theType = (Class) type; } else { throw new IllegalArgumentException("type must be instance of Class or String"); // $NON-NLS-1$ } if (!Element.class.isAssignableFrom(theType)) { throw new IllegalArgumentException("type must represent an Element"); // $NON-NLS-1$ } Collection<Element> result = new ArrayList<Element>(); for (Element element : ((Namespace) nsa).allOwnedElements()) { if (theType.isAssignableFrom(element.getClass())) { result.add(element); } } return result; }
/** * * <!-- begin-user-doc --> * <!-- end-user-doc --> * * @generated */ @Override public Element getOwner() { Element owner = basicGetOwner(); return owner != null && owner.eIsProxy() ? (Element) eResolveProxy((InternalEObject) owner) : owner; }
@Override protected boolean isCompatibleMetaclass(Object containerElement, Object metaclass) { Element semanticElement = UMLUtil.resolveUMLElement(containerElement); if (semanticElement == null) { return false; } if (metaclass instanceof Stereotype) { Stereotype stereotype = (Stereotype) metaclass; boolean res = semanticElement.getAppliedStereotype(stereotype.getQualifiedName()) != null; if (!res) { EClass definition = stereotype.getDefinition(); for (EObject e : semanticElement.getStereotypeApplications()) { EClass c = e.eClass(); if (definition != null && definition.isSuperTypeOf(c)) { res = true; break; } } } return res; } // TODO : We should use super.isCompatibleMetaclass(), but the super-implementation // may not be compatible with our implementation of getAdaptedValue() if (metaclass instanceof EClassifier) { return ((EClassifier) metaclass).isInstance(semanticElement); } return false; }
/** * Returns the image for the element * * @param editPart the edit part that displays the element * @return the image */ public Image getImage(GraphicalEditPart editPart) { Element element = getUMLElement(editPart); String key = ""; if (element instanceof NamedElement) { key = ((NamedElement) element).getName() + "::" + ((NamedElement) element).getVisibility(); } else if (element != null) { key = element.getClass().getName(); } else { return null; } ImageRegistry imageRegistry = Activator.getDefault().getImageRegistry(); Image image = imageRegistry.get(key); ImageDescriptor descriptor = null; if (image == null) { AdapterFactory factory = Activator.getDefault().getItemProvidersAdapterFactory(); IItemLabelProvider labelProvider = (IItemLabelProvider) factory.adapt(getUMLElement(editPart), IItemLabelProvider.class); if (labelProvider != null) { descriptor = ExtendedImageRegistry.getInstance() .getImageDescriptor(labelProvider.getImage(getUMLElement(editPart))); } if (descriptor == null) { descriptor = ImageDescriptor.getMissingImageDescriptor(); } imageRegistry.put(key, descriptor); image = imageRegistry.get(key); } return image; }
private static void print(MessageSort messageSort, Element source, Element target) { StringBuffer buf = new StringBuffer(); if (messageSort != null) { buf.append(messageSort.getName()); buf.append("["); } buf.append("Source: "); if (source != null) { buf.append(source.eClass().getName()); if (source instanceof NamedElement) { buf.append("("); buf.append(((NamedElement) source).getName()); buf.append(")"); } } else { buf.append("null"); } buf.append(", Target: "); if (target != null) { buf.append(target.eClass().getName()); if (target instanceof NamedElement) { buf.append("("); buf.append(((NamedElement) target).getName()); buf.append(")"); } } else { buf.append("null"); } buf.append("]"); System.out.println(new String(buf)); }
/** * 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(); }
/** * Adds listeners on * * <ul> * <li>Affixed Child Node * <li>graphical parent, when its a {@link Property} (we add the listener on its Type) * </ul> */ public void activate() { IGraphicalEditPart gep = (IGraphicalEditPart) getDecoratorTarget().getAdapter(IGraphicalEditPart.class); assert gep != null; View view = ((View) gep.getModel()); if (view instanceof Node) { // the location of the decorator can change if it's an Affixed Child // Node if (isInherited((Node) view) && Util.isAffixedChildNode(gep)) { DiagramEventBroker.getInstance(gep.getEditingDomain()) .addNotificationListener(gep.getNotationView(), notificationListener); } } // if the graphical parent is a Property, we add a listener on the type // of the property, to refresh the decoration EObject parent = view.eContainer(); if (parent instanceof DecorationNode) { parent = parent.eContainer(); } if (parent instanceof View) { EObject el = ((View) parent).getElement(); if (el instanceof Property) { DiagramEventBroker.getInstance(gep.getEditingDomain()) .addNotificationListener( el, UMLPackage.eINSTANCE.getTypedElement_Type(), notificationListener); } } /* * We listen the changes on the UML parent, in order to know if the * element is changing of parent Adding a listener using the following * EReference doesn't work UMLPackage.eINSTANCE.getElement_Owner(); * UMLPackage.eINSTANCE.getProperty_Class(); * UMLPackage.eINSTANCE.getNamedElement_Namespace(); that's why we * listen the parent */ if (view.getElement() instanceof Element) { Element semanticElement = (Element) view.getElement(); /* * We need add a listener only if the element is an element which * can be inherited, like Property, Operation, Signal, Classifier... */ if (semanticElement != null && canBeInherited(semanticElement)) { // we listen if the container of the element changes! if (semanticElement.eContainer() != null) { DiagramEventBroker.getInstance(gep.getEditingDomain()) .addNotificationListener(semanticElement.eContainer(), notificationListener); } } } }
/** * Get all available root packages. * * @param element ELement * @return List of root packages */ public List<Package> getAllAvailableRootPackages(Element element) { // <%script type="uml.Element" name="allAvailableRootPackages"%> // <%(getRootContainer().filter("Package") + // rootPackagesFromImportedModel).nMinimize()%> final List<Package> packages = Lists.newArrayList(); packages.add(element.getModel()); packages.addAll( Lists.newArrayList( Iterables.filter(element.getModel().getImportedPackages(), Model.class))); return packages; }
@Override public void activate() { super.activate(); // if stereotype has been applied, compartment has to be created final GraphicalEditPart editPart = (GraphicalEditPart) getHost(); Element UMLEelement = (Element) editPart.resolveSemanticElement(); Iterator<EObject> iterator = UMLEelement.getStereotypeApplications().iterator(); while (iterator.hasNext()) { final EObject appliedstereotype = (EObject) iterator.next(); createAppliedStereotypeCompartment(appliedstereotype); } }
@Override public boolean select(Element e) { boolean isMapped = e.eResource().getResourceSet() instanceof IUIElementMapMap && ((IUIElementMapMap) e.eResource().getResourceSet()).getElementFor(e) != null; if (isMapped) { if (e instanceof TypedElement && e instanceof MultiplicityElement && ((TypedElement) e).getType() != null) { return EmfClassifierUtil.isPersistentComplexStructure(((TypedElement) e).getType()); } } return false; }
/** * @see * org.eclipse.nebula.widgets.nattable.edit.gui.AbstractDialogCellEditor#createDialogInstance() * @return */ @Override public Object createDialogInstance() { int columnIndex = this.layerCell.getColumnIndex(); int rowIndex = this.layerCell.getRowIndex(); Object row = this.manager.getRowElement(rowIndex); Object column = this.manager.getColumnElement(columnIndex); row = AxisUtils.getRepresentedElement(row); column = AxisUtils.getRepresentedElement(column); Element editedElement = null; Object feature = null; if (row instanceof EObject && column == this.axisElement) { editedElement = (Element) row; feature = column; } else { editedElement = (Element) column; feature = row; } EStructuralFeature realFeature = null; EObject realEditedObject = null; Stereotype stereotype = null; List<Stereotype> stereotypesWithEditedFeatureAppliedOnElement = null; if (feature instanceof EStructuralFeature) { realFeature = (EStructuralFeature) feature; realEditedObject = editedElement; } else { final String id = AxisUtils.getPropertyId(this.axisElement); stereotypesWithEditedFeatureAppliedOnElement = UMLTableUtils.getAppliedSteretoypesWithThisProperty(editedElement, id); stereotype = stereotypesWithEditedFeatureAppliedOnElement.get(0); realEditedObject = editedElement.getStereotypeApplication( stereotypesWithEditedFeatureAppliedOnElement.get(0)); Property prop = UMLTableUtils.getRealStereotypeProperty(editedElement, id); realFeature = realEditedObject.eClass().getEStructuralFeature(prop.getName()); } if (stereotypesWithEditedFeatureAppliedOnElement != null && stereotypesWithEditedFeatureAppliedOnElement.size() > 1) { // FIXME : not yet managed } else { this.dialog = createDialog( realEditedObject, realFeature, stereotype, editedElement.eResource().getResourceSet()); } return this.dialog; }
/** @generated */ protected CommandResult doExecuteWithResult(IProgressMonitor monitor, IAdaptable info) throws ExecutionException { Comment newElement = UMLFactory.eINSTANCE.createComment(); Element owner = (Element) getElementToEdit(); owner.getOwnedComments().add(newElement); ElementInitializers.getInstance().init_Comment_2109(newElement); doConfigure(newElement, monitor, info); ((CreateElementRequest) getRequest()).setNewElement(newElement); return CommandResult.newOKCommandResult(newElement); }
/** * 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; }
/** * @see * org.eclipse.gmf.runtime.diagram.core.listener.NotificationListener#notifyChanged(org.eclipse.emf.common.notify.Notification) * @param notification */ public void notifyChanged(Notification notification) { Object feature = notification.getFeature(); boolean headChanged = false; if (NotationPackage.eINSTANCE.getFontStyle_FontHeight().equals(feature) || NotationPackage.eINSTANCE.getFontStyle_FontName().equals(feature) || NotationPackage.eINSTANCE.getFontStyle_Bold().equals(feature) || NotationPackage.eINSTANCE.getFontStyle_Italic().equals(feature)) { headChanged = true; } else if (notification.getNotifier() instanceof EAnnotation && UMLVisualInformationPapyrusConstant.STEREOTYPE_ANNOTATION == ((EAnnotation) notification.getNotifier()).getSource()) { headChanged = true; } else if ((notification.getNotifier() instanceof DynamicEObjectImpl) && (hostSemanticElement != null) && (hostSemanticElement.getStereotypeApplications().contains(notification.getNotifier()))) { headChanged = true; } else if (PapyrusStereotypeListener.MODIFIED_STEREOTYPE == notification.getEventType()) { headChanged = true; } else if (notification instanceof StereotypeCustomNotification) { headChanged = true; } if (headChanged) { Display.getDefault() .asyncExec( new Runnable() { public void run() { impactLayout(); } }); } }
/** * this method returns the icon image that represents the first applied stereotype. * * @param element the stereotyped element * @return {@link image} of the icon */ public static Image getIconElement(Element element, boolean withVisibilityDecorator) { List<Stereotype> stereotypeList = element.getAppliedStereotypes(); if (stereotypeList == null || stereotypeList.isEmpty()) { return null; } return getIconElement(element, stereotypeList.get(0), withVisibilityDecorator); }
/** * Default Constructor. * * @param parentShell the parent shell * @param theElement the UML element to be modified */ public ChooseSetStereotypeDialog(Shell parentShell, org.eclipse.uml2.uml.Element theElement) { super(parentShell, "Applicable Stereotypes: ", "Applied Stereotypes: "); labelProvider = new StereotypeLabelProvider(); decoratedContentProposalProvider = new StereotypeContentProposalProvider(); Iterator<Stereotype> stereotypes = theElement.getAppliedStereotypes().iterator(); while (stereotypes.hasNext()) { selectedElementList.addElement(stereotypes.next()); } stereotypes = theElement.getApplicableStereotypes().iterator(); while (stereotypes.hasNext()) { Stereotype current = stereotypes.next(); if (!selectedElementList.contains(current)) { possibleElementList.addElement(current); } } }
protected String getStereotype(Element element) { final List stereotypes = element.getAppliedStereotypes(); if (stereotypes != null && stereotypes.size() != 0) { final StringBuffer sb = new StringBuffer(); appendStereotype(element, sb, false); return sb.toString(); } return CoreStringUtil.Constants.EMPTY_STRING; }
public static String getDocumentationText(Element umlElement) { if (!umlElement.getOwnedComments().isEmpty()) { return umlElement.getOwnedComments().get(0).getBody(); } EAnnotation topcasedDocAnnotation = umlElement.getEAnnotation("http://www.topcased.org/documentation"); if (topcasedDocAnnotation != null) { return topcasedDocAnnotation.getDetails().get("documentation"); } for (EObject obj : EcoreUtil2.findAllByType(umlElement.getModel().eAllContents(), Comment.class)) { Comment c = (Comment) obj; for (EObject annotatedObject : c.getAnnotatedElements()) { if (annotatedObject == umlElement) { return c.getBody(); } } } return null; }
public void ProcessComments(org.eclipse.uml2.uml.Element e1) { RefOntoUML.Element e2 = GetElement(e1); // ownedComment RefOntoUML.Comment c2; for (org.eclipse.uml2.uml.Comment c1 : e1.getOwnedComments()) { c2 = myfactory.createComment(); DealComment(c1, c2); e2.getOwnedComment().add(c2); } }
/** As its name says, retrieves the output ports for a given element. */ public static List<org.eclipse.uml2.uml.Port> getOutputPortsForElement(Element elt) { LinkedList<org.eclipse.uml2.uml.Port> found_output_ports = new LinkedList<org.eclipse.uml2.uml.Port>(); for (Element child : elt.getOwnedElements()) { if (child instanceof org.eclipse.uml2.uml.Port) { if (isAnOutputPort((org.eclipse.uml2.uml.Port) child)) { found_output_ports.add((org.eclipse.uml2.uml.Port) child); } } } return found_output_ports; }
/** As its name says, retrieves the input ports for a given element. */ public static List<Port> getInputPortsForElement(Element elt) { LinkedList<Port> found_input_ports = new LinkedList<org.eclipse.uml2.uml.Port>(); for (Element child : elt.getOwnedElements()) { if (child instanceof NamedElement && child instanceof org.eclipse.uml2.uml.Port) { if (isAnInputPort((org.eclipse.uml2.uml.Port) child)) { Port found_port = (org.eclipse.uml2.uml.Port) child; found_input_ports.add(found_port); } } } return found_input_ports; }
/** * return the top-level owner of an element. This function returns the same value as getModel, if * the top-level element is a model. While this is the case for models, model libraries have a * top-level package (not a model). In this case, getTop returns the top-level package whereas * getModel would return null. * * @param element * @return the top-level owning package */ public static Package getTop(Element element) { while (element != null) { Element owner = element.getOwner(); if (owner == null) { if (element instanceof Package) { return (Package) element; } } element = owner; } return null; }
/** Removes the listeners and the decorations */ public void deactivate() { removeDecoration(); IGraphicalEditPart gep = (IGraphicalEditPart) getDecoratorTarget().getAdapter(IGraphicalEditPart.class); assert gep != null; DiagramEventBroker.getInstance(gep.getEditingDomain()) .removeNotificationListener(gep.getNotationView(), notificationListener); View view = ((View) gep.getModel()); if (view instanceof Node) { // the location of the decorator can change if it's an Affixed Child // Node if (isInherited((Node) view) && Util.isAffixedChildNode(gep)) { DiagramEventBroker.getInstance(gep.getEditingDomain()) .removeNotificationListener(gep.getNotationView(), notificationListener); } } EObject parent = view.eContainer(); if (parent instanceof View) { EObject el = ((View) parent).getElement(); if (el instanceof Property) { DiagramEventBroker.getInstance(gep.getEditingDomain()) .removeNotificationListener( el, UMLPackage.eINSTANCE.getTypedElement_Type(), notificationListener); } } if (view.getElement() instanceof Element) { Element semanticElement = (Element) view.getElement(); if (semanticElement != null) { if (semanticElement.eContainer() != null) { DiagramEventBroker.getInstance(gep.getEditingDomain()) .addNotificationListener(semanticElement.eContainer(), notificationListener); } } } }
/** @generated */ protected CommandResult doExecuteWithResult(IProgressMonitor monitor, IAdaptable info) throws ExecutionException { Comment newElement = UMLFactory.eINSTANCE.createComment(); 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 { Element qualifiedTarget = (Element) target; qualifiedTarget.getOwnedComments().add(newElement); } } else { return CommandResult.newErrorCommandResult( "The active policy restricts the addition of this element"); } ElementInitializers.getInstance().init_Comment_3201(newElement); doConfigure(newElement, monitor, info); ((CreateElementRequest) getRequest()).setNewElement(newElement); return CommandResult.newOKCommandResult(newElement); }
@Override public String stereotypesOnlyToDisplay() { Object hostModel = getHost().getModel(); String result = ""; // $NON-NLS-1$ View view = (View) hostModel; EObject viewElement = view.getElement(); Element element = (Element) viewElement; Iterator<Stereotype> listStereotype = element.getAppliedStereotypes().iterator(); StringBuffer buffer = new StringBuffer(); while (listStereotype.hasNext()) { Stereotype stereotypec = listStereotype.next(); String stereotype_string = stereotypec.getQualifiedName(); buffer.append(stereotype_string); if (listStereotype.hasNext()) { buffer.append(","); // $NON-NLS-1$ } } result = buffer.toString(); if (result.length() != 0) { String stereotypespresentationKind = AppliedStereotypeHelper.getAppliedStereotypePresentationKind(view); // vertical representation if (UMLVisualInformationPapyrusConstant.STEREOTYPE_TEXT_VERTICAL_PRESENTATION.equals( stereotypespresentationKind)) { return Activator.ST_LEFT + stereotypesToDisplay(Activator.ST_RIGHT + "\n" + Activator.ST_LEFT, result, "") + Activator.ST_RIGHT; } else { // horizontal representation return Activator.ST_LEFT + stereotypesToDisplay(", ", result, "") + Activator.ST_RIGHT; } } return result; }
/** {@inheritDoc} */ public void deactivate() { // retrieve the view and the element managed by the edit part View view = getView(); if (view == null) { return; } getDiagramEventBroker().removeNotificationListener(view, this); if (hostSemanticElement == null) { return; } // remove listeners to applied stereotyped for (EObject stereotypeApplication : hostSemanticElement.getStereotypeApplications()) { getDiagramEventBroker().removeNotificationListener(stereotypeApplication, this); } // remove notification on element getDiagramEventBroker().removeNotificationListener(hostSemanticElement, this); // removes the reference to the semantic element hostSemanticElement = null; }
public void activate() { // retrieve the view and the element managed by the edit part View view = getView(); if (view == null) { return; } hostSemanticElement = getUMLElement(); // adds a listener on the view and the element controlled by the // editpart getDiagramEventBroker().addNotificationListener(view, this); if (hostSemanticElement == null) { return; } getDiagramEventBroker().addNotificationListener(hostSemanticElement, this); // adds the listener for stereotype application and applied stereotypes // add listener to react to the application and remove of a stereotype // add a lister to each already applied stereotyped for (EObject stereotypeApplication : hostSemanticElement.getStereotypeApplications()) { getDiagramEventBroker().addNotificationListener(stereotypeApplication, this); } currentHeadHeight = getHeadHeight(); }
protected void appendStereotype( final Element element, final StringBuffer sb, final boolean includeWrappers) { boolean first = true; final List stereotypes = element.getAppliedStereotypes(); if (stereotypes.isEmpty()) { return; } if (includeWrappers) { sb.append("<<"); // $NON-NLS-1$ } final Iterator iter = stereotypes.iterator(); while (iter.hasNext()) { final Stereotype stereotype = (Stereotype) iter.next(); if (!first) { sb.append(","); // $NON-NLS-1$ } first = false; sb.append(stereotype.getName()); } if (includeWrappers) { sb.append(">>"); // $NON-NLS-1$ } }
@Override public void undo() { for (Stereotype stereotype : stereotypes) { element.unapplyStereotype(stereotype); } }