1 13 14 package org.eclipse.ui.dialogs; 15 16 import java.util.ArrayList ; 17 import java.util.List ; 18 19 import org.eclipse.core.resources.IContainer; 20 import org.eclipse.core.runtime.IPath; 21 import org.eclipse.swt.SWT; 22 import org.eclipse.swt.layout.GridData; 23 import org.eclipse.swt.widgets.Composite; 24 import org.eclipse.swt.widgets.Control; 25 import org.eclipse.swt.widgets.Event; 26 import org.eclipse.swt.widgets.Label; 27 import org.eclipse.swt.widgets.Listener; 28 import org.eclipse.swt.widgets.Shell; 29 import org.eclipse.ui.PlatformUI; 30 import org.eclipse.ui.internal.ide.IDEWorkbenchMessages; 31 import org.eclipse.ui.internal.ide.IIDEHelpContextIds; 32 import org.eclipse.ui.internal.ide.misc.ContainerSelectionGroup; 33 34 50 public class ContainerSelectionDialog extends SelectionDialog { 51 54 private static final String EMPTY_STRING = ""; 56 ContainerSelectionGroup group; 58 59 private IContainer initialSelection; 61 62 private boolean allowNewContainerName = true; 64 65 Label statusMessage; 67 68 ISelectionValidator validator; 70 71 private boolean showClosedProjects = true; 73 74 86 public ContainerSelectionDialog(Shell parentShell, IContainer initialRoot, 87 boolean allowNewContainerName, String message) { 88 super(parentShell); 89 setTitle(IDEWorkbenchMessages.ContainerSelectionDialog_title); 90 this.initialSelection = initialRoot; 91 this.allowNewContainerName = allowNewContainerName; 92 if (message != null) { 93 setMessage(message); 94 } else { 95 setMessage(IDEWorkbenchMessages.ContainerSelectionDialog_message); 96 } 97 setShellStyle(getShellStyle() | SWT.RESIZE); 98 } 99 100 103 protected void configureShell(Shell shell) { 104 super.configureShell(shell); 105 PlatformUI.getWorkbench().getHelpSystem() 106 .setHelp(shell, IIDEHelpContextIds.CONTAINER_SELECTION_DIALOG); 107 } 108 109 112 protected Control createDialogArea(Composite parent) { 113 Composite area = (Composite) super.createDialogArea(parent); 115 116 Listener listener = new Listener() { 117 public void handleEvent(Event event) { 118 if (statusMessage != null && validator != null) { 119 String errorMsg = validator.isValid(group 120 .getContainerFullPath()); 121 if (errorMsg == null || errorMsg.equals(EMPTY_STRING)) { 122 statusMessage.setText(EMPTY_STRING); 123 getOkButton().setEnabled(true); 124 } else { 125 statusMessage.setText(errorMsg); 126 getOkButton().setEnabled(false); 127 } 128 } 129 } 130 }; 131 132 group = new ContainerSelectionGroup(area, listener, 134 allowNewContainerName, getMessage(), showClosedProjects); 135 if (initialSelection != null) { 136 group.setSelectedContainer(initialSelection); 137 } 138 139 statusMessage = new Label(area, SWT.WRAP); 140 statusMessage.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); 141 statusMessage.setText(" \n "); statusMessage.setFont(parent.getFont()); 143 144 return dialogArea; 145 } 146 147 152 protected void okPressed() { 153 154 List chosenContainerPathList = new ArrayList (); 155 IPath returnValue = group.getContainerFullPath(); 156 if (returnValue != null) { 157 chosenContainerPathList.add(returnValue); 158 } 159 setResult(chosenContainerPathList); 160 super.okPressed(); 161 } 162 163 168 public void setValidator(ISelectionValidator validator) { 169 this.validator = validator; 170 } 171 172 178 public void showClosedProjects(boolean show) { 179 this.showClosedProjects = show; 180 } 181 } 182 | Popular Tags |