Skip to main content
summaryrefslogtreecommitdiffstats
blob: f5896f6c3dd54ed350428d2d4a52a78b271eb6fa (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
/*******************************************************************************
 * Copyright (c) 2000, 2013 IBM Corporation 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:
 *     IBM Corporation - initial API and implementation
 *     Wind River - Pawel Piech - Drag/Drop to Expressions View (Bug 184057)
 *     Wind River - Pawel Piech - Fix viewer input race condition (Bug 234908)
 *******************************************************************************/
package org.eclipse.debug.internal.ui.views.expression;

 
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;

import org.eclipse.core.runtime.IAdaptable;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.debug.core.DebugPlugin;
import org.eclipse.debug.core.IExpressionManager;
import org.eclipse.debug.core.ILaunch;
import org.eclipse.debug.core.model.IDebugElement;
import org.eclipse.debug.core.model.IWatchExpression;
import org.eclipse.debug.internal.ui.DebugUIPlugin;
import org.eclipse.debug.internal.ui.IDebugHelpContextIds;
import org.eclipse.debug.internal.ui.actions.expressions.EditWatchExpressinInPlaceAction;
import org.eclipse.debug.internal.ui.actions.expressions.PasteWatchExpressionsAction;
import org.eclipse.debug.internal.ui.actions.variables.ChangeVariableValueAction;
import org.eclipse.debug.internal.ui.preferences.IDebugPreferenceConstants;
import org.eclipse.debug.internal.ui.viewers.model.ViewerAdapterService;
import org.eclipse.debug.internal.ui.viewers.model.provisional.IElementCompareRequest;
import org.eclipse.debug.internal.ui.viewers.model.provisional.IElementMementoProvider;
import org.eclipse.debug.internal.ui.viewers.model.provisional.IElementMementoRequest;
import org.eclipse.debug.internal.ui.viewers.model.provisional.IPresentationContext;
import org.eclipse.debug.internal.ui.viewers.model.provisional.ITreeModelViewer;
import org.eclipse.debug.internal.ui.viewers.model.provisional.IViewerInputUpdate;
import org.eclipse.debug.internal.ui.viewers.model.provisional.TreeModelViewer;
import org.eclipse.debug.internal.ui.views.variables.AvailableLogicalStructuresAction;
import org.eclipse.debug.internal.ui.views.variables.SelectionDragAdapter;
import org.eclipse.debug.internal.ui.views.variables.VariablesView;
import org.eclipse.debug.internal.ui.views.variables.VariablesViewMessages;
import org.eclipse.debug.internal.ui.views.variables.details.AvailableDetailPanesAction;
import org.eclipse.debug.ui.DebugUITools;
import org.eclipse.debug.ui.IDebugUIConstants;
import org.eclipse.jface.action.IAction;
import org.eclipse.jface.action.IMenuManager;
import org.eclipse.jface.action.IToolBarManager;
import org.eclipse.jface.action.Separator;
import org.eclipse.jface.util.LocalSelectionTransfer;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.viewers.StructuredSelection;
import org.eclipse.jface.viewers.Viewer;
import org.eclipse.jface.viewers.ViewerFilter;
import org.eclipse.swt.dnd.Clipboard;
import org.eclipse.swt.dnd.DND;
import org.eclipse.swt.dnd.TextTransfer;
import org.eclipse.swt.dnd.Transfer;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
import org.eclipse.ui.IMemento;
import org.eclipse.ui.ISharedImages;
import org.eclipse.ui.IWorkbenchActionConstants;
import org.eclipse.ui.IWorkbenchCommandConstants;
import org.eclipse.ui.IWorkingSet;
import org.eclipse.ui.IWorkingSetManager;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.WorkbenchException;
import org.eclipse.ui.XMLMemento;
import org.eclipse.ui.actions.ActionFactory;
 
/**
 * Displays expressions and their values with a detail
 * pane.
 */
public class ExpressionView extends VariablesView {

	// The preference name for autoselect working sets toggle
	private static final String PREF_WORKINGSETS_AUTOSELECT = DebugUIPlugin.getUniqueIdentifier() + ".workingSetAutoselect"; //$NON-NLS-1$

	// The preference name for saving fWorkingSets
	private static final String PREF_ELEMENT_WORKINGSET = DebugUIPlugin.getUniqueIdentifier() + ".workingSet"; //$NON-NLS-1$

	// The preference name for saving fWorkingSetMementos.
	private static final String PREF_ELEMENT_WORKINGSET_MEMENTOS = DebugUIPlugin.getUniqueIdentifier() + ".workingSetMementos"; //$NON-NLS-1$

	// Limit on the number of entries in the working sets / selection map.
	private static final int MAX_WORKING_SETS_MEMENTOS = 100;
	
	private static final IWorkingSet[] EMPTY_WORKING_SETS = new IWorkingSet[0];
	
    private PasteWatchExpressionsAction fPasteAction;
    private EditWatchExpressinInPlaceAction fEditInPlaceAction;
    
    private IWorkingSet[] fWorkingSets;
    
	private boolean fAutoSelectnWorkingSets = true;

	private Map fWorkingSetMementos = new LinkedHashMap(16, (float)0.75, true) {
		private static final long serialVersionUID = 1L;

		protected boolean removeEldestEntry(java.util.Map.Entry eldest) {
			return size() > MAX_WORKING_SETS_MEMENTOS;
		}
	};
    
	private Set fPendingCompareRequests;
	
	private ExpressionElementMementoRequest fPendingMementoRequest;
	
	/* (non-Javadoc)
	 * @see org.eclipse.debug.internal.ui.views.variables.VariablesView#getHelpContextId()
	 */
	protected String getHelpContextId() {
		return IDebugHelpContextIds.EXPRESSION_VIEW;		
	}	
	
	/* (non-Javadoc)
	 * @see org.eclipse.debug.internal.ui.views.variables.VariablesView#configureToolBar(org.eclipse.jface.action.IToolBarManager)
	 */
	protected void configureToolBar(IToolBarManager tbm) {
		super.configureToolBar(tbm);
		tbm.add(new Separator(IDebugUIConstants.EMPTY_EXPRESSION_GROUP));		
		tbm.add(new Separator(IDebugUIConstants.EXPRESSION_GROUP));
	}	
	
	/* (non-Javadoc)
	 * @see org.eclipse.debug.internal.ui.views.variables.VariablesView#fillContextMenu(org.eclipse.jface.action.IMenuManager)
	 */
	protected void fillContextMenu(IMenuManager menu) {
		menu.add(new Separator(IDebugUIConstants.EMPTY_EXPRESSION_GROUP));
		menu.add(new Separator(IDebugUIConstants.EXPRESSION_GROUP));
		menu.add(getAction(FIND_ACTION));
        ChangeVariableValueAction changeValueAction = (ChangeVariableValueAction)getAction("ChangeVariableValue"); //$NON-NLS-1$
        if (changeValueAction.isApplicable()) {
            menu.add(changeValueAction); 
        }
		menu.add(new Separator());
		IAction action = new AvailableLogicalStructuresAction(this);
        if (action.isEnabled()) {
            menu.add(action);
        }
		action = new AvailableDetailPanesAction(this);
		if (isDetailPaneVisible() && action.isEnabled()) {
			menu.add(action);
		}
		menu.add(new Separator(IDebugUIConstants.EMPTY_RENDER_GROUP));
		menu.add(new Separator(IWorkbenchActionConstants.MB_ADDITIONS));
	}

	/* (non-Javadoc)
	 * @see org.eclipse.debug.internal.ui.views.variables.VariablesView#contextActivated(org.eclipse.jface.viewers.ISelection)
	 */
	protected void contextActivated(ISelection selection) {
		if (!isAvailable() || !isVisible()) {
			return;
		}
		if (selection == null || selection.isEmpty()) {
            super.contextActivated(new StructuredSelection(DebugPlugin.getDefault().getExpressionManager()));
		} else {
			super.contextActivated(selection);
			if (fAutoSelectnWorkingSets) {
		        Object element = ((IStructuredSelection)selection).getFirstElement();
		        compareElementMementos(element);
			}
		}
        if (isAvailable() && isVisible()) {
            updateAction("ContentAssist"); //$NON-NLS-1$
        }
	}

    /* (non-Javadoc)
     * @see org.eclipse.debug.internal.ui.views.variables.VariablesView#viewerInputUpdateComplete(IViewerInputUpdate)
     */
	protected void viewerInputUpdateComplete(IViewerInputUpdate update) {
        IStatus status = update.getStatus();
        if ( (status == null || status.isOK()) && update.getElement() != null) {
            setViewerInput(update.getInputElement());
        } else {
            setViewerInput(DebugPlugin.getDefault().getExpressionManager());
        }
        updateAction(FIND_ACTION);
	}
	
	public void setAutoSelectWoringSets(boolean autoSelect) {
		if (fAutoSelectnWorkingSets != autoSelect) {
			fAutoSelectnWorkingSets = autoSelect;
		}
	}
	
	public boolean isAutoSelectWorkingSets() {
		return fAutoSelectnWorkingSets;
	}
	
	public void elementCompareComplete(String[] workingSetNames) {
		IWorkingSetManager mgr = PlatformUI.getWorkbench().getWorkingSetManager();
		List workingSetList = new ArrayList();
		for (int j = 0; j < workingSetNames.length; j++) {
			IWorkingSet workingSet = mgr.getWorkingSet(workingSetNames[j]);
			if (workingSet != null) {
				workingSetList.add(workingSet);
			}
		}
		doApplyWorkingSets((IWorkingSet[])workingSetList.toArray(new IWorkingSet[workingSetList.size()]));
	}
	
	/* (non-Javadoc)
	 * @see org.eclipse.debug.internal.ui.views.variables.VariablesView#getDetailPanePreferenceKey()
	 */
	protected String getDetailPanePreferenceKey() {
		return IDebugPreferenceConstants.EXPRESSIONS_DETAIL_PANE_ORIENTATION;
	}

	/* (non-Javadoc)
	 * @see org.eclipse.debug.internal.ui.views.variables.VariablesView#getToggleActionLabel()
	 */
	protected String getToggleActionLabel() {
		return VariablesViewMessages.ExpressionView_4; 
	}

	/* (non-Javadoc)
	 * @see org.eclipse.debug.internal.ui.views.variables.VariablesView#getPresentationContextId()
	 */
	protected String getPresentationContextId() {
		return IDebugUIConstants.ID_EXPRESSION_VIEW;
	}	
	
    /* (non-Javadoc)
     * @see org.eclipse.debug.internal.ui.views.variables.VariablesView#initDragAndDrop(org.eclipse.debug.internal.ui.viewers.model.provisional.TreeModelViewer)
     */
    protected void initDragAndDrop(TreeModelViewer viewer) {
        viewer.addDragSupport(DND.DROP_MOVE, new Transfer[] {LocalSelectionTransfer.getTransfer()}, new SelectionDragAdapter(viewer));
        viewer.addDropSupport(DND.DROP_MOVE|DND.DROP_COPY, new Transfer[] {LocalSelectionTransfer.getTransfer(), TextTransfer.getInstance()}, new ExpressionDropAdapter(getSite(), viewer));
    }
    
    /* (non-Javadoc)
     * @see org.eclipse.debug.internal.ui.views.variables.VariablesView#createActions()
     */
    protected void createActions() {
    	super.createActions();
    	fPasteAction = new PasteWatchExpressionsAction(this);
    	configure(fPasteAction, IWorkbenchCommandConstants.EDIT_PASTE, PASTE_ACTION, ISharedImages.IMG_TOOL_PASTE);
    	fEditInPlaceAction = new EditWatchExpressinInPlaceAction(this);
        configure(fEditInPlaceAction, IWorkbenchCommandConstants.FILE_RENAME, ActionFactory.RENAME.getId(), null);
    }
    
    public void dispose() {
        fEditInPlaceAction.dispose();
        cancelPendingCompareRequests();
        if (fPendingMementoRequest != null) fPendingMementoRequest.cancel();
        super.dispose();
    }
    
    /**
     * Configures the action to override the global action, and registers the
     * action with this view.
     * 
     * @param action
     * 		action
     * @param defId
     * 		action definition id
     * @param globalId
     * 		global action id
     * @param imgId
     * 		image identifier
     */
    private void configure(IAction action, String defId, String globalId,
    		String imgId) {
    	setAction(globalId, action);
    	action.setActionDefinitionId(defId);
    	setGlobalAction(globalId, action);
    	if (imgId != null) {
    	    action.setImageDescriptor(PlatformUI.getWorkbench().getSharedImages().getImageDescriptor(imgId));
    	}
    }
    
    /**
     * Returns whether the given selection can be pasted into the expressions
     * view.
     * 
     * @return whether the given selection can be pasted into the given target
     */
    public boolean canPaste() {
    	String clipboardText = getClipboardText();
    	if (clipboardText != null && clipboardText.length() > 0) {
    		return true;
    	}
    	return false;
    }
       
    /**
     * Pastes the selection into the given target
     * 
     * @return whether successful
     */
    public boolean performPaste() {
    	String clipboardText = getClipboardText();
    	if (clipboardText != null && clipboardText.length() > 0) {
    		IExpressionManager expressionManager = DebugPlugin.getDefault().getExpressionManager();
    		IWatchExpression watchExpression = expressionManager
    				.newWatchExpression(clipboardText);
    		expressionManager.addExpression(watchExpression);
    		watchExpression.setExpressionContext(getContext());
    		return true;
    	}
    	return false;
    }
    
    // TODO: duplicate code from WatchExpressionAction
    protected IDebugElement getContext() {
        IAdaptable object = DebugUITools.getPartDebugContext(getSite());
        IDebugElement context = null;
        if (object instanceof IDebugElement) {
            context = (IDebugElement) object;
        } else if (object instanceof ILaunch) {
            context = ((ILaunch) object).getDebugTarget();
        }
        return context;
    }
    
    protected String getClipboardText() {
    	Clipboard clipboard = new Clipboard(Display.getDefault());
    	try {
    		TextTransfer textTransfer = TextTransfer.getInstance();
    		return (String) clipboard.getContents(textTransfer);
    	} finally {
    		clipboard.dispose();
    	}
    }

    public Viewer createViewer(Composite parent) {
    	TreeModelViewer viewer = (TreeModelViewer)super.createViewer(parent);

    	initWorkingSets();
    	initWorkingSetMementos();
		getWorkingSetFilter(viewer).setSelectedWorkingSets(fWorkingSets);
		updateWorkingSetsProperty(viewer.getPresentationContext());    	

    	return viewer;
    }

    private String[] loadWorkingSetNames(IMemento memento) {
		IMemento[] workingsets = memento.getChildren(PREF_ELEMENT_WORKINGSET);
		if (workingsets != null) {
			List list = new ArrayList();
			for (int j=0; j<workingsets.length; j++) {
				list.add(workingsets[j].getID());
			}
			return (String[])list.toArray(new String[list.size()]);
		} 
		return new String[0];
    }

    private void initWorkingSets() {
    	String[] workingSetNames = loadWorkingSetNames(getMemento());
		List list = new ArrayList();
		for (int j = 0; j < workingSetNames.length; j++) {
			IWorkingSet workingsetObject = PlatformUI.getWorkbench().getWorkingSetManager().getWorkingSet(workingSetNames[j]);
			if (workingsetObject != null) {
				list.add(workingsetObject);
			}
		}
		fWorkingSets = (IWorkingSet[]) list.toArray(new IWorkingSet[list.size()]);
    }

    private void initWorkingSetMementos() {
		IMemento[] workingsetMementos = getMemento().getChildren(PREF_ELEMENT_WORKINGSET_MEMENTOS);
		if (workingsetMementos != null) {
			for (int j=0; j<workingsetMementos.length; j++) {
				String[] workingSetNames = loadWorkingSetNames(workingsetMementos[j]);
				String string = workingsetMementos[j].getID();
		        if(string.length() > 0 && workingSetNames != null) {
		            ByteArrayInputStream bin = new ByteArrayInputStream(string.getBytes());
		            InputStreamReader reader = new InputStreamReader(bin);
		            try {
		                XMLMemento workingSetsKey = XMLMemento.createReadRoot(reader);
		                fWorkingSetMementos.put(workingSetsKey, workingSetNames);
		            } catch (WorkbenchException e) {
		            } finally {
		                try {
		                    reader.close();
		                    bin.close();
		                } catch (IOException e){}
		            }
		        }
			}
		}
    }

    public void saveViewerState(IMemento memento) {
    	super.saveViewerState(memento);

    	memento.putBoolean(PREF_WORKINGSETS_AUTOSELECT, fAutoSelectnWorkingSets);
    	if (!fAutoSelectnWorkingSets) {
    		saveWorkingSets(memento, getWorkingSetNames());
    	}
    	saveWorkingSetMementos(memento);
    }

    private void saveWorkingSets(IMemento memento, String[] workingSetNames) {
		for (int i=0; i<workingSetNames.length; i++) {
			memento.createChild(PREF_ELEMENT_WORKINGSET, workingSetNames[i]);
		}    	
    }
    
    private void saveWorkingSetMementos(IMemento memento) {
    	for (Iterator itr = fWorkingSetMementos.entrySet().iterator(); itr.hasNext();) {
    		Map.Entry entry = (Map.Entry)itr.next();
    		String keyMementoString = getMenentoString((XMLMemento)entry.getKey());
            IMemento workingSetsForElementMemento = memento.createChild(PREF_ELEMENT_WORKINGSET_MEMENTOS, keyMementoString);
            saveWorkingSets(workingSetsForElementMemento, (String[])entry.getValue());
    	}
    }
    
    private String getMenentoString(XMLMemento memento) {
		ByteArrayOutputStream bout = new ByteArrayOutputStream();
		OutputStreamWriter writer = new OutputStreamWriter(bout);
	
		try {
			memento.save(writer);
			return bout.toString();
		} catch (IOException e) {
		} finally {
			try {
				writer.close();
				bout.close();
			} catch (IOException e) {
			}
		}
		return null;
    }
    
    public void applyWorkingSets(IWorkingSet[] selectedWorkingSets) {
    	doApplyWorkingSets(selectedWorkingSets);
		saveWorkingSetsForInput();
    }

    private void doApplyWorkingSets(IWorkingSet[] selectedWorkingSets) {
    	fWorkingSets = selectedWorkingSets;
    	TreeModelViewer viewer = (TreeModelViewer)getViewer(); 
		getWorkingSetFilter(viewer).setSelectedWorkingSets(fWorkingSets);
		updateWorkingSetsProperty(viewer.getPresentationContext());
		getViewer().refresh();    	
    }
    
    private void saveWorkingSetsForInput() {
    	if (fPendingMementoRequest != null) {
    		fPendingMementoRequest.cancel();
    	}
    	Object element = getDebugContextElement();
		IElementMementoProvider provider = ViewerAdapterService.getMementoProvider(element);
		if (provider == null) return;
		
        XMLMemento expressionMemento = XMLMemento.createWriteRoot("EXPRESSION_WORKING_SETS_MEMENTO"); //$NON-NLS-1$
        fPendingMementoRequest = new ExpressionElementMementoRequest(
        		this, getPresentationContext(), getDebugContextElement(), expressionMemento, getWorkingSetNames());
        provider.encodeElements(new IElementMementoRequest[] { fPendingMementoRequest });
    }
    
    void mementoRequestFinished(ExpressionElementMementoRequest request) {
		if (!request.isCanceled()) {
			fWorkingSetMementos.put(request.getMemento(), request.getWorkingSets());
		}    	
    }
    
    private String[] getWorkingSetNames() {
    	String[] names = new String[fWorkingSets.length];
    	for (int i = 0; i < fWorkingSets.length; i++) {
    		names[i] = fWorkingSets[i].getName();
    	}
    	return names;
    }
    
    private Object getDebugContextElement() {
    	ISelection selection = getDebugContext();
    	if (selection == null || selection.isEmpty() || !(selection instanceof IStructuredSelection)) {
    		return DebugPlugin.getDefault().getExpressionManager();
    	}
    	return ((IStructuredSelection)selection).getFirstElement();
    }

    private void updateWorkingSetsProperty(IPresentationContext presentationContext) {
		if (fWorkingSets.length > 0) {
			String[] workingSetNames = new String[fWorkingSets.length];
			for (int j=0; j<fWorkingSets.length; j++) {
				workingSetNames[j] = fWorkingSets[j].getName();
			}		
			presentationContext.setProperty(IDebugUIConstants.PROP_EXPRESSIONS_WORKING_SETS, workingSetNames);
		} else {
			presentationContext.setProperty(IDebugUIConstants.PROP_EXPRESSIONS_WORKING_SETS, new String[0]);
		}
    }
    
    public IWorkingSet[] getWorkingSets() {
    	return fWorkingSets;
    }
    
	private ExpressionWorkingSetFilter getWorkingSetFilter(ITreeModelViewer viewer) {
        ViewerFilter[] existingFilters = viewer.getFilters();
        for (int i=0; i<existingFilters.length; i++) {
        	ViewerFilter existingFilter = existingFilters[i];
        	if (existingFilter instanceof ExpressionWorkingSetFilter) {
        		return (ExpressionWorkingSetFilter) existingFilter;
        	}
        }
        
        ExpressionWorkingSetFilter workingSetFilter = new ExpressionWorkingSetFilter();
        viewer.addFilter(workingSetFilter);
        return workingSetFilter;
	}

	private void compareElementMementos(Object source) {
		IElementMementoProvider provdier = ViewerAdapterService.getMementoProvider(source);
		if (provdier != null) {
	        Set requests = new HashSet(fWorkingSetMementos.size() * 4/3);
	        for (Iterator itr = fWorkingSetMementos.entrySet().iterator(); itr.hasNext();) {
	        	Map.Entry entry = (Map.Entry)itr.next();
	        	requests.add( new  ExpressionElementCompareRequest(
	        			this, getPresentationContext(), source, (IMemento)entry.getKey(), (String[])entry.getValue()) );
	        }
	
			// cancel any pending update
			cancelPendingCompareRequests();
			if (!requests.isEmpty()) {
				fPendingCompareRequests = requests;
				provdier.compareElements((IElementCompareRequest[])
						fPendingCompareRequests.toArray(new IElementCompareRequest[fPendingCompareRequests.size()]) );
			}
		} else {
			doApplyWorkingSets(EMPTY_WORKING_SETS);
		}
	}
	
	void compareRequestFinished(final ExpressionElementCompareRequest request) {
		if (fPendingCompareRequests != null && fPendingCompareRequests.remove(request)) {
			if (!request.isCanceled() && request.isEqual()) {
				elementCompareComplete(request.getWorkingSets());
				cancelPendingCompareRequests();
			} else if (fPendingCompareRequests.isEmpty()) {
				elementCompareComplete(new String[0]);
				fPendingCompareRequests = null;
			}
		}
	}
	
	private void cancelPendingCompareRequests() {
		if (fPendingCompareRequests == null) return;
        for (Iterator itr = fPendingCompareRequests.iterator(); itr.hasNext();) {
        	((IElementCompareRequest)itr.next()).cancel();
        }
		fPendingCompareRequests = null;
	}
	
}

Back to the top