krysalis-version/src/java/org/krysalis/version/eclipse/plugin/actions ShowVersionViewAction.java,NONE,1.1 PackageCollectorAction.java,1.1,1.2 CollectAllAction.java,1.1,1.2 ClassCollectorAction.java,1.1,1.2

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

Modified Files:
	PackageCollectorAction.java CollectAllAction.java 
	ClassCollectorAction.java 
Added Files:
	ShowVersionViewAction.java 
Log Message:


--- NEW FILE: ShowVersionViewAction.java ---
/*****************************************************************************
 * Copyright (C) The Krysalis project. All rights reserved.                  *
 * ------------------------------------------------------------------------- *
 * This software is published under the terms of the Krysalis Patchy         *
 * Software License version 1.1_01, a copy of which has been included        *
 * at the bottom of this file.                                               *
 *****************************************************************************/

package org.krysalis.version.eclipse.plugin.actions;

import java.util.ArrayList;
import java.util.Iterator;

import org.eclipse.core.resources.IContainer;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.IAdaptable;
import org.eclipse.jface.action.IAction;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.ui.IObjectActionDelegate;
import org.eclipse.ui.IWorkbench;
import org.eclipse.ui.IWorkbenchPart;
import org.eclipse.ui.WorkbenchException;
import org.krysalis.version.collecting.collectors.PackageCollector;
import org.krysalis.version.eclipse.plugin.VersionPlugin;
import org.krysalis.version.eclipse.plugin.views.VersionView;

/**
 * @author Anou Manavalan
 *
 */
public class ShowVersionViewAction implements IObjectActionDelegate
{
	/** Progress with dialog. */
	public static final int PROGRESS_DIALOG = 1;
	/** Progress with budy cursor. */
	public static final int PROGRESS_BUSYCURSOR = 2;
	/** Stores the shell. */
	private Shell m_shell;
	/** Stores the selection. */
	private IStructuredSelection m_selection;

	/**
	 * Constructor for ShowVersionViewAction.
	 */
	public ShowVersionViewAction()
	{
		super();
	}

	/**
	 * @see org.eclipse.ui.IObjectActionDelegate#setActivePart(org.eclipse.jface.action.IAction, org.eclipse.ui.IWorkbenchPart)
	 */
	public void setActivePart(IAction action, IWorkbenchPart workBenchPart)
	{
		this.m_shell = workBenchPart.getSite().getShell();
	}

	/**
	 * @see org.eclipse.ui.IActionDelegate#run(org.eclipse.jface.action.IAction)
	 */
	public void run(IAction action)
	{
		System.out.println("ShowVersionViewAction::run");
		IContainer[] resources = getSelectedResources();
		if (resources == null || resources.length == 0)
		{
			return;
		}
		IWorkbench workb = VersionPlugin.getDefault().getWorkbench();
		try
		{
			workb.showPerspective("org.krysalis.version.VersionPerspective", workb.getActiveWorkbenchWindow());
		}
		catch (WorkbenchException e)
		{
			// @todo : exceptions!!!
			e.printStackTrace();
		}
		VersionView versionView = VersionView.openInActivePerspective();
		if (versionView != null)
		{
			String classpath = ""; // ::todo:: have to get it from each project
			versionView.setResource(classpath, new PackageCollector());
		}

	}

	/** Returns the selected resources.
	  *
	  * @return the selected resources
	  */
	protected IContainer[] getSelectedResources()
	{
		System.out.println("ShowVersionViewAction::getSelectedResources");
		ArrayList resources = null;
		if (!m_selection.isEmpty())
		{
			resources = new ArrayList();
			for (Iterator elements = getSelection().iterator(); elements.hasNext();)
			{
				Object next = elements.next();
				if (next instanceof IContainer)
				{
					resources.add(next);
					continue;
				}
				else if (next instanceof IAdaptable)
				{
					IAdaptable a = (IAdaptable) next;
					Object adapter = a.getAdapter(IContainer.class);
					if (adapter instanceof IContainer)
					{
						resources.add(adapter);
						continue;
					}
				}
			}
		}

		if (resources != null && !resources.isEmpty())
		{
			return (IContainer[]) resources.toArray(new IContainer[resources.size()]);
		}

		return new IContainer[0];
	}

	/** Returns the Shell object.
	  *
	  * @return the shell.
	  */
	protected Shell getShell()
	{
		if (m_shell != null)
		{
			return m_shell;
		}
		else
		{
			return VersionPlugin.getDefault().getWorkbench().getActiveWorkbenchWindow().getShell();
		}
	}
	/** @see IActionDelegate#selectionChanged(action, selection) */
	public void selectionChanged(IAction action, ISelection selection)
	{
		System.out.println("ShowVersionViewAction::selectionChanged");
		if (selection instanceof IStructuredSelection)
		{
			this.m_selection = (IStructuredSelection) selection;
			if (action != null)
			{
				try
				{
					action.setEnabled(isEnabled());
				}
				catch (Exception e)
				{
					action.setEnabled(false);
					e.printStackTrace();
					// ::todo:: exception
				}
			}
		}
	}

