1 20 21 package org.apache.directory.ldapstudio.valueeditors.address; 22 23 24 import org.apache.directory.ldapstudio.browser.core.BrowserCoreConstants; 25 import org.apache.directory.ldapstudio.valueeditors.ValueEditorsActivator; 26 import org.apache.directory.ldapstudio.valueeditors.ValueEditorsConstants; 27 import org.eclipse.jface.dialogs.Dialog; 28 import org.eclipse.jface.dialogs.IDialogConstants; 29 import org.eclipse.swt.SWT; 30 import org.eclipse.swt.layout.GridData; 31 import org.eclipse.swt.widgets.Composite; 32 import org.eclipse.swt.widgets.Control; 33 import org.eclipse.swt.widgets.Shell; 34 import org.eclipse.swt.widgets.Text; 35 36 37 public class AddressDialog extends Dialog 38 { 39 40 public static final String DIALOG_TITLE = "Address Editor"; 41 42 public static final double MAX_WIDTH = 250.0; 43 44 public static final double MAX_HEIGHT = 250.0; 45 46 private String initialValue; 47 48 private String returnValue; 49 50 private Text text; 51 52 53 public AddressDialog( Shell parentShell, String initialValue ) 54 { 55 super( parentShell ); 56 super.setShellStyle( super.getShellStyle() | SWT.RESIZE ); 57 this.initialValue = initialValue; 58 this.returnValue = null; 59 } 60 61 62 public boolean close() 63 { 64 return super.close(); 65 } 66 67 68 protected void configureShell( Shell shell ) 69 { 70 super.configureShell( shell ); 71 shell.setText( DIALOG_TITLE ); 72 shell.setImage( ValueEditorsActivator.getDefault().getImage( ValueEditorsConstants.IMG_ADDRESSEDITOR ) ); 73 } 74 75 76 protected void createButtonsForButtonBar( Composite parent ) 77 { 78 createButton( parent, IDialogConstants.OK_ID, IDialogConstants.OK_LABEL, false ); 79 createButton( parent, IDialogConstants.CANCEL_ID, IDialogConstants.CANCEL_LABEL, false ); 80 } 81 82 83 protected void okPressed() 84 { 85 this.returnValue = this.text.getText(); 86 this.returnValue = this.returnValue.replaceAll( "\n", "\\$" ); 87 this.returnValue = this.returnValue.replaceAll( "\r", "\\$" ); 88 this.returnValue = this.returnValue.replaceAll( "\\$\\$", "\\$" ); 89 super.okPressed(); 90 } 91 92 93 protected Control createDialogArea( Composite parent ) 94 { 95 Composite composite = ( Composite ) super.createDialogArea( parent ); 97 GridData gd = new GridData( GridData.FILL_BOTH ); 98 composite.setLayoutData( gd ); 99 100 text = new Text( composite, SWT.MULTI | SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL ); 102 text.setText( this.initialValue.replaceAll( "\\$", BrowserCoreConstants.LINE_SEPARATOR ) ); 103 gd = new GridData( GridData.FILL_BOTH ); 106 gd.widthHint = convertHorizontalDLUsToPixels( IDialogConstants.MINIMUM_MESSAGE_AREA_WIDTH ); 107 gd.heightHint = convertHorizontalDLUsToPixels( IDialogConstants.MINIMUM_MESSAGE_AREA_WIDTH / 2 ); 108 text.setLayoutData( gd ); 109 110 applyDialogFont( composite ); 111 return composite; 112 } 113 114 115 public String getText() 116 { 117 return this.returnValue; 118 } 119 120 } 121 | Popular Tags |