Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorpguilet2017-07-18 15:13:04 +0000
committerPierre Guilet2017-08-01 13:19:57 +0000
commit2b729a632ab4bdbc1f90759314b0a8e9d0b3bb4b (patch)
tree0eb3eeb4887c867d4126a8a16228e2d8889b0b2a
parent41f0c705ba38d48b0214ffb3ae619727b9136623 (diff)
downloadorg.eclipse.sirius-2b729a632ab4bdbc1f90759314b0a8e9d0b3bb4b.tar.gz
org.eclipse.sirius-2b729a632ab4bdbc1f90759314b0a8e9d0b3bb4b.tar.xz
org.eclipse.sirius-2b729a632ab4bdbc1f90759314b0a8e9d0b3bb4b.zip
[518524] Add an extension point to provide custom aird editor pages
A new extension point allows to provide a PageProvider providing custom aird editor pages. Bug: 518524 Change-Id: Ib114c0cf6328540b7cc62e9db03655a42ae6a60f Signed-off-by: pguilet <pierre.guilet@obeo.fr>
-rw-r--r--plugins/org.eclipse.sirius.ui.debug/plugin.xml8
-rw-r--r--plugins/org.eclipse.sirius.ui.debug/src/org/eclipse/sirius/ui/debug/AbstractDebugView.java257
-rw-r--r--plugins/org.eclipse.sirius.ui.debug/src/org/eclipse/sirius/ui/debug/pages/DebugPage.java44
-rw-r--r--plugins/org.eclipse.sirius.ui.editor/plugin.properties4
-rw-r--r--plugins/org.eclipse.sirius.ui.editor/plugin.xml1
-rw-r--r--plugins/org.eclipse.sirius.ui.editor/schema/sessionEditorPageProvider.exsd154
-rw-r--r--plugins/org.eclipse.sirius.ui.editor/src/org/eclipse/sirius/ui/editor/Messages.java6
-rw-r--r--plugins/org.eclipse.sirius.ui.editor/src/org/eclipse/sirius/ui/editor/SessionEditor.java25
-rw-r--r--plugins/org.eclipse.sirius.ui.editor/src/org/eclipse/sirius/ui/editor/SessionEditorPlugin.java8
-rw-r--r--plugins/org.eclipse.sirius.ui.editor/src/org/eclipse/sirius/ui/editor/api/pages/AbstractSessionEditorPage.java14
-rw-r--r--plugins/org.eclipse.sirius.ui.editor/src/org/eclipse/sirius/ui/editor/internal/pages/PluginPageProviderRegistry.java150
11 files changed, 516 insertions, 155 deletions
diff --git a/plugins/org.eclipse.sirius.ui.debug/plugin.xml b/plugins/org.eclipse.sirius.ui.debug/plugin.xml
index 3f63503d24..38b38b9735 100644
--- a/plugins/org.eclipse.sirius.ui.debug/plugin.xml
+++ b/plugins/org.eclipse.sirius.ui.debug/plugin.xml
@@ -66,4 +66,10 @@
id="org.eclipse.sirius.ui.debug.SiriusDebugView">
</view>
</extension>
-</plugin> \ No newline at end of file
+ <extension
+ point="org.eclipse.sirius.ui.editor.sessionEditorPageProvider">
+ <pageProvider
+ class="org.eclipse.sirius.ui.debug.pages.DebugPageProvider">
+ </pageProvider>
+ </extension>
+</plugin>
diff --git a/plugins/org.eclipse.sirius.ui.debug/src/org/eclipse/sirius/ui/debug/AbstractDebugView.java b/plugins/org.eclipse.sirius.ui.debug/src/org/eclipse/sirius/ui/debug/AbstractDebugView.java
index a728195d4a..3588e98a03 100644
--- a/plugins/org.eclipse.sirius.ui.debug/src/org/eclipse/sirius/ui/debug/AbstractDebugView.java
+++ b/plugins/org.eclipse.sirius.ui.debug/src/org/eclipse/sirius/ui/debug/AbstractDebugView.java
@@ -25,8 +25,6 @@ import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.window.Window;
import org.eclipse.sirius.ext.base.Option;
import org.eclipse.sirius.ext.base.Options;
-import org.eclipse.sirius.ui.debug.pages.DebugPageProvider;
-import org.eclipse.sirius.ui.editor.SessionEditorPlugin;
import org.eclipse.sirius.viewpoint.provider.ViewpointItemProviderAdapterFactory;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
@@ -43,141 +41,132 @@ import org.eclipse.ui.IWorkbenchPart;
import org.eclipse.ui.part.ViewPart;
/**
- * A simple view synchronized with the Eclipse selection, used to show arbitrary
- * computed information from the currently selected edit part of a diagram and
- * launch actions on them. This view is targeted to developers to help
- * debugging, it should not be packaged in the final product and should not be
- * available to end users.
+ * A simple view synchronized with the Eclipse selection, used to show arbitrary computed information from the currently
+ * selected edit part of a diagram and launch actions on them. This view is targeted to developers to help debugging, it
+ * should not be packaged in the final product and should not be available to end users.
*
* @author pcdavid
*/
public abstract class AbstractDebugView extends ViewPart implements ISelectionListener {
- /**
- * The text area in which information is placed.
- */
- private Text info;
-
- /**
- * The group of action buttons.
- */
- private Group buttons;
-
- /**
- * The currently selection object.
- */
- protected Object selection;
-
- private DebugPageProvider debugPageProvider;
-
- @Override
- public void createPartControl(Composite parent) {
- debugPageProvider = new DebugPageProvider();
- SessionEditorPlugin.getPlugin().getPageRegistry().addPageProvider(debugPageProvider);
- getSite().getPage().addSelectionListener(this);
- GridLayout layout = new GridLayout(1, false);
- parent.setLayout(layout);
-
- info = new Text(parent, SWT.MULTI | SWT.READ_ONLY | SWT.WRAP | SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL);
- info.setText("Sirius/GMF Debug View");
- info.setLayoutData(new GridData(GridData.FILL_BOTH));
- info.setFont(JFaceResources.getFont("org.eclipse.debug.ui.consoleFont"));
-
- buttons = new Group(parent, SWT.SHADOW_ETCHED_IN);
- buttons.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
- buttons.setLayout(new RowLayout(SWT.HORIZONTAL));
- createActionButtons();
- }
-
- /**
- * Helper method to add an action button to the view.
- */
- protected void addAction(String name, final Runnable body) {
- Button button = new Button(buttons, SWT.PUSH);
- button.setText(name);
- button.addSelectionListener(new SelectionAdapter() {
- @Override
- public void widgetSelected(SelectionEvent e) {
- body.run();
- }
- });
- }
-
- @Override
- public void dispose() {
- SessionEditorPlugin.getPlugin().getPageRegistry().removePageProvider(debugPageProvider);
- getSite().getPage().removeSelectionListener(this);
- super.dispose();
- }
-
- @Override
- public void setFocus() {
- // Do nothing.
- }
-
- /**
- * Update the <code>selection</code> field and fill the info area with the
- * corresponding details.
- */
- @Override
- public void selectionChanged(IWorkbenchPart part, ISelection selection) {
- Option<Object> selected = getSelectedElement(selection);
- if (selected.some()) {
- this.selection = selected.get();
- this.info.setText(getTextFor(this.selection));
- }
- }
-
- /**
- * Get the main object selected from the Eclipse ISelection.
- */
- private Option<Object> getSelectedElement(ISelection selection) {
- if (selection instanceof IStructuredSelection) {
- IStructuredSelection iss = (IStructuredSelection) selection;
- return Options.newSome(iss.getFirstElement());
- }
- return Options.newNone();
- }
-
- /**
- * Opens a dialog box to ask the user for a string. Useful for actions which
- * need some additional data.
- */
- protected String askStringFromUser(String title, String message, String initialValue) {
- InputDialog dlg = new InputDialog(getSite().getShell(), title, message, initialValue, null);
- if (dlg.open() == Window.OK) {
- return dlg.getValue();
- } else {
- return null;
- }
- }
-
- protected AdapterFactory getAdapterFactory() {
- List<AdapterFactory> factories = new ArrayList<AdapterFactory>();
- factories.add(new ViewpointItemProviderAdapterFactory());
- factories.add(new ResourceItemProviderAdapterFactory());
- factories.add(new EcoreItemProviderAdapterFactory());
- factories.add(new ReflectiveItemProviderAdapterFactory());
- return new ComposedAdapterFactory(factories);
- }
-
- /**
- * Sets the text shown in the view's text area.
- *
- * @param text
- * the text to show in the view's text area.
- */
- protected void setText(String text) {
- info.setText(text);
- }
-
- /**
- * Returns the text to show in the main text area for the specified object.
- */
- protected abstract String getTextFor(Object obj);
-
- /**
- * Contribute the action buttons using {@link #addAction(String, Runnable)}.
- */
- protected abstract void createActionButtons();
+ /**
+ * The text area in which information is placed.
+ */
+ private Text info;
+
+ /**
+ * The group of action buttons.
+ */
+ private Group buttons;
+
+ /**
+ * The currently selection object.
+ */
+ protected Object selection;
+
+ @Override
+ public void createPartControl(Composite parent) {
+ getSite().getPage().addSelectionListener(this);
+ GridLayout layout = new GridLayout(1, false);
+ parent.setLayout(layout);
+
+ info = new Text(parent, SWT.MULTI | SWT.READ_ONLY | SWT.WRAP | SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL);
+ info.setText("Sirius/GMF Debug View");
+ info.setLayoutData(new GridData(GridData.FILL_BOTH));
+ info.setFont(JFaceResources.getFont("org.eclipse.debug.ui.consoleFont"));
+
+ buttons = new Group(parent, SWT.SHADOW_ETCHED_IN);
+ buttons.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
+ buttons.setLayout(new RowLayout(SWT.HORIZONTAL));
+ createActionButtons();
+ }
+
+ /**
+ * Helper method to add an action button to the view.
+ */
+ protected void addAction(String name, final Runnable body) {
+ Button button = new Button(buttons, SWT.PUSH);
+ button.setText(name);
+ button.addSelectionListener(new SelectionAdapter() {
+ @Override
+ public void widgetSelected(SelectionEvent e) {
+ body.run();
+ }
+ });
+ }
+
+ @Override
+ public void dispose() {
+ getSite().getPage().removeSelectionListener(this);
+ super.dispose();
+ }
+
+ @Override
+ public void setFocus() {
+ // Do nothing.
+ }
+
+ /**
+ * Update the <code>selection</code> field and fill the info area with the corresponding details.
+ */
+ @Override
+ public void selectionChanged(IWorkbenchPart part, ISelection selection) {
+ Option<Object> selected = getSelectedElement(selection);
+ if (selected.some()) {
+ this.selection = selected.get();
+ this.info.setText(getTextFor(this.selection));
+ }
+ }
+
+ /**
+ * Get the main object selected from the Eclipse ISelection.
+ */
+ private Option<Object> getSelectedElement(ISelection selection) {
+ if (selection instanceof IStructuredSelection) {
+ IStructuredSelection iss = (IStructuredSelection) selection;
+ return Options.newSome(iss.getFirstElement());
+ }
+ return Options.newNone();
+ }
+
+ /**
+ * Opens a dialog box to ask the user for a string. Useful for actions which need some additional data.
+ */
+ protected String askStringFromUser(String title, String message, String initialValue) {
+ InputDialog dlg = new InputDialog(getSite().getShell(), title, message, initialValue, null);
+ if (dlg.open() == Window.OK) {
+ return dlg.getValue();
+ } else {
+ return null;
+ }
+ }
+
+ protected AdapterFactory getAdapterFactory() {
+ List<AdapterFactory> factories = new ArrayList<AdapterFactory>();
+ factories.add(new ViewpointItemProviderAdapterFactory());
+ factories.add(new ResourceItemProviderAdapterFactory());
+ factories.add(new EcoreItemProviderAdapterFactory());
+ factories.add(new ReflectiveItemProviderAdapterFactory());
+ return new ComposedAdapterFactory(factories);
+ }
+
+ /**
+ * Sets the text shown in the view's text area.
+ *
+ * @param text
+ * the text to show in the view's text area.
+ */
+ protected void setText(String text) {
+ info.setText(text);
+ }
+
+ /**
+ * Returns the text to show in the main text area for the specified object.
+ */
+ protected abstract String getTextFor(Object obj);
+
+ /**
+ * Contribute the action buttons using {@link #addAction(String, Runnable)}.
+ */
+ protected abstract void createActionButtons();
}
diff --git a/plugins/org.eclipse.sirius.ui.debug/src/org/eclipse/sirius/ui/debug/pages/DebugPage.java b/plugins/org.eclipse.sirius.ui.debug/src/org/eclipse/sirius/ui/debug/pages/DebugPage.java
index eada1587d0..47508417cf 100644
--- a/plugins/org.eclipse.sirius.ui.debug/src/org/eclipse/sirius/ui/debug/pages/DebugPage.java
+++ b/plugins/org.eclipse.sirius.ui.debug/src/org/eclipse/sirius/ui/debug/pages/DebugPage.java
@@ -10,8 +10,12 @@
*******************************************************************************/
package org.eclipse.sirius.ui.debug.pages;
+import java.util.Collection;
import java.util.Optional;
+import org.eclipse.emf.common.util.TreeIterator;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.emf.transaction.ResourceSetChangeEvent;
import org.eclipse.jface.layout.GridLayoutFactory;
import org.eclipse.sirius.business.api.session.Session;
@@ -24,6 +28,7 @@ import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.ui.forms.IManagedForm;
+import org.eclipse.ui.forms.widgets.FormText;
import org.eclipse.ui.forms.widgets.FormToolkit;
import org.eclipse.ui.forms.widgets.ScrolledForm;
@@ -42,6 +47,10 @@ public class DebugPage extends AbstractSessionEditorPage {
private Session session;
+ private FormText semanticValueText;
+
+ private FormText viewpointNumberText;
+
public DebugPage(SessionEditor editor, String id, String title) {
super(editor, id, title);
this.session = editor.getSession();
@@ -63,6 +72,37 @@ public class DebugPage extends AbstractSessionEditorPage {
Composite subBody = toolkit.createComposite(body);
subBody.setLayout(GridLayoutFactory.swtDefaults().numColumns(2).equalWidth(false).create());
subBody.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
+
+ toolkit.createLabel(subBody, "Viewpoins enabled: ");
+ viewpointNumberText = toolkit.createFormText(subBody, true);
+ setViewpointNumber();
+
+ toolkit.createLabel(subBody, "Semantic elements number: ");
+ semanticValueText = toolkit.createFormText(subBody, true);
+ setSemanticValue();
+ }
+
+ /**
+ * Set the number of viewpoints activated.
+ */
+ private void setViewpointNumber() {
+ viewpointNumberText.setText(String.valueOf(session.getSelectedViewpoints(false).size()), false, false);
+ }
+
+ /**
+ * Set the number of semantic elements loaded in the session.
+ */
+ private void setSemanticValue() {
+ Collection<Resource> semanticResources = session.getSemanticResources();
+ int semanticResourcesNumber = 0;
+ for (Resource resource : semanticResources) {
+ TreeIterator<EObject> allContents = resource.getAllContents();
+ while (allContents.hasNext()) {
+ allContents.next();
+ semanticResourcesNumber++;
+ }
+ }
+ semanticValueText.setText(String.valueOf(semanticResourcesNumber), false, false);
}
@Override
@@ -82,6 +122,10 @@ public class DebugPage extends AbstractSessionEditorPage {
@Override
public Optional<PageUpdateCommand> pageChanged(boolean isVisible) {
+ if (isVisible) {
+ setSemanticValue();
+ setViewpointNumber();
+ }
return Optional.empty();
}
diff --git a/plugins/org.eclipse.sirius.ui.editor/plugin.properties b/plugins/org.eclipse.sirius.ui.editor/plugin.properties
index 456fadea1c..d8c5ca2c0c 100644
--- a/plugins/org.eclipse.sirius.ui.editor/plugin.properties
+++ b/plugins/org.eclipse.sirius.ui.editor/plugin.properties
@@ -11,6 +11,7 @@
pluginName = Sirius Aird Editor
providerName = Eclipse Modeling Project
+sessionEditorPageProviderExtensionPointName=Session Editor Page Provider
UI_SessionEditor_label = Aird Editor
UI_SessionEditor_header_title={0}
UI_SessionEditor_page_loading_error_message=An error occurred while creating pages for the aird editor.
@@ -40,3 +41,6 @@ DefaultSessionEditorPage_closeSession_action_tooltip=Unload models and close all
DefaultSessionEditorPage_selectFilterAction_tooltip=Customize view...
DefaultSessionEditorPage_collapseAllAction_tooltip=Collapse all
SessionEditor_PageCommand_Integrity_Error=Some page update commands from page {0} were ignored because a remove command was executed first and thus no update can be done anymore.
+PluginPageProviderRegistry_classInitialization=The PageProvider class ''{0}'' could not be initialized.
+PluginPageProviderRegistry_badClassType=The class ''{0}'' provided by the extension to extension point ''org.eclipse.sirius.ui.editor.airdEditoPageProvider'' is not an instance of ''org.eclipse.sirius.ui.editor.api.pages.PageProvider''
+SessionEditor_PageCommand_Integrity_Error=Some page update commands from page {0} were ignored because a remove command was executed first and thus no update cannot be done anymore.
diff --git a/plugins/org.eclipse.sirius.ui.editor/plugin.xml b/plugins/org.eclipse.sirius.ui.editor/plugin.xml
index a47128d0eb..aeae98e3c5 100644
--- a/plugins/org.eclipse.sirius.ui.editor/plugin.xml
+++ b/plugins/org.eclipse.sirius.ui.editor/plugin.xml
@@ -12,6 +12,7 @@
-->
<plugin>
+ <extension-point id="sessionEditorPageProvider" name="%sessionEditorPageProviderExtensionPointName" schema="schema/sessionEditorPageProvider.exsd"/>
<extension
point="org.eclipse.ui.editors">
<editor
diff --git a/plugins/org.eclipse.sirius.ui.editor/schema/sessionEditorPageProvider.exsd b/plugins/org.eclipse.sirius.ui.editor/schema/sessionEditorPageProvider.exsd
new file mode 100644
index 0000000000..59f60bceda
--- /dev/null
+++ b/plugins/org.eclipse.sirius.ui.editor/schema/sessionEditorPageProvider.exsd
@@ -0,0 +1,154 @@
+<?xml version='1.0' encoding='UTF-8'?>
+<!-- Schema file written by PDE -->
+<schema targetNamespace="org.eclipse.sirius.ui.editor" xmlns="http://www.w3.org/2001/XMLSchema">
+<annotation>
+ <appInfo>
+ <meta.schema plugin="org.eclipse.sirius.ui.editor" id="sessionEditoPageProvider" name="Session Editor Page Provider"/>
+ </appInfo>
+ <documentation>
+ This plugin is the entry point to provide custom pages to show in the mutli-page aird editor.
+
+The provided pages can specify positioning information. I.e where the page should be positioned regarding the id of another page when created. It can be before, after the page specified or it can even replace a page.
+
+When initialized and visible in editor, a page can still update its position regarding session&apos;s resource set events or page activation status or tell the editor to be removed or to update its tab label.
+
+See Sirius developper documentation to have more details about this extension point.
+ </documentation>
+ </annotation>
+
+ <element name="extension">
+ <annotation>
+ <appInfo>
+ <meta.element />
+ </appInfo>
+ </annotation>
+ <complexType>
+ <sequence minOccurs="1" maxOccurs="unbounded">
+ <element ref="pageProvider"/>
+ </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="pageProvider">
+ <complexType>
+ <attribute name="class" type="string" use="required">
+ <annotation>
+ <documentation>
+ A class providing custom pages to show in the aird editor.
+ </documentation>
+ <appInfo>
+ <meta.attribute kind="java" basedOn="org.eclipse.sirius.ui.editor.api.pages.PageProvider:"/>
+ </appInfo>
+ </annotation>
+ </attribute>
+ </complexType>
+ </element>
+
+ <annotation>
+ <appInfo>
+ <meta.section type="since"/>
+ </appInfo>
+ <documentation>
+ Since 5.1.0
+ </documentation>
+ </annotation>
+
+ <annotation>
+ <appInfo>
+ <meta.section type="examples"/>
+ </appInfo>
+ <documentation>
+ A full example exists in the plugin &lt;code&gt;org.eclipse.sirius.ui.debug&lt;/code&gt;.
+
+The extension is the following:
+&lt;pre&gt;
+ &lt;extension
+ point=&quot;org.eclipse.sirius.ui.editor.sessionEditorPageProvider&quot;&gt;
+ &lt;pageProvider
+ class=&quot;org.eclipse.sirius.ui.debug.pages.DebugPageProvider&quot;&gt;
+ &lt;/pageProvider&gt;
+ &lt;/extension&gt;
+&lt;/pre&gt;
+
+The registered page provider from this extension adds a custom page &lt;code&gt;org.eclipse.sirius.ui.debug.pages.DebugPage&lt;/code&gt; in the aird editor showing various information about the editor&apos;s session.
+
+
+ </documentation>
+ </annotation>
+
+ <annotation>
+ <appInfo>
+ <meta.section type="apiinfo"/>
+ </appInfo>
+ <documentation>
+ &lt;h1&gt;PageProvider&lt;/h1&gt;
+
+The entry point for custom page providing is the class &lt;code&gt;org.eclipse.sirius.ui.editor.api.pages.PageProvider&lt;/code&gt;. You must provide an instanceof this class in your extension for this extension point.
+
+This class contains a method &lt;code&gt;org.eclipse.sirius.ui.editor.api.pages.AbstractSessionEditorPagevider.getPages(SessionEditor)&lt;/code&gt; that defines initial visibility condition and returns new instances of &lt;code&gt;org.eclipse.sirius.ui.editor.api.pages.AbstractSessionEditorPage&lt;/code&gt; if the initial conditions are verified.
+
+The initial conditions can be determined only from the given aird editor instance and its session accessible from the method &lt;code&gt;org.eclipse.sirius.ui.editor.SessionEditor.getSession()&lt;/code&gt; or from singleton components like &lt;code&gt;PlatformUI&lt;/code&gt;
+
+You can use any graphic components in your pages.
+
+You also must tell callers of the method &lt;code&gt;org.eclipse.sirius.ui.editor.api.pages.PageProvider.provides(String)&lt;/code&gt; if the given page id correspond to the id of a page your provider provides. If all the pages your provider handles are not defined in this method, page positionning may fail.
+
+&lt;h1&gt;AbstractSessionEditorPage&lt;/h1&gt;
+
+The pages your page provider provides must extends the class &lt;code&gt;org.eclipse.sirius.ui.editor.api.pages.AbstractSessionEditorPage&lt;/code&gt;. It defines positioning information to use when creating the page with the methods &lt;code&gt;org.eclipse.sirius.ui.editor.api.pages.AbstractSessionEditorPage.getPositioning()&lt;/code&gt; and &lt;code&gt;org.eclipse.sirius.ui.editor.api.pages.AbstractSessionEditorPage.getLocationId()&lt;/code&gt;.
+
+And dynamic positioning with the methods &lt;code&gt;org.eclipse.sirius.ui.editor.api.pages.AbstractSessionEditorPage.pageChanged(boolean)&lt;/code&gt; and &lt;code&gt;org.eclipse.sirius.ui.editor.api.pages.AbstractSessionEditorPage.resourceSetChanged(ResourceSetChangeEvent)&lt;/code&gt;
+
+You also can specify a filter&lt;code&gt;org.eclipse.emf.transaction.NotificationFilter&lt;/code&gt; different from the default one &lt;code&gt;org.eclipse.emf.transaction.NotificationFilter.NOT_TOUCH&lt;/code&gt; or in addition of it. The filter is used to filter event from session&apos;s resource set from which you don&apos;t want to react to. I.e the method &lt;code&gt;resourceSetChanged(ResourceSetChangeEvent)&lt;/code&gt; will not be called for this filtered events.
+
+&lt;h1&gt;Programmatic contribution&lt;/h1&gt;
+
+An alternative to this extension point exists to provide custom pages. You can programmatically add your &lt;code&gt;PageProvider&lt;/code&gt; providing custom pages by using the methods of the registry &lt;code&gt;org.eclipse.sirius.ui.editor.api.pages.PageProviderRegistry&lt;/code&gt; accessible with the following code: &lt;code&gt;SessionEditorPlugin.getPlugin().getPageRegistry()&lt;/code&gt;.
+
+When using this API it is your responsability to handle lifecycle of your page provider. If you don&apos;t want memory issues, you will have to remove your provider from the registry when not needed anymore.
+
+ </documentation>
+ </annotation>
+
+
+ <annotation>
+ <appInfo>
+ <meta.section type="copyright"/>
+ </appInfo>
+ <documentation>
+ Copyright (c) 2017 Obeo
+ 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:
+ Obeo - initial API and implementation
+ </documentation>
+ </annotation>
+
+</schema>
diff --git a/plugins/org.eclipse.sirius.ui.editor/src/org/eclipse/sirius/ui/editor/Messages.java b/plugins/org.eclipse.sirius.ui.editor/src/org/eclipse/sirius/ui/editor/Messages.java
index 974866d73c..672f279fe9 100644
--- a/plugins/org.eclipse.sirius.ui.editor/src/org/eclipse/sirius/ui/editor/Messages.java
+++ b/plugins/org.eclipse.sirius.ui.editor/src/org/eclipse/sirius/ui/editor/Messages.java
@@ -100,6 +100,12 @@ public final class Messages {
@TranslatableMessage
public static String SessionEditor_PageCommand_Integrity_Error;
+ @TranslatableMessage
+ public static String PluginPageProviderRegistry_classInitialization;
+
+ @TranslatableMessage
+ public static String PluginPageProviderRegistry_badClassType;
+
// CHECKSTYLE:ON
private Messages() {
diff --git a/plugins/org.eclipse.sirius.ui.editor/src/org/eclipse/sirius/ui/editor/SessionEditor.java b/plugins/org.eclipse.sirius.ui.editor/src/org/eclipse/sirius/ui/editor/SessionEditor.java
index 85c797fbc6..7e673e6aba 100644
--- a/plugins/org.eclipse.sirius.ui.editor/src/org/eclipse/sirius/ui/editor/SessionEditor.java
+++ b/plugins/org.eclipse.sirius.ui.editor/src/org/eclipse/sirius/ui/editor/SessionEditor.java
@@ -95,6 +95,7 @@ public class SessionEditor extends SharedHeaderFormEditor implements ITabbedProp
private final class SessionResourceSetListener extends ResourceSetListenerImpl {
@Override
public void resourceSetChanged(ResourceSetChangeEvent event) {
+
int pageCount = SessionEditor.this.getPageCount();
List<Runnable> commandsToExecute = new ArrayList<>();
for (int i = 0; i < pageCount; i++) {
@@ -102,15 +103,17 @@ public class SessionEditor extends SharedHeaderFormEditor implements ITabbedProp
if (page instanceof AbstractSessionEditorPage) {
AbstractSessionEditorPage customPage = (AbstractSessionEditorPage) page;
Optional<NotificationFilter> notificationFilter = customPage.getFilterForPageRequesting();
- boolean providePages = event.getNotifications().stream().anyMatch(notification -> notificationFilter.isPresent() ? true : notificationFilter.get().matches(notification));
- if (providePages) {
+ boolean reactToNotification = event.getNotifications().stream().anyMatch(notification -> notificationFilter.isPresent() ? true : notificationFilter.get().matches(notification));
+ if (reactToNotification) {
Optional<PageUpdateCommand> updateCommand = customPage.resourceSetChanged(event);
commandsToExecute.addAll(prepareUpdateCommands(customPage, updateCommand));
}
}
}
- executeCommands(commandsToExecute);
- updatePages(event);
+ PlatformUI.getWorkbench().getDisplay().syncExec(() -> {
+ commandsToExecute.stream().forEach(Runnable::run);
+ updatePages(event);
+ });
}
@Override
@@ -159,18 +162,6 @@ public class SessionEditor extends SharedHeaderFormEditor implements ITabbedProp
}
/**
- * Execute the given command in UI thread.
- *
- * @param commandsToExecute
- * the commands to execute.
- */
- private void executeCommands(List<Runnable> commandsToExecute) {
- PlatformUI.getWorkbench().getDisplay().asyncExec(() -> {
- commandsToExecute.stream().forEach(Runnable::run);
- });
- }
-
- /**
* Remove obsolete page, add new pages and reorder all pages currently
* displayed like the new list.
*
@@ -298,7 +289,7 @@ public class SessionEditor extends SharedHeaderFormEditor implements ITabbedProp
}
}
}
- executeCommands(commandsToExecute);
+ commandsToExecute.stream().forEach(Runnable::run);
}
});
IEditorInput editorInput = this.getEditorInput();
diff --git a/plugins/org.eclipse.sirius.ui.editor/src/org/eclipse/sirius/ui/editor/SessionEditorPlugin.java b/plugins/org.eclipse.sirius.ui.editor/src/org/eclipse/sirius/ui/editor/SessionEditorPlugin.java
index 042534cef1..4e5f850f59 100644
--- a/plugins/org.eclipse.sirius.ui.editor/src/org/eclipse/sirius/ui/editor/SessionEditorPlugin.java
+++ b/plugins/org.eclipse.sirius.ui.editor/src/org/eclipse/sirius/ui/editor/SessionEditorPlugin.java
@@ -14,6 +14,7 @@ import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Path;
+import org.eclipse.core.runtime.Platform;
import org.eclipse.core.runtime.Status;
import org.eclipse.emf.common.EMFPlugin;
import org.eclipse.emf.common.ui.EclipseUIPlugin;
@@ -22,6 +23,7 @@ import org.eclipse.emf.common.util.URI;
import org.eclipse.sirius.business.api.session.Session;
import org.eclipse.sirius.ui.editor.api.pages.PageProviderRegistry;
import org.eclipse.sirius.ui.editor.internal.pages.DefaultPageProvider;
+import org.eclipse.sirius.ui.editor.internal.pages.PluginPageProviderRegistry;
import org.eclipse.sirius.ui.tools.internal.views.modelexplorer.resourcelistener.ISessionFileLoadingListener;
import org.eclipse.sirius.viewpoint.provider.SiriusEditPlugin;
import org.eclipse.ui.PartInitException;
@@ -86,6 +88,8 @@ public class SessionEditorPlugin extends EMFPlugin {
*/
private PageProviderRegistry pageRegistry;
+ private PluginPageProviderRegistry pluginPageProviderRegistry;
+
/**
* Creates an instance.
*/
@@ -126,13 +130,17 @@ public class SessionEditorPlugin extends EMFPlugin {
SiriusEditPlugin.getPlugin().addSessionFileLoadingListener(modelingProjectExpansionListener);
pageRegistry = new PageProviderRegistry();
pageRegistry.addPageProvider(new DefaultPageProvider());
+ pluginPageProviderRegistry = new PluginPageProviderRegistry(pageRegistry);
+ Platform.getExtensionRegistry().addListener(pluginPageProviderRegistry, PluginPageProviderRegistry.PAGE_PROVIDER_EXTENSION_POINT_ID);
}
@Override
public void stop(BundleContext context) throws Exception {
SiriusEditPlugin.getPlugin().removeSessionFileLoadingListener(modelingProjectExpansionListener);
+ Platform.getExtensionRegistry().removeListener(pluginPageProviderRegistry);
modelingProjectExpansionListener = null;
pageRegistry = null;
+ pluginPageProviderRegistry = null;
super.stop(context);
}
diff --git a/plugins/org.eclipse.sirius.ui.editor/src/org/eclipse/sirius/ui/editor/api/pages/AbstractSessionEditorPage.java b/plugins/org.eclipse.sirius.ui.editor/src/org/eclipse/sirius/ui/editor/api/pages/AbstractSessionEditorPage.java
index e7876e4457..7ea0d9d0b6 100644
--- a/plugins/org.eclipse.sirius.ui.editor/src/org/eclipse/sirius/ui/editor/api/pages/AbstractSessionEditorPage.java
+++ b/plugins/org.eclipse.sirius.ui.editor/src/org/eclipse/sirius/ui/editor/api/pages/AbstractSessionEditorPage.java
@@ -18,6 +18,7 @@ import org.eclipse.emf.transaction.ResourceSetChangeEvent;
import org.eclipse.sirius.ui.editor.SessionEditor;
import org.eclipse.sirius.ui.editor.api.pages.PageProviderRegistry.PositioningKind;
import org.eclipse.sirius.ui.editor.api.pages.PageUpdateCommandBuilder.PageUpdateCommand;
+import org.eclipse.ui.forms.IManagedForm;
import org.eclipse.ui.forms.editor.FormEditor;
import org.eclipse.ui.forms.editor.FormPage;
@@ -83,6 +84,10 @@ public abstract class AbstractSessionEditorPage extends FormPage {
* {@link PageUpdateCommand} built with {@link PageUpdateCommandBuilder} to
* do so.
*
+ * WARNING: Your page may not be initialized with
+ * {@link FormPage#createFormContent(IManagedForm)} when this method is
+ * called.
+ *
* @param resourceSetChangeEvent
* the event that occurred.
* @return an {@link PageUpdateCommand} the editor should execute.
@@ -95,12 +100,15 @@ public abstract class AbstractSessionEditorPage extends FormPage {
* a {@link PageUpdateCommand} built with {@link PageUpdateCommandBuilder}
* if a page update must be done from session editor owning this page.
*
- * The method is call with the parameter isVisible to true when the page tab
- * is selected.
+ * The method is called with the parameter isVisible to true when the page
+ * tab is selected.
*
- * The method is call with the parameter isVisible to false when any page
+ * The method is called with the parameter isVisible to false when any page
* tab except the one of this page is selected.
*
+ * WARNING: Your page may not be initialized with
+ * {@link FormPage#createFormContent(IManagedForm)} when this method is
+ * called.
*
* @param isVisible
* true if the page has just been made visible. I.e page tab has
diff --git a/plugins/org.eclipse.sirius.ui.editor/src/org/eclipse/sirius/ui/editor/internal/pages/PluginPageProviderRegistry.java b/plugins/org.eclipse.sirius.ui.editor/src/org/eclipse/sirius/ui/editor/internal/pages/PluginPageProviderRegistry.java
new file mode 100644
index 0000000000..27f06b2130
--- /dev/null
+++ b/plugins/org.eclipse.sirius.ui.editor/src/org/eclipse/sirius/ui/editor/internal/pages/PluginPageProviderRegistry.java
@@ -0,0 +1,150 @@
+/*******************************************************************************
+ * Copyright (c) 2017 Obeo
+ * 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:
+ * Obeo - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.sirius.ui.editor.internal.pages;
+
+import java.text.MessageFormat;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IConfigurationElement;
+import org.eclipse.core.runtime.IExtension;
+import org.eclipse.core.runtime.IExtensionPoint;
+import org.eclipse.core.runtime.IExtensionRegistry;
+import org.eclipse.core.runtime.IRegistryEventListener;
+import org.eclipse.core.runtime.Platform;
+import org.eclipse.sirius.ui.editor.Messages;
+import org.eclipse.sirius.ui.editor.SessionEditorPlugin;
+import org.eclipse.sirius.ui.editor.api.pages.PageProvider;
+import org.eclipse.sirius.ui.editor.api.pages.PageProviderRegistry;
+
+/**
+ * This registry dynamically update providers in the given
+ * {@link PageProviderRegistry} when plugins providing some are
+ * activated/deactivated.
+ *
+ * @author <a href="mailto:pierre.guilet@obeo.fr">Pierre Guilet</a>
+ *
+ */
+public class PluginPageProviderRegistry implements IRegistryEventListener {
+ /**
+ * Aird editor page provider extension point's id.
+ */
+ public static final String PAGE_PROVIDER_EXTENSION_POINT_ID = "org.eclipse.sirius.ui.editor.sessionEditorPageProvider"; //$NON-NLS-1$
+
+ /**
+ * Page provider element's name.
+ */
+ private static final String PAGE_PROVIDER_ELEMENT_NAME = "pageProvider"; //$NON-NLS-1$
+
+ /**
+ * Page provider's class attribute's name.
+ */
+ private static final String PAGE_PROVIDER_CLASS_ATTRIBUTE_NAME = "class"; //$NON-NLS-1$
+
+ /**
+ * The registry containing all {@link PageProvider} registered.
+ */
+ private PageProviderRegistry pageRegistry;
+
+ /**
+ * A map of {@link IExtension} currently provided by plugins to the
+ * {@link PageProvider} they provide.
+ */
+ private Map<IExtension, List<PageProvider>> extensionToPageProvider;
+
+ /**
+ * Initialize this registry with a {@link PageProviderRegistry}.
+ *
+ * @param thePageRegistry
+ * the page registry providing pages from registered
+ * {@link PageProvider}.
+ */
+ public PluginPageProviderRegistry(PageProviderRegistry thePageRegistry) {
+ this.pageRegistry = thePageRegistry;
+ extensionToPageProvider = new HashMap<>();
+ final IExtensionRegistry registry = Platform.getExtensionRegistry();
+
+ for (IExtension extension : registry.getExtensionPoint(PAGE_PROVIDER_EXTENSION_POINT_ID).getExtensions()) {
+ parseExtension(extension);
+ }
+ }
+
+ @Override
+ public void added(IExtension[] extensions) {
+ for (IExtension extension : extensions) {
+ parseExtension(extension);
+ }
+ }
+
+ /**
+ * Parse extension. If the extension corresponds to the extension point
+ * identified by
+ * {@link PluginPageProviderRegistry#PAGE_PROVIDER_EXTENSION_POINT_ID}, then
+ * all {@link PageProvider} it provides are registered to the
+ * {@link PageProviderRegistry} instance.
+ *
+ * @param extension
+ * the extension to parse.
+ */
+ private void parseExtension(IExtension extension) {
+ List<PageProvider> pageProviders = extensionToPageProvider.get(extension);
+ if (pageProviders == null) {
+ pageProviders = new ArrayList<>();
+ extensionToPageProvider.put(extension, pageProviders);
+ }
+ IConfigurationElement[] configurationElements = extension.getConfigurationElements();
+ for (IConfigurationElement configurationElement : configurationElements) {
+ if (PAGE_PROVIDER_ELEMENT_NAME.equals(configurationElement.getName())) {
+ try {
+ Object newInstance = configurationElement.createExecutableExtension(PAGE_PROVIDER_CLASS_ATTRIBUTE_NAME);
+ if (PageProvider.class.isAssignableFrom(newInstance.getClass())) {
+ PageProvider pageProvider = (PageProvider) newInstance;
+ pageProviders.add(pageProvider);
+ pageRegistry.addPageProvider(pageProvider);
+ } else {
+ SessionEditorPlugin.getPlugin().error(MessageFormat.format(Messages.PluginPageProviderRegistry_badClassType, newInstance.getClass().getName()), null);
+ }
+ } catch (CoreException e) {
+ SessionEditorPlugin.getPlugin().error(MessageFormat.format(Messages.PluginPageProviderRegistry_classInitialization, configurationElement.getName()), e);
+ }
+ }
+ }
+ }
+
+ @Override
+ public void removed(IExtension[] extensions) {
+ for (IExtension extension : extensions) {
+ List<PageProvider> pageProviders = extensionToPageProvider.get(extensions);
+
+ if (pageProviders != null) {
+ for (PageProvider pageProvider : pageProviders) {
+ pageRegistry.removePageProvider(pageProvider);
+ }
+ }
+ extensionToPageProvider.put(extension, null);
+ }
+
+ }
+
+ @Override
+ public void added(IExtensionPoint[] extensionPoints) {
+
+ }
+
+ @Override
+ public void removed(IExtensionPoint[] extensionPoints) {
+
+ }
+
+}

Back to the top