KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > debug > internal > ui > sourcelookup > ResolveDuplicatesHandler


1 /*******************************************************************************
2  * Copyright (c) 2000, 2005 IBM Corporation 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  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.debug.internal.ui.sourcelookup;
12
13 import java.util.ArrayList JavaDoc;
14 import java.util.Iterator JavaDoc;
15 import java.util.List JavaDoc;
16
17 import org.eclipse.core.runtime.CoreException;
18 import org.eclipse.core.runtime.IStatus;
19 import org.eclipse.debug.core.IStatusHandler;
20 import org.eclipse.debug.internal.ui.DebugUIPlugin;
21 import org.eclipse.debug.ui.sourcelookup.CommonSourceNotFoundEditor;
22 import org.eclipse.jface.window.Window;
23 import org.eclipse.ui.dialogs.ElementListSelectionDialog;
24
25 /**
26  * Status handler to prompt for dupicate source element resolution.
27  *
28  * @since 3.0
29  */

30 public class ResolveDuplicatesHandler implements IStatusHandler {
31     /* (non-Javadoc)
32      * @see org.eclipse.debug.core.IStatusHandler#handleStatus(org.eclipse.core.runtime.IStatus, java.lang.Object)
33      */

34     public Object JavaDoc handleStatus(IStatus status, Object JavaDoc source) throws CoreException {
35         Object JavaDoc[] args = (Object JavaDoc[])source;
36         List JavaDoc sources = (List JavaDoc) args[1];
37         return resolveSourceElement(sources);
38     }
39     
40     public Object JavaDoc resolveSourceElement(List JavaDoc sources) {
41         Object JavaDoc file = null;
42         sources = removeSourceNotFoundEditors(sources);
43         if(sources.size() == 1) {
44             return sources.get(0);
45         } else if(sources.size() == 0) {
46             return null;
47         }
48         ElementListSelectionDialog dialog = new ElementListSelectionDialog(DebugUIPlugin.getShell(), new SourceElementLabelProvider());
49         dialog.setMultipleSelection(false);
50         dialog.setTitle(SourceLookupUIMessages.ResolveDuplicatesHandler_0);
51         dialog.setMessage(SourceLookupUIMessages.ResolveDuplicatesHandler_1);
52         dialog.setElements(sources.toArray());
53         dialog.open();
54         if(dialog.getReturnCode() == Window.OK) {
55             file = dialog.getFirstResult();
56         }
57         return file;
58     }
59     
60     /**
61      * Remove extra source not found editors, if any.
62      * If multiple source not found editors and no "real" source inputs,
63      * return the first source not found editor.
64      * @param sources the list to be filtered
65      * @return the filtered list, may be empty
66      */

67     private List JavaDoc removeSourceNotFoundEditors(List JavaDoc sources){
68         Iterator JavaDoc iterator = sources.iterator();
69         List JavaDoc filteredList = new ArrayList JavaDoc();
70         Object JavaDoc next;
71         while(iterator.hasNext()) {
72             next = iterator.next();
73             if (!(next instanceof CommonSourceNotFoundEditor)) {
74                 filteredList.add(next);
75             }
76         }
77         if (filteredList.isEmpty() && sources.get(0) != null) {
78             filteredList.add(sources.get(0));
79         }
80         return filteredList;
81     }
82 }
83
Popular Tags