Home » Modeling » OCL » OCL Console with history
OCL Console with history [message #494931] |
Tue, 03 November 2009 10:11 |
Patrick Konemann Messages: 116 Registered: July 2009 |
Senior Member |
|
|
This is a multi-part message in MIME format.
--------------020907020302090804000201
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit
Hi newsgroup,
I'm using the OCL console frequently and I am really missing some history function like the unix bash has, for instance.
So I coded one and I think it is really helpful especially when writing long expressions.
Instructions:
1. Apply the attached patch to the org.eclipse.emf.ocl.examples.interpreter project.
2. Run the OCL Console and explore the history with pageUp and pageDown :-)
I hope it might be helpful for some others, too!
Cheers
Patrick
--------------020907020302090804000201
Content-Type: text/plain;
name="ocl_console_history.patch"
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment;
filename="ocl_console_history.patch"
Index: src/org/eclipse/emf/ocl/examples/interpreter/console/OCLCons olePage.java
============================================================ =======
RCS file: /cvsroot/modeling/org.eclipse.mdt/org.eclipse.ocl/examples/o rg.eclipse.emf.ocl.examples.interpreter/src/org/eclipse/emf/ ocl/examples/interpreter/console/OCLConsolePage.java,v
retrieving revision 1.21
diff -u -r1.21 OCLConsolePage.java
--- src/org/eclipse/emf/ocl/examples/interpreter/console/OCLCons olePage.java 5 Oct 2008 14:35:44 -0000 1.21
+++ src/org/eclipse/emf/ocl/examples/interpreter/console/OCLCons olePage.java 3 Nov 2009 10:05:04 -0000
@@ -18,6 +18,7 @@
package org.eclipse.emf.ocl.examples.interpreter.console;
+import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
@@ -129,6 +130,9 @@
private OCL<?, Object, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?> ocl;
private ModelingLevel modelingLevel = ModelingLevel.M2;
+ private List<String> history = new ArrayList<String>();
+ private int currentHistoryPointer = 0;
+
private Map<TargetMetamodel, IAction> metamodelActions =
new java.util.HashMap<TargetMetamodel, IAction>();
@@ -586,6 +590,8 @@
/**
* A key listener that listens for the Enter key to evaluate the OCL
* expression.
+ *
+ * added: history management via pageUp and pageDown
*/
private class InputKeyListener implements KeyListener {
private boolean evaluationSuccess = false;;
@@ -600,6 +606,36 @@
}
break;
+ case SWT.PAGE_UP :
+ if (!input.isContentAssistActive()
+ && (e.stateMask & (SWT.CTRL | SWT.SHIFT)) == 0) {
+
+ // history
+ if (currentHistoryPointer == 0 && history.size() > 0) {
+ if (history.get(0).trim().length() == 0)
+ history.remove(0);
+ history.add(0, document.get());
+ currentHistoryPointer = 1;
+ document.set(history.get(currentHistoryPointer));
+ } else if (currentHistoryPointer < history.size() - 1) {
+ currentHistoryPointer++;
+ document.set(history.get(currentHistoryPointer));
+ }
+ }
+
+ break;
+ case SWT.PAGE_DOWN :
+ if (!input.isContentAssistActive()
+ && (e.stateMask & (SWT.CTRL | SWT.SHIFT)) == 0) {
+
+ // history
+ if (currentHistoryPointer > 0) {
+ currentHistoryPointer--;
+ document.set(history.get(currentHistoryPointer));
+ }
+ }
+
+ break;
}
}
@@ -609,6 +645,12 @@
if ((e.stateMask & SWT.CTRL) == 0) {
if (evaluationSuccess) {
document.set(""); //$NON-NLS-1$
+
+ // history
+ if (history.get(0).trim().length() == 0)
+ history.remove(0);
+ history.add(0, lastOCLExpression);
+ currentHistoryPointer = 0;
}
evaluationSuccess = false;
--------------020907020302090804000201--
|
|
| | |
Re: OCL Console with history [message #495297 is a reply to message #495123] |
Wed, 04 November 2009 14:17 |
Patrick Konemann Messages: 116 Registered: July 2009 |
Senior Member |
|
|
Hi Ed,
of course: https://bugs.eclipse.org/bugs/show_bug.cgi?id=294200
Cheers
Patrick
On 03-11-2009 21:37, Ed Willink wrote:
> Hi Patrick
>
> That looks to be a useful simple patch that we can easily review and
> incorporate.
>
> Unfortunately Eclipse IP procedures require contributions via Bugzilla,
> so can you please arise a Bugzilla and attach the patch to it, with an
> assurance that the patch is all your own work and that your employer
> is happy for you to contribute it.
>
> Regards
>
> Ed Willink
>
>
> Patrick Könemann wrote:
>> Hi again,
>>
>> sorry for sending yet another message, but I realized that an
>> ArrayOutOfBoundsException might occur if the history is empty and you
>> already press pageUp/pageDown.
>> The new patch is attached :-)
>>
>> Cheers
>> Patrick
>>
>>
>> On 03-11-2009 11:11, Patrick Könemann wrote:
>>> Hi newsgroup,
>>>
>>> I'm using the OCL console frequently and I am really missing some
>>> history function like the unix bash has, for instance.
>>> So I coded one and I think it is really helpful especially when writing
>>> long expressions.
>>>
>>> Instructions:
>>> 1. Apply the attached patch to the
>>> org.eclipse.emf.ocl.examples.interpreter project.
>>> 2. Run the OCL Console and explore the history with pageUp and
>>> pageDown :-)
>>>
>>> I hope it might be helpful for some others, too!
>>>
>>> Cheers
>>> Patrick
>>
|
|
|
Goto Forum:
Current Time: Fri Apr 19 22:04:36 GMT 2024
Powered by FUDForum. Page generated in 0.03050 seconds
|