diff --git a/src/main/java/spdxedit/Main.java b/src/main/java/spdxedit/Main.java index 6ac0fe5..40c563f 100644 --- a/src/main/java/spdxedit/Main.java +++ b/src/main/java/spdxedit/Main.java @@ -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 { diff --git a/src/main/java/spdxedit/MainSceneController.java b/src/main/java/spdxedit/MainSceneController.java index ff55e94..3ce3370 100644 --- a/src/main/java/spdxedit/MainSceneController.java +++ b/src/main/java/spdxedit/MainSceneController.java @@ -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; @@ -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; diff --git a/src/main/java/spdxedit/NewPackageDialog.java b/src/main/java/spdxedit/NewPackageDialog.java index 15de9e4..6555831 100644 --- a/src/main/java/spdxedit/NewPackageDialog.java +++ b/src/main/java/spdxedit/NewPackageDialog.java @@ -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; diff --git a/src/main/java/spdxedit/PackageEditor.java b/src/main/java/spdxedit/PackageEditor.java index f72765d..2af927c 100644 --- a/src/main/java/spdxedit/PackageEditor.java +++ b/src/main/java/spdxedit/PackageEditor.java @@ -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; @@ -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; @@ -80,10 +80,6 @@ public class PackageEditor { @FXML private TitledPane tabPackageProperties; - @FXML - private PropertySheet pkgPropertySheet; - - @FXML private TitledPane tabExternalRefs; @@ -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()); @@ -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 @@ -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); } @@ -327,9 +319,9 @@ public static void editPackage(final SpdxPackage pkg, final List 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. @@ -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()); @@ -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 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); } } diff --git a/src/main/java/spdxedit/PackagePropertyEditor.java b/src/main/java/spdxedit/PackagePropertyEditor.java new file mode 100644 index 0000000..ef30f3a --- /dev/null +++ b/src/main/java/spdxedit/PackagePropertyEditor.java @@ -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 rows = ImmutableList.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 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 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); + } + + +} diff --git a/src/main/java/spdxedit/SpdxLogic.java b/src/main/java/spdxedit/SpdxLogic.java index 5676f3d..333f728 100644 --- a/src/main/java/spdxedit/SpdxLogic.java +++ b/src/main/java/spdxedit/SpdxLogic.java @@ -346,11 +346,6 @@ public static void removeFilesFromPackage(SpdxPackage pkg, List filesT } } - // Properties of a package that can be edited on the properties tab. - // TODO: Create editors, pretty names, etc. - static final Set 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 diff --git a/src/main/java/spdxedit/externalRef/ExternalRefListControl.java b/src/main/java/spdxedit/externalRef/ExternalRefListControl.java index 9d063d8..4616a0e 100644 --- a/src/main/java/spdxedit/externalRef/ExternalRefListControl.java +++ b/src/main/java/spdxedit/externalRef/ExternalRefListControl.java @@ -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 { @@ -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); diff --git a/src/main/java/spdxedit/license/FileLicenseEditor.java b/src/main/java/spdxedit/license/FileLicenseEditor.java index 8341166..d481afc 100644 --- a/src/main/java/spdxedit/license/FileLicenseEditor.java +++ b/src/main/java/spdxedit/license/FileLicenseEditor.java @@ -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; @@ -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; diff --git a/src/main/java/spdxedit/UiUtils.java b/src/main/java/spdxedit/util/UiUtils.java similarity index 63% rename from src/main/java/spdxedit/UiUtils.java rename to src/main/java/spdxedit/util/UiUtils.java index 1e04049..0fa5178 100644 --- a/src/main/java/spdxedit/UiUtils.java +++ b/src/main/java/spdxedit/util/UiUtils.java @@ -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 @@ -23,4 +26,14 @@ public static Dialog 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; + } } diff --git a/src/main/resources/ExternalRefList.fxml b/src/main/resources/ExternalRefList.fxml index 35b3156..09e50f7 100644 --- a/src/main/resources/ExternalRefList.fxml +++ b/src/main/resources/ExternalRefList.fxml @@ -6,11 +6,11 @@ - + - +