KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > debug > internal > ui > sourcelookup > browsers > ArchiveSourceContainerBrowser


1 /*******************************************************************************
2  * Copyright (c) 2000, 2007 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.browsers;
12
13
14 import java.util.ArrayList JavaDoc;
15 import java.util.List JavaDoc;
16
17 import org.eclipse.core.resources.IFile;
18 import org.eclipse.core.resources.ResourcesPlugin;
19 import org.eclipse.core.runtime.IStatus;
20 import org.eclipse.core.runtime.Status;
21 import org.eclipse.debug.core.sourcelookup.ISourceContainer;
22 import org.eclipse.debug.core.sourcelookup.ISourceLookupDirector;
23 import org.eclipse.debug.core.sourcelookup.containers.ArchiveSourceContainer;
24 import org.eclipse.debug.internal.ui.DebugUIPlugin;
25 import org.eclipse.debug.internal.ui.sourcelookup.SourceLookupUIMessages;
26 import org.eclipse.debug.ui.sourcelookup.AbstractSourceContainerBrowser;
27 import org.eclipse.jface.viewers.ILabelProvider;
28 import org.eclipse.jface.viewers.ITreeContentProvider;
29 import org.eclipse.jface.viewers.ViewerFilter;
30 import org.eclipse.jface.window.Window;
31 import org.eclipse.swt.widgets.Shell;
32 import org.eclipse.ui.dialogs.ElementTreeSelectionDialog;
33 import org.eclipse.ui.dialogs.ISelectionStatusValidator;
34 import org.eclipse.ui.model.WorkbenchContentProvider;
35 import org.eclipse.ui.model.WorkbenchLabelProvider;
36 import org.eclipse.ui.views.navigator.ResourceComparator;
37
38 /**
39  * Adds an internal jar to the runtime class path.
40  */

41 public class ArchiveSourceContainerBrowser extends AbstractSourceContainerBrowser {
42
43     private ISelectionStatusValidator validator= new ISelectionStatusValidator() {
44         public IStatus validate(Object JavaDoc[] selection) {
45             if (selection.length == 0) {
46                 return new Status(IStatus.ERROR, DebugUIPlugin.getUniqueIdentifier(), 0, "", null); //$NON-NLS-1$
47
}
48             for (int i= 0; i < selection.length; i++) {
49                 if (!(selection[i] instanceof IFile)) {
50                     return new Status(IStatus.ERROR, DebugUIPlugin.getUniqueIdentifier(), 0, "", null); //$NON-NLS-1$
51
}
52             }
53             return new Status(IStatus.OK, DebugUIPlugin.getUniqueIdentifier(), 0, "", null); //$NON-NLS-1$
54
}
55     };
56
57     /**
58      * Returns internal jars (source containers) currently used by the
59      * given source lookup director.
60      *
61      * @param director source lookup director jars are being added to
62      */

63     protected List JavaDoc getSelectedJars(ISourceLookupDirector director) {
64         ISourceContainer[] containers = director.getSourceContainers();
65         List JavaDoc jars = new ArrayList JavaDoc();
66         for (int i = 0; i < containers.length; i++) {
67             ISourceContainer container = containers[i];
68             if (container.getType().getId().equals(ArchiveSourceContainer.TYPE_ID)) {
69                 jars.add(container);
70             }
71         }
72         return jars;
73     }
74
75     /* (non-Javadoc)
76      * @see org.eclipse.debug.internal.ui.sourcelookup.ISourceContainerBrowser#createSourceContainers(org.eclipse.swt.widgets.Shell, org.eclipse.debug.internal.core.sourcelookup.ISourceLookupDirector)
77      */

78     public ISourceContainer[] addSourceContainers(Shell shell, ISourceLookupDirector director) {
79         ViewerFilter filter= new ArchiveFilter(getSelectedJars(director));
80         
81         ILabelProvider lp= new WorkbenchLabelProvider();
82         ITreeContentProvider cp= new WorkbenchContentProvider();
83
84         ElementTreeSelectionDialog dialog= new ElementTreeSelectionDialog(shell, lp, cp);
85         dialog.setValidator(validator);
86         dialog.setTitle(SourceLookupUIMessages.ArchiveSourceContainerBrowser_3);
87         dialog.setMessage(SourceLookupUIMessages.ArchiveSourceContainerBrowser_4);
88         dialog.addFilter(filter);
89         dialog.setInput(ResourcesPlugin.getWorkspace().getRoot());
90         dialog.setComparator(new ResourceComparator(ResourceComparator.NAME));
91
92         if (dialog.open() == Window.OK) {
93             Object JavaDoc[] result = dialog.getResult();
94             ISourceContainer[] containers = new ISourceContainer[result.length];
95             for (int i = 0; i < containers.length; i++) {
96                 containers[i] = new ArchiveSourceContainer((IFile)result[i], true);
97             }
98             return containers;
99         }
100         return new ISourceContainer[0];
101     }
102 }
103
Popular Tags