1 20 package org.apache.directory.ldapstudio.aciitemeditor.dialogs; 21 22 23 import java.text.ParseException ; 24 25 import org.apache.directory.ldapstudio.aciitemeditor.ACIItemValueWithContext; 26 import org.apache.directory.ldapstudio.aciitemeditor.Activator; 27 import org.apache.directory.ldapstudio.aciitemeditor.widgets.ACIItemTabFolderComposite; 28 import org.eclipse.core.runtime.IStatus; 29 import org.eclipse.core.runtime.Status; 30 import org.eclipse.jface.dialogs.Dialog; 31 import org.eclipse.jface.dialogs.ErrorDialog; 32 import org.eclipse.jface.dialogs.IDialogConstants; 33 import org.eclipse.jface.dialogs.MessageDialog; 34 import org.eclipse.swt.SWT; 35 import org.eclipse.swt.layout.GridData; 36 import org.eclipse.swt.widgets.Composite; 37 import org.eclipse.swt.widgets.Control; 38 import org.eclipse.swt.widgets.Shell; 39 40 41 47 public class ACIItemDialog extends Dialog 48 { 49 50 51 private ACIItemValueWithContext context; 52 53 54 private String returnValue; 55 56 57 private ACIItemTabFolderComposite tabFolderComposite; 58 59 60 66 public ACIItemDialog( Shell parentShell, ACIItemValueWithContext context ) 67 { 68 super( parentShell ); 69 super.setShellStyle( super.getShellStyle() | SWT.RESIZE ); 70 71 assert context != null; 72 assert context.getACIItemValue() != null; 73 assert context.getConnection() != null; 74 75 this.context = context; 76 77 this.returnValue = null; 78 } 79 80 81 86 protected void configureShell( Shell shell ) 87 { 88 super.configureShell( shell ); 89 shell.setText( Messages.getString( "ACIItemDialog.dialog.text" ) ); shell.setImage( Activator.getDefault().getImage( Messages.getString( "ACIItemDialog.dialog.icon" ) ) ); } 92 93 94 99 protected Control createButtonBar( Composite parent ) 100 { 101 Composite composite = ( Composite ) super.createButtonBar( parent ); 102 super.createButton( composite, 987654321, Messages.getString( "ACIItemDialog.button.format" ), false ); super.createButton( composite, 876543210, Messages.getString( "ACIItemDialog.button.checkSyntax" ), false ); return composite; 105 } 106 107 108 113 protected void buttonPressed( int buttonId ) 114 { 115 if ( buttonId == 987654321 ) 116 { 117 tabFolderComposite.format(); 118 } 119 if ( buttonId == 876543210 ) 120 { 121 try 122 { 123 tabFolderComposite.getInput(); 124 MessageDialog 125 .openInformation( 126 getShell(), 127 Messages.getString( "ACIItemDialog.syntaxOk.title" ), Messages.getString( "ACIItemDialog.syntaxOk.text" ) ); } 129 catch ( ParseException pe ) 130 { 131 IStatus status = new Status( IStatus.ERROR, Activator.PLUGIN_ID, 1, Messages 132 .getString( "ACIItemDialog.error.invalidSyntax" ), pe ); ErrorDialog.openError( getShell(), Messages.getString( "ACIItemDialog.error.title" ), null, status ); } 135 } 136 137 super.buttonPressed( buttonId ); 139 } 140 141 142 145 protected void okPressed() 146 { 147 try 148 { 149 this.returnValue = tabFolderComposite.getInput(); 150 super.okPressed(); 151 } 152 catch ( ParseException pe ) 153 { 154 IStatus status = new Status( IStatus.ERROR, Activator.PLUGIN_ID, 1, Messages 155 .getString( "ACIItemDialog.error.invalidSyntax" ), pe ); ErrorDialog.openError( getShell(), Messages.getString( "ACIItemDialog.error.title" ), null, status ); } 158 } 159 160 161 168 protected Control createDialogArea( Composite parent ) 169 { 170 Composite composite = ( Composite ) super.createDialogArea( parent ); 171 GridData gd = new GridData( GridData.FILL_BOTH ); 172 gd.widthHint = convertHorizontalDLUsToPixels( IDialogConstants.MINIMUM_MESSAGE_AREA_WIDTH ) * 4 / 3; 173 gd.heightHint = convertVerticalDLUsToPixels( IDialogConstants.MINIMUM_MESSAGE_AREA_WIDTH ) * 4 / 3; 174 composite.setLayoutData( gd ); 175 176 tabFolderComposite = new ACIItemTabFolderComposite( composite, SWT.NONE ); 177 178 if ( context != null ) 180 { 181 tabFolderComposite.setContext( context ); 182 tabFolderComposite.setInput( context.getACIItemValue() ); 183 } 184 185 applyDialogFont( composite ); 186 return composite; 187 } 188 189 190 196 public String getACIItemValue() 197 { 198 return returnValue; 199 } 200 201 } 202 | Popular Tags |