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

reworked evaluator gui

refs 916
parent 2cb83d35
......@@ -19,25 +19,20 @@ package org.fortiss.af3.expression.ui.editor;
import static org.eclipse.swt.SWT.ARROW_DOWN;
import static org.eclipse.swt.SWT.ARROW_UP;
import static org.eclipse.swt.SWT.BORDER;
import static org.eclipse.swt.SWT.CR;
import static org.eclipse.swt.SWT.H_SCROLL;
import static org.eclipse.swt.SWT.LEFT;
import static org.eclipse.swt.SWT.MULTI;
import static org.eclipse.swt.SWT.SINGLE;
import static org.eclipse.swt.SWT.VERTICAL;
import static org.eclipse.swt.SWT.V_SCROLL;
import java.util.LinkedList;
import org.eclipse.swt.custom.SashForm;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.KeyAdapter;
import org.eclipse.swt.events.KeyEvent;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Text;
import org.fortiss.af3.expression.language.ParseException;
import org.fortiss.af3.expression.model.DataDictionary;
import org.fortiss.af3.expression.ui.AF3ExpressionUIActivator;
import org.fortiss.af3.project.model.typesystem.ITerm;
import org.fortiss.af3.project.services.ITypeSystemService;
import org.fortiss.af3.project.typesystem.IEvaluationContext;
......@@ -78,50 +73,68 @@ public final class DataDictionaryEvaluator extends EditorBase<DataDictionary> {
stackPointer = 0;
}
/** Stores the GUI object. */
private DataDictionaryEvaluatorGUI gui;
/** Stores the evaluator help icon. */
private Label evaluatorHelpIcon;
/** Stores the error image. */
private static Image ERROR = AF3ExpressionUIActivator.getImageDescriptor("icons/error.gif")
.createImage();
/** Stores the info image. */
private static Image INFO = AF3ExpressionUIActivator.getImageDescriptor("icons/info.gif")
.createImage();
/** {@inheritDoc} */
@Override
public void createPartControl(Composite parent) {
SashForm form = new SashForm(parent, VERTICAL);
gui = new DataDictionaryEvaluatorGUI(parent, SWT.NONE);
evaluatorOutput = new Text(form, MULTI | H_SCROLL | V_SCROLL | BORDER);
evaluatorOutput.setEditable(false);
evaluatorOutput = gui.getEvalOutputText();
evaluatorHelp = gui.getEvalInfoText();
evaluatorInput = gui.getEvalInputText();
evaluatorHelp = new Label(form, LEFT | BORDER);
evaluatorHelpIcon = gui.getEvalInfoIcon();
evaluatorHelpIcon.setImage(INFO);
evaluatorInput = new Text(form, SINGLE | BORDER);
evaluatorInput.addKeyListener(new KeyAdapter() {
@Override
public void keyReleased(KeyEvent e) {
if (e.keyCode == CR && evaluatorInput.getText() != "") {
if(e.keyCode == CR && evaluatorInput.getText() != "") {
evaluatorHelp.setText("");
evaluatorHelpIcon.setImage(null);
evaluate();
} else if (e.keyCode == ARROW_DOWN) {
} else if(e.keyCode == ARROW_DOWN) {
if (stackPointer < evaluatorStack.size() - 1) {
if(stackPointer < evaluatorStack.size() - 1) {
stackPointer++;
evaluatorInput.setText(evaluatorStack.get(stackPointer));
} else if (stackPointer == evaluatorStack.size() - 1) {
} else if(stackPointer == evaluatorStack.size() - 1) {
stackPointer++;
evaluatorInput.setText("");
}
} else if (e.keyCode == ARROW_UP) {
} else if(e.keyCode == ARROW_UP) {
if (stackPointer > 0) {
if(stackPointer > 0) {
stackPointer--;
evaluatorInput.setText(evaluatorStack.get(stackPointer));
}
} else { // compile and show errors
evaluatorHelp.setText("");
evaluatorHelpIcon.setImage(null);
String input = evaluatorInput.getText().trim();
final ITypeSystemCompiler compiler = ITypeSystemService.INSTANCE
.getHandler(editedObject).getTypeSystemCompiler();
final ITypeSystemCompiler compiler =
ITypeSystemService.INSTANCE.getHandler(editedObject)
.getTypeSystemCompiler();
try {
compiler.compileTerm(input);
} catch (ParseException pe) {
} catch(ParseException pe) {
evaluatorHelp.setText(pe.getMessage());
evaluatorHelpIcon.setImage(ERROR);
}
}
......@@ -146,17 +159,20 @@ public final class DataDictionaryEvaluator extends EditorBase<DataDictionary> {
stackPointer = evaluatorStack.size();
evaluatorInput.setText("");
} catch (Exception e) {
evaluatorHelpIcon.setImage(null);
} catch(Exception e) {
// FIXME CD: thrown exceptions end up in console - especially NPEs
evaluatorHelp.setText(e.getMessage());
evaluatorHelpIcon.setImage(ERROR);
}
}
/** Evaluates the given term. */
private Term<? extends ITerm> evaluateTerm(ITerm term) throws Exception {
ITermEvaluator evaluator = ITypeSystemService.INSTANCE.getHandler(
editedObject).getTermEvaluator();
IEvaluationContext context = ITypeSystemService.INSTANCE
.createEvaluationContext(editedObject);
ITermEvaluator evaluator =
ITypeSystemService.INSTANCE.getHandler(editedObject).getTermEvaluator();
IEvaluationContext context =
ITypeSystemService.INSTANCE.createEvaluationContext(editedObject);
return evaluator.evaluate(term, context);
}
......@@ -170,8 +186,8 @@ public final class DataDictionaryEvaluator extends EditorBase<DataDictionary> {
/** Compiles the given input string. */
private ITerm compileInput(String input) {
input = input.trim();
ITypeSystemCompiler compiler = ITypeSystemService.INSTANCE.getHandler(
editedObject).getTypeSystemCompiler();
ITypeSystemCompiler compiler =
ITypeSystemService.INSTANCE.getHandler(editedObject).getTypeSystemCompiler();
return compiler.compileTerm(input);
}
......
/*--------------------------------------------------------------------------+
$Id$
| |
| 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.editor;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Text;
import org.eclipse.ui.forms.widgets.Form;
import org.eclipse.ui.forms.widgets.FormToolkit;
/**
*
* @author doebber
* @author $Author$
* @version $Rev$
* @ConQAT.Rating GREEN Hash: 29E0AA6A1E4888127A6F4E054DE2098E
*/
public class DataDictionaryEvaluatorGUI extends Composite {
private final FormToolkit formToolkit = new FormToolkit(Display.getDefault());
private Text text;
private Text text_1;
private Composite composite;
private Label lblIcon;
private Label lblErrors;
/**
* Create the composite.
*
* @param parent
* @param style
*/
public DataDictionaryEvaluatorGUI(Composite parent, int style) {
super(parent, style);
setLayout(new FillLayout(SWT.HORIZONTAL));
Form frmEvaluator = formToolkit.createForm(this);
formToolkit.paintBordersFor(frmEvaluator);
frmEvaluator.setText("Evaluator");
formToolkit.decorateFormHeading(frmEvaluator);
frmEvaluator.getBody().setLayout(new GridLayout(1, false));
text =
new Text(frmEvaluator.getBody(), SWT.BORDER | SWT.READ_ONLY | SWT.H_SCROLL |
SWT.V_SCROLL | SWT.CANCEL | SWT.MULTI);
text.setText(">");
text.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
formToolkit.adapt(text, true, true);
composite = new Composite(frmEvaluator.getBody(), SWT.NONE);
composite.setLayout(new GridLayout(2, false));
composite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false, 1, 1));
formToolkit.adapt(composite);
formToolkit.paintBordersFor(composite);
lblIcon = new Label(composite, SWT.NONE);
formToolkit.adapt(lblIcon, true, true);
lblIcon.setText("ICON");
lblErrors = new Label(composite, SWT.NONE);
lblErrors.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false, 1, 1));
formToolkit.adapt(lblErrors, true, true);
lblErrors.setText("Enter terms below...");
text_1 = new Text(frmEvaluator.getBody(), SWT.BORDER);
text_1.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
formToolkit.adapt(text_1, true, true);
}
@Override
protected void checkSubclass() {
// Disable the check that prevents subclassing of SWT components
}
public Text getEvalOutputText() {
return text;
}
public Text getEvalInputText() {
return text_1;
}
public Label getEvalInfoText() {
return lblErrors;
}
public Label getEvalInfoIcon() {
return lblIcon;
}
}
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