Skip to content

Commit

Permalink
Merge pull request #68 from tshoang/master
Browse files Browse the repository at this point in the history
Issue #67: Support Symbol Table for CamilleX Editors
  • Loading branch information
cfsnook committed Feb 23, 2021
2 parents 63a5d38 + 01366de commit 0c8cfe7
Show file tree
Hide file tree
Showing 15 changed files with 212 additions and 13 deletions.
25 changes: 25 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,31 @@ This feature provides a text editor (CamilleX) for Event-B constructs (e.g., XMa

Release history:
---------------
### 2.1.0 Usability Update ###
#### Updated Plug-ins/Features ####
- XContext (2.1.0): Attach the markers to the XContext's name if no child element found (see Issue #65).
- XContext UI (2.1.0): Added handler to insert Event-B symbols into XContext Editor (see Issue #67).
- XMachine (2.1.0): Attach the markers to the XMachine's name if no child element found (see Issue #65).
- XMachine UI (2.1.0): Added handler to insert Event-B symbols into XMachine Editor (see Issue #67).
- CamilleX UI (1.1.0):
+ Added a context menu item to do the batch generation of CamilleX source files (see Issue #63).
+ Added common implementation for a handler to insert Event-B Symbols to a text editor (see Issue #67).
#### Fixed Issues ####
- Issue #63: Batch generation for a collection of CamilleX source files.
- Issue #65: Markers attach to an XMachine or an XContext.
- Issue #67: SymbolTable does not work with CamilleX editors
### 2.0.2 Maintenance release ###
- Fixed the Update Site name.
- Removed the included features: Inclusion, Records, Containment
#### Updated Plug-ins ####
- XContext (2.0.2):
+ Added extra dependency on the Record Edit Plug-in.
- XMachine (2.0.2):
+ Added extra dependency on the Inclusion Edit Plug-in.
+ Added extra dependency on the Record Edit Plug-in.
+ Added extra dependency on the Containment Edit Plug-in.
- XMachine UI (2.0.1):
+ Update dependency range for org.eventb.core.emf.
### 2.0.1 Maintenance release ###
#### Updated Plugins/Features ####
- Branding (0.0.5): Update copyright information on branding.
Expand Down
14 changes: 11 additions & 3 deletions ac.soton.xeventb.feature/feature.properties
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,21 @@ Release history:\n\
#### Updated Plug-ins/Features ####\n\
- XContext (2.1.0): Attach the markers to the XContext's name if no child \
element found (see Issue #65).\n\
- XContext UI (2.1.0): Added handler to insert Event-B symbols into XContext \
Editor (see Issue #67).\n\
- XMachine (2.1.0): Attach the markers to the XMachine's name if no child \
element found (see Issue #65).\n\
- CamilleX UI (1.1.0): Added a context menu item to do the batch generation of \
CamilleX source files (see Issue #63).\n\
- XMachine UI (2.1.0): Added handler to insert Event-B symbols into XMachine \
Editor (see Issue #67).\n\
- CamilleX UI (1.1.0): \n\
+ Added a context menu item to do the batch generation of CamilleX source \
files (see Issue #63).\n\
+ Added common implementation for a handler to insert Event-B Symbols to a \
text editor (see Issue #67).\n\
#### Fixed Issues ####\n\
- Issue #63: Batch generation for a collection of CamilleX source files.\n\
- Issue #65: Markers attach to an XMachine or an XContext.\n\
- Issue #67: SymbolTable does not work with CamilleX editors\n\
### 2.0.2 Maintenance release ###\n\
- Fixed the Update Site name.\n\
- Removed the included features: Inclusion, Records, Containment\n\
Expand All @@ -55,7 +63,7 @@ CamilleX source files (see Issue #63).\n\
+ Added extra dependency on the Record Edit Plug-in.\n\
+ Added extra dependency on the Containment Edit Plug-in.\n\
- XMachine UI (2.0.1):\n\
- Update dependency range for org.eventb.core.emf.\n\
+ Update dependency range for org.eventb.core.emf.\n\
### 2.0.1 Maintenance release ###\n\
#### Updated Plug-ins ####\n\
- Branding (0.0.5): Update copyright information on branding.\n\
Expand Down
2 changes: 2 additions & 0 deletions ac.soton.xeventb.sdk/feature.properties
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,9 @@ Release history:\n\
#### Updated Plug-ins/Features ####\n\
- CamilleX Feature (2.1.0)\n\
- XContext Source (2.1.0): Generated\n\
- XContext UI Source (2.1.0): Generated\n\
- XMachine Source (2.1.0): Generated\n\
- XMachine UI Source (2.1.0): Generated\n\
- CamilleX UI Source (1.1.0): Generated \n\
### 2.0.2 Maintenance release ###\n\
- Fixed Update Site name.\n\
Expand Down
3 changes: 2 additions & 1 deletion ac.soton.xeventb.ui/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,6 @@ Import-Package: org.eclipse.emf.common.util,
org.eclipse.emf.ecore.util
Bundle-ActivationPolicy: lazy
Bundle-Activator: ac.soton.xeventb.ui.XEventBUIPlugin
Export-Package: ac.soton.xeventb.ui
Export-Package: ac.soton.xeventb.ui,
ac.soton.xeventb.ui.handlers
Automatic-Module-Name: ac.soton.xeventb.ui
4 changes: 2 additions & 2 deletions ac.soton.xeventb.ui/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
<extension
point="org.eclipse.ui.handlers">
<handler
class="ac.soton.xeventb.internal.ui.XTextConvertHandler"
class="ac.soton.xeventb.internal.ui.handlers.XTextConvertHandler"
commandId="ac.soton.eventb.xtext.ui.XTextConvert">
</handler>
</extension>
Expand Down Expand Up @@ -111,7 +111,7 @@
<extension
point="org.eclipse.ui.handlers">
<handler
class="ac.soton.xeventb.internal.ui.RegenerateHandler"
class="ac.soton.xeventb.internal.ui.handlers.RegenerateHandler"
commandId="ac.soton.eventb.xtext.ui.Regenerate">
</handler>
</extension>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
* Contributors:
* University of Southampton - initial API and implementation
*******************************************************************************/
package ac.soton.xeventb.internal.ui
package ac.soton.xeventb.internal.ui.handlers

import ac.soton.eventb.emf.inclusion.MachineInclusion
import ac.soton.xeventb.xcontext.generator.XContextGenerator
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
* Contributors:
* University of Southampton - initial API and implementation
*******************************************************************************/
package ac.soton.xeventb.internal.ui
package ac.soton.xeventb.internal.ui.handlers

import org.eclipse.core.commands.AbstractHandler
import org.eclipse.core.commands.ExecutionEvent
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
/*******************************************************************************
* Copyright (c) 2021 University of Southampton.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
* which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* University of Southampton - initial API and implementation
*******************************************************************************/
package ac.soton.xeventb.ui.handlers

import org.eclipse.core.commands.AbstractHandler
import org.eclipse.core.commands.ExecutionEvent
import org.eclipse.core.commands.ExecutionException
import org.eclipse.jface.text.ITextSelection
import org.eclipse.ui.handlers.HandlerUtil
import org.eclipse.ui.texteditor.AbstractDecoratedTextEditor
import org.eclipse.jface.text.TextSelection

/**
* An implementation of a handler for inserting Event-B Symbol into an editor.
* This can be used for CamilleX editors.
*
* @author htson
* @version 0.1
* @since 1.1.0
*/
class InsertSymbolHandler extends AbstractHandler {

override Object execute(ExecutionEvent event) throws ExecutionException {
// Get the inserted text from the event.
val String insertText = event.getParameter("org.eventb.ui.edit.insert.text")
if (insertText === null) {
return "Unable to retrieve the text to insert"
}

// Get the active editor
val editor = HandlerUtil.getActiveEditor(event)
if (editor instanceof AbstractDecoratedTextEditor) {
val dp = editor.getDocumentProvider()
val doc = dp.getDocument(editor.getEditorInput())
// Get the current text selection
val selectionProvider = editor.getSite().getSelectionProvider()
val textSelection = selectionProvider.getSelection()
if (textSelection instanceof ITextSelection) {
// Replace the current text selection with the inserted text
val offset = textSelection.offset
val length = textSelection.length
doc.replace(offset, length, insertText)

// Set the current selection to after the inserted text
val selection = new TextSelection(offset + insertText.length, 0)
selectionProvider.selection = selection
return null
} else {
return "Current selection is not text selection"
}
} else {
return "Active editor is not a text editor"
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
* Contributors:
* University of Southampton - initial API and implementation
*/
package ac.soton.xeventb.internal.ui;
package ac.soton.xeventb.internal.ui.handlers;

import ac.soton.eventb.emf.inclusion.MachineInclusion;
import ac.soton.xeventb.xcontext.generator.XContextGenerator;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
* Contributors:
* University of Southampton - initial API and implementation
*/
package ac.soton.xeventb.internal.ui;
package ac.soton.xeventb.internal.ui.handlers;

import ch.ethz.eventb.utils.EventBUtils;
import org.eclipse.core.commands.AbstractHandler;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
/**
* Copyright (c) 2021 University of Southampton.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
* which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* University of Southampton - initial API and implementation
*/
package ac.soton.xeventb.ui.handlers;

import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
import org.eclipse.jface.text.IDocument;
import org.eclipse.jface.text.ITextSelection;
import org.eclipse.jface.text.TextSelection;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.ISelectionProvider;
import org.eclipse.ui.IEditorPart;
import org.eclipse.ui.handlers.HandlerUtil;
import org.eclipse.ui.texteditor.AbstractDecoratedTextEditor;
import org.eclipse.ui.texteditor.IDocumentProvider;
import org.eclipse.xtext.xbase.lib.Exceptions;

/**
* An implementation of a handler for inserting Event-B Symbol into an editor.
* This can be used for CamilleX editors.
*
* @author htson
* @version 0.1
* @since 1.1.0
*/
@SuppressWarnings("all")
public class InsertSymbolHandler extends AbstractHandler {
@Override
public Object execute(final ExecutionEvent event) throws ExecutionException {
try {
final String insertText = event.getParameter("org.eventb.ui.edit.insert.text");
if ((insertText == null)) {
return "Unable to retrieve the text to insert";
}
final IEditorPart editor = HandlerUtil.getActiveEditor(event);
if ((editor instanceof AbstractDecoratedTextEditor)) {
final IDocumentProvider dp = ((AbstractDecoratedTextEditor)editor).getDocumentProvider();
final IDocument doc = dp.getDocument(((AbstractDecoratedTextEditor)editor).getEditorInput());
final ISelectionProvider selectionProvider = ((AbstractDecoratedTextEditor)editor).getSite().getSelectionProvider();
final ISelection textSelection = selectionProvider.getSelection();
if ((textSelection instanceof ITextSelection)) {
final int offset = ((ITextSelection)textSelection).getOffset();
final int length = ((ITextSelection)textSelection).getLength();
doc.replace(offset, length, insertText);
int _length = insertText.length();
int _plus = (offset + _length);
final TextSelection selection = new TextSelection(_plus, 0);
selectionProvider.setSelection(selection);
return null;
} else {
return "Current selection is not text selection";
}
} else {
return "Active editor is not a text editor";
}
} catch (Throwable _e) {
throw Exceptions.sneakyThrow(_e);
}
}
}
2 changes: 1 addition & 1 deletion ac.soton.xeventb.xcontext.ui/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: %Bundle-Name
Bundle-Vendor: %Bundle-Vendor
Bundle-Version: 2.0.0.release
Bundle-Version: 2.1.0.qualifier
Bundle-SymbolicName: ac.soton.xeventb.xcontext.ui; singleton:=true
Bundle-ActivationPolicy: lazy
Require-Bundle: ac.soton.xeventb.xcontext;bundle-version="[2.0.0,3.0.0)",
Expand Down
12 changes: 12 additions & 0 deletions ac.soton.xeventb.xcontext.ui/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,18 @@
</and>
</activeWhen>
</handler>
<handler
class="ac.soton.xeventb.ui.handlers.InsertSymbolHandler"
commandId="org.eventb.ui.edit.insert">
<activeWhen>
<with
variable="activeEditorId">
<equals
value="ac.soton.xeventb.xcontext.XContext">
</equals>
</with>
</activeWhen>
</handler>
</extension>
<extension point="org.eclipse.core.expressions.definitions">
<definition id="ac.soton.xeventb.xcontext.XContext.Editor.opened">
Expand Down
4 changes: 2 additions & 2 deletions ac.soton.xeventb.xmachine.ui/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: %Bundle-Name
Bundle-Vendor: %Bundle-Vendor
Bundle-Version: 2.0.1.release
Bundle-Version: 2.1.0.qualifier
Bundle-SymbolicName: ac.soton.xeventb.xmachine.ui; singleton:=true
Bundle-ActivationPolicy: lazy
Require-Bundle: ac.soton.xeventb.xmachine;bundle-version="[2.0.0,3.0.0)",
Expand All @@ -22,7 +22,7 @@ Require-Bundle: ac.soton.xeventb.xmachine;bundle-version="[2.0.0,3.0.0)",
org.eclipse.ui.navigator;bundle-version="[3.7.0,4.0.0)",
org.eventb.core;bundle-version="[3.3.1,4.0.0)",
ch.ethz.eventb.utils;bundle-version="[0.2.4,1.0.0)",
ac.soton.xeventb.ui;bundle-version="[1.0.0,2.0.0)",
ac.soton.xeventb.ui;bundle-version="[1.1.0,2.0.0)",
org.rodinp.core;bundle-version="[1.7.1,2.0.0)",
org.eventb.emf.core;bundle-version="[5.0.0,6.0.0)"
Import-Package: org.apache.log4j
Expand Down
12 changes: 12 additions & 0 deletions ac.soton.xeventb.xmachine.ui/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,18 @@
</and>
</activeWhen>
</handler>
<handler
class="ac.soton.xeventb.ui.handlers.InsertSymbolHandler"
commandId="org.eventb.ui.edit.insert">
<activeWhen>
<with
variable="activeEditorId">
<equals
value="ac.soton.xeventb.xmachine.XMachine">
</equals>
</with>
</activeWhen>
</handler>
</extension>
<extension point="org.eclipse.core.expressions.definitions">
<definition id="ac.soton.xeventb.xmachine.XMachine.Editor.opened">
Expand Down

0 comments on commit 0c8cfe7

Please sign in to comment.