/**
* SPDXVersion: SPDX-1.1
* Creator: Person: Nuno Brito (nuno.brito@triplecheck.de)
* Creator: Organization: TripleCheck (http://triplecheck.de)
* Created: 2013-12-15T00:00:00Z
* LicenseName: NOASSERTION
* FileName: TreeNodeDetails.java
* FileType: SOURCE
* FileCopyrightText: <text> Copyright (c) 2013 Nuno Brito, TripleCheck </text>
* FileComment: <text> This plugin adds up more details on the tree view
* whenever the user clicks on a given SPDX document </text>
*/
package basic;
import GUI.NodeType;
import GUI.TreeNodeSPDX;
import GUI.swingUtils;
import definitions.Messages;
import definitions.is;
import java.io.File;
import java.util.Enumeration;
import main.core;
import main.param;
import script.Plugin;
import script.log;
import spdxlib.Person;
import spdxlib.SPDXfile;
/**
*
* @author Nuno Brito, 15th of December 2013 in Darsmtadt, Germany
*/
public class TreeNodeDetails extends Plugin{
@Override
public void startup(){
// react whenever a tree node is changed
log.hooks.addAction(Messages.TreeNodeChanged, thisFile, "react");
}
/**
* Displays a basic list of tools that are supported
*/
public void react(){ // ensure we get to know which node is selected
TreeNodeSPDX node = swingUtils.getSelectedNode();
// no need to continue if there is nothing selected
if(node == null){
return;
}
// we only want SPDX documents from this point forward
if(node.nodeType != NodeType.SPDX){
return;
}
// SPDX nodes only come with a single param, easy to get
String[] parameter = node.scriptParameters.get(0);
// check if this is really what I want
if(parameter[0].equals(param.spdx)==false){
log.write(is.ERROR, "TN01 - Was expecting to find the first parameter "
+ " of the SPDX tree node defining the SPDX document file "
+ "path on %1", node.getUID());
return;
}
// get the relative name of this file
String spdxRelativePath = parameter[1];
// now we get the file point, it needs to exist before we continue
File spdxFile = new File(core.getProductsFolder(), spdxRelativePath);
if(spdxFile.exists() == false){
log.write(is.NOTFOUND, "TN02 - Unable to find file %1",
spdxFile.getAbsolutePath());
return;
}
// now read the SPDX document
SPDXfile spdx = new SPDXfile(spdxFile);
// basic parts were done, now add up the needed details
addPeople(spdx, node);
}
/**
* When necessary, add nodes listing the people that have created the SPDX
* document. If these nodes were already created, do nothing
*/
private void addPeople(SPDXfile spdx, TreeNodeSPDX spdxNode){
Enumeration list = spdxNode.children();
while(list.hasMoreElements()){
TreeNodeSPDX child = (TreeNodeSPDX) list.nextElement();
if(child.nodeType == NodeType.sectionCreator){
// no need to continue, people were already listed
return;
}
}
// let's add people, this is our main node
TreeNodeSPDX node = swingUtils.nodeCreate("SPDX author",
NodeType.sectionCreator, spdxNode);
node.nodeType = NodeType.sectionCreator;
node.id = "SPDX author";
node.setUserObject(spdx.creatorSection);
// create now a node for each author
for(Person person : spdx.creatorSection.people){
TreeNodeSPDX nodePerson = swingUtils.addNodePerson(node, person);
// add here the action we want to happen when clicked
File scriptFile = new File(core.getPluginsFolder(), "/people/show.java");
nodePerson.scriptFile = scriptFile;
nodePerson.scriptFolder = scriptFile.getParentFile();
nodePerson.scriptMethod = "details";
// create the correct parameters
String relativePath =
spdx.file.getAbsolutePath().replace(core.getProductsFolder().getAbsolutePath(), "");
// add the SPDX that we want to edit/show
nodePerson.scriptParameters.add(new String[]{param.spdx, relativePath});
// add the user name that we want to edit
nodePerson.scriptParameters.add(new String[]{param.filter, person.getTitle()});
}
// all done, time to refresh things up
swingUtils.setSelectedNode(spdxNode.getUID());
// refresh things up
core.studio.getTree().repaint();
}
}