egovframework.hdev.imp.ide.EgovDeviceAPIIdePlugin.java Source code

Java tutorial

Introduction

Here is the source code for egovframework.hdev.imp.ide.EgovDeviceAPIIdePlugin.java

Source

/*
 * Copyright 2008-2009 the original author or authors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package egovframework.hdev.imp.ide;

import java.io.File;
import java.net.URL;

import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.Path;
import org.eclipse.core.runtime.Platform;
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.jface.resource.ImageRegistry;
import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.ui.plugin.AbstractUIPlugin;
import org.osgi.framework.BundleContext;

import egovframework.hdev.imp.ide.common.DeviceAPIIdeLog;

/**  
 * ? ?? ?? ?
 * @Class Name : EgovDeviceAPIIdePlugin
 * @Description : EgovDeviceAPIIdePlugin Class
 * @Modification Information  
 * @
 * @  ?         ?      
 * @ ---------      ---------   -------------------------------
 * @ 2012. 9. 17.      ?      ?
 * 
 * @author ? API  
 * @since 2012. 9. 17.
 * @version 1.0
 * @see
 * 
 */
public class EgovDeviceAPIIdePlugin extends AbstractUIPlugin {

    /** ? ? */
    public static final String PLUGIN_ID = "egovframework.hdev.imp.ide"; //$NON-NLS-1$

    /** ? ? */
    public static final String ID_NATURE = PLUGIN_ID + ".natures.egovnature";

    /**  ? */
    public static final String IMG_ITEM = "item";

    /** ? ? */
    private static EgovDeviceAPIIdePlugin plugin;

    /**  ?   ? */
    public static final String IMG_CORE_PROJ_WIZ_BANNER = "core_proj_wiz_banner";

    /** ? ?  */
    private static final String ICONS_PATH = "icons/";

    /**
     * ??
     */
    public EgovDeviceAPIIdePlugin() {
    }

    /*
     * (non-Javadoc)
     * @see org.eclipse.ui.plugin.AbstractUIPlugin#start(org.osgi.framework.BundleContext)
     */
    public void start(BundleContext context) throws Exception {
        super.start(context);
        plugin = this;
    }

    /*
     * (non-Javadoc)
     * @see org.eclipse.ui.plugin.AbstractUIPlugin#stop(org.osgi.framework.BundleContext)
     */
    public void stop(BundleContext context) throws Exception {
        plugin = null;
        super.stop(context);
    }

    /**
     * ? ? 
     * @return Plugin
     */
    public static EgovDeviceAPIIdePlugin getDefault() {
        return plugin;
    }

    /**
      * ? ? ? 
      * @return WorkbenchWindow
      */
    public static IWorkbenchWindow getActiveWorkbenchWindow() {
        IWorkbenchWindow workbenchWindow = getDefault().getWorkbench().getActiveWorkbenchWindow();
        return workbenchWindow;
    }

    /**
     * ?   ?
     * @return ?  
     */
    @SuppressWarnings("deprecation")
    public String getInstalledPath() {
        String path = "";
        try {
            URL url = Platform.resolve(getDefault().getDescriptor().getInstallURL());
            DeviceAPIIdeLog.logInfo(url.toString());
            path = (new File(url.getPath())).getAbsolutePath();
            DeviceAPIIdeLog.logInfo(path.toString());
        } catch (Exception e) {

            DeviceAPIIdeLog.logError(e);
        }
        return path;
    }

    /**
     * ?  
     * @param registry
     */
    protected void initializeImageRegistry(ImageRegistry registry) {
        super.initializeImageRegistry(registry);

        registerImage(registry, IMG_CORE_PROJ_WIZ_BANNER, "newjprj_wiz_c.png");
        return;
    }

    /**
     * ? ? ?
     * @param registry
     * @param key
     * @param fileName
     */
    @SuppressWarnings("deprecation")
    private void registerImage(ImageRegistry registry, String key, String fileName) {
        try {
            IPath path = new Path(ICONS_PATH + fileName);
            URL url = find(path);
            if (url != null) {
                ImageDescriptor desc = ImageDescriptor.createFromURL(url);
                registry.put(key, desc);
            }
        } catch (Exception e) {
            DeviceAPIIdeLog.logError(e);
        }
        return;
    }

    /**
     * ImageDescriptor 
     * @param key
     * @return ImageDescriptor
     */
    public ImageDescriptor getImageDescriptor(String key) {
        ImageDescriptor imageDescriptor = getImageRegistry().getDescriptor(key);
        return imageDescriptor;
    }
}