diff --git a/src/main/java/kieker/diagnosis/Main.java b/src/main/java/kieker/diagnosis/Main.java index daf7bef14a29f2cee4cdb6c7fb73138a7817fbbc..75284585ce3a0df4f9d4709e3f34fe2bc579d23a 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 770826f9189fb7b3ac6348c4a7785e40d4f35cbb..36a3837f8cbf085afb934b0cd6ba1d4707c20697 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 8b078f71b47a2f515787a32cbd481ae31340c480..ed37ffdd95adfa2804eaad0ac0873a1eb9e6847b 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 9f63688bfac42d328f01cdccde90d1723e726a1f..4e654cda5c36c6f2dde7b282983c555d957d70d0 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 a4bb3d7d637779bddce9fd62ed1f58872db47717..a16ef5d1ca0e092c90f1ef116bf946cb9c8b1167 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;