This is an automated email from the git hooks/post-receive script. New commit to branch develop in repository jtimer. See https://gitlab.nuiton.org/chorem/jtimer.git commit 66a5144997928c9f0dd88e782f78d8cb3d761b34 Author: Eric Chatellier <chatellier@codelutin.com> Date: Tue Mar 22 17:45:53 2016 +0100 fixes #1348: After creating a task, set the focus on this new task --- src/main/java/org/chorem/jtimer/JTimer.java | 17 ++++++--- .../java/org/chorem/jtimer/ui/NewTaskView.java | 3 +- .../jtimer/ui/treetable/ProjectsAndTasksTable.java | 41 +++++++++++++++++----- 3 files changed, 46 insertions(+), 15 deletions(-) diff --git a/src/main/java/org/chorem/jtimer/JTimer.java b/src/main/java/org/chorem/jtimer/JTimer.java index c318f94..9eef46e 100644 --- a/src/main/java/org/chorem/jtimer/JTimer.java +++ b/src/main/java/org/chorem/jtimer/JTimer.java @@ -280,8 +280,7 @@ public class JTimer extends SingleFrameApplication implements // tree middle (center-top) ProjectsAndTasksTable projectTreeTable = createTreeTable(); - JScrollPane scrollPaneProjectTreeTable = new JScrollPane( - projectTreeTable); + JScrollPane scrollPaneProjectTreeTable = new JScrollPane(projectTreeTable); panel.add(scrollPaneProjectTreeTable, BorderLayout.CENTER); // status bar bottom @@ -313,8 +312,7 @@ public class JTimer extends SingleFrameApplication implements projectsAndTasksTable.setShowClosed(config.isShowClosed()); // since merge option, selection can be multiple - projectsAndTasksTable - .setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION); + projectsAndTasksTable.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION); // remove F2 KeyStroke from table KeyStroke keyToRemove = KeyStroke.getKeyStroke(KeyEvent.VK_F2, 0); @@ -323,7 +321,7 @@ public class JTimer extends SingleFrameApplication implements imap.remove(keyToRemove); imap = imap.getParent(); } - + // default lines are non visible projectsAndTasksTable.putClientProperty("JTree.lineStyle", "Angled"); @@ -645,6 +643,15 @@ public class JTimer extends SingleFrameApplication implements } /** + * Auto select task after creation. + * + * @param task task to select + */ + public void selectTask(TimerTask task) { + projectsAndTasksTable.setSelectedTask(task); + } + + /** * Edit task. * * Enabled when a task is selected diff --git a/src/main/java/org/chorem/jtimer/ui/NewTaskView.java b/src/main/java/org/chorem/jtimer/ui/NewTaskView.java index 29c9aba..9b6f9c8 100644 --- a/src/main/java/org/chorem/jtimer/ui/NewTaskView.java +++ b/src/main/java/org/chorem/jtimer/ui/NewTaskView.java @@ -24,12 +24,10 @@ package org.chorem.jtimer.ui; import java.awt.GridBagConstraints; import java.awt.GridBagLayout; import java.awt.Insets; -import java.awt.event.ActionEvent; import java.util.Date; import java.util.Map; import java.util.Set; -import javax.swing.AbstractAction; import javax.swing.ActionMap; import javax.swing.DefaultComboBoxModel; import javax.swing.ImageIcon; @@ -156,6 +154,7 @@ public class NewTaskView extends DialogView { try { core.getData().addTask(selectedTask, t, taskTemplate); + parent.selectTask(t); } catch (DataViolationException e) { parent.displayErrorMessage(e.getExceptionKey()); } diff --git a/src/main/java/org/chorem/jtimer/ui/treetable/ProjectsAndTasksTable.java b/src/main/java/org/chorem/jtimer/ui/treetable/ProjectsAndTasksTable.java index fac743b..b087b51 100644 --- a/src/main/java/org/chorem/jtimer/ui/treetable/ProjectsAndTasksTable.java +++ b/src/main/java/org/chorem/jtimer/ui/treetable/ProjectsAndTasksTable.java @@ -2,7 +2,7 @@ * #%L * jTimer * %% - * Copyright (C) 2007 - 2012 CodeLutin, Chatellier Eric, Chemit Tony + * Copyright (C) 2007 - 2016 CodeLutin, Chatellier Eric, Chemit Tony * %% * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as @@ -26,6 +26,8 @@ import java.awt.Color; import java.awt.event.ActionEvent; import java.awt.event.KeyEvent; import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; import java.util.List; import javax.swing.AbstractAction; @@ -78,12 +80,10 @@ public class ProjectsAndTasksTable extends JXTreeTable { // start with init i18n of table column name ApplicationContext ctxt = application.getContext(); ResourceManager mgr = ctxt.getResourceManager(); - ResourceMap resourceMap = mgr - .getResourceMap(ProjectsAndTasksTable.class); + ResourceMap resourceMap = mgr.getResourceMap(ProjectsAndTasksTable.class); // init list List<String> columnIdentifiers = new ArrayList<>(); - columnIdentifiers.add(resourceMap - .getString("projectsAndTaskColumnName")); + columnIdentifiers.add(resourceMap.getString("projectsAndTaskColumnName")); columnIdentifiers.add(resourceMap.getString("todayTimeColumnName")); columnIdentifiers.add(resourceMap.getString("totalTimeColumnName")); @@ -107,7 +107,7 @@ public class ProjectsAndTasksTable extends JXTreeTable { setDragEnabled(true); setTransferHandler(new TimerTaskTransferHandler(application, core.getData())); - { // add action to collapse (left arrow) selected node + { // add action to collapse (left arrow) selected node Action action = new AbstractAction("collapseSelectedNode") { private static final long serialVersionUID = 1L; @@ -125,7 +125,7 @@ public class ProjectsAndTasksTable extends JXTreeTable { action.getValue(Action.NAME)); getActionMap().put(action.getValue(Action.NAME), action); } - { // add action to expand (right arrow) selected node + { // add action to expand (right arrow) selected node Action action = new AbstractAction("expandSelectedNode") { private static final long serialVersionUID = 1L; @@ -137,7 +137,7 @@ public class ProjectsAndTasksTable extends JXTreeTable { } } }; - + getInputMap(WHEN_ANCESTOR_OF_FOCUSED_COMPONENT).put( KeyStroke.getKeyStroke(KeyEvent.VK_RIGHT, 0), action.getValue(Action.NAME)); @@ -252,4 +252,29 @@ public class ProjectsAndTasksTable extends JXTreeTable { return results; } + + /** + * Set selected task in tree. + * + * @param task task + */ + public void setSelectedTask(TimerTask task) { + // compute task tree path + List<TimerTask> components = new ArrayList<>(); + TimerTask current = task; + while (current != null) { + components.add(current); + current = current.getParent(); + } + + // add model root + components.add((TimerTask)treeTableModel.getRoot()); + + // select tree path in reverse order (from root to leaf) + Collections.reverse(components); + System.out.println("path " + components); + TreePath path = new TreePath(components.toArray()); + int row = getRowForPath(path); + getSelectionModel().setSelectionInterval(row, row); + } } -- To stop receiving notification emails like this one, please contact chorem.org SCM administrator <admin+scm@chorem.org>.