Skip to content

Refactor/new object diagram design level#126

Open
ahmedkha79 wants to merge 25 commits intouseocl:masterfrom
ahmedkha79:refactor/NewObjectDiagram-DesignLevel
Open

Refactor/new object diagram design level#126
ahmedkha79 wants to merge 25 commits intouseocl:masterfrom
ahmedkha79:refactor/NewObjectDiagram-DesignLevel

Conversation

@ahmedkha79
Copy link

MVP refactor: scaffold Presenter & Model, decouple view/canvas; add PlantUML docs

Summary

Introduce an incremental MVP scaffold for the object diagram to decouple UI rendering (view/canvas) from orchestration and persistence. This PR adds Presenter and Model contracts and light scaffolding so the subsequent, low-risk migration steps can proceed in small, testable commits.

Motivation

The original NewObjectDiagram (and its view) mixed rendering, user input handling, business logic and persistence. This created a large God class, high cyclomatic complexity and bidirectional couplings that reduce testability and maintainability. The scaffold in this PR prepares a Passive-View MVP: view = UI only; presenter = orchestrator; model = state; repository = persistence.

What changed

  • Added/updated Presenter and Model scaffolding for the object diagram.
  • Decoupled view/canvas from orchestration; view forwards events to Presenter.
  • Introduced PlacementRepository contract (persistence hook) and Null adapters to preserve current runtime behavior while migrating.
  • Added PlantUML documentation for current and target MVP in docs/.
  • Left fallbacks in place intentionally to avoid regressions during incremental migration.

Files included in this PR

(Committed files relevant to this PR)

  • use-gui/src/main/java/org/tzi/use/gui/views/diagrams/objectdiagram/NewObjectDiagramPresenter.java
  • use-gui/src/main/java/org/tzi/use/gui/views/diagrams/objectdiagram/NewObjectDiagramView.java
  • use-gui/src/main/java/org/tzi/use/gui/views/diagrams/objectdiagram/ObjectDiagramModel.java
  • use-gui/src/main/java/org/tzi/use/gui/views/diagrams/objectdiagram/PlacementRepository.java
  • use-gui/src/main/java/org/tzi/use/gui/views/diagrams/objectdiagram/NullPlacementRepository.java
  • use-gui/src/main/java/org/tzi/use/gui/views/diagrams/objectdiagram/NullContextMenuProvider.java
  • use-gui/src/main/java/org/tzi/use/gui/views/diagrams/objectdiagram/NullApplicationController.java
  • docs/objectdiagram_mvp_current.puml
  • docs/objectdiagram_mvp_target.puml

Behavior & backward compatibility

  • The commit is scaffolding only. Runtime behavior should remain unchanged because Null adapters act as no-ops that mirror the old code path for now.
  • Follow-up commits will incrementally move logic from NewObjectDiagram into Presenter and Model. Each chunk should be small and accompanied by a compile/run check.

Testing / QA instructions (PowerShell)

  1. Build GUI module:
    cd C:\Users\ahmed\IdeaProjects\use
    mvn -pl use-gui -DskipTests compile

  2. Smoke test (manual):

    • Start the application and open the Object Diagram.
    • Verify that the diagram opens without exceptions and that basic actions (select, context menu, basic create/delete) behave as before.
  3. Unit tests (next phase):

    • Write Presenter unit tests that mock the View and the PlacementRepository. Verify orchestration rules.

Acceptance checklist for merge

  • mvn -pl use-gui -DskipTests compile -> Build passes
  • Smoke test: Object Diagram opens and basic interactions work
  • Reviewers have checked the PlantUML architecture diagrams in docs/
  • Plan for next refactor chunks is acknowledged in the PR comments

Next steps (recommended incremental chunks)

  1. Move placement persistence (restore/storePlacementInfos) entirely to PlacementRepository; call from Presenter. (Chunk 1)
  2. Move visibility/highlight/selection state from NewObjectDiagram into ObjectDiagramModel; make NewObjectDiagram render model snapshots only. (Chunk 2)
  3. Route all menu actions, toolbar and shortcuts through the Presenter (remove direct application/system calls from view/diagram). (Chunk 3)
  4. Remove Null adapters, finalize API naming (drop I- prefixes if desired), add JavaDoc and unit tests. (Chunk 4)

Risks & mitigation

  • Risk: intermediate commits may create compile errors. Mitigation: perform small, reversible chunks, run build after each.
  • Risk: Null adapters could remain in code permanently by accident. Mitigation: mark them TODO/FIXME and schedule purge in the final chunk.
  • Risk: UI thread (Swing EDT) violations. Mitigation: Presenter must ensure View updates happen on EDT; tests should cover UI behavior where possible.

Suggested reviewers & labels

  • Reviewers: GUI/diagram maintainers, architecture reviewers
  • Labels: enhancement, refactor, needs-review, MVP

Short PR summary (for PR subject line)

MVP refactor: scaffold Presenter+Model to decouple view/canvas; add PlacementRepository and PlantUML docs

If you want, I can also:

  • Add this file to the current commit and push to a remote branch, or
  • Create the actual PR text in your remote hosting system (GitHub/GitLab) if you provide the target remote/branch name.

ahmed and others added 25 commits January 29, 2026 01:23
- Automatic Deletion of all unnecessary imports in use-gui with Copilot
…ty and consistency

