-
-
Notifications
You must be signed in to change notification settings - Fork 187
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #298 from gaphor/feature/package-import
Add Package Import to Toolbar
- Loading branch information
Showing
6 changed files
with
171 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
"""Profile Import dependency relationship.""" | ||
|
||
from gaphor import UML | ||
from gaphor.diagram.presentation import LinePresentation | ||
from gaphor.diagram.shapes import Text, draw_arrow_head | ||
from gaphor.diagram.support import represents | ||
from gaphor.UML.modelfactory import stereotypes_str | ||
|
||
|
||
@represents(UML.PackageImport) | ||
class PackageImportItem(LinePresentation): | ||
"""Profile Import dependency relationship.""" | ||
|
||
def __init__(self, id=None, model=None): | ||
super().__init__(id, model, style={"dash-style": (7.0, 5.0)}) | ||
|
||
self.shape_middle = Text( | ||
text=lambda: stereotypes_str(self.subject, ("import",)), | ||
style={"min-width": 0, "min-height": 0}, | ||
) | ||
self.watch("subject.appliedStereotype.classifier.name") | ||
self.draw_head = draw_arrow_head |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
"""Package Import connection adapters.""" | ||
|
||
from gaphor import UML | ||
from gaphor.diagram.connectors import Connector, RelationshipConnect | ||
from gaphor.diagram.presentation import Named | ||
from gaphor.diagram.profiles.packageimport import PackageImportItem | ||
|
||
|
||
@Connector.register(Named, PackageImportItem) | ||
class PackageImportConnect(RelationshipConnect): | ||
"""Connect an external model to a Package using an Import.""" | ||
|
||
def allow(self, handle, port): | ||
line = self.line | ||
element = self.element | ||
|
||
# Element at the head should be a Package | ||
if handle is line.head and not isinstance(element.subject, UML.Package): | ||
return None | ||
|
||
# Element at the tail should also be a Package | ||
if handle is line.tail and not isinstance(element.subject, UML.Package): | ||
return None | ||
|
||
return super().allow(handle, port) | ||
|
||
def reconnect(self, handle, port): | ||
line = self.line | ||
impl = line.subject | ||
assert isinstance(impl, UML.Package) | ||
self.reconnect_relationship( | ||
handle, | ||
UML.PackageImport.importedPackage, | ||
UML.PackageImport.importingNamespace, | ||
) | ||
|
||
def connect_subject(self, handle): | ||
"""Perform import package relationship connection.""" | ||
relation = self.relationship_or_new( | ||
UML.PackageImport, | ||
UML.PackageImport.importedPackage, | ||
UML.PackageImport.importingNamespace, | ||
) | ||
self.line.subject = relation |
47 changes: 47 additions & 0 deletions
47
gaphor/diagram/profiles/tests/test_packageimportconnect.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
"""Package Import Item connection adapter tests.""" | ||
|
||
from gaphor import UML | ||
from gaphor.diagram.classes.klass import ClassItem | ||
from gaphor.diagram.classes.package import PackageItem | ||
from gaphor.diagram.profiles.packageimport import PackageImportItem | ||
from gaphor.diagram.tests.fixtures import allow, connect | ||
|
||
|
||
def test_glue(element_factory, diagram): | ||
"""Test gluing package import item.""" | ||
|
||
pkg_import = diagram.create(PackageImportItem) | ||
package1 = diagram.create(PackageItem, subject=element_factory.create(UML.Package)) | ||
package2 = diagram.create(PackageItem, subject=element_factory.create(UML.Package)) | ||
|
||
glued = allow(pkg_import, pkg_import.tail, package1) | ||
|
||
assert glued | ||
|
||
connect(pkg_import, pkg_import.tail, package1) | ||
|
||
glued = allow(pkg_import, pkg_import.head, package2) | ||
|
||
assert glued | ||
|
||
|
||
def test_package_glue(element_factory, diagram): | ||
"""Test package import item can't glue to a class.""" | ||
|
||
pkg_import = diagram.create(PackageImportItem) | ||
import_class = diagram.create(ClassItem, subject=element_factory.create(UML.Class)) | ||
|
||
glued = allow(pkg_import, pkg_import.head, import_class) | ||
|
||
assert not glued | ||
|
||
|
||
def test_connection(element_factory, diagram): | ||
"""Test package import item connection.""" | ||
|
||
pkg_import = diagram.create(PackageImportItem) | ||
package1 = diagram.create(PackageItem, subject=element_factory.create(UML.Package)) | ||
package2 = diagram.create(PackageItem, subject=element_factory.create(UML.Package)) | ||
|
||
connect(pkg_import, pkg_import.tail, package1) | ||
connect(pkg_import, pkg_import.head, package2) |
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.