1 11 package org.eclipse.jdt.internal.ui.wizards.buildpaths; 12 13 import org.eclipse.core.resources.IContainer; 14 15 import org.eclipse.swt.SWT; 16 import org.eclipse.swt.events.SelectionAdapter; 17 import org.eclipse.swt.events.SelectionEvent; 18 import org.eclipse.swt.widgets.Button; 19 import org.eclipse.swt.widgets.Composite; 20 import org.eclipse.swt.widgets.Control; 21 import org.eclipse.swt.widgets.Shell; 22 23 import org.eclipse.jface.viewers.ILabelProvider; 24 import org.eclipse.jface.viewers.ISelectionChangedListener; 25 import org.eclipse.jface.viewers.IStructuredSelection; 26 import org.eclipse.jface.viewers.ITreeContentProvider; 27 import org.eclipse.jface.viewers.SelectionChangedEvent; 28 import org.eclipse.jface.viewers.StructuredSelection; 29 import org.eclipse.jface.viewers.TreeViewer; 30 import org.eclipse.jface.window.Window; 31 32 import org.eclipse.ui.PlatformUI; 33 import org.eclipse.ui.dialogs.ElementTreeSelectionDialog; 34 import org.eclipse.ui.dialogs.NewFolderDialog; 35 36 import org.eclipse.ui.views.navigator.ResourceComparator; 37 38 import org.eclipse.jdt.internal.ui.IJavaHelpContextIds; 39 import org.eclipse.jdt.internal.ui.wizards.NewWizardMessages; 40 41 43 public class FolderSelectionDialog extends ElementTreeSelectionDialog implements ISelectionChangedListener { 44 45 private Button fNewFolderButton; 46 private IContainer fSelectedContainer; 47 48 public FolderSelectionDialog(Shell parent, ILabelProvider labelProvider, ITreeContentProvider contentProvider) { 49 super(parent, labelProvider, contentProvider); 50 setComparator(new ResourceComparator(ResourceComparator.NAME)); 51 } 52 53 56 protected Control createDialogArea(Composite parent) { 57 Composite result= (Composite)super.createDialogArea(parent); 58 59 getTreeViewer().addSelectionChangedListener(this); 60 61 Button button = new Button(result, SWT.PUSH); 62 button.setText(NewWizardMessages.FolderSelectionDialog_button); 63 button.addSelectionListener(new SelectionAdapter() { 64 public void widgetSelected(SelectionEvent event) { 65 newFolderButtonPressed(); 66 } 67 }); 68 button.setFont(parent.getFont()); 69 fNewFolderButton= button; 70 71 applyDialogFont(result); 72 73 PlatformUI.getWorkbench().getHelpSystem().setHelp(parent, IJavaHelpContextIds.BP_SELECT_DEFAULT_OUTPUT_FOLDER_DIALOG); 74 75 return result; 76 } 77 78 private void updateNewFolderButtonState() { 79 IStructuredSelection selection= (IStructuredSelection) getTreeViewer().getSelection(); 80 fSelectedContainer= null; 81 if (selection.size() == 1) { 82 Object first= selection.getFirstElement(); 83 if (first instanceof IContainer) { 84 fSelectedContainer= (IContainer) first; 85 } 86 } 87 fNewFolderButton.setEnabled(fSelectedContainer != null); 88 } 89 90 protected void newFolderButtonPressed() { 91 NewFolderDialog dialog= new NewFolderDialog(getShell(), fSelectedContainer) { 92 protected Control createContents(Composite parent) { 93 PlatformUI.getWorkbench().getHelpSystem().setHelp(parent, IJavaHelpContextIds.BP_CREATE_NEW_FOLDER); 94 return super.createContents(parent); 95 } 96 }; 97 if (dialog.open() == Window.OK) { 98 TreeViewer treeViewer= getTreeViewer(); 99 treeViewer.refresh(fSelectedContainer); 100 Object createdFolder= dialog.getResult()[0]; 101 treeViewer.reveal(createdFolder); 102 treeViewer.setSelection(new StructuredSelection(createdFolder)); 103 } 104 } 105 106 109 public void selectionChanged(SelectionChangedEvent event) { 110 updateNewFolderButtonState(); 111 } 112 113 114 115 } 116 | Popular Tags |