KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > ui > internal > ide > dialogs > FileSystemSelectionArea


1 /*******************************************************************************
2  * Copyright (c) 2006 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
12 package org.eclipse.ui.internal.ide.dialogs;
13
14 import org.eclipse.jface.viewers.ComboViewer;
15 import org.eclipse.jface.viewers.ISelection;
16 import org.eclipse.jface.viewers.IStructuredContentProvider;
17 import org.eclipse.jface.viewers.IStructuredSelection;
18 import org.eclipse.jface.viewers.LabelProvider;
19 import org.eclipse.jface.viewers.StructuredSelection;
20 import org.eclipse.swt.SWT;
21 import org.eclipse.swt.layout.GridData;
22 import org.eclipse.swt.widgets.Composite;
23 import org.eclipse.swt.widgets.Label;
24 import org.eclipse.ui.internal.ide.filesystem.FileSystemConfiguration;
25 import org.eclipse.ui.internal.ide.filesystem.FileSystemMessages;
26 import org.eclipse.ui.internal.ide.filesystem.FileSystemSupportRegistry;
27
28 /**
29  * FileSystemSelectionArea is the area used to select the file system.
30  * @since 3.2
31  *
32  */

33
34 public class FileSystemSelectionArea {
35
36     private Label fileSystemTitle;
37     private ComboViewer fileSystems;
38     
39     /**
40      * Create a new instance of the receiver.
41      */

42     public FileSystemSelectionArea(){
43         
44     }
45
46     /**
47      * Create the contents of the receiver in composite.
48      * @param composite
49      */

50     public void createContents(Composite composite) {
51
52         fileSystemTitle = new Label(composite, SWT.NONE);
53         fileSystemTitle.setText(FileSystemMessages.FileSystemSelection_title);
54
55         fileSystems = new ComboViewer(composite, SWT.READ_ONLY);
56
57         fileSystems.getControl().setLayoutData(
58                 new GridData(GridData.FILL_HORIZONTAL
59                         | GridData.GRAB_HORIZONTAL));
60
61         fileSystems.setLabelProvider(new LabelProvider() {
62             /*
63              * (non-Javadoc)
64              *
65              * @see org.eclipse.jface.viewers.LabelProvider#getText(java.lang.Object)
66              */

67             public String JavaDoc getText(Object JavaDoc element) {
68                 return ((FileSystemConfiguration) element).getLabel();
69             }
70         });
71
72         fileSystems.setContentProvider(new IStructuredContentProvider() {
73
74             /*
75              * (non-Javadoc)
76              *
77              * @see org.eclipse.jface.viewers.IContentProvider#dispose()
78              */

79             public void dispose() {
80                 // Nothing to do
81
}
82
83             /*
84              * (non-Javadoc)
85              *
86              * @see org.eclipse.jface.viewers.IStructuredContentProvider#getElements(java.lang.Object)
87              */

88             public Object JavaDoc[] getElements(Object JavaDoc inputElement) {
89                 return FileSystemSupportRegistry.getInstance()
90                         .getConfigurations();
91             }
92
93             /*
94              * (non-Javadoc)
95              *
96              * @see org.eclipse.jface.viewers.IContentProvider#inputChanged(org.eclipse.jface.viewers.Viewer,
97              * java.lang.Object, java.lang.Object)
98              */

99             public void inputChanged(org.eclipse.jface.viewers.Viewer viewer,
100                     Object JavaDoc oldInput, Object JavaDoc newInput) {
101                 // Nothing to do
102
}
103
104         });
105
106         fileSystems.setInput(this);
107         fileSystems.setSelection(new StructuredSelection(
108                 FileSystemSupportRegistry.getInstance()
109                         .getDefaultConfiguration()));
110     }
111
112     /**
113      * Return the selected configuration.
114      * @return FileSystemConfiguration or <code>null</code> if nothing
115      * is selected.
116      */

117     public FileSystemConfiguration getSelectedConfiguration() {
118         ISelection selection = fileSystems.getSelection();
119         
120         if (selection instanceof IStructuredSelection) {
121             IStructuredSelection structured = (IStructuredSelection) selection;
122             if (structured.size() == 1) {
123                 return (FileSystemConfiguration) structured.getFirstElement();
124             }
125         }
126         
127         return null;
128     }
129
130     /**
131      * Set the enablement state of the widget.
132      * @param enabled
133      */

134     public void setEnabled(boolean enabled) {
135         fileSystemTitle.setEnabled(enabled);
136         fileSystems.getControl().setEnabled(enabled);
137         
138     }
139 }
140
Popular Tags