1 20 21 package org.apache.directory.ldapstudio.browser.common.dialogs.preferences; 22 23 24 import org.apache.directory.ldapstudio.browser.common.BrowserCommonActivator; 25 import org.apache.directory.ldapstudio.browser.common.BrowserCommonConstants; 26 import org.apache.directory.ldapstudio.browser.common.widgets.BaseWidgetUtils; 27 import org.apache.directory.ldapstudio.browser.common.widgets.BinaryEncodingInput; 28 import org.apache.directory.ldapstudio.browser.common.widgets.FileEncodingInput; 29 import org.apache.directory.ldapstudio.browser.common.widgets.LineSeparatorInput; 30 import org.apache.directory.ldapstudio.browser.common.widgets.OptionsInput; 31 import org.apache.directory.ldapstudio.browser.common.widgets.WidgetModifyEvent; 32 import org.apache.directory.ldapstudio.browser.common.widgets.WidgetModifyListener; 33 import org.apache.directory.ldapstudio.browser.core.BrowserCoreConstants; 34 import org.apache.directory.ldapstudio.browser.core.BrowserCorePlugin; 35 import org.eclipse.core.runtime.Preferences; 36 import org.eclipse.jface.preference.PreferencePage; 37 import org.eclipse.swt.SWT; 38 import org.eclipse.swt.events.ModifyEvent; 39 import org.eclipse.swt.events.ModifyListener; 40 import org.eclipse.swt.events.VerifyEvent; 41 import org.eclipse.swt.events.VerifyListener; 42 import org.eclipse.swt.layout.GridLayout; 43 import org.eclipse.swt.widgets.Button; 44 import org.eclipse.swt.widgets.Composite; 45 import org.eclipse.swt.widgets.Control; 46 import org.eclipse.swt.widgets.TabFolder; 47 import org.eclipse.swt.widgets.TabItem; 48 import org.eclipse.swt.widgets.Text; 49 import org.eclipse.ui.IWorkbench; 50 import org.eclipse.ui.IWorkbenchPreferencePage; 51 52 53 public class TextFormatsPreferencePage extends PreferencePage implements IWorkbenchPreferencePage, 54 WidgetModifyListener, ModifyListener 55 { 56 57 public static final String LDIF_TAB = "LDIF"; 58 59 public static final String CSV_TAB = "CSV"; 60 61 public static final String XLS_TAB = "XLS"; 62 63 public static final String TABLE_TAB = "TABLE"; 64 65 private Preferences coreStore = BrowserCorePlugin.getDefault().getPluginPreferences(); 66 67 private TabFolder tabFolder; 68 69 private TabItem ldifTab; 70 71 private TabItem tableTab; 72 73 private TabItem csvTab; 74 75 private TabItem xlsTab; 76 77 private Text ldifLineLengthText; 78 79 private Button ldifSpaceAfterColonButton; 80 81 private LineSeparatorInput ldifLineSeparator; 82 83 85 private OptionsInput tableAttributeDelimiterWidget; 86 87 private OptionsInput tableValueDelimiterWidget; 88 89 private OptionsInput tableQuoteWidget; 90 91 private LineSeparatorInput tableLineSeparator; 92 93 private BinaryEncodingInput tableBinaryEncodingWidget; 94 95 private OptionsInput csvAttributeDelimiterWidget; 96 97 private OptionsInput csvValueDelimiterWidget; 98 99 private OptionsInput csvQuoteWidget; 100 101 private LineSeparatorInput csvLineSeparator; 102 103 private BinaryEncodingInput csvBinaryEncodingWidget; 104 105 private FileEncodingInput csvEncodingWidget; 106 107 private OptionsInput xlsValueDelimiterWidget; 108 109 private OptionsInput xlsBinaryEncodingWidget; 110 111 112 public TextFormatsPreferencePage() 113 { 114 super(); 115 super.setPreferenceStore( BrowserCommonActivator.getDefault().getPreferenceStore() ); 116 super.setDescription( "Settings for text formats" ); 117 } 118 119 120 public void init( IWorkbench workbench ) 121 { 122 } 123 124 125 public void applyData( Object data ) 126 { 127 if ( data != null && tabFolder != null ) 128 { 129 if ( LDIF_TAB.equals( data ) ) 130 { 131 tabFolder.setSelection( 0 ); 132 } 133 else if ( TABLE_TAB.equals( data ) ) 134 { 135 tabFolder.setSelection( 1 ); 136 } 137 else if ( CSV_TAB.equals( data ) ) 138 { 139 tabFolder.setSelection( 2 ); 140 } 141 else if ( XLS_TAB.equals( data ) ) 142 { 143 tabFolder.setSelection( 3 ); 144 } 145 } 146 } 147 148 149 protected Control createContents( Composite parent ) 150 { 151 BaseWidgetUtils.createSpacer( parent, 1 ); 152 tabFolder = new TabFolder( parent, SWT.TOP ); 153 154 createLdifTab(); 155 createTableTab(); 156 createCsvTab(); 157 createXlsTab(); 158 159 updateEnabled(); 160 validate(); 161 162 applyDialogFont( tabFolder ); 163 164 return tabFolder; 165 } 166 167 168 private void createTableTab() 169 { 170 171 tableTab = new TabItem( tabFolder, SWT.NONE ); 172 tableTab.setText( "CSV Copy" ); 173 174 Composite tableComposite = new Composite( tabFolder, SWT.NONE ); 175 tableComposite.setLayout( new GridLayout( 1, false ) ); 176 Composite tableInnerComposite = BaseWidgetUtils.createColumnContainer( tableComposite, 3, 1 ); 177 178 BaseWidgetUtils.createLabel( tableInnerComposite, "Select CSV copy format options:", 3 ); 179 BaseWidgetUtils.createSpacer( tableInnerComposite, 3 ); 180 181 tableAttributeDelimiterWidget = new OptionsInput( "Attribute Delimiter", "Tabulator (\\t)", "\t", new String [] 182 { "Tabulator (\\t)", "Comma (,)", "Semikolon (;)" }, new String [] 183 { "\t", ",", ";" }, getPreferenceStore().getString( 184 BrowserCommonConstants.PREFERENCE_FORMAT_TABLE_ATTRIBUTEDELIMITER ), false, true ); 185 tableAttributeDelimiterWidget.createWidget( tableInnerComposite ); 186 tableAttributeDelimiterWidget.addWidgetModifyListener( this ); 187 188 tableValueDelimiterWidget = new OptionsInput( "Value Delimiter", "Pipe (|)", "|", new String [] 189 { "Pipe (|)", "Comma (,)", "Semikolon (;)", "Newline (\\n)" }, new String [] 190 { "|", ",", ";", "\n" }, getPreferenceStore().getString( 191 BrowserCommonConstants.PREFERENCE_FORMAT_TABLE_VALUEDELIMITER ), false, true ); 192 tableValueDelimiterWidget.createWidget( tableInnerComposite ); 193 tableValueDelimiterWidget.addWidgetModifyListener( this ); 194 195 tableQuoteWidget = new OptionsInput( "Quote Character", "Double Quote (\")", "\"", new String [] 196 { "Double Quote (\")", "Single Quote (')" }, new String [] 197 { "\"", "'" }, getPreferenceStore().getString( BrowserCommonConstants.PREFERENCE_FORMAT_TABLE_QUOTECHARACTER ), 198 false, true ); 199 tableQuoteWidget.createWidget( tableInnerComposite ); 200 tableQuoteWidget.addWidgetModifyListener( this ); 201 202 tableLineSeparator = new LineSeparatorInput( getPreferenceStore().getString( 203 BrowserCommonConstants.PREFERENCE_FORMAT_TABLE_LINESEPARATOR ), false ); 204 tableLineSeparator.createWidget( tableInnerComposite ); 205 tableLineSeparator.addWidgetModifyListener( this ); 206 207 tableBinaryEncodingWidget = new BinaryEncodingInput( getPreferenceStore().getString( 208 BrowserCommonConstants.PREFERENCE_FORMAT_TABLE_BINARYENCODING ), false ); 209 tableBinaryEncodingWidget.createWidget( tableInnerComposite ); 210 tableBinaryEncodingWidget.addWidgetModifyListener( this ); 211 212 Composite copyTableHintComposite = BaseWidgetUtils.createColumnContainer( tableInnerComposite, 3, 3 ); 213 BaseWidgetUtils.createWrappedLabeledText( copyTableHintComposite, 214 "Hint: The default settings are suitable to paste the copied data into Excel or OpenOffice.", 1 ); 215 216 tableTab.setControl( tableComposite ); 217 } 218 219 220 private void createCsvTab() 221 { 222 223 csvTab = new TabItem( tabFolder, SWT.NONE ); 224 csvTab.setText( "CSV Export" ); 225 226 Composite csvComposite = new Composite( tabFolder, SWT.NONE ); 227 csvComposite.setLayout( new GridLayout( 1, false ) ); 228 Composite csvInnerComposite = BaseWidgetUtils.createColumnContainer( csvComposite, 3, 1 ); 229 230 BaseWidgetUtils.createLabel( csvInnerComposite, "Select CSV export file format options:", 3 ); 231 BaseWidgetUtils.createSpacer( csvInnerComposite, 3 ); 232 233 csvAttributeDelimiterWidget = new OptionsInput( "Attribute Delimiter", "Comma (,)", ",", new String [] 234 { "Comma (,)", "Semikolon (;)", "Tabulator (\\t)" }, new String [] 235 { ",", ";", "\t" }, coreStore.getString( BrowserCoreConstants.PREFERENCE_FORMAT_CSV_ATTRIBUTEDELIMITER ), 236 false, true ); 237 csvAttributeDelimiterWidget.createWidget( csvInnerComposite ); 238 csvAttributeDelimiterWidget.addWidgetModifyListener( this ); 239 240 csvValueDelimiterWidget = new OptionsInput( "Value Delimiter", "Pipe (|)", "|", new String [] 241 { "Pipe (|)", "Comma (,)", "Semikolon (;)", "Newline (\\n)" }, new String [] 242 { "|", ",", ";", "\n" }, coreStore.getString( BrowserCoreConstants.PREFERENCE_FORMAT_CSV_VALUEDELIMITER ), 243 false, true ); 244 csvValueDelimiterWidget.createWidget( csvInnerComposite ); 245 csvValueDelimiterWidget.addWidgetModifyListener( this ); 246 247 csvQuoteWidget = new OptionsInput( "Quote Character", "Double Quote (\")", "\"", new String [] 248 { "Double Quote (\")", "Single Quote (')" }, new String [] 249 { "\"", "'" }, coreStore.getString( BrowserCoreConstants.PREFERENCE_FORMAT_CSV_QUOTECHARACTER ), false, 250 true ); 251 csvQuoteWidget.createWidget( csvInnerComposite ); 252 csvQuoteWidget.addWidgetModifyListener( this ); 253 254 csvLineSeparator = new LineSeparatorInput( coreStore 255 .getString( BrowserCoreConstants.PREFERENCE_FORMAT_CSV_LINESEPARATOR ), false ); 256 csvLineSeparator.createWidget( csvInnerComposite ); 257 csvLineSeparator.addWidgetModifyListener( this ); 258 259 csvBinaryEncodingWidget = new BinaryEncodingInput( coreStore 260 .getString( BrowserCoreConstants.PREFERENCE_FORMAT_CSV_BINARYENCODING ), false ); 261 csvBinaryEncodingWidget.createWidget( csvInnerComposite ); 262 csvBinaryEncodingWidget.addWidgetModifyListener( this ); 263 264 csvEncodingWidget = new FileEncodingInput( coreStore 265 .getString( BrowserCoreConstants.PREFERENCE_FORMAT_CSV_ENCODING ), false ); 266 csvEncodingWidget.createWidget( csvInnerComposite ); 267 csvEncodingWidget.addWidgetModifyListener( this ); 268 269 csvTab.setControl( csvComposite ); 270 } 271 272 273 private void createXlsTab() 274 { 275 276 xlsTab = new TabItem( tabFolder, SWT.NONE ); 277 xlsTab.setText( "Excel Export" ); 278 279 Composite xlsComposite = new Composite( tabFolder, SWT.NONE ); 280 xlsComposite.setLayout( new GridLayout( 1, false ) ); 281 Composite xlsInnerComposite = BaseWidgetUtils.createColumnContainer( xlsComposite, 3, 1 ); 282 283 BaseWidgetUtils.createWrappedLabeledText( xlsInnerComposite, "Select Excel export file format options:", 3 ); 284 BaseWidgetUtils.createSpacer( xlsInnerComposite, 3 ); 285 286 xlsValueDelimiterWidget = new OptionsInput( "Value Delimiter", "Pipe (|)", "|", new String [] 287 { "Pipe (|)", "Comma (,)", "Semikolon (;)", "Newline (\\n)" }, new String [] 288 { "|", ",", ";", "\n" }, coreStore.getString( BrowserCoreConstants.PREFERENCE_FORMAT_XLS_VALUEDELIMITER ), 289 false, true ); 290 xlsValueDelimiterWidget.createWidget( xlsInnerComposite ); 291 xlsValueDelimiterWidget.addWidgetModifyListener( this ); 292 293 xlsBinaryEncodingWidget = new BinaryEncodingInput( coreStore 294 .getString( BrowserCoreConstants.PREFERENCE_FORMAT_XLS_BINARYENCODING ), false ); 295 xlsBinaryEncodingWidget.createWidget( xlsInnerComposite ); 296 xlsBinaryEncodingWidget.addWidgetModifyListener( this ); 297 298 xlsTab.setControl( xlsComposite ); 299 } 300 301 302 private void createLdifTab() 303 { 304 305 ldifTab = new TabItem( tabFolder, SWT.NONE ); 306 ldifTab.setText( "LDIF" ); 307 308 Composite ldifComposite = new Composite( tabFolder, SWT.NONE ); 309 ldifComposite.setLayout( new GridLayout( 1, false ) ); 310 Composite ldifInnerComposite = BaseWidgetUtils.createColumnContainer( ldifComposite, 1, 1 ); 311 312 BaseWidgetUtils.createLabel( ldifInnerComposite, "Select LDIF format options:", 1 ); 313 BaseWidgetUtils.createSpacer( ldifInnerComposite, 1 ); 314 315 ldifLineSeparator = new LineSeparatorInput( coreStore 316 .getString( BrowserCoreConstants.PREFERENCE_LDIF_LINE_SEPARATOR ), true ); 317 ldifLineSeparator.createWidget( ldifInnerComposite ); 318 ldifLineSeparator.addWidgetModifyListener( this ); 319 320 BaseWidgetUtils.createSpacer( ldifInnerComposite, 1 ); 321 322 Composite lineLengthComposite = BaseWidgetUtils.createColumnContainer( ldifInnerComposite, 3, 1 ); 323 BaseWidgetUtils.createLabel( lineLengthComposite, "Line length:", 1 ); 324 ldifLineLengthText = BaseWidgetUtils.createText( lineLengthComposite, "", 3, 1 ); 325 ldifLineLengthText.setText( coreStore.getString( BrowserCoreConstants.PREFERENCE_LDIF_LINE_WIDTH ) ); 326 ldifLineLengthText.addVerifyListener( new VerifyListener() 327 { 328 public void verifyText( VerifyEvent e ) 329 { 330 if ( !e.text.matches( "[0-9]*" ) ) 331 { 332 e.doit = false; 333 } 334 if ( "".equals( ldifLineLengthText.getText() ) && e.text.matches( "[0]" ) ) 335 { 336 e.doit = false; 337 } 338 } 339 } ); 340 ldifLineLengthText.addModifyListener( this ); 341 BaseWidgetUtils.createLabel( lineLengthComposite, "characters", 1 ); 342 343 ldifSpaceAfterColonButton = BaseWidgetUtils.createCheckbox( ldifInnerComposite, "Space after colon", 1 ); 344 ldifSpaceAfterColonButton.setSelection( coreStore 345 .getBoolean( BrowserCoreConstants.PREFERENCE_LDIF_SPACE_AFTER_COLON ) ); 346 347 352 ldifTab.setControl( ldifComposite ); 353 } 354 355 356 private void updateEnabled() 357 { 358 359 } 360 361 362 public boolean performOk() 363 { 364 365 coreStore.setValue( BrowserCoreConstants.PREFERENCE_LDIF_LINE_WIDTH, this.ldifLineLengthText.getText() ); 366 coreStore.setValue( BrowserCoreConstants.PREFERENCE_LDIF_LINE_SEPARATOR, this.ldifLineSeparator.getRawValue() ); 367 coreStore.setValue( BrowserCoreConstants.PREFERENCE_LDIF_SPACE_AFTER_COLON, this.ldifSpaceAfterColonButton 368 .getSelection() ); 369 BrowserCorePlugin.getDefault().savePluginPreferences(); 372 373 coreStore.setValue( BrowserCoreConstants.PREFERENCE_FORMAT_CSV_ATTRIBUTEDELIMITER, 374 this.csvAttributeDelimiterWidget.getRawValue() ); 375 coreStore.setValue( BrowserCoreConstants.PREFERENCE_FORMAT_CSV_VALUEDELIMITER, this.csvValueDelimiterWidget 376 .getRawValue() ); 377 coreStore.setValue( BrowserCoreConstants.PREFERENCE_FORMAT_CSV_QUOTECHARACTER, this.csvQuoteWidget 378 .getRawValue() ); 379 coreStore.setValue( BrowserCoreConstants.PREFERENCE_FORMAT_CSV_LINESEPARATOR, this.csvLineSeparator 380 .getRawValue() ); 381 coreStore.setValue( BrowserCoreConstants.PREFERENCE_FORMAT_CSV_BINARYENCODING, this.csvBinaryEncodingWidget 382 .getRawValue() ); 383 coreStore.setValue( BrowserCoreConstants.PREFERENCE_FORMAT_CSV_ENCODING, this.csvEncodingWidget.getRawValue() ); 384 385 getPreferenceStore().setValue( BrowserCommonConstants.PREFERENCE_FORMAT_TABLE_ATTRIBUTEDELIMITER, 386 this.tableAttributeDelimiterWidget.getRawValue() ); 387 getPreferenceStore().setValue( BrowserCommonConstants.PREFERENCE_FORMAT_TABLE_VALUEDELIMITER, 388 this.tableValueDelimiterWidget.getRawValue() ); 389 getPreferenceStore().setValue( BrowserCommonConstants.PREFERENCE_FORMAT_TABLE_QUOTECHARACTER, 390 this.tableQuoteWidget.getRawValue() ); 391 getPreferenceStore().setValue( BrowserCommonConstants.PREFERENCE_FORMAT_TABLE_LINESEPARATOR, 392 this.tableLineSeparator.getRawValue() ); 393 getPreferenceStore().setValue( BrowserCommonConstants.PREFERENCE_FORMAT_TABLE_BINARYENCODING, 394 this.tableBinaryEncodingWidget.getRawValue() ); 395 396 coreStore.setValue( BrowserCoreConstants.PREFERENCE_FORMAT_XLS_VALUEDELIMITER, this.xlsValueDelimiterWidget 397 .getRawValue() ); 398 coreStore.setValue( BrowserCoreConstants.PREFERENCE_FORMAT_XLS_BINARYENCODING, this.xlsBinaryEncodingWidget 399 .getRawValue() ); 400 401 updateEnabled(); 402 validate(); 403 404 return true; 405 } 406 407 408 protected void performDefaults() 409 { 410 411 this.ldifLineLengthText.setText( coreStore.getDefaultString( BrowserCoreConstants.PREFERENCE_LDIF_LINE_WIDTH ) ); 412 this.ldifLineSeparator.setRawValue( coreStore 413 .getDefaultString( BrowserCoreConstants.PREFERENCE_LDIF_LINE_SEPARATOR ) ); 414 this.ldifSpaceAfterColonButton.setSelection( coreStore 415 .getDefaultBoolean( BrowserCoreConstants.PREFERENCE_LDIF_SPACE_AFTER_COLON ) ); 416 418 this.csvAttributeDelimiterWidget.setRawValue( coreStore 419 .getDefaultString( BrowserCoreConstants.PREFERENCE_FORMAT_CSV_ATTRIBUTEDELIMITER ) ); 420 this.csvValueDelimiterWidget.setRawValue( coreStore 421 .getDefaultString( BrowserCoreConstants.PREFERENCE_FORMAT_CSV_VALUEDELIMITER ) ); 422 this.csvQuoteWidget.setRawValue( coreStore 423 .getDefaultString( BrowserCoreConstants.PREFERENCE_FORMAT_CSV_QUOTECHARACTER ) ); 424 this.csvLineSeparator.setRawValue( coreStore 425 .getDefaultString( BrowserCoreConstants.PREFERENCE_FORMAT_CSV_LINESEPARATOR ) ); 426 this.csvBinaryEncodingWidget.setRawValue( coreStore 427 .getDefaultString( BrowserCoreConstants.PREFERENCE_FORMAT_CSV_BINARYENCODING ) ); 428 this.csvEncodingWidget.setRawValue( coreStore 429 .getDefaultString( BrowserCoreConstants.PREFERENCE_FORMAT_CSV_ENCODING ) ); 430 431 this.tableAttributeDelimiterWidget.setRawValue( getPreferenceStore().getDefaultString( 432 BrowserCommonConstants.PREFERENCE_FORMAT_TABLE_ATTRIBUTEDELIMITER ) ); 433 this.tableValueDelimiterWidget.setRawValue( getPreferenceStore().getDefaultString( 434 BrowserCommonConstants.PREFERENCE_FORMAT_TABLE_VALUEDELIMITER ) ); 435 this.tableQuoteWidget.setRawValue( getPreferenceStore().getDefaultString( 436 BrowserCommonConstants.PREFERENCE_FORMAT_TABLE_QUOTECHARACTER ) ); 437 this.tableLineSeparator.setRawValue( getPreferenceStore().getDefaultString( 438 BrowserCommonConstants.PREFERENCE_FORMAT_TABLE_LINESEPARATOR ) ); 439 this.tableBinaryEncodingWidget.setRawValue( getPreferenceStore().getDefaultString( 440 BrowserCommonConstants.PREFERENCE_FORMAT_TABLE_BINARYENCODING ) ); 441 442 this.xlsValueDelimiterWidget.setRawValue( coreStore 443 .getDefaultString( BrowserCoreConstants.PREFERENCE_FORMAT_XLS_VALUEDELIMITER ) ); 444 this.xlsBinaryEncodingWidget.setRawValue( coreStore 445 .getDefaultString( BrowserCoreConstants.PREFERENCE_FORMAT_XLS_BINARYENCODING ) ); 446 447 updateEnabled(); 448 validate(); 449 450 super.performDefaults(); 451 } 452 453 454 public void widgetModified( WidgetModifyEvent event ) 455 { 456 updateEnabled(); 457 validate(); 458 } 459 460 461 public void modifyText( ModifyEvent e ) 462 { 463 updateEnabled(); 464 validate(); 465 } 466 467 468 protected void validate() 469 { 470 setValid( !"".equals( csvAttributeDelimiterWidget.getRawValue() ) 471 && !"".equals( csvValueDelimiterWidget.getRawValue() ) && !"".equals( csvQuoteWidget.getRawValue() ) 472 && !"".equals( csvLineSeparator.getRawValue() ) && !"".equals( csvBinaryEncodingWidget.getRawValue() ) 473 && !"".equals( csvEncodingWidget.getRawValue() ) && 474 475 !"".equals( tableAttributeDelimiterWidget.getRawValue() ) 476 && !"".equals( tableValueDelimiterWidget.getRawValue() ) && !"".equals( tableQuoteWidget.getRawValue() ) 477 && !"".equals( tableLineSeparator.getRawValue() ) && !"".equals( tableBinaryEncodingWidget.getRawValue() ) 478 && 479 480 !"".equals( xlsValueDelimiterWidget.getRawValue() ) && !"".equals( xlsBinaryEncodingWidget.getRawValue() ) 481 && 482 483 !"".equals( ldifLineLengthText.getText() ) && !"".equals( ldifLineSeparator.getRawValue() ) ); 484 } 485 486 } 487 | Popular Tags |