Skip to content

Commit 4feab10

Browse files
committed
Scan summary by double clicking scan cell in table and scrollable tables!
1 parent 200c9d9 commit 4feab10

20 files changed

Lines changed: 464 additions & 112 deletions

src/main/java/org/pwss/Start.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public static void main(String[] args) {
3333
NavigationEvents.setListener(navigator::navigateTo);
3434

3535
// Start with Login screen
36-
navigator.navigateTo(Screen.LOGIN);
36+
navigator.navigateTo(Screen.LOGIN, null);
3737

3838
// Finally, show the main frame hosting the screens :)
3939
frame.setVisible(true);

src/main/java/org/pwss/model/entity/File.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
* @param basename Base name of the file (name without directory path).
1111
* @param directory Directory path where the file is located.
1212
* @param size Size of the file in bytes.
13-
* @param mTime Last modification time of the file.
13+
* @param mtime Last modification time of the file.
1414
*/
15-
public record File(long id, String path, String basename, String directory, long size, Date mTime) {
15+
public record File(long id, String path, String basename, String directory, long size, Date mtime) {
1616
}

src/main/java/org/pwss/model/table/MonitoredDirectoryTableModel.java

Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,14 @@
11
package org.pwss.model.table;
22

33
import org.pwss.model.entity.MonitoredDirectory;
4-
import org.pwss.model.entity.Time;
54

65
import javax.swing.table.AbstractTableModel;
7-
import java.util.Date;
86
import java.util.List;
97

108
public class MonitoredDirectoryTableModel extends AbstractTableModel {
119
private final List<MonitoredDirectory> directories;
1210
private final String[] columnNames = {
13-
"ID", "Path", "Active", "Added At", "Last Scanned",
14-
"Notes", "Baseline Established", "Include Subdirectories"
11+
"Path", "Active", "Last Scanned", "Baseline Established", "Include Subdirectories"
1512
};
1613

1714
public MonitoredDirectoryTableModel(List<MonitoredDirectory> directories) {
@@ -36,26 +33,21 @@ public String getColumnName(int column) {
3633
@Override
3734
public Class<?> getColumnClass(int columnIndex) {
3835
return switch (columnIndex) {
39-
case 0 -> Long.class;
40-
case 2, 6, 7 -> Boolean.class;
41-
case 3 -> Time.class;
42-
case 4 -> Date.class;
43-
default -> String.class;
36+
case 1, 3, 4 -> Boolean.class;
37+
default -> super.getColumnClass(columnIndex);
4438
};
4539
}
4640

41+
4742
@Override
4843
public Object getValueAt(int rowIndex, int columnIndex) {
4944
MonitoredDirectory dir = directories.get(rowIndex);
5045
return switch (columnIndex) {
51-
case 0 -> dir.id();
52-
case 1 -> dir.path();
53-
case 2 -> dir.isActive();
54-
case 3 -> dir.addedAt().created();
55-
case 4 -> dir.lastScanned();
56-
case 5 -> dir.notes() != null ? dir.notes().notes() : "";
57-
case 6 -> dir.baselineEstablished();
58-
case 7 -> dir.includeSubdirectories();
46+
case 0 -> dir.path();
47+
case 1 -> dir.isActive();
48+
case 2 -> dir.lastScanned();
49+
case 3 -> dir.baselineEstablished();
50+
case 4 -> dir.includeSubdirectories();
5951
default -> null;
6052
};
6153
}
@@ -72,6 +64,5 @@ public MonitoredDirectory getDirectoryAt(int rowIndex) {
7264
}
7365
return null;
7466
}
75-
7667
}
7768

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
package org.pwss.model.table;
2+
3+
import org.pwss.model.entity.ScanSummary;
4+
5+
import javax.swing.table.AbstractTableModel;
6+
import java.util.List;
7+
8+
public class ScanSummaryTableModel extends AbstractTableModel {
9+
private final List<ScanSummary> data;
10+
private final String[] columns = {"File Path", "Last modified", "Notes"};
11+
12+
public ScanSummaryTableModel(List<ScanSummary> data) {
13+
this.data = data;
14+
}
15+
16+
@Override
17+
public int getRowCount() {
18+
return data.size();
19+
}
20+
21+
@Override
22+
public int getColumnCount() {
23+
return columns.length;
24+
}
25+
26+
@Override
27+
public String getColumnName(int column) {
28+
return columns[column];
29+
}
30+
31+
@Override
32+
public Object getValueAt(int rowIndex, int columnIndex) {
33+
ScanSummary summary = data.get(rowIndex);
34+
return switch (columnIndex) {
35+
case 0 -> summary.file().path();
36+
case 1 -> summary.file().mtime();
37+
case 2 -> summary.scan().notes().notes();
38+
default -> null;
39+
};
40+
}
41+
42+
/**
43+
* Get the ScanSummary object at the specified row index.
44+
*
45+
* @param rowIndex the index of the row in the table.
46+
* @return the ScanSummary object at the specified row index, or null if the index is out of bounds.
47+
*/
48+
public ScanSummary getSummaryAt(int rowIndex) {
49+
if (rowIndex >= 0 && rowIndex < data.size()) {
50+
return data.get(rowIndex);
51+
}
52+
return null;
53+
}
54+
}

src/main/java/org/pwss/model/table/ScanTableModel.java

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
public class ScanTableModel extends AbstractTableModel {
99
private final List<Scan> scans;
1010
private final String[] columnNames = {
11-
"ID", "Scan Time", "Status", "Notes", "Directory", "Baseline"
11+
"Directory", "Scan Time", "Status", "Notes"
1212
};
1313

1414
public ScanTableModel(List<Scan> scans) {
@@ -34,13 +34,24 @@ public String getColumnName(int column) {
3434
public Object getValueAt(int rowIndex, int columnIndex) {
3535
Scan scan = scans.get(rowIndex);
3636
return switch (columnIndex) {
37-
case 0 -> scan.id();
37+
case 0 -> scan.monitoredDirectory().path();
3838
case 1 -> scan.scanTime().created();
3939
case 2 -> scan.status();
4040
case 3 -> scan.notes() != null ? scan.notes().notes() : "";
41-
case 4 -> scan.monitoredDirectory() != null ? scan.monitoredDirectory().path() : "";
42-
case 5 -> scan.isBaselineScan();
4341
default -> null;
4442
};
4543
}
44+
45+
/**
46+
* Returns the Scan object at the specified row index.
47+
*
48+
* @param rowIndex the index of the row in the table.
49+
* @return the Scan object at the specified row index, or null if the index is out of bounds.
50+
*/
51+
public Scan getScanAt(int rowIndex) {
52+
if (rowIndex >= 0 && rowIndex < scans.size()) {
53+
return scans.get(rowIndex);
54+
}
55+
return null;
56+
}
4657
}

src/main/java/org/pwss/navigation/NavigationEvents.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package org.pwss.navigation;
22

3+
import org.pwss.presenter.util.NavigationContext;
4+
35
/**
46
* Handles navigation events within the application.
57
*/
@@ -22,10 +24,11 @@ public static void setListener(NavigationListener l) {
2224
* Navigates to the specified screen by invoking the listener's `onNavigate` method.
2325
*
2426
* @param screen The `Screen` to navigate to.
27+
* @param context The `NavigationContext` containing data for the new screen.
2528
*/
26-
public static void navigateTo(Screen screen) {
29+
public static void navigateTo(Screen screen, NavigationContext context) {
2730
if (listener != null) {
28-
listener.onNavigate(screen);
31+
listener.onNavigate(screen, context);
2932
}
3033
}
3134
}

src/main/java/org/pwss/navigation/NavigationHandler.java

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
import org.pwss.presenter.BasePresenter;
1010
import org.pwss.presenter.factory.PresenterFactory;
11+
import org.pwss.presenter.util.NavigationContext;
1112
import org.pwss.view.screen.BaseScreen;
1213

1314
/**
@@ -41,13 +42,16 @@ public NavigationHandler(JFrame frame, PresenterFactory factory) {
4142
}
4243

4344
/**
44-
* Navigates to the specified screen by retrieving or creating its presenter,
45-
* updating the frame's content pane with the presenter's view, and refreshing the frame.
45+
* Navigates to the specified screen, creating its presenter if it doesn't already exist.
46+
* The presenter is set with the provided navigation context, and its data is reloaded.
4647
*
47-
* @param screen The `Screen` to navigate to.
48+
* @param screen The `Screen` to navigate to.
49+
* @param context The `NavigationContext` containing data for the new screen.
4850
*/
49-
public void navigateTo(Screen screen) {
51+
public void navigateTo(Screen screen, NavigationContext context) {
5052
BasePresenter<?> presenter = presenters.computeIfAbsent(screen, factory::createPresenter);
53+
// Set the navigation context for the presenter
54+
presenter.setContext(context);
5155
BaseScreen baseScreen = presenter.getScreen();
5256
// Ensure the presenter reloads its data when navigating to the screen
5357
presenter.reloadData();
@@ -57,5 +61,8 @@ public void navigateTo(Screen screen) {
5761
frame.getContentPane().add(baseScreen.getRootPanel());
5862
frame.revalidate();
5963
frame.repaint();
64+
65+
// Notify the presenter that its screen is now visible
66+
presenter.onShow();
6067
}
6168
}
Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package org.pwss.navigation;
22

3+
import org.pwss.presenter.util.NavigationContext;
4+
35
/**
46
* A listener interface for handling navigation events within the application.
57
*/
@@ -8,6 +10,7 @@ public interface NavigationListener {
810
* Called when a navigation event occurs.
911
*
1012
* @param screen The `Screen` to navigate to.
13+
* @param context The `NavigationContext` containing data for the new screen.
1114
*/
12-
void onNavigate(Screen screen);
15+
void onNavigate(Screen screen, NavigationContext context);
1316
}

src/main/java/org/pwss/navigation/Screen.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,17 @@ public enum Screen {
1212
/**
1313
* The home screen displayed after successful login.
1414
*/
15-
HOME(600, 400),
15+
HOME(800, 600),
1616

1717
/**
1818
* The screen for creating a new monitored directory.
1919
*/
20-
NEW_DIRECTORY(400, 250);
20+
NEW_DIRECTORY(400, 250),
21+
22+
/**
23+
* The screen for viewing scan summaries.
24+
*/
25+
SCAN_SUMMARY(800, 600);
2126

2227
/**
2328
* The width of the frame for this screen.

src/main/java/org/pwss/presenter/BasePresenter.java

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package org.pwss.presenter;
22

3+
import org.pwss.presenter.util.NavigationContext;
34
import org.pwss.view.screen.BaseScreen;
45

56

@@ -14,6 +15,28 @@ public abstract class BasePresenter<Screen extends BaseScreen> {
1415
*/
1516
protected Screen screen;
1617

18+
/**
19+
* The navigation context for passing data between different parts of the application during navigation.
20+
*/
21+
private NavigationContext context;
22+
23+
/**
24+
* Retrieves the current navigation context.
25+
*
26+
* @return The `NavigationContext` instance associated with this presenter.
27+
*/
28+
protected NavigationContext getContext() {
29+
return context;
30+
}
31+
32+
/**
33+
* Sets the navigation context for the presenter.
34+
*
35+
* @param context
36+
*/
37+
public void setContext(NavigationContext context) {
38+
this.context = context;
39+
}
1740

1841
/**
1942
* Constructs a `BasePresenter` with the specified view.
@@ -56,4 +79,13 @@ public void reloadData() {
5679
public Screen getScreen() {
5780
return screen;
5881
}
82+
83+
/**
84+
* Method called when the view is shown.
85+
* Subclasses can override this method to perform actions when the view becomes visible.
86+
* The default implementation does nothing.
87+
*/
88+
public void onShow() {
89+
// Default implementation does nothing
90+
}
5991
}

0 commit comments

Comments
 (0)