KickJava   Java API By Example, From Geeks To Geeks.

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


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  * QNX Software Systems - Mikhail Khodjaiants - Bug 114664
11  *******************************************************************************/

12 package org.eclipse.debug.internal.ui.sourcelookup.browsers;
13
14 import org.eclipse.core.runtime.Path;
15 import org.eclipse.debug.core.sourcelookup.ISourceContainer;
16 import org.eclipse.debug.core.sourcelookup.ISourceLookupDirector;
17 import org.eclipse.debug.core.sourcelookup.containers.DirectorySourceContainer;
18 import org.eclipse.debug.ui.sourcelookup.AbstractSourceContainerBrowser;
19 import org.eclipse.jface.window.Window;
20 import org.eclipse.swt.widgets.Shell;
21
22 /**
23  * The browser for adding an external folder source container.
24  * @since 3.0
25  */

26 public class DirectorySourceContainerBrowser extends AbstractSourceContainerBrowser {
27     
28     /* (non-Javadoc)
29      * @see org.eclipse.debug.internal.ui.sourcelookup.ISourceContainerBrowser#createSourceContainers(org.eclipse.swt.widgets.Shell, org.eclipse.debug.core.ILaunchConfiguration)
30      */

31     public ISourceContainer[] addSourceContainers(Shell shell, ISourceLookupDirector director) {
32         ISourceContainer[] containers = new ISourceContainer[1];
33         DirectorySourceContainerDialog dialog = new DirectorySourceContainerDialog(shell);
34         if (dialog.open() == Window.OK) {
35             String JavaDoc directory = dialog.getDirectory();
36             if(directory !=null) {
37                 containers[0] = new DirectorySourceContainer(new Path(directory), dialog.isSearchSubfolders());
38                 return containers;
39             }
40         }
41         return new ISourceContainer[0];
42     }
43
44     /* (non-Javadoc)
45      * @see org.eclipse.debug.ui.sourcelookup.AbstractSourceContainerBrowser#canEditSourceContainers(org.eclipse.debug.core.sourcelookup.ISourceLookupDirector, org.eclipse.debug.core.sourcelookup.ISourceContainer[])
46      */

47     public boolean canEditSourceContainers(ISourceLookupDirector director, ISourceContainer[] containers) {
48         return containers.length == 1 && DirectorySourceContainer.TYPE_ID.equals(containers[0].getType().getId());
49     }
50
51     /* (non-Javadoc)
52      * @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[])
53      */

54     public ISourceContainer[] editSourceContainers(Shell shell, ISourceLookupDirector director, ISourceContainer[] containers) {
55         if (containers.length == 1 && DirectorySourceContainer.TYPE_ID.equals(containers[0].getType().getId()) ) {
56             DirectorySourceContainer c = (DirectorySourceContainer)containers[0];
57             DirectorySourceContainerDialog dialog = new DirectorySourceContainerDialog(shell, c.getDirectory().getPath(), c.isComposite());
58             if (dialog.open() == Window.OK) {
59                 String JavaDoc directory = dialog.getDirectory();
60                 if(directory !=null) {
61                     containers[0].dispose();
62                     return new ISourceContainer[]{ new DirectorySourceContainer(new Path(directory), dialog.isSearchSubfolders())};
63                 }
64             }
65         }
66         return containers;
67     }
68     
69 }
70
Popular Tags