Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [bpel-dev] BPEL - Expression Editor is not working, How can we fix this

Hi Bob

I was able to fix the following issues. 

   2. Context Menu is missing
   3. Variable Picker (Which comes when click the context menu) is missing
   4. XPath _expression_ auto fill  functionality is not there.

I think this fix solves many usability issues we had when writing expressions.

In my fix i have introduced context menu (in ExpressionSection class) which enables cut, copy, paste and Variable Picker actions
and also enabled content assist for the StyledText. Following classes were modified in the patch.

plugins/org.eclipse.bpel.ui.noEmbeddedEditors/src/org/eclipse/bpel/ui/contentassist/ExpressionContentAssistProcessor.java
plugins/org.eclipse.bpel.ui.noEmbeddedEditors/src/org/eclipse/bpel/ui/contentassist/ExpressionSourceViewerConfiguration.java
plugins/org.eclipse.bpel.ui.noEmbeddedEditors/src/org/eclipse/bpel/ui/properties/BPELPropertySection.java
plugins/org.eclipse.bpel.ui.noEmbeddedEditors/src/org/eclipse/bpel/ui/properties/ExpressionSection.java

I haven't done the fix for _expression_ Language' selection drop-down menu yet since want to make sure whether this approach is ok. I'd like to contribute this fix and would appreciate if someone could look at this fix and give me some feedback. Here i 'm attaching the git diff of the patch.


Thanks
Susinda



On Wed, Apr 9, 2014 at 6:52 PM, Susinda <susinda@xxxxxxxxx> wrote:
Hi Bob/Lorenzo

Cant we give a try with the fix mentioned in this bug[1], seems like it supports embedding editors inside another(composite). In that case we may not want to remove the embedded editors.
Please give me your thoughts and any guidelines, i'd like to tryout this approach. Your directions are highly appreciated.


Thanks



On Tue, Apr 8, 2014 at 12:17 PM, Lorenzo Bettini <lorenzo.bettini@xxxxxxxxx> wrote:
On 08/04/2014 08:43, Susinda wrote:
> Hi Bob
>
> Currently i do not have experience in Xtext and _expression_ grammars etc,
> however if this is needed i could have a look at those and start. But
> what i was worrying about is other issue that you have reported in [1].
> As i can see we are stuck with the compile error in the EditorInViewSite
> class in org.eclipse.bpel.common.ui.composite. This was due to the api
> change introduced in eclipse Juno. I have few questions on this.
>     Does Lorenzo's patch fix this issue. If so can i have that patch to
> tryout and have a look.

From what I remember, yes, my patch also reintroduce the possibility of
embedding a text editor (actually a text field), independently from
Xtext.  The main point is to NOT use an editor site, but a text field
(again, if I remember correctly :)

