org.symbian.tools.mtw.ui/src/org/symbian/tools/mtw/ui/MTWCoreUI.java
changeset 461 7a8f9fa8d278
parent 460 c0bff5ed874c
child 462 cdc4995b1677
equal deleted inserted replaced
460:c0bff5ed874c 461:7a8f9fa8d278
     1 package org.symbian.tools.mtw.ui;
       
     2 
       
     3 import java.util.Map;
       
     4 import java.util.WeakHashMap;
       
     5 
       
     6 import org.eclipse.core.resources.IProject;
       
     7 import org.eclipse.core.runtime.IStatus;
       
     8 import org.eclipse.core.runtime.Status;
       
     9 import org.eclipse.jface.resource.ImageRegistry;
       
    10 import org.eclipse.ui.plugin.AbstractUIPlugin;
       
    11 import org.osgi.framework.BundleContext;
       
    12 import org.symbian.tools.mtw.core.projects.IMTWProject;
       
    13 import org.symbian.tools.mtw.internal.deployment.DeploymentTargetPresentationsManager;
       
    14 import org.symbian.tools.mtw.internal.deployment.DeploymentTargetTypesRegistry;
       
    15 
       
    16 /**
       
    17  * The activator class controls the plug-in life cycle
       
    18  */
       
    19 public class MTWCoreUI extends AbstractUIPlugin {
       
    20     private final Map<IProject, ProjectMemo> MEMOS = new WeakHashMap<IProject, ProjectMemo>();
       
    21     private final DeploymentTargetTypesRegistry typesRegistry = new DeploymentTargetTypesRegistry();
       
    22 
       
    23     // The plug-in ID
       
    24     public static final String PLUGIN_ID = "org.symbian.tools.mtw.ui"; //$NON-NLS-1$
       
    25 
       
    26     // The shared instance
       
    27     private static MTWCoreUI plugin;
       
    28     private Images images;
       
    29     private final DeploymentTargetPresentationsManager presentations = new DeploymentTargetPresentationsManager();
       
    30 
       
    31     /**
       
    32      * The constructor
       
    33      */
       
    34     public MTWCoreUI() {
       
    35     }
       
    36 
       
    37     @Override
       
    38     protected void initializeImageRegistry(ImageRegistry reg) {
       
    39         super.initializeImageRegistry(reg);
       
    40     }
       
    41 
       
    42     /*
       
    43      * (non-Javadoc)
       
    44      * @see org.eclipse.ui.plugin.AbstractUIPlugin#start(org.osgi.framework.BundleContext)
       
    45      */
       
    46     public void start(BundleContext context) throws Exception {
       
    47         super.start(context);
       
    48         plugin = this;
       
    49     }
       
    50 
       
    51     /*
       
    52      * (non-Javadoc)
       
    53      * @see org.eclipse.ui.plugin.AbstractUIPlugin#stop(org.osgi.framework.BundleContext)
       
    54      */
       
    55     public void stop(BundleContext context) throws Exception {
       
    56         plugin = null;
       
    57         super.stop(context);
       
    58     }
       
    59 
       
    60     /**
       
    61      * Returns the shared instance
       
    62      *
       
    63      * @return the shared instance
       
    64      */
       
    65     public static MTWCoreUI getDefault() {
       
    66         return plugin;
       
    67     }
       
    68 
       
    69     public static void log(String message, Exception e) {
       
    70         getDefault().getLog().log(new Status(IStatus.ERROR, PLUGIN_ID, message, e));
       
    71     }
       
    72 
       
    73     public static void log(String message, Object... args) {
       
    74         log(String.format(message, args), (Exception) null);
       
    75     }
       
    76 
       
    77     public static void log(Exception e) {
       
    78         log(null, e);
       
    79     }
       
    80 
       
    81     public static ProjectMemo getMemo(IMTWProject project) {
       
    82         return getDefault().getMemoForProject(project);
       
    83     }
       
    84 
       
    85     private synchronized ProjectMemo getMemoForProject(IMTWProject project) {
       
    86         ProjectMemo memo = MEMOS.get(project.getProject());
       
    87         if (memo == null) {
       
    88             memo = new ProjectMemo(project);
       
    89             MEMOS.put(project.getProject(), memo);
       
    90         }
       
    91         return memo;
       
    92     }
       
    93 
       
    94     public DeploymentTargetTypesRegistry getDeploymentTypesRegistry() {
       
    95         return typesRegistry;
       
    96     }
       
    97 
       
    98     public static Images getImages() {
       
    99         if (getDefault().images == null) {
       
   100             getDefault().images = new Images(getDefault().getImageRegistry());
       
   101         }
       
   102         return getDefault().images;
       
   103     }
       
   104 
       
   105     public DeploymentTargetPresentationsManager getPresentations() {
       
   106         return presentations;
       
   107     }
       
   108 }