webpumpideplugin.java

来自「一个eclipse插件源代码。用于web开发」· Java 代码 · 共 672 行 · 第 1/2 页

JAVA
672
字号

private static String getFoldName(IFile file) {
    String foldname = "";
    String path = file.getFullPath().toString();
    int firstindex = path.indexOf("/");
    int secondindex = path.indexOf("/", firstindex + 1);
    int thirdindex = path.indexOf("/", secondindex + 1);
    int forthindex = path.indexOf("/", thirdindex + 1);
    foldname = path.substring(thirdindex + 1, forthindex);
    return foldname;
}

/**
 * The constructor.
 * @param descriptor IPluginDescriptor
 */
public WebpumpIDEPlugin(IPluginDescriptor descriptor) {
	super(descriptor);
	plugin = this;
	try {

		resourceBundle = PropertyResourceBundle.getBundle("resources");
	} catch (MissingResourceException x) {
		resourceBundle = null;
	}
	
	getWorkspace().addResourceChangeListener(new WebpumpProjectChangeListener(),IResourceChangeEvent.POST_CHANGE );
}

/**
 * get default WebpumpView4JPlugin object
 *   
 * @return Returns the shared instance.
 */
public static WebpumpIDEPlugin getDefault() {
	return plugin;
}

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

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

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

/**
	 * Returns the string from the plugin's resource bundle,
	 * or 'key' if not found.
	 * @param key String 
	 * @return String[]
	 */
	public static String[] getResourceStringArray(String key) {
		
		String strValue = getResourceString(key);
		
		String[] strReturn =  splitString(strValue,",");
		
		return strReturn;
		
		
	}

	/**
 * Returns the plugin's resource bundle,
 * @return ResourceBundle
 */
public ResourceBundle getResourceBundle() {
	return resourceBundle;
}

/**
 * write log
 * @param msg String
 */
public static void log(String msg) {
	ILog log = WebpumpIDEPlugin.getDefault().getLog();
	Status status =
		new Status(
			IStatus.ERROR,
			WebpumpIDEPlugin.getDefault().getDescriptor().getUniqueIdentifier(),
			IStatus.ERROR,
			msg + "\n",
			null);
	log.log(status);
}

/**
 * write log
 * @param ex Exception
 */
