Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
View | Details | Raw Unified | Return to bug 219173 | Differences between
and this patch

Collapse All | Expand All

(-)src/org/eclipse/mylyn/internal/tasks/core/ITasksCoreConstants.java (+2 lines)
Lines 49-54 Link Here
49
49
50
	public static final ISchedulingRule ACTIVITY_SCHEDULING_RULE = new MutexSchedulingRule();
50
	public static final ISchedulingRule ACTIVITY_SCHEDULING_RULE = new MutexSchedulingRule();
51
51
52
	public static final ISchedulingRule ACTIVE_CONTEXT_SCHEDULING_RULE = new MutexSchedulingRule();
53
52
	public static final ISchedulingRule TASKLIST_SCHEDULING_RULE = new MutexSchedulingRule();
54
	public static final ISchedulingRule TASKLIST_SCHEDULING_RULE = new MutexSchedulingRule();
53
55
54
	public static final ISchedulingRule ROOT_SCHEDULING_RULE = new RootSchedulingRule();
56
	public static final ISchedulingRule ROOT_SCHEDULING_RULE = new RootSchedulingRule();
(-)src/org/eclipse/mylyn/internal/context/core/LocalContextStore.java (-3 / +6 lines)
Lines 128-138 Link Here
128
				// FIXME this should not reference the context manager
128
				// FIXME this should not reference the context manager
129
				ContextCore.getContextManager().setContextCapturePaused(true);
129
				ContextCore.getContextManager().setContextCapturePaused(true);
130
			}
130
			}
131
			synchronized (context) {
132
				IInteractionContext contextToSave = context;
133
				if (context instanceof InteractionContext) {
134
					contextToSave = ((InteractionContext) context).createCollapsedWritableCopy();
135
				}
131
136
132
			if (context instanceof InteractionContext) {
137
				externalizer.writeContextToXml(contextToSave, getFileForContext(contextToSave.getHandleIdentifier()));
133
				((InteractionContext) context).collapse();
134
			}
138
			}
135
			externalizer.writeContextToXml(context, getFileForContext(context.getHandleIdentifier()));
136
139
137
			if (context.getAllElements().size() == 0) {
140
			if (context.getAllElements().size() == 0) {
138
				removeFromCache(context);
141
				removeFromCache(context);
(-)src/org/eclipse/mylyn/internal/context/core/InteractionContext.java (-2 / +28 lines)
Lines 249-254 Link Here
249
	}
249
	}
250
250
251
	public synchronized void collapse() {
251
	public synchronized void collapse() {
252
		collapseHistory(interactionHistory);
253
	}
254
255
	private synchronized void collapseHistory(List<InteractionEvent> interactionHistoryToCollapseTo) {
252
		List<InteractionEvent> collapsedHistory = new ArrayList<InteractionEvent>();
256
		List<InteractionEvent> collapsedHistory = new ArrayList<InteractionEvent>();
253
		for (InteractionContextElement node : elementMap.values()) {
257
		for (InteractionContextElement node : elementMap.values()) {
254
			if (!node.equals(activeNode)) {
258
			if (!node.equals(activeNode)) {
Lines 259-266 Link Here
259
			collapseNode(collapsedHistory, activeNode);
263
			collapseNode(collapsedHistory, activeNode);
260
		}
264
		}
261
265
262
		interactionHistory.clear();
266
		interactionHistoryToCollapseTo.clear();
263
		interactionHistory.addAll(collapsedHistory);
267
		interactionHistoryToCollapseTo.addAll(collapsedHistory);
268
	}
269
270
	/**
271
	 * This method is only used for asynchronous saving of task contexts
272
	 * 
273
	 * @return a context with a copy of the collapsed interaction history. All other fields are not set.
274
	 */
275
	synchronized IInteractionContext createCollapsedWritableCopy() {
276
		InteractionContext copiedContext = new InteractionContext(handleIdentifier, contextScaling);
277
		copiedContext.contentLimitedTo = contentLimitedTo;
278
279
		collapseHistory(copiedContext.interactionHistory);
280
		
281
		// none of the following are used for writing contexts so we aren't going to try to copy them
282
		//copiedContext.numUserEvents = numUserEvents;
283
		// copiedContext.lastEdgeNode = lastEdgeNode;
284
		// copiedContext.lastEdgeEvent = lastEdgeEvent;
285
		// copiedContext.landmarkMap = landmarkMap;
286
		// copiedContext.elementMap = elementMap;
287
		// copiedContext.activeNode = activeNode;
288
289
		return copiedContext;
264
	}
290
	}
265
291
266
	private void collapseNode(List<InteractionEvent> collapsedHistory, InteractionContextElement node) {
292
	private void collapseNode(List<InteractionEvent> collapsedHistory, InteractionContextElement node) {
(-)src/org/eclipse/mylyn/internal/context/core/InteractionContextManager.java (-1 / +7 lines)
Lines 414-426 Link Here
414
		}
414
		}
415
	}
415
	}
