Child: [r13] (diff)

Download this file

TreeNodeDetails.java    136 lines (113 with data), 4.8 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
/**
* 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();
}
}