|
Lines 24-29
Link Here
|
| 24 |
import java.util.Iterator; |
24 |
import java.util.Iterator; |
| 25 |
import java.util.List; |
25 |
import java.util.List; |
| 26 |
import java.util.Map; |
26 |
import java.util.Map; |
|
|
27 |
import java.util.Vector; |
| 27 |
|
28 |
|
| 28 |
import org.eclipse.core.runtime.FileLocator; |
29 |
import org.eclipse.core.runtime.FileLocator; |
| 29 |
import org.eclipse.core.runtime.IAdaptable; |
30 |
import org.eclipse.core.runtime.IAdaptable; |
|
Lines 80-85
Link Here
|
| 80 |
import org.eclipse.swt.SWT; |
81 |
import org.eclipse.swt.SWT; |
| 81 |
import org.eclipse.swt.custom.SashForm; |
82 |
import org.eclipse.swt.custom.SashForm; |
| 82 |
import org.eclipse.swt.custom.StyleRange; |
83 |
import org.eclipse.swt.custom.StyleRange; |
|
|
84 |
import org.eclipse.swt.custom.StyledText; |
| 83 |
import org.eclipse.swt.events.KeyEvent; |
85 |
import org.eclipse.swt.events.KeyEvent; |
| 84 |
import org.eclipse.swt.events.KeyListener; |
86 |
import org.eclipse.swt.events.KeyListener; |
| 85 |
import org.eclipse.swt.graphics.Color; |
87 |
import org.eclipse.swt.graphics.Color; |
|
Lines 111-116
Link Here
|
| 111 |
private static int BUNDLE_AVAILABLE = Bundle.RESOLVED | Bundle.ACTIVE | |
113 |
private static int BUNDLE_AVAILABLE = Bundle.RESOLVED | Bundle.ACTIVE | |
| 112 |
Bundle.STARTING; |
114 |
Bundle.STARTING; |
| 113 |
|
115 |
|
|
|
116 |
/** |
| 117 |
* The number of expressions to save in the history. |
| 118 |
*/ |
| 119 |
public static int OCL_EXPRESSION_RING_BUFFER_SIZE = 10; |
| 120 |
|
| 121 |
private static String lineSeparator = System.getProperty("line.separator"); |
| 114 |
private Composite page; |
122 |
private Composite page; |
| 115 |
|
123 |
|
| 116 |
private ITextViewer output; |
124 |
private ITextViewer output; |
|
Lines 119-125
Link Here
|
| 119 |
|
127 |
|
| 120 |
private ColorManager colorManager; |
128 |
private ColorManager colorManager; |
| 121 |
|
129 |
|
| 122 |
private String lastOCLExpression; |
130 |
private final Vector<String> oclExpressionHistory = new Vector<String>(OCL_EXPRESSION_RING_BUFFER_SIZE); |
| 123 |
private EObject context; |
131 |
private EObject context; |
| 124 |
|
132 |
|
| 125 |
private ISelectionService selectionService; |
133 |
private ISelectionService selectionService; |
|
Lines 197-204
Link Here
|
| 197 |
|
205 |
|
| 198 |
input = new OCLSourceViewer(page, colorManager, SWT.BORDER | SWT.MULTI); |
206 |
input = new OCLSourceViewer(page, colorManager, SWT.BORDER | SWT.MULTI); |
| 199 |
input.setDocument(document); |
207 |
input.setDocument(document); |
| 200 |
input.getTextWidget().addKeyListener(new InputKeyListener()); |
208 |
input.getTextWidget().addKeyListener(new InputKeyListener(input.getTextWidget())); |
| 201 |
|
209 |
|
| 202 |
selectionListener = new ISelectionListener() { |
210 |
selectionListener = new ISelectionListener() { |
| 203 |
public void selectionChanged(IWorkbenchPart part, ISelection selection) { |
211 |
public void selectionChanged(IWorkbenchPart part, ISelection selection) { |
| 204 |
OCLConsolePage.this.selectionChanged(selection); |
212 |
OCLConsolePage.this.selectionChanged(selection); |
|
Lines 432-438
Link Here
|
| 432 |
} |
440 |
} |
| 433 |
|
441 |
|
| 434 |
// store the successfully parsed expression |
442 |
// store the successfully parsed expression |
| 435 |
lastOCLExpression = expression; |
443 |
if (oclExpressionHistory.size() == oclExpressionHistory.capacity()) { |
|
|
444 |
oclExpressionHistory.remove(0); |
| 445 |
} |
| 446 |
|
| 447 |
if (expression.endsWith(lineSeparator)) { |
| 448 |
int offset = expression.length() - lineSeparator.length(); |
| 449 |
expression = expression.substring(0, offset); |
| 450 |
} |
| 451 |
oclExpressionHistory.add(expression); |
| 436 |
} catch (Exception e) { |
452 |
} catch (Exception e) { |
| 437 |
result = false; |
453 |
result = false; |
| 438 |
error((e.getLocalizedMessage() == null) ? e.getClass().getName() |
454 |
error((e.getLocalizedMessage() == null) ? e.getClass().getName() |
|
Lines 590-595
Link Here
|
| 590 |
private class InputKeyListener implements KeyListener { |
606 |
private class InputKeyListener implements KeyListener { |
| 591 |
private boolean evaluationSuccess = false;; |
607 |
private boolean evaluationSuccess = false;; |
| 592 |
|
608 |
|
|
|
609 |
private final StyledText textWidget; |
| 610 |
|
| 611 |
public InputKeyListener(StyledText textWidget) { |
| 612 |
super(); |
| 613 |
this.textWidget = textWidget; |
| 614 |
} |
| 615 |
|
| 593 |
public void keyPressed(KeyEvent e) { |
616 |
public void keyPressed(KeyEvent e) { |
| 594 |
switch (e.keyCode) { |
617 |
switch (e.keyCode) { |
| 595 |
case SWT.CR : |
618 |
case SWT.CR : |
|
Lines 619-624
Link Here
|
| 619 |
if ((e.stateMask & SWT.CTRL) == SWT.CTRL) { |
642 |
if ((e.stateMask & SWT.CTRL) == SWT.CTRL) { |
| 620 |
input.getContentAssistant().showPossibleCompletions(); |
643 |
input.getContentAssistant().showPossibleCompletions(); |
| 621 |
} |
644 |
} |
|
|
645 |
break; |
| 646 |
|
| 647 |
case SWT.PAGE_UP: |
| 648 |
if (!oclExpressionHistory.isEmpty()) { |
| 649 |
String lastExpression = oclExpressionHistory.remove(oclExpressionHistory.size()-1); |
| 650 |
oclExpressionHistory.add(0, lastExpression); |
| 651 |
document.set(oclExpressionHistory.lastElement()); |
| 652 |
textWidget.setCaretOffset(document.getLength()); |
| 653 |
} |
| 654 |
break; |
| 655 |
|
| 656 |
case SWT.PAGE_DOWN: |
| 657 |
if (!oclExpressionHistory.isEmpty()) { |
| 658 |
String firstExpression = oclExpressionHistory.remove(0); |
| 659 |
oclExpressionHistory.add(firstExpression); |
| 660 |
document.set(oclExpressionHistory.lastElement()); |
| 661 |
textWidget.setCaretOffset(document.getLength()); |
| 662 |
} |
| 663 |
break; |
| 622 |
} |
664 |
} |
| 623 |
} |
665 |
} |
| 624 |
} |
666 |
} |
|
Lines 682-688
Link Here
|
| 682 |
public void run() { |
724 |
public void run() { |
| 683 |
Shell shell = getControl().getShell(); |
725 |
Shell shell = getControl().getShell(); |
| 684 |
|
726 |
|
| 685 |
if (lastOCLExpression != null) { |
727 |
if (! oclExpressionHistory.isEmpty()) { |
| 686 |
FileDialog dlg = new FileDialog(shell, SWT.SAVE); |
728 |
FileDialog dlg = new FileDialog(shell, SWT.SAVE); |
| 687 |
dlg.setFilterExtensions(new String[] {"*.xmi"}); //$NON-NLS-1$ |
729 |
dlg.setFilterExtensions(new String[] {"*.xmi"}); //$NON-NLS-1$ |
| 688 |
dlg.setText(OCLInterpreterMessages.console_saveDlg_title); |
730 |
dlg.setText(OCLInterpreterMessages.console_saveDlg_title); |
|
Lines 690-696
Link Here
|
| 690 |
String file = dlg.open(); |
732 |
String file = dlg.open(); |
| 691 |
if (file != null) { |
733 |
if (file != null) { |
| 692 |
try { |
734 |
try { |
| 693 |
OCLResource.save(file, document, lastOCLExpression); |
735 |
OCLResource.save(file, document, oclExpressionHistory.lastElement()); |
| 694 |
} catch (Exception e) { |
736 |
} catch (Exception e) { |
| 695 |
MessageDialog.openError( |
737 |
MessageDialog.openError( |
| 696 |
shell, |
738 |
shell, |