public static void log(Exception ex) {
	ILog log = WebpumpIDEPlugin.getDefault().getLog();
	StringWriter stringWriter = new StringWriter();
	ex.printStackTrace(new PrintWriter(stringWriter));
	String msg = stringWriter.getBuffer().toString();

	Status status =
		new Status(
			IStatus.ERROR,
			WebpumpIDEPlugin.getDefault().getDescriptor().getUniqueIdentifier(),
			IStatus.ERROR,
			msg,
			null);
	log.log(status);
}

	/**
	 *  parse String value to String by splitStr
	 *  @param  strValue, strSplitStr
	 *  @reurn  String[]
	 */
	 public static String[] splitString( String strSource, String strDivide )
	 {
		StringTokenizer st = new StringTokenizer(strSource,strDivide);
		Vector vt = new Vector();
		String[] strResult = null;

		while (st.hasMoreTokens())
		{
			vt.add(st.nextToken());
		}

		strResult = new String[vt.size()];
		vt.copyInto(strResult);

		 return strResult;
	 }
	
	public static void setComboxValue(Combo combo,String[] strArray)
	{
		if ((combo!=null)&&(strArray!=null))
		{
			for (int i =0;i<strArray.length;i++ )
			{
				combo.add(strArray[i]);
			}
		}
		
	}

	
	public static void setComboxValue(CCombo combo,String[] strArray)
	{
		if ((combo!=null)&&(strArray!=null))
		{
			for (int i =0;i<strArray.length;i++ )
			{
				combo.add(strArray[i]);
			}
		}
		
	}
		
	public static boolean setComboxSelect(Combo combo,String strSelected)
	{
		boolean bReturn = false;
		if ((combo!=null)&&(strSelected!=null))
		{
			combo.select(0);
			for (int i =0;i<combo.getItemCount();i++ )
			{
				if (strSelected.equals(combo.getItem(i)))
				{
					combo.select(i);
					bReturn = true;
					break;
				}
				
			}
		}
		
		return bReturn;
		
	}	
	
	public static boolean setComboxSelect(CCombo combo,String strSelected)
	{
		boolean bReturn = false;
		if ((combo!=null)&&(strSelected!=null))
		{
			combo.select(0);
			for (int i =0;i<combo.getItemCount();i++ )
			{
				if (strSelected.equals(combo.getItem(i)))
				{
					combo.select(i);
					bReturn = true;
					break;
				}
				
			}
		}
		return bReturn;
	}		
	
	public void startup() throws CoreException {
		IAdapterManager manager = Platform.getAdapterManager();
		RegistryPropertySourceFactory factory =
			new RegistryPropertySourceFactory();
		manager.registerAdapters(factory, BaseObject.class);
	}
	
	public static String filterXML(String strInfo)
	{
		if (strInfo==null) strInfo = "";
		strInfo = strInfo.replaceAll("&", "&amp;");
		strInfo = strInfo.replaceAll(">", "&gt;");
		strInfo = strInfo.replaceAll("<", "&lt;");
		strInfo = strInfo.replaceAll("\"", "&quot;");
		return strInfo;
	}
	
	
	//add by shi_l 04-5-31

	private static WebpumpIDEPlugin singleton;
	
	private static Shell m_objShell = null;
	
	private static Display m_objDisplay = null;

	static private List createCategories(PaletteRoot root) {
		List categories = new ArrayList();

		categories.add(createControlGroup(root));
		categories.add(createComponentsDrawer());

		return categories;
	}

	static private PaletteContainer createComponentsDrawer() {

		PaletteDrawer drawer = new PaletteDrawer("", ImageDescriptor.createFromFile(ModuleEditor.class, "icons/comp.gif")); //$NON-NLS-1$

		List entries = new ArrayList();

		CombinedTemplateCreationEntry combined = new CombinedTemplateCreationEntry(
			"",
			WebpumpIDEPlugin.getResourceString(MacroResource.GEF_MODULE_EDITOR_ADDPAGE),
			"PAGE",
			new SimpleFactory(Page.class),
			ImageDescriptor.createFromFile(ModuleEditor.class, "icons/Page16.gif"), //$NON-NLS-1$
			ImageDescriptor.createFromFile(ModuleEditor.class, "icons/Page24.gif")//$NON-NLS-1$
		);
		entries.add(combined);

		ToolEntry tool = new ConnectionCreationToolEntry(
			"",
			WebpumpIDEPlugin.getResourceString(MacroResource.GEF_MODULE_EDITOR_ADDTASK),
			null,
			ImageDescriptor.createFromFile(ModuleEditor.class, "icons/Task16.gif"),//$NON-NLS-1$
			ImageDescriptor.createFromFile(ModuleEditor.class, "icons/Task24.gif")//$NON-NLS-1$
		);
		entries.add(tool);
		drawer.addAll(entries);
		return drawer;
	}

	static private PaletteContainer createControlGroup(PaletteRoot root) {
		PaletteGroup controlGroup = new PaletteGroup("PaletteGroup");

		List entries = new ArrayList();

		ToolEntry tool = new SelectionToolEntry();
		entries.add(tool);
		root.setDefaultEntry(tool);

		tool = new MarqueeToolEntry();
		entries.add(tool);

		PaletteSeparator sep = new PaletteSeparator("org.eclipse.gef.examples.logicdesigner.logicplugin.sep2"); //$NON-NLS-1$
		sep.setUserModificationPermission(
			PaletteEntry.PERMISSION_NO_MODIFICATION);
		entries.add(sep); //$NON-NLS-1$

		controlGroup.addAll(entries);
		return controlGroup;
	}

	public static PaletteRoot createPalette() {
		PaletteRoot logicPalette = new PaletteRoot();
		logicPalette.addAll(createCategories(logicPalette));
		return logicPalette;
	}
	
	public static void setShell(Shell shell) {
		m_objShell = shell;
	}
	
	public static void setDisplay(Display display) {
		m_objDisplay = display;
	}
	
	public static Shell getShell() {
		return m_objShell;
	}
	
	public static Display getDisplay() {
		return m_objDisplay;
	}
}

⌨️ 快捷键说明

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