Loading plugins/org.etsi.mts.tdl.rt.ui/src/org/etsi/mts/tdl/tools/rt/ui/TP2TDDialog.java +35 −1 Original line number Diff line number Diff line Loading @@ -22,18 +22,24 @@ public class TP2TDDialog extends TitleAreaDialog { private Text prefixField; private Text suffixField; private Text substituteField; private Text withField; private Button removeAnnotationsButton; private Button removeAnnotatedBlocksButton; private Button markAsDerivedButton; //TODO: numbers, first / last? private String regex = "[a-zA-Z_]"; //TODO: store between runs //DONE: store between runs private String prefix = ""; private String suffix = "_TDs"; private String substitute = "TP_"; private String with = "TD_"; private boolean removeAnnotations = false; private boolean removeAnnotatedBlocks = false; private boolean markAsDerived = false; private IEclipsePreferences preferences; private Preferences tp2td; Loading Loading @@ -61,8 +67,11 @@ public class TP2TDDialog extends TitleAreaDialog { prefix = tp2td.get("prefix", ""); suffix = tp2td.get("suffix", "_TDs"); substitute = tp2td.get("substitute", "TP_"); with = tp2td.get("with", "TD_"); removeAnnotations = tp2td.getBoolean("removeAnnotations", false); removeAnnotatedBlocks = tp2td.getBoolean("removeAnnotatedBlocks", false); markAsDerived = tp2td.getBoolean("markAsDerived", true); //DONE: validate to make sure that at least one is used Loading @@ -73,9 +82,16 @@ public class TP2TDDialog extends TitleAreaDialog { addValidation(prefixField, regex); suffixField = createTextField(container, "Package suffix", suffix); addValidation(suffixField, regex); substituteField = createTextField(container, "Substitute in name", substitute); addValidation(substituteField, substitute); withField = createTextField(container, "With", with); addValidation(withField, regex); //TODO: hints removeAnnotationsButton = createOption(container, "Remove annotations", isRemoveAnnotations()); removeAnnotatedBlocksButton = createOption(container, "Remove annotated blocks", isRemoveAnnotatedBlocks()); markAsDerivedButton = createOption(container, "Mark target file as derived", isMarkAsDerived()); removeAnnotationsButton.addSelectionListener(SelectionListener.widgetSelectedAdapter(e-> { if (!removeAnnotationsButton.getSelection() && removeAnnotatedBlocksButton.getSelection()) { removeAnnotatedBlocksButton.setSelection(false); Loading Loading @@ -134,13 +150,19 @@ public class TP2TDDialog extends TitleAreaDialog { private void saveInput() { prefix = prefixField.getText(); suffix = suffixField.getText(); substitute = substituteField.getText(); with = withField.getText(); removeAnnotations = removeAnnotationsButton.getSelection(); removeAnnotatedBlocks = removeAnnotatedBlocksButton.getSelection(); markAsDerived = markAsDerivedButton.getSelection(); tp2td.put("prefix", prefix); tp2td.get("suffix", suffix); tp2td.put("substitute", substitute); tp2td.get("with", with); tp2td.putBoolean("removeAnnotations", removeAnnotations); tp2td.putBoolean("removeAnnotatedBlocks", removeAnnotatedBlocks); tp2td.putBoolean("markAsDerived", markAsDerived); try { // forces the application to save the preferences Loading Loading @@ -172,4 +194,16 @@ public class TP2TDDialog extends TitleAreaDialog { public boolean isRemoveAnnotatedBlocks() { return removeAnnotatedBlocks; } public String getSubstitute() { return substitute; } public String getWith() { return with; } public boolean isMarkAsDerived() { return markAsDerived; } } No newline at end of file plugins/org.etsi.mts.tdl.rt.ui/src/org/etsi/mts/tdl/tools/rt/ui/handlers/TP2TDHandler.java +24 −4 Original line number Diff line number Diff line Loading @@ -6,6 +6,10 @@ import org.eclipse.core.commands.AbstractHandler; import org.eclipse.core.commands.ExecutionEvent; import org.eclipse.core.commands.ExecutionException; import org.eclipse.core.resources.IFile; import org.eclipse.core.resources.IWorkspace; import org.eclipse.core.resources.ResourcesPlugin; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IPath; import org.eclipse.emf.common.util.URI; import org.eclipse.emf.ecore.EObject; import org.eclipse.emf.ecore.resource.Resource; Loading Loading @@ -80,7 +84,9 @@ public class TP2TDHandler extends AbstractHandler{ tr.getContents().addAll(EcoreUtil.copyAll(r.getContents())); processModel(tr, dialog.getPrefix(), dialog.getSuffix(), dialog.isRemoveAnnotations(), dialog.isRemoveAnnotatedBlocks()); dialog.getSubstitute(), dialog.getWith(), dialog.isRemoveAnnotations(), dialog.isRemoveAnnotatedBlocks() ); //TODO: this also has to be reused try { Loading @@ -94,14 +100,27 @@ public class TP2TDHandler extends AbstractHandler{ e1.printStackTrace(); //TODO: provide an error dialog, fall back to XF, indicate approximate location based on error message / details } //DONE: Make optional IWorkspace workspace = ResourcesPlugin.getWorkspace(); IPath targetPath = file.getFullPath().removeLastSegments(1).append(last).addFileExtension(ext); IFile targetFile = workspace.getRoot().getFile(targetPath); try { if (dialog.isMarkAsDerived()) { targetFile.setDerived(true); } else { targetFile.setDerived(false); } } catch (CoreException e) { // TODO Auto-generated catch block e.printStackTrace(); } } } return null; } private void processModel(Resource resource, String prefix, String suffix, boolean removeAnnotations, boolean removeAnnotatedBlocks) { private void processModel(Resource resource, String prefix, String suffix, String substitute, String with, boolean removeAnnotations, boolean removeAnnotatedBlocks) { //update names for all packages var packages = EcoreUtil2.eAllOfType(resource.getContents().get(0), Package.class); for (var p : packages) { Loading @@ -111,6 +130,7 @@ public class TP2TDHandler extends AbstractHandler{ if (removeAnnotations) { var tds = EcoreUtil2.eAllOfType(resource.getContents().get(0), TestDescription.class); for (var td : tds) { td.setName(td.getName().replace(substitute, with)); if (!removeAnnotatedBlocks) { //naive approach, clean up blocks as well removeElements(td, Annotation.class); Loading Loading
plugins/org.etsi.mts.tdl.rt.ui/src/org/etsi/mts/tdl/tools/rt/ui/TP2TDDialog.java +35 −1 Original line number Diff line number Diff line Loading @@ -22,18 +22,24 @@ public class TP2TDDialog extends TitleAreaDialog { private Text prefixField; private Text suffixField; private Text substituteField; private Text withField; private Button removeAnnotationsButton; private Button removeAnnotatedBlocksButton; private Button markAsDerivedButton; //TODO: numbers, first / last? private String regex = "[a-zA-Z_]"; //TODO: store between runs //DONE: store between runs private String prefix = ""; private String suffix = "_TDs"; private String substitute = "TP_"; private String with = "TD_"; private boolean removeAnnotations = false; private boolean removeAnnotatedBlocks = false; private boolean markAsDerived = false; private IEclipsePreferences preferences; private Preferences tp2td; Loading Loading @@ -61,8 +67,11 @@ public class TP2TDDialog extends TitleAreaDialog { prefix = tp2td.get("prefix", ""); suffix = tp2td.get("suffix", "_TDs"); substitute = tp2td.get("substitute", "TP_"); with = tp2td.get("with", "TD_"); removeAnnotations = tp2td.getBoolean("removeAnnotations", false); removeAnnotatedBlocks = tp2td.getBoolean("removeAnnotatedBlocks", false); markAsDerived = tp2td.getBoolean("markAsDerived", true); //DONE: validate to make sure that at least one is used Loading @@ -73,9 +82,16 @@ public class TP2TDDialog extends TitleAreaDialog { addValidation(prefixField, regex); suffixField = createTextField(container, "Package suffix", suffix); addValidation(suffixField, regex); substituteField = createTextField(container, "Substitute in name", substitute); addValidation(substituteField, substitute); withField = createTextField(container, "With", with); addValidation(withField, regex); //TODO: hints removeAnnotationsButton = createOption(container, "Remove annotations", isRemoveAnnotations()); removeAnnotatedBlocksButton = createOption(container, "Remove annotated blocks", isRemoveAnnotatedBlocks()); markAsDerivedButton = createOption(container, "Mark target file as derived", isMarkAsDerived()); removeAnnotationsButton.addSelectionListener(SelectionListener.widgetSelectedAdapter(e-> { if (!removeAnnotationsButton.getSelection() && removeAnnotatedBlocksButton.getSelection()) { removeAnnotatedBlocksButton.setSelection(false); Loading Loading @@ -134,13 +150,19 @@ public class TP2TDDialog extends TitleAreaDialog { private void saveInput() { prefix = prefixField.getText(); suffix = suffixField.getText(); substitute = substituteField.getText(); with = withField.getText(); removeAnnotations = removeAnnotationsButton.getSelection(); removeAnnotatedBlocks = removeAnnotatedBlocksButton.getSelection(); markAsDerived = markAsDerivedButton.getSelection(); tp2td.put("prefix", prefix); tp2td.get("suffix", suffix); tp2td.put("substitute", substitute); tp2td.get("with", with); tp2td.putBoolean("removeAnnotations", removeAnnotations); tp2td.putBoolean("removeAnnotatedBlocks", removeAnnotatedBlocks); tp2td.putBoolean("markAsDerived", markAsDerived); try { // forces the application to save the preferences Loading Loading @@ -172,4 +194,16 @@ public class TP2TDDialog extends TitleAreaDialog { public boolean isRemoveAnnotatedBlocks() { return removeAnnotatedBlocks; } public String getSubstitute() { return substitute; } public String getWith() { return with; } public boolean isMarkAsDerived() { return markAsDerived; } } No newline at end of file
plugins/org.etsi.mts.tdl.rt.ui/src/org/etsi/mts/tdl/tools/rt/ui/handlers/TP2TDHandler.java +24 −4 Original line number Diff line number Diff line Loading @@ -6,6 +6,10 @@ import org.eclipse.core.commands.AbstractHandler; import org.eclipse.core.commands.ExecutionEvent; import org.eclipse.core.commands.ExecutionException; import org.eclipse.core.resources.IFile; import org.eclipse.core.resources.IWorkspace; import org.eclipse.core.resources.ResourcesPlugin; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IPath; import org.eclipse.emf.common.util.URI; import org.eclipse.emf.ecore.EObject; import org.eclipse.emf.ecore.resource.Resource; Loading Loading @@ -80,7 +84,9 @@ public class TP2TDHandler extends AbstractHandler{ tr.getContents().addAll(EcoreUtil.copyAll(r.getContents())); processModel(tr, dialog.getPrefix(), dialog.getSuffix(), dialog.isRemoveAnnotations(), dialog.isRemoveAnnotatedBlocks()); dialog.getSubstitute(), dialog.getWith(), dialog.isRemoveAnnotations(), dialog.isRemoveAnnotatedBlocks() ); //TODO: this also has to be reused try { Loading @@ -94,14 +100,27 @@ public class TP2TDHandler extends AbstractHandler{ e1.printStackTrace(); //TODO: provide an error dialog, fall back to XF, indicate approximate location based on error message / details } //DONE: Make optional IWorkspace workspace = ResourcesPlugin.getWorkspace(); IPath targetPath = file.getFullPath().removeLastSegments(1).append(last).addFileExtension(ext); IFile targetFile = workspace.getRoot().getFile(targetPath); try { if (dialog.isMarkAsDerived()) { targetFile.setDerived(true); } else { targetFile.setDerived(false); } } catch (CoreException e) { // TODO Auto-generated catch block e.printStackTrace(); } } } return null; } private void processModel(Resource resource, String prefix, String suffix, boolean removeAnnotations, boolean removeAnnotatedBlocks) { private void processModel(Resource resource, String prefix, String suffix, String substitute, String with, boolean removeAnnotations, boolean removeAnnotatedBlocks) { //update names for all packages var packages = EcoreUtil2.eAllOfType(resource.getContents().get(0), Package.class); for (var p : packages) { Loading @@ -111,6 +130,7 @@ public class TP2TDHandler extends AbstractHandler{ if (removeAnnotations) { var tds = EcoreUtil2.eAllOfType(resource.getContents().get(0), TestDescription.class); for (var td : tds) { td.setName(td.getName().replace(substitute, with)); if (!removeAnnotatedBlocks) { //naive approach, clean up blocks as well removeElements(td, Annotation.class); Loading