KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*******************************************************************************
2  * Copyright (c) 2003, 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.browsers;
12
13 import java.util.ArrayList JavaDoc;
14
15 import org.eclipse.core.resources.IFolder;
16 import org.eclipse.debug.core.sourcelookup.ISourceContainer;
17 import org.eclipse.debug.core.sourcelookup.ISourceLookupDirector;
18 import org.eclipse.debug.core.sourcelookup.containers.FolderSourceContainer;
19 import org.eclipse.debug.ui.sourcelookup.AbstractSourceContainerBrowser;
20 import org.eclipse.jface.window.Window;
21 import org.eclipse.swt.widgets.Shell;
22 import org.eclipse.ui.dialogs.ElementTreeSelectionDialog;
23 import org.eclipse.ui.model.WorkbenchContentProvider;
24 import org.eclipse.ui.model.WorkbenchLabelProvider;
25
26 /**
27  * The browser for adding a folder source container.
28  *
29  * @since 3.0
30  */

31 public class FolderSourceContainerBrowser extends AbstractSourceContainerBrowser {
32     
33     /* (non-Javadoc)
34      * @see org.eclipse.debug.internal.ui.sourcelookup.ISourceContainerBrowser#createSourceContainers(org.eclipse.swt.widgets.Shell, org.eclipse.debug.core.ILaunchConfiguration)
35      */

36     public ISourceContainer[] addSourceContainers(Shell shell, ISourceLookupDirector director) {
37         FolderSourceContainerDialog dialog = new FolderSourceContainerDialog(shell, new WorkbenchLabelProvider(), new WorkbenchContentProvider());
38         
39         if (dialog.open() == Window.OK) {
40             Object JavaDoc[] selection= ((ElementTreeSelectionDialog)dialog).getResult();
41             ArrayList JavaDoc containers = new ArrayList JavaDoc();
42             for (int i= 0; i < selection.length; i++) {
43                 if(selection[i] instanceof IFolder) {
44                     containers.add(new FolderSourceContainer((IFolder)selection[i], dialog.isSearchSubfolders()));
45                 }
46             }
47             return (ISourceContainer[])containers.toArray(new ISourceContainer[containers.size()]);
48         }
49         return new ISourceContainer[0];
50     }
51
52     /* (non-Javadoc)
53      * @see org.eclipse.debug.ui.sourcelookup.AbstractSourceContainerBrowser#canEditSourceContainers(org.eclipse.debug.core.sourcelookup.ISourceLookupDirector, org.eclipse.debug.core.sourcelookup.ISourceContainer[])
54      */

55     public boolean canEditSourceContainers(ISourceLookupDirector director, ISourceContainer[] containers) {
56         return containers.length == 1 && containers[0].getType().getId().equals(FolderSourceContainer.TYPE_ID);
57     }
58
59     /* (non-Javadoc)
60      * @see org.eclipse.debug.ui.sourcelookup.AbstractSourceContainerBrowser#editSourceContainers(org.eclipse.swt.widgets.Shell, org.eclipse.debug.core.sourcelookup.ISourceLookupDirector, org.eclipse.debug.core.sourcelookup.ISourceContainer[])
61      */

62     public ISourceContainer[] editSourceContainers(Shell shell, ISourceLookupDirector director, ISourceContainer[] containers) {
63         FolderSourceContainerDialog dialog = new FolderSourceContainerDialog(shell, new WorkbenchLabelProvider(), new WorkbenchContentProvider());
64         FolderSourceContainer container = (FolderSourceContainer) containers[0];
65         dialog.setSearchSubfolders(container.isComposite());
66         dialog.setInitialSelection(container.getContainer());
67         if (dialog.open() == Window.OK) {
68             container.dispose();
69             Object JavaDoc[] selection= ((ElementTreeSelectionDialog)dialog).getResult();
70             ArrayList JavaDoc list = new ArrayList JavaDoc();
71             for (int i= 0; i < selection.length; i++) {
72                 if(selection[i] instanceof IFolder) {
73                     list.add(new FolderSourceContainer((IFolder)selection[i], dialog.isSearchSubfolders()));
74                 }
75             }
76             return (ISourceContainer[])list.toArray(new ISourceContainer[list.size()]);
77         }
78         return new ISourceContainer[0];
79     }
80     
81     
82     
83 }
84
Popular Tags