001: /*******************************************************************************
002: * Copyright (c) 2006 IBM Corporation and others.
003: * All rights reserved. This program and the accompanying materials
004: * are made available under the terms of the Eclipse Public License v1.0
005: * which accompanies this distribution, and is available at
006: * http://www.eclipse.org/legal/epl-v10.html
007: *
008: * Contributors:
009: * IBM Corporation - initial API and implementation
010: ******************************************************************************/package org.eclipse.ui.internal.ide.dialogs;
011:
012: import org.eclipse.jface.viewers.ComboViewer;
013: import org.eclipse.jface.viewers.ISelection;
014: import org.eclipse.jface.viewers.IStructuredContentProvider;
015: import org.eclipse.jface.viewers.IStructuredSelection;
016: import org.eclipse.jface.viewers.LabelProvider;
017: import org.eclipse.jface.viewers.StructuredSelection;
018: import org.eclipse.swt.SWT;
019: import org.eclipse.swt.layout.GridData;
020: import org.eclipse.swt.widgets.Composite;
021: import org.eclipse.swt.widgets.Label;
022: import org.eclipse.ui.internal.ide.filesystem.FileSystemConfiguration;
023: import org.eclipse.ui.internal.ide.filesystem.FileSystemMessages;
024: import org.eclipse.ui.internal.ide.filesystem.FileSystemSupportRegistry;
025:
026: /**
027: * FileSystemSelectionArea is the area used to select the file system.
028: * @since 3.2
029: *
030: */
031:
032: public class FileSystemSelectionArea {
033:
034: private Label fileSystemTitle;
035: private ComboViewer fileSystems;
036:
037: /**
038: * Create a new instance of the receiver.
039: */
040: public FileSystemSelectionArea() {
041:
042: }
043:
044: /**
045: * Create the contents of the receiver in composite.
046: * @param composite
047: */
048: public void createContents(Composite composite) {
049:
050: fileSystemTitle = new Label(composite, SWT.NONE);
051: fileSystemTitle
052: .setText(FileSystemMessages.FileSystemSelection_title);
053:
054: fileSystems = new ComboViewer(composite, SWT.READ_ONLY);
055:
056: fileSystems.getControl().setLayoutData(
057: new GridData(GridData.FILL_HORIZONTAL
058: | GridData.GRAB_HORIZONTAL));
059:
060: fileSystems.setLabelProvider(new LabelProvider() {
061: /*
062: * (non-Javadoc)
063: *
064: * @see org.eclipse.jface.viewers.LabelProvider#getText(java.lang.Object)
065: */
066: public String getText(Object element) {
067: return ((FileSystemConfiguration) element).getLabel();
068: }
069: });
070:
071: fileSystems
072: .setContentProvider(new IStructuredContentProvider() {
073:
074: /*
075: * (non-Javadoc)
076: *
077: * @see org.eclipse.jface.viewers.IContentProvider#dispose()
078: */
079: public void dispose() {
080: // Nothing to do
081: }
082:
083: /*
084: * (non-Javadoc)
085: *
086: * @see org.eclipse.jface.viewers.IStructuredContentProvider#getElements(java.lang.Object)
087: */
088: public Object[] getElements(Object inputElement) {
089: return FileSystemSupportRegistry.getInstance()
090: .getConfigurations();
091: }
092:
093: /*
094: * (non-Javadoc)
095: *
096: * @see org.eclipse.jface.viewers.IContentProvider#inputChanged(org.eclipse.jface.viewers.Viewer,
097: * java.lang.Object, java.lang.Object)
098: */
099: public void inputChanged(
100: org.eclipse.jface.viewers.Viewer viewer,
101: Object oldInput, Object newInput) {
102: // Nothing to do
103: }
104:
105: });
106:
107: fileSystems.setInput(this );
108: fileSystems.setSelection(new StructuredSelection(
109: FileSystemSupportRegistry.getInstance()
110: .getDefaultConfiguration()));
111: }
112:
113: /**
114: * Return the selected configuration.
115: * @return FileSystemConfiguration or <code>null</code> if nothing
116: * is selected.
117: */
118: public FileSystemConfiguration getSelectedConfiguration() {
119: ISelection selection = fileSystems.getSelection();
120:
121: if (selection instanceof IStructuredSelection) {
122: IStructuredSelection structured = (IStructuredSelection) selection;
123: if (structured.size() == 1) {
124: return (FileSystemConfiguration) structured
125: .getFirstElement();
126: }
127: }
128:
129: return null;
130: }
131:
132: /**
133: * Set the enablement state of the widget.
134: * @param enabled
135: */
136: public void setEnabled(boolean enabled) {
137: fileSystemTitle.setEnabled(enabled);
138: fileSystems.getControl().setEnabled(enabled);
139:
140: }
141: }
|