⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 tanghanplugin.java

📁 J2EE eclipse 下开发数据库一个插件
💻 JAVA
字号:
package com.tanghan.plugin;

import org.eclipse.ui.plugin.*;
//import org.eclipse.core.internal.plugins.PluginClassLoader;
import org.eclipse.core.runtime.*;
import org.eclipse.core.resources.*;
import org.eclipse.jface.preference.IPreferenceStore;
//import org.eclipse.swt.graphics.*;
import java.util.*;
//import java.io.*;

import org.apache.log4j.Logger;

import com.tanghan.plugin.dataSave.DBDealDataSaveXML;
import com.tanghan.plugin.dataSave.IDBDealDataSave;
import com.tanghan.util.Log;
import com.tanghan.util.PageList;
//import org.eclipse.jface.resource.ImageRegistry;
/**
 * The main plugin class to be used in the desktop. 
 * @author Jerry Tang
 * @version v0.1.0
 * @copyright  (C) 2003 Tanghan工作组
 */
public class TanghanPlugin extends AbstractUIPlugin implements ILogListener{
	
	public static final String PLUGIN_ID = ITanghanConstants.PLUGIN_ID;
	
	private static TanghanClassLoader tanghanClassLoader = new TanghanClassLoader(TanghanPlugin.class.getClassLoader()); 
	
	private static Logger logger = Log.getInstanse().getLogger();

	//The shared instance.
	private static TanghanPlugin plugin;
	//Resource bundle.
	private ResourceBundle resourceBundle;
	/**处理存储数据的接口*/
	IDBDealDataSave dealDataSave;
	
	/**
	 * The constructor.
	 */
	public TanghanPlugin(IPluginDescriptor descriptor) {
		super(descriptor);
		plugin = this;
		this.getLog().addLogListener(this);
//		initImageResources();
		try {
			resourceBundle= ResourceBundle.getBundle("com.tanghan.plugin.TanghanPluginResources");
		} catch (MissingResourceException x) {
			resourceBundle = null;
		}
		//getLog().log(new Status(IStatus.ERROR, plugin.toString(),IStatus.OK,this.getStateLocation().toFile().toString(),null));
		//((PluginClassLoader)getClass().getClassLoader()).newInstance()
	}

	/**
	 * Returns the shared instance.
	 */
	public static TanghanPlugin getDefault() {
		return plugin;
	}

	/**
	 * Returns the workspace instance.
	 */
	public static IWorkspace getWorkspace() {
		return ResourcesPlugin.getWorkspace();
	}

	/**
	 * Returns the string from the plugin's resource bundle,
	 * or 'key' if not found.
	 */
	public static String getResourceString(String key) {
		ResourceBundle bundle= TanghanPlugin.getDefault().getResourceBundle();
		try {
			return bundle.getString(key);
		} catch (MissingResourceException e) {
			return key;
		}
	}

	/**
	 * Returns the plugin's resource bundle,
	 */
	public ResourceBundle getResourceBundle() {
		return resourceBundle;
	}
	public IPublicImages getPublicImages(){
		return NowPublicImages.getInstance();
	}

	/* (non-Javadoc)
	 * @see org.eclipse.core.runtime.ILogListener#logging(org.eclipse.core.runtime.IStatus, java.lang.String)
	 */
	public void logging(IStatus status, String plugin) {
		//Logger logger = Log.getInstanse().getLogger(plugin);
		switch(status.getSeverity()){
			case IStatus.ERROR:
				if(status.getException()==null){
					logger.error(status.getMessage());
				}else{
					logger.error(status.getMessage(),status.getException());
				}
				break;
			case IStatus.WARNING:
				if(status.getException()==null){
					logger.warn(status.getMessage());
				}else{
					logger.warn(status.getMessage(),status.getException());
				}
				break;
			default:
				if(status.getException()==null){
					logger.info(status.getMessage());
				}else{
					logger.info(status.getMessage(),status.getException());
				}
				break;
		}
	}
	/* (non-Javadoc)
	 * @see org.eclipse.core.runtime.Plugin#startup()
	 */
	public void startup() throws CoreException {
		// TO_DO 载入TanghanPlugin的配置文件。
		super.startup();
		this.dealDataSave = new DBDealDataSaveXML();
		try{
			dealDataSave.loadData(this);
		}catch(Exception ex){
			//TODO 处理改意外
		}
		
	}
	
	/** 
	 * Sets default preference values. These values will be used
	 * until some preferences are actually set using Preference dialog.
	 */
	protected void initializeDefaultPreferences(IPreferenceStore store) {
		store.setValue(ITanghanConstants.PAGELIST_SHOWALL, false);
		store.setValue(ITanghanConstants.PAGELIST_LIST, 20);

	}
	public PageList getDefaultPageList(){
		IPreferenceStore store = this.getPreferenceStore();
		boolean showAll = store.getBoolean(ITanghanConstants.PAGELIST_SHOWALL);
		PageList pl = new PageList(1,store.getInt(ITanghanConstants.PAGELIST_LIST));
		pl.setShowAll(showAll);
		return pl;

	}

	/**
	 * @return
	 */
	public IDBDealDataSave getDealDataSave() {
		return dealDataSave;
	}

	/* (non-Javadoc)
	 * @see org.eclipse.core.runtime.Plugin#shutdown()
	 */
	public void shutdown() throws CoreException {
		super.shutdown();
		//保存数据到文件
		try{
			this.dealDataSave.saveData();
		}catch(Exception ex){
			getLog().log(new Status(IStatus.ERROR, plugin.toString(),IStatus.OK,ex.getMessage(),ex));
			ex.printStackTrace();
			//TO_DO 处理改意外
		}
		int  o =0 ;
	}

	/**
	 * @return
	 */
	public TanghanClassLoader getTanghanClassLoader() {
		return tanghanClassLoader;
	}

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -