Skip to content

Commit

Permalink
#164 Set default values
Browse files Browse the repository at this point in the history
Set default initial value of the import path to the current import
project.
Do not allow empty content for the target path.
Adapt test accordingly.

Change-Id: I0000000000000000000000000000000000000000
Signed-off-by: Arnaud Dieumegard <arnaud.dieumegard@obeo.fr>
  • Loading branch information
arnauddieumegard authored and pdulth committed Jul 21, 2022
1 parent 5b71dfc commit 3fa23dd
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -64,15 +64,16 @@ protected Control createDialogArea(Composite parent) {

protected void setUpRelPathUI(Composite container, Composite importingModesComposite) {
Label relativePathTextChoice = new Label(importingModesComposite, SWT.SINGLE);
relativePathTextChoice.setText("Path to image folder that is relative to the current project:");
relativePathTextChoice.setText(Messages.ImageImportingDialog_RelativePathLabel);
GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).applyTo(relativePathTextChoice);

relativePathText = new Text(importingModesComposite, SWT.SINGLE | SWT.BORDER);
relativePathText.setText(currentProject.getName() + "/");
relativePathText.addModifyListener(e -> {
String currentProjectLocation = currentProject.getLocation().toString();
Path currentProjectPath = Paths.get(currentProjectLocation);
if (!currentProjectPath.resolve(relativePathText.getText()).toFile().exists()) {
setErrorMessage("The relative path does not point to a valid folder.");
String currentProjectParentLocation = currentProject.getLocation().removeLastSegments(1).toString();
Path currentProjectParentPath = Paths.get(currentProjectParentLocation);
if (relativePathText.getText() == "" || !currentProjectParentPath.resolve(relativePathText.getText()).toFile().exists()) {
setErrorMessage(Messages.ImageImportingDialog_RelativePathErrorMessage);
disableFinish();
} else {
enableFinishForRelPath();
Expand All @@ -87,13 +88,14 @@ protected void setUpRelPathUI(Composite container, Composite importingModesCompo
public void widgetSelected(SelectionEvent e) {
DirectoryDialog dialog = new DirectoryDialog(container.getShell());
String currentProjectLocation = currentProject.getLocation().toString();
String currentProjectParentLocation = currentProject.getLocation().removeLastSegments(1).toString();
dialog.setFilterPath(currentProjectLocation);
String result = dialog.open();
if (result != null) {
URI resultPath = Paths.get(result).toUri();
URI currentProjectPath = Paths.get(currentProjectLocation).toUri();
if (resultPath.toString().startsWith(currentProjectPath.toString())) {
URI relativizedPath = currentProjectPath.relativize(resultPath);
URI currentProjectParentPath = Paths.get(currentProjectParentLocation).toUri();
if (resultPath.toString().startsWith(currentProjectParentPath.toString())) {
URI relativizedPath = currentProjectParentPath.relativize(resultPath);
relativePathText.setText(relativizedPath.getPath());
} else {
relativePathText.setText("");
Expand All @@ -106,7 +108,6 @@ public void widgetSelected(SelectionEvent e) {
}

protected void enableFinishForRelPath() {
setMessage(Messages.ImageImportingDialog_DefaultMessage + Messages.ImageImportingDialog_RelPathMessage);
setErrorMessage(null);
getButton(IDialogConstants.OK_ID).setEnabled(true);
imageImporter.setRelPath(relativePathText.getText());
Expand All @@ -123,7 +124,7 @@ protected boolean isResizable() {

@Override
protected Point getInitialSize() {
return new Point(600, 200);
return new Point(700, 200);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ public class Messages extends NLS {
public static String CategoryFormat_Description;
public static String CategoryFormat_Name;
public static String ImageImportingDialog_DefaultMessage;
public static String ImageImportingDialog_AbsPathMessage;
public static String ImageImportingDialog_RelPathMessage;
public static String ImageImportingDialog_EmbeddedMessage;
public static String ImageImportingDialog_RelPathMessage;
public static String ImageImportingDialog_RelativePathLabel;
public static String ImageImportingDialog_RelativePathErrorMessage;

static {
// initialize resource bundle
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -258,9 +258,9 @@ protected void convertImgElement(AttributeOwner owner, Node child) {
*/
protected void convertImgElement(Element imgElement, AttributeOwner owner) {
String imgName = imgElement.getAttribute("src");
imgElement.setAttribute("src", getCurrentProject().getName() + "/" + imageImporter.getRelPath() + imgName);
imgElement.setAttribute("src", imageImporter.getRelPath() + imgName);
storeFileToCopy(imgName, getReqIFFolder(),
(new File(getCurrentProject().getLocation().toString(), imageImporter.getRelPath())).getPath(), owner);
(new File(getCurrentProject().getLocation().removeLastSegments(1).toString(), imageImporter.getRelPath())).getPath(), owner);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@ Categories_Types=Type Definitions
CategoryFormat_Name={0}
CategoryFormat_Description=Handle all differences manipulating {0} elements
ImageImportingDialog_DefaultMessage= The imported ReqIf file references images. Please indicate below how to import these images into your model.\n
ImageImportingDialog_AbsPathMessage= In this mode, images will be in an absolute path folder. This is the recommended mode.
ImageImportingDialog_RelPathMessage= Images will be located in a relative path folder. If the text is empty, the current project will be chosen.
ImageImportingDialog_EmbeddedMessage= In this mode, images will be encoded in Base64 and embed in the text. Be aware that this will add up the image to your model size.
ImageImportingDialog_RelPathMessage= Images will be located in a folder whose path is give relatively to the workspace location.
ImageImportingDialog_RelativePathLabel=Path to image folder that is relative to the workspace:
ImageImportingDialog_RelativePathErrorMessage=The relative path does not point to a valid folder.
Original file line number Diff line number Diff line change
Expand Up @@ -70,12 +70,12 @@ public void test() throws Exception {
}

protected void testRelativePathImportStrategy(IContext context, ImageImporter imageImporter) {
imageImporter.setRelPath("");
imageImporter.setRelPath(PROJECT + "/");
ReqIFTextParser parser = new ReqIFTextParser(context, imageImporter);
Requirement dummyReq = RequirementsFactory.eINSTANCE.createRequirement();
dummyReq.setReqIFIdentifier("Dummy");
String parsedContent = parser.transformToHTML(REQIF_TEXT, dummyReq);
String expectedConent = MessageFormat.format(PARSED_REQIF_TEXT, PROJECT + "/" + OUPUT_IMG_FILE_RELATIVE_PATH);
String expectedConent = MessageFormat.format(PARSED_REQIF_TEXT, PROJECT + "/" + OUPUT_IMG_FILE_RELATIVE_PATH);
assertTrue(UNEXPECTED_IMPORTED_TEXT, parsedContent.equals(expectedConent));
}
}

0 comments on commit 3fa23dd

Please sign in to comment.