416
416
417
	public void saveContext(IInteractionContext context) {
418
		if (context != null && contextStore != null) {
419
			contextStore.saveContext(context);
420
		}
421
	}
422
417
	public void deactivateContext(String handleIdentifier) {
423
	public void deactivateContext(String handleIdentifier) {
418
		try {
424
		try {
419
			System.setProperty(InteractionContextManager.PROPERTY_CONTEXT_ACTIVE, Boolean.FALSE.toString());
425
			System.setProperty(InteractionContextManager.PROPERTY_CONTEXT_ACTIVE, Boolean.FALSE.toString());
420
426
421
			final IInteractionContext context = activeContext.getContextMap().get(handleIdentifier);
427
			final IInteractionContext context = activeContext.getContextMap().get(handleIdentifier);
422
			if (context != null) {
428
			if (context != null) {
423
				contextStore.saveContext(context);
429
				saveContext(context);
424
				activeContext.getContextMap().remove(handleIdentifier);
430
				activeContext.getContextMap().remove(handleIdentifier);
425
431
426
				setContextCapturePaused(true);
432
				setContextCapturePaused(true);
(-)src/org/eclipse/mylyn/internal/tasks/ui/messages.properties (+1 lines)
Lines 8-13 Link Here
8
# Contributors:
8
# Contributors:
9
#      Tasktop Technologies - initial API and implementation
9
#      Tasktop Technologies - initial API and implementation
10
###############################################################################
10
###############################################################################
11
ActiveContextExternalizationParticipant_Active_Task_Context=Active Task Context
11
ActivityExternalizationParticipant_Activity_Context=Activity Context
12
ActivityExternalizationParticipant_Activity_Context=Activity Context
12
13
13
ChangeActivityHandleOperation_Activity_migration=Activity migration
14
ChangeActivityHandleOperation_Activity_migration=Activity migration
(-)src/org/eclipse/mylyn/internal/tasks/ui/Messages.java (+2 lines)
Lines 25-30 Link Here
25
		NLS.initializeMessages(BUNDLE_NAME, Messages.class);
25
		NLS.initializeMessages(BUNDLE_NAME, Messages.class);
26
	}
26
	}
27
27
28
	public static String ActiveContextExternalizationParticipant_Active_Task_Context;
29
28
	public static String ActivityExternalizationParticipant_Activity_Context;
30
	public static String ActivityExternalizationParticipant_Activity_Context;
29
31
30
	public static String ChangeActivityHandleOperation_Activity_migration;
32
	public static String ChangeActivityHandleOperation_Activity_migration;
(-)src/org/eclipse/mylyn/internal/tasks/ui/TasksUiPlugin.java (+6 lines)
Lines 350-355 Link Here
350
350
351
	private static TaskListExternalizationParticipant taskListExternalizationParticipant;
351
	private static TaskListExternalizationParticipant taskListExternalizationParticipant;
352
352
353
	private ActiveContextExternalizationParticipant activeContextExternalizationParticipant;
354
353
	private final Set<IRepositoryModelListener> listeners = new HashSet<IRepositoryModelListener>();
355
	private final Set<IRepositoryModelListener> listeners = new HashSet<IRepositoryModelListener>();
354
356
355
	private static TaskList taskList;
357
	private static TaskList taskList;
Lines 435-440 Link Here
435
			} finally {
437
			} finally {
436
				monitor.done();
438
				monitor.done();
437
			}
439
			}
440
			activeContextExternalizationParticipant = new ActiveContextExternalizationParticipant(
441
					externalizationManager);
442
			externalizationManager.addParticipant(activeContextExternalizationParticipant);
443
			activeContextExternalizationParticipant.registerListeners();
438
			return new Status(IStatus.OK, TasksUiPlugin.ID_PLUGIN, IStatus.OK, "", null); //$NON-NLS-1$
444
			return new Status(IStatus.OK, TasksUiPlugin.ID_PLUGIN, IStatus.OK, "", null); //$NON-NLS-1$
439
		}
445
		}
