1 20 21 package org.apache.directory.ldapstudio.browser.common.widgets.search; 22 23 24 import org.apache.directory.ldapstudio.browser.common.dialogs.SelectConnectionDialog; 25 import org.apache.directory.ldapstudio.browser.common.widgets.BaseWidgetUtils; 26 import org.apache.directory.ldapstudio.browser.common.widgets.BrowserWidget; 27 import org.apache.directory.ldapstudio.browser.core.model.IConnection; 28 import org.eclipse.swt.events.SelectionAdapter; 29 import org.eclipse.swt.events.SelectionEvent; 30 import org.eclipse.swt.widgets.Button; 31 import org.eclipse.swt.widgets.Composite; 32 import org.eclipse.swt.widgets.Text; 33 34 35 43 public class ConnectionWidget extends BrowserWidget 44 { 45 46 47 private Text connectionText; 48 49 50 private Button connectionBrowseButton; 51 52 53 private IConnection selectedConnection; 54 55 56 61 public ConnectionWidget( IConnection connection ) 62 { 63 this.selectedConnection = connection; 64 } 65 66 67 70 public ConnectionWidget() 71 { 72 this.selectedConnection = null; 73 } 74 75 76 81 public void createWidget( final Composite parent ) 82 { 83 84 connectionText = BaseWidgetUtils.createReadonlyText( parent, "", 1 ); 86 87 connectionBrowseButton = BaseWidgetUtils.createButton( parent, "B&rowse...", 1 ); 89 connectionBrowseButton.addSelectionListener( new SelectionAdapter() 90 { 91 public void widgetSelected( SelectionEvent e ) 92 { 93 SelectConnectionDialog dialog = new SelectConnectionDialog( parent.getShell(), "Select Connection", 95 selectedConnection ); 96 dialog.open(); 97 IConnection connection = dialog.getSelectedConnection(); 98 if ( connection != null ) 99 { 100 setConnection( connection ); 101 notifyListeners(); 102 } 103 } 105 } ); 106 107 setConnection( selectedConnection ); 109 110 } 111 112 113 118 public IConnection getConnection() 119 { 120 return selectedConnection; 121 } 122 123 124 129 public void setConnection( IConnection connection ) 130 { 131 selectedConnection = connection; 132 connectionText.setText( selectedConnection != null ? selectedConnection.getName() : "" ); 133 } 134 135 136 141 public void setEnabled( boolean b ) 142 { 143 connectionText.setEnabled( b ); 144 connectionBrowseButton.setEnabled( b ); 145 } 146 147 } 148 | Popular Tags |