Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[bpel-dev] adding source view - patch #1

Hello,

 

Please find attached the first patch re source view development.

A source view itself is added, it reacts on the designer area (=BPELEditor) selection changes. I.e. if you select an element in the design view and switch to the source view then you see the corresponding piece of text selected.

I used ideas and code from the XML editor.

 

What is in the patch.

1. BPELMultipageEditorPart (extends org.eclipse.ui.part.MultiPageEditorPart) is taken as the base class for BPEL multipage editor.

This class will hold all the “core” functionality of the editor UI: handling events, etc. Design and text views (BPELEditor and org.eclipse.wst.sse.ui.StructuredTextEditor) will be just views.

I haven’t moved any core functionality from BPELEditor to this class yet.

 

2. org.eclipse.wst.sse.ui is added to the org.eclipse.bpel.ui dependencies. This is needed to make possible import of org.eclipse.wst.sse.ui.StructuredTextEditor.

 

3. Editor class BPELEditor is changed to BPELMultipageEditorPart in the org.eclipse.ui.editors extension point of org.eclipse.bpel.ui.

 

Feel free to express your opinion  J

 

Thanks,

            Vitaly.

 

 

 

### Eclipse Workspace Patch 1.0
#P org.eclipse.bpel.ui
Index: plugin.xml
===================================================================
RCS file: /cvsroot/technology/org.eclipse.bpel/plugins/org.eclipse.bpel.ui/plugin.xml,v
retrieving revision 1.17
diff -u -r1.17 plugin.xml
--- plugin.xml	17 May 2007 00:34:02 -0000	1.17
+++ plugin.xml	21 May 2007 13:56:25 -0000
@@ -11,7 +11,7 @@
    <extension
          point="org.eclipse.ui.editors">
       <editor
-            class="org.eclipse.bpel.ui.BPELEditor"
+            class="org.eclipse.bpel.ui.BPELMultipageEditorPart"
             contributorClass="org.eclipse.bpel.ui.BPELActionBarContributor"
             default="true"
             extensions="bpel"
Index: META-INF/MANIFEST.MF
===================================================================
RCS file: /cvsroot/technology/org.eclipse.bpel/plugins/org.eclipse.bpel.ui/META-INF/MANIFEST.MF,v
retrieving revision 1.9
diff -u -r1.9 MANIFEST.MF
--- META-INF/MANIFEST.MF	13 Apr 2007 19:09:31 -0000	1.9
+++ META-INF/MANIFEST.MF	21 May 2007 13:56:25 -0000
@@ -22,7 +22,8 @@
  org.eclipse.bpel.common.model,
  org.eclipse.bpel.model,
  org.eclipse.wst.xml.core,
- org.eclipse.bpel.wsil.model
+ org.eclipse.bpel.wsil.model,
+ org.eclipse.wst.sse.ui
 Eclipse-LazyStart: true
 Export-Package: org.eclipse.bpel.ui,
  org.eclipse.bpel.ui.actions,
