1 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 33 34 public class FileSystemSelectionArea { 35 36 private Label fileSystemTitle; 37 private ComboViewer fileSystems; 38 39 42 public FileSystemSelectionArea(){ 43 44 } 45 46 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 67 public String getText(Object element) { 68 return ((FileSystemConfiguration) element).getLabel(); 69 } 70 }); 71 72 fileSystems.setContentProvider(new IStructuredContentProvider() { 73 74 79 public void dispose() { 80 } 82 83 88 public Object [] getElements(Object inputElement) { 89 return FileSystemSupportRegistry.getInstance() 90 .getConfigurations(); 91 } 92 93 99 public void inputChanged(org.eclipse.jface.viewers.Viewer viewer, 100 Object oldInput, Object newInput) { 101 } 103 104 }); 105 106 fileSystems.setInput(this); 107 fileSystems.setSelection(new StructuredSelection( 108 FileSystemSupportRegistry.getInstance() 109 .getDefaultConfiguration())); 110 } 111 112 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 134 public void setEnabled(boolean enabled) { 135 fileSystemTitle.setEnabled(enabled); 136 fileSystems.getControl().setEnabled(enabled); 137 138 } 139 } 140 | Popular Tags |