Commit 20792bea authored by fortissBot's avatar fortissBot
Browse files

Added NoValAllowed Flag to ports.

refs 3020
parent 4d1debad
......@@ -55,7 +55,7 @@ import org.fortiss.tooling.kernel.utils.EcoreUtils;
* @version $Rev: 1650 $
* @ConQAT.Rating GREEN Hash: 40CEAD77564AE9F6F44489DF1B00C3EF
*/
public class PortDataPropagation implements SelectionListener {
class PortDataPropagation implements SelectionListener {
/**
* Interface for classes providing access to port specifications and
* providing and copying method for port specification.
......@@ -159,8 +159,8 @@ public class PortDataPropagation implements SelectionListener {
@Override
public void widgetSelected(SelectionEvent e) {
ITopLevelElement topLevel =
IPersistencyService.getInstance().getTopLevelElementFor(portDataAccess
.getPortSpecification());
IPersistencyService.getInstance().getTopLevelElementFor(
portDataAccess.getPortSpecification());
topLevel.runAsCommand(new Runnable() {
@Override
public void run() {
......
......@@ -85,7 +85,7 @@ public class PortInitValueSection extends PropertySectionBase {
buttonEnabler = new ComplexDataDialogButtonEnableListener(null, structInitHelperButton);
new FieldAssist(initialValueText, mkPP(word -> createInitialValueProposals(spec)));
composite.pack();
// composite.pack();
}
/** {@inheritDoc} */
......@@ -160,7 +160,7 @@ public class PortInitValueSection extends PropertySectionBase {
* @ConQAT.Rating RED Hash:
*/
@FunctionalInterface
private interface SSL extends SelectionListener {
static interface SSL extends SelectionListener {
/** {@inheritDoc} */
@Override
default public void widgetDefaultSelected(SelectionEvent e) {
......@@ -173,7 +173,7 @@ public class PortInitValueSection extends PropertySectionBase {
* Constructs a proposal provider with the supplied provider function. Uses whitespace policies
* from ProposalProviderBase.
*/
private static ProposalProviderBase mkPP(Function<String, String[]> provider) {
static ProposalProviderBase mkPP(Function<String, String[]> provider) {
return new ProposalProviderBase() {
@Override
public String[] getProposals(String currentWord) {
......
......@@ -17,7 +17,6 @@ $Id$
+--------------------------------------------------------------------------*/
package org.fortiss.af3.component.ui.properties;
import static org.fortiss.af3.component.AF3ComponentActivator.getDefault;
import static org.fortiss.af3.component.ui.properties.PortDataPropagation.getPortsToPropagate;
import static org.fortiss.af3.expression.utils.ExpressionUtils.getAllVisibleTypes;
import static org.fortiss.tooling.kernel.utils.EcoreUtils.copy;
......@@ -29,21 +28,16 @@ import java.util.stream.Collectors;
import org.conqat.lib.commons.collections.Pair;
import org.eclipse.emf.common.util.EList;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.jface.layout.GridDataFactory;
import org.eclipse.jface.databinding.swt.SWTObservables;
import org.eclipse.jface.viewers.ArrayContentProvider;
import org.eclipse.jface.viewers.ComboViewer;
import org.eclipse.jface.viewers.ISelectionChangedListener;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.viewers.SelectionChangedEvent;
import org.eclipse.jface.viewers.StructuredSelection;
import org.eclipse.jface.viewers.Viewer;
import org.eclipse.jface.viewers.ViewerComparator;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.ModifyEvent;
import org.eclipse.swt.events.ModifyListener;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.events.SelectionListener;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.layout.RowData;
import org.eclipse.swt.layout.RowLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Text;
......@@ -51,7 +45,9 @@ import org.eclipse.ui.views.properties.tabbed.TabbedPropertySheetPage;
import org.fortiss.af3.component.model.Channel;
import org.fortiss.af3.component.model.Port;
import org.fortiss.af3.component.model.PortSpecification;
import org.fortiss.af3.component.model.impl.AF3ComponentPackageImpl;
import org.fortiss.af3.component.ui.AF3ComponentUIActivator;
import org.fortiss.af3.component.ui.properties.PortInitValueSection.SSL;
import org.fortiss.af3.expression.model.DataDictionary;
import org.fortiss.af3.expression.model.types.TInt;
import org.fortiss.af3.expression.ui.editor.DataDictionaryEditorGUI;
......@@ -63,13 +59,11 @@ import org.fortiss.tooling.kernel.extension.data.ITopLevelElement;
import org.fortiss.tooling.kernel.service.IPersistencyService;
import org.fortiss.tooling.kernel.ui.extension.base.PropertySectionBase;
import org.fortiss.tooling.kernel.ui.service.IModelEditorBindingService;
import org.fortiss.tooling.kernel.ui.util.WidgetsFactory;
import org.fortiss.tooling.kernel.ui.util.ObservableUtils;
/**
* Property section for {@link PortSpecification}s.
*
* TODO: USE DATABINDINGS, OMG
*
* @author eder
* @author $Author$
* @version $Rev$
......@@ -87,7 +81,7 @@ public final class PortSpecificationPropertySection extends PropertySectionBase
* Needed because a "selected" event / text changed event is triggered in all cases and we do
* not want to register any transaction if the change does not come from the user. Not so nice
* but the interface of the {@link ComboViewer} / {@link Text} does not provide any tool
* allowing to do better. TODO: WTF, DATABINDINGS?
* allowing to do better.
* </p>
*/
private boolean userInput;
......@@ -102,9 +96,10 @@ public final class PortSpecificationPropertySection extends PropertySectionBase
// WIDGETS
/** Type Selection */
private ComboViewer typeComboViewer;
private Button NoValAllowed;
/** data propagation buttons */
private PortDataPropagation propagate;
private PortDataPropagation propagation;
/** Button to go to the type. */
private Button goToTypeButton;
......@@ -129,124 +124,53 @@ public final class PortSpecificationPropertySection extends PropertySectionBase
return compareTypes(e1, e2);
}
});
typeComboViewer.addSelectionChangedListener(event -> typeSelectionChangeHandler());
goToTypeButton = getWidgetFactory().createButton(composite, "Go to type", SWT.NONE);
createFormEntry(goToTypeButton, "");
GridDataFactory.defaultsFor(goToTypeButton).hint("Go to type".length() * 10, SWT.DEFAULT)
.align(SWT.BEGINNING, SWT.BEGINNING).applyTo(goToTypeButton);
goToTypeButton.addSelectionListener(new SelectionListener() {
@Override
public void widgetSelected(SelectionEvent e) {
goToType();
}
@Override
public void widgetDefaultSelected(SelectionEvent e) {
// EMPTY - needed for typeButton
}
});
typeComboViewer.addSelectionChangedListener(new ISelectionChangedListener() {
@Override
public void selectionChanged(SelectionChangedEvent event) {
if(userInput) {
topLevel.runAsCommand(new Runnable() {
@Override
public void run() {
typeSelectionChangeHandler();
}
});
}
}
});
propagate = new PortDataPropagation(getWidgetFactory(), composite, this);
createFormEntry(propagate.createPropagationControls(), "Propagate data");
goToTypeButton = createDecoratedButton("Go to type", typeComboViewer.getControl());
goToTypeButton.addSelectionListener((SSL)e -> goToType());
variableBounds = getWidgetFactory().createComposite(composite);
variableBounds.setLayout(new GridLayout(3, false));
RowLayout rl = new RowLayout();
rl.center = true;
rl.spacing = 8;
variableBounds.setLayout(rl);
lowerBound = getWidgetFactory().createText(variableBounds, "", SWT.BORDER);
lowerBound.setLayoutData(new RowData(40, SWT.DEFAULT));
lowerBound.addModifyListener(e -> lowerBoundHandler());
lowerBound = WidgetsFactory.createText(variableBounds, SWT.BORDER, "", 6);
getWidgetFactory().createLabel(variableBounds, "...");
lowerBound.addModifyListener(new ModifyListener() {
@Override
public void modifyText(ModifyEvent e) {
upperBound = getWidgetFactory().createText(variableBounds, "", SWT.BORDER);
upperBound.setLayoutData(new RowData(40, SWT.DEFAULT));
upperBound.addModifyListener(e -> upperBoundHandler());
topLevel.runAsCommand(new Runnable() {
@Override
public void run() {
lowerBoundHandler();
}
});
}
});
upperBound = WidgetsFactory.createText(variableBounds, SWT.BORDER, "", 6);
upperBound.addModifyListener(new ModifyListener() {
@Override
public void modifyText(ModifyEvent e) {
NoValAllowed = getWidgetFactory().createButton(variableBounds, "NoVal Allowed", SWT.CHECK);
topLevel.runAsCommand(new Runnable() {
@Override
public void run() {
upperBoundHandler();
}
});
}
});
createFormEntry(variableBounds, "Port Bounds:");
}
/** Opens the data dictionary with the selected type being shown. */
private void goToType() {
IStructuredSelection selection = (IStructuredSelection)typeComboViewer.getSelection();
IType selectedType = (IType)selection.getFirstElement();
if(!isBuiltInType(selectedType)) {
DataDictionary dd = DataDictionaryUtils.findDataDictionary(port);
goToTypeButton.setEnabled(true);
IModelEditorBindingService.getInstance().openInEditor(dd);
DataDictionaryEditorGUI.setFilteredTree(selectedType.toString());
}
propagation = new PortDataPropagation(getWidgetFactory(), composite, this);
createFormEntry(propagation.createPropagationControls(), "Propagate data");
}
/** Sets the lower bound in the model. */
private void lowerBoundHandler() {
if(spec.getType() instanceof TInt) {
TInt intType = (TInt)spec.getType();
Integer boundValue = Integer.parseInt(lowerBound.getText());
if(boundValue != null) {
intType.setLowerBound(boundValue);
}
/** {@inheritDoc} */
@Override
protected void setSectionInput(Object input) {
if(input instanceof EObject) {
topLevel = IPersistencyService.getInstance().getTopLevelElementFor((EObject)input);
}
}
/** Sets the upper bound in the model. */
private void upperBoundHandler() {
if(spec.getType() instanceof TInt) {
TInt intType = (TInt)spec.getType();
Integer boundValue = Integer.parseInt(upperBound.getText());
if(boundValue != null) {
intType.setUpperBound(boundValue);
}
if(input instanceof Port) {
port = (Port)input;
spec = ((Port)input).getPortSpecification();
}
}
/** Handles type selection change. */
private void typeSelectionChangeHandler() {
IStructuredSelection selection = (IStructuredSelection)typeComboViewer.getSelection();
IType selectedType = (IType)selection.getFirstElement();
if(!typesAreEqual(selectedType, spec.getType())) {
spec.setType(copy(selectedType));
for(Pair<Channel, Port> c : getPortsToPropagate(port, getPart())) {
c.getSecond().getPortSpecification().setType(copy(selectedType));
}
if(spec == null) {
error(AF3ComponentUIActivator.getDefault(),
"PortSpecificationPropertySection input is null!");
} else {
refreshBoundsControls();
}
refreshBoundsControls();
refreshGotoTypeButton();
}
/** {@inheritDoc} */
......@@ -268,32 +192,72 @@ public final class PortSpecificationPropertySection extends PropertySectionBase
typeComboViewer.setSelection(new StructuredSelection(types.stream()
.filter(t -> typesAreEqual(t, spec.getType())).collect(Collectors.toList())));
userInput = true;
propagate.refresh(port);
propagation.refresh(port);
super.dbc.bindValue(SWTObservables.observeSelection(NoValAllowed), ObservableUtils
.observeValue(this.spec,
AF3ComponentPackageImpl.Literals.PORT_SPECIFICATION__NO_VAL_ALLOWED));
}
/** {@inheritDoc} */
@Override
protected void setSectionInput(Object input) {
if(input instanceof EObject) {
topLevel = IPersistencyService.getInstance().getTopLevelElementFor((EObject)input);
/** Opens the data dictionary with the selected type being shown. */
private void goToType() {
IStructuredSelection selection = (IStructuredSelection)typeComboViewer.getSelection();
IType selectedType = (IType)selection.getFirstElement();
if(!isBuiltInType(selectedType)) {
DataDictionary dd = DataDictionaryUtils.findDataDictionary(port);
goToTypeButton.setEnabled(true);
IModelEditorBindingService.getInstance().openInEditor(dd);
DataDictionaryEditorGUI.setFilteredTree(selectedType.toString());
}
}
if(input instanceof Port) {
port = (Port)input;
spec = ((Port)input).getPortSpecification();
}
/** Sets the lower bound in the model. */
private void lowerBoundHandler() {
topLevel.runAsCommand(() -> {
if(spec.getType() instanceof TInt) {
TInt intType = (TInt)spec.getType();
Integer boundValue = Integer.parseInt(lowerBound.getText());
if(boundValue != null) {
intType.setLowerBound(boundValue);
}
}
});
}
if(spec == null) {
error(AF3ComponentUIActivator.getDefault(),
"PortSpecificationPropertySection input is null!");
} else {
// Check if the parent component of the port is strong causal or not.
try {
refreshBoundsControls();
} catch(ClassCastException ex) {
error(getDefault(), "The port parent component was not found.", ex);
/** Sets the upper bound in the model. */
private void upperBoundHandler() {
topLevel.runAsCommand(() -> {
if(spec.getType() instanceof TInt) {
TInt intType = (TInt)spec.getType();
Integer boundValue = Integer.parseInt(upperBound.getText());
if(boundValue != null) {
intType.setUpperBound(boundValue);
}
}
});
}
/** Handles type selection change. */
private void typeSelectionChangeHandler() {
if(userInput) {
topLevel.runAsCommand(new Runnable() {
@Override
public void run() {
IStructuredSelection selection =
(IStructuredSelection)typeComboViewer.getSelection();
IType selectedType = (IType)selection.getFirstElement();
if(!typesAreEqual(selectedType, spec.getType())) {
spec.setType(copy(selectedType));
for(Pair<Channel, Port> c : getPortsToPropagate(port, getPart())) {
c.getSecond().getPortSpecification().setType(copy(selectedType));
}
}
}
});
}
refreshBoundsControls();
refreshGotoTypeButton();
}
/** Refreshes the BoundControlls. */
......@@ -331,7 +295,7 @@ public final class PortSpecificationPropertySection extends PropertySectionBase
@Override
protected void disableControls() {
super.disableControls();
propagate.enableControls(true);
propagation.enableControls(true);
}
/** {@inheritDoc} */
......
......@@ -244,6 +244,8 @@
<eStructuralFeatures xsi:type="ecore:EReference" name="initialValue" eType="ecore:EClass platform:/resource/org.fortiss.af3.expression/model/expression.ecore#//terms/IExpressionTerm"
containment="true"/>
<eStructuralFeatures xsi:type="ecore:EAttribute" name="stateSignal" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EBoolean"/>
<eStructuralFeatures xsi:type="ecore:EAttribute" name="NoValAllowed" lowerBound="1"
eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EBoolean" defaultValueLiteral="true"/>
</eClassifiers>
<eClassifiers xsi:type="ecore:EClass" name="ComponentRef" eSuperTypes="#//Component platform:/resource/org.fortiss.tooling.kernel/model/kernel.ecore#//ILibraryElementReference">
<eOperations name="getOutputPorts" upperBound="-1" eType="#//OutputPort">
......
......@@ -94,6 +94,7 @@
<genFeatures property="None" children="true" createChild="true" ecoreFeature="ecore:EReference component.ecore#//PortSpecification/type"/>
<genFeatures property="None" children="true" createChild="true" ecoreFeature="ecore:EReference component.ecore#//PortSpecification/initialValue"/>
<genFeatures createChild="false" ecoreFeature="ecore:EAttribute component.ecore#//PortSpecification/stateSignal"/>
<genFeatures createChild="false" ecoreFeature="ecore:EAttribute component.ecore#//PortSpecification/NoValAllowed"/>
<genOperations ecoreOperation="component.ecore#//PortSpecification/propagate">
<genParameters ecoreParameter="component.ecore#//PortSpecification/propagate/dest"/>
</genOperations>
......
......@@ -39,6 +39,7 @@ public class PortSpecificationStaticImpl {
PortSpecification portSrc = (PortSpecification)src;
portDest.setInitialValue(copy(portSrc.getInitialValue()));
portDest.setType(copy(portSrc.getType()));
portDest.setNoValAllowed(portSrc.isNoValAllowed());
}
}
}
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