1 20 21 package org.apache.directory.ldapstudio.browser.common.widgets.connection; 22 23 24 import org.apache.directory.ldapstudio.browser.common.widgets.ViewFormWidget; 25 import org.eclipse.jface.action.IMenuManager; 26 import org.eclipse.jface.action.IToolBarManager; 27 import org.eclipse.jface.viewers.TableViewer; 28 import org.eclipse.swt.SWT; 29 import org.eclipse.swt.layout.GridData; 30 import org.eclipse.swt.widgets.Composite; 31 import org.eclipse.swt.widgets.Control; 32 import org.eclipse.swt.widgets.Table; 33 import org.eclipse.ui.IActionBars; 34 35 36 51 public class ConnectionWidget extends ViewFormWidget 52 { 53 54 55 private ConnectionConfiguration configuration; 56 57 58 private IActionBars actionBars; 59 60 61 private Table table; 62 63 64 private TableViewer viewer; 65 66 67 73 public ConnectionWidget( ConnectionConfiguration configuration, IActionBars actionBars ) 74 { 75 this.configuration = configuration; 76 this.actionBars = actionBars; 77 } 78 79 80 83 public void createWidget( Composite parent ) 84 { 85 if ( actionBars == null ) 86 { 87 super.createWidget( parent ); 88 } 89 else 90 { 91 createContent( parent ); 92 } 93 } 94 95 96 99 public IToolBarManager getToolBarManager() 100 { 101 if ( actionBars == null ) 102 { 103 return super.getToolBarManager(); 104 } 105 else 106 { 107 return actionBars.getToolBarManager(); 108 } 109 } 110 111 112 115 public IMenuManager getMenuManager() 116 { 117 if ( actionBars == null ) 118 { 119 return super.getMenuManager(); 120 121 } 122 else 123 { 124 return actionBars.getMenuManager(); 125 } 126 } 127 128 129 132 public IMenuManager getContextMenuManager() 133 { 134 if ( actionBars == null ) 135 { 136 return super.getContextMenuManager(); 137 } 138 else 139 { 140 return configuration.getContextMenuManager( viewer ); 141 } 142 } 143 144 145 148 protected Control createContent( Composite parent ) 149 { 150 151 table = new Table( parent, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER ); 152 GridData data = new GridData( GridData.FILL_BOTH ); 153 data.widthHint = 450; 154 data.heightHint = 250; 155 table.setLayoutData( data ); 156 viewer = new TableViewer( table ); 157 158 viewer.setContentProvider( configuration.getContentProvider( viewer ) ); 160 viewer.setLabelProvider( configuration.getLabelProvider( viewer ) ); 161 162 return table; 163 } 164 165 166 171 public void setInput( Object input ) 172 { 173 viewer.setInput( input ); 174 } 175 176 177 180 public void setFocus() 181 { 182 viewer.getTable().setFocus(); 183 } 184 185 186 189 public void dispose() 190 { 191 if ( viewer != null ) 192 { 193 configuration.dispose(); 194 configuration = null; 195 196 table.dispose(); 197 table = null; 198 viewer = null; 199 } 200 } 201 202 203 208 public TableViewer getViewer() 209 { 210 return viewer; 211 } 212 213 } 214 | Popular Tags |