1 20 package org.apache.directory.ldapstudio.aciitemeditor.widgets; 21 22 23 import java.text.ParseException ; 24 25 import org.apache.directory.ldapstudio.aciitemeditor.ACIItemValueWithContext; 26 import org.apache.directory.ldapstudio.aciitemeditor.Activator; 27 import org.eclipse.core.runtime.IStatus; 28 import org.eclipse.core.runtime.Status; 29 import org.eclipse.jface.dialogs.ErrorDialog; 30 import org.eclipse.swt.SWT; 31 import org.eclipse.swt.events.SelectionAdapter; 32 import org.eclipse.swt.events.SelectionEvent; 33 import org.eclipse.swt.layout.FillLayout; 34 import org.eclipse.swt.layout.GridData; 35 import org.eclipse.swt.layout.GridLayout; 36 import org.eclipse.swt.widgets.Composite; 37 import org.eclipse.swt.widgets.TabFolder; 38 import org.eclipse.swt.widgets.TabItem; 39 40 41 49 public class ACIItemTabFolderComposite extends Composite 50 { 51 52 53 public static final int VISUAL_TAB_INDEX = 0; 54 55 56 public static final int SOURCE_TAB_INDEX = 1; 57 58 59 private TabFolder tabFolder; 60 61 62 private TabItem visualTab; 63 64 65 private Composite visualContainer; 66 67 68 private ACIItemVisualEditorComposite visualComposite; 69 70 71 private TabItem sourceTab; 72 73 74 private Composite sourceContainer; 75 76 77 private ACIItemSourceEditorComposite sourceComposite; 78 79 80 86 public ACIItemTabFolderComposite( Composite parent, int style ) 87 { 88 super( parent, style ); 89 setLayoutData( new GridData( GridData.FILL_BOTH ) ); 90 GridLayout layout = new GridLayout( 1, false ); 91 layout.marginWidth = 0; 92 layout.marginHeight = 0; 93 setLayout( layout ); 94 95 createTabFolder(); 96 97 createVisualTab(); 98 99 createSourceTab(); 100 101 initListeners(); 102 } 103 104 105 109 private void initListeners() 110 { 111 tabFolder.addSelectionListener( new SelectionAdapter() 112 { 113 public void widgetSelected( SelectionEvent e ) 114 { 115 tabSelected(); 116 } 117 } ); 118 } 119 120 121 125 private void createSourceTab() 126 { 127 sourceContainer = new Composite( tabFolder, SWT.BORDER ); 129 sourceContainer.setLayout( new FillLayout() ); 130 131 sourceComposite = new ACIItemSourceEditorComposite( sourceContainer, SWT.NONE ); 133 134 sourceTab = new TabItem( tabFolder, SWT.NONE, SOURCE_TAB_INDEX ); 136 sourceTab.setText( Messages.getString( "ACIItemTabFolderComposite.source.tab" ) ); sourceTab.setControl( sourceContainer ); 138 } 139 140 141 145 private void createVisualTab() 146 { 147 visualContainer = new Composite( tabFolder, SWT.NONE ); 149 visualContainer.setLayout( new FillLayout() ); 150 151 visualComposite = new ACIItemVisualEditorComposite( visualContainer, SWT.NONE ); 153 154 visualTab = new TabItem( tabFolder, SWT.NONE, VISUAL_TAB_INDEX ); 156 visualTab.setText( Messages.getString( "ACIItemTabFolderComposite.visual.tab" ) ); visualTab.setControl( visualContainer ); 158 } 159 160 161 165 private void createTabFolder() 166 { 167 tabFolder = new TabFolder( this, SWT.TOP ); 168 GridLayout mainLayout = new GridLayout(); 169 mainLayout.marginWidth = 0; 170 mainLayout.marginHeight = 0; 171 tabFolder.setLayout( mainLayout ); 172 tabFolder.setLayoutData( new GridData( GridData.FILL_BOTH ) ); 173 } 174 175 176 180 private void tabSelected() 181 { 182 int index = tabFolder.getSelectionIndex(); 183 184 if ( index == SOURCE_TAB_INDEX ) 185 { 186 try 189 { 190 String input = visualComposite.getInput(); 191 sourceComposite.setInput( input ); 192 } 193 catch ( ParseException pe ) 194 { 195 IStatus status = new Status( IStatus.ERROR, Activator.PLUGIN_ID, 1, Messages 196 .getString( "ACIItemTabFolderComposite.error.onVisualEditor" ), pe ); ErrorDialog.openError( getShell(), 198 Messages.getString( "ACIItemTabFolderComposite.error.title" ), null, status ); tabFolder.setSelection( VISUAL_TAB_INDEX ); 200 } 201 } 202 else if ( index == VISUAL_TAB_INDEX ) 203 { 204 try 207 { 208 String input = sourceComposite.getInput(); 209 visualComposite.setInput( input ); 210 } 211 catch ( ParseException pe ) 212 { 213 IStatus status = new Status( IStatus.ERROR, Activator.PLUGIN_ID, 1, Messages 214 .getString( "ACIItemTabFolderComposite.error.onSourceEditor" ), pe ); ErrorDialog.openError( getShell(), 216 Messages.getString( "ACIItemTabFolderComposite.error.title" ), null, status ); tabFolder.setSelection( SOURCE_TAB_INDEX ); 218 } 219 } 220 } 221 222 223 229 public void setInput( String input ) 230 { 231 sourceComposite.forceSetInput( input ); 233 234 try 236 { 237 visualComposite.setInput( input ); 238 } 239 catch ( ParseException pe ) 240 { 241 IStatus status = new Status( IStatus.ERROR, Activator.PLUGIN_ID, 1, Messages 242 .getString( "ACIItemTabFolderComposite.error.onInput" ), pe ); ErrorDialog.openError( getShell(), 244 Messages.getString( "ACIItemTabFolderComposite.error.title" ), null, status ); 246 tabFolder.setSelection( SOURCE_TAB_INDEX ); 247 } 248 } 249 250 251 259 public String getInput() throws ParseException 260 { 261 int index = tabFolder.getSelectionIndex(); 262 if ( index == VISUAL_TAB_INDEX ) 263 { 264 String input = visualComposite.getInput(); 265 return input; 266 } 267 else 268 { 269 String input = sourceComposite.getInput(); 270 return input; 271 } 272 } 273 274 275 280 public void setContext( ACIItemValueWithContext context ) 281 { 282 sourceComposite.setContext( context ); 283 visualComposite.setContext( context ); 284 } 285 286 287 290 public void format() 291 { 292 sourceComposite.format(); 293 } 295 296 } 297 | Popular Tags |