1 20 21 package org.apache.directory.ldapstudio.browser.ui.dialogs.properties; 22 23 24 import org.apache.directory.ldapstudio.browser.common.widgets.BaseWidgetUtils; 25 import org.apache.directory.ldapstudio.browser.common.widgets.WidgetModifyEvent; 26 import org.apache.directory.ldapstudio.browser.common.widgets.WidgetModifyListener; 27 import org.apache.directory.ldapstudio.browser.common.widgets.search.EntryWidget; 28 import org.apache.directory.ldapstudio.browser.core.model.IBookmark; 29 import org.apache.directory.ldapstudio.browser.core.utils.Utils; 30 31 import org.eclipse.core.runtime.IAdaptable; 32 import org.eclipse.swt.events.ModifyEvent; 33 import org.eclipse.swt.events.ModifyListener; 34 import org.eclipse.swt.widgets.Composite; 35 import org.eclipse.swt.widgets.Control; 36 import org.eclipse.swt.widgets.Text; 37 import org.eclipse.ui.IWorkbenchPropertyPage; 38 import org.eclipse.ui.dialogs.PropertyPage; 39 40 41 public class BookmarkPropertyPage extends PropertyPage implements IWorkbenchPropertyPage 42 { 43 44 private IBookmark bookmark; 45 46 private Text bookmarkNameText; 47 48 private EntryWidget bookmarkEntryWidget; 49 50 51 public BookmarkPropertyPage() 52 { 53 super(); 54 super.noDefaultAndApplyButton(); 55 } 56 57 58 public void dispose() 59 { 60 super.dispose(); 61 } 62 63 64 protected Control createContents( Composite parent ) 65 { 66 67 if ( getElement() instanceof IAdaptable ) 68 { 69 this.bookmark = ( IBookmark ) ( ( IAdaptable ) getElement() ).getAdapter( IBookmark.class ); 70 super.setMessage( "Bookmark " + Utils.shorten( bookmark.getName(), 30 ) ); 71 } 72 else 73 { 74 this.bookmark = null; 75 } 76 77 Composite innerComposite = BaseWidgetUtils.createColumnContainer( parent, 3, 1 ); 78 79 BaseWidgetUtils.createLabel( innerComposite, "Bookmark Name:", 1 ); 80 this.bookmarkNameText = BaseWidgetUtils.createText( innerComposite, this.bookmark != null ? this.bookmark 81 .getName() : "", 2 ); 82 this.bookmarkNameText.setFocus(); 83 this.bookmarkNameText.addModifyListener( new ModifyListener() 84 { 85 public void modifyText( ModifyEvent e ) 86 { 87 validate(); 88 } 89 } ); 90 91 BaseWidgetUtils.createLabel( innerComposite, "Bookmark DN:", 1 ); 92 this.bookmarkEntryWidget = new EntryWidget(); 93 this.bookmarkEntryWidget.createWidget( innerComposite ); 94 if ( this.bookmark != null ) 95 { 96 this.bookmarkEntryWidget.setInput( this.bookmark.getConnection(), this.bookmark.getDn() ); 97 } 98 this.bookmarkEntryWidget.addWidgetModifyListener( new WidgetModifyListener() 99 { 100 public void widgetModified( WidgetModifyEvent event ) 101 { 102 validate(); 103 } 104 } ); 105 106 return innerComposite; 107 } 108 109 110 public boolean performOk() 111 { 112 if ( this.bookmark != null ) 113 { 114 this.bookmark.setName( this.bookmarkNameText.getText() ); 115 this.bookmark.setDn( this.bookmarkEntryWidget.getDn() ); 116 this.bookmarkEntryWidget.saveDialogSettings(); 117 } 118 119 return true; 120 } 121 122 123 private void validate() 124 { 125 126 setValid( this.bookmarkEntryWidget.getDn() != null && !"".equals( this.bookmarkNameText.getText() ) ); 127 128 if ( this.bookmark != null ) 129 { 130 if ( this.bookmarkEntryWidget.getDn() == null ) 131 { 132 setValid( false ); 133 setErrorMessage( "Please enter a DN." ); 134 } 135 else if ( "".equals( this.bookmarkNameText.getText() ) ) 136 { 137 setValid( false ); 138 setErrorMessage( "Please enter a name." ); 139 } 140 else if ( !bookmark.getName().equals( this.bookmarkNameText.getText() ) 141 && bookmark.getConnection().getBookmarkManager().getBookmark( this.bookmarkNameText.getText() ) != null ) 142 { 143 setValid( false ); 144 setErrorMessage( "A bookmark with this name already exists." ); 145 } 146 else 147 { 148 setValid( true ); 149 setErrorMessage( null ); 150 } 151 } 152 else 153 { 154 setValid( false ); 155 } 156 } 157 158 } 159 | Popular Tags |