1 20 21 package org.apache.directory.ldapstudio.browser.common.widgets.entryeditor; 22 23 24 import org.apache.directory.ldapstudio.browser.common.widgets.ViewFormWidget; 25 import org.eclipse.jface.viewers.CellEditor; 26 import org.eclipse.jface.viewers.TreeViewer; 27 import org.eclipse.swt.SWT; 28 import org.eclipse.swt.events.ControlAdapter; 29 import org.eclipse.swt.events.ControlEvent; 30 import org.eclipse.swt.layout.GridData; 31 import org.eclipse.swt.widgets.Composite; 32 import org.eclipse.swt.widgets.Control; 33 import org.eclipse.swt.widgets.Tree; 34 import org.eclipse.swt.widgets.TreeColumn; 35 36 37 52 public class EntryEditorWidget extends ViewFormWidget 53 { 54 55 56 private EntryEditorWidgetConfiguration configuration; 57 58 59 private EntryEditorWidgetQuickFilterWidget quickFilterWidget; 60 61 62 private Tree tree; 63 64 65 private TreeViewer viewer; 66 67 68 73 public EntryEditorWidget( EntryEditorWidgetConfiguration configuration ) 74 { 75 this.configuration = configuration; 76 } 77 78 79 82 protected Control createContent( Composite parent ) 83 { 84 quickFilterWidget = new EntryEditorWidgetQuickFilterWidget( configuration.getFilter(), this ); 85 quickFilterWidget.createComposite( parent ); 86 87 tree = new Tree( parent, SWT.MULTI | SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL | SWT.FULL_SELECTION 89 | SWT.HIDE_SELECTION ); 90 GridData data = new GridData( GridData.FILL_BOTH ); 91 data.widthHint = 450; 92 data.heightHint = 250; 93 tree.setLayoutData( data ); 94 tree.setHeaderVisible( true ); 95 tree.setLinesVisible( true ); 96 viewer = new TreeViewer( tree ); 97 viewer.setUseHashlookup( true ); 98 99 for ( int i = 0; i < EntryEditorWidgetTableMetadata.COLUM_NAMES.length; i++ ) 101 { 102 TreeColumn column = new TreeColumn( tree, SWT.LEFT, i ); 103 column.setText( EntryEditorWidgetTableMetadata.COLUM_NAMES[i] ); 104 column.setWidth( 200 ); 105 column.setResizable( true ); 106 107 } 108 viewer.setColumnProperties( EntryEditorWidgetTableMetadata.COLUM_NAMES ); 109 tree.addControlListener( new ControlAdapter() 110 { 111 public void controlResized( ControlEvent e ) 112 { 113 if ( tree.getClientArea().width > 0 ) 114 { 115 int width = tree.getClientArea().width - 2 * tree.getBorderWidth(); 116 if ( tree.getVerticalBar().isVisible() ) 117 { 118 width -= tree.getVerticalBar().getSize().x; 119 } 120 tree.getColumn( EntryEditorWidgetTableMetadata.VALUE_COLUMN_INDEX ).setWidth( 121 width - tree.getColumn( EntryEditorWidgetTableMetadata.KEY_COLUMN_INDEX ).getWidth() ); 122 } 123 } 124 } ); 125 126 configuration.getSorter().connect( viewer ); 128 configuration.getFilter().connect( viewer ); 129 configuration.getPreferences().connect( viewer ); 130 131 viewer.setContentProvider( configuration.getContentProvider( this ) ); 133 viewer.setLabelProvider( configuration.getLabelProvider( viewer ) ); 134 135 viewer.setCellModifier( configuration.getCellModifier( viewer ) ); 137 CellEditor[] editors = new CellEditor[EntryEditorWidgetTableMetadata.COLUM_NAMES.length]; 138 viewer.setCellEditors( editors ); 139 140 return tree; 141 142 } 143 144 145 148 public void setFocus() 149 { 150 viewer.getTree().setFocus(); 151 } 152 153 154 157 public void dispose() 158 { 159 if ( viewer != null ) 160 { 161 configuration.dispose(); 162 configuration = null; 163 164 if ( quickFilterWidget != null ) 165 { 166 quickFilterWidget.dispose(); 167 quickFilterWidget = null; 168 } 169 170 tree.dispose(); 171 tree = null; 172 viewer = null; 173 } 174 175 super.dispose(); 176 } 177 178 179 184 public TreeViewer getViewer() 185 { 186 return viewer; 187 } 188 189 190 195 public EntryEditorWidgetQuickFilterWidget getQuickFilterWidget() 196 { 197 return quickFilterWidget; 198 } 199 200 201 206 public void setEnabled( boolean enabled ) 207 { 208 tree.setEnabled( enabled ); 209 } 210 211 } 212 | Popular Tags |