Skip to content
Snippets Groups Projects
Commit be278116 authored by Ondřej Hrdlička's avatar Ondřej Hrdlička
Browse files

Fixed general project problems

parent daa22bb5
No related branches found
No related tags found
2 merge requests!52Final project MR,!48Implement dao tests
Pipeline #
Showing
with 29 additions and 46 deletions
......@@ -9,8 +9,8 @@ public class CategoryTime {
private Long id;
private Long taskId;
private LocalDate completionDate;
private final Long taskId;
private final LocalDate completionDate;
private Duration timeSpent;
public CategoryTime(LocalDate completionDate, Long hoursSpent, Long taskId) {
......
......@@ -24,13 +24,13 @@ public class DaoHolder {
private final TaskDao taskDao;
public DaoHolder(DataSource dataSource) {
var taskManager = new TaskManager(dataSource);
var subTaskManager = new SubTaskManager(dataSource); // must be after TaskManager
var dependencyManager = new DependencyManager(dataSource); // must be after TaskManager
new TaskManager(dataSource);
new SubTaskManager(dataSource);
new DependencyManager(dataSource);
var categoryManager = new CategoryManager(dataSource);
var taskCategoryManager = new TaskCategoryManager(dataSource); // must be after CategoryManager
var categoryTimeManager = new CategoryTimeManager(dataSource); // must be after CategoryManager
new CategoryManager(dataSource);
new TaskCategoryManager(dataSource);
new CategoryTimeManager(dataSource);
var categoryTimeDao = new CategoryTimeDao(dataSource);
categoryDao = new CategoryDao(dataSource, categoryTimeDao);
......
......@@ -13,7 +13,7 @@ public class CategoryManager implements DataAccessManager {
public CategoryManager(DataSource dataSource) {
this.dataSource = dataSource;
if (!tableExists()) {
if (tableDoesNotExist()) {
createTable();
}
}
......
......@@ -13,7 +13,7 @@ public class CategoryTimeManager implements DataAccessManager {
public CategoryTimeManager(DataSource dataSource) {
this.dataSource = dataSource;
if (!tableExists()) {
if (tableDoesNotExist()) {
createTable();
}
}
......
......@@ -13,7 +13,7 @@ public class DependencyManager implements DataAccessManager {
public DependencyManager(DataSource dataSource) {
this.dataSource = dataSource;
if (!tableExists()) {
if (tableDoesNotExist()) {
createTable();
}
}
......
......@@ -10,10 +10,10 @@ public interface DataAccessManager extends ConnectionProvider {
String getCreateTableStatement();
default boolean tableExists() {
default boolean tableDoesNotExist() {
try (var connection = getConnection();
var rs = connection.getMetaData().getTables(null, null, getTableName(), null)) {
return rs.next();
return !rs.next();
} catch (SQLException ex) {
throw new DataAccessException("Failed to detect if the table " + getTableName() + " exist", ex);
}
......
......@@ -13,7 +13,7 @@ public class SubTaskManager implements DataAccessManager {
public SubTaskManager(DataSource dataSource) {
this.dataSource = dataSource;
if (!tableExists()) {
if (tableDoesNotExist()) {
createTable();
}
}
......
......@@ -13,7 +13,7 @@ public class TaskManager implements DataAccessManager {
public TaskManager(DataSource dataSource) {
this.dataSource = dataSource;
if (!tableExists()) {
if (tableDoesNotExist()) {
createTable();
}
}
......
......@@ -13,7 +13,7 @@ public class TaskCategoryManager implements DataAccessManager {
public TaskCategoryManager(DataSource dataSource) {
this.dataSource = dataSource;
if (!tableExists()) {
if (tableDoesNotExist()) {
createTable();
}
}
......
......@@ -22,7 +22,6 @@ abstract class AbstractEntityDialog<E> extends JDialog {
private final JPanel panel;
private final JButton okButton;
private final JButton cancelButton;
private boolean wasOk;
......@@ -36,7 +35,7 @@ abstract class AbstractEntityDialog<E> extends JDialog {
wasOk = true;
this.dispose();
});
cancelButton = new JButton("Cancel");
JButton cancelButton = new JButton("Cancel");
cancelButton.addActionListener(e -> this.dispose());
GridBagConstraints gbc = new GridBagConstraints();
......
......@@ -16,23 +16,18 @@ import java.awt.Dimension;
public class MainWindow {
private final JFrame mainFrame;
private final JPanel mainPanel;
private final CardPanel toolbarPanel;
private final TabContainer tabContainer;
public MainWindow(DaoHolder daoHolder) {
mainFrame = new JFrame();
mainPanel = new JPanel(new BorderLayout());
toolbarPanel = new CardPanel();
tabContainer = initializeTabbedPane(daoHolder);
JPanel mainPanel = new JPanel(new BorderLayout());
mainPanel.add(tabContainer.getTabbedPane(), BorderLayout.CENTER);
mainPanel.add(toolbarPanel.getContainer(), BorderLayout.NORTH);
JFrame mainFrame = new JFrame();
mainFrame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
mainFrame.setTitle("to:do");
mainFrame.setSize(1280, 720);
......
......@@ -5,8 +5,8 @@ import javax.swing.JPanel;
import java.awt.CardLayout;
public class CardPanel {
private CardLayout cardLayout;
private JPanel outerPanel;
private final CardLayout cardLayout;
private final JPanel outerPanel;
public CardPanel() {
cardLayout = new CardLayout();
......
......@@ -16,10 +16,6 @@ public class CircleColorPanel extends JPanel {
this.setOpaque(false);
}
public void setColor(Color color) {
this.color = color;
}
@Override
protected void paintComponent(Graphics g) {
super.paintComponent(g);
......
......@@ -68,10 +68,6 @@ public abstract class AbstractHolderPanel<T> implements ListHolder<T>, Updatable
jList.setCustomListModel(listModel);
}
protected Optional<CounterPanel<T>> getCounterPanel() {
return counterPanel;
}
@Override
public void updateFrom(Task parent) {
currentTask = parent;
......
......@@ -22,7 +22,7 @@ import java.util.Optional;
public class SubTaskHolderPanel extends AbstractHolderPanel<SubTask> {
DbOneToNModel<SubTask> model;
private final DbOneToNModel<SubTask> model;
public SubTaskHolderPanel(DbConnectedModel<Task> parentTaskModel, OneToNDao<SubTask> subTaskDao) {
super(parentTaskModel,
......
......@@ -12,7 +12,7 @@ import java.awt.event.ActionListener;
public class TasksToolBar {
private JToolBar toolBar;
private final JToolBar toolBar;
private final JCheckBox isJustToday;
private final JComboBox<TaskStatus> taskTypes;
......
......@@ -24,7 +24,6 @@ public class CategoryAndStatisticsView implements Tab<Category> {
private final DbConnectedModel<Category> categoryModel;
private final CategoriesStatisticsToolBar toolBar;
private final TabActions tabActions;
private final JSplitPane splitPane;
......@@ -38,7 +37,7 @@ public class CategoryAndStatisticsView implements Tab<Category> {
this.categoryView = new CategoryView(categoryModel);
this.statisticsView = new StatisticsView(categoryModel);
tabActions = TabActions.builder()
TabActions tabActions = TabActions.builder()
.addLeftSideAction(new AddAction<>(this, Icons.ADD_CATEGORY_ICON, "Add a new category"))
.addLeftSideAction(new EditAction<>(this, Icons.EDIT_CATEGORY_ICON, "Edit a selected category"))
.addLeftSideAction(new DeleteAction<>(this, Icons.REMOVE_CATEGORY_BIN_ICON, "Delete a selected category")
......@@ -61,9 +60,7 @@ public class CategoryAndStatisticsView implements Tab<Category> {
}
private void setupToolBar() {
toolBar.addDateActionListener(actionEvent -> {
statisticsView.updateTable(toolBar.getFromDate(), toolBar.getToDate());
});
toolBar.addDateActionListener(actionEvent -> statisticsView.updateTable(toolBar.getFromDate(), toolBar.getToDate()));
}
@Override
......
......@@ -25,8 +25,8 @@ public abstract class AbstractStatisticsRenderer<T> implements TableCellRenderer
tableCellRenderer.setForeground(null);
var component = (JComponent) tableCellRenderer.getTableCellRendererComponent(
table, value, isSelected, hasFocus, row, column);
return modifyComponent(component, elementType.cast(value));
return modifyComponent(elementType.cast(value));
}
protected abstract JComponent modifyComponent(JComponent component, T value);
protected abstract JComponent modifyComponent(T value);
}
......@@ -13,7 +13,7 @@ public class CategoryStatisticsRenderer extends AbstractStatisticsRenderer<Categ
}
@Override
protected JComponent modifyComponent(JComponent component, Category value) {
protected JComponent modifyComponent(Category value) {
final var panel = new JPanel();
panel.add(new JLabel(value.getName()));
panel.add(new CircleColorPanel(value.getColor()));
......
......@@ -10,7 +10,7 @@ public class TimeSpentStatisticsRenderer extends AbstractStatisticsRenderer<Stri
}
@Override
protected JComponent modifyComponent(JComponent component, String value) {
protected JComponent modifyComponent(String value) {
final var panel = new JPanel();
panel.add(new JLabel(value));
return panel;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment