blob: 1d76b3c3eb8d245abb704fd237541b867255b852 [file] [log] [blame]
/*******************************************************************************
* Copyright (c) 2004 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* IBM Corporation - initial API and implementation
*******************************************************************************/
package org.eclipse.wst.html.ui.internal;
import java.io.IOException;
import java.text.MessageFormat;
import java.util.MissingResourceException;
import java.util.ResourceBundle;
import org.eclipse.jface.text.templates.ContextTypeRegistry;
import org.eclipse.jface.text.templates.persistence.TemplateStore;
import org.eclipse.ui.editors.text.templates.ContributionContextTypeRegistry;
import org.eclipse.ui.editors.text.templates.ContributionTemplateStore;
import org.eclipse.ui.plugin.AbstractUIPlugin;
import org.eclipse.wst.html.ui.internal.preferences.HTMLUIPreferenceNames;
import org.eclipse.wst.html.ui.internal.templates.TemplateContextTypeIdsHTML;
import org.eclipse.wst.sse.ui.registry.AdapterFactoryRegistry;
import org.eclipse.wst.sse.ui.registry.AdapterFactoryRegistryImpl;
import org.eclipse.wst.sse.ui.registry.embedded.EmbeddedAdapterFactoryRegistryImpl;
/**
* The main plugin class to be used in the desktop.
*/
public class HTMLUIPlugin extends AbstractUIPlugin {
public final static String ID = "org.eclipse.wst.html.ui"; //$NON-NLS-1$
protected static HTMLUIPlugin instance = null;
// Resource bundle.
private ResourceBundle resourceBundle;
private static final String KEY_PREFIX = "%"; //$NON-NLS-1$
private static final String KEY_DOUBLE_PREFIX = "%%"; //$NON-NLS-1$
/**
* The template store for the html editor.
*/
private TemplateStore fTemplateStore;
/**
* The template context type registry for the html editor.
*/
private ContextTypeRegistry fContextTypeRegistry;
public HTMLUIPlugin() {
super();
instance = this;
}
public static HTMLUIPlugin getDefault() {
return instance;
}
public synchronized static HTMLUIPlugin getInstance() {
return instance;
}
public AdapterFactoryRegistry getAdapterFactoryRegistry() {
return AdapterFactoryRegistryImpl.getInstance();
}
public AdapterFactoryRegistry getEmbeddedAdapterFactoryRegistry() {
return EmbeddedAdapterFactoryRegistryImpl.getInstance();
}
/**
* Returns the template store for the html editor templates.
*
* @return the template store for the html editor templates
*/
public TemplateStore getTemplateStore() {
if (fTemplateStore == null) {
fTemplateStore = new ContributionTemplateStore(getTemplateContextRegistry(), getPreferenceStore(), HTMLUIPreferenceNames.TEMPLATES_KEY);
try {
fTemplateStore.load();
} catch (IOException e) {
Logger.logException(e);
}
}
return fTemplateStore;
}
/**
* Returns the template context type registry for the html plugin.
*
* @return the template context type registry for the html plugin
*/
public ContextTypeRegistry getTemplateContextRegistry() {
if (fContextTypeRegistry == null) {
ContributionContextTypeRegistry registry = new ContributionContextTypeRegistry();
registry.addContextType(TemplateContextTypeIdsHTML.ALL);
registry.addContextType(TemplateContextTypeIdsHTML.NEW);
registry.addContextType(TemplateContextTypeIdsHTML.TAG);
registry.addContextType(TemplateContextTypeIdsHTML.ATTRIBUTE);
registry.addContextType(TemplateContextTypeIdsHTML.ATTRIBUTE_VALUE);
fContextTypeRegistry = registry;
}
return fContextTypeRegistry;
}
/**
* Returns the string from the plugin's resource bundle, or 'key' if not
* found.
*/
public static String getResourceString(String value) {
String s = value.trim();
if (!s.startsWith(KEY_PREFIX, 0))
return s;
if (s.startsWith(KEY_DOUBLE_PREFIX, 0))
return s.substring(1);
int ix = s.indexOf(' ');
String key = ix == -1 ? s : s.substring(0, ix);
ResourceBundle bundle = getDefault().getResourceBundle();
try {
return (bundle != null) ? bundle.getString(key.substring(1)) : key;
} catch (MissingResourceException e) {
return key;
}
}
public static String getResourceString(String key, Object[] args) {
try {
return MessageFormat.format(getResourceString(key), args);
} catch (IllegalArgumentException e) {
return getResourceString(key);
}
}
/**
* Returns the plugin's resource bundle,
*/
public ResourceBundle getResourceBundle() {
try {
if (resourceBundle == null)
resourceBundle = ResourceBundle.getBundle("org.eclipse.wst.html.ui.internal.HTMLUIPluginResources");
} catch (MissingResourceException x) {
resourceBundle = null;
}
return resourceBundle;
}
}