Commit c8dad297 authored by Dongyue Mou's avatar Dongyue Mou
Browse files

moved some util methods to kernel and base

replaced the icon of CA
improved constraint checker by allowing multi results in one apply
added a base class for contraint violation
added helper operator in the mira model
overall code clean up in mira
refs 301
parent f4f3da8e
......@@ -17,11 +17,14 @@ $Id$
+--------------------------------------------------------------------------*/
package org.fortiss.af3.expression.language.constraint;
import org.eclipse.emf.ecore.EObject;
import java.util.ArrayList;
import java.util.List;
import org.fortiss.af3.expression.model.definitions.Enumeration;
import org.fortiss.af3.expression.model.definitions.EnumerationMember;
import org.fortiss.tooling.kernel.extension.IConstraintChecker;
import org.fortiss.tooling.kernel.extension.data.IConstraintViolation;
import org.fortiss.tooling.kernel.extension.data.IConstraintViolation.ESeverity;
/**
* A constraint checker for {@link Enumeration}s. It checks duplicate
......@@ -43,39 +46,18 @@ public class EnumerationConstraintChecker implements
/** {@inheritDoc} */
@Override
public IConstraintViolation<EObject> apply(Enumeration modelElement) {
public List<IConstraintViolation<Enumeration>> apply(
Enumeration modelElement) {
List<IConstraintViolation<Enumeration>> results = new ArrayList<IConstraintViolation<Enumeration>>();
// check duplicate enumeration member
for (EnumerationMember mem1 : modelElement.getMembersList()) {
for (EnumerationMember mem2 : modelElement.getMembersList()) {
if (mem1 != mem2 && mem1.getName().equals(mem2.getName())) {
final Enumeration enumeration = (Enumeration) mem1
.eContainer();
final String name = mem1.getName();
return new IConstraintViolation<EObject>() {
@Override
public EObject getSource() {
return enumeration;
}
@Override
public ESeverity getSeverity() {
return ESeverity.ERROR;
}
@Override
public String getExplanation() {
return "Duplicate member " + name
+ " in enumeration "
+ enumeration.getName();
}
@Override
public IQuickFixHandler getQuickFixHandler() {
// no quickfix possible
return null;
}
};
results.add(new EnumerationConstraintViolation(modelElement, ESeverity.ERROR,
"Duplicate member "
+ mem1.getName() + " in enumeration "
+ modelElement.getName()));
}
}
}
......
/*--------------------------------------------------------------------------+
$Id$
| |
| Copyright 2011 ForTISS GmbH |
| |
| Licensed under the Apache License, Version 2.0 (the "License"); |
| you may not use this file except in compliance with the License. |
| You may obtain a copy of the License at |
| |
| http://www.apache.org/licenses/LICENSE-2.0 |
| |
| Unless required by applicable law or agreed to in writing, software |
| distributed under the License is distributed on an "AS IS" BASIS, |
| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| See the License for the specific language governing permissions and |
| limitations under the License. |
+--------------------------------------------------------------------------*/
package org.fortiss.af3.expression.language.constraint;
import org.fortiss.af3.expression.model.definitions.Enumeration;
import org.fortiss.tooling.kernel.extension.base.ConstraintViolationBase;
/**
*
* @author mou
* @author $Author$
* @version $Rev$
* @ConQAT.Rating RED Hash:
*/
public class EnumerationConstraintViolation extends
ConstraintViolationBase<Enumeration> {
/**
* @param source
* @param severity
* @param explanation
*/
public EnumerationConstraintViolation(Enumeration source, ESeverity severity,
String explanation) {
super(source, severity, explanation);
}
}
\ No newline at end of file
......@@ -11,7 +11,8 @@ Bundle-RequiredExecutionEnvironment: JavaSE-1.6
Require-Bundle: org.fortiss.af3.mira;bundle-version="1.0.0";visibility:=reexport,
org.eclipse.swtbot.eclipse.finder;bundle-version="2.0.4";resolution:=optional,
org.eclipse.swtbot.junit4_x;bundle-version="2.0.4";resolution:=optional,
org.fortiss.af3.state.ui;bundle-version="1.0.0";visibility:=reexport
org.fortiss.af3.state.ui;bundle-version="1.0.0";visibility:=reexport,
org.eclipse.core.databinding.property;bundle-version="1.4.0"
Bundle-ActivationPolicy: lazy
Bundle-Activator: org.fortiss.af3.mira.ui.AF3MiraUIActivator
Export-Package: org.fortiss.af3.mira.ui,
......
......@@ -30,6 +30,10 @@ public class AF3MiraUIActivator extends AbstractUIPlugin {
/** The plug-in ID. */
public static final String PLUGIN_ID = AF3MiraUIActivator.class
.getPackage().getName(); //$NON-NLS-1$
/**
* The ID of the view as specified by the extension.
*/
public static final String REQUIREMENT_HIERARCHY_VIEW_ID = "org.fortiss.af3.mira.ui.views.RequirementHierarchyView";
/** The shared instance. */
private static AF3MiraUIActivator plugin;
......@@ -57,12 +61,4 @@ public class AF3MiraUIActivator extends AbstractUIPlugin {
public static AF3MiraUIActivator getDefault() {
return plugin;
}
/** Build a resource URI according to the given absolute path */
public static String getResourceURI(String resource) {
if (!resource.startsWith("/"))
throw new IllegalArgumentException("The path " + resource
+ " is not a absolute path.");
return "platform:/plugin/" + PLUGIN_ID + resource;
}
}
......@@ -30,10 +30,9 @@ import org.fortiss.af3.mira.model.usecase.ScopeSpecification;
import org.fortiss.af3.mira.ui.AF3MiraUIActivator;
import org.fortiss.af3.mira.ui.dialog.StateSelectionDialog;
import org.fortiss.af3.state.model.State;
import org.fortiss.tooling.base.model.element.IModelElement;
import org.fortiss.tooling.base.model.element.IModelElementReference;
import org.fortiss.tooling.kernel.service.ICommandStackService;
import org.fortiss.tooling.kernel.ui.extension.base.EObjectActionBase;
import org.fortiss.tooling.kernel.utils.EcoreUtils;
/**
* Action to connect a condition to a component by requirement specification
......@@ -66,25 +65,18 @@ public class ConnectConditionToComponentAction extends EObjectActionBase {
/** {@inheritDoc} */
@Override
public void run() {
Component scope = null;
for (IModelElementReference ref : ((Requirement) getTarget())
.getReferencedByList()) {
if (ref instanceof ScopeSpecification) {
IModelElement element = ((ScopeSpecification) ref)
.getSpecificationOf();
if (element != null && element instanceof Component) {
scope = (Component) element;
break;
}
}
}
ScopeSpecification spec = EcoreUtils.pickFirstInstanceOf(
ScopeSpecification.class,
((Requirement) getTarget()).getReferencedByList());
if (scope == null) {
if (spec == null || !(spec.getSpecificationOf() instanceof Component)) {
MessageDialog.openError(shell, "Scope",
"Cannot find assigned scope component!");
return;
}
Component scope = (Component) spec.getSpecificationOf();
final State state = StateSelectionDialog.open(shell,
scope.getSpecificationsList());
if (state == null)
......
......@@ -30,9 +30,9 @@ import org.fortiss.af3.mira.model.usecase.UseCase;
import org.fortiss.af3.mira.model.usecase.UsecaseFactory;
import org.fortiss.af3.mira.ui.AF3MiraUIActivator;
import org.fortiss.af3.mira.ui.dialog.InputPortSelectionDialog;
import org.fortiss.tooling.base.model.element.IModelElementReference;
import org.fortiss.tooling.kernel.service.ICommandStackService;
import org.fortiss.tooling.kernel.ui.extension.base.EObjectActionBase;
import org.fortiss.tooling.kernel.utils.EcoreUtils;
/**
* Action to connect trigger to an input port by using
......@@ -59,23 +59,18 @@ public final class ConnectTriggerToInputPortAction extends EObjectActionBase {
/** {@inheritDoc} */
@Override
public void run() {
ScopeSpecification spec = EcoreUtils.pickFirstInstanceOf(
ScopeSpecification.class,
((Requirement) getTarget()).getReferencedByList());
Component scope = null;
for (IModelElementReference ref : ((Requirement) getTarget())
.getReferencedByList()) {
if (ref instanceof ScopeSpecification && ref.eContainer() != null
&& ref.eContainer() instanceof Component) {
scope = (Component) ref.eContainer();
break;
}
}
if (scope == null) {
if (spec == null || !(spec.getSpecificationOf() instanceof Component)) {
MessageDialog.openError(shell, "Scope",
"Cannot find assigned scope component!");
return;
}
Component scope = (Component) spec.getSpecificationOf();
final InputPort port = InputPortSelectionDialog.open(shell.getShell(),
scope);
if (port == null)
......
......@@ -64,7 +64,7 @@ public class ExportReportAction extends EObjectActionBase {
@Override
public void run() {
if (getTarget() == null) {
MessageDialog.openError(shell, "No requirement specified",
MessageDialog.openError(shell, "Exprot report",
"No requirement is specified to export");
return;
}
......@@ -89,8 +89,8 @@ public class ExportReportAction extends EObjectActionBase {
}
try {
new ExportReportCommand((Requirement) getTarget(), htmfile, docfile)
.call();
new ExportReportCommand(getTarget(),
"/template/ReportTemplate.html", htmfile, docfile).call();
} catch (Exception e) {
e.printStackTrace();
ErrorDialog.openError(shell, "Error while generating report", e
......
......@@ -26,7 +26,7 @@ import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.swt.widgets.FileDialog;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.ui.plugin.AbstractUIPlugin;
import org.fortiss.af3.mira.command.ExportReportSummarizationCommand;
import org.fortiss.af3.mira.command.ExportReportCommand;
import org.fortiss.af3.mira.model.Analysis;
import org.fortiss.af3.mira.ui.AF3MiraUIActivator;
import org.fortiss.tooling.kernel.ui.extension.base.EObjectActionBase;
......@@ -64,14 +64,14 @@ public class ExportReportSummarizationAction extends EObjectActionBase {
@Override
public void run() {
if (getTarget() == null) {
MessageDialog.openError(shell, "No requirement specified",
MessageDialog.openError(shell, "Exprot report",
"No requirement is specified to export");
return;
}
FileDialog fsd = new FileDialog(shell);
fsd.setFilterExtensions(new String[] { "*.htm", "*.doc" });
fsd.setText("Select the name of the report summarization");
fsd.setText("Select the name of the report");
fsd.setOverwrite(false);
String file = fsd.open();
......@@ -89,15 +89,15 @@ public class ExportReportSummarizationAction extends EObjectActionBase {
}
try {
new ExportReportSummarizationCommand((Analysis) getTarget(),
htmfile, docfile).call();
new ExportReportCommand(getTarget(),
"/template/ReportTemplateAnalysis.html", htmfile, docfile)
.call();
} catch (Exception e) {
e.printStackTrace();
ErrorDialog.openError(shell,
"Error while generating report summarization", e
.getMessage(), new Status(IStatus.ERROR,
AF3MiraUIActivator.PLUGIN_ID, 0,
"Cannot generate report summarization", e));
ErrorDialog.openError(shell, "Error while generating report", e
.getMessage(), new Status(IStatus.ERROR,
AF3MiraUIActivator.PLUGIN_ID, 0, "Cannot generate report",
e));
}
}
}
......@@ -54,7 +54,7 @@ public class ShowHierarchyAction extends EObjectActionBase {
public void run() {
try {
RequirementHierarchyView part = (RequirementHierarchyView) page
.showView(RequirementHierarchyView.ID);
.showView(AF3MiraUIActivator.REQUIREMENT_HIERARCHY_VIEW_ID);
part.setInput((Requirement) getTarget());
} catch (Exception e) {
e.printStackTrace();
......
......@@ -22,7 +22,7 @@ import java.util.List;
import org.eclipse.ui.plugin.AbstractUIPlugin;
import org.fortiss.af3.mira.model.Analysis;
import org.fortiss.af3.mira.ui.AF3MiraUIActivator;
import org.fortiss.af3.mira.verification.VerificationUtil;
import org.fortiss.af3.mira.utils.VerificationUtil;
import org.fortiss.tooling.kernel.extension.data.IConstraintViolation;
import org.fortiss.tooling.kernel.service.IConstraintCheckerService;
import org.fortiss.tooling.kernel.ui.extension.base.EObjectActionBase;
......
......@@ -17,10 +17,10 @@ $Id$
+--------------------------------------------------------------------------*/
package org.fortiss.af3.mira.ui.dialog;
import org.conqat.lib.commons.string.StringUtils;
import org.eclipse.jface.dialogs.IInputValidator;
import org.fortiss.af3.mira.model.usecase.Actor;
import org.fortiss.af3.mira.model.usecase.UseCase;
import org.fortiss.af3.mira.verification.VerificationUtil;
/**
* {@link IInputValidator} to check the actor name
......@@ -43,7 +43,7 @@ public class ActorNameValidator implements IInputValidator {
/** {@inheritDoc} */
@Override
public String isValid(String newText) {
if (VerificationUtil.isNullOrEmptyString(newText))
if (StringUtils.isEmpty(newText))
return "The name may not be empty!";
for (Actor a : uc.getActor())
......
......@@ -17,6 +17,12 @@ $Id$
+--------------------------------------------------------------------------*/
package org.fortiss.af3.mira.ui.editor;
import static org.fortiss.af3.mira.model.verification.VerificationPackage.Literals.CHECK_ITEM__CATEGORY;
import static org.fortiss.af3.mira.model.verification.VerificationPackage.Literals.CHECK_ITEM__LAST_UPDATE;
import static org.fortiss.af3.mira.model.verification.VerificationPackage.Literals.CHECK_ITEM__STATUS;
import static org.fortiss.tooling.kernel.model.FortissToolingKernelPackage.Literals.INAMED_COMMENTED_ELEMENT__COMMENT;
import static org.fortiss.tooling.kernel.model.FortissToolingKernelPackage.Literals.INAMED_ELEMENT__NAME;
import java.util.Date;
import java.util.List;
......@@ -40,10 +46,8 @@ import org.fortiss.af3.mira.model.Requirement;
import org.fortiss.af3.mira.model.verification.CheckItem;
import org.fortiss.af3.mira.model.verification.CheckList;
import org.fortiss.af3.mira.model.verification.CheckStatus;
import org.fortiss.af3.mira.model.verification.VerificationPackage;
import org.fortiss.tooling.base.model.element.IModelElementSpecification;
import org.fortiss.tooling.base.ui.editor.FormsEditorBase;
import org.fortiss.tooling.kernel.model.FortissToolingKernelPackage;
import org.fortiss.tooling.kernel.ui.databinding.ObservableUtil;
import org.fortiss.tooling.kernel.ui.util.DataBindingUtils;
......@@ -85,28 +89,28 @@ public class CheckListEditor extends FormsEditorBase<Requirement> {
Label id = toolkit.createLabel(composite, "");
GridDataFactory.swtDefaults().minSize(25, SWT.DEFAULT)
.applyTo(id);
dbc.bindValue(
SWTObservables.observeText(id),
ObservableUtil
.observeValue(
item,
VerificationPackage.Literals.CHECK_ITEM__CATEGORY));
dbc.bindValue(SWTObservables.observeText(id),
ObservableUtil.observeValue(item, CHECK_ITEM__CATEGORY));
Label name = toolkit.createLabel(composite, "");
GridDataFactory.swtDefaults().minSize(100, SWT.DEFAULT)
.applyTo(name);
dbc.bindValue(
SWTObservables.observeText(name),
ObservableUtil
.observeValue(
item,
FortissToolingKernelPackage.Literals.INAMED_ELEMENT__NAME));
dbc.bindValue(SWTObservables.observeText(name),
ObservableUtil.observeValue(item, INAMED_ELEMENT__NAME));
final ComboViewer status = new ComboViewer(composite,
SWT.DROP_DOWN);
toolkit.adapt(status.getCombo());
GridDataFactory.swtDefaults().minSize(75, SWT.DEFAULT)
.applyTo(status.getControl());
status.setContentProvider(new ArrayContentProvider());
status.setLabelProvider(new LabelProvider());
status.setInput(CheckStatus.values());
dbc.bindValue(
ViewersObservables.observeSinglePostSelection(status),
ObservableUtil.observeValue(item, CHECK_ITEM__STATUS));
status.addSelectionChangedListener(new ISelectionChangedListener() {
@Override
public void selectionChanged(SelectionChangedEvent event) {
......@@ -120,37 +124,21 @@ public class CheckListEditor extends FormsEditorBase<Requirement> {
});
}
});
toolkit.adapt(status.getCombo());
GridDataFactory.swtDefaults().minSize(75, SWT.DEFAULT)
.applyTo(status.getControl());
dbc.bindValue(
ViewersObservables.observeSinglePostSelection(status),
ObservableUtil
.observeValue(
item,
VerificationPackage.Literals.CHECK_ITEM__STATUS));
Label date = toolkit.createLabel(composite, "");
GridDataFactory.swtDefaults().minSize(100, SWT.DEFAULT)
.applyTo(date);
dbc.bindValue(
SWTObservables.observeText(date),
ObservableUtil
.observeValue(
item,
VerificationPackage.Literals.CHECK_ITEM__LAST_UPDATE),
null, new UpdateValueStrategy()
dbc.bindValue(SWTObservables.observeText(date), ObservableUtil
.observeValue(item, CHECK_ITEM__LAST_UPDATE), null,
new UpdateValueStrategy()
.setConverter(new DateToStringConverter(
"yyyy-MM-dd HH:mm")));
Text comment = toolkit.createText(composite, "");
GridDataFactory.swtDefaults().minSize(300, SWT.DEFAULT)
.grab(true, false).applyTo(comment);
DataBindingUtils
.bind(dbc,
comment,
item,
FortissToolingKernelPackage.Literals.INAMED_COMMENTED_ELEMENT__COMMENT);
DataBindingUtils.bind(dbc, comment, item,
INAMED_COMMENTED_ELEMENT__COMMENT);
}
}
}
......
......@@ -69,17 +69,14 @@ public class RelationTargetEditingSupport extends EditingSupport {
final RequirementRelation rel = (RequirementRelation) element;
final Requirement target = (Requirement) value;
if (rel.getSource() != null && rel.getSource().getOwner() != null
&& rel.getSource().getOwner().equals(req)) {
if (rel.getSourceRequirement() == req) {
ICommandStackService.INSTANCE.runAsCommand(req,
new CreateRelationCommand(req, target,
IRelationService.INSTANCE.getHandler(rel)));
ICommandStackService.INSTANCE.runAsCommand(req,
new DeleteRelationCommand(rel));
} else if (rel.getTarget() != null
&& rel.getTarget().getOwner() != null
&& rel.getTarget().getOwner().equals(req)) {
} else if (rel.getTargetRequirement() == req) {
ICommandStackService.INSTANCE.runAsCommand(req,
new CreateRelationCommand(target, req,
IRelationService.INSTANCE.getHandler(rel)));
......@@ -89,7 +86,7 @@ public class RelationTargetEditingSupport extends EditingSupport {
throw new IllegalArgumentException();
}
getViewer().update(rel, null);
getViewer().refresh();
}
/** {@inheritDoc} */
......@@ -100,10 +97,10 @@ public class RelationTargetEditingSupport extends EditingSupport {
RequirementRelation rel = (RequirementRelation) element;
if (rel.getSource().eContainer().equals(req))
return rel.getTarget().eContainer();
else if (rel.getTarget().eContainer().equals(req))
return rel.getSource().eContainer();
if (rel.getSourceRequirement() == req)
return rel.getTargetRequirement();
else if (rel.getTargetRequirement() == req)
return rel.getSourceRequirement();
else
throw new IllegalArgumentException();
}
......
......@@ -17,20 +17,12 @@ $Id$
+--------------------------------------------------------------------------*/
package org.fortiss.af3.mira.ui.editor;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;
import org.eclipse.core.databinding.observable.map.IObservableMap;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.jface.databinding.viewers.ObservableMapCellLabelProvider;
import org.eclipse.jface.viewers.LabelProvider;
import org.eclipse.jface.viewers.LabelProviderChangedEvent;
import org.eclipse.jface.viewers.ViewerCell;
import org.fortiss.af3.mira.model.Requirement;
import org.fortiss.af3.mira.model.RequirementRelation;
import org.fortiss.tooling.base.model.element.IConnection;
import org.fortiss.tooling.base.model.element.IHierarchicElement;
import org.fortiss.tooling.kernel.ui.service.IModelElementHandlerService;
/**
......@@ -49,45 +41,25 @@ public final class RelationTargetLabelProvider extends
/** Constructor */
public RelationTargetLabelProvider(Requirement requirement,
IObservableMap[] attributeMaps) {
super(attributeMaps);
IObservableMap attributeMap) {
super(attributeMap);
this.req = requirement;
}
/** {@inheritDoc} */
@Override
public void update(ViewerCell cell) {
try {
RequirementRelation rel = (RequirementRelation) cell.getElement();
EObject o;
if (rel.getSource().eContainer().equals(req)) {
o = rel.getTarget().eContainer();
cell.setText(IModelElementHandlerService.INSTANCE
.getModelElementHandler(o).getName(o));
} else if (rel.getTarget().eContainer().equals(req)) {
o = rel.getSource().eContainer();
cell.setText(IModelElementHandlerService.INSTANCE
.getModelElementHandler(o).getName(o));
}
} catch (NullPointerException e) {
RequirementRelation rel = (RequirementRelation) cell.getElement();
if (rel.getSourceRequirement() == req) {
cell.setText(IModelElementHandlerService.INSTANCE
.getModelElementHandler(rel.getTargetRequirement())
.getName(rel.getTargetRequirement()));
} else if (rel.getTargetRequirement() == req) {
cell.setText(IModelElementHandlerService.INSTANCE
.getModelElementHandler(rel.getSourceRequirement())
.getName(rel.getSourceRequirement()));
} else {
cell.setText("");
}
}
/** {@inheritDoc} */