ruper2/src/java/eclipse/org/krysalis/ruper2/eclipse/plugin EclipsePluginLogListener.java,NONE,1.1 UpdateAction.java,NONE,1.1 RuperPlugin.java,NONE,1.1

[email protected]
Newsgroups gmane.comp.krysalis.metamorphosis.cvs
Message-ID <[email protected]>
Update of /cvsroot/metamorphosis/ruper2/src/java/eclipse/org/krysalis/ruper2/eclipse/plugin
In directory sc8-pr-cvs1:/tmp/cvs-serv7074/src/java/eclipse/org/krysalis/ruper2/eclipse/plugin

Added Files:
	EclipsePluginLogListener.java UpdateAction.java 
	RuperPlugin.java 
Log Message:
Eclipse plugin start

--- NEW FILE: EclipsePluginLogListener.java ---
/*
 * Created on Oct 13, 2003
 */
package org.krysalis.ruper2.eclipse.plugin;

import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.ILog;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Plugin;
import org.eclipse.core.runtime.Status;
import org.krysalis.ruper2.log.ILogListener;
import org.krysalis.ruper2.log.LogConstant;

/**
 * @author anou_mana
 */
public class EclipsePluginLogListener implements ILogListener {

	private ILog m_log = null;
	private String m_pluginId = null;

	public EclipsePluginLogListener(Plugin plugin) {
		m_log = plugin.getLog();
		m_pluginId = plugin.getDescriptor().getUniqueIdentifier();
	}

	/* (non-Javadoc)
	 * @see org.krysalis.ruper2.log.LogListener#log(int, java.lang.Object, java.lang.Throwable)
	 */
	public void log(int severity, Object message, Throwable thrower) {
		int eclipseSeverity = IStatus.INFO;

		switch (severity) {
			case LogConstant.WARN :
				{
					eclipseSeverity = IStatus.WARNING;
					break;
				}
			default :
			case LogConstant.ERROR :
				{
					eclipseSeverity = IStatus.ERROR;
					break;
				}
		}
		String messageStr = message.toString();

		m_log.log(createStatus(severity, messageStr, thrower));
	}

	private IStatus createStatus(int severity, String addOnMsg, Throwable thrower) {

		IStatus status = null;
		String msg = null;

		if (thrower != null) {
			if (thrower instanceof CoreException) {
				status = ((CoreException) thrower).getStatus();
			}
			else
				msg = thrower.getMessage();
		}

		if (null == status) {
			if (msg == null)
				msg = new String(""); //$NON-NLS-1$

			status =
				new Status(severity, m_pluginId, IStatus.OK, addOnMsg + msg, thrower);
		}

		return status;
	}
}

--- NEW FILE: UpdateAction.java ---
/*
 * Created on Jun 13, 2003
 *
 */
package org.krysalis.ruper2.eclipse.plugin;

import java.util.Iterator;

import org.eclipse.jface.action.IAction;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.ui.IWorkbenchWindowActionDelegate;
import org.krysalis.ruper2.eclipse.EclipseFileUpdater;
import org.krysalis.ruper2.log.Logger;

/**
 * @author Anou Manavalan
 */
public class UpdateAction implements IWorkbenchWindowActionDelegate
{
	IStructuredSelection m_selection;
	EclipseFileUpdater m_fileUpdater;

	/**
	 * 
	 */
	public UpdateAction()
	{
		super();
		initialize();
	}
	
	private void initialize()
	{
		try {
			if(m_fileUpdater == null){
				m_fileUpdater = new EclipseFileUpdater();
			}
		}
		catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
	}

	/* (non-Javadoc)
	 * @see org.eclipse.ui.IWorkbenchWindowActionDelegate#dispose()
	 */
	public void dispose()
	{

	}

	/* (non-Javadoc)
	 * @see org.eclipse.ui.IWorkbenchWindowActionDelegate#init(org.eclipse.ui.IWorkbenchWindow)
	 */
	public void init(IWorkbenchWindow window)
	{

	}