Index: src/org/eclipse/bpel/ui/BPELMultipageEditorPart.java
===================================================================
RCS file: src/org/eclipse/bpel/ui/BPELMultipageEditorPart.java
diff -N src/org/eclipse/bpel/ui/BPELMultipageEditorPart.java
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ src/org/eclipse/bpel/ui/BPELMultipageEditorPart.java	1 Jan 1970 00:00:00 -0000
@@ -0,0 +1,190 @@
+/*******************************************************************************
+ * Copyright (c) 2007 Intel Corporation.
+ * 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:
+ *    Vitaly Tishkov, Intel - Initial API and Implementation
+ *
+ *******************************************************************************/ 
+
+package org.eclipse.bpel.ui;
+
+import org.eclipse.bpel.model.ExtensibleElement;
+import org.eclipse.bpel.ui.uiextensionmodel.StartNode;
+
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.jface.dialogs.ErrorDialog;
+import org.eclipse.jface.text.TextSelection;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.viewers.ISelectionChangedListener;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.jface.viewers.SelectionChangedEvent;
+import org.eclipse.ui.IEditorInput;
+import org.eclipse.ui.IEditorSite;
+import org.eclipse.ui.PartInitException;
+import org.eclipse.ui.part.MultiPageEditorPart;
+import org.eclipse.wst.sse.ui.StructuredTextEditor;
+
+import org.w3c.dom.Element;
+
+public class BPELMultipageEditorPart extends MultiPageEditorPart {
+
+	private StructuredTextEditor fTextEditor = null;
+	private BPELEditor fDesignViewer = null;
+	
+	private static int DESIGN_PAGE_INDEX = 0;
+	private static int SOURCE_PAGE_INDEX = 1;
+	
+	/**
+	 * Adds the source page of the multi-page editor.
+	 */
+	private void addSourcePage() throws PartInitException {
+	    try
+	    {
+	    	addPage(SOURCE_PAGE_INDEX, fTextEditor, getEditorInput());
+	    	//FIXME I18N
+	    	setPageText(SOURCE_PAGE_INDEX, "Source");
+	    	firePropertyChange(PROP_TITLE);
+	    } catch (PartInitException e) {
+	    	ErrorDialog.openError(getSite().getShell(), "Error creating nested text editor", null, e.getStatus()); //$NON-NLS-1$
+	    }
+	}
+
+	/**
+	 * Connects the design viewer with the viewer selection manager. Should be
+	 * done after createSourcePage() is done because we need to get the
+	 * ViewerSelectionManager from the TextEditor. setModel is also done here
+	 * because getModel() needs to reference the TextEditor.
+	 */
+	private void connectDesignPage() {
+		/*
+		 * Connect selection from the Design page to the selection provider
+		 * for the BPELMultiPageEditorPart so that selection changes in the
+		 * Design page will propogate across the workbench
+		 */
+		/*fDesignViewer.getAdaptingSelectionProvider().addSelectionChangedListener(new ISelectionChangedListener() {
+			public void selectionChanged(SelectionChangedEvent event) {
+				((MultiPageSelectionProvider) getSite().getSelectionProvider()).fireSelectionChanged(event);
+			}
+		});*/
+
+		/*
+		 * Connect selection from the Design page to the selection provider of
+		 * the Source page so that selection in the Design page will drive
+		 * selection in the Source page. 
+		 */
+		fDesignViewer.getAdaptingSelectionProvider().addSelectionChangedListener(new ISelectionChangedListener() {
+			public void selectionChanged(SelectionChangedEvent event) {
+				//force selection update if only source page is not active
+				if (getActivePage() != SOURCE_PAGE_INDEX) {
+					try {
+						ISelection sel = fDesignViewer.getSelection();
+						Object selectedNode = ((IStructuredSelection)sel).getFirstElement();
+						Element selectedNodeElement = null;
+						
+						if (selectedNode instanceof StartNode) {
+							selectedNodeElement = ((StartNode)selectedNode).getProcess().getElement();
+						} else if (selectedNode instanceof ExtensibleElement) {
+							selectedNodeElement = ((ExtensibleElement)selectedNode).getElement();
+						} 
+					
+						if (selectedNodeElement != null) {
+							int charStart = ((Number)selectedNodeElement.getUserData("location.charStart")).intValue();
+							//-1 to point to the '<' literal  
+							TextSelection textSelection = new TextSelection(charStart - 1, 0);
+							getTextEditor().getSelectionProvider().setSelection(textSelection);
+						}
+					} catch (Exception e) {
+						e.printStackTrace();
+					}
+				}
+			}
+		});
+	}
+
+	private void createAndAddDesignPage() {
+		fDesignViewer = new BPELEditor();
+
+		try
+	    {
+			addPage(DESIGN_PAGE_INDEX, fDesignViewer, getEditorInput());
+			//FIXME I18N
+			setPageText(DESIGN_PAGE_INDEX, "Design");
+			firePropertyChange(PROP_TITLE);
+	    } catch (PartInitException e) {
+	    	ErrorDialog.openError(getSite().getShell(), "Error creating nested BPEL editor", null, e.getStatus()); //$NON-NLS-1$
+	    }
+	}
+
+	private void createSourcePage() {
+		fTextEditor = new StructuredTextEditor();
+	}
+
+	
+	/**
+	 * Creates the pages of this multi-page editor.
+	 */
+	protected void createPages() {
+		// source page must be created before design page
+			
+		try {
+			createSourcePage();
+			createAndAddDesignPage();
+			addSourcePage();
+			connectDesignPage();
+		} catch (PartInitException e) {
+			//Logger.logException(e);
+			throw new RuntimeException(e);
+		} 
+	}
+
+
+	/**
+	 * @see org.eclipse.ui.IEditorPart#doSave(org.eclipse.core.runtime.IProgressMonitor)
+	 */
+	public void doSave(IProgressMonitor progressMonitor) {
+		fDesignViewer.doSave(progressMonitor);
+		fTextEditor.doSave(progressMonitor);
+	}
+
+	/*
+	 * (non-Javadoc)
+	 * 
+	 * @see org.eclipse.ui.ISaveablePart#doSaveAs()
+	 */
+	public void doSaveAs() {
+		//saveAs is not allowed; do nothing
+	}
+	
+	StructuredTextEditor getTextEditor() {
+		return fTextEditor;
+	}
+	
+	/*
+	 * (non-Javadoc)
+	 * 
+	 * @see org.eclipse.ui.IEditorPart#init(org.eclipse.ui.IEditorSite,
+	 *      org.eclipse.ui.IEditorInput)
+	 */
+	public void init(IEditorSite site, IEditorInput input) throws PartInitException {
+		try {
+			super.init(site, input);
+		} catch (Exception e) {
+			e.printStackTrace();
+		}
+		setPartName(input.getName());
+	}
+	
+	/*
+	 * (non-Javadoc)
+	 * 
+	 * @see org.eclipse.ui.ISaveablePart#isSaveAsAllowed()
+	 */
+	public boolean isSaveAsAllowed() {
+		return false;
+	}
+}
+

Back to the top