>     Where can i found the latest (half completed) source (I'm using the
> source @ http://git.eclipse.org/gitroot/bpel/org.eclipse.bpel.git but
> that doesn't reflect such changes)
>
> Thanks
> Susinda
>
>
>
>
>
>
>
> On Tue, Apr 8, 2014 at 2:53 AM, Bob Brodt <bbrodt@xxxxxxxxxx
> <mailto:bbrodt@xxxxxxxxxx>> wrote:
>
>     Hi Susinda,
>
>     Thanks for the offer to help - it is greatly appreciated :)
>
>     The BPEL _expression_ editor extension is currently half complete:
>     Xtext has been integrated into the project, but we are lacking the
>     _expression_ grammars for XPath (and possibly XPath 2 and java). If
>     you have experience with Xtext and converting an abstract grammar
>     definition into one that can be parsed by Xtext, that would be a
>     great help and we can continue to move the project forward.
>
>     Please let me know if you are willing/able to help in this capacity.
>
>     Thanks,
>     Bob
>
>
>     ------------------------------------------------------------------------
>
>         Hi Bob
>
>         Yes i'm willing to volunteer to fix this issue. If you could
>         give me some points on how/where to start, that would be easy
>         for me to give a quick start.
>         @ Lorenzo - Could you please provide me the link for your patch,
>         So i could start from your patch.
>
>         Thanks all for all the inputs and responses.
>
>         Susinda
>
>
>
>
>         On Sun, Apr 6, 2014 at 2:01 PM, Lorenzo Bettini
>         <lorenzo.bettini@xxxxxxxxx <mailto:lorenzo.bettini@xxxxxxxxx>>
>         wrote:
>
>             Hi
>
>             I don't know whether this is related but last year I
>             submitted a patch to renable the _expression_ editor and also
>             to integrate Xtext languages...
>
>             cheers
>                     Lorenzo
>
>             --
>             Lorenzo Bettini, PhD in Computer Science, DI, Univ. Torino
>             HOME: http://www.lorenzobettini.it
>             Xtext Book:
>             http://www.packtpub.com/implementing-domain-specific-languages-with-xtext-and-xtend/book
>             <http://www.packtpub.com/implementing-domain-specific-languages-with-xtext-and-xtend/book>
>
>
>             On 4/4/2014 7:55 PM, Bob Brodt wrote:
>
>                 Hi Susinda,
>
>                 This is a significant rewrite and, unfortunately has
>                 been put off
>                 because of other ongoing work. We are looking for
>                 volunteers to help
>                 with this project, so if you or someone you know is
>                 interested please
>                 let me know ;)
>                 I don't expect this enhancement to be available until
>                 the Luna release
>                 (June 25) or possibly later.
>
>                 Cheers,
>                 Bob
>
>                 ________________________
>                 Robert ("Bob") Brodt
>                 Senior Software Engineer
>                 JBoss by Red Hat
>
>                 ------------------------------------------------------------------------
>
>
>                     Hi Andrej
>
>                     Thanks a lot for the quick response. I tried with
>                 Kepler and BPEL
>                     1.0.3 and now i can see the editor. But following
>                 parts and features
>                     are missing
>
>                      1. _expression_ Language' selection drop-down menu is
>                 missing
>                      2. Context Menu is missing
>                      3. Variable Picker (Which comes when click the
>                 context menu) is missing
>                      4. XPath _expression_ auto fill functionality is not
>                 there.
>
>
>
>                     The readme file at
>                 org.eclipse.bpel.ui.noEmbeddedEditors package
>                     says following
>
>                     This plugin is essentially a duplicate of
>                 org.eclipse.bpel.ui with
>                     the embedded editor functionality removed.
>                     This was necessary because of breaking
>                 org.eclipse.ui API changes in
>                     Eclipse Juno.
>                     After this feature is rewritten to work with Juno,
>                 this plugin must
>                     be removed and the plugins/pom.xml restored to its
>                 original.
>
>                     I think this is the reason for above (1, 2, 3, 4)
>                 issues. I guess
>                     this need to be properly fixed (i.e this feature is
>                 rewritten) so
>                     these issues will be fixed.
>                     So what i wanted to ask is to know when this will be
>                 fixed, is
>                     anyone working on this or is there any patches etc.
>
>                     Thanks
>
>
>
>                     On Fri, Apr 4, 2014 at 12:06 PM, Andrej Podhradsky
>                     <apodhrad@xxxxxxxxxx <mailto:apodhrad@xxxxxxxxxx>
>                 <mailto:apodhrad@xxxxxxxxxx
>                 <mailto:apodhrad@xxxxxxxxxx>>> wrote:
>
>                         Hi Susinda,
>
>                         I recommend to use Eclipse Kepler for JEE
>                 Develepers with BPEL
>                         plugin of version 1.0.3.
>                         If the problem is still present, could you
>                 report a bug, please?
>
>                         Have a nice day!
>
>                         Andrej
>
>                         ----- Original Message -----
>                         From: "Susinda" <susinda@xxxxxxxxx
>                 <mailto:susinda@xxxxxxxxx> <mailto:susinda@xxxxxxxxx
>                 <mailto:susinda@xxxxxxxxx>>>
>                         To: bpel-dev@xxxxxxxxxxx
>                 <mailto:bpel-dev@xxxxxxxxxxx>
>                 <mailto:bpel-dev@xxxxxxxxxxx <mailto:bpel-dev@xxxxxxxxxxx>>
>                         Sent: Friday, April 4, 2014 7:37:21 AM
>                         Subject: [bpel-dev] BPEL - _expression_ Editor is
>                 not working,
>                           How can we fix this
>
>                         Hi All
>                         I tried to use an _expression_ in assign activity,
>                 but _expression_
>                         editor is not loading so i could not give an
>                 _expression_.
>                         I have read your issue tracker[1] and googled
>                 this issue and got
>                         to know that this issue was because of the
>                         org.eclipse.ui.internal.EditorSite class has
>                 been removed when
>                         eclipse goes to Juno. The mentioned fix @[1] has
>                 removed the
>                         _expression_ editor totally therefore BPEL
>                 Designer plugin
>                         unusable in Eclipse Juno.
>                         May i know when this will be fixed and Do u have
>                 any releases
>                         planned in near future in which this would be fixed.
>                         Also i'd like to contribute to fix this issue,
>                 in that case do
>                         you have any guidelines that would be valuable
>                 for me to
>                         proceed. And i'd like to know if any patches
>                 exists for this issue.
>
>                         Thanks
>                         [1] -
>                 https://bugs.eclipse.org/bugs/show_bug.cgi?id=378997
>                 <https://bugs.eclipse.org/bugs/show_bug.cgi?id=378997>
>
>
>                         --
>                         **********************************
>                         Susinda Perera
>                         B.Sc. (Eng), AMIE(SL)
>                         E-mail : susinda@xxxxxxxxx
>                 <mailto:susinda@xxxxxxxxx> <mailto:susinda@xxxxxxxxx
>                 <mailto:susinda@xxxxxxxxx>>
>                         Voice : 0716049075 <tel:0716049075>
>                 <tel:0716049075 <tel:0716049075>>
>
>                         **********************************
>
>                         _______________________________________________
>                         bpel-dev mailing list
>                         bpel-dev@xxxxxxxxxxx
>                 <mailto:bpel-dev@xxxxxxxxxxx>
>                 <mailto:bpel-dev@xxxxxxxxxxx <mailto:bpel-dev@xxxxxxxxxxx>>
>
>
>                 https://dev.eclipse.org/mailman/listinfo/bpel-dev
>                 <https://dev.eclipse.org/mailman/listinfo/bpel-dev>
>                         _______________________________________________
>                         bpel-dev mailing list
>                         bpel-dev@xxxxxxxxxxx
>                 <mailto:bpel-dev@xxxxxxxxxxx>
>                 <mailto:bpel-dev@xxxxxxxxxxx <mailto:bpel-dev@xxxxxxxxxxx>>
>
>
>                 https://dev.eclipse.org/mailman/listinfo/bpel-dev
>                 <https://dev.eclipse.org/mailman/listinfo/bpel-dev>
>
>
>
>
>                     --
>                     **********************************
>                     Susinda Perera
>                     B.Sc. (Eng), AMIE(SL)
>                     E-mail : susinda@xxxxxxxxx
>                 <mailto:susinda@xxxxxxxxx> <mailto:susinda@xxxxxxxxx
>                 <mailto:susinda@xxxxxxxxx>>
>
>                     Voice  : 0716049075 <tel:0716049075>
>                     **********************************
>
>                     _______________________________________________
>                     bpel-dev mailing list
>                     bpel-dev@xxxxxxxxxxx <mailto:bpel-dev@xxxxxxxxxxx>
>                     https://dev.eclipse.org/mailman/listinfo/bpel-dev
>                 <https://dev.eclipse.org/mailman/listinfo/bpel-dev>
>
>
>
>
>                 _______________________________________________
>                 bpel-dev mailing list
>                 bpel-dev@xxxxxxxxxxx <mailto:bpel-dev@xxxxxxxxxxx>
>                 https://dev.eclipse.org/mailman/listinfo/bpel-dev
>                 <https://dev.eclipse.org/mailman/listinfo/bpel-dev>
>
>
>             _______________________________________________
>             bpel-dev mailing list
>             bpel-dev@xxxxxxxxxxx <mailto:bpel-dev@xxxxxxxxxxx>
>             https://dev.eclipse.org/mailman/listinfo/bpel-dev
>             <https://dev.eclipse.org/mailman/listinfo/bpel-dev>
>
>
>
>
>         --
>         **********************************
>         Susinda Perera
>         B.Sc. (Eng), AMIE(SL)
>         E-mail : susinda@xxxxxxxxx <mailto:susinda@xxxxxxxxx>
>         Voice  : 0716049075 <tel:0716049075>
>         **********************************
>
>         _______________________________________________
>         bpel-dev mailing list
>         bpel-dev@xxxxxxxxxxx <mailto:bpel-dev@xxxxxxxxxxx>
>         https://dev.eclipse.org/mailman/listinfo/bpel-dev
>
>
>
>     _______________________________________________
>     bpel-dev mailing list
>     bpel-dev@xxxxxxxxxxx <mailto:bpel-dev@xxxxxxxxxxx>
>     https://dev.eclipse.org/mailman/listinfo/bpel-dev
>
>
>
>
> --
> **********************************
> Susinda Perera
> B.Sc. (Eng), AMIE(SL)
> E-mail : susinda@xxxxxxxxx <mailto:susinda@xxxxxxxxx>
> Voice  : 0716049075
> **********************************
>
>
> _______________________________________________
> bpel-dev mailing list
> bpel-dev@xxxxxxxxxxx
> https://dev.eclipse.org/mailman/listinfo/bpel-dev
>