	private void initializeLog()
	{
		// Set logging context..
		//Logger logger = Logger.pushContext();
		
	}
	/* (non-Javadoc)
	 * @see org.eclipse.ui.IActionDelegate#run(org.eclipse.jface.action.IAction)
	 */
	public void run(IAction action)
	{
		//initializeLog();
		
		try
		{
			if(m_selection != null && !m_selection.isEmpty())
			{
				Iterator iter = m_selection.iterator();
				while(iter.hasNext())
				{
					m_fileUpdater.updateFile(iter.next());
					
					
					/*if(obj instanceof IProject)
					{
						IProject project = (IProject)obj;
						//Downloader downloader = new Downloader();
						//downloader.downloadFiles(project);
				
						/*if(downloader.isSuccess())
						{
							//TODO
							//TODO RuperPluginLog.messageDialog("Files downloaded, please refresh your target directory to see the file");
						}

					}
					else
					{
						String msg = "Please select a project and try again !!";
						//TODO RuperPluginLog.info(msg);
						//TODO RuperPluginLog.messageDialog(msg);
					}*/
				}
			}
			else
			{
				//String msg = "Please select a project and try again !!";
				//TODO RuperPluginLog.info(msg);
				//TODO RuperPluginLog.messageDialog(msg);
			}
		}
		catch(Exception exp)
		{
			Logger.getLog().error(
							"Failed to download files  ",
							exp);			//TODO RuperPluginLog.error("Failed to download files " + exp.getMessage(), exp);
			//TODO RuperPluginLog.errorDialog("Failed to download files " + exp.getMessage());
		}
	}

	/* (non-Javadoc)
	 * @see org.eclipse.ui.IActionDelegate#selectionChanged(org.eclipse.jface.action.IAction, org.eclipse.jface.viewers.ISelection)
	 */
	public void selectionChanged(IAction action, ISelection selection)
	{
		if(selection instanceof IStructuredSelection)
		{
			m_selection = (IStructuredSelection)selection;
		}
	}
    
}

--- NEW FILE: RuperPlugin.java ---
package org.krysalis.ruper2.eclipse.plugin;

import java.util.MissingResourceException;
import java.util.ResourceBundle;

import org.eclipse.core.resources.IWorkspace;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.IPluginDescriptor;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.ui.IWorkbench;
import org.eclipse.ui.IWorkbenchPage;
import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.ui.plugin.AbstractUIPlugin;
import org.krysalis.ruper2.eclipse.util.RuperEclipseConstants;

/**
 * The main plugin class to be used in the desktop.
 */
public class RuperPlugin extends AbstractUIPlugin {
	
	/** Identifier of the plug-in */
	public static final String PLUGIN_ID = RuperEclipseConstants.RUPER_PLUGIN_ID;
	
    //The shared instance.
    private static RuperPlugin m_plugin;
    //Resource bundle.
    private ResourceBundle m_resourceBundle;

	// Log listener
	private EclipsePluginLogListener m_logger;


    /**
     * The constructor.
     */
    public RuperPlugin(IPluginDescriptor descriptor) {
        super(descriptor);
        m_plugin = this;
        
      // m_logger = new EclipsePluginLogListener(this);
    }

    /**
     * Returns the shared instance.
     */
    public static RuperPlugin getDefault() {
        return m_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 = RuperPlugin.getDefault().getResourceBundle();
        try {
            return bundle.getString(key);
        }
        catch (MissingResourceException mre) {
            System.err.println("Missing Resource:" + key + ":" + mre);
            
            return key;
        }
    }

    /**
     * Returns the plugin's resource bundle,
     */
    public ResourceBundle getResourceBundle() {
        return m_resourceBundle;
    }
    
	public static IWorkbench getActiveWorkbench() {
		RuperPlugin plugin= getDefault();
		if (plugin == null)
			return null;
		return plugin.getWorkbench();
	}
	
	public static IWorkbenchWindow getActiveWorkbenchWindow() {
		IWorkbench workbench= getActiveWorkbench();
		if (workbench == null)
			return null;	
		return workbench.getActiveWorkbenchWindow();
	}
	
	/**
	 * Returns the active workkbench page or <code>null</code> if
	 * no active workkbench page can be determined.
	 *
	 * @return the active workkbench page or <code>null</code> if
	 * 	no active workkbench page can be determined
	 */
	private static IWorkbenchPage getActivePage() {
		IWorkbenchWindow window= getActiveWorkbenchWindow();
		if (window == null)
			return null;
		return window.getActivePage();
	}
	
	/**
	 * Returns the SWT Shell of the active workbench window or <code>null</code> if
	 * no workbench window is active.
	 *
	 * @return the SWT Shell of the active workbench window, or <code>null</code> if
	 * 	no workbench window is active
	 */
	public static Shell getShell() {
		IWorkbenchWindow window= getActiveWorkbenchWindow();
		if (window == null)
			return null;
		return window.getShell();
	}

    
}




-------------------------------------------------------
This SF.net email is sponsored by: SF.net Giveback Program.
SourceForge.net hosts over 70,000 Open Source Projects.
See the people who have HELPED US provide better services:
Click here: http://sourceforge.net/supporters.php
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.