Commit a98495e3 authored by Sudeep Kanav's avatar Sudeep Kanav
Browse files

rolled back changes to the working version

refs 3020
parent 4a480454
......@@ -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
static interface SSL extends SelectionListener {
private 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.
*/
static ProposalProviderBase mkPP(Function<String, String[]> provider) {
private static ProposalProviderBase mkPP(Function<String, String[]> provider) {
return new ProposalProviderBase() {
@Override
public String[] getProposals(String currentWord) {
......
......@@ -17,6 +17,7 @@ $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;
......@@ -28,16 +29,21 @@ 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.databinding.swt.SWTObservables;
import org.eclipse.jface.layout.GridDataFactory;
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.layout.RowData;
import org.eclipse.swt.layout.RowLayout;
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.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Text;
......@@ -45,9 +51,7 @@ 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;
......@@ -59,11 +63,13 @@ 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.ObservableUtils;
import org.fortiss.tooling.kernel.ui.util.WidgetsFactory;
/**
* Property section for {@link PortSpecification}s.
*
* TODO: USE DATABINDINGS, OMG
*
* @author eder
* @author $Author$
* @version $Rev$
......@@ -81,7 +87,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.
* allowing to do better. TODO: WTF, DATABINDINGS?
* </p>
*/
private boolean userInput;
......@@ -96,10 +102,9 @@ public final class PortSpecificationPropertySection extends PropertySectionBase
// WIDGETS
/** Type Selection */
private ComboViewer typeComboViewer;
private Button NoValAllowed;
/** data propagation buttons */
private PortDataPropagation propagation;
private PortDataPropagation propagate;
/** Button to go to the type. */
private Button goToTypeButton;
......@@ -124,53 +129,124 @@ public final class PortSpecificationPropertySection extends PropertySectionBase
return compareTypes(e1, e2);
}
});
typeComboViewer.addSelectionChangedListener(event -> typeSelectionChangeHandler());
goToTypeButton = createDecoratedButton("Go to type", typeComboViewer.getControl());
goToTypeButton.addSelectionListener((SSL)e -> goToType());
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() {
variableBounds = getWidgetFactory().createComposite(composite);
RowLayout rl = new RowLayout();
rl.center = true;
rl.spacing = 8;
variableBounds.setLayout(rl);
@Override
public void widgetSelected(SelectionEvent e) {
goToType();
}
lowerBound = getWidgetFactory().createText(variableBounds, "", SWT.BORDER);
lowerBound.setLayoutData(new RowData(40, SWT.DEFAULT));
lowerBound.addModifyListener(e -> lowerBoundHandler());
@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");
variableBounds = getWidgetFactory().createComposite(composite);
variableBounds.setLayout(new GridLayout(3, false));
lowerBound = WidgetsFactory.createText(variableBounds, SWT.BORDER, "", 6);
getWidgetFactory().createLabel(variableBounds, "...");
lowerBound.addModifyListener(new ModifyListener() {
upperBound = getWidgetFactory().createText(variableBounds, "", SWT.BORDER);
upperBound.setLayoutData(new RowData(40, SWT.DEFAULT));
upperBound.addModifyListener(e -> upperBoundHandler());
@Override
public void modifyText(ModifyEvent e) {
NoValAllowed = getWidgetFactory().createButton(variableBounds, "NoVal Allowed", SWT.CHECK);
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) {
topLevel.runAsCommand(new Runnable() {
@Override
public void run() {
upperBoundHandler();
}
});
}
});
createFormEntry(variableBounds, "Port Bounds:");
}
propagation = new PortDataPropagation(getWidgetFactory(), composite, this);
createFormEntry(propagation.createPropagationControls(), "Propagate data");
/** 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());
}
}
/** {@inheritDoc} */
@Override
protected void setSectionInput(Object input) {
if(input instanceof EObject) {
topLevel = IPersistencyService.getInstance().getTopLevelElementFor((EObject)input);
/** 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);
}
}
}
if(input instanceof Port) {
port = (Port)input;
spec = ((Port)input).getPortSpecification();
/** 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(spec == null) {
error(AF3ComponentUIActivator.getDefault(),
"PortSpecificationPropertySection input is null!");
} else {
refreshBoundsControls();
/** 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));
}
}
refreshBoundsControls();
refreshGotoTypeButton();
}
/** {@inheritDoc} */
......@@ -192,72 +268,32 @@ public final class PortSpecificationPropertySection extends PropertySectionBase
typeComboViewer.setSelection(new StructuredSelection(types.stream()
.filter(t -> typesAreEqual(t, spec.getType())).collect(Collectors.toList())));
userInput = true;
propagation.refresh(port);
super.dbc.bindValue(SWTObservables.observeSelection(NoValAllowed), ObservableUtils
.observeValue(this.spec,
AF3ComponentPackageImpl.Literals.PORT_SPECIFICATION__NO_VAL_ALLOWED));
propagate.refresh(port);
}
/** 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());
/** {@inheritDoc} */
@Override
protected void setSectionInput(Object input) {
if(input instanceof EObject) {
topLevel = IPersistencyService.getInstance().getTopLevelElementFor((EObject)input);
}
}
/** 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(input instanceof Port) {
port = (Port)input;
spec = ((Port)input).getPortSpecification();
}
/** 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);
}
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);
}
});
}
/** 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. */
......@@ -295,7 +331,7 @@ public final class PortSpecificationPropertySection extends PropertySectionBase
@Override
protected void disableControls() {
super.disableControls();
propagation.enableControls(true);
propagate.enableControls(true);
}
/** {@inheritDoc} */
......
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