bug 391913: reintroduce expression editors
https://bugs.eclipse.org/bugs/show_bug.cgi?id=391913
Change-Id: I46ecdb09f03d33b0f33674295153e3249491d14f
diff --git a/.gitignore b/.gitignore
index 3768928..e2c221f 100644
--- a/.gitignore
+++ b/.gitignore
@@ -18,3 +18,9 @@
bin/
.settings/
*.swp
+
+*~
+*.orig
+target/
+*.java._trace
+*.smap
\ No newline at end of file
diff --git a/plugins/org.eclipse.bpel.examples.extensionPoints.noEmbeddedEditors/plugin.xml b/plugins/org.eclipse.bpel.examples.extensionPoints.noEmbeddedEditors/plugin.xml
index 2aa1bdd..e350016 100644
--- a/plugins/org.eclipse.bpel.examples.extensionPoints.noEmbeddedEditors/plugin.xml
+++ b/plugins/org.eclipse.bpel.examples.extensionPoints.noEmbeddedEditors/plugin.xml
@@ -27,5 +27,12 @@
uri="platform:/plugin/org.eclipse.bpel.examples.extensionPoints/functions/functions.xml">
</registry>
</extension>
+ <extension
+ point="org.eclipse.bpel.ui.assignCategoryAdditions">
+ <assignSection
+ class="org.eclipse.bpel.examples.extensionpoints.assigncategory.SimpleTextAssignCategory"
+ name="simpleText">
+ </assignSection>
+ </extension>
</plugin>
diff --git a/plugins/org.eclipse.bpel.examples.extensionPoints.noEmbeddedEditors/src/org/eclipse/bpel/examples/extensionpoints/assigncategory/SimpleTextAssignCategory.java b/plugins/org.eclipse.bpel.examples.extensionPoints.noEmbeddedEditors/src/org/eclipse/bpel/examples/extensionpoints/assigncategory/SimpleTextAssignCategory.java
new file mode 100644
index 0000000..028de79
--- /dev/null
+++ b/plugins/org.eclipse.bpel.examples.extensionPoints.noEmbeddedEditors/src/org/eclipse/bpel/examples/extensionpoints/assigncategory/SimpleTextAssignCategory.java
@@ -0,0 +1,71 @@
+/**
+ *
+ */
+package org.eclipse.bpel.examples.extensionpoints.assigncategory;
+
+import org.eclipse.bpel.ui.properties.AbstractExpressionAssignCategory;
+import org.eclipse.bpel.ui.properties.IAssignCategory;
+import org.eclipse.jface.text.Document;
+import org.eclipse.jface.text.IDocument;
+import org.eclipse.jface.text.source.ISourceViewer;
+import org.eclipse.jface.text.source.SourceViewer;
+import org.eclipse.jface.text.source.VerticalRuler;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.custom.StyledText;
+import org.eclipse.swt.layout.FillLayout;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.widgets.Composite;
+
+/**
+ * An example of {@link IAssignCategory} which only shows a simple text editor.
+ *
+ * @author Lorenzo Bettini
+ *
+ */
+public class SimpleTextAssignCategory extends AbstractExpressionAssignCategory {
+
+ /* (non-Javadoc)
+ * @see org.eclipse.bpel.ui.properties.AbstractExpressionAssignCategory#getExpressionLanguage()
+ */
+ @Override
+ protected String getExpressionLanguage() {
+ return "simpletext";
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.bpel.ui.properties.AbstractStyledTextExpressionSection#createStyledText(org.eclipse.swt.widgets.Composite)
+ */
+ @Override
+ 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);
+
+ StyledText styledText = viewer.getTextWidget();
+ styledText.setLayoutData(new FillLayout());
+ IDocument document = new Document("");
+ viewer.setDocument(document);
+ return styledText;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.bpel.ui.properties.AbstractStyledTextExpressionSection#getStyledTextLabelString()
+ */
+ @Override
+ protected String getStyledTextLabelString() {
+ return "Edit the associated simple text Expression.";
+ }
+
+ @Override
+ public String getName() {
+ return "Simple Text Editor";
+ }
+
+
+}
diff --git a/plugins/org.eclipse.bpel.ui.noEmbeddedEditors/plugin.xml b/plugins/org.eclipse.bpel.ui.noEmbeddedEditors/plugin.xml
index 6bf303b..ba39c4a 100644
--- a/plugins/org.eclipse.bpel.ui.noEmbeddedEditors/plugin.xml
+++ b/plugins/org.eclipse.bpel.ui.noEmbeddedEditors/plugin.xml
@@ -6,7 +6,7 @@
<extension-point id="actions" name="%ACTIONS_NAME" schema="schemas/actions.exsd"/>
<extension-point id="modelListener" name="Model Listener" schema="schemas/modelListener.exsd"/>
<extension-point id="uiObjectFactories" name="UIObjectFactories" schema="schemas/uiObjectFactories.exsd"/>
-
+ <extension-point id="assignCategoryAdditions" name="Assign Section Additions" schema="schema/assignCategoryAdditions.exsd"/>
<extension
point="org.eclipse.ui.editors">
diff --git a/plugins/org.eclipse.bpel.ui.noEmbeddedEditors/schema/assignCategoryAdditions.exsd b/plugins/org.eclipse.bpel.ui.noEmbeddedEditors/schema/assignCategoryAdditions.exsd
new file mode 100644
index 0000000..20cf523
--- /dev/null
+++ b/plugins/org.eclipse.bpel.ui.noEmbeddedEditors/schema/assignCategoryAdditions.exsd
@@ -0,0 +1,109 @@
+<?xml version='1.0' encoding='UTF-8'?>
+<!-- Schema file written by PDE -->
+<schema targetNamespace="org.eclipse.bpel.common.ui" xmlns="http://www.w3.org/2001/XMLSchema">
+<annotation>
+ <appInfo>
+ <meta.schema plugin="org.eclipse.bpel.common.ui" id="assignCategoryAdditions" name="Assign Section Additions"/>
+ </appInfo>
+ <documentation>
+ [Enter description of this extension point.]
+ </documentation>
+ </annotation>
+
+ <element name="extension">
+ <annotation>
+ <appInfo>
+ <meta.element />
+ </appInfo>
+ </annotation>
+ <complexType>
+ <sequence>
+ <element ref="assignSection"/>
+ </sequence>
+ <attribute name="point" type="string" use="required">
+ <annotation>
+ <documentation>
+
+ </documentation>
+ </annotation>
+ </attribute>
+ <attribute name="id" type="string">
+ <annotation>
+ <documentation>
+
+ </documentation>
+ </annotation>
+ </attribute>
+ <attribute name="name" type="string">
+ <annotation>
+ <documentation>
+
+ </documentation>
+ <appInfo>
+ <meta.attribute translatable="true"/>
+ </appInfo>
+ </annotation>
+ </attribute>
+ </complexType>
+ </element>
+
+ <element name="assignSection">
+ <complexType>
+ <attribute name="name" type="string">
+ <annotation>
+ <documentation>
+
+ </documentation>
+ </annotation>
+ </attribute>
+ <attribute name="class" type="string">
+ <annotation>
+ <documentation>
+
+ </documentation>
+ <appInfo>
+ <meta.attribute kind="java" basedOn=":org.eclipse.bpel.ui.properties.IAssignCategory"/>
+ </appInfo>
+ </annotation>
+ </attribute>
+ </complexType>
+ </element>
+
+ <annotation>
+ <appInfo>
+ <meta.section type="since"/>
+ </appInfo>
+ <documentation>
+ [Enter the first release in which this extension point appears.]
+ </documentation>
+ </annotation>
+
+ <annotation>
+ <appInfo>
+ <meta.section type="examples"/>
+ </appInfo>
+ <documentation>
+ [Enter extension point usage example here.]
+ </documentation>
+ </annotation>
+
+ <annotation>
+ <appInfo>
+ <meta.section type="apiinfo"/>
+ </appInfo>
+ <documentation>
+ [Enter API information here.]
+ </documentation>
+ </annotation>
+
+ <annotation>
+ <appInfo>
+ <meta.section type="implementation"/>
+ </appInfo>
+ <documentation>
+ [Enter information about supplied implementation of this extension point.]
+ </documentation>
+ </annotation>
+
+
+</schema>
diff --git a/plugins/org.eclipse.bpel.ui.noEmbeddedEditors/src/org/eclipse/bpel/ui/extensions/BPELUIRegistry.java b/plugins/org.eclipse.bpel.ui.noEmbeddedEditors/src/org/eclipse/bpel/ui/extensions/BPELUIRegistry.java
index 69be592..6673669 100644
--- a/plugins/org.eclipse.bpel.ui.noEmbeddedEditors/src/org/eclipse/bpel/ui/extensions/BPELUIRegistry.java
+++ b/plugins/org.eclipse.bpel.ui.noEmbeddedEditors/src/org/eclipse/bpel/ui/extensions/BPELUIRegistry.java
@@ -11,12 +11,14 @@
package org.eclipse.bpel.ui.extensions;
import java.util.ArrayList;
+import java.util.LinkedList;
import java.util.List;
import org.eclipse.bpel.ui.BPELUIPlugin;
import org.eclipse.bpel.ui.IHoverHelper;
import org.eclipse.bpel.ui.bpelactions.AbstractBPELAction;
import org.eclipse.bpel.ui.factories.AbstractUIObjectFactory;
+import org.eclipse.bpel.ui.properties.IAssignCategory;
import org.eclipse.bpel.ui.util.BPELUtil;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IConfigurationElement;
@@ -38,6 +40,7 @@
static final String ATT_CLASS = "class"; //$NON-NLS-1$
static final String ATT_LABEL = "label"; //$NON-NLS-1$
static final String EXTPT_ACTIONS = "actions"; //$NON-NLS-1$
+ static final String EXTPT_ASSIGN_CATEGORY_ADDITIONS = "assignCategoryAdditions"; //$NON-NLS-1$
static final String ELEMENT_CATEGORY = "category"; //$NON-NLS-1$
static final String ATT_NAME = "name"; //$NON-NLS-1$
static final String ATT_ID = "id"; //$NON-NLS-1$
@@ -235,6 +238,22 @@
factories.toArray(this.uiObjectFactoryDescriptor);
}
+ public List<IAssignCategory> getAdditionalAssignCategories() {
+ List<IAssignCategory> assignCategories = new LinkedList<IAssignCategory>();
+ IConfigurationElement[] extensions = getConfigurationElements(EXTPT_ASSIGN_CATEGORY_ADDITIONS);
+ for( IConfigurationElement element : extensions ) {
+ //String name = element.getAttribute(ATT_NAME);
+ try {
+ IAssignCategory assignCategory = (IAssignCategory) element.createExecutableExtension(ATT_CLASS);
+ assignCategories.add(assignCategory);
+ System.out.println(assignCategory);
+ } catch (CoreException e1) {
+ e1.printStackTrace();
+ }
+ }
+ return assignCategories;
+ }
+
/**
* Read all the model listeners
*/
diff --git a/plugins/org.eclipse.bpel.ui.noEmbeddedEditors/src/org/eclipse/bpel/ui/properties/AbstractExpressionAssignCategory.java b/plugins/org.eclipse.bpel.ui.noEmbeddedEditors/src/org/eclipse/bpel/ui/properties/AbstractExpressionAssignCategory.java
new file mode 100644
index 0000000..d5c4e28
--- /dev/null
+++ b/plugins/org.eclipse.bpel.ui.noEmbeddedEditors/src/org/eclipse/bpel/ui/properties/AbstractExpressionAssignCategory.java
@@ -0,0 +1,148 @@
+/*******************************************************************************
+ * Copyright (c) 2005, 2012 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.bpel.ui.properties;
+
+import org.eclipse.bpel.model.AbstractAssignBound;
+import org.eclipse.bpel.model.BPELPackage;
+import org.eclipse.bpel.model.Expression;
+import org.eclipse.bpel.ui.IBPELUIConstants;
+import org.eclipse.bpel.ui.adapters.IVirtualCopyRuleSide;
+import org.eclipse.bpel.ui.util.BPELUtil;
+import org.eclipse.emf.common.notify.Notification;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.ecore.EStructuralFeature;
+import org.eclipse.gef.commands.Command;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.ui.views.properties.tabbed.TabbedPropertySheetPage;
+
+
+/**
+ * TODO: when you first set the model object into the details page, it should query the
+ * sections to find out which one thinks it "owns" the model object. If NONE of them
+ * claim to own it, then we will use whatever combo selection is stored in the transient
+ * CopyExtension. The same procedure is followed when refreshing the contents of the
+ * page.
+ *
+ * When you select a *different* category in the combo, we must update the value in the
+ * CopyExtension. We should also replace the existing Copy with an *empty* Copy.
+ *
+ * Categories should become responsible for storing the value into the model themselves.
+ */
+public abstract class AbstractExpressionAssignCategory extends AbstractStyledTextExpressionSection implements IAssignCategory {
+
+ /**
+ * @see org.eclipse.bpel.ui.properties.IAssignCategory#isHidden()
+ */
+ public boolean isHidden() {
+ return this.isHidden;
+ }
+
+ protected BPELPropertySection fOwnerSection;
+
+ protected Composite composite;
+
+ protected Composite fParent;
+
+ protected AbstractExpressionAssignCategory() {
+
+ }
+
+ protected AbstractExpressionAssignCategory( BPELPropertySection ownerSection ) {
+ this.fOwnerSection = ownerSection;
+ }
+
+
+ /*
+ * (non-Javadoc)
+ * @see org.eclipse.bpel.ui.properties.BPELPropertySection
+ * #createControls(org.eclipse.swt.widgets.Composite, org.eclipse.ui.views.properties.tabbed.TabbedPropertySheetPage)
+ */
+ @Override
+ public void createControls(Composite parent, TabbedPropertySheetPage aTabbedPropertySheetPage) {
+ super.createControls(parent, aTabbedPropertySheetPage);
+ this.fParent = parent;
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.eclipse.bpel.ui.properties.IAssignCategory
+ * #getComposite()
+ */
+ public Composite getComposite() {
+ return this.fParent;
+ }
+
+
+ // This is used by changeHelper to determine what shows up in Undo/Redo.
+ // The return value is FlatFormatted with getName() as the only argument.
+ // Subclasses may override.
+ protected String getLabelFlatFormatString() {
+ return IBPELUIConstants.FORMAT_CMD_SELECT;
+ }
+
+ protected boolean isToOrFromAffected(Notification n) {
+ return true;
+ }
+
+ /**
+ * Policy: wrap the command with contexts from the ownerSection (rather
+ * than from the category itself). On undo, the ownerSection will delegate
+ * to the category's methods.
+ */
+ @Override
+ protected Command wrapInShowContextCommand(Command inner) {
+ return super.wrapInShowContextCommand(inner, this.fOwnerSection);
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.eclipse.bpel.ui.properties.IAssignCategory
+ * #isCategoryForModel(org.eclipse.emf.ecore.EObject)
+ */
+ public boolean isCategoryForModel(EObject aModel) {
+ IVirtualCopyRuleSide side = BPELUtil.adapt(aModel,
+ IVirtualCopyRuleSide.class);
+
+ if (side == null)
+ return false;
+ Expression exp = side.getExpression();
+ if (exp == null)
+ return false;
+ return exp.getExpressionLanguage() != null &&
+ exp.getExpressionLanguage().equals(getExpressionLanguage());
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.eclipse.bpel.ui.properties.ExpressionSection
+ * #getStructuralFeature(org.eclipse.emf.ecore.EObject)
+ */
+ @Override
+ protected EStructuralFeature getStructuralFeature(EObject object) {
+ return object instanceof AbstractAssignBound ? BPELPackage.eINSTANCE.getAbstractAssignBound_Expression() : null;
+ }
+
+ /**
+ * This is just a workaround to keep the AssignCategory from changing too much.
+ * @param model the model object
+ */
+ public void setInput (EObject model) {
+ basicSetInput(model);
+ addAllAdapters();
+ }
+
+ /**
+ * @return the expression language
+ */
+ protected abstract String getExpressionLanguage();
+
+}
+
diff --git a/plugins/org.eclipse.bpel.ui.noEmbeddedEditors/src/org/eclipse/bpel/ui/properties/AbstractStyledTextExpressionSection.java b/plugins/org.eclipse.bpel.ui.noEmbeddedEditors/src/org/eclipse/bpel/ui/properties/AbstractStyledTextExpressionSection.java
new file mode 100644
index 0000000..e3a9687
--- /dev/null
+++ b/plugins/org.eclipse.bpel.ui.noEmbeddedEditors/src/org/eclipse/bpel/ui/properties/AbstractStyledTextExpressionSection.java
@@ -0,0 +1,289 @@
+/*******************************************************************************
+ * Copyright (c) 2005, 2012 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.bpel.ui.properties;
+
+import java.util.concurrent.atomic.AtomicBoolean;
+
+import org.eclipse.bpel.model.BPELFactory;
+import org.eclipse.bpel.model.Expression;
+import org.eclipse.bpel.ui.IBPELUIConstants;
+import org.eclipse.bpel.ui.commands.CompoundCommand;
+import org.eclipse.bpel.ui.commands.SetCommand;
+import org.eclipse.bpel.ui.expressions.IEditorConstants;
+import org.eclipse.core.resources.IMarker;
+import org.eclipse.emf.common.notify.Notification;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.ecore.EStructuralFeature;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.custom.StyledText;
+import org.eclipse.swt.events.ModifyEvent;
+import org.eclipse.swt.events.ModifyListener;
+import org.eclipse.swt.graphics.Font;
+import org.eclipse.swt.graphics.FontData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Label;
+
+/**
+ * Base class with some shared behavior for details panes that edit a through a {@link StyledText}.
+ * @author Michal Chmielewski (michal.chmielewski@oracle.com)
+ * @author Vincent Zurczak - EBM WebSourcing (Merge this class with TextSection, simplify it by only using the XPath viewer)
+ * @author Lorenzo Bettini abstract class for all StyledText based expression sections
+ * FIXME: There are probably cases that are not handled correctly. To be fixed on the fly.
+ * FIXME: Undo is not supported correctly.
+ */
+public abstract class AbstractStyledTextExpressionSection extends BPELPropertySection {
+
+ protected Composite fEditorArea ;
+ protected StyledText expressionText;
+
+ protected Font boldFont;
+ protected String title;
+ protected Label titleLabel;
+
+ protected EStructuralFeature fStructuralFeature;
+ protected AtomicBoolean modelUpdate = new AtomicBoolean( false );
+
+
+ /*
+ * (non-Javadoc)
+ * @see org.eclipse.bpel.ui.properties.BPELPropertySection
+ * #addAllAdapters()
+ */
+ @Override
+ protected void addAllAdapters() {
+ super.addAllAdapters();
+ Expression e = getExprFromModel();
+ if( e != null && this.fAdapters.length > 0 )
+ this.fAdapters[0].addToObject(e);
+ }
+
+
+ /**
+ * When this method is called, the section has already been created.
+ *
+ * The widgets are available to be configured, however, the section may not be shown yet.
+ *
+ * The concept here is that we are reflecting the input selected in the UI. So the path that is taken
+ * by this code must not create any re-doable commands, just set the widgets to what they are supposed to
+ * be based on the model.
+ */
+ @Override
+ protected void basicSetInput( EObject newInput ) {
+
+ this.modelUpdate.set( true );
+ super.basicSetInput(newInput);
+
+ /** Figure out based in the input, what EMF structural feature we are setting */
+ this.fStructuralFeature = getStructuralFeature( newInput );
+
+ Expression exp = getExprFromModel();
+ Object o = exp != null ? exp.getBody() : null;
+ String content = o == null ? "" : String.valueOf( o );
+ this.expressionText.setText( content );
+ this.expressionText.setSelection( content.length());
+ this.expressionText.setFocus();
+
+ this.modelUpdate.set( false );
+ }
+
+
+ /**
+ * The expression target is the target object on which we can execute
+ * the SetCommand(target,object,structural-feature).
+ *
+ * In most cases, it is just the input of the section. But in some cases
+ * the input if the section does not match the target, so sub-classes
+ * may override this method.
+ *
+ * @return
+ */
+ protected EObject getExpressionTarget() {
+ return getInput();
+ }
+
+
+ /**
+ * @return
+ */
+ protected String getExpressionType() {
+ return IEditorConstants.ET_ANY ;
+ }
+
+
+ /**
+ * Return the previously computed structural feature of the input object.
+ * @return
+ */
+ protected EStructuralFeature getStructuralFeature() {
+ return this.fStructuralFeature;
+ }
+
+
+ /**
+ * @param object
+ * @return the structural feature to update on the model object
+ */
+ protected abstract EStructuralFeature getStructuralFeature( EObject object );
+
+
+ /**
+ * @return
+ */
+ protected Expression getExprFromModel() {
+
+ Expression result = null;
+ EObject target = getExpressionTarget();
+ if( target != null ) {
+ Object o = target.eGet( getStructuralFeature());
+ if( o instanceof Expression )
+ result = (Expression) o;
+ }
+
+ return result;
+ }
+
+
+ /**
+ * @param expression
+ * @return
+ */
+ protected Expression getExpression4Target( Expression expression ) {
+ return expression;
+ }
+
+
+ /**
+ * Determines whether a notification affects this section.
+ * @param n a notification
+ * @return true if it affects this section, false otherwise
+ */
+ protected boolean isBodyAffected( Notification n ) {
+
+ return n.getOldValue() instanceof Expression
+ || n.getNewValue() instanceof Expression
+ || n.getNotifier() instanceof Expression
+ || n.getFeature() == getStructuralFeature();
+ }
+
+
+ /*
+ * (non-Javadoc)
+ * @see org.eclipse.bpel.ui.properties.BPELPropertySection
+ * #isValidMarker(org.eclipse.core.resources.IMarker)
+ */
+ @Override
+ public final boolean isValidMarker( IMarker marker ) {
+
+ // FIXME: the implementation may not be valid for all the sub-classes
+ boolean result = false;
+ try {
+ String context = (String) marker.getAttribute( "href.context" );
+ result = "name".equals ( context );
+
+ } catch( Exception ex ) {
+ // nothing
+ }
+
+ return result;
+ }
+
+
+ protected String getCommandLabel() {
+ return IBPELUIConstants.CMD_EDIT_EXPRESSION;
+ }
+
+
+ /*
+ * (non-Javadoc)
+ * @see org.eclipse.bpel.ui.properties.BPELPropertySection
+ * #createClient(org.eclipse.swt.widgets.Composite)
+ */
+ @Override
+ protected void createClient( Composite parent ) {
+
+ // The top
+ this.fEditorArea = getWidgetFactory().createComposite( parent );
+ this.fEditorArea.setLayout( new GridLayout());
+ if( this.title != null ) {
+
+ // The font
+ FontData[] fontData = parent.getDisplay().getSystemFont().getFontData();
+ fontData[ 0 ].setStyle( SWT.BOLD );
+ this.boldFont = new Font( parent.getDisplay(), fontData[ 0 ]);
+
+ // The title
+ this.titleLabel = this.fWidgetFactory.createLabel( this.fEditorArea, this.title);
+ this.titleLabel.setFont(this.boldFont);
+ }
+
+ // The expression editor
+ getWidgetFactory().createLabel( this.fEditorArea, getStyledTextLabelString() );
+
+ this.expressionText = createStyledText(this.fEditorArea);
+ this.expressionText.addModifyListener( new ModifyListener() {
+ @Override
+ public void modifyText( ModifyEvent e ) {
+ saveExpressionToModel();
+ }
+ });
+ }
+
+ /**
+ * Saves the expression to the model.
+ */
+ protected void saveExpressionToModel() {
+
+ if( this.modelUpdate.get())
+ return;
+
+ CompoundCommand result = new CompoundCommand();
+ Expression exp = BPELFactory.eINSTANCE.createCondition();
+ exp.setBody( this.expressionText != null ? this.expressionText.getText().trim() : "" );
+ exp.setExpressionLanguage(getExpressionLanguage());
+ result.add( new SetCommand( getExpressionTarget(), getExpression4Target( exp ) , getStructuralFeature()));
+
+ getCommandFramework().execute( result );
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.eclipse.bpel.ui.properties.TextSection
+ * #dispose()
+ */
+ @Override
+ public void dispose() {
+
+ if( this.boldFont != null && ! this.boldFont.isDisposed())
+ this.boldFont.dispose();
+
+ super.dispose();
+ }
+
+ /**
+ * @param styledTextComposite
+ * the Composite for the StyledText
+ * @return the created and configured StyledText
+ */
+ protected abstract StyledText createStyledText(Composite styledTextComposite);
+
+ /**
+ * @return The string for the label to be shown above the StyledText.
+ */
+ protected abstract String getStyledTextLabelString();
+
+
+ /**
+ * @return the expression language
+ */
+ protected abstract String getExpressionLanguage();
+
+}
\ No newline at end of file
diff --git a/plugins/org.eclipse.bpel.ui.noEmbeddedEditors/src/org/eclipse/bpel/ui/properties/AssignImplSection.java b/plugins/org.eclipse.bpel.ui.noEmbeddedEditors/src/org/eclipse/bpel/ui/properties/AssignImplSection.java
index 0175edd..9fee3bc 100644
--- a/plugins/org.eclipse.bpel.ui.noEmbeddedEditors/src/org/eclipse/bpel/ui/properties/AssignImplSection.java
+++ b/plugins/org.eclipse.bpel.ui.noEmbeddedEditors/src/org/eclipse/bpel/ui/properties/AssignImplSection.java
@@ -10,6 +10,10 @@
*******************************************************************************/
package org.eclipse.bpel.ui.properties;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
import org.eclipse.bpel.common.ui.details.ButtonIValue;
import org.eclipse.bpel.common.ui.details.IDetailsAreaConstants;
import org.eclipse.bpel.common.ui.flatui.FlatFormAttachment;
@@ -25,6 +29,7 @@
import org.eclipse.bpel.ui.commands.AddCopyCommand;
import org.eclipse.bpel.ui.commands.RemoveCopyCommand;
import org.eclipse.bpel.ui.commands.SwapCopyCommand;
+import org.eclipse.bpel.ui.extensions.BPELUIRegistry;
import org.eclipse.bpel.ui.util.BPELUtil;
import org.eclipse.bpel.ui.util.MultiObjectAdapter;
import org.eclipse.core.resources.IMarker;
@@ -90,21 +95,36 @@
public AssignImplSection() {
super();
- fToSection.fAllowed = new IAssignCategory[] {
- new VariablePartAssignCategory(this),
- new ExpressionAssignCategory(this),
- new VariablePropertyAssignCategory(this),
- new PartnerRoleAssignCategory(this, false) };
+ List<IAssignCategory> fToAllowed = defaultToCategories();
+ fToAllowed.addAll(BPELUIRegistry.getInstance()
+ .getAdditionalAssignCategories());
+ List<IAssignCategory> fFromAllowed = defaultFromCategories();
+ fFromAllowed.addAll(BPELUIRegistry.getInstance()
+ .getAdditionalAssignCategories());
- fFromSection.fAllowed = new IAssignCategory[] {
- new VariablePartAssignCategory(this),
- new ExpressionAssignCategory(this),
- new LiteralAssignCategory(this),
- new VariablePropertyAssignCategory(this),
- new PartnerRoleAssignCategory(this, true),
- new EndpointReferenceAssignCategory(this),
- new OpaqueAssignCategory(this) };
+ fToSection.fAllowed = fToAllowed.toArray(fToSection.fAllowed);
+ fFromSection.fAllowed = fFromAllowed.toArray(fFromSection.fAllowed);
+ }
+ protected ArrayList<IAssignCategory> defaultToCategories() {
+ return new ArrayList<IAssignCategory>(
+ Arrays.asList(new IAssignCategory[] {
+ new VariablePartAssignCategory(this),
+ new ExpressionAssignCategory(this),
+ new VariablePropertyAssignCategory(this),
+ new PartnerRoleAssignCategory(this, false) }));
+ }
+
+ protected ArrayList<IAssignCategory> defaultFromCategories() {
+ return new ArrayList<IAssignCategory>(
+ Arrays.asList(new IAssignCategory[] {
+ new VariablePartAssignCategory(this),
+ new ExpressionAssignCategory(this),
+ new LiteralAssignCategory(this),
+ new VariablePropertyAssignCategory(this),
+ new PartnerRoleAssignCategory(this, true),
+ new EndpointReferenceAssignCategory(this),
+ new OpaqueAssignCategory(this) }));
}
@Override
diff --git a/plugins/org.eclipse.bpel.ui.noEmbeddedEditors/src/org/eclipse/bpel/ui/properties/ExpressionAssignCategory.java b/plugins/org.eclipse.bpel.ui.noEmbeddedEditors/src/org/eclipse/bpel/ui/properties/ExpressionAssignCategory.java
index ac086d0..b1b3a4d 100644
--- a/plugins/org.eclipse.bpel.ui.noEmbeddedEditors/src/org/eclipse/bpel/ui/properties/ExpressionAssignCategory.java
+++ b/plugins/org.eclipse.bpel.ui.noEmbeddedEditors/src/org/eclipse/bpel/ui/properties/ExpressionAssignCategory.java
@@ -12,6 +12,7 @@
import org.eclipse.bpel.model.AbstractAssignBound;
import org.eclipse.bpel.model.BPELPackage;
+import org.eclipse.bpel.model.Expression;
import org.eclipse.bpel.ui.IBPELUIConstants;
import org.eclipse.bpel.ui.Messages;
import org.eclipse.bpel.ui.adapters.IVirtualCopyRuleSide;
@@ -20,7 +21,6 @@
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.EStructuralFeature;
import org.eclipse.gef.commands.Command;
-import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.ui.views.properties.tabbed.TabbedPropertySheetPage;
@@ -113,9 +113,21 @@
* @see org.eclipse.bpel.ui.properties.IAssignCategory
* #isCategoryForModel(org.eclipse.emf.ecore.EObject)
*/
- public boolean isCategoryForModel ( EObject aModel ) {
- IVirtualCopyRuleSide side = BPELUtil.adapt(aModel, IVirtualCopyRuleSide.class);
- return side != null ? side.getExpression() != null : false;
+ public boolean isCategoryForModel(EObject aModel) {
+ IVirtualCopyRuleSide side = BPELUtil.adapt(aModel,
+ IVirtualCopyRuleSide.class);
+
+ if (side == null)
+ return false;
+ Expression exp = side.getExpression();
+ if (exp == null)
+ return false;
+
+ // we assume XPath as the default language if none is specified?
+ if (exp.getExpressionLanguage() == null)
+ return true;
+
+ return exp.getExpressionLanguage().equals(getExpressionLanguage());
}
/*
@@ -137,21 +149,5 @@
addAllAdapters();
}
- /*
- * (non-Javadoc)
- * @see org.eclipse.bpel.ui.properties.ExpressionSection
- * #createClient(org.eclipse.swt.widgets.Composite)
- */
- @Override
- protected final void createClient(Composite parent) {
- // ugly HACK to make subclasses work
- //FlatFormLayout layout = new FlatFormLayout();
- //layout.marginHeight = layout.marginWidth = 0;
- //parent.setLayout(layout);
- FillLayout fillLayout = new FillLayout();
- fillLayout.marginHeight = fillLayout.marginWidth = 0;
- parent.setLayout(fillLayout);
- super.createClient(parent);
- }
}
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 04894db..cbd5f3e 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
@@ -10,20 +10,9 @@
*******************************************************************************/
package org.eclipse.bpel.ui.properties;
-import java.util.concurrent.atomic.AtomicBoolean;
-
-import org.eclipse.bpel.model.BPELFactory;
-import org.eclipse.bpel.model.Expression;
-import org.eclipse.bpel.ui.IBPELUIConstants;
-import org.eclipse.bpel.ui.commands.CompoundCommand;
-import org.eclipse.bpel.ui.commands.SetCommand;
+import org.eclipse.bpel.model.util.BPELConstants;
import org.eclipse.bpel.ui.editors.xpath.ColorManager;
import org.eclipse.bpel.ui.editors.xpath.XPathSourceViewerConfiguration;
-import org.eclipse.bpel.ui.expressions.IEditorConstants;
-import org.eclipse.core.resources.IMarker;
-import org.eclipse.emf.common.notify.Notification;
-import org.eclipse.emf.ecore.EObject;
-import org.eclipse.emf.ecore.EStructuralFeature;
import org.eclipse.jface.text.Document;
import org.eclipse.jface.text.IDocument;
import org.eclipse.jface.text.source.ISourceViewer;
@@ -31,263 +20,46 @@
import org.eclipse.jface.text.source.VerticalRuler;
import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.StyledText;
-import org.eclipse.swt.events.ModifyEvent;
-import org.eclipse.swt.events.ModifyListener;
-import org.eclipse.swt.graphics.Font;
-import org.eclipse.swt.graphics.FontData;
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.Label;
/**
* Base class with some shared behavior for details panes that edit a XPath expression.
* @author Michal Chmielewski (michal.chmielewski@oracle.com)
* @author Vincent Zurczak - EBM WebSourcing (Merge this class with TextSection, simplify it by only using the XPath viewer)
+ * @author Lorenzo Bettini relies on {@link AbstractStyledTextExpressionSection}
* FIXME: There are probably cases that are not handled correctly. To be fixed on the fly.
* FIXME: Undo is not supported correctly.
*/
-public abstract class ExpressionSection extends BPELPropertySection {
-
- protected Composite fEditorArea ;
- protected StyledText expressionText;
-
- protected Font boldFont;
- protected String title;
- protected Label titleLabel;
-
- protected EStructuralFeature fStructuralFeature;
- protected AtomicBoolean modelUpdate = new AtomicBoolean( false );
+public abstract class ExpressionSection extends AbstractStyledTextExpressionSection {
- /*
- * (non-Javadoc)
- * @see org.eclipse.bpel.ui.properties.BPELPropertySection
- * #addAllAdapters()
- */
- @Override
- protected void addAllAdapters() {
- super.addAllAdapters();
- Expression e = getExprFromModel();
- if( e != null && this.fAdapters.length > 0 )
- this.fAdapters[0].addToObject(e);
+ protected String getStyledTextLabelString() {
+ return "Edit the associated XPath Expression.";
}
-
- /**
- * When this method is called, the section has already been created.
- *
- * The widgets are available to be configured, however, the section may not be shown yet.
- *
- * The concept here is that we are reflecting the input selected in the UI. So the path that is taken
- * by this code must not create any re-doable commands, just set the widgets to what they are supposed to
- * be based on the model.
- */
- @Override
- protected void basicSetInput( EObject newInput ) {
-
- this.modelUpdate.set( true );
- super.basicSetInput(newInput);
-
- /** Figure out based in the input, what EMF structural feature we are setting */
- this.fStructuralFeature = getStructuralFeature( newInput );
-
- Expression exp = getExprFromModel();
- Object o = exp != null ? exp.getBody() : null;
- String content = o == null ? "" : String.valueOf( o );
- this.expressionText.setText( content );
- this.expressionText.setSelection( content.length());
- this.expressionText.setFocus();
-
- this.modelUpdate.set( false );
- }
-
-
- /**
- * The expression target is the target object on which we can execute
- * the SetCommand(target,object,structural-feature).
- *
- * In most cases, it is just the input of the section. But in some cases
- * the input if the section does not match the target, so sub-classes
- * may override this method.
- *
- * @return
- */
- protected EObject getExpressionTarget() {
- return getInput();
- }
-
-
- /**
- * @return
- */
- protected String getExpressionType() {
- return IEditorConstants.ET_ANY ;
- }
-
-
- /**
- * Return the previously computed structural feature of the input object.
- * @return
- */
- protected EStructuralFeature getStructuralFeature() {
- return this.fStructuralFeature;
- }
-
-
- /**
- * @param object
- * @return the structural feature to update on the model object
- */
- protected abstract EStructuralFeature getStructuralFeature( EObject object );
-
-
- /**
- * @return
- */
- protected Expression getExprFromModel() {
-
- Expression result = null;
- EObject target = getExpressionTarget();
- if( target != null ) {
- Object o = target.eGet( getStructuralFeature());
- if( o instanceof Expression )
- result = (Expression) o;
- }
-
- return result;
- }
-
-
- /**
- * @param expression
- * @return
- */
- protected Expression getExpression4Target( Expression expression ) {
- return expression;
- }
-
-
- /**
- * Determines whether a notification affects this section.
- * @param n a notification
- * @return true if it affects this section, false otherwise
- */
- protected boolean isBodyAffected( Notification n ) {
-
- return n.getOldValue() instanceof Expression
- || n.getNewValue() instanceof Expression
- || n.getNotifier() instanceof Expression
- || n.getFeature() == getStructuralFeature();
- }
-
-
- /*
- * (non-Javadoc)
- * @see org.eclipse.bpel.ui.properties.BPELPropertySection
- * #isValidMarker(org.eclipse.core.resources.IMarker)
- */
- @Override
- public final boolean isValidMarker( IMarker marker ) {
-
- // FIXME: the implementation may not be valid for all the sub-classes
- boolean result = false;
- try {
- String context = (String) marker.getAttribute( "href.context" );
- result = "name".equals ( context );
-
- } catch( Exception ex ) {
- // nothing
- }
-
- return result;
- }
-
-
- protected String getCommandLabel() {
- return IBPELUIConstants.CMD_EDIT_EXPRESSION;
- }
-
-
- /*
- * (non-Javadoc)
- * @see org.eclipse.bpel.ui.properties.BPELPropertySection
- * #createClient(org.eclipse.swt.widgets.Composite)
- */
- @Override
- protected void createClient( Composite parent ) {
-
- // The top
- this.fEditorArea = getWidgetFactory().createComposite( parent );
- this.fEditorArea.setLayout( new GridLayout());
- if( this.title != null ) {
-
- // The font
- FontData[] fontData = parent.getDisplay().getSystemFont().getFontData();
- fontData[ 0 ].setStyle( SWT.BOLD );
- this.boldFont = new Font( parent.getDisplay(), fontData[ 0 ]);
-
- // The title
- this.titleLabel = this.fWidgetFactory.createLabel( this.fEditorArea, this.title);
- this.titleLabel.setFont(this.boldFont);
- }
-
- // The expression editor
- getWidgetFactory().createLabel( this.fEditorArea, "Edit the associated XPath Expression." );
- Composite editor = getWidgetFactory().createComposite( this.fEditorArea, SWT.BORDER );
+ 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 ));
+ final ISourceViewer viewer = new SourceViewer(editor,
+ new VerticalRuler(0), style);
+ ColorManager cManager = new ColorManager();
+ viewer.configure(new XPathSourceViewerConfiguration(cManager));
- viewer.getTextWidget().setLayoutData( new GridData( GridData.FILL_BOTH ));
- IDocument document = new Document( "" );
- viewer.setDocument( document );
-
- this.expressionText = viewer.getTextWidget();
- this.expressionText.addModifyListener( new ModifyListener() {
- @Override
- public void modifyText( ModifyEvent e ) {
- saveExpressionToModel();
- }
- });
+ StyledText styledText = viewer.getTextWidget();
+ styledText.setLayoutData(new FillLayout());
+ IDocument document = new Document("");
+ viewer.setDocument(document);
+ return styledText;
}
-
- /**
- * Saves the expression to the model.
- */
- protected void saveExpressionToModel() {
-
- if( this.modelUpdate.get())
- return;
-
- CompoundCommand result = new CompoundCommand();
- Expression exp = BPELFactory.eINSTANCE.createCondition();
- exp.setBody( this.expressionText != null ? this.expressionText.getText().trim() : "" );
- result.add( new SetCommand( getExpressionTarget(), getExpression4Target( exp ) , getStructuralFeature()));
-
- getCommandFramework().execute( result );
- }
-
-
- /*
- * (non-Javadoc)
- * @see org.eclipse.bpel.ui.properties.TextSection
- * #dispose()
- */
- @Override
- public void dispose() {
-
- if( this.boldFont != null && ! this.boldFont.isDisposed())
- this.boldFont.dispose();
-
- super.dispose();
+ protected String getExpressionLanguage() {
+ return BPELConstants.XMLNS_XPATH_EXPRESSION_LANGUAGE_2007;
}
}
\ No newline at end of file