	/** @see TeamAction#isEnabled() */
	protected boolean isEnabled() throws Exception
	{
		System.out.println("ShowVersionViewAction::isEnabled");
		IResource[] resources = getSelectedResources();
		if (resources.length == 0)
		{
			return false;
		}

		for (int i = 0; i < resources.length; i++)
		{
			if (resources[i] == null || resources[i].getType() != IResource.FOLDER)
			{
				return false;
			}
		}
		return true;
	}

	/** Call this method to retrieve the current selection.
	  *
	  * @return the current selection.
	  */
	protected IStructuredSelection getSelection()
	{
		System.out.println("ShowVersionViewAction::getSelection");
		return m_selection;
	}

}
/*
The Krysalis Patchy Software License, Version 1.1_01
Copyright (c) 2002-2003  Nicola Ken Barozzi.  All rights reserved.

This Licence is compatible with the BSD licence as described and 
approved by http://www.opensource.org/, and is based on the
Apache Software Licence Version 1.1.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:

1. Redistributions of source code must retain the above copyright
 notice, this list of conditions and the following disclaimer.

2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in
the documentation and/or other materials provided with the
distribution.

3. The end-user documentation included with the redistribution,
if any, must include the following acknowledgment:
   "This product includes software developed for project 
	Krysalis (http://www.krysalis.org/)."
Alternately, this acknowledgment may appear in the software itself,
if and wherever such third-party acknowledgments normally appear.

4. The names "Krysalis" and "Nicola Ken Barozzi" and
"Krysalis Centipede" must not be used to endorse or promote products
derived from this software without prior written permission. For
written permission, please contact [email protected].

5. Products derived from this software may not be called "Krysalis",
"Krysalis Centipede", nor may "Krysalis" appear in their name,
without prior written permission of Nicola Ken Barozzi.

6. This software may contain voluntary contributions made by many 
individuals, who decided to donate the code to this project in
respect of this licence.

THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED.  IN NO EVENT SHALL THE KRYSALIS PROJECT OR
ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
SUCH DAMAGE.
====================================================================*/
Index: PackageCollectorAction.java
===================================================================
RCS file: /cvsroot/metamorphosis/krysalis-version/src/java/org/krysalis/version/eclipse/plugin/actions/PackageCollectorAction.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** PackageCollectorAction.java	11 Feb 2003 23:45:54 -0000	1.1
--- PackageCollectorAction.java	18 Feb 2003 18:24:39 -0000	1.2
***************
*** 60,63 ****
--- 60,64 ----
  	private void collect()
  	{
+ 		System.out.println("PackageCollectorAction::collect");
  		Collector oldInput = (Collector) m_viewer.getInput();
  		
***************
*** 65,69 ****
  		{
  			Collector input = new PackageCollector();
! 			m_viewer.setNewInput(input);
  			
  		}
--- 66,70 ----
  		{
  			Collector input = new PackageCollector();
! 			m_viewer.setResource("",input);
  			
  		}

Index: CollectAllAction.java
===================================================================
RCS file: /cvsroot/metamorphosis/krysalis-version/src/java/org/krysalis/version/eclipse/plugin/actions/CollectAllAction.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** CollectAllAction.java	11 Feb 2003 23:45:54 -0000	1.1
--- CollectAllAction.java	18 Feb 2003 18:24:40 -0000	1.2
***************
*** 59,62 ****
--- 59,63 ----
  	private void collect()
  	{
+ 		System.out.println("CollectAllAction::collect");
  		Collector oldInput = (Collector) m_viewer.getInput();
  		
***************
*** 64,68 ****
  		{
  			Collector input = new JarManifestCollector();
! 			m_viewer.setNewInput(input);
  			
  		}
--- 65,69 ----
  		{
  			Collector input = new JarManifestCollector();
! 			m_viewer.setResource("",input);
  			
  		}

Index: ClassCollectorAction.java
===================================================================
RCS file: /cvsroot/metamorphosis/krysalis-version/src/java/org/krysalis/version/eclipse/plugin/actions/ClassCollectorAction.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** ClassCollectorAction.java	11 Feb 2003 23:45:54 -0000	1.1
--- ClassCollectorAction.java	18 Feb 2003 18:24:40 -0000	1.2
***************
*** 58,61 ****
--- 58,62 ----
  	private void collect()
  	{
+ 		System.out.println("ClassCollectorAction::collect");
  		Collector oldInput = (Collector) m_viewer.getInput();
  		
***************
*** 63,67 ****
  		{
  			Collector input = new VersionBrandCollector();
! 			m_viewer.setNewInput(input);
  			
  		}
--- 64,68 ----
  		{
  			Collector input = new VersionBrandCollector();
! 			m_viewer.setResource("",input);
  			
  		}




-------------------------------------------------------
This sf.net email is sponsored by:ThinkGeek
Welcome to geek heaven.
http://thinkgeek.com/sf
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.