--
Lorenzo Bettini, PhD in Computer Science, DI, Univ. Torino
HOME: http://www.lorenzobettini.it
Xtext Book:
http://www.packtpub.com/implementing-domain-specific-languages-with-xtext-and-xtend/book

_______________________________________________
bpel-dev mailing list
bpel-dev@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/bpel-dev



--
**********************************
Susinda Perera
B.Sc. (Eng), AMIE(SL)
Voice  : 0716049075
**********************************



--
**********************************
Susinda Perera
B.Sc. (Eng), AMIE(SL)
Voice  : 0716049075
**********************************
diff --git a/plugins/org.eclipse.bpel.ui.noEmbeddedEditors/src/org/eclipse/bpel/ui/contentassist/ExpressionContentAssistProcessor.java b/plugins/org.eclipse.bpel.ui.noEmbeddedEditors/src/org/eclipse/bpel/ui/contentassist/ExpressionContentAssistProcessor.java
index bc0029a..fe6ad17 100644
--- a/plugins/org.eclipse.bpel.ui.noEmbeddedEditors/src/org/eclipse/bpel/ui/contentassist/ExpressionContentAssistProcessor.java
+++ b/plugins/org.eclipse.bpel.ui.noEmbeddedEditors/src/org/eclipse/bpel/ui/contentassist/ExpressionContentAssistProcessor.java
@@ -22,6 +22,7 @@ import org.eclipse.bpel.ui.BPELUIPlugin;
 import org.eclipse.bpel.ui.IBPELUIConstants;
 import org.eclipse.bpel.ui.details.providers.LinkContentProvider;
 import org.eclipse.bpel.ui.expressions.IEditorConstants;
