1 20 21 package org.apache.directory.ldapstudio.ldifeditor.dialogs.preferences; 22 23 24 import org.apache.directory.ldapstudio.browser.common.widgets.BaseWidgetUtils; 25 import org.apache.directory.ldapstudio.browser.core.BrowserCorePlugin; 26 import org.apache.directory.ldapstudio.ldifeditor.LdifEditorActivator; 27 import org.apache.directory.ldapstudio.ldifeditor.LdifEditorConstants; 28 import org.eclipse.jface.preference.PreferencePage; 29 import org.eclipse.swt.SWT; 30 import org.eclipse.swt.events.SelectionAdapter; 31 import org.eclipse.swt.events.SelectionEvent; 32 import org.eclipse.swt.events.VerifyEvent; 33 import org.eclipse.swt.events.VerifyListener; 34 import org.eclipse.swt.layout.GridData; 35 import org.eclipse.swt.layout.GridLayout; 36 import org.eclipse.swt.widgets.Button; 37 import org.eclipse.swt.widgets.Composite; 38 import org.eclipse.swt.widgets.Control; 39 import org.eclipse.swt.widgets.Group; 40 import org.eclipse.swt.widgets.Label; 41 import org.eclipse.swt.widgets.Text; 42 import org.eclipse.ui.IWorkbench; 43 import org.eclipse.ui.IWorkbenchPreferencePage; 44 45 46 public class LdifEditorContentAssistPreferencePage extends PreferencePage implements IWorkbenchPreferencePage 47 { 48 49 private Button insertSingleProposalAutoButton; 50 51 private Button enableAutoActivationButton; 52 53 private Label autoActivationDelayLabel; 54 55 private Text autoActivationDelayText; 56 57 private Label autoActivationDelayMs; 58 59 private Button smartInsertAttributeInModspecButton; 60 61 62 public LdifEditorContentAssistPreferencePage() 63 { 64 super( "Content Assist" ); 65 super.setPreferenceStore( LdifEditorActivator.getDefault().getPreferenceStore() ); 66 } 67 68 69 public void init( IWorkbench workbench ) 70 { 71 } 72 73 74 protected Control createContents( Composite parent ) 75 { 76 77 Composite composite = new Composite( parent, SWT.NONE ); 78 GridLayout layout = new GridLayout( 1, false ); 79 layout.marginWidth = 0; 80 layout.marginHeight = 0; 81 layout.marginLeft = 0; 82 layout.marginRight = 0; 83 layout.marginTop = 0; 84 layout.marginBottom = 0; 85 composite.setLayout( layout ); 86 GridData gd = new GridData( GridData.FILL_HORIZONTAL ); 87 composite.setLayoutData( gd ); 88 89 BaseWidgetUtils.createSpacer( composite, 1 ); 90 BaseWidgetUtils.createSpacer( composite, 1 ); 91 92 Group caGroup = BaseWidgetUtils.createGroup( BaseWidgetUtils.createColumnContainer( composite, 1, 1 ), 93 "Content Assist", 1 ); 94 95 insertSingleProposalAutoButton = BaseWidgetUtils.createCheckbox( caGroup, 96 "Insert single proposal automatically", 1 ); 97 insertSingleProposalAutoButton.setSelection( getPreferenceStore().getBoolean( 98 LdifEditorConstants.PREFERENCE_LDIFEDITOR_CONTENTASSIST_INSERTSINGLEPROPOSALAUTO ) ); 99 100 enableAutoActivationButton = BaseWidgetUtils.createCheckbox( caGroup, "Enable auto activation", 1 ); 101 enableAutoActivationButton.setSelection( getPreferenceStore().getBoolean( 102 LdifEditorConstants.PREFERENCE_LDIFEDITOR_CONTENTASSIST_ENABLEAUTOACTIVATION ) ); 103 enableAutoActivationButton.addSelectionListener( new SelectionAdapter() 104 { 105 public void widgetSelected( SelectionEvent e ) 106 { 107 checkEnabled(); 108 } 109 } ); 110 111 Composite autoActivationDelayComposite = BaseWidgetUtils.createColumnContainer( caGroup, 4, 1 ); 112 BaseWidgetUtils.createRadioIndent( autoActivationDelayComposite, 1 ); 113 autoActivationDelayLabel = BaseWidgetUtils.createLabel( autoActivationDelayComposite, "Auto activation delay:", 114 1 ); 115 autoActivationDelayText = BaseWidgetUtils.createText( autoActivationDelayComposite, "", 4, 1 ); 116 autoActivationDelayText.setText( getPreferenceStore().getString( 117 LdifEditorConstants.PREFERENCE_LDIFEDITOR_CONTENTASSIST_AUTOACTIVATIONDELAY ) ); 118 autoActivationDelayText.addVerifyListener( new VerifyListener() 119 { 120 public void verifyText( VerifyEvent e ) 121 { 122 if ( !e.text.matches( "[0-9]*" ) ) 123 { 124 e.doit = false; 125 } 126 if ( "".equals( autoActivationDelayText.getText() ) && e.text.matches( "[0]" ) ) 127 { 128 e.doit = false; 129 } 130 } 131 } ); 132 autoActivationDelayMs = BaseWidgetUtils.createLabel( autoActivationDelayComposite, "ms", 1 ); 133 134 smartInsertAttributeInModspecButton = BaseWidgetUtils.createCheckbox( caGroup, 135 "Smart insert attribute name in modification items", 1 ); 136 smartInsertAttributeInModspecButton.setSelection( getPreferenceStore().getBoolean( 137 LdifEditorConstants.PREFERENCE_LDIFEDITOR_CONTENTASSIST_SMARTINSERTATTRIBUTEINMODSPEC ) ); 138 BaseWidgetUtils.createLabel( caGroup, "TODO: Smart insert must attributes", 1 ); 139 140 checkEnabled(); 141 142 return composite; 143 } 144 145 146 private void checkEnabled() 147 { 148 autoActivationDelayLabel.setEnabled( enableAutoActivationButton.getSelection() ); 149 autoActivationDelayText.setEnabled( enableAutoActivationButton.getSelection() ); 150 autoActivationDelayMs.setEnabled( enableAutoActivationButton.getSelection() ); 151 } 152 153 154 public boolean performOk() 155 { 156 157 getPreferenceStore().setValue( LdifEditorConstants.PREFERENCE_LDIFEDITOR_CONTENTASSIST_INSERTSINGLEPROPOSALAUTO, 158 this.insertSingleProposalAutoButton.getSelection() ); 159 getPreferenceStore().setValue( LdifEditorConstants.PREFERENCE_LDIFEDITOR_CONTENTASSIST_ENABLEAUTOACTIVATION, 160 this.enableAutoActivationButton.getSelection() ); 161 getPreferenceStore().setValue( LdifEditorConstants.PREFERENCE_LDIFEDITOR_CONTENTASSIST_AUTOACTIVATIONDELAY, 162 this.autoActivationDelayText.getText() ); 163 getPreferenceStore().setValue( 164 LdifEditorConstants.PREFERENCE_LDIFEDITOR_CONTENTASSIST_SMARTINSERTATTRIBUTEINMODSPEC, 165 this.smartInsertAttributeInModspecButton.getSelection() ); 166 167 BrowserCorePlugin.getDefault().savePluginPreferences(); 168 169 return true; 170 } 171 172 173 protected void performDefaults() 174 { 175 176 insertSingleProposalAutoButton.setSelection( getPreferenceStore().getDefaultBoolean( 177 LdifEditorConstants.PREFERENCE_LDIFEDITOR_CONTENTASSIST_INSERTSINGLEPROPOSALAUTO ) ); 178 enableAutoActivationButton.setSelection( getPreferenceStore().getDefaultBoolean( 179 LdifEditorConstants.PREFERENCE_LDIFEDITOR_CONTENTASSIST_ENABLEAUTOACTIVATION ) ); 180 autoActivationDelayText.setText( getPreferenceStore().getDefaultString( 181 LdifEditorConstants.PREFERENCE_LDIFEDITOR_CONTENTASSIST_AUTOACTIVATIONDELAY ) ); 182 smartInsertAttributeInModspecButton.setSelection( getPreferenceStore().getDefaultBoolean( 183 LdifEditorConstants.PREFERENCE_LDIFEDITOR_CONTENTASSIST_SMARTINSERTATTRIBUTEINMODSPEC ) ); 184 185 super.performDefaults(); 186 187 checkEnabled(); 188 } 189 190 } 191 | Popular Tags |