Commit ce77f1d6 authored by Philip Makedonski's avatar Philip Makedonski
Browse files

+ allow overwriting in import wizard

parent 31708bb9
Loading
Loading
Loading
Loading
Loading
+30 −2
Original line number Diff line number Diff line
@@ -37,12 +37,14 @@ public class ImportWizardPage extends WizardNewFileCreationPage {
	protected FileFieldEditor editor;
	private boolean inline = false;
	private boolean copySource = false;
	private boolean overwrite = true;
	private IPath sourcePath;
	LinkedHashMap<String, String> dataFormats = new LinkedHashMap<>();

	public ImportWizardPage(String pageName, IStructuredSelection selection) {
		super(pageName, selection);
		setTitle(pageName); //NON-NLS-1
		setAllowExistingResources(overwrite);
		setDescription("Import data definitions from a file from the local file system into the workspace"); //NON-NLS-1
		loadDataFormat("org.etsi.mts.tdl.openapi2tdl.next", "OpenAPI", "*.yaml");
		loadDataFormat("org.etsi.mts.tdl.asn2tdl", "ASN.1", "*.asn1;*.asn");
@@ -105,6 +107,16 @@ public class ImportWizardPage extends WizardNewFileCreationPage {
        Button buttonFlatten = new Button(fileSelectionArea, SWT.CHECK);
        buttonFlatten.setSelection(false);
        buttonFlatten.addSelectionListener(SelectionListener.widgetSelectedAdapter(this::flattenDataDefinitions));
//        fill empty cell
		new Label(fileSelectionArea, SWT.NONE);

		Label labelOverwrite = new Label(fileSelectionArea, SWT.NONE);
		//TODO: for OpenAPI only?
		labelOverwrite.setText("Overwrite File:");
        //TODO: link and verify results
        Button buttonOverwrite = new Button(fileSelectionArea, SWT.CHECK);
        buttonOverwrite.setSelection(true);
        buttonOverwrite.addSelectionListener(SelectionListener.widgetSelectedAdapter(this::overwriteDefinitions));
//        fill empty cell
		new Label(fileSelectionArea, SWT.NONE);
	}
@@ -133,9 +145,11 @@ public class ImportWizardPage extends WizardNewFileCreationPage {
//				IWorkspace workspace = ResourcesPlugin.getWorkspace();
//				IWorkspaceRoot root = workspace.getRoot();
//				IPath location = root.getLocation();
				
				String content = ConverterNext.processToString(editor.getStringValue(), 
//						editor.getStringValue()+".tdltx",
//						location.append(getContainerFullPath()).append(getFileName()).toOSString(),
//						ResourcesPlugin.getWorkspace().getRoot().getFile(getContainerFullPath().append(getFileName())).getRawLocation().toOSString(),
						getContainerFullPath().append(getFileName()).toOSString(),
						"SOURCE_MAPPING", 
						"TARGET_MAPPING",
@@ -185,7 +199,7 @@ public class ImportWizardPage extends WizardNewFileCreationPage {
		if (this.editor != null) {
			IPath sourcePath = Path.fromOSString(this.editor.getStringValue());
			boolean exists = sourcePath.toFile().exists();
			if (!exists) {
			if (!overwrite && exists) {
				setErrorMessage("The selected data file path is not valid.");
			}
			return exists && validatePage;
@@ -198,6 +212,12 @@ public class ImportWizardPage extends WizardNewFileCreationPage {
		inline = ((Button) e.getSource()).getSelection();
	}

	private void overwriteDefinitions(SelectionEvent e) {
		overwrite = ((Button) e.getSource()).getSelection();
		setAllowExistingResources(overwrite);
	}

	
	private void copyDataDefinitions(SelectionEvent e) {
		setCopySource(((Button) e.getSource()).getSelection());
	}
@@ -217,4 +237,12 @@ public class ImportWizardPage extends WizardNewFileCreationPage {
	public void setSourcePath(IPath sourcePath) {
		this.sourcePath = sourcePath;
	}

	public boolean isOverwrite() {
		return overwrite;
	}

	public void setOverwrite(boolean overwrite) {
		this.overwrite = overwrite;
	}
}