+import org.eclipse.bpel.ui.properties.BPELPropertySection;
 import org.eclipse.bpel.ui.util.BPELUtil;
 import org.eclipse.bpel.ui.util.XSDUtils;
 import org.eclipse.emf.ecore.EObject;
@@ -61,12 +62,20 @@ public class ExpressionContentAssistProcessor
 	static ICompletionProposal[] EMPTY_COMPLETION_PROPOSALS = {} ; 
 	
 	// members of class ExpressionContentAssistProcessor
-	private Object theModel = null;
+	private Object theModel = null; 
+	private BPELPropertySection propertySection;
+
+	public void setPropertySection(BPELPropertySection propertySection) {
+		this.propertySection = propertySection;
+	}
+		
 	private int theToggle = 3;
 	private String theLastBeginsWith = EMPTY_STRING; 
 	private String theExpressionContext = EMPTY_STRING; 
 	private IContentAssistantExtension2 theContentAssistant;
 	
+	
+
 	/**
 	 * The function templates content assist processor.
 	 */
@@ -938,7 +947,8 @@ public class ExpressionContentAssistProcessor
 				
 		Image linkImg = BPELUIPlugin.INSTANCE.getImage(IBPELUIConstants.ICON_LINK_16);
 		
-		for( Object next : new LinkContentProvider( LinkContentProvider.INCOMING ).getElements(theModel) ) {
+		//for( Object next : new LinkContentProvider( LinkContentProvider.INCOMING ).getElements(theModel) ) {
+		for( Object next : new LinkContentProvider(LinkContentProvider.INCOMING ).getElements(propertySection.getInput())) {
 			Link link = (Link) next;
 			
 			String replName = DOLLAR + link.getName();
@@ -991,7 +1001,8 @@ public class ExpressionContentAssistProcessor
 		if ((slash > -1) || (dot > -1) || (at > -1))
 			seekChildren = true;
 		
-		Variable[] variables = BPELUtil.getVisibleVariables((EObject)theModel);
+		//Variable[] variables = BPELUtil.getVisibleVariables((EObject)theModel); 
+		Variable[] variables = BPELUtil.getVisibleVariables(propertySection.getInput());
 		ArrayList<ICompletionProposal> results = new ArrayList<ICompletionProposal>();
 		CompletionProposal prop = null;
 		String name;
diff --git a/plugins/org.eclipse.bpel.ui.noEmbeddedEditors/src/org/eclipse/bpel/ui/contentassist/ExpressionSourceViewerConfiguration.java b/plugins/org.eclipse.bpel.ui.noEmbeddedEditors/src/org/eclipse/bpel/ui/contentassist/ExpressionSourceViewerConfiguration.java
index 3d47757..a935811 100644
--- a/plugins/org.eclipse.bpel.ui.noEmbeddedEditors/src/org/eclipse/bpel/ui/contentassist/ExpressionSourceViewerConfiguration.java
+++ b/plugins/org.eclipse.bpel.ui.noEmbeddedEditors/src/org/eclipse/bpel/ui/contentassist/ExpressionSourceViewerConfiguration.java
@@ -43,4 +43,8 @@ public class ExpressionSourceViewerConfiguration extends
 		}
 		return bpelAssistant;
 	}
