sftemplateswizard/com.nokia.s60tools.symbianfoundationtemplates/src/com/nokia/s60tools/symbianfoundationtemplates/SymbianFoundationTemplates.java
author dpodwall
Tue, 12 Jan 2010 13:17:53 -0600
changeset 0 61163b28edca
permissions -rw-r--r--
initial EPL conversion
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
0
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
     1
/*
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
     2
* Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). 
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
     3
* All rights reserved.
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
     4
* This component and the accompanying materials are made available
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
     5
* under the terms of "Eclipse Public License v1.0"
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
     6
* which accompanies this distribution, and is available
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
     7
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
     8
*
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
     9
* Initial Contributors:
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    10
* Nokia Corporation - initial contribution.
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    11
*
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    12
* Contributors:
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    13
*
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    14
* Description:
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    15
*
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    16
*/
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    17
package com.nokia.s60tools.symbianfoundationtemplates;
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    18
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    19
import java.io.File;
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    20
import java.io.IOException;
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    21
import java.net.URL;
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    22
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    23
import org.eclipse.core.runtime.FileLocator;
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    24
import org.eclipse.core.runtime.IStatus;
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    25
import org.eclipse.core.runtime.Status;
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    26
import org.eclipse.jface.dialogs.ErrorDialog;
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    27
import org.eclipse.swt.widgets.Display;
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    28
import org.eclipse.ui.plugin.AbstractUIPlugin;
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    29
import org.osgi.framework.BundleContext;
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    30
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    31
import com.nokia.s60tools.symbianfoundationtemplates.resources.Messages;
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    32
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    33
/**
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    34
 * The activator class controls the plug-in life cycle
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    35
 */
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    36
public class SymbianFoundationTemplates extends AbstractUIPlugin {
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    37
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    38
	// The plug-in ID
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    39
	public static final String PLUGIN_ID = "com.nokia.s60tools.symbianfoundationtemplates"; //$NON-NLS-1$
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    40
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    41
	// The shared instance
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    42
	private static SymbianFoundationTemplates plugin;
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    43
	
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    44
	/**
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    45
	 * The constructor
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    46
	 */
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    47
	public SymbianFoundationTemplates() {
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    48
		plugin = this;
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    49
	}
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    50
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    51
	/*
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    52
	 * (non-Javadoc)
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    53
	 * @see org.eclipse.ui.plugin.AbstractUIPlugin#start(org.osgi.framework.BundleContext)
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    54
	 */
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    55
	public void start(BundleContext context) throws Exception {
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    56
		super.start(context);
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    57
	}
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    58
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    59
	/*
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    60
	 * (non-Javadoc)
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    61
	 * @see org.eclipse.ui.plugin.AbstractUIPlugin#stop(org.osgi.framework.BundleContext)
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    62
	 */
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    63
	public void stop(BundleContext context) throws Exception {
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    64
		plugin = null;
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    65
		super.stop(context);
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    66
	}
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    67
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    68
	/**
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    69
	 * Returns the shared instance
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    70
	 *
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    71
	 * @return the shared instance
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    72
	 */
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    73
	public static SymbianFoundationTemplates getDefault() {
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    74
		return plugin;
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    75
	}
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    76
	
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    77
	/**
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    78
	 * Show the error dialog.
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    79
	 * 
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    80
	 * @param error the error message.
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    81
	 * @param reason the reason of the error.
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    82
	 */
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    83
	public void showErrorDialog(String error, String reason) {
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    84
		IStatus status = new Status(IStatus.ERROR, SymbianFoundationTemplates.PLUGIN_ID, -1, reason, null);
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    85
		
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    86
		ErrorDialog.openError(Display.getCurrent().getActiveShell(),
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    87
				Messages.getString("ErrorMessageTitle"), //$NON-NLS-1$
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    88
				error, status);
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    89
	}
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    90
	
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    91
	/**
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    92
	 * Get the location of the templates associated with this plugin.
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    93
	 * 
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    94
	 * @return the location of templates
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    95
	 */
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    96
	public String getTemplatesPath() {
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    97
		return getRootPath() + "templates"; //$NON-NLS-1$
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    98
	}
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    99
	
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   100
	/**
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   101
	 * Get the location of the images associated with this plugin.
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   102
	 * 
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   103
	 * @return the location of images
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   104
	 */
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   105
	public String getImagesPath() {
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   106
		return getRootPath() + "images"; //$NON-NLS-1$
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   107
	}
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   108
	
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   109
	/**
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   110
	 * Get the plugin root path of this plugin
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   111
	 * @return the plugin installation path
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   112
	 */
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   113
	private String getRootPath() {
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   114
		URL relativeURL = getBundle().getEntry("/"); //$NON-NLS-1$
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   115
		
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   116
		URL localURL = null;
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   117
		try {
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   118
			localURL = FileLocator.toFileURL(relativeURL);
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   119
		} catch(IOException ioe) {
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   120
		}
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   121
		
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   122
		if(localURL == null)
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   123
			return null;
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   124
		
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   125
		File f = new File(localURL.getPath());
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   126
		
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   127
		return f.getAbsolutePath() + File.separator;
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   128
	}
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   129
}