Commit c7af0c5e authored by Christoph Döbber's avatar Christoph Döbber
Browse files

widely integrated FiedlAssist

refs 563
parent 9f4b1f93
......@@ -19,6 +19,11 @@ package org.fortiss.af3.component.ui.editor;
import static org.eclipse.swt.SWT.LEFT;
import static org.eclipse.swt.SWT.TOP;
import static org.fortiss.af3.component.ui.utils.ComponentFieldAssistUtils.getPorts;
import static org.fortiss.af3.expression.ui.utils.ExpressionFieldAssistUtils.getAllConstructors;
import static org.fortiss.af3.expression.ui.utils.ExpressionFieldAssistUtils.getFunctions;
import static org.fortiss.af3.expression.ui.utils.ExpressionFieldAssistUtils.getPrimitiveValues;
import static org.fortiss.af3.expression.ui.utils.ExpressionFieldAssistUtils.getUsefulExpressions;
import static org.fortiss.tooling.kernel.ui.util.DataBindingUtils.DECORATION_KEY;
import static org.fortiss.tooling.kernel.ui.util.DataBindingUtils.performComplexTextBinding;
import static org.fortiss.tooling.kernel.ui.util.ObservableUtils.observeValue;
......@@ -35,10 +40,8 @@ import org.fortiss.af3.component.model.behavior.code.CodeSpecification;
import org.fortiss.af3.expression.ui.databinding.convert.StatementSequenceToStringConverter;
import org.fortiss.af3.expression.ui.databinding.convert.StringToStatementSequenceConverter;
import org.fortiss.af3.expression.ui.databinding.validate.StringToStatementSequenceValidator;
import org.fortiss.tooling.base.model.element.IConnector;
import org.fortiss.tooling.base.ui.fieldassist.FieldAssist;
import org.fortiss.tooling.base.ui.fieldassist.ProposalProviderBase;
import org.fortiss.tooling.kernel.model.INamedElement;
import org.fortiss.tooling.kernel.ui.extension.base.EditorBase;
/**
......@@ -63,29 +66,18 @@ public class CodeSpecificationEditorBackend extends
gui.getTextField().setData(DECORATION_KEY,
new ControlDecoration(gui.getTextField(), LEFT | TOP));
final String[] staticProposals = new String[] { "if ( ){\n\n}",
"else {\n\n}", "true", "false", "return" };
@SuppressWarnings("unused")
FieldAssist assist = new FieldAssist(gui.getTextField(),
new ProposalProviderBase() {
@Override
/** {@inheritDoc} */
public String[] getProposals(String currentWord) {
// TODO CD: add dynamic proposals like local variables
ArrayList<String> proposals = new ArrayList<String>();
for (IConnector conn : getEditedObject().getComponent()
.getConnectorsList()) {
if (conn instanceof INamedElement) {
proposals.add(((INamedElement) conn).getName());
}
}
for (int i = 0; i < staticProposals.length; i++) {
proposals.add(staticProposals[i]);
}
return proposals.toArray(new String[proposals.size()]);
}
});
new FieldAssist(gui.getTextField(), new ProposalProviderBase() {
@Override
/** {@inheritDoc} */
public String[] getProposals(String currentWord) {
ArrayList<String> prop = getPorts(editedObject.getComponent());
prop.addAll(getFunctions(editedObject));
prop.addAll(getAllConstructors(editedObject, true));
prop.addAll(getPrimitiveValues());
prop.addAll(getUsefulExpressions());
return prop.toArray(new String[0]);
}
});
updateModel();
}
......
......@@ -18,10 +18,15 @@ $Id$
package org.fortiss.af3.component.ui.properties;
import static org.eclipse.emf.ecore.util.EcoreUtil.copy;
import static org.fortiss.af3.expression.ui.utils.ExpressionFieldAssistUtils.getConstructorsForType;
import static org.fortiss.af3.expression.ui.utils.ExpressionFieldAssistUtils.getPrimitiveTypes;
import static org.fortiss.af3.expression.ui.utils.ExpressionFieldAssistUtils.getTypeDefinitions;
import static org.fortiss.tooling.kernel.ui.util.DataBindingUtils.performComplexTextBinding;
import static org.fortiss.tooling.kernel.ui.util.ObservableUtils.observeValue;
import static org.fortiss.tooling.kernel.utils.LoggingUtils.error;
import java.util.ArrayList;
import org.eclipse.core.databinding.observable.value.IObservableValue;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Text;
......@@ -37,6 +42,8 @@ import org.fortiss.af3.expression.ui.databinding.convert.TypeToStringConverter;
import org.fortiss.af3.expression.ui.databinding.validate.StringToIExpressionTermWithTypeCheckValidatorBase;
import org.fortiss.af3.expression.ui.databinding.validate.StringToTypeValidator;
import org.fortiss.af3.project.model.typesystem.IType;
import org.fortiss.tooling.base.ui.fieldassist.FieldAssist;
import org.fortiss.tooling.base.ui.fieldassist.ProposalProviderBase;
import org.fortiss.tooling.kernel.ui.extension.base.PropertySectionBase;
/**
......@@ -82,6 +89,31 @@ public final class PortSpecificationPropertySection extends PropertySectionBase
createFormEntry(PortDataPropagation.newPropagationComposite(
getWidgetFactory(), composite, this), "Propagate data");
setupFieldAssist();
}
/** Creates {@link FieldAssist} for text fields. */
private void setupFieldAssist() {
new FieldAssist(typeText, new ProposalProviderBase() {
/** {@inheritDoc} */
@Override
public String[] getProposals(String currentWord) {
ArrayList<String> proposals = getTypeDefinitions(specification);
proposals.addAll(getPrimitiveTypes());
return proposals.toArray(new String[0]);
}
});
new FieldAssist(initialValueText, new ProposalProviderBase() {
/** {@inheritDoc} */
@Override
public String[] getProposals(String currentWord) {
ArrayList<String> proposals = getConstructorsForType(
specification.getType().toString(), true, specification);
return proposals.toArray(new String[0]);
}
});
}
/** {@inheritDoc} */
......
/*--------------------------------------------------------------------------+
$Id: codetemplates.xml 1 2011-01-01 00:00:01Z hoelzl $
| |
| Copyright 2012 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.component.ui.utils;
import java.util.ArrayList;
import org.fortiss.af3.component.model.Component;
import org.fortiss.tooling.base.model.element.IConnector;
import org.fortiss.tooling.kernel.model.INamedElement;
/**
* Utils class for assembling component related proposals for FieldAssist.
*
* @author doebber
* @author $Author: hoelzl $
* @version $Rev: 18709 $
* @ConQAT.Rating RED Hash:
*/
public class ComponentFieldAssistUtils {
/** Returns all ports of given component. */
public static ArrayList<String> getPorts(Component component) {
ArrayList<String> result = new ArrayList<String>();
for (IConnector conn : component.getConnectorsList()) {
if (conn instanceof INamedElement) {
result.add(((INamedElement) conn).getName());
}
}
return result;
}
}
......@@ -268,4 +268,17 @@ public class ComponentArchitectureUtils {
}
return "UNKNOWN";
}
/**
* Returns this EObject's enclosing component. May return <code>null</code>
* if there is no such component.
*/
public static Component getEnclosingComponent(EObject element) {
EObject iterator = element;
while (iterator.eContainer() != null
&& !(iterator.eContainer() instanceof Component)) {
iterator = iterator.eContainer();
}
return (Component) iterator.eContainer();
}
}
......@@ -17,4 +17,5 @@ Export-Package: org.fortiss.af3.expression.ui,
org.fortiss.af3.expression.ui.editor,
org.fortiss.af3.expression.ui.handler,
org.fortiss.af3.expression.ui.properties,
org.fortiss.af3.expression.ui.prototypes
org.fortiss.af3.expression.ui.prototypes,
org.fortiss.af3.expression.ui.utils
......@@ -17,10 +17,18 @@ $Id$
+--------------------------------------------------------------------------*/
package org.fortiss.af3.expression.ui.properties;
import static org.fortiss.af3.expression.ui.utils.ExpressionFieldAssistUtils.getAllConstructors;
import static org.fortiss.af3.expression.ui.utils.ExpressionFieldAssistUtils.getFunctions;
import static org.fortiss.af3.expression.ui.utils.ExpressionFieldAssistUtils.getPrimitiveTypes;
import static org.fortiss.af3.expression.ui.utils.ExpressionFieldAssistUtils.getPrimitiveValues;
import static org.fortiss.af3.expression.ui.utils.ExpressionFieldAssistUtils.getTypeDefinitions;
import static org.fortiss.af3.expression.ui.utils.ExpressionFieldAssistUtils.getUsefulExpressions;
import static org.fortiss.tooling.kernel.ui.util.DataBindingUtils.DECORATION_KEY;
import static org.fortiss.tooling.kernel.ui.util.DataBindingUtils.performComplexTextBinding;
import static org.fortiss.tooling.kernel.ui.util.ObservableUtils.observeValue;
import java.util.ArrayList;
import org.eclipse.core.databinding.observable.value.IObservableValue;
import org.eclipse.jface.databinding.swt.SWTObservables;
import org.eclipse.jface.fieldassist.ControlDecoration;
......@@ -40,6 +48,8 @@ import org.fortiss.af3.expression.ui.databinding.convert.TypeToStringConverter;
import org.fortiss.af3.expression.ui.databinding.validate.StringToStatementSequenceValidator;
import org.fortiss.af3.expression.ui.databinding.validate.StringToStructureMemberOrParameterValidator;
import org.fortiss.af3.expression.ui.databinding.validate.StringToTypeValidator;
import org.fortiss.tooling.base.ui.fieldassist.FieldAssist;
import org.fortiss.tooling.base.ui.fieldassist.ProposalProviderBase;
import org.fortiss.tooling.kernel.model.FortissToolingKernelPackage;
import org.fortiss.tooling.kernel.ui.extension.base.PropertySectionBase;
......@@ -51,7 +61,8 @@ import org.fortiss.tooling.kernel.ui.extension.base.PropertySectionBase;
* @version $Rev$
* @ConQAT.Rating YELLOW Hash: 1E7B5B694FC9F4F2D2C10EDB3399D713
*/
public final class FunctionDefinitionPropertySection extends PropertySectionBase {
public final class FunctionDefinitionPropertySection extends
PropertySectionBase {
/** The selected {@link FunctionDefinition}. */
protected FunctionDefinition function;
......@@ -90,6 +101,49 @@ public final class FunctionDefinitionPropertySection extends PropertySectionBase
GridData gd = new GridData(SWT.FILL, SWT.FILL, true, true);
gd.heightHint = 150;
definitionText.setLayoutData(gd);
setupFieldAssist();
}
/** Creates {@link FieldAssist} for text fields. */
private void setupFieldAssist() {
new FieldAssist(parametersText, new ProposalProviderBase() {
/** {@inheritDoc} */
@Override
public String[] getProposals(String currentWord) {
ArrayList<String> proposals = getTypeDefinitions(function);
proposals.addAll(getPrimitiveTypes());
return proposals.toArray(new String[0]);
}
/** {@inheritDoc} */
@Override
public char[] getAdditionalWhitespaceChars() {
return new char[] { ':' };
}
});
new FieldAssist(returnTypeText, new ProposalProviderBase() {
/** {@inheritDoc} */
@Override
public String[] getProposals(String currentWord) {
ArrayList<String> proposals = getTypeDefinitions(function);
proposals.addAll(getPrimitiveTypes());
return proposals.toArray(new String[0]);
}
});
new FieldAssist(definitionText, new ProposalProviderBase() {
@Override
/** {@inheritDoc} */
public String[] getProposals(String currentWord) {
ArrayList<String> prop = getFunctions(function);
prop.addAll(getAllConstructors(function, true));
prop.addAll(getPrimitiveValues());
prop.addAll(getUsefulExpressions());
return prop.toArray(new String[0]);
}
});
}
/** {@inheritDoc} */
......
/*--------------------------------------------------------------------------+
$Id: codetemplates.xml 1 2011-01-01 00:00:01Z hoelzl $
| |
| Copyright 2012 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.ui.utils;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import org.eclipse.emf.ecore.EObject;
import org.fortiss.af3.expression.model.DataDictionary;
import org.fortiss.af3.expression.model.definitions.Enumeration;
import org.fortiss.af3.expression.model.definitions.EnumerationMember;
import org.fortiss.af3.expression.model.definitions.FunctionDefinition;
import org.fortiss.af3.expression.model.definitions.TypeDefinition;
import org.fortiss.tooling.kernel.utils.KernelModelElementUtils;
/**
* Utils class for assembling expression related proposals for FieldAssist.
*
* @author doebber
* @author $Author: hoelzl $
* @version $Rev: 18709 $
* @ConQAT.Rating RED Hash:
*/
public class ExpressionFieldAssistUtils {
/** Stores the NoVal value. */
public static String NOVAL = "NoVal";
/** Stores the return keyword. */
public static String RETURN = "return";
/** Stores primitive types. */
public static String[] PRIMITIVE_TYPES = new String[] { "boolean", "int",
"double" };
/** Stores primitive values. */
public static String[] PRIMITIVE_VALUES = new String[] { "true", "false" };
/** Stores useful expressions. */
public static String[] USEFUL_EXPRESSIONS = new String[] { RETURN,
"if ( ){\n\n}", "else {\n\n}" };
/** Returns the {@link DataDictionary} for this model. */
public static DataDictionary getDataDictionary(EObject element) {
return KernelModelElementUtils.getRootElement(element,
DataDictionary.class);
}
/** Returns the {@link #PRIMITIVE_TYPES} as List for convenience. */
public static List<String> getPrimitiveTypes() {
return Arrays.asList(PRIMITIVE_TYPES);
}
/** Returns the {@link #PRIMITIVE_VALUES} as List for convenience. */
public static List<String> getPrimitiveValues() {
return Arrays.asList(PRIMITIVE_VALUES);
}
/** Returns the {@link #USEFUL_EXPRESSIONS} as List for convenience. */
public static List<String> getUsefulExpressions() {
return Arrays.asList(USEFUL_EXPRESSIONS);
}
/** Returns all type definitions. */
public static ArrayList<String> getTypeDefinitions(EObject element) {
ArrayList<String> result = new ArrayList<String>();
DataDictionary dd = getDataDictionary(element);
for (TypeDefinition def : dd.getTypeDefinitionsList()) {
result.add(def.getName());
}
return result;
}
/** Returns all functions. */
public static ArrayList<String> getFunctions(EObject element) {
ArrayList<String> result = new ArrayList<String>();
DataDictionary dd = getDataDictionary(element);
for (FunctionDefinition def : dd.getFunctionsList()) {
result.add(def.getFunction().getName());
}
return result;
}
/**
* Returns all constructors.
*
* @param includeNoVal
* if NoVal is to be included for convenience
*/
public static ArrayList<String> getAllConstructors(EObject element,
boolean includeNoVal) {
ArrayList<String> result = new ArrayList<String>();
DataDictionary dd = getDataDictionary(element);
for (Enumeration def : dd.getEnumerationsList()) {
for (EnumerationMember mem : def.getMembersList()) {
result.add(mem.getName() + "()");
}
}
if (includeNoVal) {
result.add(NOVAL);
}
// TODO CD: structures not included in release Feb2012
// https://af3.fortiss.org/issues/367
return result;
}
/**
* Returns all constructors of a given type.
*
* @param includeNoVal
* if NoVal is to be included for convenience
*/
public static ArrayList<String> getConstructorsForType(String type,
boolean includeNoVal, EObject element) {
ArrayList<String> result = new ArrayList<String>();
if (type.equals("boolean")) {
result.addAll(getPrimitiveValues());
} else {
DataDictionary dd = getDataDictionary(element);
for (Enumeration def : dd.getEnumerationsList()) {
if (!def.getName().equals(type)) {
continue;
}
for (EnumerationMember mem : def.getMembersList()) {
result.add(mem.getName() + "()");
}
}
}
if (includeNoVal) {
result.add(NOVAL);
}
// TODO CD: structures not included in release Feb2012
// https://af3.fortiss.org/issues/367
return result;
}
}
......@@ -76,8 +76,8 @@ public class ExecutionUnitFigure extends PrettyRoundedRectangle {
gfx.fillRoundRectangle(b, cornerRadius, cornerRadius);
gfx.setAlpha(255);
gfx.setClip(b);
gfx.drawImage(bgr, new Rectangle(bgr.getBounds()), b.getCopy()
.resize(-1, -1));
// gfx.drawImage(bgr, new Rectangle(bgr.getBounds()), b.getCopy()
// .resize(-1, -1));
gfx.setAlpha(200);
} else {
......
......@@ -17,11 +17,18 @@ $Id: codetemplates.xml 1 2011-01-01 00:00:01Z ratiu $
+--------------------------------------------------------------------------*/
package org.fortiss.af3.state.ui.properties;
import static org.fortiss.af3.component.ui.utils.ComponentFieldAssistUtils.getPorts;
import static org.fortiss.af3.component.utils.ComponentArchitectureUtils.getEnclosingComponent;
import static org.fortiss.af3.expression.ui.utils.ExpressionFieldAssistUtils.getAllConstructors;
import static org.fortiss.af3.expression.ui.utils.ExpressionFieldAssistUtils.getFunctions;
import static org.fortiss.af3.expression.ui.utils.ExpressionFieldAssistUtils.getPrimitiveValues;
import static org.fortiss.af3.state.model.AF3StatePackage.Literals.STATE_SPECIFICATION__INITIAL;
import static org.fortiss.af3.state.model.AF3StatePackage.Literals.TRANSITION_SEGMENT_SPECIFICATION__ACTIONS;
import static org.fortiss.tooling.kernel.ui.util.DataBindingUtils.performComplexTextBinding;
import static org.fortiss.tooling.kernel.ui.util.ObservableUtils.observeValue;
import java.util.ArrayList;
import org.eclipse.core.databinding.observable.value.IObservableValue;
import org.eclipse.jface.databinding.swt.SWTObservables;
import org.eclipse.swt.SWT;
......@@ -37,6 +44,8 @@ import org.fortiss.af3.state.model.State;
import org.fortiss.af3.state.model.StateSpecification;
import org.fortiss.af3.state.model.TransitionSegmentSpecification;
import org.fortiss.af3.state.ui.AF3StateUIActivator;
import org.fortiss.tooling.base.ui.fieldassist.FieldAssist;
import org.fortiss.tooling.base.ui.fieldassist.ProposalProviderBase;
import org.fortiss.tooling.kernel.ui.extension.base.PropertySectionBase;
import org.fortiss.tooling.kernel.utils.LoggingUtils;
......@@ -75,6 +84,22 @@ public class StateSpecificationPropertySection extends PropertySectionBase {
initialButton = getWidgetFactory().createButton(composite, "",
SWT.CHECK);
createFormEntry(initialButton, "Is initial:");
setupFieldAssist();
}
/** Creates {@link FieldAssist} for text fields. */
private void setupFieldAssist() {
new FieldAssist(idleActionsText, new ProposalProviderBase() {
@Override
/** {@inheritDoc} */
public String[] getProposals(String currentWord) {
ArrayList<String> prop = getPorts(getEnclosingComponent(state));
prop.addAll(getFunctions(state));
prop.addAll(getAllConstructors(state, true));
prop.addAll(getPrimitiveValues());
return prop.toArray(new String[0]);
}
});
}
/** {@inheritDoc} */
......
......@@ -17,11 +17,18 @@ $Id: codetemplates.xml 1 2011-01-01 00:00:01Z ratiu $
+--------------------------------------------------------------------------*/
package org.fortiss.af3.state.ui.properties;
import static org.fortiss.af3.component.ui.utils.ComponentFieldAssistUtils.getPorts;
import static org.fortiss.af3.component.utils.ComponentArchitectureUtils.getEnclosingComponent;
import static org.fortiss.af3.expression.ui.utils.ExpressionFieldAssistUtils.getAllConstructors;
import static org.fortiss.af3.expression.ui.utils.ExpressionFieldAssistUtils.getFunctions;
import static org.fortiss.af3.expression.ui.utils.ExpressionFieldAssistUtils.getPrimitiveValues;
import static org.fortiss.af3.state.model.AF3StatePackage.Literals.TRANSITION_SEGMENT_SPECIFICATION__ACTIONS;
import static org.fortiss.af3.state.model.AF3StatePackage.Literals.TRANSITION_SEGMENT_SPECIFICATION__GUARD;
import static org.fortiss.tooling.kernel.ui.util.DataBindingUtils.performComplexTextBinding;
import static org.fortiss.tooling.kernel.ui.util.ObservableUtils.observeValue;
import java.util.ArrayList;
import org.eclipse.core.databinding.observable.value.IObservableValue;
import org.eclipse.emf.ecore.util.EcoreUtil;
import org.eclipse.swt.widgets.Composite;
......@@ -38,6 +45,8 @@ import org.fortiss.af3.component.ui.behavior.StringToGuardConverter;
import org.fortiss.af3.component.ui.behavior.StringToGuardValidator;
import org.fortiss.af3.state.model.TransitionSegment;
import org.fortiss.af3.state.model.TransitionSegmentSpecification;
import org.fortiss.tooling.base.ui.fieldassist.FieldAssist;
import org.fortiss.tooling.base.ui.fieldassist.ProposalProviderBase;
import org.fortiss.tooling.base.ui.properties.view.PropertySectionWithCopyPasteBase;
import org.fortiss.tooling.kernel.extension.data.ITopLevelElement;
import org.fortiss.tooling.kernel.service.IPersistencyService;
......@@ -72,6 +81,33 @@ public class TransitionSegmentSpecificationPropertySection extends
actionsText = createDecoratedText("Actions");
createCopyPasteComposite();
setupFieldAssist();
}
/** Creates {@link FieldAssist} for text fields. */
private void setupFieldAssist() {
new FieldAssist(guardText, new ProposalProviderBase() {
@Override
/** {@inheritDoc} */
public String[] getProposals(String currentWord) {
ArrayList<String> prop = getPorts(getEnclosingComponent(specification));
prop.addAll(getFunctions(specification));
prop.addAll(getAllConstructors(specification, true));
prop.addAll(getPrimitiveValues());
return prop.toArray(new String[0]);
}
});
new FieldAssist(actionsText, new ProposalProviderBase() {
@Override