[
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.
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;
}
- References:
- [bpel-dev] BPEL - Expression Editor is not working, How can we fix this
- Re: [bpel-dev] BPEL - Expression Editor is not working, How can we fix this
- Re: [bpel-dev] BPEL - Expression Editor is not working, How can we fix this
- Re: [bpel-dev] BPEL - Expression Editor is not working, How can we fix this
- Re: [bpel-dev] BPEL - Expression Editor is not working, How can we fix this
- Re: [bpel-dev] BPEL - Expression Editor is not working, How can we fix this
- Re: [bpel-dev] BPEL - Expression Editor is not working, How can we fix this
- Re: [bpel-dev] BPEL - Expression Editor is not working, How can we fix this
- Re: [bpel-dev] BPEL - Expression Editor is not working, How can we fix this
- Re: [bpel-dev] BPEL - Expression Editor is not working, How can we fix this