01/01: fixes #144: Select the parent on "left arrow" key
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 d97a2b4a8893bea456218d2df78f5624b9903ec2 Author: Eric Chatellier <chatellier@codelutin.com> Date: Wed Jun 20 17:13:34 2018 +0200 fixes #144: Select the parent on "left arrow" key --- src/main/java/org/chorem/jtimer/JTimer.java | 39 ++++---- .../jtimer/ui/treetable/ProjectsAndTasksTable.java | 103 ++++++++++++++------- 2 files changed, 89 insertions(+), 53 deletions(-) diff --git a/src/main/java/org/chorem/jtimer/JTimer.java b/src/main/java/org/chorem/jtimer/JTimer.java index c02b8b9..0402637 100644 --- a/src/main/java/org/chorem/jtimer/JTimer.java +++ b/src/main/java/org/chorem/jtimer/JTimer.java @@ -1438,24 +1438,7 @@ public class JTimer extends SingleFrameApplication implements if (e.getSource() == projectsAndTasksTable) { // demarre la tache lors d'un double clic dessus if (e.getClickCount() == 2) { - - if (isSelectedSingleStoppedTask()) { // can only launch non running tasks - Task<?, ?> appTask = startTask(); - if (appTask != null) { - - // first, on dlb click stop all running tasks - stopAllTasks(); - - getContext().getTaskService().execute(appTask); - } - } else if (isSelectedSingleTask()) { - TimerTask task = projectsAndTasksTable.getSelectedTasks().get(0); - stopTask(task); - } else { - if (log.isDebugEnabled()) { - log.debug("Non selected non running task to launch"); - } - } + startOrStopCurrentSelectedTask(); } else { if (log.isDebugEnabled()) { log.debug("Single clic on tree, do nothing"); @@ -1506,6 +1489,26 @@ public class JTimer extends SingleFrameApplication implements } } + public void startOrStopCurrentSelectedTask() { + if (isSelectedSingleStoppedTask()) { // can only launch non running tasks + Task<?, ?> appTask = startTask(); + if (appTask != null) { + + // first, on dlb click stop all running tasks + stopAllTasks(); + + getContext().getTaskService().execute(appTask); + } + } else if (isSelectedSingleTask()) { + TimerTask task = projectsAndTasksTable.getSelectedTasks().get(0); + stopTask(task); + } else { + if (log.isDebugEnabled()) { + log.debug("Non selected non running task to launch"); + } + } + } + @Override public void mouseEntered(MouseEvent e) { } 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 aabb82d..5356211 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 - 2016 CodeLutin, Chemit Tony + * Copyright (C) 2007 - 2018 CodeLutin, 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 @@ -22,12 +22,12 @@ package org.chorem.jtimer.ui.treetable; +import org.chorem.jtimer.JTimer; import org.chorem.jtimer.data.TimerCore; import org.chorem.jtimer.entities.TimerProject; import org.chorem.jtimer.entities.TimerTask; import org.chorem.jtimer.entities.TimerTaskHelper; import org.chorem.jtimer.ui.treetable.dnd.TimerTaskTransferHandler; -import org.jdesktop.application.Application; import org.jdesktop.application.ApplicationContext; import org.jdesktop.application.ResourceManager; import org.jdesktop.application.ResourceMap; @@ -61,6 +61,9 @@ public class ProjectsAndTasksTable extends JXTreeTable { /** serialVersionUID. */ private static final long serialVersionUID = -6909972377431117193L; + /** Parent application. */ + protected JTimer parent; + /** Table model. */ protected ProjectsAndTasksModel treeTableModel; @@ -70,13 +73,14 @@ public class ProjectsAndTasksTable extends JXTreeTable { /** * Constructor. * - * @param application application + * @param parent parent * @param core timer core */ - public ProjectsAndTasksTable(Application application, TimerCore core) { + public ProjectsAndTasksTable(JTimer parent, TimerCore core) { + this.parent = parent; // start with init i18n of table column name - ApplicationContext ctxt = application.getContext(); + ApplicationContext ctxt = parent.getContext(); ResourceManager mgr = ctxt.getResourceManager(); ResourceMap resourceMap = mgr.getResourceMap(ProjectsAndTasksTable.class); // init list @@ -103,44 +107,73 @@ public class ProjectsAndTasksTable extends JXTreeTable { // enable drag n drop setDragEnabled(true); - setTransferHandler(new TimerTaskTransferHandler(application, core.getData())); + setTransferHandler(new TimerTaskTransferHandler(parent, core.getData())); - { // add action to collapse (left arrow) selected node - Action action = new AbstractAction("collapseSelectedNode") { - private static final long serialVersionUID = 1L; + registerKeys(); + } - @Override - public void actionPerformed(ActionEvent e) { - int selectedRow = getSelectedRow(); - if (selectedRow != -1) { + /** + * Add some key action to tree. + */ + protected void registerKeys() { + // add action to collapse (left arrow) selected node + Action actionLeft = new AbstractAction("collapseSelectedNode") { + private static final long serialVersionUID = 1L; + + @Override + public void actionPerformed(ActionEvent e) { + int selectedRow = getSelectedRow(); + if (selectedRow != -1) { + if (isExpanded(selectedRow)) { collapseRow(selectedRow); + } else { + // select parent node + TimerTask timerTask = getSelectedTasks().get(0); + setSelectedTask(timerTask.getParent()); } } - }; + } + }; - getInputMap(WHEN_ANCESTOR_OF_FOCUSED_COMPONENT).put( - KeyStroke.getKeyStroke(KeyEvent.VK_LEFT, 0), - action.getValue(Action.NAME)); - getActionMap().put(action.getValue(Action.NAME), action); - } - { // add action to expand (right arrow) selected node - Action action = new AbstractAction("expandSelectedNode") { - private static final long serialVersionUID = 1L; - - @Override - public void actionPerformed(ActionEvent e) { - int selectedRow = getSelectedRow(); - if (selectedRow != -1) { - expandRow(selectedRow); - } + getInputMap(WHEN_ANCESTOR_OF_FOCUSED_COMPONENT).put( + KeyStroke.getKeyStroke(KeyEvent.VK_LEFT, 0), + actionLeft.getValue(Action.NAME)); + getActionMap().put(actionLeft.getValue(Action.NAME), actionLeft); + + + // add action to expand (right arrow) selected node + Action actionRight = new AbstractAction("expandSelectedNode") { + private static final long serialVersionUID = 1L; + + @Override + public void actionPerformed(ActionEvent e) { + int selectedRow = getSelectedRow(); + if (selectedRow != -1) { + expandRow(selectedRow); } - }; + } + }; - getInputMap(WHEN_ANCESTOR_OF_FOCUSED_COMPONENT).put( - KeyStroke.getKeyStroke(KeyEvent.VK_RIGHT, 0), - action.getValue(Action.NAME)); - getActionMap().put(action.getValue(Action.NAME), action); - } + getInputMap(WHEN_ANCESTOR_OF_FOCUSED_COMPONENT).put( + KeyStroke.getKeyStroke(KeyEvent.VK_RIGHT, 0), + actionRight.getValue(Action.NAME)); + getActionMap().put(actionRight.getValue(Action.NAME), actionRight); + + + // add action to collapse (left arrow) selected node + Action actionEnter = new AbstractAction("startSelectedTask") { + private static final long serialVersionUID = 1L; + + @Override + public void actionPerformed(ActionEvent e) { + parent.startOrStopCurrentSelectedTask(); + } + }; + + getInputMap(WHEN_ANCESTOR_OF_FOCUSED_COMPONENT).put( + KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0), + actionEnter.getValue(Action.NAME)); + getActionMap().put(actionEnter.getValue(Action.NAME), actionEnter); } /** -- To stop receiving notification emails like this one, please contact chorem.org SCM administrator <admin+scm@chorem.org>.
participants (1)
-
chorem.org scm