Commit 23d95e81 authored by Vivek Nigam's avatar Vivek Nigam
Browse files

Cleaned the code. It now generates htm files and checks whether there are no signals.

If so, it opens a dialog box.
refs 2888
parent 238619fe
......@@ -19,6 +19,7 @@ import static java.awt.Desktop.getDesktop;
import static org.apache.commons.lang.ArrayUtils.add;
import static org.eclipse.jface.dialogs.ErrorDialog.openError;
import static org.eclipse.jface.dialogs.MessageDialog.openConfirm;
import static org.eclipse.jface.dialogs.MessageDialog.openInformation;
import static org.eclipse.ui.plugin.AbstractUIPlugin.imageDescriptorFromPlugin;
import static org.fortiss.af3.mira.ui.AF3MiraUIActivator.PLUGIN_ID;
import static org.fortiss.tooling.kernel.utils.EcoreUtils.pickFirstInstanceOf;
......@@ -36,12 +37,11 @@ import org.eclipse.emf.common.util.ECollections;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.jface.viewers.ITreeContentProvider;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.FileDialog;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.ui.dialogs.CheckedTreeSelectionDialog;
import org.fortiss.af3.mira.command.ExportDocReportCommand;
import org.fortiss.af3.mira.command.ExportHTMLReportCommand;
import org.fortiss.af3.mira.command.ExportReqIFCommand;
import org.fortiss.af3.mira.model.Analysis;
import org.fortiss.af3.mira.model.Requirement;
import org.fortiss.af3.mira.model.RequirementsContainer;
......@@ -79,10 +79,7 @@ public class GenerateSignals extends EObjectActionBase<EObject> {
/** {@inheritDoc} */
@Override
public void run() {
EObject target = getTarget();
boolean isWindows = System.getProperty("os.name").startsWith("Windows");
ITreeContentProvider treeContentProvider = buildTreeContentProviderBase();
CheckedTreeSelectionDialog dialog =
......@@ -114,15 +111,13 @@ public class GenerateSignals extends EObjectActionBase<EObject> {
}
}
}
FileDialog fsd = new FileDialog(shell, SWT.SAVE);
// Doc files are not yet tested and therefore not yet supported.
if(isWindows) {
fsd.setFilterExtensions(new String[] {"*.htm", "*.reqif"});
} else {
fsd.setFilterExtensions(new String[] {"*.htm", "*.reqif"});
if(signals.size() == 0) {
openInformation(Display.getCurrent().getActiveShell(), "No Signal Aspect Found",
"There are no signal aspects to generate a report from.");
return;
}
FileDialog fsd = new FileDialog(shell, SWT.SAVE);
fsd.setFilterExtensions(new String[] {"*.htm"});
fsd.setText("Select the name of the report");
fsd.setOverwrite(false);
String fileName = fsd.open();
......@@ -134,31 +129,9 @@ public class GenerateSignals extends EObjectActionBase<EObject> {
return;
}
try {
if(fileName.endsWith(".reqif")) {
try {
new ExportReqIFCommand(signals, getReqIfTemplatePath(target), file).call();
} catch(Exception e) {
e.printStackTrace();
openErrorDialog(e, "ReqIF");
}
} else if(fileName.endsWith(".htm")) {
if(fileName.endsWith(".htm")) {
new ExportHTMLReportCommand(signals, getHtmlTemplatePath(target), file).call();
} else if(fileName.endsWith(".doc")) {
String prefix = fileName.substring(0, fileName.length() - 4);
File htmfile = new File(prefix + ".htm");
while(htmfile.exists()) {
prefix += "_";
htmfile = new File(prefix + ".htm");
}
new ExportDocReportCommand(signals, getHtmlTemplatePath(target), file, htmfile)
.call();
}
// open the report automatically
getDesktop().open(file);
} else {
throw new IllegalArgumentException("Export format is not (yet) supported!");
}
new ExportHTMLReportCommand(signals, getHtmlTemplatePath(target), file).call();
// open the report automatically
getDesktop().open(file);
} catch(Exception e) {
e.printStackTrace();
openErrorDialog(e, "report");
......
......@@ -97,7 +97,6 @@ public class ContextFactory {
public static EvaluationContext getContextFor(List<EObject> obj, OutputFormat format) {
checklist = obj;
EvaluationContext context = null;
// get Analysis object which is at position 1 of list obj for context evaluation
if(obj.get(0) instanceof Analysis) {
// the only call to this method in ExportReportAction checks for the obj parameter never
......@@ -105,7 +104,7 @@ public class ContextFactory {
context = getContextFor((Analysis)obj.get(0));
}
// If the obj list has a signal at position 0
else if(obj.get(0) instanceof Signal) {
else if(obj.get(0) instanceof Signal || obj.size() == 0) {
// the only call to this method in ExportReportAction checks for the obj parameter never
// being null
context = getContextFor((List<Signal>)(List<?>)obj);
......
......@@ -33,6 +33,7 @@ import org.fortiss.af3.mira.model.RequirementStatus;
import org.fortiss.af3.mira.model.SafetyLevel;
import org.fortiss.af3.mira.model.SafetyRequirementType;
import org.fortiss.af3.mira.model.functional.Signal;
import org.fortiss.af3.mira.model.functional.ValueRange;
import org.fortiss.af3.mira.model.relations.DirectedRequirementRelationType;
import org.fortiss.af3.mira.model.usecase.Actor;
import org.fortiss.af3.mira.model.usecase.Scenario;
......@@ -42,6 +43,7 @@ import org.fortiss.af3.mira.model.usecase.UseCase;
import org.fortiss.af3.mira.relation.IRelationTypeHandler;
import org.fortiss.af3.mira.relation.IRelationTypeService;
import org.fortiss.af3.mira.report.template.EvaluationContext;
import org.fortiss.af3.project.model.typesystem.IType;
import org.fortiss.af3.safety.model.SafetyStandard;
import org.fortiss.tooling.base.model.element.IConnection;
import org.fortiss.tooling.base.model.element.IHierarchicElement;
......@@ -100,6 +102,9 @@ public class ReqIFContextFactory {
return getContextForSignals((List<Signal>)(List<?>)obj);
}
}
if(obj.size() == 0) {
throw new IllegalArgumentException("No Signal Aspects found");
}
throw new IllegalArgumentException(obj.getClass().getSimpleName() + " is not supported!");
}
......@@ -119,10 +124,24 @@ public class ReqIFContextFactory {
public static EvaluationContext getContextForSignal(Signal signal) {
EvaluationContext ctx = new EvaluationContext();
ctx.set("dateTime", getDateTime());
ctx.set("signalName", signal.getName());
ctx.set("signalRangeMax", signal.getRange().getMax());
ctx.set("signalRangeMin", signal.getRange().getMin());
ctx.set("signalType", signal.getType());
String name = signal.getName();
if(name != null)
ctx.set("signalName", name);
ValueRange range = signal.getRange();
if(range != null) {
ctx.set("signalRangeMax", range.getMax());
ctx.set("signalRangeMin", range.getMin());
} else {
ctx.set("signalRangeMax", "NA");
ctx.set("signalRangeMin", "NA");
}
IType type = signal.getType();
if(type != null) {
ctx.set("signalType", type);
} else {
ctx.set("signalType", "NA");
}
ctx.set("signalInitial", signal.getInitialValue());
ctx.set("signalUpdateRate", signal.getUpdateRate());
return ctx;
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment