1 20 21 package org.apache.directory.ldapstudio.schemas.view.views; 22 23 24 import org.apache.directory.ldapstudio.schemas.Activator; 25 import org.apache.directory.ldapstudio.schemas.controller.SchemasViewController; 26 import org.apache.directory.ldapstudio.schemas.model.Schema; 27 import org.apache.directory.ldapstudio.schemas.model.SchemaPool; 28 import org.apache.directory.ldapstudio.schemas.view.views.wrappers.ITreeNode; 29 import org.apache.directory.ldapstudio.schemas.view.views.wrappers.SchemasViewRoot; 30 import org.apache.log4j.Logger; 31 import org.eclipse.core.runtime.IProgressMonitor; 32 import org.eclipse.jface.viewers.DecoratingLabelProvider; 33 import org.eclipse.jface.viewers.TreeViewer; 34 import org.eclipse.swt.SWT; 35 import org.eclipse.swt.widgets.Composite; 36 import org.eclipse.ui.ISaveablePart2; 37 import org.eclipse.ui.part.ViewPart; 38 39 40 46 public class SchemasView extends ViewPart implements ISaveablePart2 47 { 48 49 public static final String ID = Activator.PLUGIN_ID + ".view.SchemasView"; 51 52 private static Logger logger = Logger.getLogger( SchemasView.class ); 53 54 55 private TreeViewer viewer; 56 57 58 private SchemasViewContentProvider contentProvider; 59 60 61 64 public void createPartControl( Composite parent ) 65 { 66 initViewer( parent ); 67 68 getSite().setSelectionProvider( viewer ); 70 71 new SchemasViewController( this ); 73 } 74 75 76 79 private void initViewer( Composite parent ) 80 { 81 viewer = new TreeViewer( parent, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER ); 82 contentProvider = new SchemasViewContentProvider( viewer ); 83 viewer.setContentProvider( contentProvider ); 84 viewer.setLabelProvider( new DecoratingLabelProvider( new SchemasViewLabelProvider(), Activator.getDefault() 85 .getWorkbench().getDecoratorManager().getLabelDecorator() ) ); 86 viewer.setInput( new SchemasViewRoot() ); 87 } 88 89 90 93 public void setFocus() 94 { 95 viewer.getControl().setFocus(); 96 } 97 98 99 104 public void completeRefresh() 105 { 106 Object [] exp = viewer.getExpandedElements(); 107 108 viewer.setInput( new SchemasViewRoot() ); 110 111 for ( Object object : exp ) 113 { 114 viewer.setExpandedState( object, true ); 115 } 116 } 117 118 119 124 public void refresh() 125 { 126 viewer.refresh(); 127 } 128 129 130 136 public TreeViewer getViewer() 137 { 138 return viewer; 139 } 140 141 142 145 public int promptToSaveOnClose() 146 { 147 return ISaveablePart2.YES; 148 } 149 150 151 154 public void doSave( IProgressMonitor monitor ) 155 { 156 try 158 { 159 SchemaPool.getInstance().saveAll( true ); 160 } 161 catch ( Exception e ) 162 { 163 logger.debug( "error when saving schemas on disk after asking for confirmation" ); } 165 } 166 167 168 171 public void doSaveAs() 172 { 173 } 174 175 176 179 public boolean isDirty() 180 { 181 Schema[] schemas = SchemaPool.getInstance().getSchemas(); 182 for ( Schema schema : schemas ) 183 { 184 if ( schema.type == Schema.SchemaType.userSchema ) 185 { 186 if ( schema.hasBeenModified() || schema.hasPendingModification() ) 187 { 188 return true; 189 } 190 } 191 } 192 193 return false; 195 } 196 197 198 201 public boolean isSaveAsAllowed() 202 { 203 return false; 204 } 205 206 207 210 public boolean isSaveOnCloseNeeded() 211 { 212 return true; 213 } 214 215 216 224 public ITreeNode findElementInTree( ITreeNode element ) 225 { 226 if ( element == null ) 227 { 228 return null; 229 } 230 231 ITreeNode input = ( ITreeNode ) getViewer().getInput(); 232 233 return findElementInTree( element, input ); 234 } 235 236 237 246 public ITreeNode findElementInTree( ITreeNode element, ITreeNode node ) 247 { 248 if ( element.equals( node ) ) 249 { 250 return node; 251 } 252 else 253 { 254 Object [] children = contentProvider.getChildren( node ); 255 for ( Object child : children ) 256 { 257 ITreeNode foundElement = findElementInTree( element, ( ITreeNode ) child ); 258 if ( foundElement != null ) 259 { 260 return foundElement; 261 } 262 } 263 } 264 return null; 265 } 266 } 267 | Popular Tags |