440
446
(-)src/org/eclipse/mylyn/internal/tasks/ui/ActiveContextExternalizationParticipant.java (+189 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2004, 2009 Tasktop Technologies and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     Tasktop Technologies - initial API and implementation
10
 *******************************************************************************/
11
12
package org.eclipse.mylyn.internal.tasks.ui;
13
14
import java.io.File;
15
16
import org.eclipse.core.runtime.Assert;
17
import org.eclipse.core.runtime.CoreException;
18
import org.eclipse.core.runtime.IProgressMonitor;
19
import org.eclipse.core.runtime.IStatus;
20
import org.eclipse.core.runtime.Status;
21
import org.eclipse.core.runtime.jobs.ISchedulingRule;
22
import org.eclipse.mylyn.commons.core.StatusHandler;
23
import org.eclipse.mylyn.context.core.AbstractContextListener;
24
import org.eclipse.mylyn.context.core.ContextChangeEvent;
25
import org.eclipse.mylyn.context.core.ContextCore;
26
import org.eclipse.mylyn.context.core.IInteractionContext;
27
import org.eclipse.mylyn.internal.context.core.ContextCorePlugin;
28
import org.eclipse.mylyn.internal.monitor.ui.ActivityContextManager;
29
import org.eclipse.mylyn.internal.monitor.ui.MonitorUiPlugin;
30
import org.eclipse.mylyn.internal.tasks.core.ITasksCoreConstants;
31
import org.eclipse.mylyn.internal.tasks.core.externalization.AbstractExternalizationParticipant;
32
import org.eclipse.mylyn.internal.tasks.core.externalization.ExternalizationManager;
33
import org.eclipse.mylyn.internal.tasks.core.externalization.IExternalizationContext;
34
import org.eclipse.mylyn.monitor.ui.IUserAttentionListener;
35
import org.eclipse.mylyn.tasks.core.ITask;
36
import org.eclipse.mylyn.tasks.core.ITaskActivityListener;
37
import org.eclipse.mylyn.tasks.ui.TasksUi;
38
39
/**
40
 * This externalization participant only handles saving the active context periodically. No snapshots are taken and task
41
 * activation and deactivation control the load and final write of the context in InteractionContextManager.
42
 * 
43
 * @author Shawn Minto
44
 */
45
@SuppressWarnings("restriction")
46
public class ActiveContextExternalizationParticipant extends AbstractExternalizationParticipant implements
47
		ITaskActivityListener, IUserAttentionListener {
48
	private boolean isDirty = false;
49
50
	private final ExternalizationManager manager;
51
52
	private long lastUpdate;
53
54
	private IInteractionContext currentlyActiveContext;
55
56
	private final AbstractContextListener listener = new AbstractContextListener() {
57
		@Override
58
		public void contextChanged(ContextChangeEvent event) {
59
			switch (event.getEventKind()) {
60
			case ACTIVATED:
61
				currentlyActiveContext = event.getContext();
62
				break;
63
			case DEACTIVATED:
64
				currentlyActiveContext = null;
65
				setDirty(false);
66
				break;
67
			}
68
		}
69
	};
70
71
	public ActiveContextExternalizationParticipant(ExternalizationManager manager) {
72
		this.manager = manager;
73
	}
74
75
	public void registerListeners() {
76
		ContextCore.getContextManager().addListener(listener);
77
		TasksUi.getTaskActivityManager().addActivityListener(this);
78
		if (MonitorUiPlugin.getDefault().getActivityContextManager() != null) {
79
			((ActivityContextManager) MonitorUiPlugin.getDefault().getActivityContextManager()).addListener(this);
80
		} else {
81
			StatusHandler.log(new Status(IStatus.WARNING, TasksUiPlugin.ID_PLUGIN,
82
					"Unable to register user activity listener.", new Exception())); //$NON-NLS-1$
83
		}
84
	}
85
86
	// currently not called since no way to remove a participant
87
	public void dispose() {
88
		ContextCore.getContextManager().removeListener(listener);
89
		TasksUi.getTaskActivityManager().removeActivityListener(this);
90
		if (MonitorUiPlugin.getDefault().getActivityContextManager() != null) {
91
			((ActivityContextManager) MonitorUiPlugin.getDefault().getActivityContextManager()).removeListener(this);
92
		}
93
	}
94
95
	@Override
96
	public void execute(IExternalizationContext context, IProgressMonitor monitor) throws CoreException {
97
		Assert.isNotNull(context);
98
		switch (context.getKind()) {
99
		case SAVE:
100
			if (shouldWriteContext()) {
101
				setDirty(false);
102
				ContextCorePlugin.getContextManager().saveContext(currentlyActiveContext);
103
			}
104
			break;
105
		case LOAD:
106
			// ignore loads since we will do this synchronously with task activation
107
			break;
108
		case SNAPSHOT:
109
			// ignore snapshots
110
			break;
111
		}
112
	}
113
114
	@Override
115
	public String getDescription() {
116
		return Messages.ActiveContextExternalizationParticipant_Active_Task_Context;
117
	}
118
119
	@Override
120
	public ISchedulingRule getSchedulingRule() {
121
		return ITasksCoreConstants.ACTIVE_CONTEXT_SCHEDULING_RULE;
122
	}
123
124
	@Override
125
	public boolean isDirty() {
126
		synchronized (this) {
127
			return isDirty;
128
		}
129
	}
130
131
	public void setDirty(boolean dirty) {
132
		synchronized (this) {
133
			isDirty = dirty;
134
		}
135
	}
136
137
	@Override
138
	public String getFileName() {
139
		// ignore
140
		return null;
141
	}
142
143
	@Override
144
	public void load(File sourceFile, IProgressMonitor monitor) throws CoreException {
145
		// ignore see execute method
146
	}
147
148
	@Override
149
	public void save(File targetFile, IProgressMonitor monitor) throws CoreException {
150
		// ignore see execute method
151
	}
152
153
	public void elapsedTimeUpdated(ITask task, long newElapsedTime) {
154
		if (System.currentTimeMillis() - lastUpdate > 1000 * 60 * 3) {
155
			// TODO TYR TO CHECK IF IT IS DIRTY AND IT EXISTS
156
			setDirty(shouldWriteContext());
157
			if (isDirty()) {
158
				manager.requestSave();
159
			}
160
			lastUpdate = System.currentTimeMillis();
161
		}
162
	}
163
164
	private boolean shouldWriteContext() {
165
		if (ContextCorePlugin.getContextManager() != null && currentlyActiveContext != null
166
				&& currentlyActiveContext.getAllElements().size() > 0) {
167
			// we could add a check here for whether there were changes to the context
168
			return true;
169
		}
170
		return false;
171
	}
172
173
	public void activityReset() {
174
		// ignore
175
	}
176
177
	public void userAttentionGained() {
178
		// ignore
179
	}
180
181
	public void userAttentionLost() {
182
		setDirty(shouldWriteContext());
183
		if (isDirty()) {
184
			manager.requestSave();
185
		}
186
		lastUpdate = System.currentTimeMillis();
187
	}
188
189
}

Return to bug 219173