IDEA-74652 Time tracking features. New way calculate time - is using timer.

This commit is contained in:
Evgeny Zakrevsky
2012-11-13 21:32:05 +04:00
parent e3a17a5b6c
commit e8bbe3e40b
4 changed files with 20 additions and 52 deletions
@@ -53,8 +53,4 @@ public abstract class LocalTask extends Task {
public abstract long getTimeSpent();
public abstract void setTimeSpent(long time);
public abstract long getActivated();
public abstract void setActivated(long time);
}
@@ -59,7 +59,6 @@ public class LocalTaskImpl extends LocalTask {
private boolean myActive;
private List<ChangeListInfo> myChangeLists = new ArrayList<ChangeListInfo>();
private long myTimeSpent = 0;
private long myActivated;
/** for serialization */
@@ -271,14 +270,4 @@ public class LocalTaskImpl extends LocalTask {
public void setTimeSpent(final long timeSpent) {
myTimeSpent = timeSpent;
}
@Override
public long getActivated() {
return myActivated;
}
@Override
public void setActivated(final long time) {
myActivated = time;
}
}
@@ -25,8 +25,6 @@ import com.intellij.openapi.progress.ProcessCanceledException;
import com.intellij.openapi.progress.ProgressIndicator;
import com.intellij.openapi.progress.ProgressManager;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.project.ProjectManager;
import com.intellij.openapi.project.ProjectManagerAdapter;
import com.intellij.openapi.startup.StartupManager;
import com.intellij.openapi.ui.Messages;
import com.intellij.openapi.util.Comparing;
@@ -96,6 +94,7 @@ public class TaskManagerImpl extends TaskManager implements ProjectComponent, Pe
}
};
static final String TASKS_NOTIFICATION_GROUP = "Task Group";
public static final int TIME_TRACKING_TIME_UNIT = 1000;
private final Project myProject;
@@ -120,7 +119,6 @@ public class TaskManagerImpl extends TaskManager implements ProjectComponent, Pe
return result;
}
});
private final ProjectManagerAdapter myProjectManagerListener;
@NotNull
private LocalTask myActiveTask = createDefaultTask();
@@ -134,7 +132,7 @@ public class TaskManagerImpl extends TaskManager implements ProjectComponent, Pe
private final List<TaskRepository> myRepositories = new ArrayList<TaskRepository>();
private final EventDispatcher<TaskListener> myDispatcher = EventDispatcher.create(TaskListener.class);
private Set<TaskRepository> myBadRepositories = new ConcurrentHashSet<TaskRepository>();
private long myProjectOpenedTime = 0;
private Timer myTimeTrackingTimer;
public TaskManagerImpl(Project project,
WorkingContextManager contextManager,
@@ -162,33 +160,6 @@ public class TaskManagerImpl extends TaskManager implements ProjectComponent, Pe
}
}
};
addTaskListener(new TaskListenerAdapter() {
@Override
public void taskDeactivated(final LocalTask task) {
assert task.getActivated() != 0;
task.setTimeSpent(task.getTimeSpent() + System.currentTimeMillis() - task.getActivated());
}
@Override
public void taskActivated(final LocalTask task) {
task.setActivated(System.currentTimeMillis());
}
});
myProjectManagerListener = new ProjectManagerAdapter() {
@Override
public boolean canCloseProject(final Project project) {
assert myProjectOpenedTime != 0;
getState().myTotallyTimeSpent += System.currentTimeMillis() - myProjectOpenedTime;
myProjectOpenedTime = 0;
assert myActiveTask.getActivated() != 0;
myActiveTask.setTimeSpent(myActiveTask.getTimeSpent() + System.currentTimeMillis() - myActiveTask.getActivated());
myActiveTask.setActivated(0);
return true;
}
};
ProjectManager.getInstance().addProjectManagerListener(myProjectManagerListener);
}
@Override
@@ -575,8 +546,6 @@ public class TaskManagerImpl extends TaskManager implements ProjectComponent, Pe
}
myContextManager.pack(200, 50);
myProjectOpenedTime = System.currentTimeMillis();
}
private TaskProjectConfiguration getProjectConfiguration() {
@@ -609,6 +578,19 @@ public class TaskManagerImpl extends TaskManager implements ProjectComponent, Pe
});
}
myTimeTrackingTimer = UIUtil.createNamedTimer("TaskManager time tracking", TIME_TRACKING_TIME_UNIT, new ActionListener() {
@Override
public void actionPerformed(final ActionEvent e) {
getActiveTask().setTimeSpent(getActiveTask().getTimeSpent() + TIME_TRACKING_TIME_UNIT);
getState().myTotallyTimeSpent += TIME_TRACKING_TIME_UNIT;
}
});
StartupManager.getInstance(myProject).registerStartupActivity(new Runnable() {
public void run() {
myTimeTrackingTimer.start();
}
});
LocalTask defaultTask = myTasks.get(LocalTaskImpl.DEFAULT_TASK_ID);
if (defaultTask == null) {
defaultTask = createDefaultTask();
@@ -663,8 +645,10 @@ public class TaskManagerImpl extends TaskManager implements ProjectComponent, Pe
if (myCacheRefreshTimer != null) {
myCacheRefreshTimer.stop();
}
if (myTimeTrackingTimer != null) {
myTimeTrackingTimer.stop();
}
myChangeListManager.removeChangeListListener(myChangeListListener);
ProjectManager.getInstance().removeProjectManagerListener(myProjectManagerListener);
}
public void updateIssues(final @Nullable Runnable onComplete) {
@@ -8,6 +8,7 @@ import com.intellij.openapi.util.IconLoader;
import com.intellij.tasks.LocalTask;
import com.intellij.tasks.TaskListenerAdapter;
import com.intellij.tasks.TaskManager;
import com.intellij.tasks.impl.TaskManagerImpl;
import com.intellij.ui.ScrollPaneFactory;
import com.intellij.ui.SimpleColoredComponent;
import com.intellij.ui.SimpleTextAttributes;
@@ -68,7 +69,7 @@ public class TasksToolWindowPanel extends JPanel implements Disposable {
}
});
myTimer = new Timer(1000, new ActionListener() {
myTimer = new Timer(TaskManagerImpl.TIME_TRACKING_TIME_UNIT, new ActionListener() {
@Override
public void actionPerformed(final ActionEvent e) {
table.repaint();
@@ -112,7 +113,6 @@ public class TasksToolWindowPanel extends JPanel implements Disposable {
final boolean isClosed = task.isClosed() || myTaskManager.isLocallyClosed(task);
component.append((String)value, getAttributes(isClosed, task.isActive(), isSelected));
component.setIcon(isClosed ? IconLoader.getTransparentIcon(task.getIcon()) : task.getIcon());
component.setIconOpaque(false);
component.setOpaque(false);
panel.add(component, BorderLayout.CENTER);
panel.setOpaque(true);
@@ -139,7 +139,6 @@ public class TasksToolWindowPanel extends JPanel implements Disposable {
public String valueOf(final LocalTask task) {
long timeSpent = task.getTimeSpent();
if (task.isActive()) {
timeSpent += System.currentTimeMillis() - task.getActivated();
return formatDuration(timeSpent);
}
return DateFormatUtil.formatDuration(timeSpent);