1 20 package org.apache.directory.ldapstudio.aciitemeditor; 21 22 23 import java.io.IOException ; 24 25 import org.apache.directory.ldapstudio.aciitemeditor.sourceeditor.ACICodeScanner; 26 import org.apache.directory.ldapstudio.aciitemeditor.sourceeditor.ACITextAttributeProvider; 27 import org.apache.directory.shared.ldap.aci.ACIItemParser; 28 import org.eclipse.jface.dialogs.Dialog; 29 import org.eclipse.jface.dialogs.IDialogConstants; 30 import org.eclipse.jface.resource.ImageDescriptor; 31 import org.eclipse.jface.resource.JFaceResources; 32 import org.eclipse.jface.text.templates.GlobalTemplateVariables; 33 import org.eclipse.swt.graphics.FontMetrics; 34 import org.eclipse.swt.graphics.GC; 35 import org.eclipse.swt.graphics.Image; 36 import org.eclipse.swt.widgets.Control; 37 import org.eclipse.ui.editors.text.templates.ContributionContextTypeRegistry; 38 import org.eclipse.ui.editors.text.templates.ContributionTemplateStore; 39 import org.eclipse.ui.plugin.AbstractUIPlugin; 40 import org.osgi.framework.BundleContext; 41 42 43 49 public class Activator extends AbstractUIPlugin 50 { 51 52 53 public static final String PLUGIN_ID = "org.apache.directory.ldapstudio.aciitemeditor"; 55 56 private static Activator plugin; 57 58 59 private ACIItemParser aciItemParser; 60 61 62 private ACICodeScanner aciCodeScanner; 63 64 65 private ACITextAttributeProvider textAttributeProvider; 66 67 68 private ContributionTemplateStore aciTemplateStore; 69 70 71 private ContributionContextTypeRegistry aciTemplateContextTypeRegistry; 72 73 74 77 public Activator() 78 { 79 plugin = this; 80 } 81 82 83 86 public void start( BundleContext context ) throws Exception 87 { 88 super.start( context ); 89 90 if ( aciTemplateContextTypeRegistry == null ) 92 { 93 aciTemplateContextTypeRegistry = new ContributionContextTypeRegistry(); 94 95 aciTemplateContextTypeRegistry.addContextType( ACIITemConstants.ACI_ITEM_TEMPLATE_ID ); 96 aciTemplateContextTypeRegistry.getContextType( ACIITemConstants.ACI_ITEM_TEMPLATE_ID ).addResolver( 97 new GlobalTemplateVariables.Cursor() ); 98 } 99 100 if ( aciTemplateStore == null ) 102 { 103 aciTemplateStore = new ContributionTemplateStore( getAciTemplateContextTypeRegistry(), 104 getPreferenceStore(), "templates" ); try 106 { 107 aciTemplateStore.load(); 108 } 109 catch ( IOException e ) 110 { 111 e.printStackTrace(); 112 } 113 } 114 } 115 116 117 120 public void stop( BundleContext context ) throws Exception 121 { 122 plugin = null; 123 super.stop( context ); 124 } 125 126 127 132 public static Activator getDefault() 133 { 134 return plugin; 135 } 136 137 138 145 public static ImageDescriptor getImageDescriptor( String path ) 146 { 147 return imageDescriptorFromPlugin( PLUGIN_ID, path ); 148 } 149 150 151 161 public Image getImage( String path ) 162 { 163 Image image = getImageRegistry().get( path ); 164 if ( image == null ) 165 { 166 ImageDescriptor id = getImageDescriptor( path ); 167 if ( id != null ) 168 { 169 image = id.createImage(); 170 getImageRegistry().put( path, image ); 171 } 172 } 173 return image; 174 } 175 176 177 183 public ACIItemParser getACIItemParser() 184 { 185 if ( aciItemParser == null ) 186 { 187 aciItemParser = new ACIItemParser( null ); 188 } 189 return aciItemParser; 190 } 191 192 193 199 public static int getButtonWidth( Control control ) 200 { 201 GC gc = new GC( control ); 202 gc.setFont( JFaceResources.getDialogFont() ); 203 FontMetrics fontMetrics = gc.getFontMetrics(); 204 gc.dispose(); 205 206 int width = Dialog.convertHorizontalDLUsToPixels( fontMetrics, IDialogConstants.BUTTON_WIDTH ); 207 return width; 208 } 209 210 211 217 public ACITextAttributeProvider getTextAttributeProvider() 218 { 219 if ( textAttributeProvider == null ) 220 { 221 textAttributeProvider = new ACITextAttributeProvider(); 222 } 223 return textAttributeProvider; 224 } 225 226 227 233 public ACICodeScanner getAciCodeScanner() 234 { 235 if ( aciCodeScanner == null ) 236 { 237 aciCodeScanner = new ACICodeScanner( getTextAttributeProvider() ); 238 } 239 return aciCodeScanner; 240 } 241 242 243 249 public ContributionContextTypeRegistry getAciTemplateContextTypeRegistry() 250 { 251 return aciTemplateContextTypeRegistry; 252 } 253 254 255 261 public ContributionTemplateStore getAciTemplateStore() 262 { 263 return aciTemplateStore; 264 } 265 266 } 267 | Popular Tags |