Update of /cvsroot/metamorphosis/krysalis-version/src/java/org/krysalis/version/eclipse/plugin/views
In directory sc8-pr-cvs1:/tmp/cvs-serv13187/src/java/org/krysalis/version/eclipse/plugin/views
Added Files:
VersionListViewer.java VersionView.java
Log Message:
Back into one project...
--- NEW FILE: VersionListViewer.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.views;
import org.eclipse.jface.viewers.ListViewer;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.List;
import org.krysalis.version.collecting.EntryCollection;
import org.krysalis.version.collecting.Collector;
/**
* @author Anou Manavalan
*
*/
public class VersionListViewer extends ListViewer
{
/**
* Constructor for VersionListViewer.
* @param arg0
*/
public VersionListViewer(Composite arg0)
{
super(arg0);
}
/**
* Constructor for VersionListViewer.
* @param arg0
* @param arg1
*/
public VersionListViewer(Composite arg0, int arg1)
{
super(arg0, arg1);
}
/**
* Constructor for VersionListViewer.
* @param arg0
*/
public VersionListViewer(List arg0)
{
super(arg0);
}
private Object[] getInputElements(Collector input)
{
try
{
EntryCollection tree = input.collect();
if(tree == null)
return new Object[0];
if(tree.isEmpty())
{
System.out.println("Empty tree");
return new Object[0];
}
System.out.println("Tree name is " + tree.getName());
System.out.println("Tree size is " + tree.size() );
return input.collect().toArray();
}
catch(Exception exp)
{
System.out.println("Exception in getting the elements " + exp );
// log the exception
}
return new Object[0];
}
}
/*
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.
====================================================================*/
--- NEW FILE: VersionView.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.views;
import java.net.MalformedURLException;
import java.net.URL;
import org.eclipse.jface.action.IMenuListener;
import org.eclipse.jface.action.IMenuManager;
import org.eclipse.jface.action.IToolBarManager;
import org.eclipse.jface.action.MenuManager;
import org.eclipse.jface.action.Separator;
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.jface.viewers.LabelProvider;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Menu;
import org.eclipse.ui.IViewSite;
import org.eclipse.ui.PartInitException;
import org.eclipse.ui.part.ViewPart;
import org.krysalis.version.collecting.Collector;
import org.krysalis.version.collecting.EntryCollection;
import org.krysalis.version.collecting.collectors.PackageCollector;
import org.krysalis.version.eclipse.plugin.VersionPlugin;
import org.krysalis.version.eclipse.plugin.actions.ClassCollectorAction;
import org.krysalis.version.eclipse.plugin.actions.CollectAllAction;
import org.krysalis.version.eclipse.plugin.actions.PackageCollectorAction;
import org.krysalis.version.eclipse.plugin.model.VersionContentProvider;
import org.krysalis.version.loading.VersionLoadContext;
/**
* A VersionView shows a bunch of words.
*/
public class VersionView extends ViewPart
{
Collector m_input;
VersionListViewer m_viewer;
PackageCollectorAction m_packageCollectorAction;
ClassCollectorAction m_classCollectorAction;
CollectAllAction m_collectAllAction;
/**
* Constructor
*/
public VersionView()
{
super();
//input = new VersionFile(new File("list.lst"));
m_input = new PackageCollector();
}
/**
* @see IViewPart.init(IViewSite)
*/
public void init(IViewSite site) throws PartInitException
{
super.init(site);
}
/**
* @see IWorkbenchPart#createPartControl(Composite)
*/
public void createPartControl(Composite parent)
{
// Create viewer.
m_viewer = new VersionListViewer(parent);
m_viewer.setContentProvider(new VersionContentProvider());
m_viewer.setLabelProvider(new LabelProvider());
setNewInput(m_input);
getSite().setSelectionProvider(m_viewer);
// Create menu and toolbars.
createActions();
createMenu();
createToolbar();
createContextMenu();
}
public void setNewInput(Collector input)
{
m_input = input;
m_viewer.setInput(m_input);
m_viewer.add(getInputElements());
}
public void clearView()
{
//m_viewer.remove(getInputElements());
}
private Object[] getInputElements()
{
Object[] returnObjArray;
try
{
EntryCollection tree = m_input.collect();
if (tree == null)
return new Object[0];
if (tree.isEmpty())
{
System.out.println("Empty tree");
return new Object[0];
}
System.out.println("Tree name is " + tree.getName());
System.out.println("Tree size is " + tree.size());
returnObjArray = new Object[tree.size()];
for(int i = 0; i < tree.size(); i++)
{
returnObjArray[i] = ((VersionLoadContext)tree.get(i)).getVersion();
}
return returnObjArray;
}
catch (Exception exp)
{
System.out.println("Exception in getting the elements " + exp);
// log the exception
returnObjArray = new Object[0];
}
return returnObjArray;
}
/**
* @see WorkbenchPart#setFocus()
*/
public void setFocus()
{
m_viewer.getControl().setFocus();
}
/**
* Create the actions.
*/
public void createActions()
{
m_packageCollectorAction = new PackageCollectorAction("PackageVersion", this);
m_packageCollectorAction.setImageDescriptor(getImageDescriptor("packages.gif"));
m_classCollectorAction = new ClassCollectorAction("ClassVersion",this);
m_classCollectorAction.setImageDescriptor(getImageDescriptor("class_hi.gif"));
m_collectAllAction = new CollectAllAction("JarManifestVersion", this);
m_collectAllAction.setImageDescriptor(getImageDescriptor("jar_desc_obj.gif"));
}
/**
* Returns the image descriptor with the given relative path.
*/
private ImageDescriptor getImageDescriptor(String relativePath)
{
String iconPath = "icons/";
try
{
VersionPlugin plugin = VersionPlugin.getDefault();
URL installURL = plugin.getDescriptor().getInstallURL();
URL url = new URL(installURL, iconPath + relativePath);
return ImageDescriptor.createFromURL(url);
}
catch (MalformedURLException e)
{
// should not happen
return ImageDescriptor.getMissingImageDescriptor();
}
}
/**
* Create menu.
*/
private void createMenu()
{
IMenuManager mgr = getViewSite().getActionBars().getMenuManager();
mgr.add(m_packageCollectorAction);
mgr.add(m_classCollectorAction);
mgr.add(m_collectAllAction);
}
/**
* Create toolbar.
*/
private void createToolbar()
{
IToolBarManager mgr = getViewSite().getActionBars().getToolBarManager();
mgr.add(m_packageCollectorAction);
mgr.add(m_classCollectorAction);
mgr.add(m_collectAllAction);
}
/**
* Create context menu.
*/
private void createContextMenu()
{
// Create menu manager.
MenuManager menuMgr = new MenuManager();
menuMgr.setRemoveAllWhenShown(true);
menuMgr.addMenuListener(new IMenuListener()
{
public void menuAboutToShow(IMenuManager mgr)
{
fillContextMenu(mgr);
}
});
// Create menu.
Menu menu = menuMgr.createContextMenu(m_viewer.getControl());
m_viewer.getControl().setMenu(menu);
// Register menu for extension.
getSite().registerContextMenu(menuMgr, m_viewer);
}
private void fillContextMenu(IMenuManager mgr)
{
mgr.add(m_packageCollectorAction);
mgr.add(new Separator());
mgr.add(m_classCollectorAction);
mgr.add(new Separator());
mgr.add(m_collectAllAction);
}
/**
* Returns the input.
* @return Collector
*/
public Collector getInput()
{
return m_input;
}
/**
* Returns the viewer.
* @return VersionListViewer
*/
public VersionListViewer getViewer()
{
return m_viewer;
}
/**
* Sets the input.
* @param input The input to set
*/
public void setInput(Collector input)
{
m_input = input;
}
/**
* Sets the viewer.
* @param viewer The viewer to set
*/
public void setViewer(VersionListViewer viewer)
{
m_viewer = viewer;
}
}
/*
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.
====================================================================*/
-------------------------------------------------------
This SF.NET email is sponsored by:
SourceForge Enterprise Edition + IBM + LinuxWorld = Something 2 See!
http://www.vasoftware.com
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.