Skip to content

Commit

Permalink
Cleaning up package editing, fixing omitted editing for version info.
Browse files Browse the repository at this point in the history
  • Loading branch information
yevster committed Sep 24, 2016
1 parent a9e018a commit 9714b10
Show file tree
Hide file tree
Showing 11 changed files with 151 additions and 50 deletions.
1 change: 1 addition & 0 deletions src/main/java/spdxedit/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.stage.Stage;
import spdxedit.util.UiUtils;

public class Main extends Application {

Expand Down
6 changes: 1 addition & 5 deletions src/main/java/spdxedit/MainSceneController.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
package spdxedit;

import antlr.RecognitionException;
import antlr.TokenStreamException;
import com.google.common.base.Joiner;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.scene.control.*;
import javafx.scene.image.ImageView;
import javafx.scene.input.MouseEvent;
import javafx.scene.layout.GridPane;
import javafx.scene.layout.Priority;
Expand All @@ -24,7 +20,7 @@
import org.spdx.rdfparser.model.SpdxPackage;
import org.spdx.tag.CommonCode;
import org.spdx.tools.TagToRDF;
import spdxedit.license.FileLicenseEditor;
import spdxedit.util.UiUtils;

import java.io.*;
import java.nio.file.Files;
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/spdxedit/NewPackageDialog.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@
import javafx.scene.layout.Pane;
import javafx.stage.Modality;
import javafx.stage.Stage;
import javafx.stage.StageStyle;
import javafx.stage.Window;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.spdx.rdfparser.SpdxDocumentContainer;
import org.spdx.rdfparser.model.SpdxPackage;
import spdxedit.license.LicenseEditControl;
import spdxedit.util.UiUtils;

import java.io.IOException;
import java.nio.file.Path;
Expand Down
38 changes: 15 additions & 23 deletions src/main/java/spdxedit/PackageEditor.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,17 @@
import javafx.collections.ListChangeListener;
import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.scene.Node;
import javafx.geometry.Insets;
import javafx.scene.Scene;
import javafx.scene.control.*;
import javafx.scene.input.MouseEvent;
import javafx.scene.layout.AnchorPane;
import javafx.scene.layout.Pane;
import javafx.stage.*;
import javafx.util.StringConverter;
import org.apache.commons.lang3.ArrayUtils;
import org.apache.commons.lang3.StringUtils;
import org.controlsfx.control.CheckListView;
import org.controlsfx.control.PropertySheet;
import org.controlsfx.property.BeanPropertyUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.spdx.rdfparser.InvalidSPDXAnalysisException;
Expand All @@ -32,6 +31,7 @@
import spdxedit.license.LicenseEditControl;
import spdxedit.license.SpdxWithoutExeption;
import spdxedit.util.StringableWrapper;
import spdxedit.util.UiUtils;

import java.io.File;
import java.io.IOException;
Expand Down Expand Up @@ -80,10 +80,6 @@ public class PackageEditor {
@FXML
private TitledPane tabPackageProperties;

@FXML
private PropertySheet pkgPropertySheet;


@FXML
private TitledPane tabExternalRefs;

Expand Down Expand Up @@ -221,13 +217,6 @@ private void initialize() {
assert btnRemoveRelationship != null : "fx:id=\"btnRemoveRelationship\" was not injected: check your FXML file 'PackageEditor.fxml'.";


//Package properties
assert pkgPropertySheet != null : "fx:id=\"pkgPropertySheet\" was not injected: check your FXML file 'PackageEditor.fxml'.";
pkgPropertySheet.setSearchBoxVisible(false);
pkgPropertySheet.setMode(PropertySheet.Mode.NAME);
pkgPropertySheet.setModeSwitcherVisible(false);


//Initialize package relationship controls
lstTargetPackages.getSelectionModel().selectedItemProperty().addListener((observable1, oldValue1, newValue1) -> handleTargetPackageSelected(newValue1));
lstTargetPackages.setCellFactory(listView -> new MainSceneController.SpdxPackageListCell());
Expand All @@ -245,7 +234,7 @@ private void initialize() {
RelationshipType.PREREQUISITE_FOR,
RelationshipType.STATIC_LINK,
RelationshipType.OTHER
)
)
.collect(Collectors.toList()));
chcNewRelationshipType.getSelectionModel().selectFirst();
assert (otherPackages != null); //Constructor finished executing
Expand Down Expand Up @@ -279,9 +268,12 @@ private void initialize() {
filesTable.getSelectionModel().setSelectionMode(SelectionMode.MULTIPLE);
filesTable.setShowRoot(false);

Node externalRefControl = new ExternalRefListControl(pkg).getUi();
AnchorPane externalRefControl = new ExternalRefListControl(pkg).getUi();
externalRefControl.setPadding(new Insets(12, 10, 5, 10));
tabExternalRefs.setContent(externalRefControl);
externalRefControl.setManaged(true);

new PackagePropertyEditor(pkg).initialize(tabPackageProperties);

}

Expand Down Expand Up @@ -327,9 +319,9 @@ public static void editPackage(final SpdxPackage pkg, final List<SpdxPackage> re
} catch (InvalidSPDXAnalysisException e) {
logger.error("Unable to get files for package " + pkg.getName(), e);
}
packageEditor.pkgPropertySheet.getItems().setAll(BeanPropertyUtils.getProperties(pkg, propertyDescriptor ->
SpdxLogic.EDITABLE_PACKAGE_PROPERTIES.contains(propertyDescriptor.getName())));

packageEditor.tabFiles.setExpanded(true);

});