+
+	public ContentAssistant getBpelAssistant() {
+		return bpelAssistant;
+	}
 }
diff --git a/plugins/org.eclipse.bpel.ui.noEmbeddedEditors/src/org/eclipse/bpel/ui/properties/BPELPropertySection.java b/plugins/org.eclipse.bpel.ui.noEmbeddedEditors/src/org/eclipse/bpel/ui/properties/BPELPropertySection.java
index 9033604..edabe84 100644
--- a/plugins/org.eclipse.bpel.ui.noEmbeddedEditors/src/org/eclipse/bpel/ui/properties/BPELPropertySection.java
+++ b/plugins/org.eclipse.bpel.ui.noEmbeddedEditors/src/org/eclipse/bpel/ui/properties/BPELPropertySection.java
@@ -247,7 +247,7 @@ public abstract class BPELPropertySection extends AbstractPropertySection
 		return (T) this.fModelObject;
 	}
 
-	protected final <T extends EObject> T getInput() {
+	public final <T extends EObject> T getInput() {
 		return getModel();
 	}
 
diff --git a/plugins/org.eclipse.bpel.ui.noEmbeddedEditors/src/org/eclipse/bpel/ui/properties/ExpressionSection.java b/plugins/org.eclipse.bpel.ui.noEmbeddedEditors/src/org/eclipse/bpel/ui/properties/ExpressionSection.java
index cbd5f3e..a406c7d 100644
--- a/plugins/org.eclipse.bpel.ui.noEmbeddedEditors/src/org/eclipse/bpel/ui/properties/ExpressionSection.java
+++ b/plugins/org.eclipse.bpel.ui.noEmbeddedEditors/src/org/eclipse/bpel/ui/properties/ExpressionSection.java
@@ -11,18 +11,40 @@
 package org.eclipse.bpel.ui.properties;
 
 import org.eclipse.bpel.model.util.BPELConstants;
+import org.eclipse.bpel.ui.contentassist.ExpressionContentAssistProcessor;
+import org.eclipse.bpel.ui.details.providers.ModelTreeLabelProvider;
+import org.eclipse.bpel.ui.details.providers.VariableTreeContentProvider;
+import org.eclipse.bpel.ui.dialogs.ElementTreePreviewSelectionDialog;
 import org.eclipse.bpel.ui.editors.xpath.ColorManager;
 import org.eclipse.bpel.ui.editors.xpath.XPathSourceViewerConfiguration;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.jface.text.BadLocationException;
 import org.eclipse.jface.text.Document;
 import org.eclipse.jface.text.IDocument;
+import org.eclipse.jface.text.contentassist.ContentAssistEvent;
+import org.eclipse.jface.text.contentassist.ContentAssistant;
+import org.eclipse.jface.text.contentassist.ICompletionListener;
+import org.eclipse.jface.text.contentassist.ICompletionProposal;
+import org.eclipse.jface.text.contentassist.IContentAssistProcessor;
 import org.eclipse.jface.text.source.ISourceViewer;
 import org.eclipse.jface.text.source.SourceViewer;
 import org.eclipse.jface.text.source.VerticalRuler;
+import org.eclipse.jface.window.Window;
 import org.eclipse.swt.SWT;
+import org.eclipse.swt.custom.ST;
 import org.eclipse.swt.custom.StyledText;
+import org.eclipse.swt.custom.VerifyKeyListener;
+import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.events.SelectionListener;
+import org.eclipse.swt.events.VerifyEvent;
+import org.eclipse.swt.graphics.Color;
+import org.eclipse.swt.graphics.Point;
 import org.eclipse.swt.layout.FillLayout;
 import org.eclipse.swt.layout.GridData;
 import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.swt.widgets.Menu;
+import org.eclipse.swt.widgets.MenuItem;
 
 /**
  * Base class with some shared behavior for details panes that edit a XPath expression.
@@ -34,7 +56,6 @@ import org.eclipse.swt.widgets.Composite;
  */
 public abstract class ExpressionSection extends AbstractStyledTextExpressionSection {
 
-
 	protected String getStyledTextLabelString() {
 		return "Edit the associated XPath Expression.";
 	}
@@ -42,23 +63,168 @@ public abstract class ExpressionSection extends AbstractStyledTextExpressionSect
 	protected StyledText createStyledText(Composite styledTextComposite) {
 		Composite editor = getWidgetFactory().createComposite( styledTextComposite, SWT.BORDER );
 		editor.setLayout( new FillLayout ());
-
+	
 		GridData layoutData = new GridData( GridData.FILL_BOTH );
 		editor.setLayoutData( layoutData );
 		
 		int style = SWT.V_SCROLL | SWT.MULTI | SWT.BORDER;
 		final ISourceViewer viewer = new SourceViewer(editor,
 				new VerticalRuler(0), style);
-		ColorManager cManager = new ColorManager();
-		viewer.configure(new XPathSourceViewerConfiguration(cManager));
-
+		
+		XPathSourceViewerConfiguration sourceViewConfiguration = new XPathSourceViewerConfiguration(new ColorManager());
+		viewer.configure(sourceViewConfiguration);
+		
 		StyledText styledText = viewer.getTextWidget();
 		styledText.setLayoutData(new FillLayout());
 		IDocument document = new Document("");
 		viewer.setDocument(document);
+		
+		setContentAssist(sourceViewConfiguration, viewer);
+		setContextMenu(styledTextComposite, editor, document, styledText);
 		return styledText;
 	}
 
+	private void setContentAssist(XPathSourceViewerConfiguration sourceViewConfiguration, ISourceViewer viewer) {
+		
+		final SourceViewer sourceViewer = (SourceViewer)viewer;
+		sourceViewer.appendVerifyKeyListener( new VerifyKeyListener() {
+				      public void verifyKey(VerifyEvent event) {
+
+				      if (event.stateMask == SWT.CTRL && event.character == ' ') {
+
+				        if (sourceViewer.canDoOperation(SourceViewer.CONTENTASSIST_PROPOSALS)) {
+				        	sourceViewer.doOperation(SourceViewer.CONTENTASSIST_PROPOSALS);
+				        }
+				        //to avoid further processing
+				        event.doit = false;
+				      }
+				   }
+				});
+		
+		ContentAssistant assitant = sourceViewConfiguration.getBpelAssistant();
+		if (assitant != null) {
+			IContentAssistProcessor processor = assitant.getContentAssistProcessor(IDocument.DEFAULT_CONTENT_TYPE);
+			if (processor instanceof ExpressionContentAssistProcessor) {
+				final ExpressionContentAssistProcessor exprProcessor  = (ExpressionContentAssistProcessor)processor;
+				exprProcessor.setPropertySection(this);
+			}
+			
+			assitant.addCompletionListener(new ICompletionListener() {
+				
+				@Override
+				public void selectionChanged(ICompletionProposal proposal, boolean smartToggle) {
+				}
+				
+				@Override
+				public void assistSessionStarted(ContentAssistEvent event) {
+				}
+				
+				@Override
+				public void assistSessionEnded(ContentAssistEvent event) {
+					//Have to rub this asynchronously since we have to wait till text editor updates itself with the proposal
+					Display.getDefault().asyncExec(new Runnable() {
+						
+						@Override
+						public void run() {
+							updateExpressionToModel();
+						}
+					});
+				}
+
+			});
+			
+		}
+	}
+	
+	private void updateExpressionToModel() {
+		super.saveExpressionToModel();
+	}
+
+	private void setContextMenu(Composite styledTextComposite,
+			final Composite editor, final IDocument document,
+			final StyledText styledText) {
+		
+		Menu menu = new Menu(styledTextComposite.getShell(), SWT.POP_UP);
+		addEditMenuItem(styledText, menu, "Cut", ST.CUT);
+		addEditMenuItem(styledText, menu, "Copy", ST.COPY);
+		addEditMenuItem(styledText, menu, "Paste", ST.PASTE);
+		addVariablePickerMenuItem(editor, document, styledText, menu);
+		styledTextComposite.setMenu(menu);
+		styledText.setMenu(menu);
+	}
+
+	private void addVariablePickerMenuItem(final Composite editor,
+			final IDocument document, final StyledText styledText, Menu menu) {
+		MenuItem item = new MenuItem(menu, SWT.PUSH);
+		item.setText("Variable Picker..");
+		item.addSelectionListener(new SelectionListener() {
+
+			@Override
+			public void widgetSelected(SelectionEvent e) {
+				popupVariablePickerDialog(editor, styledText, document);
+			}
+
+			@Override
+			public void widgetDefaultSelected(SelectionEvent e) {
+			}
+		});
+	}
+
+	private void addEditMenuItem(final StyledText styledText, Menu menu, String editAction, final int styledTextAction ) {
+		MenuItem cutItem = new MenuItem(menu, SWT.PUSH);
+		cutItem.setText(editAction);
+		cutItem.addSelectionListener(new SelectionListener() {
+
+			@Override
+			public void widgetSelected(SelectionEvent e) {
+				styledText.invokeAction(styledTextAction);
+			}
+
+			@Override
+			public void widgetDefaultSelected(SelectionEvent e) {
+			}
+		});
+	}
+	
+	private void popupVariablePickerDialog(Composite editor, StyledText styledText, IDocument document){
+		VariableTreeContentProvider variableContentProvider = new VariableTreeContentProvider(true, false, false);
+        
+        ElementTreePreviewSelectionDialog dialog = new ElementTreePreviewSelectionDialog (
+        		editor.getShell(), 
+        		new ModelTreeLabelProvider(), 
+        		variableContentProvider);
+        
+		dialog.setTitle( "Select Variable" );
+		dialog.setAllowMultiple(false);
+		
+		if (this instanceof ExpressionAssignCategory) {
+			ExpressionAssignCategory expAssign = (ExpressionAssignCategory)this;
+			EObject eObject = expAssign.getInput();
+			dialog.setInput( eObject );
+		}
+		
+		if (dialog.open() == Window.OK) {
+			String result = dialog.getPreviewResult();
+			replaceText(styledText, document, result);				
+		}
+	}
+
+	private void replaceText(StyledText styledText, IDocument document,
+			String result) {
+	   Point sel = styledText.getSelectionRange();
+	   int offset = sel.x;
+	   int length = sel.y;
+		
+	   try {
+			   document.replace(offset, length, result);
+			   updateExpressionToModel();
+	   }
+	   catch (BadLocationException ble) {
+			   ble.printStackTrace();
+	   }
+	}
+	
+
 	protected String getExpressionLanguage() {
 		return BPELConstants.XMLNS_XPATH_EXPRESSION_LANGUAGE_2007;
 	}

Back to the top