/* * (non-Javadoc) * * @see org.eclipse.papyrus.infra.gmfdiag.common.strategy.paste.IPasteStrategy#getSemanticCommand(org.eclipse.emf.edit.domain.EditingDomain, * org.eclipse.emf.ecore.EObject, org.eclipse.papyrus.infra.core.clipboard.PapyrusClipboard) */ @Override public org.eclipse.emf.common.command.Command getSemanticCommand( EditingDomain domain, EObject targetOwner, PapyrusClipboard<Object> papyrusClipboard) { CompoundCommand compoundCommand = new CompoundCommand("Rename root paste elements"); // $NON-NLS-1$ List<EObject> filterDescendants = EcoreUtil.filterDescendants(papyrusClipboard.getTarget()); for (Iterator<EObject> iterator = filterDescendants.iterator(); iterator.hasNext(); ) { EObject target = iterator.next(); if (target instanceof NamedElement) { NamedElement namedElement = (NamedElement) target; if (namedElement.getName() != null) { String defaultCopyNameWithIncrement = NamedElementUtil.getDefaultCopyNameWithIncrement( namedElement, targetOwner.eContents()); RenameElementCommand renameElementCommand = new RenameElementCommand( (TransactionalEditingDomain) domain, namedElement, defaultCopyNameWithIncrement); compoundCommand.append(renameElementCommand); } } } // An empty can't be executed if (compoundCommand.getCommandList().isEmpty()) { return null; } return compoundCommand; }
/** * Provides custom completion for specifying the type of a property, taking into account the path * if the name is qualified * * @see * org.eclipse.papyrus.uml.textedit.property.xtext.ui.contentassist.AbstractUmlPropertyProposalProvider#completeTypeRule_Type(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_Type( EObject model, Assignment assignment, ContentAssistContext context, ICompletionProposalAcceptor acceptor) { Namespace namespace = ((Property) ContextElementUtil.getContextElement(model.eResource())).getNamespace(); if (model instanceof TypeRule) { TypeRule typeRule = (TypeRule) model; QualifiedName path = typeRule.getPath(); while (path.getRemaining() != null) { path = path.getRemaining(); } namespace = path.getPath(); } else if (!(model instanceof PortRule)) { return; } for (NamedElement n : namespace.getOwnedMembers()) { if (n instanceof Classifier) { 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); } } } }
/** * 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); } } }
/** * 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; }
public String evaluate(final NamedElement context, final ParameterValueList parameterValues) throws ModelQueryExecutionException { // TODO Auto-generated method stub String txt = ""; List<Stereotype> stereoList = context.getAppliedStereotypes(); if (stereoList.size() == 0) { return context.getName(); } else { for (int i = 0; i < stereoList.size(); i++) { txt = txt + stereoList.get(i).getName(); if (i < stereoList.size() - 1) { txt = txt + ", "; } } txt = ST_LEFT + txt + ST_RIGHT + " " + context.getName(); return txt; } }
public void DealNamedElement(org.eclipse.uml2.uml.NamedElement ne1, RefOntoUML.NamedElement ne2) { System.out.println(ne1.getName()); // name ne2.setName(ne1.getName()); // visibility org.eclipse.uml2.uml.VisibilityKind vk1 = ne1.getVisibility(); if (vk1.getValue() == org.eclipse.uml2.uml.VisibilityKind.PUBLIC) { ne2.setVisibility(RefOntoUML.VisibilityKind.PUBLIC); } else if (vk1.getValue() == org.eclipse.uml2.uml.VisibilityKind.PRIVATE) { ne2.setVisibility(RefOntoUML.VisibilityKind.PRIVATE); } else if (vk1.getValue() == org.eclipse.uml2.uml.VisibilityKind.PROTECTED) { ne2.setVisibility(RefOntoUML.VisibilityKind.PROTECTED); } else if (vk1.getValue() == org.eclipse.uml2.uml.VisibilityKind.PACKAGE) { ne2.setVisibility(RefOntoUML.VisibilityKind.PACKAGE); } }
private void removeDerivedInterfacesInRoot(Model generatedModel) { // 2b: remove derived interfaces in root: derived interfaces // that can not be placed in the same package as the port type (e.g. // since read-only type from system library), are put in a top-level // package called "derivedInterfaces". Due to the copying of imports, // the top-level package has changed which implies that new derived // interfaces are put into a different package and the derivedInterfaces // package in the original root becomes obsolete. Delete this obsolete // package, if existing. for (PackageableElement packagedElement : generatedModel.getPackagedElements()) { if (packagedElement instanceof Package) { NamedElement derivedInterfaces = ((Package) packagedElement).getPackagedElement("derivedInterfaces"); // $NON-NLS-1$ if (derivedInterfaces instanceof Package) { derivedInterfaces.destroy(); } } } }
/** * Return the correct edit of a specific namedElement from an editPartCollection * * @param namedElement * @param editPartCollection * @return */ protected EditPart getEditPart( NamedElement namedElement, Collection<EditPart> editPartCollection) { for (EditPart editPart : editPartCollection) { Object model = editPart.getModel(); if (model instanceof View) { View view = (View) model; EObject element = view.getElement(); if (namedElement.equals(element)) { return editPart; } } } return null; }
/** * * <!-- begin-user-doc --> * <!-- end-user-doc --> * * @generated */ public NamedElement getBase_NamedElement() { if (base_NamedElement != null && base_NamedElement.eIsProxy()) { InternalEObject oldBase_NamedElement = (InternalEObject) base_NamedElement; base_NamedElement = (NamedElement) eResolveProxy(oldBase_NamedElement); if (base_NamedElement != oldBase_NamedElement) { if (eNotificationRequired()) eNotify( new ENotificationImpl( this, Notification.RESOLVE, GRMPackage.RESOURCE_USAGE__BASE_NAMED_ELEMENT, oldBase_NamedElement, base_NamedElement)); } } return base_NamedElement; }
@Test public void testCreationAndDestructionOnRequirement() { Object result = ModelExplorerUtils.executeCreateNestedEditorHandlerInModelExplorer( papyrusEditor, TableCreationInSysMLModelTest.view, AllTests.COMMAND_ID, TableCreationInSysMLModelTest.requirement1, BUNDLE_ID); // to refresh the table content DisplayUtils.flushEventLoop(); Assert.assertTrue(result instanceof NatTableEditor); NatTableEditor editor = (NatTableEditor) result; NattableModelManager manager = (NattableModelManager) editor.getAdapter(INattableModelManager.class); Assert.assertNotNull(manager); Table table = manager.getTable(); Assert.assertEquals(AllTests.REQUIREMENT_TABLE_ID, table.getTableConfiguration().getType()); IAxisManager rowAxisManager = manager.getRowAxisManager(); Collection<Object> managedAxis = rowAxisManager.getAllManagedAxis(); Assert.assertEquals(2, managedAxis.size()); Assert.assertTrue(managedAxis.contains(nestedRequirement1)); Assert.assertTrue(managedAxis.contains(nestedRequirement2)); Assert.assertEquals( managedAxis.size(), rowAxisManager.getTableManager().getRowElementsList().size()); Assert.assertTrue( rowAxisManager.getTableManager().getRowElementsList().contains(nestedRequirement1)); Assert.assertTrue( rowAxisManager.getTableManager().getRowElementsList().contains(nestedRequirement2)); final TransactionalEditingDomain domain = (TransactionalEditingDomain) papyrusEditor.getAdapter(TransactionalEditingDomain.class); Assert.assertNotNull(domain); IElementEditService provider = ElementEditServiceUtils.getCommandProvider(TableCreationInSysMLModelTest.requirement1); Assert.assertNotNull(provider); CreateElementRequest request = new CreateElementRequest( domain, TableCreationInSysMLModelTest.requirement1, SysMLElementTypes.REQUIREMENT); final ICommand creationCommand = provider.getEditCommand(request); Assert.assertNotNull(creationCommand); Assert.assertTrue(creationCommand.canExecute()); domain.getCommandStack().execute(new GMFtoEMFCommandWrapper(creationCommand)); final NamedElement createdElement = (NamedElement) request.getNewElement(); NamedElement requirement = TableCreationInSysMLModelTest.requirement1.getMember( createdElement.getName()); // $NON-NLS-1$ Assert.assertNotNull(requirement); nestedRequirement3 = (Class) requirement; // to refresh the table content DisplayUtils.flushEventLoop(); managedAxis = rowAxisManager.getAllManagedAxis(); Assert.assertEquals(3, managedAxis.size()); Assert.assertTrue(managedAxis.contains(nestedRequirement1)); Assert.assertTrue(managedAxis.contains(nestedRequirement2)); Assert.assertTrue(managedAxis.contains(nestedRequirement3)); Assert.assertEquals( managedAxis.size(), rowAxisManager.getTableManager().getRowElementsList().size()); Assert.assertTrue( rowAxisManager.getTableManager().getRowElementsList().contains(nestedRequirement1)); Assert.assertTrue( rowAxisManager.getTableManager().getRowElementsList().contains(nestedRequirement2)); Assert.assertTrue( rowAxisManager.getTableManager().getRowElementsList().contains(nestedRequirement3)); DestroyElementRequest destroyRequest = new DestroyElementRequest(domain, nestedRequirement3, false); provider = ElementEditServiceUtils.getCommandProvider(nestedRequirement3); final ICommand destroyCommand = provider.getEditCommand(destroyRequest); Assert.assertNotNull(destroyCommand); Assert.assertTrue(destroyCommand.canExecute()); domain.getCommandStack().execute(new GMFtoEMFCommandWrapper(destroyCommand)); requirement = TableCreationInSysMLModelTest.requirement1.getMember( createdElement.getName()); // $NON-NLS-1$ Assert.assertNull(requirement); nestedRequirement3 = (Class) requirement; // to refresh the table content DisplayUtils.flushEventLoop(); managedAxis = rowAxisManager.getAllManagedAxis(); Assert.assertEquals(2, managedAxis.size()); Assert.assertTrue(managedAxis.contains(nestedRequirement1)); Assert.assertTrue(managedAxis.contains(nestedRequirement2)); Assert.assertEquals( managedAxis.size(), rowAxisManager.getTableManager().getRowElementsList().size()); Assert.assertTrue( rowAxisManager.getTableManager().getRowElementsList().contains(nestedRequirement1)); Assert.assertTrue( rowAxisManager.getTableManager().getRowElementsList().contains(nestedRequirement2)); }
public static String endNodeFieldNameFor(NamedElement flow) { return "endNodeIn" + NameConverter.capitalize(flow.getName()); }
public static String getGuardMethod(NamedElement source, NamedElement flow) { return JavaNameGenerator.toJavaName( "is" + NameConverter.capitalize(source.getName()) + NameConverter.capitalize(flow.getName())); }
public static boolean isMatch(NamedElement element, String elementName, boolean ignoreCase) { return element.getName().equals(elementName) || (ignoreCase && element.getName().equalsIgnoreCase(elementName)); }