1 11 package org.eclipse.ui.dialogs; 12 13 import java.util.Arrays ; 14 import java.util.List ; 15 16 import org.eclipse.core.resources.IContainer; 17 import org.eclipse.core.runtime.IPath; 18 import org.eclipse.core.runtime.Path; 19 import org.eclipse.jface.dialogs.IDialogConstants; 20 import org.eclipse.jface.dialogs.MessageDialog; 21 import org.eclipse.jface.resource.JFaceResources; 22 import org.eclipse.jface.wizard.WizardPage; 23 import org.eclipse.osgi.util.NLS; 24 import org.eclipse.swt.SWT; 25 import org.eclipse.swt.graphics.Image; 26 import org.eclipse.swt.layout.GridData; 27 import org.eclipse.swt.layout.GridLayout; 28 import org.eclipse.swt.widgets.Composite; 29 import org.eclipse.swt.widgets.Group; 30 import org.eclipse.swt.widgets.Label; 31 import org.eclipse.swt.widgets.Listener; 32 import org.eclipse.swt.widgets.Text; 33 import org.eclipse.ui.internal.ide.IDEWorkbenchMessages; 34 35 41 public abstract class WizardDataTransferPage extends WizardPage implements 42 Listener, IOverwriteQuery { 43 44 protected static final int SIZING_TEXT_FIELD_WIDTH = 250; 46 47 protected static final int COMBO_HISTORY_LENGTH = 5; 48 49 54 protected WizardDataTransferPage(String pageName) { 55 super(pageName); 56 } 57 58 66 protected String [] addToHistory(String [] history, String newEntry) { 67 java.util.ArrayList l = new java.util.ArrayList (Arrays.asList(history)); 68 addToHistory(l, newEntry); 69 String [] r = new String [l.size()]; 70 l.toArray(r); 71 return r; 72 } 73 74 82 protected void addToHistory(List history, String newEntry) { 83 history.remove(newEntry); 84 history.add(0, newEntry); 85 86 if (history.size() > COMBO_HISTORY_LENGTH) { 89 history.remove(COMBO_HISTORY_LENGTH); 90 } 91 } 92 93 103 protected abstract boolean allowNewContainerName(); 104 105 112 protected Label createBoldLabel(Composite parent, String text) { 113 Label label = new Label(parent, SWT.NONE); 114 label.setFont(JFaceResources.getBannerFont()); 115 label.setText(text); 116 GridData data = new GridData(); 117 data.verticalAlignment = GridData.FILL; 118 data.horizontalAlignment = GridData.FILL; 119 label.setLayoutData(data); 120 return label; 121 } 122 123 133 protected void createOptionsGroupButtons(Group optionsGroup) { 134 } 135 136 143 protected Label createPlainLabel(Composite parent, String text) { 144 Label label = new Label(parent, SWT.NONE); 145 label.setText(text); 146 label.setFont(parent.getFont()); 147 GridData data = new GridData(); 148 data.verticalAlignment = GridData.FILL; 149 data.horizontalAlignment = GridData.FILL; 150 label.setLayoutData(data); 151 return label; 152 } 153 154 159 protected void createSpacer(Composite parent) { 160 Label spacer = new Label(parent, SWT.NONE); 161 GridData data = new GridData(); 162 data.horizontalAlignment = GridData.FILL; 163 data.verticalAlignment = GridData.BEGINNING; 164 spacer.setLayoutData(data); 165 } 166 167 178 protected boolean determinePageCompletion() { 179 boolean complete = validateSourceGroup() && validateDestinationGroup() 180 && validateOptionsGroup(); 181 182 if (complete) { 185 setErrorMessage(null); 186 } 187 188 return complete; 189 } 190 191 195 protected IPath getPathFromText(Text textField) { 196 String text = textField.getText(); 197 if (text.length() == 0) { 199 return new Path(text); 200 } 201 202 return (new Path(text)).makeAbsolute(); 203 } 204 205 211 protected IPath queryForContainer(IContainer initialSelection, String msg) { 212 return queryForContainer(initialSelection, msg, null); 213 } 214 215 221 protected IPath queryForContainer(IContainer initialSelection, String msg, 222 String title) { 223 ContainerSelectionDialog dialog = new ContainerSelectionDialog( 224 getControl().getShell(), initialSelection, 225 allowNewContainerName(), msg); 226 if (title != null) { 227 dialog.setTitle(title); 228 } 229 dialog.showClosedProjects(false); 230 dialog.open(); 231 Object [] result = dialog.getResult(); 232 if (result != null && result.length == 1) { 233 return (IPath) result[0]; 234 } 235 return null; 236 } 237 238 247 public String queryOverwrite(String pathString) { 248 249 Path path = new Path(pathString); 250 251 String messageString; 252 if (path.getFileExtension() == null || path.segmentCount() < 2) { 255 messageString = NLS.bind(IDEWorkbenchMessages.WizardDataTransfer_existsQuestion, pathString); 256 } else { 257 messageString = NLS.bind(IDEWorkbenchMessages.WizardDataTransfer_overwriteNameAndPathQuestion, path.lastSegment(), 258 path.removeLastSegments(1).toOSString()); 259 } 260 261 final MessageDialog dialog = new MessageDialog(getContainer() 262 .getShell(), IDEWorkbenchMessages.Question, 263 null, messageString, MessageDialog.QUESTION, new String [] { 264 IDialogConstants.YES_LABEL, 265 IDialogConstants.YES_TO_ALL_LABEL, 266 IDialogConstants.NO_LABEL, 267 IDialogConstants.NO_TO_ALL_LABEL, 268 IDialogConstants.CANCEL_LABEL }, 0); 269 String [] response = new String [] { YES, ALL, NO, NO_ALL, CANCEL }; 270 getControl().getDisplay().syncExec(new Runnable () { 273 public void run() { 274 dialog.open(); 275 } 276 }); 277 return dialog.getReturnCode() < 0 ? CANCEL : response[dialog 278 .getReturnCode()]; 279 } 280 281 288 protected boolean queryYesNoQuestion(String message) { 289 MessageDialog dialog = new MessageDialog(getContainer().getShell(), 290 IDEWorkbenchMessages.Question, 291 (Image) null, message, MessageDialog.NONE, 292 new String [] { IDialogConstants.YES_LABEL, 293 IDialogConstants.NO_LABEL }, 0); 294 296 return dialog.open() == 0; 297 } 298 299 307 protected void restoreWidgetValues() { 308 } 309 310 318 protected void saveWidgetValues() { 319 } 320 321 324 protected void updatePageCompletion() { 325 boolean pageComplete = determinePageCompletion(); 326 setPageComplete(pageComplete); 327 if (pageComplete) { 328 setErrorMessage(null); 329 } 330 } 331 332 339 protected void updateWidgetEnablements() { 340 } 341 342 353 protected boolean validateDestinationGroup() { 354 return true; 355 } 356 357 368 protected boolean validateOptionsGroup() { 369 return true; 370 } 371 372 383 protected boolean validateSourceGroup() { 384 return true; 385 } 386 387 392 protected void createOptionsGroup(Composite parent) { 393 Group optionsGroup = new Group(parent, SWT.NONE); 395 GridLayout layout = new GridLayout(); 396 optionsGroup.setLayout(layout); 397 optionsGroup.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_FILL 398 | GridData.GRAB_HORIZONTAL)); 399 optionsGroup.setText(IDEWorkbenchMessages.WizardExportPage_options); 400 optionsGroup.setFont(parent.getFont()); 401 402 createOptionsGroupButtons(optionsGroup); 403 404 } 405 406 411 protected void displayErrorDialog(String message) { 412 MessageDialog.openError(getContainer().getShell(), 413 getErrorDialogTitle(), message); 414 } 415 416 421 protected void displayErrorDialog(Throwable exception) { 422 String message = exception.getMessage(); 423 if (message == null) { 425 message = NLS.bind(IDEWorkbenchMessages.WizardDataTransfer_exceptionMessage, exception); 426 } 427 displayErrorDialog(message); 428 } 429 430 434 protected String getErrorDialogTitle() { 435 return IDEWorkbenchMessages.WizardExportPage_internalErrorTitle; 436 } 437 438 } 439 | Popular Tags |