- Use diamond operator (<>) to reduce generic verbosity
- Replace `size() > 0` checks with `isEmpty()` for clearer intent
- Convert simple anonymous listeners to lambdas to reduce boilerplate
- Remove redundant null checks before `instanceof`
- Simplify ternary negation and other small readability fixes
- Prepare code for follow-up refactors (extracting data structures, controllers)

No behavioral changes intended; this is a mechanical cleanup to reduce cognitive load and prepare the file for safer, larger refactors.
…or clarity improvements

- Fix broken Map access (use getLinkObjectToNodeEdge().get(link)) which caused compile errors and broken restore/delete flows.
- Add null checks before invoking methods on edges during restore and delete to avoid NPEs when layout data is missing.
- Change javaFxCall from boxed Boolean to primitive boolean and update setter for NPE safety and clarity.
- Correct copyTo Javadoc param description.
These are small, low-risk fixes to restore compileability and improve robustness and readability. No behavioral change expected.
Co-authored-by: automated-refactor-agent <refactor@example.com>
…e initializers, use computeIfAbsent, lambdas & method refs, improve drop logging, minor readability fixes
…accesses, use List.sort, use fLog.println, lambdas and small readability fixes
…n: - Map-safety & Null-Checks - Ersetzte unsichere Map.get()-Aufrufe durch computeIfPresent / null-checks. - Entfernte doppelte containsKey/get-Kombinationen. - Listener & Event-Handling - Entfernt unbenutztes Feld/innere Klasse ShowObjectPropertiesViewMouseListener. - Vereinfacht MouseListener mit Pattern Matching (instanceof). - Data & API - Vereinheitlichte Handhabung sichtbarer/verborgener Daten via ObjectDiagramData-Accessoren. - getVisibleData/getHiddenData abgestimmt. - getDefaultLayoutFileSuffix gesetzt. - Readability & Helpers - createAction Helper eingeführt, Boilerplate reduziert. - getLinkByValue implementiert (Restore/layouter Hilfsmethode). - Analyzer & Warnings - @SuppressWarnings(unused) wo sinnvoll (z.B. isHidden Persist-Helper Version).   - Weitere Konsistenz- und Null-Sicherheits-Fixes. Keine API-Breaking Änderungen; low-risk Refactorings zur Verbesserung der Lesbarkeit und Analysehygiene.
…n: - Map-safety & Null-Checks - Ersetzte unsichere Map.get()-Aufrufe durch computeIfPresent / null-checks. - Entfernte doppelte containsKey/get-Kombinationen. - Listener & Event-Handling - Entfernt unbenutztes Feld/innere Klasse ShowObjectPropertiesViewMouseListener. - Vereinfacht MouseListener mit Pattern Matching (instanceof). - Data & API - Vereinheitlichte Handhabung sichtbarer/verborgener Daten via ObjectDiagramData-Accessoren. - getVisibleData/getHiddenData abgestimmt. - getDefaultLayoutFileSuffix gesetzt. - Readability & Helpers - createAction Helper eingeführt, Boilerplate reduziert. - getLinkByValue implementiert (Restore/layouter Hilfsmethode). - Analyzer & Warnings - @SuppressWarnings(unused) wo sinnvoll (z.B. isHidden Persist-Helper Version).   - Weitere Konsistenz- und Null-Sicherheits-Fixes. Keine API-Breaking Änderungen; low-risk Refactorings zur Verbesserung der Lesbarkeit und Analysehygiene.
…gram/NewObjectDiagram.java

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
…gram/NewObjectDiagram.java

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
…gram/NewObjectDiagram.java

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
…gram/NewObjectDiagram.java

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
…gram/NewObjectDiagram.java

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
…gram/NewObjectDiagram.java

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
…gram/NewObjectDiagram.java

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
…gram/NewObjectDiagram.java

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
…gram/NewObjectDiagram.java

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
…ews.diagrams.objectdiagram)

Presenter: NewObjectDiagramPresenter
Model: ObjectDiagramModel
View/Presenter contracts (INew*/IObject* interfaces)
Persistence/auxiliary contracts: PlacementRepository, ContextMenuProvider, ApplicationController
No-op adapters: NullPlacementRepository, NullContextMenuProvider, NullApplicationController
Helper: DiagramCanvas and related small helpers
Motivation:
Decouple view rendering from presentation and model logic to remove bidirectional dependencies between diagram and view and to prepare an incremental refactoring towards MVP.
Make future refactorings safer by introducing clear contracts and temporary Null‑Adapters so behavior remains unchanged.
Behavioural note:
This commit wires the new presenter/model into the existing NewObjectDiagram/NewObjectDiagramView using Null adapters — intentionally preserves existing runtime behavior.
No domain logic moved yet; this is scaffolding for the follow-up steps.
Decoupled view/canvas from domain orchestration; forwarder/adapters (Null* adapters) used to keep behavior stable during migration.
Added PlantUML documentation for current and target MVP architecture.
Introduced/kept PlacementRepository contract for persistence hooks and ContextMenuProvider contract for menu callbacks.
Kept temporary fallbacks (Null adapters / no‑op providers) so runtime behavior remains unchanged while refactoring proceeds.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant