Code Search for Developers
 
 
  

PovClipseActionDeligator.java from PovClipse at Krugle


Show PovClipseActionDeligator.java syntax highlighted

/*
 * PovClipse - Eclipse plugin for editing and rendering Povray sceene files.
 * Copyright (C) 2006-2007  Wolfgang Moestl  wmoestl@web.de
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
 */

package com.wm.povclipse.deligator;

import org.apache.log4j.Logger;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.jface.action.IAction;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.StructuredSelection;
import org.eclipse.ui.IActionDelegate;

import com.wm.povclipse.LoggerProvider;
import com.wm.povclipse.PovClipseProjectNature;

/**
 * Action deligator for deligating all PovClipse related
 * Package Explorer popup menu actions.
 * 
 * @author Wolfgang Möstl
 */
public class PovClipseActionDeligator implements IActionDelegate {
	
	static private Logger logger = LoggerProvider.getLogger(PovClipseActionDeligator.class.getName());
	
	private IResource ressource;
	
	/**
	 * Indicates that a valid resource was selected. 
	 */
	boolean ok = false;
	
	/**
	 * @see org.eclipse.ui.IActionDelegate#run(org.eclipse.jface.action.IAction)
	 */
	public void run(IAction action) {
		if (ok && ressource instanceof IProject) {
			IProject project = (IProject)ressource;
			
			if ("com.wm.povclipse.addPovClipseNatureAction".equals(action.getId())) {
				try {
					PovClipseProjectNature.addPovClipseProjectNature((IProject)project);
			    } catch (CoreException e) {
				    logger.fatal("Unable to assing the PovClipse project nature to project [" + project.getName() + "]:");
				    logger.fatal(e);
			    }
			}
			if ("com.wm.povclipse.removePovClipseNatureAction".equals(action.getId())) {
				try {
					PovClipseProjectNature.removePovClipseProjectNature((IProject)project);
			    } catch (CoreException e) {
				    logger.fatal("Unable to remove the PovClipse project nature from project [" + project.getName() + "]:");
				    logger.fatal(e);
			    }
			}
		}
	}

	/**
	 * @see org.eclipse.ui.IActionDelegate#selectionChanged(org.eclipse.jface.action.IAction, org.eclipse.jface.viewers.ISelection)
	 */
	public void selectionChanged(IAction action, ISelection selection) {
		ok = false;
		if (!selection.isEmpty() && selection instanceof StructuredSelection) {
			StructuredSelection structuredSelection = (StructuredSelection)selection;
			if (structuredSelection.getFirstElement() instanceof IResource) {
				ressource = (IResource)structuredSelection.getFirstElement();
				ok = true;
			}
		}
	}

}



See more files for this project here

PovClipse

PovClipse is an eclipse editor plugin for Povray (Persistence of Vision Raytracer) sceene- and include files.\r\nIt features syntax highlighting, code folding, code assist, outline view as well as running Povray using render configurations.

Project homepage: http://sourceforge.net/projects/povclipse
Programming language(s): Java
License: other

  PovClipseActionDeligator.java