//Won't assign this event through FXML - don't want to propagate the stage beyond this point.
Expand Down Expand Up @@ -419,7 +411,7 @@ public void handleAddFileClick(MouseEvent event) {
FileChooser chooser = new FileChooser();
chooser.setTitle("Add file");
File file = chooser.showOpenDialog(btnAddFile.getParent().getScene().getWindow());
if (file==null) //Dialog cancelled.
if (file == null) //Dialog cancelled.
return;
Path path = Paths.get(file.getAbsolutePath());
SpdxLogic.addFileToPackage(pkg, path, file.toURI().toString());
Expand Down Expand Up @@ -476,21 +468,21 @@ private void handleChkExcludeFileChange(boolean newValue) {
}
}

public void handleBtnCopyrightClick(MouseEvent event){
public void handleBtnCopyrightClick(MouseEvent event) {
String oldCopyright = currentFile.getCopyrightText();
TextInputDialog dialog = new TextInputDialog();
dialog.setTitle("Copyright");
dialog.setHeaderText("Enter the copyright text");
((Stage)dialog.getDialogPane().getScene().getWindow()).getIcons().addAll(UiUtils.ICON_IMAGE_VIEW.getImage());
((Stage) dialog.getDialogPane().getScene().getWindow()).getIcons().addAll(UiUtils.ICON_IMAGE_VIEW.getImage());
Optional<String> newCopyrightText = dialog.showAndWait();
if (newCopyrightText.isPresent()){
if (newCopyrightText.isPresent()) {
currentFile.setCopyrightText(newCopyrightText.get());
}

}


public void handleBtnFileLicenseClick(MouseEvent event){
public void handleBtnFileLicenseClick(MouseEvent event) {
FileLicenseEditor.editConcludedLicense(this.currentFile, documentContainer);
}
}
112 changes: 112 additions & 0 deletions src/main/java/spdxedit/PackagePropertyEditor.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
package spdxedit;

import com.google.common.collect.ImmutableList;
import javafx.geometry.Insets;
import javafx.geometry.Pos;
import javafx.scene.Node;
import javafx.scene.control.*;
import javafx.scene.layout.*;
import org.spdx.rdfparser.model.SpdxPackage;
import spdxedit.util.UiUtils;

import java.util.List;
import java.util.function.Consumer;

/**
* Created by yevster on 9/23/16.
*/
public class PackagePropertyEditor {
private final SpdxPackage spdxPackage;

final static int rowHeight = 66;
final static int left = 45;
final static int fieldLeft = 160;


public PackagePropertyEditor(SpdxPackage pkg) {
this.spdxPackage = pkg;

}

public void initialize(TitledPane parentContainer) {
AnchorPane control = new AnchorPane();

parentContainer.setContent(control);
int top = 40;

VBox vbox = new VBox();
control.getChildren().addAll(vbox);
AnchorPane.setBottomAnchor(vbox,0D);
AnchorPane.setTopAnchor(vbox,0D);
AnchorPane.setLeftAnchor(vbox,0D);
AnchorPane.setRightAnchor(vbox,0D);

vbox.setPadding(new Insets(20));
vbox.setSpacing(11);

List<Pane> rows = ImmutableList.<Pane>builder().add(createTextBoxEditor("Version Info:", spdxPackage.getVersionInfo(), spdxPackage::setVersionInfo, top += rowHeight),
createTextAreaEditor("Description:", spdxPackage.getDescription(), spdxPackage::setDescription, top += rowHeight),
createTextBoxEditor("Summary:", spdxPackage.getSummary(), spdxPackage::setSummary, top += rowHeight),
createTextBoxEditor("Download Location:", spdxPackage.getDownloadLocation(), spdxPackage::setDownloadLocation, top += rowHeight),
createTextBoxEditor("Source Info:", spdxPackage.getSourceInfo(), spdxPackage::setSourceInfo, top += rowHeight),
createTextBoxEditor("Copyright Text:", spdxPackage.getCopyrightText(), spdxPackage::setCopyrightText, top += rowHeight),
createTextBoxEditor("Package File Name:", spdxPackage.getPackageFileName(), spdxPackage::setPackageFileName, top += rowHeight),
createTextBoxEditor("Homepage:", spdxPackage.getHomepage(), spdxPackage::setHomepage, top += rowHeight),
createTextBoxEditor("Originator:", spdxPackage.getOriginator(), spdxPackage::setOriginator, top += rowHeight),
createTextBoxEditor("Supplier:", spdxPackage.getSupplier(), spdxPackage::setSupplier, top += rowHeight)).build();
vbox.getChildren().addAll(rows);

rows.stream().map(Pane::getChildren).flatMap(List::stream).filter(n -> n instanceof TextField).forEach(Node::autosize);
rows.forEach(Node::autosize);
}

private static final Pane createTextBoxEditor(String label, String value, Consumer<String> onUpdate, int top) {

HBox box = new HBox();
box.setPrefWidth(Double.MAX_VALUE);
box.setMaxWidth(Double.MAX_VALUE);
box.setAlignment(Pos.CENTER_LEFT);
box.setSpacing(2);
TextField result = new TextField(value);

result.setMinWidth(750);
result.setMaxWidth(Double.MAX_VALUE);
result.setLayoutX(fieldLeft);
result.setLayoutY(top);
result.textProperty().addListener((observable, oldValue, newValue) -> onUpdate.accept(newValue));
AnchorPane ap = UiUtils.wrapInAnchor(result);

Label l = new Label(label);
l.setMinWidth(fieldLeft);
box.getChildren().addAll(l, ap);

return UiUtils.wrapInAnchor(box);
}

private static final Pane createTextAreaEditor(String label, String value, Consumer<String> onUpdate, int top) {

HBox box = new HBox();
box.setPrefWidth(Double.MAX_VALUE);
box.setMaxWidth(Double.MAX_VALUE);
box.setAlignment(Pos.CENTER_LEFT);
box.setSpacing(2);
TextArea result = new TextArea(value);

result.setMinWidth(750);
result.setMaxWidth(Double.MAX_VALUE);
result.setLayoutX(fieldLeft);
result.setLayoutY(top);
result.setMinHeight(rowHeight);
result.setWrapText(true);
result.textProperty().addListener((observable, oldValue, newValue) -> onUpdate.accept(newValue));
AnchorPane ap = UiUtils.wrapInAnchor(result);

Label l = new Label(label);
l.setMinWidth(fieldLeft);
box.getChildren().addAll(l, ap);

return UiUtils.wrapInAnchor(box);
}


}
5 changes: 0 additions & 5 deletions src/main/java/spdxedit/SpdxLogic.java
Original file line number Diff line number Diff line change
Expand Up @@ -346,11 +346,6 @@ public static void removeFilesFromPackage(SpdxPackage pkg, List<SpdxFile> filesT
}
}

// Properties of a package that can be edited on the properties tab.
// TODO: Create editors, pretty names, etc.
static final Set<String> EDITABLE_PACKAGE_PROPERTIES = ImmutableSet.of("description", "copyrightText",
"downloadLocation", "packageFileName", "homepage", "originator", "packageFileName", "summary", "supplier",
"versionInfo", "comment", "sourceInfo");

/**
* Utility method to make verification code use in stream processing not
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ protected ExternalReferenceCell() {
txtRefType.setMinWidth(300);
txtRefType.setMaxWidth(300);
txtLocator.setMaxWidth(Double.MAX_VALUE);
txtLocator.setMinWidth(340);

txtRefType.textProperty().addListener((observable, oldValue, newValue) -> {
try {
Expand Down Expand Up @@ -143,7 +144,7 @@ void initialize() {
}
}

public Node getUi() {
public AnchorPane getUi() {
try {
FXMLLoader loader = new FXMLLoader(ExternalRefListControl.class.getResource("/ExternalRefList.fxml"));
loader.setController(this);
Expand Down
4 changes: 1 addition & 3 deletions src/main/java/spdxedit/license/FileLicenseEditor.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@
import javafx.scene.control.Alert;
import javafx.scene.control.ButtonType;
import javafx.scene.control.Dialog;
import javafx.scene.control.DialogPane;
import javafx.stage.Stage;
import javafx.stage.StageStyle;
import org.apache.commons.lang3.StringUtils;
import org.spdx.rdfparser.InvalidSPDXAnalysisException;
import org.spdx.rdfparser.SpdxDocumentContainer;
Expand All @@ -15,7 +13,7 @@
import org.spdx.rdfparser.model.SpdxFile;
import spdxedit.Main;
import spdxedit.SpdxLogic;
import spdxedit.UiUtils;
import spdxedit.util.UiUtils;

import java.util.Arrays;
import java.util.Optional;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
package spdxedit;
package spdxedit.util;

import javafx.scene.Node;
import javafx.scene.control.ButtonType;
import javafx.scene.control.Dialog;
import javafx.scene.image.ImageView;
import javafx.scene.layout.AnchorPane;
import javafx.stage.Modality;
import javafx.stage.Stage;
import spdxedit.MainSceneController;

/**
* Common UI utilities
Expand All @@ -23,4 +26,14 @@ public static <T> Dialog<T> newDialog(String title, ButtonType...buttonTypes){
((Stage)result.getDialogPane().getScene().getWindow()).getIcons().addAll(ICON_IMAGE_VIEW.getImage());
return result;
}

public static AnchorPane wrapInAnchor(Node control){
AnchorPane result = new AnchorPane();
result.getChildren().addAll(control);
AnchorPane.setRightAnchor(control, 0D);
AnchorPane.setLeftAnchor(control, 0D);
AnchorPane.setTopAnchor(control, 0D);
AnchorPane.setBottomAnchor(control, 0D);
return result;
}
}
4 changes: 2 additions & 2 deletions src/main/resources/ExternalRefList.fxml
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@
<?import javafx.scene.control.ListView?>
<?import javafx.scene.layout.AnchorPane?>

<AnchorPane maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" minHeight="-Infinity" minWidth="-Infinity" prefHeight="450.0" prefWidth="666.0" xmlns="http://javafx.com/javafx/8.0.60" xmlns:fx="http://javafx.com/fxml/1">
<AnchorPane maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" minHeight="-Infinity" minWidth="-Infinity" prefHeight="421.0" prefWidth="666.0" xmlns="http://javafx.com/javafx/8.0.65" xmlns:fx="http://javafx.com/fxml/1">

<children>
<ListView fx:id="lstExternalRefs" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" prefHeight="360.0" prefWidth="666.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0" />
<ButtonBar maxWidth="1.7976931348623157E308" prefHeight="40.0" prefWidth="200.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="410.0">
<ButtonBar layoutY="354.0" maxWidth="1.7976931348623157E308" prefHeight="46.0" prefWidth="666.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0">
<buttons>
<Button fx:id="btnAdd" minWidth="65.0" mnemonicParsing="false" prefHeight="25.0" text="Add..." />
<Button fx:id="btnRemove" mnemonicParsing="false" text="Remove" />
Expand Down
11 changes: 2 additions & 9 deletions src/main/resources/PackageEditor.fxml
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,13 @@
<?import javafx.scene.layout.AnchorPane?>
<?import javafx.scene.layout.Pane?>
<?import org.controlsfx.control.CheckListView?>
<?import org.controlsfx.control.PropertySheet?>

<Pane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="624.0" prefWidth="1020.0" xmlns="http://javafx.com/javafx/8.0.60" xmlns:fx="http://javafx.com/fxml/1">


<Pane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="624.0" prefWidth="1020.0" xmlns="http://javafx.com/javafx/8.0.65" xmlns:fx="http://javafx.com/fxml/1">
<Accordion maxHeight="-Infinity" maxWidth="1.7976931348623157E308" minHeight="-Infinity" minWidth="-Infinity" prefHeight="564.0" prefWidth="1020.0">
<panes>
<TitledPane fx:id="tabPackageProperties" animated="false" text="Package">
<content>
<AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="180.0" prefWidth="200.0">
<children>
<PropertySheet fx:id="pkgPropertySheet" layoutX="1.0" layoutY="-1.0" prefHeight="348.0" prefWidth="937.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0" />
</children>
</AnchorPane>
<AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="180.0" prefWidth="200.0" />
</content>
</TitledPane>
<TitledPane fx:id="tabPkgLicenses" animated="false" prefHeight="422.0" prefWidth="1029.0" text="Package License">
Expand Down

0 comments on commit 9714b10

Please sign in to comment.