From 67b9f96061cf0f5266282cf3f36d6fbc61f85e4c Mon Sep 17 00:00:00 2001 From: Nils Christian Ehmke <nils@rhocas.de> Date: Fri, 27 Mar 2015 15:14:19 +0100 Subject: [PATCH] Comments and some minor refactoring --- src/main/java/kieker/diagnosis/Main.java | 9 +++-- .../java/kieker/diagnosis/common/Mapper.java | 5 +++ .../kieker/diagnosis/mainview/Controller.java | 39 ++++++++----------- .../java/kieker/diagnosis/mainview/Model.java | 15 ++++--- .../java/kieker/diagnosis/mainview/View.java | 5 ++- 5 files changed, 39 insertions(+), 34 deletions(-) diff --git a/src/main/java/kieker/diagnosis/Main.java b/src/main/java/kieker/diagnosis/Main.java index daf7bef1..75284585 100644 --- a/src/main/java/kieker/diagnosis/Main.java +++ b/src/main/java/kieker/diagnosis/Main.java @@ -21,7 +21,7 @@ import kieker.diagnosis.mainview.Controller; import org.springframework.context.annotation.AnnotationConfigApplicationContext; /** - * Contains the main method of this application. + * Contains the main method of this application. Do not move this class without changing the scanned package name for the Spring context. * * @author Nils Christian Ehmke */ @@ -30,14 +30,15 @@ public final class Main { private Main() {} /** - * The main method of this application. + * The main method of this application. It initializes the Spring context and uses the main controller to start everything. * * @param args - * The command line arguments. They have no effect. + * The command line arguments. They have currently no effect. */ public static void main(final String[] args) { try (AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext()) { - context.scan("kieker.diagnosis"); + final String applicationPackageName = Main.class.getPackage().getName(); + context.scan(applicationPackageName); context.refresh(); final Controller controller = context.getBean(Controller.class); diff --git a/src/main/java/kieker/diagnosis/common/Mapper.java b/src/main/java/kieker/diagnosis/common/Mapper.java index 770826f9..36a3837f 100644 --- a/src/main/java/kieker/diagnosis/common/Mapper.java +++ b/src/main/java/kieker/diagnosis/common/Mapper.java @@ -16,6 +16,7 @@ package kieker.diagnosis.common; +import java.util.Collection; import java.util.HashMap; import java.util.Map; @@ -49,6 +50,10 @@ public final class Mapper<I, O> { return null; } + public Collection<O> values() { + return this.internalMap.values(); + } + public final class To { private final I key; diff --git a/src/main/java/kieker/diagnosis/mainview/Controller.java b/src/main/java/kieker/diagnosis/mainview/Controller.java index 8b078f71..ed37ffdd 100644 --- a/src/main/java/kieker/diagnosis/mainview/Controller.java +++ b/src/main/java/kieker/diagnosis/mainview/Controller.java @@ -16,15 +16,15 @@ package kieker.diagnosis.mainview; -import java.util.HashMap; -import java.util.Map; import java.util.logging.Logger; import java.util.prefs.BackingStoreException; import java.util.prefs.Preferences; import javax.annotation.PostConstruct; +import kieker.diagnosis.common.Mapper; import kieker.diagnosis.domain.OperationCall; +import kieker.diagnosis.mainview.Model.SubView; import kieker.diagnosis.mainview.dialog.SettingsDialog; import kieker.diagnosis.model.DataModel; import kieker.diagnosis.subview.ISubView; @@ -41,8 +41,7 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; /** - * The main controller of this application. It is responsible for creating top level models, further sub-controllers, and for creating and controlling the - * application's main view. The sub-views and their corresponding models are created by the sub-controllers. + * The main controller of this application. It is responsible for controlling the application's main window. * * @author Nils Christian Ehmke */ @@ -72,15 +71,15 @@ public final class Controller implements SelectionListener { @Autowired private Model model; - private Map<String, ISubView> subViews; + private Mapper<SubView, ISubView> subViewMapper; @PostConstruct public void initialize() { - this.subViews = new HashMap<>(); - this.subViews.put(SubView.AGGREGATED_TRACES_SUB_VIEW.name(), this.aggregatedTracesViewController.getView()); - this.subViews.put(SubView.TRACES_SUB_VIEW.name(), this.tracesViewController.getView()); - this.subViews.put(SubView.AGGREGATED_OPERATION_CALLS_SUB_VIEW.name(), this.aggregatedCallsViewController.getView()); - this.subViews.put(SubView.OPERATION_CALLS_SUB_VIEW.name(), this.callsViewController.getView()); + this.subViewMapper = new Mapper<>(); + this.subViewMapper.map(SubView.AGGREGATED_TRACES_SUB_VIEW).to(this.aggregatedTracesViewController.getView()); + this.subViewMapper.map(SubView.TRACES_SUB_VIEW).to(this.tracesViewController.getView()); + this.subViewMapper.map(SubView.AGGREGATED_OPERATION_CALLS_SUB_VIEW).to(this.aggregatedCallsViewController.getView()); + this.subViewMapper.map(SubView.OPERATION_CALLS_SUB_VIEW).to(this.callsViewController.getView()); } public void showView() { @@ -135,25 +134,25 @@ public final class Controller implements SelectionListener { private void handlePotentialTreeSelection(final SelectionEvent e) { // NOPMD (this method violates some metrics. This is acceptable, as it is readable) if (e.item == this.view.getTrtmExplorer()) { - this.model.setCurrentActiveSubView(SubView.NONE.name()); + this.model.setActiveSubView(SubView.NONE); } if (e.item == this.view.getTrtmTraces()) { - this.model.setCurrentActiveSubView(SubView.TRACES_SUB_VIEW.name()); + this.model.setActiveSubView(SubView.TRACES_SUB_VIEW); } if (e.item == this.view.getTrtmAggregatedTraces()) { - this.model.setCurrentActiveSubView(SubView.AGGREGATED_TRACES_SUB_VIEW.name()); + this.model.setActiveSubView(SubView.AGGREGATED_TRACES_SUB_VIEW); } if (e.item == this.view.getTrtmAggregatedOperationCalls()) { - this.model.setCurrentActiveSubView(SubView.AGGREGATED_OPERATION_CALLS_SUB_VIEW.name()); + this.model.setActiveSubView(SubView.AGGREGATED_OPERATION_CALLS_SUB_VIEW); } if (e.item == this.view.getTrtmOperationCalls()) { - this.model.setCurrentActiveSubView(SubView.OPERATION_CALLS_SUB_VIEW.name()); + this.model.setActiveSubView(SubView.OPERATION_CALLS_SUB_VIEW); } } public void jumpToCorrespondingTrace(final OperationCall call) { this.view.getTree().select(this.view.getTrtmTraces()); - this.model.setCurrentActiveSubView(SubView.TRACES_SUB_VIEW.name()); + this.model.setActiveSubView(SubView.TRACES_SUB_VIEW); this.tracesViewController.jumpToCorrespondingTrace(call); } @@ -162,12 +161,8 @@ public final class Controller implements SelectionListener { // Nothing to do here. This method is just required by the interface. } - public Map<String, ISubView> getSubViews() { - return this.subViews; - } - - public enum SubView { - TRACES_SUB_VIEW, AGGREGATED_TRACES_SUB_VIEW, NONE, AGGREGATED_OPERATION_CALLS_SUB_VIEW, OPERATION_CALLS_SUB_VIEW, + public Mapper<SubView, ISubView> getSubViews() { + return this.subViewMapper; } } diff --git a/src/main/java/kieker/diagnosis/mainview/Model.java b/src/main/java/kieker/diagnosis/mainview/Model.java index 9f63688b..4e654cda 100644 --- a/src/main/java/kieker/diagnosis/mainview/Model.java +++ b/src/main/java/kieker/diagnosis/mainview/Model.java @@ -25,7 +25,6 @@ import org.springframework.stereotype.Component; * * @author Nils Christian Ehmke */ - @Component public final class Model { @@ -33,7 +32,7 @@ public final class Model { private View view; private Cursor cursor; - private String currentActiveSubViewKey; + private SubView activeSubView; public Cursor getCursor() { return this.cursor; @@ -45,14 +44,18 @@ public final class Model { this.view.notifyAboutChangedCursor(); } - public String getCurrentActiveSubViewKey() { - return this.currentActiveSubViewKey; + public SubView getActiveSubView() { + return this.activeSubView; } - public void setCurrentActiveSubView(final String currentActiveSubViewKey) { - this.currentActiveSubViewKey = currentActiveSubViewKey; + public void setActiveSubView(final SubView activeSubView) { + this.activeSubView = activeSubView; this.view.notifyAboutChangedSubView(); } + public enum SubView { + TRACES_SUB_VIEW, AGGREGATED_TRACES_SUB_VIEW, NONE, AGGREGATED_OPERATION_CALLS_SUB_VIEW, OPERATION_CALLS_SUB_VIEW, + } + } diff --git a/src/main/java/kieker/diagnosis/mainview/View.java b/src/main/java/kieker/diagnosis/mainview/View.java index a4bb3d7d..a16ef5d1 100644 --- a/src/main/java/kieker/diagnosis/mainview/View.java +++ b/src/main/java/kieker/diagnosis/mainview/View.java @@ -16,6 +16,7 @@ package kieker.diagnosis.mainview; +import kieker.diagnosis.mainview.Model.SubView; import kieker.diagnosis.mainview.dialog.SettingsDialog; import kieker.diagnosis.model.PropertiesModel; import kieker.diagnosis.subview.ISubView; @@ -256,9 +257,9 @@ public final class View { } private void handleChangedSubView() { - final String subViewKey = this.model.getCurrentActiveSubViewKey(); + final SubView subView = this.model.getActiveSubView(); - final ISubView subViewToShow = this.controller.getSubViews().get(subViewKey); + final ISubView subViewToShow = this.controller.getSubViews().resolve(subView); final Composite compositeToShow = (subViewToShow != null) ? subViewToShow.getComposite() : null; // NOPMD (null assigment) this.subViewLayout.topControl = compositeToShow; -- GitLab