diff options
author | Steffen Pingel | 2011-07-22 21:47:28 +0000 |
---|---|---|
committer | Steffen Pingel | 2011-07-22 21:47:28 +0000 |
commit | 11303ccd712dfd8fb7fa3f639fa8a8381170e553 (patch) | |
tree | eec11fbb0e0d5b5e2a185bc1df331dd28c5aa4e9 /org.eclipse.mylyn.tasks.ui | |
parent | d02ba239c8c77469ff137cbf4d939a834ff39c97 (diff) | |
download | org.eclipse.mylyn.tasks-11303ccd712dfd8fb7fa3f639fa8a8381170e553.tar.gz org.eclipse.mylyn.tasks-11303ccd712dfd8fb7fa3f639fa8a8381170e553.tar.xz org.eclipse.mylyn.tasks-11303ccd712dfd8fb7fa3f639fa8a8381170e553.zip |
NEW - bug 336430: separate Context framework from Tasks
https://bugs.eclipse.org/bugs/show_bug.cgi?id=336430
Diffstat (limited to 'org.eclipse.mylyn.tasks.ui')
11 files changed, 91 insertions, 699 deletions
diff --git a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/ActiveContextExternalizationParticipant.java b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/ActiveContextExternalizationParticipant.java deleted file mode 100644 index 745932886..000000000 --- a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/ActiveContextExternalizationParticipant.java +++ /dev/null @@ -1,186 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2004, 2010 Tasktop Technologies and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Tasktop Technologies - initial API and implementation - *******************************************************************************/ - -package org.eclipse.mylyn.internal.tasks.ui; - -import java.io.File; - -import org.eclipse.core.runtime.Assert; -import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.core.runtime.jobs.ISchedulingRule; -import org.eclipse.mylyn.context.core.AbstractContextListener; -import org.eclipse.mylyn.context.core.ContextChangeEvent; -import org.eclipse.mylyn.context.core.ContextCore; -import org.eclipse.mylyn.context.core.IInteractionContext; -import org.eclipse.mylyn.internal.context.core.ContextCorePlugin; -import org.eclipse.mylyn.internal.monitor.ui.MonitorUiPlugin; -import org.eclipse.mylyn.internal.tasks.core.ITasksCoreConstants; -import org.eclipse.mylyn.internal.tasks.core.externalization.AbstractExternalizationParticipant; -import org.eclipse.mylyn.internal.tasks.core.externalization.ExternalizationManager; -import org.eclipse.mylyn.internal.tasks.core.externalization.IExternalizationContext; -import org.eclipse.mylyn.monitor.ui.IUserAttentionListener; -import org.eclipse.mylyn.tasks.core.ITask; -import org.eclipse.mylyn.tasks.core.ITaskActivityListener; -import org.eclipse.mylyn.tasks.ui.TasksUi; - -/** - * This externalization participant only handles saving the active context periodically. No snapshots are taken and task - * activation and deactivation control the load and final write of the context in InteractionContextManager. - * - * @author Shawn Minto - */ -@SuppressWarnings("restriction") -public class ActiveContextExternalizationParticipant extends AbstractExternalizationParticipant implements - ITaskActivityListener, IUserAttentionListener { - private boolean isDirty = false; - - private final ExternalizationManager manager; - - private long lastUpdate; - - private IInteractionContext currentlyActiveContext; - - private final AbstractContextListener listener = new AbstractContextListener() { - @Override - public void contextChanged(ContextChangeEvent event) { - switch (event.getEventKind()) { - case ACTIVATED: - currentlyActiveContext = event.getContext(); - break; - case DEACTIVATED: - currentlyActiveContext = null; - setDirty(false); - break; - } - } - }; - - public ActiveContextExternalizationParticipant(ExternalizationManager manager) { - this.manager = manager; - } - - public void registerListeners() { - ContextCore.getContextManager().addListener(listener); - TasksUi.getTaskActivityManager().addActivityListener(this); - (MonitorUiPlugin.getDefault().getActivityContextManager()).addListener(this); - currentlyActiveContext = ContextCore.getContextManager().getActiveContext(); - } - - // currently not called since no way to remove a participant - public void dispose() { - ContextCore.getContextManager().removeListener(listener); - TasksUi.getTaskActivityManager().removeActivityListener(this); - if (MonitorUiPlugin.getDefault().getActivityContextManager() != null) { - (MonitorUiPlugin.getDefault().getActivityContextManager()).removeListener(this); - } - } - - @Override - public void execute(IExternalizationContext context, IProgressMonitor monitor) throws CoreException { - Assert.isNotNull(context); - switch (context.getKind()) { - case SAVE: - if (shouldWriteContext()) { - setDirty(false); - ContextCorePlugin.getContextManager().saveContext(currentlyActiveContext); - } - break; - case LOAD: - // ignore loads since we will do this synchronously with task activation - break; - case SNAPSHOT: - // ignore snapshots - break; - } - } - - @Override - public String getDescription() { - return Messages.ActiveContextExternalizationParticipant_Active_Task_Context; - } - - @Override - public ISchedulingRule getSchedulingRule() { - return ITasksCoreConstants.ACTIVE_CONTEXT_SCHEDULING_RULE; - } - - @Override - public boolean isDirty() { - return isDirty(false); - } - - @Override - public boolean isDirty(boolean full) { - synchronized (this) { - return isDirty || (full && shouldWriteContext()); - } - } - - public void setDirty(boolean dirty) { - synchronized (this) { - isDirty = dirty; - } - } - - @Override - public String getFileName() { - // ignore - return null; - } - - @Override - public void load(File sourceFile, IProgressMonitor monitor) throws CoreException { - // ignore see execute method - } - - @Override - public void save(File targetFile, IProgressMonitor monitor) throws CoreException { - // ignore see execute method - } - - public void elapsedTimeUpdated(ITask task, long newElapsedTime) { - if (System.currentTimeMillis() - lastUpdate > 1000 * 60 * 3) { - // TODO TYR TO CHECK IF IT IS DIRTY AND IT EXISTS - setDirty(shouldWriteContext()); - if (isDirty()) { - manager.requestSave(); - } - lastUpdate = System.currentTimeMillis(); - } - } - - private boolean shouldWriteContext() { - if (ContextCorePlugin.getContextManager() != null && currentlyActiveContext != null - && currentlyActiveContext.getAllElements().size() > 0) { - // we could add a check here for whether there were changes to the context - return true; - } - return false; - } - - public void activityReset() { - // ignore - } - - public void userAttentionGained() { - // ignore - } - - public void userAttentionLost() { - setDirty(shouldWriteContext()); - if (isDirty()) { - manager.requestSave(); - } - lastUpdate = System.currentTimeMillis(); - } - -} diff --git a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/ActivityExternalizationParticipant.java b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/ActivityExternalizationParticipant.java deleted file mode 100644 index 19af29c93..000000000 --- a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/ActivityExternalizationParticipant.java +++ /dev/null @@ -1,133 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2004, 2010 Tasktop Technologies and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Tasktop Technologies - initial API and implementation - *******************************************************************************/ - -package org.eclipse.mylyn.internal.tasks.ui; - -import java.io.File; - -import org.eclipse.core.runtime.Assert; -import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.core.runtime.jobs.ISchedulingRule; -import org.eclipse.jface.util.IPropertyChangeListener; -import org.eclipse.mylyn.internal.context.core.ContextCorePlugin; -import org.eclipse.mylyn.internal.monitor.ui.MonitorUiPlugin; -import org.eclipse.mylyn.internal.tasks.core.ITasksCoreConstants; -import org.eclipse.mylyn.internal.tasks.core.externalization.AbstractExternalizationParticipant; -import org.eclipse.mylyn.internal.tasks.core.externalization.ExternalizationManager; -import org.eclipse.mylyn.internal.tasks.core.externalization.IExternalizationContext; -import org.eclipse.mylyn.tasks.core.ITask; -import org.eclipse.mylyn.tasks.core.ITaskActivityListener; - -/** - * @author Rob Elves - */ -@SuppressWarnings("restriction") -public class ActivityExternalizationParticipant extends AbstractExternalizationParticipant implements - ITaskActivityListener { - - private boolean isDirty = false; - - private final ExternalizationManager manager; - - private long lastUpdate; - - public ActivityExternalizationParticipant(ExternalizationManager manager) { - this.manager = manager; - MonitorUiPlugin.getDefault().getPreferenceStore().addPropertyChangeListener(new IPropertyChangeListener() { - public void propertyChange(org.eclipse.jface.util.PropertyChangeEvent event) { - if (event.getProperty().equals(MonitorUiPlugin.ACTIVITY_TRACKING_ENABLED)) { - requestSave(); - } - } - }); - } - - @Override - public void execute(IExternalizationContext context, IProgressMonitor monitor) throws CoreException { - Assert.isNotNull(context); - switch (context.getKind()) { - case SAVE: - if (ContextCorePlugin.getDefault() != null && MonitorUiPlugin.getDefault().isActivityTrackingEnabled() - && ContextCorePlugin.getContextManager() != null) { - setDirty(false); - ContextCorePlugin.getContextManager().saveActivityMetaContext(); - } - break; - case LOAD: - ContextCorePlugin.getContextManager().loadActivityMetaContext(); - break; - case SNAPSHOT: - break; - } - } - - @Override - public String getDescription() { - return Messages.ActivityExternalizationParticipant_Activity_Context; - } - - @Override - public ISchedulingRule getSchedulingRule() { - return ITasksCoreConstants.ACTIVITY_SCHEDULING_RULE; - } - - @Override - public boolean isDirty() { - return isDirty(false); - } - - @Override - public boolean isDirty(boolean full) { - synchronized (this) { - return isDirty || full; - } - } - - public void setDirty(boolean dirty) { - synchronized (this) { - isDirty = dirty; - } - } - - @Override - public String getFileName() { - // ignore - return null; - } - - @Override - public void load(File sourceFile, IProgressMonitor monitor) throws CoreException { - // ignore see execute method - } - - @Override - public void save(File targetFile, IProgressMonitor monitor) throws CoreException { - // ignore see execute method - } - - public void activityReset() { - // ignore see execute method - } - - public void elapsedTimeUpdated(ITask task, long newElapsedTime) { - if (System.currentTimeMillis() - lastUpdate > 1000 * 60) { - requestSave(); - } - } - - private void requestSave() { - setDirty(true); - manager.requestSave(); - lastUpdate = System.currentTimeMillis(); - } - -} diff --git a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/ChangeActivityHandleOperation.java b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/ChangeActivityHandleOperation.java deleted file mode 100644 index 35a8785b1..000000000 --- a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/ChangeActivityHandleOperation.java +++ /dev/null @@ -1,72 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2004, 2008 Tasktop Technologies and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Tasktop Technologies - initial API and implementation - *******************************************************************************/ - -package org.eclipse.mylyn.internal.tasks.ui; - -import java.lang.reflect.InvocationTargetException; - -import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.mylyn.internal.context.core.ContextCorePlugin; -import org.eclipse.mylyn.internal.context.core.InteractionContext; -import org.eclipse.mylyn.monitor.core.InteractionEvent; - -/** - * Changes handle from oldHandle to newHandle in Activity Meta Context - * - * @author Rob Elves - */ -public class ChangeActivityHandleOperation extends TaskListModifyOperation { - - private final String oldHandle; - - private final String newHandle; - - public ChangeActivityHandleOperation(String oldHandle, String newHandle) { - this.oldHandle = oldHandle; - this.newHandle = newHandle; - } - - @Override - protected void operations(IProgressMonitor monitor) throws CoreException, InvocationTargetException, - InterruptedException { - if (oldHandle == null || newHandle == null || oldHandle.equals(newHandle)) { - return; - } - try { - monitor.beginTask(Messages.ChangeActivityHandleOperation_Activity_migration, IProgressMonitor.UNKNOWN); - refactorMetaContextHandles(oldHandle, newHandle); - TasksUiPlugin.getTaskActivityMonitor().reloadActivityTime(); - } finally { - monitor.done(); - } - } - - @SuppressWarnings("restriction") - private void refactorMetaContextHandles(String oldHandle, String newHandle) { - ContextCorePlugin.getContextManager().saveActivityMetaContext(); - InteractionContext metaContext = ContextCorePlugin.getContextManager().getActivityMetaContext(); - ContextCorePlugin.getContextManager().resetActivityMetaContext(); - InteractionContext newMetaContext = ContextCorePlugin.getContextManager().getActivityMetaContext(); - for (InteractionEvent event : metaContext.getInteractionHistory()) { - if (event.getStructureHandle() != null) { - if (event.getStructureHandle().equals(oldHandle)) { - event = new InteractionEvent(event.getKind(), event.getStructureKind(), newHandle, - event.getOriginId(), event.getNavigation(), event.getDelta(), - event.getInterestContribution(), event.getDate(), event.getEndDate()); - } - } - newMetaContext.parseEvent(event); - } - ContextCorePlugin.getContextManager().saveActivityMetaContext(); - } - -} diff --git a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/RefactorRepositoryUrlOperation.java b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/RefactorRepositoryUrlOperation.java index 43c04e459..2ab9c8071 100644 --- a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/RefactorRepositoryUrlOperation.java +++ b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/RefactorRepositoryUrlOperation.java @@ -11,23 +11,13 @@ package org.eclipse.mylyn.internal.tasks.ui; -import java.io.File; import java.lang.reflect.InvocationTargetException; -import java.net.URLDecoder; import org.eclipse.core.runtime.Assert; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.core.runtime.IStatus; -import org.eclipse.core.runtime.Status; -import org.eclipse.mylyn.commons.core.StatusHandler; -import org.eclipse.mylyn.internal.context.core.ContextCorePlugin; -import org.eclipse.mylyn.internal.context.core.InteractionContext; -import org.eclipse.mylyn.internal.context.core.InteractionContextManager; import org.eclipse.mylyn.internal.tasks.core.ITasksCoreConstants; -import org.eclipse.mylyn.internal.tasks.core.RepositoryTaskHandleUtil; import org.eclipse.mylyn.internal.tasks.core.data.TaskDataManager; -import org.eclipse.mylyn.monitor.core.InteractionEvent; import org.eclipse.mylyn.tasks.core.ITask; /** @@ -56,48 +46,13 @@ public class RefactorRepositoryUrlOperation extends TaskListModifyOperation { monitor.beginTask(Messages.RefactorRepositoryUrlOperation_Repository_URL_update, IProgressMonitor.UNKNOWN); refactorOfflineHandles(oldUrl, newUrl); getTaskList().refactorRepositoryUrl(oldUrl, newUrl); - refactorMetaContextHandles(oldUrl, newUrl); - refactorContextFileNames(); + TasksUiPlugin.getContextStore().refactorRepositoryUrl(oldUrl, newUrl); TasksUiPlugin.getTaskActivityMonitor().reloadActivityTime(); } finally { monitor.done(); } } - @SuppressWarnings("restriction") - public void refactorContextFileNames() { - - File dataDir = new File(TasksUiPlugin.getDefault().getDataDirectory(), ITasksCoreConstants.CONTEXTS_DIRECTORY); - if (dataDir.exists() && dataDir.isDirectory()) { - File[] files = dataDir.listFiles(); - if (files != null) { - for (File file : dataDir.listFiles()) { - int dotIndex = file.getName().lastIndexOf(".xml"); //$NON-NLS-1$ - if (dotIndex != -1) { - String storedHandle; - try { - storedHandle = URLDecoder.decode(file.getName().substring(0, dotIndex), - InteractionContextManager.CONTEXT_FILENAME_ENCODING); - int delimIndex = storedHandle.lastIndexOf(RepositoryTaskHandleUtil.HANDLE_DELIM); - if (delimIndex != -1) { - String storedUrl = storedHandle.substring(0, delimIndex); - if (oldUrl.equals(storedUrl)) { - String id = RepositoryTaskHandleUtil.getTaskId(storedHandle); - String newHandle = RepositoryTaskHandleUtil.getHandle(newUrl, id); - File newFile = ContextCorePlugin.getContextStore().getFileForContext(newHandle); - file.renameTo(newFile); - } - } - } catch (Exception e) { - StatusHandler.log(new Status(IStatus.ERROR, TasksUiPlugin.ID_PLUGIN, - "Could not move context file: " + file.getName(), e)); //$NON-NLS-1$ - } - } - } - } - } - } - private void refactorOfflineHandles(String oldRepositoryUrl, String newRepositoryUrl) throws CoreException { TaskDataManager taskDataManager = TasksUiPlugin.getTaskDataManager(); for (ITask task : getTaskList().getAllTasks()) { @@ -130,28 +85,4 @@ public class RefactorRepositoryUrlOperation extends TaskListModifyOperation { // TasksUiPlugin.getTaskDataStorageManager().saveNow(); } - @SuppressWarnings("restriction") - private void refactorMetaContextHandles(String oldRepositoryUrl, String newRepositoryUrl) { - InteractionContext metaContext = ContextCorePlugin.getContextManager().getActivityMetaContext(); - ContextCorePlugin.getContextManager().resetActivityMetaContext(); - InteractionContext newMetaContext = ContextCorePlugin.getContextManager().getActivityMetaContext(); - for (InteractionEvent event : metaContext.getInteractionHistory()) { - if (event.getStructureHandle() != null) { - String storedUrl = RepositoryTaskHandleUtil.getRepositoryUrl(event.getStructureHandle()); - if (storedUrl != null) { - if (oldRepositoryUrl.equals(storedUrl)) { - String taskId = RepositoryTaskHandleUtil.getTaskId(event.getStructureHandle()); - if (taskId != null) { - String newHandle = RepositoryTaskHandleUtil.getHandle(newRepositoryUrl, taskId); - event = new InteractionEvent(event.getKind(), event.getStructureKind(), newHandle, - event.getOriginId(), event.getNavigation(), event.getDelta(), - event.getInterestContribution(), event.getDate(), event.getEndDate()); - } - } - } - } - newMetaContext.parseEvent(event); - } - } - } diff --git a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/TaskActivityMonitor.java b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/TaskActivityMonitor.java deleted file mode 100644 index 7bb25f84a..000000000 --- a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/TaskActivityMonitor.java +++ /dev/null @@ -1,154 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2004, 2009 Tasktop Technologies and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Tasktop Technologies - initial API and implementation - *******************************************************************************/ - -package org.eclipse.mylyn.internal.tasks.ui; - -import java.util.ArrayList; -import java.util.List; - -import org.eclipse.core.runtime.IStatus; -import org.eclipse.core.runtime.Status; -import org.eclipse.mylyn.commons.core.StatusHandler; -import org.eclipse.mylyn.context.core.AbstractContextListener; -import org.eclipse.mylyn.context.core.ContextChangeEvent; -import org.eclipse.mylyn.internal.context.core.InteractionContextManager; -import org.eclipse.mylyn.internal.tasks.core.AbstractTask; -import org.eclipse.mylyn.internal.tasks.core.ITasksCoreConstants; -import org.eclipse.mylyn.internal.tasks.core.TaskActivityManager; -import org.eclipse.mylyn.internal.tasks.core.TaskList; -import org.eclipse.mylyn.monitor.core.InteractionEvent; -import org.eclipse.mylyn.tasks.core.ITask; - -/** - * Monitors task activity and maintains task activation history - * - * @author Robert Elves - * @author Steffen Pingel - * @since 3.0 - */ -@SuppressWarnings("restriction") -public class TaskActivityMonitor { - - private final InteractionContextManager contextManager; - - private final TaskActivityManager taskActivityManager; - - private final TaskList taskList; - - private final List<ITask> activationHistory; - - private final AbstractContextListener CONTEXT_LISTENER = new AbstractContextListener() { - - @Override - public void contextChanged(ContextChangeEvent event) { - switch (event.getEventKind()) { - case INTEREST_CHANGED: - List<InteractionEvent> events = contextManager.getActivityMetaContext().getInteractionHistory(); - if (events.size() > 0) { - InteractionEvent interactionEvent = events.get(events.size() - 1); - parseInteractionEvent(interactionEvent, false); - } - break; - } - } - }; - - private ActivityExternalizationParticipant externalizationParticipant; - - public TaskActivityMonitor(TaskActivityManager taskActivityManager, InteractionContextManager contextManager) { - this.taskActivityManager = taskActivityManager; - this.contextManager = contextManager; - this.taskList = TasksUiPlugin.getTaskList(); - this.activationHistory = new ArrayList<ITask>(); - } - - public void start() { - contextManager.addActivityMetaContextListener(CONTEXT_LISTENER); - } - - /** public for testing */ - public boolean parseInteractionEvent(InteractionEvent event, boolean isReloading) { - try { - if (event.getKind().equals(InteractionEvent.Kind.COMMAND)) { - if ((event.getDelta().equals(InteractionContextManager.ACTIVITY_DELTA_ACTIVATED))) { - AbstractTask activatedTask = taskList.getTask(event.getStructureHandle()); - if (activatedTask != null) { - activationHistory.add(activatedTask); - return true; - } - } - } else if (event.getKind().equals(InteractionEvent.Kind.ATTENTION)) { - if ((event.getDelta().equals("added") || event.getDelta().equals("add"))) { //$NON-NLS-1$ //$NON-NLS-2$ - if (event.getDate().getTime() > 0 && event.getEndDate().getTime() > 0) { - if (event.getStructureKind() - .equals(InteractionContextManager.ACTIVITY_STRUCTUREKIND_WORKINGSET)) { - taskActivityManager.addWorkingSetElapsedTime(event.getStructureHandle(), event.getDate(), - event.getEndDate()); - if (!isReloading) { - externalizationParticipant.setDirty(true); - // save not requested for working set time updates so... - externalizationParticipant.elapsedTimeUpdated(null, 0); - } - } else { - AbstractTask activatedTask = taskList.getTask(event.getStructureHandle()); - if (activatedTask != null) { - taskActivityManager.addElapsedTime(activatedTask, event.getDate(), event.getEndDate()); - } - } - } - } else if (event.getDelta().equals("removed")) { //$NON-NLS-1$ - ITask task = taskList.getTask(event.getStructureHandle()); - if (task != null) { - taskActivityManager.removeElapsedTime(task, event.getDate(), event.getEndDate()); - } - } - } - } catch (Throwable t) { - StatusHandler.log(new Status(IStatus.ERROR, ITasksCoreConstants.ID_PLUGIN, - "Error parsing interaction event", t)); //$NON-NLS-1$ - } - return false; - } - - public void stop() { - contextManager.removeActivityMetaContextListener(CONTEXT_LISTENER); - } - - public void reloadActivityTime() { - activationHistory.clear(); - taskActivityManager.clearActivity(); - List<InteractionEvent> events = contextManager.getActivityMetaContext().getInteractionHistory(); - for (InteractionEvent event : events) { - parseInteractionEvent(event, true); - } - } - - /** - * Returns the task corresponding to the interaction event history item at the specified position - */ -// protected ITask getHistoryTaskAt(int pos) { -// InteractionEvent event = contextManager.getActivityMetaContext().getInteractionHistory().get(pos); -// if (event.getDelta().equals(InteractionContextManager.ACTIVITY_DELTA_ACTIVATED)) { -// return TasksUiPlugin.getTaskList().getTask(event.getStructureHandle()); -// } else { -// return null; -// } -// } - - public void setExternalizationParticipant(ActivityExternalizationParticipant participant) { - this.externalizationParticipant = participant; - } - - public List<ITask> getActivationHistory() { - return new ArrayList<ITask>(activationHistory); - } - -} diff --git a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/TaskHistoryHandler.java b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/TaskHistoryHandler.java index 27a81dc5c..dd184d8dc 100644 --- a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/TaskHistoryHandler.java +++ b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/TaskHistoryHandler.java @@ -15,12 +15,8 @@ package org.eclipse.mylyn.internal.tasks.ui; import java.util.Map; import org.eclipse.core.commands.AbstractHandler; -import org.eclipse.core.commands.Command; import org.eclipse.core.commands.ExecutionEvent; import org.eclipse.core.commands.ExecutionException; -import org.eclipse.core.runtime.SafeRunner; -import org.eclipse.jface.util.SafeRunnable; -import org.eclipse.mylyn.context.core.ContextCore; import org.eclipse.mylyn.internal.tasks.core.AbstractTask; import org.eclipse.mylyn.internal.tasks.core.TaskActivationHistory; import org.eclipse.mylyn.internal.tasks.ui.actions.ActivateTaskDialogAction; @@ -28,7 +24,6 @@ import org.eclipse.mylyn.internal.tasks.ui.util.TasksUiInternal; import org.eclipse.mylyn.tasks.ui.TasksUi; import org.eclipse.mylyn.tasks.ui.TasksUiImages; import org.eclipse.ui.IWorkbenchWindow; -import org.eclipse.ui.commands.ICommandService; import org.eclipse.ui.commands.IElementUpdater; import org.eclipse.ui.handlers.HandlerUtil; import org.eclipse.ui.menus.UIElement; @@ -41,24 +36,7 @@ public class TaskHistoryHandler extends AbstractHandler implements IElementUpdat public Object execute(final ExecutionEvent event) throws ExecutionException { if (TasksUi.getTaskActivityManager().getActiveTask() != null) { - if (ContextCore.getContextManager().isContextCapturePaused()) { - IWorkbenchWindow window = HandlerUtil.getActiveWorkbenchWindow(event); - if (window != null) { - ICommandService commandService = (ICommandService) window.getService(ICommandService.class); - if (commandService != null) { - final Command command = commandService.getCommand("org.eclipse.mylyn.ui.context.capture.pause.command"); //$NON-NLS-1$ - if (command != null) { - SafeRunner.run(new SafeRunnable() { - public void run() throws Exception { - command.executeWithChecks(event); - } - }); - } - } - } - } else { - TasksUi.getTaskActivityManager().deactivateActiveTask(); - } + TasksUi.getTaskActivityManager().deactivateActiveTask(); } else { TaskActivationHistory taskHistory = TasksUiPlugin.getTaskActivityManager().getTaskActivationHistory(); if (taskHistory.hasPrevious()) { @@ -83,11 +61,7 @@ public class TaskHistoryHandler extends AbstractHandler implements IElementUpdat if (TasksUi.getTaskActivityManager().getActiveTask() == null) { element.setIcon(TasksUiImages.CONTEXT_HISTORY_PREVIOUS); } else { - if (ContextCore.getContextManager().isContextCapturePaused()) { - element.setIcon(TasksUiImages.CONTEXT_HISTORY_PREVIOUS_PAUSE); - } else { - element.setIcon(TasksUiImages.CONTEXT_HISTORY_PREVIOUS_ACTIVE); - } + element.setIcon(TasksUiImages.CONTEXT_HISTORY_PREVIOUS_ACTIVE); } } diff --git a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/TasksUiPlugin.java b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/TasksUiPlugin.java index 75d8ade74..7c234ea2e 100644 --- a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/TasksUiPlugin.java +++ b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/TasksUiPlugin.java @@ -95,11 +95,10 @@ import org.eclipse.mylyn.tasks.core.AbstractRepositoryConnector; import org.eclipse.mylyn.tasks.core.IRepositoryQuery; import org.eclipse.mylyn.tasks.core.ITask; import org.eclipse.mylyn.tasks.core.ITask.PriorityLevel; -import org.eclipse.mylyn.tasks.core.ITaskActivationListener; import org.eclipse.mylyn.tasks.core.ITaskContainer; import org.eclipse.mylyn.tasks.core.RepositoryTemplate; -import org.eclipse.mylyn.tasks.core.TaskActivationAdapter; import org.eclipse.mylyn.tasks.core.TaskRepository; +import org.eclipse.mylyn.tasks.core.activity.AbstractTaskActivityMonitor; import org.eclipse.mylyn.tasks.core.context.AbstractTaskContextStore; import org.eclipse.mylyn.tasks.ui.AbstractRepositoryConnectorUi; import org.eclipse.mylyn.tasks.ui.AbstractTaskRepositoryLinkProvider; @@ -256,20 +255,6 @@ public class TasksUiPlugin extends AbstractUIPlugin { EDITOR, INTERNAL_BROWSER, EXTERNAL_BROWSER; } - private static ITaskActivationListener CONTEXT_TASK_ACTIVATION_LISTENER = new TaskActivationAdapter() { - - @Override - public void taskActivated(final ITask task) { - ContextCore.getContextManager().activateContext(task.getHandleIdentifier()); - } - - @Override - public void taskDeactivated(final ITask task) { - ContextCore.getContextManager().deactivateContext(task.getHandleIdentifier()); - } - - }; - private static ITaskListNotificationProvider REMINDER_NOTIFICATION_PROVIDER = new ITaskListNotificationProvider() { public Set<AbstractNotification> getNotifications() { @@ -370,7 +355,7 @@ public class TasksUiPlugin extends AbstractUIPlugin { } }; - private TaskActivityMonitor taskActivityMonitor; + private AbstractTaskActivityMonitor taskActivityMonitor; private ServiceReference proxyServiceReference; @@ -378,8 +363,6 @@ public class TasksUiPlugin extends AbstractUIPlugin { private static TaskListExternalizationParticipant taskListExternalizationParticipant; - private ActiveContextExternalizationParticipant activeContextExternalizationParticipant; - private final Set<IRepositoryModelListener> listeners = new HashSet<IRepositoryModelListener>(); private File activationHistoryFile; @@ -476,10 +459,6 @@ public class TasksUiPlugin extends AbstractUIPlugin { } finally { monitor.done(); } - activeContextExternalizationParticipant = new ActiveContextExternalizationParticipant( - externalizationManager); - externalizationManager.addParticipant(activeContextExternalizationParticipant); - activeContextExternalizationParticipant.registerListeners(); return new Status(IStatus.OK, TasksUiPlugin.ID_PLUGIN, IStatus.OK, "", null); //$NON-NLS-1$ } } @@ -617,10 +596,8 @@ public class TasksUiPlugin extends AbstractUIPlugin { taskJobFactory = new TaskJobFactory(taskList, taskDataManager, repositoryManager, repositoryModel); - taskActivityManager.addActivationListener(CONTEXT_TASK_ACTIVATION_LISTENER); - - taskActivityMonitor = new TaskActivityMonitor(taskActivityManager, ContextCorePlugin.getContextManager()); - taskActivityMonitor.start(); + taskActivityMonitor = TasksUiExtensionReader.loadTaskActivityMonitor(); + taskActivityMonitor.start(taskActivityManager); saveParticipant = new ISaveParticipant() { @@ -641,12 +618,6 @@ public class TasksUiPlugin extends AbstractUIPlugin { }; ResourcesPlugin.getWorkspace().addSaveParticipant(this, saveParticipant); - ActivityExternalizationParticipant ACTIVITY_EXTERNALIZTAION_PARTICIPANT = new ActivityExternalizationParticipant( - externalizationManager); - externalizationManager.addParticipant(ACTIVITY_EXTERNALIZTAION_PARTICIPANT); - taskActivityManager.addActivityListener(ACTIVITY_EXTERNALIZTAION_PARTICIPANT); - taskActivityMonitor.setExternalizationParticipant(ACTIVITY_EXTERNALIZTAION_PARTICIPANT); - // initialize externalization for task activation history IPath stateLocation = Platform.getStateLocation(getBundle()); activationHistoryFile = stateLocation.append("TaskActivationHistory.xml").toFile(); //$NON-NLS-1$ @@ -894,15 +865,14 @@ public class TasksUiPlugin extends AbstractUIPlugin { public void initializeDataSources() { taskDataManager.setDataPath(getDataDirectory()); externalizationManager.setRootFolderPath(getDataDirectory()); - ContextCorePlugin.getContextStore().setContextDirectory(getContextStoreDir()); + getContextStore().setContextDirectory(getContextStoreDir()); externalizationManager.load(); // TODO: Move management of template repositories to TaskRepositoryManager loadTemplateRepositories(); taskActivityManager.clear(); - ContextCorePlugin.getContextManager().loadActivityMetaContext(); - taskActivityMonitor.reloadActivityTime(); + taskActivityMonitor.loadActivityTime(); taskActivityManager.reloadPlanningData(); if (!activationHistoryFile.exists() && taskActivityManager.getTaskActivationHistory().getSize() == 0) { @@ -1303,7 +1273,7 @@ public class TasksUiPlugin extends AbstractUIPlugin { return externalizationManager; } - public static TaskActivityMonitor getTaskActivityMonitor() { + public static AbstractTaskActivityMonitor getTaskActivityMonitor() { return INSTANCE.taskActivityMonitor; } @@ -1420,7 +1390,10 @@ public class TasksUiPlugin extends AbstractUIPlugin { return identityModel; } - public static AbstractTaskContextStore getContextStore() { + public static synchronized AbstractTaskContextStore getContextStore() { + if (contextStore == null) { + contextStore = TasksUiExtensionReader.loadTaskContextStore(); + } return contextStore; } diff --git a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/editors/TaskMigrator.java b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/editors/TaskMigrator.java index 85bd4b65e..79b9f50ea 100644 --- a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/editors/TaskMigrator.java +++ b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/editors/TaskMigrator.java @@ -11,19 +11,16 @@ package org.eclipse.mylyn.internal.tasks.ui.editors; -import java.lang.reflect.InvocationTargetException; import java.util.Date; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.ISafeRunnable; import org.eclipse.core.runtime.IStatus; -import org.eclipse.core.runtime.NullProgressMonitor; import org.eclipse.core.runtime.SafeRunner; import org.eclipse.core.runtime.Status; import org.eclipse.mylyn.commons.core.StatusHandler; import org.eclipse.mylyn.internal.tasks.core.AbstractTask; import org.eclipse.mylyn.internal.tasks.core.DateRange; -import org.eclipse.mylyn.internal.tasks.ui.ChangeActivityHandleOperation; import org.eclipse.mylyn.internal.tasks.ui.TasksUiPlugin; import org.eclipse.mylyn.internal.tasks.ui.util.TasksUiInternal; import org.eclipse.mylyn.tasks.core.AbstractRepositoryConnector; @@ -192,18 +189,6 @@ public class TaskMigrator { // migrate context TasksUiPlugin.getContextStore().cloneContext(oldTask, newTask); - - // migrate task activity - ChangeActivityHandleOperation operation = new ChangeActivityHandleOperation(oldTask.getHandleIdentifier(), - newTask.getHandleIdentifier()); - try { - operation.run(new NullProgressMonitor()); - } catch (InvocationTargetException e) { - StatusHandler.log(new Status(IStatus.WARNING, TasksUiPlugin.ID_PLUGIN, - "Failed to migrate activity to new task", e.getCause())); //$NON-NLS-1$ - } catch (InterruptedException e) { - // ignore - } } public static boolean isActive() { diff --git a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/util/AttachmentUtil.java b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/util/AttachmentUtil.java index faf88c226..10065c046 100644 --- a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/util/AttachmentUtil.java +++ b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/util/AttachmentUtil.java @@ -86,7 +86,7 @@ public class AttachmentUtil { AbstractTaskAttachmentHandler attachmentHandler = connector.getTaskAttachmentHandler(); TasksUiPlugin.getContextStore().saveActiveContext(); - File file = TasksUiPlugin.getContextStore().getFileForContext(repository, task); + File file = TasksUiPlugin.getContextStore().getFileForContext(task); if (attachmentHandler != null && file != null && file.exists()) { FileTaskAttachmentSource attachment = new FileTaskAttachmentSource(file); attachment.setDescription(CONTEXT_DESCRIPTION); @@ -138,7 +138,7 @@ public class AttachmentUtil { public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { TaskRepository repository = TasksUi.getRepositoryManager().getRepository(task.getConnectorKind(), task.getRepositoryUrl()); - File targetFile = TasksUiPlugin.getContextStore().getFileForContext(repository, task); + File targetFile = TasksUiPlugin.getContextStore().getFileForContext(task); try { boolean exceptionThrown = true; OutputStream out = new BufferedOutputStream(new FileOutputStream(targetFile)); @@ -183,7 +183,7 @@ public class AttachmentUtil { public static boolean uploadContext(final TaskRepository repository, final ITask task, final String comment, final IRunnableContext context) { TasksUiPlugin.getContextStore().saveActiveContext(); - File sourceContextFile = TasksUiPlugin.getContextStore().getFileForContext(repository, task); + File sourceContextFile = TasksUiPlugin.getContextStore().getFileForContext(task); if (!sourceContextFile.exists()) { TasksUiInternal.displayStatus(Messages.AttachmentUtil_Mylyn_Information, new Status(IStatus.WARNING, TasksUiPlugin.ID_PLUGIN, Messages.AttachmentUtil_The_context_is_empty)); diff --git a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/util/TasksUiExtensionReader.java b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/util/TasksUiExtensionReader.java index 8f2a6744a..15b536962 100644 --- a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/util/TasksUiExtensionReader.java +++ b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/util/TasksUiExtensionReader.java @@ -30,7 +30,10 @@ import org.eclipse.core.runtime.Status; import org.eclipse.jface.resource.ImageDescriptor; import org.eclipse.mylyn.commons.core.StatusHandler; import org.eclipse.mylyn.internal.provisional.commons.ui.CommonImages; +import org.eclipse.mylyn.internal.tasks.core.ITasksCoreConstants; import org.eclipse.mylyn.internal.tasks.core.TaskRepositoryManager; +import org.eclipse.mylyn.internal.tasks.core.activity.DefaultTaskActivityMonitor; +import org.eclipse.mylyn.internal.tasks.core.context.DefaultTaskContextStore; import org.eclipse.mylyn.internal.tasks.core.externalization.TaskListExternalizer; import org.eclipse.mylyn.internal.tasks.ui.IDynamicSubMenuContributor; import org.eclipse.mylyn.internal.tasks.ui.TasksUiPlugin; @@ -41,6 +44,8 @@ import org.eclipse.mylyn.tasks.core.AbstractRepositoryConnector; import org.eclipse.mylyn.tasks.core.AbstractRepositoryMigrator; import org.eclipse.mylyn.tasks.core.AbstractTaskListMigrator; import org.eclipse.mylyn.tasks.core.RepositoryTemplate; +import org.eclipse.mylyn.tasks.core.activity.AbstractTaskActivityMonitor; +import org.eclipse.mylyn.tasks.core.context.AbstractTaskContextStore; import org.eclipse.mylyn.tasks.ui.AbstractRepositoryConnectorUi; import org.eclipse.mylyn.tasks.ui.AbstractTaskRepositoryLinkProvider; import org.eclipse.mylyn.tasks.ui.TasksUi; @@ -632,4 +637,72 @@ public class TasksUiExtensionReader { } } + public static AbstractTaskActivityMonitor loadTaskActivityMonitor() { + IExtensionRegistry registry = Platform.getExtensionRegistry(); + IExtensionPoint connectorsExtensionPoint = registry.getExtensionPoint(ITasksCoreConstants.ID_PLUGIN + + ".activityMonitor"); //$NON-NLS-1$ + IExtension[] extensions = connectorsExtensionPoint.getExtensions(); + for (IExtension extension : extensions) { + IConfigurationElement[] elements = extension.getConfigurationElements(); + for (IConfigurationElement element : elements) { + if ("activityMonitor".equals(element.getName())) { //$NON-NLS-1$ + try { + Object object = element.createExecutableExtension("class"); //$NON-NLS-1$ + if (object instanceof AbstractTaskActivityMonitor) { + return (AbstractTaskActivityMonitor) object; + } else { + StatusHandler.log(new Status( + IStatus.ERROR, + ITasksCoreConstants.ID_PLUGIN, + NLS.bind( + "Task activity monitor ''{0}'' does not extend expected class for extension contributed by {1}", //$NON-NLS-1$ + object.getClass().getCanonicalName(), element.getContributor().getName()))); + } + } catch (Throwable e) { + StatusHandler.log(new Status( + IStatus.ERROR, + ITasksCoreConstants.ID_PLUGIN, + NLS.bind( + "Task activity monitor failed to load for extension contributed by {0}", element.getContributor().getName()), e)); //$NON-NLS-1$ + } + } + } + } + return new DefaultTaskActivityMonitor(); + } + + public static AbstractTaskContextStore loadTaskContextStore() { + IExtensionRegistry registry = Platform.getExtensionRegistry(); + IExtensionPoint connectorsExtensionPoint = registry.getExtensionPoint(ITasksCoreConstants.ID_PLUGIN + + ".contextStore"); //$NON-NLS-1$ + IExtension[] extensions = connectorsExtensionPoint.getExtensions(); + for (IExtension extension : extensions) { + IConfigurationElement[] elements = extension.getConfigurationElements(); + for (IConfigurationElement element : elements) { + if ("contextStore".equals(element.getName())) { //$NON-NLS-1$ + try { + Object object = element.createExecutableExtension("class"); //$NON-NLS-1$ + if (object instanceof AbstractTaskContextStore) { + return (AbstractTaskContextStore) object; + } else { + StatusHandler.log(new Status( + IStatus.ERROR, + ITasksCoreConstants.ID_PLUGIN, + NLS.bind( + "Task context store ''{0}'' does not extend expected class for extension contributed by {1}", //$NON-NLS-1$ + object.getClass().getCanonicalName(), element.getContributor().getName()))); + } + } catch (Throwable e) { + StatusHandler.log(new Status( + IStatus.ERROR, + ITasksCoreConstants.ID_PLUGIN, + NLS.bind( + "Task context store failed to load for extension contributed by {0}", element.getContributor().getName()), e)); //$NON-NLS-1$ + } + } + } + } + return new DefaultTaskContextStore(); + } + } diff --git a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/tasks/ui/TasksUiImages.java b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/tasks/ui/TasksUiImages.java index 558ca16b9..b2491ece8 100644 --- a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/tasks/ui/TasksUiImages.java +++ b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/tasks/ui/TasksUiImages.java @@ -142,6 +142,7 @@ public class TasksUiImages { public static final ImageDescriptor CONTEXT_HISTORY_PREVIOUS = create(TOOL, "navigate-previous.gif"); //$NON-NLS-1$ + @Deprecated public static final ImageDescriptor CONTEXT_HISTORY_PREVIOUS_PAUSE = create(TOOL, "navigate-previous-pause.gif"); //$NON-NLS-1$ public static final ImageDescriptor CONTEXT_HISTORY_PREVIOUS_ACTIVE = create(TOOL, "navigate-previous-active.gif"); //$NON-NLS-1$ |