Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorcletavernie2011-10-25 12:12:23 +0000
committercletavernie2011-10-25 12:12:23 +0000
commit0461ccd2972651807ebb691be5734f2509160da4 (patch)
treefdf38867337e48bd010ec5e15208e9fa9e3bc2da /plugins/views/modelexplorer
parent3731c06a8769e8c5a67b5c7015c05c98f51a549e (diff)
downloadorg.eclipse.papyrus-0461ccd2972651807ebb691be5734f2509160da4.tar.gz
org.eclipse.papyrus-0461ccd2972651807ebb691be5734f2509160da4.tar.xz
org.eclipse.papyrus-0461ccd2972651807ebb691be5734f2509160da4.zip
359057: [Architecture - SVN - Build] The Papyrus architecture should be refactored
https://bugs.eclipse.org/bugs/show_bug.cgi?id=359057
Diffstat (limited to 'plugins/views/modelexplorer')
-rw-r--r--plugins/views/modelexplorer/org.eclipse.papyrus.modelexplorer/.classpath7
-rw-r--r--plugins/views/modelexplorer/org.eclipse.papyrus.modelexplorer/.project28
-rw-r--r--plugins/views/modelexplorer/org.eclipse.papyrus.modelexplorer/.settings/org.eclipse.core.resources.prefs3
-rw-r--r--plugins/views/modelexplorer/org.eclipse.papyrus.modelexplorer/.settings/org.eclipse.jdt.core.prefs8
-rw-r--r--plugins/views/modelexplorer/org.eclipse.papyrus.modelexplorer/META-INF/MANIFEST.MF46
-rw-r--r--plugins/views/modelexplorer/org.eclipse.papyrus.modelexplorer/about.html28
-rw-r--r--plugins/views/modelexplorer/org.eclipse.papyrus.modelexplorer/build.properties7
-rw-r--r--plugins/views/modelexplorer/org.eclipse.papyrus.modelexplorer/icons/ModelExplorer.gifbin0 -> 114 bytes
-rw-r--r--plugins/views/modelexplorer/org.eclipse.papyrus.modelexplorer/icons/etool16/arrow_double.gifbin0 -> 594 bytes
-rw-r--r--plugins/views/modelexplorer/org.eclipse.papyrus.modelexplorer/icons/etool16/close.pngbin0 -> 505 bytes
-rw-r--r--plugins/views/modelexplorer/org.eclipse.papyrus.modelexplorer/icons/etool16/closeAll.pngbin0 -> 731 bytes
-rw-r--r--plugins/views/modelexplorer/org.eclipse.papyrus.modelexplorer/icons/etool16/duplicate.pngbin0 -> 663 bytes
-rw-r--r--plugins/views/modelexplorer/org.eclipse.papyrus.modelexplorer/icons/etool16/forward.gifbin0 -> 327 bytes
-rw-r--r--plugins/views/modelexplorer/org.eclipse.papyrus.modelexplorer/icons/etool16/rename.gifbin0 -> 922 bytes
-rw-r--r--plugins/views/modelexplorer/org.eclipse.papyrus.modelexplorer/icons/etool16/search.gifbin0 -> 545 bytes
-rw-r--r--plugins/views/modelexplorer/org.eclipse.papyrus.modelexplorer/icons/etool16/sort.gifbin0 -> 153 bytes
-rw-r--r--plugins/views/modelexplorer/org.eclipse.papyrus.modelexplorer/icons/etool16/uiCustom.gifbin0 -> 632 bytes
-rw-r--r--plugins/views/modelexplorer/org.eclipse.papyrus.modelexplorer/plugin.properties18
-rw-r--r--plugins/views/modelexplorer/org.eclipse.papyrus.modelexplorer/plugin.xml726
-rw-r--r--plugins/views/modelexplorer/org.eclipse.papyrus.modelexplorer/schema/org.eclipse.papyrus.modelexplorer.actionHandler.exsd141
-rw-r--r--plugins/views/modelexplorer/org.eclipse.papyrus.modelexplorer/src/org/eclipse/papyrus/core/ui/exception/ModelExplorerException.java44
-rw-r--r--plugins/views/modelexplorer/org.eclipse.papyrus.modelexplorer/src/org/eclipse/papyrus/core/ui/pagebookview/CorePage.java78
-rw-r--r--plugins/views/modelexplorer/org.eclipse.papyrus.modelexplorer/src/org/eclipse/papyrus/core/ui/pagebookview/DefaultPage.java70
-rw-r--r--plugins/views/modelexplorer/org.eclipse.papyrus.modelexplorer/src/org/eclipse/papyrus/core/ui/pagebookview/ModelExplorerDecorationAdapter.java268
-rw-r--r--plugins/views/modelexplorer/org.eclipse.papyrus.modelexplorer/src/org/eclipse/papyrus/core/ui/pagebookview/MultiViewPageBookView.java189
-rw-r--r--plugins/views/modelexplorer/org.eclipse.papyrus.modelexplorer/src/org/eclipse/papyrus/core/ui/pagebookview/ViewPageSite.java119
-rw-r--r--plugins/views/modelexplorer/org.eclipse.papyrus.modelexplorer/src/org/eclipse/papyrus/core/ui/pagebookview/ViewPartPage.java144
-rw-r--r--plugins/views/modelexplorer/org.eclipse.papyrus.modelexplorer/src/org/eclipse/papyrus/modelexplorer/Activator.java263
-rw-r--r--plugins/views/modelexplorer/org.eclipse.papyrus.modelexplorer/src/org/eclipse/papyrus/modelexplorer/CommandContext.java52
-rw-r--r--plugins/views/modelexplorer/org.eclipse.papyrus.modelexplorer/src/org/eclipse/papyrus/modelexplorer/CustomCommonViewer.java61
-rw-r--r--plugins/views/modelexplorer/org.eclipse.papyrus.modelexplorer/src/org/eclipse/papyrus/modelexplorer/ICommandContext.java37
-rw-r--r--plugins/views/modelexplorer/org.eclipse.papyrus.modelexplorer/src/org/eclipse/papyrus/modelexplorer/ICommandFilter.java32
-rw-r--r--plugins/views/modelexplorer/org.eclipse.papyrus.modelexplorer/src/org/eclipse/papyrus/modelexplorer/ITooltip.java67
-rw-r--r--plugins/views/modelexplorer/org.eclipse.papyrus.modelexplorer/src/org/eclipse/papyrus/modelexplorer/LinkHelper.java100
-rw-r--r--plugins/views/modelexplorer/org.eclipse.papyrus.modelexplorer/src/org/eclipse/papyrus/modelexplorer/Messages.java16
-rw-r--r--plugins/views/modelexplorer/org.eclipse.papyrus.modelexplorer/src/org/eclipse/papyrus/modelexplorer/MoDiscoContentProvider.java156
-rw-r--r--plugins/views/modelexplorer/org.eclipse.papyrus.modelexplorer/src/org/eclipse/papyrus/modelexplorer/MoDiscoLabelProvider.java183
-rw-r--r--plugins/views/modelexplorer/org.eclipse.papyrus.modelexplorer/src/org/eclipse/papyrus/modelexplorer/MoDiscoLabelProviderWTooltips.java92
-rw-r--r--plugins/views/modelexplorer/org.eclipse.papyrus.modelexplorer/src/org/eclipse/papyrus/modelexplorer/ModelExplorerPage.java75
-rw-r--r--plugins/views/modelexplorer/org.eclipse.papyrus.modelexplorer/src/org/eclipse/papyrus/modelexplorer/ModelExplorerPageBookView.java169
-rw-r--r--plugins/views/modelexplorer/org.eclipse.papyrus.modelexplorer/src/org/eclipse/papyrus/modelexplorer/ModelExplorerView.java622
-rw-r--r--plugins/views/modelexplorer/org.eclipse.papyrus.modelexplorer/src/org/eclipse/papyrus/modelexplorer/NavigatorUtils.java310
-rw-r--r--plugins/views/modelexplorer/org.eclipse.papyrus.modelexplorer/src/org/eclipse/papyrus/modelexplorer/SemanticFromModelExplorer.java47
-rw-r--r--plugins/views/modelexplorer/org.eclipse.papyrus.modelexplorer/src/org/eclipse/papyrus/modelexplorer/actionprovider/AbstractCommonActionProvider.java104
-rw-r--r--plugins/views/modelexplorer/org.eclipse.papyrus.modelexplorer/src/org/eclipse/papyrus/modelexplorer/actionprovider/AbstractSubmenuActionProvider.java124
-rw-r--r--plugins/views/modelexplorer/org.eclipse.papyrus.modelexplorer/src/org/eclipse/papyrus/modelexplorer/actionprovider/CreateChildActionProvider.java125
-rw-r--r--plugins/views/modelexplorer/org.eclipse.papyrus.modelexplorer/src/org/eclipse/papyrus/modelexplorer/actionprovider/CreateDiagramActionProvider.java53
-rw-r--r--plugins/views/modelexplorer/org.eclipse.papyrus.modelexplorer/src/org/eclipse/papyrus/modelexplorer/actionprovider/DiagramActionProvider.java75
-rw-r--r--plugins/views/modelexplorer/org.eclipse.papyrus.modelexplorer/src/org/eclipse/papyrus/modelexplorer/actionprovider/EditingDomainActionProvider.java295
-rw-r--r--plugins/views/modelexplorer/org.eclipse.papyrus.modelexplorer/src/org/eclipse/papyrus/modelexplorer/actionprovider/GenericTransformActionProvider.java219
-rw-r--r--plugins/views/modelexplorer/org.eclipse.papyrus.modelexplorer/src/org/eclipse/papyrus/modelexplorer/actions/CloseAllDiagramsAction.java71
-rw-r--r--plugins/views/modelexplorer/org.eclipse.papyrus.modelexplorer/src/org/eclipse/papyrus/modelexplorer/actions/CloseDiagramAction.java57
-rw-r--r--plugins/views/modelexplorer/org.eclipse.papyrus.modelexplorer/src/org/eclipse/papyrus/modelexplorer/actions/CreateDiagramAction.java88
-rw-r--r--plugins/views/modelexplorer/org.eclipse.papyrus.modelexplorer/src/org/eclipse/papyrus/modelexplorer/actions/CreateQueryAction.java64
-rw-r--r--plugins/views/modelexplorer/org.eclipse.papyrus.modelexplorer/src/org/eclipse/papyrus/modelexplorer/actions/DeleteDiagramAction.java82
-rw-r--r--plugins/views/modelexplorer/org.eclipse.papyrus.modelexplorer/src/org/eclipse/papyrus/modelexplorer/actions/DuplicateDiagramAction.java92
-rw-r--r--plugins/views/modelexplorer/org.eclipse.papyrus.modelexplorer/src/org/eclipse/papyrus/modelexplorer/actions/ExecuteQueryAction.java70
-rw-r--r--plugins/views/modelexplorer/org.eclipse.papyrus.modelexplorer/src/org/eclipse/papyrus/modelexplorer/actions/GenericTransformAction.java121
-rw-r--r--plugins/views/modelexplorer/org.eclipse.papyrus.modelexplorer/src/org/eclipse/papyrus/modelexplorer/actions/GenericTransformer.java489
-rw-r--r--plugins/views/modelexplorer/org.eclipse.papyrus.modelexplorer/src/org/eclipse/papyrus/modelexplorer/actions/OpenDiagramAction.java74
-rw-r--r--plugins/views/modelexplorer/org.eclipse.papyrus.modelexplorer/src/org/eclipse/papyrus/modelexplorer/actions/PasteShapeOrElementAction.java62
-rw-r--r--plugins/views/modelexplorer/org.eclipse.papyrus.modelexplorer/src/org/eclipse/papyrus/modelexplorer/actions/RenameDiagramAction.java71
-rw-r--r--plugins/views/modelexplorer/org.eclipse.papyrus.modelexplorer/src/org/eclipse/papyrus/modelexplorer/commands/EObjectInheritanceCopyCommand.java444
-rw-r--r--plugins/views/modelexplorer/org.eclipse.papyrus.modelexplorer/src/org/eclipse/papyrus/modelexplorer/dialog/NavigatorSearchDialog.java370
-rw-r--r--plugins/views/modelexplorer/org.eclipse.papyrus.modelexplorer/src/org/eclipse/papyrus/modelexplorer/dnd/CommonDropAdapterAssistant.java452
-rw-r--r--plugins/views/modelexplorer/org.eclipse.papyrus.modelexplorer/src/org/eclipse/papyrus/modelexplorer/dnd/EObjectDragAdapterAssistant.java77
-rw-r--r--plugins/views/modelexplorer/org.eclipse.papyrus.modelexplorer/src/org/eclipse/papyrus/modelexplorer/factory/DefaultEMFActionsFactory.java182
-rw-r--r--plugins/views/modelexplorer/org.eclipse.papyrus.modelexplorer/src/org/eclipse/papyrus/modelexplorer/factory/IActionHandlerFactory.java85
-rw-r--r--plugins/views/modelexplorer/org.eclipse.papyrus.modelexplorer/src/org/eclipse/papyrus/modelexplorer/handler/AbstractCommandHandler.java178
-rw-r--r--plugins/views/modelexplorer/org.eclipse.papyrus.modelexplorer/src/org/eclipse/papyrus/modelexplorer/handler/AbstractModelExplorerHandler.java106
-rw-r--r--plugins/views/modelexplorer/org.eclipse.papyrus.modelexplorer/src/org/eclipse/papyrus/modelexplorer/handler/CloseHandler.java94
-rw-r--r--plugins/views/modelexplorer/org.eclipse.papyrus.modelexplorer/src/org/eclipse/papyrus/modelexplorer/handler/CopyHandler.java42
-rw-r--r--plugins/views/modelexplorer/org.eclipse.papyrus.modelexplorer/src/org/eclipse/papyrus/modelexplorer/handler/CutHandler.java47
-rw-r--r--plugins/views/modelexplorer/org.eclipse.papyrus.modelexplorer/src/org/eclipse/papyrus/modelexplorer/handler/DeleteCommandHandler.java198
-rw-r--r--plugins/views/modelexplorer/org.eclipse.papyrus.modelexplorer/src/org/eclipse/papyrus/modelexplorer/handler/DeleteDiagramHandler.java73
-rw-r--r--plugins/views/modelexplorer/org.eclipse.papyrus.modelexplorer/src/org/eclipse/papyrus/modelexplorer/handler/DuplicateDiagramHandler.java79
-rw-r--r--plugins/views/modelexplorer/org.eclipse.papyrus.modelexplorer/src/org/eclipse/papyrus/modelexplorer/handler/GMFtoEMFCommandWrapper.java40
-rw-r--r--plugins/views/modelexplorer/org.eclipse.papyrus.modelexplorer/src/org/eclipse/papyrus/modelexplorer/handler/LoadBrowserCustomization.java316
-rw-r--r--plugins/views/modelexplorer/org.eclipse.papyrus.modelexplorer/src/org/eclipse/papyrus/modelexplorer/handler/OpenHandler.java147
-rw-r--r--plugins/views/modelexplorer/org.eclipse.papyrus.modelexplorer/src/org/eclipse/papyrus/modelexplorer/handler/PasteHandler.java46
-rw-r--r--plugins/views/modelexplorer/org.eclipse.papyrus.modelexplorer/src/org/eclipse/papyrus/modelexplorer/handler/RedoHandler.java51
-rw-r--r--plugins/views/modelexplorer/org.eclipse.papyrus.modelexplorer/src/org/eclipse/papyrus/modelexplorer/handler/RenameDiagramHandler.java78
-rw-r--r--plugins/views/modelexplorer/org.eclipse.papyrus.modelexplorer/src/org/eclipse/papyrus/modelexplorer/handler/SearchElementHandler.java84
-rw-r--r--plugins/views/modelexplorer/org.eclipse.papyrus.modelexplorer/src/org/eclipse/papyrus/modelexplorer/handler/SortElementHandler.java101
-rw-r--r--plugins/views/modelexplorer/org.eclipse.papyrus.modelexplorer/src/org/eclipse/papyrus/modelexplorer/handler/UndoHandler.java53
-rw-r--r--plugins/views/modelexplorer/org.eclipse.papyrus.modelexplorer/src/org/eclipse/papyrus/modelexplorer/listener/DoubleClickListener.java70
-rw-r--r--plugins/views/modelexplorer/org.eclipse.papyrus.modelexplorer/src/org/eclipse/papyrus/modelexplorer/messages.properties15
-rw-r--r--plugins/views/modelexplorer/org.eclipse.papyrus.modelexplorer/src/org/eclipse/papyrus/modelexplorer/messages/Messages.java34
-rw-r--r--plugins/views/modelexplorer/org.eclipse.papyrus.modelexplorer/src/org/eclipse/papyrus/modelexplorer/messages/messages.properties3
-rw-r--r--plugins/views/modelexplorer/org.eclipse.papyrus.modelexplorer/src/org/eclipse/papyrus/modelexplorer/preferences/INavigatorPreferenceConstants.java28
-rw-r--r--plugins/views/modelexplorer/org.eclipse.papyrus.modelexplorer/src/org/eclipse/papyrus/modelexplorer/preferences/NavigatorPreferenceInitializer.java46
-rw-r--r--plugins/views/modelexplorer/org.eclipse.papyrus.modelexplorer/src/org/eclipse/papyrus/modelexplorer/preferences/NavigatorPreferencePage.java68
-rw-r--r--plugins/views/modelexplorer/org.eclipse.papyrus.modelexplorer/src/org/eclipse/papyrus/modelexplorer/preferences/TransformCommandShowPopupDialogGroup.java69
-rw-r--r--plugins/views/modelexplorer/org.eclipse.papyrus.modelexplorer/src/org/eclipse/papyrus/modelexplorer/provider/ActionStateSourceProvider.java268
-rw-r--r--plugins/views/modelexplorer/org.eclipse.papyrus.modelexplorer/src/org/eclipse/papyrus/modelexplorer/provider/PropertyTester.java198
-rw-r--r--plugins/views/modelexplorer/org.eclipse.papyrus.modelexplorer/src/org/eclipse/papyrus/modelexplorer/queries/AbstractEditorContainerQuery.java45
-rw-r--r--plugins/views/modelexplorer/org.eclipse.papyrus.modelexplorer/src/org/eclipse/papyrus/modelexplorer/queries/AbstractGetEditorIconQuery.java69
97 files changed, 10798 insertions, 0 deletions
diff --git a/plugins/views/modelexplorer/org.eclipse.papyrus.modelexplorer/.classpath b/plugins/views/modelexplorer/org.eclipse.papyrus.modelexplorer/.classpath
new file mode 100644
index 00000000000..2d1a4302f04
--- /dev/null
+++ b/plugins/views/modelexplorer/org.eclipse.papyrus.modelexplorer/.classpath
@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+ <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.5"/>
+ <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
+ <classpathentry kind="src" path="src"/>
+ <classpathentry kind="output" path="bin"/>
+</classpath>
diff --git a/plugins/views/modelexplorer/org.eclipse.papyrus.modelexplorer/.project b/plugins/views/modelexplorer/org.eclipse.papyrus.modelexplorer/.project
new file mode 100644
index 00000000000..14e921254d8
--- /dev/null
+++ b/plugins/views/modelexplorer/org.eclipse.papyrus.modelexplorer/.project
@@ -0,0 +1,28 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+ <name>org.eclipse.papyrus.modelexplorer</name>
+ <comment></comment>
+ <projects>
+ </projects>
+ <buildSpec>
+ <buildCommand>
+ <name>org.eclipse.jdt.core.javabuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.eclipse.pde.ManifestBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.eclipse.pde.SchemaBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ </buildSpec>
+ <natures>
+ <nature>org.eclipse.pde.PluginNature</nature>
+ <nature>org.eclipse.jdt.core.javanature</nature>
+ </natures>
+</projectDescription>
diff --git a/plugins/views/modelexplorer/org.eclipse.papyrus.modelexplorer/.settings/org.eclipse.core.resources.prefs b/plugins/views/modelexplorer/org.eclipse.papyrus.modelexplorer/.settings/org.eclipse.core.resources.prefs
new file mode 100644
index 00000000000..44cb591bfe9
--- /dev/null
+++ b/plugins/views/modelexplorer/org.eclipse.papyrus.modelexplorer/.settings/org.eclipse.core.resources.prefs
@@ -0,0 +1,3 @@
+#Tue Feb 08 11:26:34 CET 2011
+eclipse.preferences.version=1
+encoding//src/org/eclipse/papyrus/modelexplorer/messages/messages.properties=ISO-8859-1
diff --git a/plugins/views/modelexplorer/org.eclipse.papyrus.modelexplorer/.settings/org.eclipse.jdt.core.prefs b/plugins/views/modelexplorer/org.eclipse.papyrus.modelexplorer/.settings/org.eclipse.jdt.core.prefs
new file mode 100644
index 00000000000..eab8bcb39de
--- /dev/null
+++ b/plugins/views/modelexplorer/org.eclipse.papyrus.modelexplorer/.settings/org.eclipse.jdt.core.prefs
@@ -0,0 +1,8 @@
+#Tue Apr 13 12:44:19 CEST 2010
+eclipse.preferences.version=1
+org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5
+org.eclipse.jdt.core.compiler.compliance=1.5
+org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
+org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
+org.eclipse.jdt.core.compiler.source=1.5
diff --git a/plugins/views/modelexplorer/org.eclipse.papyrus.modelexplorer/META-INF/MANIFEST.MF b/plugins/views/modelexplorer/org.eclipse.papyrus.modelexplorer/META-INF/MANIFEST.MF
new file mode 100644
index 00000000000..5eb49a4a286
--- /dev/null
+++ b/plugins/views/modelexplorer/org.eclipse.papyrus.modelexplorer/META-INF/MANIFEST.MF
@@ -0,0 +1,46 @@
+Manifest-Version: 1.0
+Bundle-ManifestVersion: 2
+Bundle-Name: %pluginName
+Bundle-Localization: plugin
+Bundle-SymbolicName: org.eclipse.papyrus.modelexplorer;singleton:=true
+Bundle-Version: 0.9.0.qualifier
+Bundle-Activator: org.eclipse.papyrus.modelexplorer.Activator
+Require-Bundle: org.eclipse.ui,
+ org.eclipse.core.runtime,
+ org.eclipse.ui.navigator;bundle-version="3.4.0",
+ org.eclipse.papyrus.core;bundle-version="0.8.0";visibility:=reexport,
+ org.eclipse.papyrus.log;bundle-version="0.8.0",
+ org.eclipse.emf.converter;bundle-version="2.5.0",
+ org.eclipse.papyrus.preferences;bundle-version="0.8.0",
+ org.eclipse.papyrus.sasheditor.di;bundle-version="0.8.0",
+ org.eclipse.ltk.core.refactoring;bundle-version="3.5.100",
+ org.eclipse.emf.ecore.editor;bundle-version="2.6.0",
+ org.eclipse.emf.workspace.ui;bundle-version="1.3.0",
+ org.eclipse.core.expressions;bundle-version="3.4.200",
+ org.eclipse.papyrus.service.edit;bundle-version="0.8.0",
+ org.eclipse.papyrus.validation;bundle-version="0.8.0",
+ org.eclipse.emf.facet.infra.browser;bundle-version="0.1.0",
+ org.eclipse.emf.facet.infra.browser.custom;bundle-version="0.1.0",
+ org.eclipse.emf.facet.infra.browser.custom.core;bundle-version="0.1.0",
+ org.eclipse.emf.facet.infra.browser.custom.ui;bundle-version="0.1.0",
+ org.eclipse.emf.facet.infra.browser.uicore;bundle-version="0.1.0",
+ org.eclipse.emf.facet.infra.common.core;bundle-version="0.1.0",
+ org.eclipse.emf.facet.infra.facet;bundle-version="0.1.0",
+ org.eclipse.emf.facet.infra.facet.core;bundle-version="0.1.0",
+ org.eclipse.emf.facet.infra.query.ui;bundle-version="0.1.0",
+ org.eclipse.papyrus.ui.toolbox;bundle-version="0.8.0",
+ org.eclipse.papyrus.decoration;bundle-version="0.9.0"
+Bundle-ActivationPolicy: lazy
+Bundle-RequiredExecutionEnvironment: J2SE-1.5
+Bundle-Vendor: %providerName
+Export-Package: org.eclipse.papyrus.core.ui.pagebookview,
+ org.eclipse.papyrus.modelexplorer,
+ org.eclipse.papyrus.modelexplorer.actionprovider,
+ org.eclipse.papyrus.modelexplorer.actions,
+ org.eclipse.papyrus.modelexplorer.commands,
+ org.eclipse.papyrus.modelexplorer.dialog,
+ org.eclipse.papyrus.modelexplorer.dnd,
+ org.eclipse.papyrus.modelexplorer.factory,
+ org.eclipse.papyrus.modelexplorer.handler,
+ org.eclipse.papyrus.modelexplorer.preferences,
+ org.eclipse.papyrus.modelexplorer.queries
diff --git a/plugins/views/modelexplorer/org.eclipse.papyrus.modelexplorer/about.html b/plugins/views/modelexplorer/org.eclipse.papyrus.modelexplorer/about.html
new file mode 100644
index 00000000000..dd02e0be168
--- /dev/null
+++ b/plugins/views/modelexplorer/org.eclipse.papyrus.modelexplorer/about.html
@@ -0,0 +1,28 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"/>
+<title>About</title>
+</head>
+<body lang="EN-US">
+<h2>About This Content</h2>
+
+<p>December 2, 2009</p>
+<h3>License</h3>
+
+<p>The Eclipse Foundation makes available all content in this plug-in (&quot;Content&quot;). Unless otherwise
+indicated below, the Content is provided to you under the terms and conditions of the
+Eclipse Public License Version 1.0 (&quot;EPL&quot;). A copy of the EPL is available
+at <a href="http://www.eclipse.org/legal/epl-v10.html">http://www.eclipse.org/legal/epl-v10.html</a>.
+For purposes of the EPL, &quot;Program&quot; will mean the Content.</p>
+
+<p>If you did not receive this Content directly from the Eclipse Foundation, the Content is
+being redistributed by another party (&quot;Redistributor&quot;) and different terms and conditions may
+apply to your use of any object code in the Content. Check the Redistributor's license that was
+provided with the Content. If no such license exists, contact the Redistributor. Unless otherwise
+indicated below, the terms and conditions of the EPL still apply to any source code in the Content
+and such source code may be obtained at <a href="http://www.eclipse.org">http://www.eclipse.org</a>.</p>
+
+</body>
+</html> \ No newline at end of file
diff --git a/plugins/views/modelexplorer/org.eclipse.papyrus.modelexplorer/build.properties b/plugins/views/modelexplorer/org.eclipse.papyrus.modelexplorer/build.properties
new file mode 100644
index 00000000000..9c2eda1ce0c
--- /dev/null
+++ b/plugins/views/modelexplorer/org.eclipse.papyrus.modelexplorer/build.properties
@@ -0,0 +1,7 @@
+#
+#Mon Sep 12 09:29:54 CEST 2011
+bin.includes=META-INF/,.,plugin.xml,icons/,schema/,plugin.properties,about.html
+output..=bin/
+src.includes=schema/,icons/,META-INF/,.,plugin.xml,plugin.properties,about.html
+source..=src/
+bin..=bin/
diff --git a/plugins/views/modelexplorer/org.eclipse.papyrus.modelexplorer/icons/ModelExplorer.gif b/plugins/views/modelexplorer/org.eclipse.papyrus.modelexplorer/icons/ModelExplorer.gif
new file mode 100644
index 00000000000..acb63823aa3
--- /dev/null
+++ b/plugins/views/modelexplorer/org.eclipse.papyrus.modelexplorer/icons/ModelExplorer.gif
Binary files differ
diff --git a/plugins/views/modelexplorer/org.eclipse.papyrus.modelexplorer/icons/etool16/arrow_double.gif b/plugins/views/modelexplorer/org.eclipse.papyrus.modelexplorer/icons/etool16/arrow_double.gif
new file mode 100644
index 00000000000..c02db2c9df4
--- /dev/null
+++ b/plugins/views/modelexplorer/org.eclipse.papyrus.modelexplorer/icons/etool16/arrow_double.gif
Binary files differ
diff --git a/plugins/views/modelexplorer/org.eclipse.papyrus.modelexplorer/icons/etool16/close.png b/plugins/views/modelexplorer/org.eclipse.papyrus.modelexplorer/icons/etool16/close.png
new file mode 100644
index 00000000000..65721ea8c0b
--- /dev/null
+++ b/plugins/views/modelexplorer/org.eclipse.papyrus.modelexplorer/icons/etool16/close.png
Binary files differ
diff --git a/plugins/views/modelexplorer/org.eclipse.papyrus.modelexplorer/icons/etool16/closeAll.png b/plugins/views/modelexplorer/org.eclipse.papyrus.modelexplorer/icons/etool16/closeAll.png
new file mode 100644
index 00000000000..afc21ee9683
--- /dev/null
+++ b/plugins/views/modelexplorer/org.eclipse.papyrus.modelexplorer/icons/etool16/closeAll.png
Binary files differ
diff --git a/plugins/views/modelexplorer/org.eclipse.papyrus.modelexplorer/icons/etool16/duplicate.png b/plugins/views/modelexplorer/org.eclipse.papyrus.modelexplorer/icons/etool16/duplicate.png
new file mode 100644
index 00000000000..195dc6d6c36
--- /dev/null
+++ b/plugins/views/modelexplorer/org.eclipse.papyrus.modelexplorer/icons/etool16/duplicate.png
Binary files differ
diff --git a/plugins/views/modelexplorer/org.eclipse.papyrus.modelexplorer/icons/etool16/forward.gif b/plugins/views/modelexplorer/org.eclipse.papyrus.modelexplorer/icons/etool16/forward.gif
new file mode 100644
index 00000000000..e2f8c3e1fee
--- /dev/null
+++ b/plugins/views/modelexplorer/org.eclipse.papyrus.modelexplorer/icons/etool16/forward.gif
Binary files differ
diff --git a/plugins/views/modelexplorer/org.eclipse.papyrus.modelexplorer/icons/etool16/rename.gif b/plugins/views/modelexplorer/org.eclipse.papyrus.modelexplorer/icons/etool16/rename.gif
new file mode 100644
index 00000000000..e6f786eca9a
--- /dev/null
+++ b/plugins/views/modelexplorer/org.eclipse.papyrus.modelexplorer/icons/etool16/rename.gif
Binary files differ
diff --git a/plugins/views/modelexplorer/org.eclipse.papyrus.modelexplorer/icons/etool16/search.gif b/plugins/views/modelexplorer/org.eclipse.papyrus.modelexplorer/icons/etool16/search.gif
new file mode 100644
index 00000000000..a75166978d7
--- /dev/null
+++ b/plugins/views/modelexplorer/org.eclipse.papyrus.modelexplorer/icons/etool16/search.gif
Binary files differ
diff --git a/plugins/views/modelexplorer/org.eclipse.papyrus.modelexplorer/icons/etool16/sort.gif b/plugins/views/modelexplorer/org.eclipse.papyrus.modelexplorer/icons/etool16/sort.gif
new file mode 100644
index 00000000000..866c40af135
--- /dev/null
+++ b/plugins/views/modelexplorer/org.eclipse.papyrus.modelexplorer/icons/etool16/sort.gif
Binary files differ
diff --git a/plugins/views/modelexplorer/org.eclipse.papyrus.modelexplorer/icons/etool16/uiCustom.gif b/plugins/views/modelexplorer/org.eclipse.papyrus.modelexplorer/icons/etool16/uiCustom.gif
new file mode 100644
index 00000000000..13bb5cdc73e
--- /dev/null
+++ b/plugins/views/modelexplorer/org.eclipse.papyrus.modelexplorer/icons/etool16/uiCustom.gif
Binary files differ
diff --git a/plugins/views/modelexplorer/org.eclipse.papyrus.modelexplorer/plugin.properties b/plugins/views/modelexplorer/org.eclipse.papyrus.modelexplorer/plugin.properties
new file mode 100644
index 00000000000..2a1fa306766
--- /dev/null
+++ b/plugins/views/modelexplorer/org.eclipse.papyrus.modelexplorer/plugin.properties
@@ -0,0 +1,18 @@
+##########################################################################################
+# Copyright (c) 2010 CEA LIST.
+#
+#
+# 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:
+# Patrick Tessier (CEA LIST) Patrick.tessier@cea.fr - Initial API and implementation
+#
+########################################################################################
+pluginName=Papyrus Model Explorer (Incubation)
+providerName=Eclipse Modeling Project
+navigatorContent= Model Contents
+executequery=Execute Query...
+
diff --git a/plugins/views/modelexplorer/org.eclipse.papyrus.modelexplorer/plugin.xml b/plugins/views/modelexplorer/org.eclipse.papyrus.modelexplorer/plugin.xml
new file mode 100644
index 00000000000..526fb6d1657
--- /dev/null
+++ b/plugins/views/modelexplorer/org.eclipse.papyrus.modelexplorer/plugin.xml
@@ -0,0 +1,726 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<?eclipse version="3.4"?>
+<plugin>
+ <extension-point id="actionHandler" name="actionHandler" schema="schema/org.eclipse.papyrus.modelexplorer.actionHandler.exsd"/>
+ <extension
+ point="org.eclipse.ui.views">
+ <view
+ category="org.eclipse.papyrus.views.category"
+ class="org.eclipse.papyrus.modelexplorer.ModelExplorerPageBookView"
+ icon="icons/ModelExplorer.gif"
+ id="org.eclipse.papyrus.modelexplorer.modelexplorer"
+ name="Model Explorer"
+ restorable="true">
+ </view>
+ </extension>
+ <extension
+ point="org.eclipse.ui.navigator.viewer">
+ <viewer
+ popupMenuId="org.eclipse.papyrus.modelexplorer.modelexplorer.popup"
+ viewerId="org.eclipse.papyrus.modelexplorer.modelexplorer">
+ </viewer>
+ <viewerContentBinding
+ viewerId="org.eclipse.papyrus.modelexplorer.modelexplorer">
+ <includes>
+ <contentExtension
+ pattern="org.eclipse.papyrus.modelexplorer.*">
+ </contentExtension></includes>
+ </viewerContentBinding>
+ <!--We add a drag assistant in order support drag and drop between Model Explorer and Table Editor or other View/editors -->
+ <dragAssistant
+ class="org.eclipse.papyrus.modelexplorer.dnd.EObjectDragAdapterAssistant"
+ viewerId="org.eclipse.papyrus.modelexplorer.modelexplorer">
+ </dragAssistant>
+ </extension>
+ <extension
+ point="org.eclipse.ui.navigator.navigatorContent">
+ <navigatorContent
+ activeByDefault="false"
+ contentProvider="org.eclipse.papyrus.modelexplorer.MoDiscoContentProvider"
+ id="org.eclipse.papyrus.modelexplorer.navigatorContent"
+ labelProvider="org.eclipse.papyrus.modelexplorer.MoDiscoLabelProviderWTooltips"
+ name="Model Contents"
+ priority="lowest">
+ <triggerPoints>
+ <or>
+ <instanceof
+ value="org.eclipse.emf.ecore.EObject">
+ </instanceof>
+ <adapt
+ type="org.eclipse.emf.ecore.EObject">
+ </adapt>
+ <instanceof
+ value="java.lang.Object">
+ </instanceof>
+ </or></triggerPoints>
+ <possibleChildren>
+ <or>
+ <instanceof
+ value="org.eclipse.gmf.runtime.notation.impl.DiagramImpl">
+ </instanceof>
+ <instanceof value="org.eclipse.emf.facet.infra.browser.uicore.internal.model.ModelElementItem"/>
+ </or>
+ </possibleChildren>
+ <actionProvider
+ class="org.eclipse.papyrus.modelexplorer.actionprovider.GenericTransformActionProvider"
+ id="org.eclipse.papyrus.modelexplorer.actionprovider.GenericTransformActionProvider">
+ <enablement>
+ <or>
+ <adapt
+ type="org.eclipse.emf.ecore.EObject">
+ </adapt>
+ </or>
+ </enablement>
+ </actionProvider>
+
+ <actionProvider
+ class="org.eclipse.papyrus.modelexplorer.actionprovider.EditingDomainActionProvider"
+ id="org.eclipse.papyrus.modelexplorer.actionprovider.EditingDomainActionProvider">
+ <enablement>
+ <and>
+ <not>
+ <instanceof
+ value="org.eclipse.gmf.runtime.notation.Diagram">
+ </instanceof>
+ </not>
+ <adapt
+ type="org.eclipse.emf.ecore.EObject">
+ </adapt>
+ </and>
+ </enablement>
+ </actionProvider>
+ <dropAssistant
+ class="org.eclipse.papyrus.modelexplorer.dnd.CommonDropAdapterAssistant"
+ id="org.eclipse.papyrus.modelexplorer.dnd.CommonDropAdapterAssistant">
+ <possibleDropTargets>
+ <or>
+ <instanceof
+ value="org.eclipse.gmf.runtime.notation.impl.DiagramImpl">
+ </instanceof>
+ <adapt
+ type="org.eclipse.emf.ecore.EObject">
+ </adapt>
+ </or></possibleDropTargets>
+ </dropAssistant>
+
+ </navigatorContent>
+ </extension>
+ <extension
+ point="org.eclipse.ui.popupMenus">
+ <objectContribution
+ adaptable="false"
+ id="org.eclipse.gmt.modisco.infra.query.ui.executeQuery"
+ objectClass="org.eclipse.gmt.modisco.infra.browser.uicore.internal.model.ModelElementItem">
+ <action
+ class="org.eclipse.papyrus.modelexplorer.actions.ExecuteQueryAction"
+ id="org.eclipse.gmt.modisco.infra.query.ui.executeQuery"
+ label="Execute Query">
+ </action>
+ </objectContribution>
+ <objectContribution
+ adaptable="false"
+ id="org.eclipse.gmt.modisco.infra.query.ui.executeQuery"
+ objectClass="org.eclipse.gmt.modisco.infra.browser.uicore.internal.model.ModelElementItem">
+ <action
+ class="org.eclipse.papyrus.modelexplorer.actions.CreateQueryAction"
+ id="org.eclipse.gmt.modisco.infra.query.ui.executeQuery"
+ label="Create Query">
+ </action>
+ </objectContribution>
+ </extension>
+ <!--
+ <extension
+ point="org.eclipse.papyrus.modelexplorer.actionHandler">
+
+ <customAction
+ actionHandler="org.eclipse.papyrus.modelexplorer.factory.DefaultEMFActionsFactory"
+ actionId="org.eclipse.papyrus.modelexplorer.factory.defaultEMFActions"
+ afterAction="org.eclipse.papyrus.modelexplorer.factory.renameAction"
+ needSeparator="true">
+ </customAction>
+ </extension>
+-->
+<extension point="org.eclipse.ui.menus">
+
+ <!-- ModelExplorer toolbar -->
+ <menuContribution locationURI="toolbar:org.eclipse.papyrus.modelexplorer.modelexplorer"
+ allPopups="false">
+
+ <!-- Load modisco browser customization command -->
+ <command
+ commandId="org.eclipse.papyrus.modelexplorer.LoadBrowserCustomization"
+ icon="icons/etool16/uiCustom.gif"
+ label="Load browser customization"
+ style="push">
+ </command>
+
+ <!-- Search element command -->
+ <command
+ commandId="org.eclipse.papyrus.modelexplorer.searchelement"
+ icon="icons/etool16/search.gif"
+ label="Search element"
+ style="push">
+ </command>
+
+ <!-- Sort elements command -->
+ <command
+ commandId="org.eclipse.papyrus.modelexplorer.sortelement"
+ icon="icons/etool16/sort.gif"
+ label="sort"
+ style="toggle">
+ </command>
+ </menuContribution>
+ <menuContribution
+ allPopups="false"
+ locationURI="popup:org.eclipse.papyrus.modelexplorer.modelexplorer.popup">
+ <menu
+ id="org.eclipse.papyrus.modelexplorer.popupmenu.createchild"
+ label="New Child">
+ </menu>
+ <menu
+ id="org.eclipse.papyrus.modelexplorer.popupmenu.creatediagram"
+ label="New Diagram">
+ </menu>
+ <command
+ commandId="org.eclipse.ui.edit.delete"
+ disabledIcon="IMG_TOOL_DELETE_DISABLED"
+ icon="IMG_TOOL_DELETE"
+ label="Delete"
+ style="push"
+ tooltip="Delete">
+ <visibleWhen
+ checkEnabled="true">
+ <and>
+ <with
+ variable="selection">
+ <iterate>
+ <adapt
+ type="org.eclipse.emf.ecore.EObject">
+ </adapt>
+ </iterate>
+ </with>
+ </and>
+ </visibleWhen>
+ </command>
+ <separator
+ name="popup:org.eclipse.papyrus.modelexplorer.modelexplorer.popup.separator0"
+ visible="true">
+ </separator>
+ <command
+ commandId="org.eclipse.ui.edit.rename"
+ icon="icons/etool16/rename.gif"
+ id="org.eclipse.papyrus.modelexplorer.modelexplorer.popup.rename"
+ label="&amp;Rename"
+ style="push"
+ tooltip="Rename the element">
+ <visibleWhen
+ checkEnabled="true">
+ </visibleWhen>
+ </command>
+ <separator
+ name="popup:org.eclipse.papyrus.modelexplorer.modelexplorer.popup.separator1"
+ visible="true">
+ </separator>
+ <command
+ commandId="org.eclipse.ui.edit.undo"
+ id="org.eclipse.papyrus.modelexplorer.modelexplorer.popup.undo"
+ label="&amp;Undo"
+ style="push">
+ </command>
+ <command
+ commandId="org.eclipse.ui.edit.redo"
+ id="org.eclipse.papyrus.modelexplorer.modelexplorer.popup.redo"
+ label="&amp;Redo"
+ style="push">
+ </command>
+ <separator
+ name="popup:org.eclipse.papyrus.modelexplorer.modelexplorer.popup.separator2"
+ visible="true">
+ </separator>
+ <command
+ commandId="org.eclipse.papyrus.modelexplorer.popup.open.command"
+ icon="icons/etool16/forward.gif"
+ id="org.eclipse.papyrus.modelexplorer.modelexplorer.popup.open"
+ label="&amp;Open"
+ style="push"
+ tooltip="Open">
+ <visibleWhen
+ checkEnabled="true">
+ </visibleWhen>
+ </command>
+ <command
+ commandId="org.eclipse.papyrus.modelexplorer.popup.open.new.command"
+ icon="icons/etool16/arrow_double.gif"
+ id="org.eclipse.papyrus.modelexplorer.modelexplorer.popup.open.new"
+ label="Open In &amp;New Table"
+ style="push"
+ tooltip="Open in new tab">
+ <visibleWhen
+ checkEnabled="true">
+ </visibleWhen>
+ </command>
+ <command
+ commandId="org.eclipse.papyrus.modelexplorer.popup.close.command"
+ icon="icons/etool16/close.png"
+ id="org.eclipse.papyrus.modelexplorer.modelexplorer.popup.close"
+ label="&amp;Close"
+ style="push"
+ tooltip="Close">
+ <visibleWhen
+ checkEnabled="true">
+ </visibleWhen>
+ </command>
+ <command
+ commandId="org.eclipse.papyrus.modelexplorer.close.all.command"
+ icon="icons/etool16/closeAll.png"
+ id="org.eclipse.papyrus.modelexplorer.modelexplorer.popup.close.all"
+ label="Close &amp;All"
+ style="push"
+ tooltip="Close All">
+ <visibleWhen
+ checkEnabled="true">
+ </visibleWhen>
+ </command>
+ <command
+ commandId="org.eclipse.papyrus.modelexplorer.duplicate.command"
+ icon="icons/etool16/duplicate.png"
+ id="org.eclipse.papyrus.modelexplorer.modelexplorer.popup.duplicate"
+ label="&amp;Duplicate"
+ style="push"
+ tooltip="Duplicate the element">
+ <visibleWhen
+ checkEnabled="true">
+ </visibleWhen>
+ </command>
+ <separator
+ name="popup:org.eclipse.papyrus.modelexplorer.modelexplorer.popup.separator3"
+ visible="true">
+ </separator>
+ <command
+ commandId="org.eclipse.ui.edit.cut"
+ id="org.eclipse.papyrus.modelexplorer.modelexplorer.popup.cut"
+ label="Cu&amp;t"
+ style="push">
+ <visibleWhen
+ checkEnabled="false">
+ <with
+ variable="selection">
+ <!-- We add this test in order to refresh the Cut action in the menu edit -->
+ <test
+ forcePluginActivation="true"
+ property="org.eclipse.papyrus.modelexplorer.tester.isEObject"
+ value="true">
+ </test>
+ </with>
+ </visibleWhen>
+ </command>
+ <command
+ commandId="org.eclipse.ui.edit.copy"
+ id="org.eclipse.papyrus.modelexplorer.modelexplorer.popup.copy"
+ label="&amp;Copy"
+ style="push">
+ <visibleWhen
+ checkEnabled="false">
+ <with
+ variable="selection">
+ <!-- We add this test in order to refresh the Copy action in the menu edit -->
+ <test
+ forcePluginActivation="true"
+ property="org.eclipse.papyrus.modelexplorer.tester.isEObject"
+ value="true">
+ </test>
+ </with>
+ </visibleWhen>
+ </command>
+ <command
+ commandId="org.eclipse.ui.edit.paste"
+ id="org.eclipse.papyrus.modelexplorer.modelexplorer.popup.paste"
+ label="&amp;Paste"
+ style="push">
+ <visibleWhen
+ checkEnabled="false">
+ <with
+ variable="selection">
+ <!-- We add this test in order to refresh the Paste action in the menu edit -->
+ <test
+ forcePluginActivation="true"
+ property="org.eclipse.papyrus.modelexplorer.tester.isEObject"
+ value="true">
+ </test>
+ </with>
+ </visibleWhen>
+ </command>
+ </menuContribution>
+ <!-- ModelExplorer Contextual menu -->
+
+</extension>
+
+<!-- Command declarations (for model explorer toolbar and contextual menu -->
+<extension point="org.eclipse.ui.commands">
+
+ <!-- Command declaration : Load modisco browser customization command -->
+ <command id="org.eclipse.papyrus.modelexplorer.LoadBrowserCustomization"
+ name="loadBrowserCustomization" description="Load a customization for the papyrus browser"
+ categoryId="org.eclipse.papyrus.editor.category"
+ defaultHandler="org.eclipse.papyrus.modelexplorer.handler.LoadBrowserCustomization">
+ </command>
+
+ <!-- Command declaration : Search element command -->
+ <command id="org.eclipse.papyrus.modelexplorer.searchelement"
+ name="searchelement" description="Search an element in the model explorer"
+ categoryId="org.eclipse.papyrus.editor.category"
+ defaultHandler="org.eclipse.papyrus.modelexplorer.handler.SearchElementHandler">
+ </command>
+
+ <!-- Command declaration : Sort elements command -->
+ <command id="org.eclipse.papyrus.modelexplorer.sortelement"
+ name="SortElement" description="Sort elements"
+ categoryId="org.eclipse.papyrus.editor.category"
+ defaultHandler="org.eclipse.papyrus.modelexplorer.handler.SortElementHandler">
+ </command>
+
+ <!-- Command declaration : Delete element command -->
+ <command id="org.eclipse.papyrus.uml.service.creation.DeleteCommand"
+ name="Delete" description="Delete"
+ categoryId="org.eclipse.papyrus.editor.category"
+ defaultHandler="org.eclipse.papyrus.modelexplorer.handler.DeleteCommandHandler">
+ </command>
+</extension>
+
+
+ <extension point="org.eclipse.core.runtime.preferences">
+ <?gmfgen generated="false"?>
+ <initializer class="org.eclipse.papyrus.modelexplorer.preferences.NavigatorPreferenceInitializer"/>
+ </extension>
+ <extension
+ point="org.eclipse.ui.preferencePages">
+ <page
+ category="org.eclipse.papyrus.preferences.generalcategory"
+ class="org.eclipse.papyrus.modelexplorer.preferences.NavigatorPreferencePage"
+ id="org.eclipse.papyrus.modelexplorer.preferences.NavigatorPreferencePage"
+ name="Papyrus Model Explorer">
+ </page>
+ </extension>
+
+<!-- This declaration is added in order command (DeleteCommandHandler) status to be
+ verified (isVisible and isEnabled) before any attempt to execute the command,
+ and to mask the command in case it is not supported or executable.
+ -->
+<extension point="org.eclipse.ui.startup">
+ <startup class="org.eclipse.papyrus.modelexplorer.Activator"/>
+</extension>
+<extension
+ point="org.eclipse.ui.navigator.linkHelper">
+ <linkHelper
+ class="org.eclipse.papyrus.modelexplorer.LinkHelper"
+ id="org.eclipse.papyrus.modelexplorer.linkHelper">
+ <selectionEnablement>
+ <instanceof
+ value="java.lang.Object">
+ </instanceof>
+ </selectionEnablement>
+ <editorInputEnablement>
+ <instanceof
+ value="org.eclipse.ui.part.IFileEditorInput">
+ </instanceof>
+ </editorInputEnablement>
+ </linkHelper>
+</extension>
+
+<!-- This service listen the selection, ensures that the modelExplorer is active, and update the
+ deleteInModelExplorer variable according to the selection.
+ -->
+<extension point="org.eclipse.ui.services">
+ <sourceProvider provider="org.eclipse.papyrus.modelexplorer.provider.ActionStateSourceProvider">
+ <variable name="deleteInModelExplorer" priorityLevel="workbench" />
+ </sourceProvider>
+</extension>
+
+<!-- This handler is activated when deleteInModelExplorer variable is valid.
+ -->
+<extension point="org.eclipse.ui.handlers">
+ <handler commandId="org.eclipse.ui.edit.delete" class="org.eclipse.papyrus.modelexplorer.handler.DeleteCommandHandler">
+ <activeWhen>
+ <with variable="deleteInModelExplorer">
+ <equals value="enabled" />
+ </with>
+ </activeWhen>
+ </handler>
+</extension>
+<extension
+ point="org.eclipse.ui.commands">
+ <command
+ categoryId="org.eclipse.papyrus.editor.category"
+ description="The command to open in a tab"
+ id="org.eclipse.papyrus.modelexplorer.popup.open.command"
+ name="Open Command">
+ </command>
+ <command
+ categoryId="org.eclipse.papyrus.editor.category"
+ description="The command to open in a new tab"
+ id="org.eclipse.papyrus.modelexplorer.popup.open.new.command"
+ name="Open In New Tab Command">
+ </command>
+ <command
+ categoryId="org.eclipse.papyrus.editor.category"
+ description="The command to close"
+ id="org.eclipse.papyrus.modelexplorer.popup.close.command"
+ name="Close Command">
+ </command>
+ <command
+ categoryId="org.eclipse.papyrus.editor.category"
+ description="The command to close all "
+ id="org.eclipse.papyrus.modelexplorer.close.all.command"
+ name="Close All Command">
+ </command>
+ <command
+ categoryId="org.eclipse.papyrus.editor.category"
+ description="The Command to duplicate the selected element"
+ id="org.eclipse.papyrus.modelexplorer.duplicate.command"
+ name="Duplicate ">
+ </command>
+</extension>
+<extension
+ point="org.eclipse.ui.handlers">
+ <handler
+ class="org.eclipse.papyrus.modelexplorer.handler.RenameDiagramHandler"
+ commandId="org.eclipse.ui.edit.rename">
+ <activeWhen>
+ <with
+ variable="selection">
+ <and>
+ <count
+ value="1">
+ </count>
+ <!-- We add this test in order to refresh the Rename action in the menu edit -->
+ <test
+ forcePluginActivation="true"
+ property="org.eclipse.papyrus.modelexplorer.tester.isDiagram"
+ value="true">
+ </test>
+ </and>
+ </with>
+ </activeWhen>
+ </handler>
+ <handler
+ commandId="org.eclipse.papyrus.modelexplorer.popup.close.command">
+ <activeWhen>
+ <with
+ variable="selection">
+ <and>
+ <test
+ forcePluginActivation="true"
+ property="org.eclipse.papyrus.modelexplorer.tester.isPage"
+ value="true">
+ </test>
+ </and>
+ </with>
+ </activeWhen>
+ <class
+ class="org.eclipse.papyrus.modelexplorer.handler.CloseHandler">
+ <parameter
+ name="close_parameter"
+ value="selection">
+ </parameter>
+ </class>
+ </handler>
+ <handler
+ commandId="org.eclipse.papyrus.modelexplorer.close.all.command">
+ <class
+ class="org.eclipse.papyrus.modelexplorer.handler.CloseHandler">
+ <parameter
+ name="close_parameter"
+ value="all">
+ </parameter>
+ </class>
+ <activeWhen>
+ <with
+ variable="selection">
+ <and>
+ <test
+ forcePluginActivation="true"
+ property="org.eclipse.papyrus.modelexplorer.tester.isPage"
+ value="true">
+ </test>
+ </and>
+ </with>
+ </activeWhen>
+ </handler>
+ <handler
+ class="org.eclipse.papyrus.modelexplorer.handler.DeleteDiagramHandler"
+ commandId="org.eclipse.ui.edit.delete">
+ <activeWhen>
+ <and>
+ <with
+ variable="selection">
+ </with>
+ <!-- We add this test in order to refresh the Delete action in the menu edit -->
+ <with
+ variable="selection">
+ <test
+ forcePluginActivation="true"
+ property="org.eclipse.papyrus.modelexplorer.tester.isDiagram"
+ value="true">
+ </test>
+ </with>
+ </and>
+ </activeWhen>
+ </handler>
+ <handler
+ commandId="org.eclipse.papyrus.modelexplorer.popup.open.command">
+ <activeWhen>
+ <with
+ variable="selection">
+ <and>
+ <test
+ forcePluginActivation="true"
+ property="org.eclipse.papyrus.modelexplorer.tester.isPage"
+ value="true">
+ </test>
+ </and>
+ </with>
+ </activeWhen>
+ <class
+ class="org.eclipse.papyrus.modelexplorer.handler.OpenHandler">
+ <parameter
+ name="open_parameter"
+ value="close">
+ </parameter>
+ </class>
+ </handler>
+ <handler
+ commandId="org.eclipse.papyrus.modelexplorer.popup.open.new.command">
+ <activeWhen>
+ <with
+ variable="selection">
+ <and>
+ <test
+ forcePluginActivation="true"
+ property="org.eclipse.papyrus.modelexplorer.tester.isPage"
+ value="true">
+ </test>
+ </and>
+ </with>
+ </activeWhen>
+ <class
+ class="org.eclipse.papyrus.modelexplorer.handler.OpenHandler">
+ <parameter
+ name="open_parameter"
+ value="already_open">
+ </parameter>
+ </class>
+ </handler>
+ <handler
+ class="org.eclipse.papyrus.modelexplorer.handler.DuplicateDiagramHandler"
+ commandId="org.eclipse.papyrus.modelexplorer.duplicate.command">
+ <activeWhen>
+ <and>
+ <with
+ variable="selection">
+ <and>
+ <count
+ value="1">
+ </count>
+ </and>
+ </with>
+ <with
+ variable="selection">
+ <test
+ forcePluginActivation="true"
+ property="org.eclipse.papyrus.modelexplorer.tester.isDiagram"
+ value="true">
+ </test>
+ </with>
+ </and>
+ </activeWhen>
+ </handler>
+ <handler
+ class="org.eclipse.papyrus.modelexplorer.handler.CutHandler"
+ commandId="org.eclipse.ui.edit.cut">
+ <activeWhen>
+ <and>
+ <with
+ variable="activePart">
+ <instanceof
+ value="org.eclipse.papyrus.modelexplorer.ModelExplorerPageBookView">
+ </instanceof>
+ </with>
+ <with
+ variable="selection">
+ <!-- We add this test in order to refresh the Cut action in the menu edit -->
+ <test
+ forcePluginActivation="true"
+ property="org.eclipse.papyrus.modelexplorer.tester.isEObject"
+ value="true">
+ </test>
+ </with>
+ </and>
+ </activeWhen>
+ </handler>
+ <handler
+ class="org.eclipse.papyrus.modelexplorer.handler.UndoHandler"
+ commandId="org.eclipse.ui.edit.undo">
+ <activeWhen>
+ <and>
+ <with
+ variable="activePart">
+ <instanceof
+ value="org.eclipse.papyrus.modelexplorer.ModelExplorerPageBookView">
+ </instanceof>
+ </with>
+ <with
+ variable="activePart">
+ <!-- We add this test in order to refresh the Undo action in the menu file -->
+ <test
+ forcePluginActivation="true"
+ property="org.eclipse.papyrus.modelexplorer.tester.view.isModelExplorer"
+ value="true">
+ </test>
+ </with>
+ </and>
+ </activeWhen>
+ </handler>
+ <handler
+ class="org.eclipse.papyrus.modelexplorer.handler.RedoHandler"
+ commandId="org.eclipse.ui.edit.redo">
+ <activeWhen>
+ <and>
+ <with
+ variable="activePart">
+ <instanceof
+ value="org.eclipse.papyrus.modelexplorer.ModelExplorerPageBookView">
+ </instanceof>
+ </with>
+ <with
+ variable="activePart">
+ <!-- We add this test in order to refresh the Redo action in the menu edit -->
+ <test
+ forcePluginActivation="true"
+ property="org.eclipse.papyrus.modelexplorer.tester.view.isModelExplorer"
+ value="true">
+ </test>
+ </with>
+ </and>
+ </activeWhen>
+ </handler>
+</extension>
+<extension
+ point="org.eclipse.core.expressions.propertyTesters">
+ <!-- the property tester is used to enabled/disabled handler -->
+ <propertyTester
+ class="org.eclipse.papyrus.modelexplorer.provider.PropertyTester"
+ id="org.eclipse.papyrus.modelexplorer.tester"
+ namespace="org.eclipse.papyrus.modelexplorer.tester"
+ properties="isDiagram, isEObject, isPage"
+ type="org.eclipse.jface.viewers.IStructuredSelection">
+ </propertyTester>
+ <propertyTester
+ class="org.eclipse.papyrus.modelexplorer.provider.PropertyTester"
+ id="org.eclipse.papyrus.modelexplorer.tester.view"
+ namespace="org.eclipse.papyrus.modelexplorer.tester.view"
+ properties="isModelExplorer"
+ type="org.eclipse.ui.IWorkbenchPart">
+ </propertyTester>
+</extension>
+
+</plugin>
diff --git a/plugins/views/modelexplorer/org.eclipse.papyrus.modelexplorer/schema/org.eclipse.papyrus.modelexplorer.actionHandler.exsd b/plugins/views/modelexplorer/org.eclipse.papyrus.modelexplorer/schema/org.eclipse.papyrus.modelexplorer.actionHandler.exsd
new file mode 100644
index 00000000000..e256cfdb1a9
--- /dev/null
+++ b/plugins/views/modelexplorer/org.eclipse.papyrus.modelexplorer/schema/org.eclipse.papyrus.modelexplorer.actionHandler.exsd
@@ -0,0 +1,141 @@
+<?xml version='1.0' encoding='UTF-8'?>
+<!-- Schema file written by PDE -->
+<schema targetNamespace="org.eclipse.papyrus.modelexplorer" xmlns="http://www.w3.org/2001/XMLSchema">
+<annotation>
+ <appinfo>
+ <meta.schema plugin="org.eclipse.papyrus.modelexplorer" id="org.eclipse.papyrus.modelexplorer.actionHandler" name="ActionHandler"/>
+ </appinfo>
+ <documentation>
+ This extension point allows adding action in the contextual menu of the model explorer
+ </documentation>
+ </annotation>
+
+ <element name="extension">
+ <annotation>
+ <appinfo>
+ <meta.element deprecated="true" />
+ </appinfo>
+ </annotation>
+ <complexType>
+ <sequence minOccurs="0" maxOccurs="unbounded">
+ <element ref="customAction"/>
+ </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="customAction">
+ <annotation>
+ <appinfo>
+ <meta.element deprecated="true"/>
+ </appinfo>
+ </annotation>
+ <complexType>
+ <attribute name="actionId" type="string" use="required">
+ <annotation>
+ <documentation>
+ registered action identifier
+ </documentation>
+ </annotation>
+ </attribute>
+ <attribute name="actionHandler" type="string" use="required">
+ <annotation>
+ <documentation>
+ implement the action handler factory to add your custom actions
+ </documentation>
+ <appinfo>
+ <meta.attribute kind="java" basedOn=":org.eclipse.papyrus.navigator.factory.IActionHandlerFactory"/>
+ </appinfo>
+ </annotation>
+ </attribute>
+ <attribute name="afterAction" type="string">
+ <annotation>
+ <documentation>
+ fill the action id after you want to insert yours
+ </documentation>
+ </annotation>
+ </attribute>
+ <attribute name="needSeparator" type="boolean" use="default" value="false">
+ <annotation>
+ <documentation>
+ Add a separator before your action(s) if needed
+ </documentation>
+ </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>
+ org.eclipse.papyrus.navigator.factory.DefaultEMFActionsFactory adds default EMF actions in model explorer.
+See registered extension org.eclipse.papyrus.navigator.actionHandler
+ </documentation>
+ </annotation>
+
+ <annotation>
+ <appinfo>
+ <meta.section type="apiinfo"/>
+ </appinfo>
+ <documentation>
+ The class must implement interface org.eclipse.papyrus.navigator.factory.IActionHandlerFactory
+Deprecrated extension point. Use org.eclipse.ui.commands, org.eclipse.ui.menus, org.eclipse.ui.binding instead
+ </documentation>
+ </annotation>
+
+ <annotation>
+ <appinfo>
+ <meta.section type="implementation"/>
+ </appinfo>
+ <documentation>
+ none
+ </documentation>
+ </annotation>
+
+ <annotation>
+ <appinfo>
+ <meta.section type="copyright"/>
+ </appinfo>
+ <documentation>
+ 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
+ </documentation>
+ </annotation>
+
+</schema>
diff --git a/plugins/views/modelexplorer/org.eclipse.papyrus.modelexplorer/src/org/eclipse/papyrus/core/ui/exception/ModelExplorerException.java b/plugins/views/modelexplorer/org.eclipse.papyrus.modelexplorer/src/org/eclipse/papyrus/core/ui/exception/ModelExplorerException.java
new file mode 100644
index 00000000000..d32ca620955
--- /dev/null
+++ b/plugins/views/modelexplorer/org.eclipse.papyrus.modelexplorer/src/org/eclipse/papyrus/core/ui/exception/ModelExplorerException.java
@@ -0,0 +1,44 @@
+/**
+ * Copyright (c) 2011 Atos.
+ *
+ * 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:
+ * Atos - Initial API and implementation
+ *
+ */
+package org.eclipse.papyrus.core.ui.exception;
+
+/**
+ * Exception thrown by the model explorer plugin
+ *
+ * @author "Arthur Daussy <a href="mailto:arthur.daussy@atos.net">arthur.daussy@atos.net</a>"
+ *
+ */
+public class ModelExplorerException extends Exception {
+
+ /**
+ *
+ */
+ private static final long serialVersionUID = -1197723371777623860L;
+
+ public ModelExplorerException() {
+ super();
+ }
+
+ public ModelExplorerException(String message, Throwable cause) {
+ super(message, cause);
+ }
+
+ public ModelExplorerException(String message) {
+ super(message);
+ }
+
+ public ModelExplorerException(Throwable cause) {
+ super(cause);
+ }
+
+}
diff --git a/plugins/views/modelexplorer/org.eclipse.papyrus.modelexplorer/src/org/eclipse/papyrus/core/ui/pagebookview/CorePage.java b/plugins/views/modelexplorer/org.eclipse.papyrus.modelexplorer/src/org/eclipse/papyrus/core/ui/pagebookview/CorePage.java
new file mode 100644
index 00000000000..1786db747c9
--- /dev/null
+++ b/plugins/views/modelexplorer/org.eclipse.papyrus.modelexplorer/src/org/eclipse/papyrus/core/ui/pagebookview/CorePage.java
@@ -0,0 +1,78 @@
+/*****************************************************************************
+ * Copyright (c) 2010 LIFL & CEA LIST.
+ *
+ *
+ * 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:
+ * Cedric Dumoulin (LIFL) cedric.dumoulin@lifl.fr - Initial API and implementation
+ *
+ *****************************************************************************/
+
+package org.eclipse.papyrus.core.ui.pagebookview;
+
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Text;
+import org.eclipse.ui.IWorkbenchPart;
+import org.eclipse.ui.part.Page;
+
+
+/**
+ * @author dumoulin
+ *
+ */
+public class CorePage extends Page {
+
+ /**
+ * The default ui
+ */
+ private Text text;
+
+ private IWorkbenchPart part;
+
+
+ /**
+ * Constructor.
+ *
+ */
+ public CorePage(IWorkbenchPart part) {
+ this.part = part;
+ }
+
+ /**
+ * @see org.eclipse.ui.part.Page#createControl(org.eclipse.swt.widgets.Composite)
+ *
+ * @param parent
+ */
+ @Override
+ public void createControl(Composite parent) {
+ text = new Text(parent, SWT.CENTER);
+
+ text.setMessage("page for " + part.getTitle());
+ }
+
+ /**
+ * @see org.eclipse.ui.part.Page#getControl()
+ *
+ * @return
+ */
+ @Override
+ public Control getControl() {
+ return text;
+ }
+ /**
+ * @see org.eclipse.ui.part.Page#setFocus()
+ *
+ */
+ @Override
+ public void setFocus() {
+ // TODO Auto-generated method stub
+
+ }
+
+}
diff --git a/plugins/views/modelexplorer/org.eclipse.papyrus.modelexplorer/src/org/eclipse/papyrus/core/ui/pagebookview/DefaultPage.java b/plugins/views/modelexplorer/org.eclipse.papyrus.modelexplorer/src/org/eclipse/papyrus/core/ui/pagebookview/DefaultPage.java
new file mode 100644
index 00000000000..ba05e899908
--- /dev/null
+++ b/plugins/views/modelexplorer/org.eclipse.papyrus.modelexplorer/src/org/eclipse/papyrus/core/ui/pagebookview/DefaultPage.java
@@ -0,0 +1,70 @@
+/*****************************************************************************
+ * Copyright (c) 2010 LIFL & CEA LIST.
+ *
+ *
+ * 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:
+ * Cedric Dumoulin (LIFL) cedric.dumoulin@lifl.fr - Initial API and implementation
+ *
+ *****************************************************************************/
+
+package org.eclipse.papyrus.core.ui.pagebookview;
+
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.ui.part.Page;
+
+
+/**
+ * A default page to show when the active part can't be rendered by {@link MultiViewPageBookView}.
+ *
+ * @author cedric dumoulin
+ *
+ */
+public class DefaultPage extends Page {
+
+ public DefaultPage() {
+ }
+
+ /**
+ * The default ui
+ */
+ private Label text;
+
+ /**
+ * @see org.eclipse.ui.part.Page#createControl(org.eclipse.swt.widgets.Composite)
+ *
+ * @param parent
+ */
+ @Override
+ public void createControl(Composite parent) {
+ text = new Label(parent, SWT.CENTER);
+ text.setText("No Model Available");
+ }
+
+ /**
+ * @see org.eclipse.ui.part.Page#getControl()
+ *
+ * @return
+ */
+ @Override
+ public Control getControl() {
+ return text;
+ }
+
+ /**
+ * @see org.eclipse.ui.part.Page#setFocus()
+ *
+ */
+ @Override
+ public void setFocus() {
+
+ }
+
+}
diff --git a/plugins/views/modelexplorer/org.eclipse.papyrus.modelexplorer/src/org/eclipse/papyrus/core/ui/pagebookview/ModelExplorerDecorationAdapter.java b/plugins/views/modelexplorer/org.eclipse.papyrus.modelexplorer/src/org/eclipse/papyrus/core/ui/pagebookview/ModelExplorerDecorationAdapter.java
new file mode 100644
index 00000000000..9570181e0bb
--- /dev/null
+++ b/plugins/views/modelexplorer/org.eclipse.papyrus.modelexplorer/src/org/eclipse/papyrus/core/ui/pagebookview/ModelExplorerDecorationAdapter.java
@@ -0,0 +1,268 @@
+/*****************************************************************************
+ * Copyright (c) 2011 CEA LIST.
+ *
+ *
+ * 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:
+ * Amine EL KOUHEN (CEA LIST/LIFL) - Amine.Elkouhen@cea.fr
+ *****************************************************************************/
+package org.eclipse.papyrus.core.ui.pagebookview;
+
+import org.eclipse.jface.resource.ImageDescriptor;
+import org.eclipse.jface.viewers.DecorationOverlayIcon;
+import org.eclipse.jface.viewers.IDecoration;
+import org.eclipse.papyrus.decoration.util.Decoration.PreferedPosition;
+import org.eclipse.papyrus.modelexplorer.Activator;
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.swt.graphics.Point;
+
+
+// TODO: Auto-generated Javadoc
+/**
+ * The Class ModelExplorerDecorationAdapter.
+ */
+public class ModelExplorerDecorationAdapter {
+
+ /** The decorator target. */
+ protected Image decoratorTarget;
+
+ /** The decoration. */
+ protected ImageDescriptor decoration;
+
+ /** The decoration position. */
+ protected int decorationPosition;
+
+ /** point corresponding to the size 16x16. */
+ private final Point size16 = new Point(16, 16);
+
+
+ /**
+ * Instantiates a new model explorer decoration adapter.
+ *
+ * @param baseImage the base image
+ */
+ public ModelExplorerDecorationAdapter(Image baseImage) {
+ this.decoratorTarget = baseImage;
+ }
+
+ /**
+ * Gets the decorated image.
+ *
+ * @return the decorated image
+ */
+ public Image getDecoratedImage() {
+
+ if(getDecoration() == null && getDecoratorTarget() != null)
+ return getDecoratorTarget();
+
+ if(getDecoration() == null && getDecoratorTarget() == null)
+ return null;
+
+ return getDecoratedImage(getDecoratorTarget(), getDecoration(), getDecorationPosition());
+ }
+
+ /**
+ * Gets the decoration.
+ *
+ * @return the decoration
+ */
+ public ImageDescriptor getDecoration() {
+ return this.decoration;
+ }
+
+ /**
+ * Gets the decorator target.
+ *
+ * @return the decorator target
+ */
+ public Image getDecoratorTarget() {
+ return this.decoratorTarget;
+ }
+
+ /**
+ * Sets the decoration.
+ *
+ * @param decoration the decoration
+ * @param decorationPosition the decoration position
+ */
+ public void setDecoration(ImageDescriptor decoration, int decorationPosition) {
+ setDecoratedImage(getDecoratorTarget(), decoration, decorationPosition);
+ this.decoration = decoration;
+ this.decorationPosition = decorationPosition;
+
+ }
+
+ /**
+ * Sets the decoration.
+ *
+ * @param decoration the new decoration
+ */
+ public void setDecoration(ImageDescriptor decoration) {
+ setDecoratedImage(getDecoratorTarget(), decoration, getDecorationPosition());
+ this.decoration = decoration;
+ }
+
+ /**
+ * Sets the decorator target.
+ *
+ * @param decoratorTarget the new decorator target
+ */
+ public void setDecoratorTarget(Image decoratorTarget) {
+ this.decoratorTarget = decoratorTarget;
+ }
+
+
+ /**
+ * Gets the decoration position.
+ *
+ * @return the decoration position
+ */
+ public int getDecorationPosition() {
+ //0 for TOP_LEFT, 1 for TOP_RIGHT, 2 for BOTTOM_LEFT, 3 for BOTTOM_RIGHT (Default), 4 for an UNDERLAY
+ return decorationPosition;
+ }
+
+
+ /**
+ * Sets the decoration position.
+ *
+ * @param decorationPosition the new decoration position
+ */
+ public void setDecorationPosition(int decorationPosition) {
+ this.decorationPosition = decorationPosition;
+ }
+
+ /**
+ * Sets the decorated image.
+ *
+ * @param baseImage the base image
+ * @param decoration the decoration
+ * @param decorationPosition the decoration position
+ */
+ public void setDecoratedImage(Image baseImage, ImageDescriptor decoration, int decorationPosition) {
+
+ if(decoration == null || baseImage == null)
+ return;
+
+ DecorationOverlayIcon decoratedImage = null;
+
+ // Construct a new image identifier
+ String decoratedImageId = baseImage.toString().concat(decoration.toString() + decorationPosition);
+
+ // Return the stored image if we have one
+ if(Activator.getDefault().getImageRegistry().get(decoratedImageId) == null) {
+ // Otherwise create a new image and store it
+ switch(decorationPosition) {
+
+ case IDecoration.TOP_LEFT:
+ decoratedImage = new DecorationOverlayIcon(baseImage, new ImageDescriptor[]{ decoration, null, null, null, null }, size16);
+ break;
+ case IDecoration.TOP_RIGHT:
+ decoratedImage = new DecorationOverlayIcon(baseImage, new ImageDescriptor[]{ null, decoration, null, null, null }, size16);
+ break;
+ case IDecoration.BOTTOM_LEFT:
+ decoratedImage = new DecorationOverlayIcon(baseImage, new ImageDescriptor[]{ null, null, decoration, null, null }, size16);
+ break;
+ case IDecoration.BOTTOM_RIGHT:
+ decoratedImage = new DecorationOverlayIcon(baseImage, new ImageDescriptor[]{ null, null, null, decoration, null }, size16);
+ break;
+ case IDecoration.UNDERLAY:
+ decoratedImage = new DecorationOverlayIcon(baseImage, new ImageDescriptor[]{ null, null, null, null, decoration }, size16);
+ break;
+ default:
+ decoratedImage = new DecorationOverlayIcon(baseImage, new ImageDescriptor[]{ null, null, decoration, null, null }, size16);
+ break;
+ }
+ Activator.getDefault().getImageRegistry().put(decoratedImageId, decoratedImage);
+ }
+
+ }
+
+ /**
+ * Gets the decorated image.
+ *
+ * @param baseImage the base image
+ * @param decoration the decoration
+ * @param decorationPosition the decoration position
+ * @return the decorated image
+ */
+ public Image getDecoratedImage(Image baseImage, ImageDescriptor decoration, int decorationPosition) {
+ // Construct a new image identifier
+ String decoratedImageId = baseImage.toString().concat(decoration.toString() + decorationPosition);
+
+ // Return the stored image if we have one
+ if(Activator.getDefault().getImageRegistry().get(decoratedImageId) == null) {
+ setDecoratedImage(baseImage, decoration, decorationPosition);
+ }
+ return Activator.getDefault().getImageRegistry().get(decoratedImageId);
+ }
+
+ /**
+ * Sets the decorated image.
+ *
+ * @param baseImage the base image
+ * @param decorationArray the decoration array
+ * @param imageSize the image size
+ */
+ public void setDecoratedImage(Image baseImage, ImageDescriptor[] decorationArray, Point imageSize) {
+ DecorationOverlayIcon decoratedImage = null;
+
+ // Construct a new image identifier
+ String decoratedImageId = baseImage.toString().concat(decorationArray.toString());
+
+ // Return the stored image if we have one
+ if(Activator.getDefault().getImageRegistry().get(decoratedImageId) == null) {
+ // Otherwise create a new image and store it
+ decoratedImage = new DecorationOverlayIcon(baseImage, decorationArray, imageSize);
+
+ Activator.getDefault().getImageRegistry().put(decoratedImageId, decoratedImage);
+ }
+ }
+
+ /**
+ * Sets the decoration.
+ *
+ * @param decoration the decoration
+ * @param position the position
+ */
+ public void setDecoration(ImageDescriptor decoration, PreferedPosition position) {
+ switch(position) {
+
+ case NORTH_WEST:
+ setDecoration(decoration, IDecoration.TOP_LEFT);
+ break;
+ case NORTH:
+ setDecoration(decoration, IDecoration.TOP_RIGHT);
+ break;
+ case NORTH_EAST:
+ setDecoration(decoration, IDecoration.TOP_RIGHT);
+ break;
+ case EAST:
+ setDecoration(decoration, IDecoration.BOTTOM_RIGHT);
+ break;
+ case SOUTH_EAST:
+ setDecoration(decoration, IDecoration.BOTTOM_RIGHT);
+ break;
+ case SOUTH:
+ setDecoration(decoration, IDecoration.BOTTOM_LEFT);
+ break;
+ case SOUTH_WEST:
+ setDecoration(decoration, IDecoration.BOTTOM_LEFT);
+ break;
+ case WEST:
+ setDecoration(decoration, IDecoration.TOP_LEFT);
+ break;
+ case CENTER:
+ setDecoration(decoration, IDecoration.UNDERLAY);
+ break;
+ default:
+ setDecoration(decoration, IDecoration.BOTTOM_LEFT);
+ break;
+
+ }
+ }
+}
diff --git a/plugins/views/modelexplorer/org.eclipse.papyrus.modelexplorer/src/org/eclipse/papyrus/core/ui/pagebookview/MultiViewPageBookView.java b/plugins/views/modelexplorer/org.eclipse.papyrus.modelexplorer/src/org/eclipse/papyrus/core/ui/pagebookview/MultiViewPageBookView.java
new file mode 100644
index 00000000000..a0ebda1a626
--- /dev/null
+++ b/plugins/views/modelexplorer/org.eclipse.papyrus.modelexplorer/src/org/eclipse/papyrus/core/ui/pagebookview/MultiViewPageBookView.java
@@ -0,0 +1,189 @@
+/*****************************************************************************
+ * Copyright (c) 2010 LIFL & CEA LIST.
+ *
+ *
+ * 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:
+ * Cedric Dumoulin (LIFL) cedric.dumoulin@lifl.fr - Initial API and implementation
+ *
+ *****************************************************************************/
+
+package org.eclipse.papyrus.core.ui.pagebookview;
+
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.papyrus.core.editor.IMultiDiagramEditor;
+import org.eclipse.papyrus.modelexplorer.Activator;
+import org.eclipse.ui.IMemento;
+import org.eclipse.ui.IViewPart;
+import org.eclipse.ui.IViewSite;
+import org.eclipse.ui.IWorkbenchPage;
+import org.eclipse.ui.IWorkbenchPart;
+import org.eclipse.ui.IWorkbenchWindow;
+import org.eclipse.ui.PartInitException;
+import org.eclipse.ui.PlatformUI;
+import org.eclipse.ui.part.IPage;
+import org.eclipse.ui.part.IPageBookViewPage;
+import org.eclipse.ui.part.PageBook;
+import org.eclipse.ui.part.PageBookView;
+
+
+/**
+ * Base class for PageBookView in Papyrus.
+ * The PageBook mechanism can be moved in the core, as it can be reused by other Views.
+ *
+ * @author cedric dumoulin
+ *
+ */
+public abstract class MultiViewPageBookView extends PageBookView {
+
+ /**
+ * Remember the IMemento
+ */
+ private IMemento memento;
+
+ /**
+ * @see org.eclipse.ui.part.PageBookView#createDefaultPage(org.eclipse.ui.part.PageBook)
+ *
+ * @param book
+ * @return
+ */
+ @Override
+ protected IPageBookViewPage createDefaultPage(PageBook book) {
+ IPageBookViewPage page = new DefaultPage();
+ // Set Site
+ initPage(page);
+ page.createControl(book);
+
+ return page;
+ }
+
+ /**
+ * Subclass must implement this method.
+ * The subclass implementation look like this:
+ * <ul>
+ * <li>ViewPartPage page = new MyPage();</li>
+ * <li>call initPage(page, part);</li>
+ * <li>call page.createControl(getPageBook());</li>
+ * <li>return new PageRec(part, page);</li>
+ * </ul>
+ *
+ * @param part
+ * @return
+ */
+ @Override
+ abstract protected PageRec doCreatePage(IWorkbenchPart part);
+
+ /**
+ * @see org.eclipse.ui.part.PageBookView#doDestroyPage(org.eclipse.ui.IWorkbenchPart, org.eclipse.ui.part.PageBookView.PageRec)
+ *
+ * @param part
+ * @param pageRecord
+ */
+ @Override
+ protected void doDestroyPage(IWorkbenchPart part, PageRec pageRecord) {
+ // Nothing to do
+
+ }
+
+ /**
+ * Check if the currently active part is a {@link IMultiDiagramEditor}.
+ * If true, return it.
+ *
+ * @see org.eclipse.ui.part.PageBookView#getBootstrapPart()
+ *
+ * @return The currently active editor if it is a IMultiDiagramEditor, null otherwise.
+ */
+ @Override
+ protected IWorkbenchPart getBootstrapPart() {
+
+
+ IWorkbenchPart part = null;
+ try {
+ IWorkbenchWindow activeWorkbenchWindow = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
+ if(activeWorkbenchWindow != null) {
+ IWorkbenchPage activePage = activeWorkbenchWindow.getActivePage();
+ if(activePage != null) {
+ part = activePage.getActiveEditor();
+ }
+ }
+ } catch (NullPointerException e) {
+ // An element is not active yet
+ return null;
+ }
+ if(isImportant(part)) {
+ return part;
+ }
+ // The current active part is not for us.
+ return null;
+ }
+
+ /**
+ * return true if the activated part is a {@link IMultiDiagramEditor}.
+ *
+ * @see org.eclipse.ui.part.PageBookView#isImportant(org.eclipse.ui.IWorkbenchPart)
+ *
+ * @param part
+ * @return
+ */
+ @Override
+ protected boolean isImportant(IWorkbenchPart part) {
+
+
+ if(part instanceof IMultiDiagramEditor)
+ return true;
+
+ return false;
+ }
+
+ /**
+ * Record the IMemento to use it when pages are created
+ *
+ * @see org.eclipse.ui.part.ViewPart#init(org.eclipse.ui.IViewSite, org.eclipse.ui.IMemento)
+ *
+ * @param site
+ * @param memento
+ * @throws PartInitException
+ */
+ @Override
+ public void init(IViewSite site, IMemento memento) throws PartInitException {
+ super.init(site, memento);
+ this.memento = memento;
+ }
+
+ /**
+ * Create a Site that is also a {@link IViewSite}.
+ *
+ * @see org.eclipse.ui.part.PageBookView#initPage(org.eclipse.ui.part.IPageBookViewPage)
+ *
+ * @param page
+ */
+ protected void initPage(ViewPartPage page, IWorkbenchPart part) {
+
+ try {
+ page.init(part, new ViewPageSite(getViewSite()), memento, getConfigurationElement());
+ } catch (PartInitException e) {
+ Activator.log.error("initPage", e); //$NON-NLS-1$
+ } catch (CoreException e) {
+ Activator.log.error("initPage", e); //$NON-NLS-1$
+ }
+
+ }
+
+ /**
+ * Get the currently nested active view.
+ *
+ * @return The active Viewer, or null if none.
+ */
+ public IViewPart getActiveView() {
+ IPage page = getCurrentPage();
+ if(page instanceof ViewPartPage)
+ return ((ViewPartPage)page).getViewer();
+
+ // not found
+ return null;
+ }
+}
diff --git a/plugins/views/modelexplorer/org.eclipse.papyrus.modelexplorer/src/org/eclipse/papyrus/core/ui/pagebookview/ViewPageSite.java b/plugins/views/modelexplorer/org.eclipse.papyrus.modelexplorer/src/org/eclipse/papyrus/core/ui/pagebookview/ViewPageSite.java
new file mode 100644
index 00000000000..8757bd84cf0
--- /dev/null
+++ b/plugins/views/modelexplorer/org.eclipse.papyrus.modelexplorer/src/org/eclipse/papyrus/core/ui/pagebookview/ViewPageSite.java
@@ -0,0 +1,119 @@
+/*****************************************************************************
+ * Copyright (c) 2010 LIFL & CEA LIST.
+ *
+ *
+ * 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:
+ * Cedric Dumoulin (LIFL) cedric.dumoulin@lifl.fr - Initial API and implementation
+ *
+ *****************************************************************************/
+
+package org.eclipse.papyrus.core.ui.pagebookview;
+
+import org.eclipse.jface.action.MenuManager;
+import org.eclipse.jface.viewers.ISelectionProvider;
+import org.eclipse.ui.IKeyBindingService;
+import org.eclipse.ui.IViewSite;
+import org.eclipse.ui.IWorkbenchPart;
+import org.eclipse.ui.part.IPageSite;
+import org.eclipse.ui.part.PageSite;
+
+
+/**
+ * A Site implementing {@link IViewSite} and {@link IPageSite}.
+ * This site is used by the {@link MultiViewPageBookView} to provide suitable Site to a
+ * {@link ViewPartPage} and its Viewer.
+ *
+ * @author cedric dumoulin
+ *
+ */
+public class ViewPageSite extends PageSite implements IViewSite {
+
+ /**
+ * Local copy.
+ */
+ private IViewSite parentViewSite;
+
+ /**
+ * Constructor.
+ *
+ * @param parentViewSite
+ */
+ public ViewPageSite(IViewSite parentViewSite) {
+ super(parentViewSite);
+ this.parentViewSite = parentViewSite;
+ }
+
+ /**
+ * @see org.eclipse.ui.IWorkbenchPartSite#getId()
+ *
+ * @return
+ */
+ public String getId() {
+ return parentViewSite.getId();
+ }
+
+ /**
+ * @see org.eclipse.ui.IWorkbenchPartSite#getPluginId()
+ *
+ * @return
+ */
+ public String getPluginId() {
+ return parentViewSite.getPluginId();
+ }
+
+ /**
+ * @see org.eclipse.ui.IWorkbenchPartSite#getRegisteredName()
+ *
+ * @return
+ */
+ public String getRegisteredName() {
+ // TODO Auto-generated method stub
+ return parentViewSite.getRegisteredName();
+ }
+
+ /**
+ * @see org.eclipse.ui.IWorkbenchPartSite#registerContextMenu(org.eclipse.jface.action.MenuManager, org.eclipse.jface.viewers.ISelectionProvider)
+ *
+ * @param menuManager
+ * @param selectionProvider
+ */
+ public void registerContextMenu(MenuManager menuManager, ISelectionProvider selectionProvider) {
+ parentViewSite.registerContextMenu(menuManager, selectionProvider);
+
+ }
+
+ /**
+ * @see org.eclipse.ui.IWorkbenchPartSite#getKeyBindingService()
+ *
+ * @return
+ * @deprecated
+ */
+ public IKeyBindingService getKeyBindingService() {
+ // TODO Auto-generated method stub
+ return parentViewSite.getKeyBindingService();
+ }
+
+ /**
+ * @see org.eclipse.ui.IWorkbenchPartSite#getPart()
+ *
+ * @return
+ */
+ public IWorkbenchPart getPart() {
+ return parentViewSite.getPart();
+ }
+
+ /**
+ * @see org.eclipse.ui.IViewSite#getSecondaryId()
+ *
+ * @return
+ */
+ public String getSecondaryId() {
+ return parentViewSite.getSecondaryId();
+ }
+
+}
diff --git a/plugins/views/modelexplorer/org.eclipse.papyrus.modelexplorer/src/org/eclipse/papyrus/core/ui/pagebookview/ViewPartPage.java b/plugins/views/modelexplorer/org.eclipse.papyrus.modelexplorer/src/org/eclipse/papyrus/core/ui/pagebookview/ViewPartPage.java
new file mode 100644
index 00000000000..934021c9510
--- /dev/null
+++ b/plugins/views/modelexplorer/org.eclipse.papyrus.modelexplorer/src/org/eclipse/papyrus/core/ui/pagebookview/ViewPartPage.java
@@ -0,0 +1,144 @@
+/*****************************************************************************
+ * Copyright (c) 2010 LIFL & CEA LIST.
+ *
+ *
+ * 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:
+ * Cedric Dumoulin (LIFL) cedric.dumoulin@lifl.fr - Initial API and implementation
+ *
+ *****************************************************************************/
+
+package org.eclipse.papyrus.core.ui.pagebookview;
+
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IAdaptable;
+import org.eclipse.core.runtime.IConfigurationElement;
+import org.eclipse.core.runtime.IExecutableExtension;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.ui.IMemento;
+import org.eclipse.ui.IViewPart;
+import org.eclipse.ui.IWorkbenchPart;
+import org.eclipse.ui.part.IPageSite;
+import org.eclipse.ui.part.Page;
+import org.eclipse.ui.part.ViewPart;
+
+
+/**
+ * A {@link Page} handling a {@link ViewPart} in a {@link MultiViewPageBookView}.
+ * Subclass must create the viewer in their constructor. The constructor take the part as argument.
+ * The constructor is called from a subclass of {@link MultiViewPageBookView}.
+ * Subclass should also implements the method getControl().
+ *
+ * @author cedric dumoulin
+ *
+ */
+public abstract class ViewPartPage extends Page implements IAdaptable {
+
+
+ /**
+ * The wrapped View
+ */
+ private IViewPart modelExplorer;
+
+ /**
+ * Constructor.
+ *
+ */
+ public ViewPartPage() {
+ }
+
+ /**
+ * Init the inner View
+ *
+ * @see org.eclipse.ui.part.Page#init(org.eclipse.ui.part.IPageSite)
+ *
+ * @param pageSite
+ */
+ @Override
+ public void init(IPageSite pageSite) {
+ // Not used.
+ super.init(pageSite);
+ }
+
+ /**
+ * @param viewPageSite
+ * @param memento
+ * @throws CoreException
+ */
+ public void init(IWorkbenchPart part, ViewPageSite viewPageSite, IMemento memento, IConfigurationElement cfig) throws CoreException {
+
+ // Call the original method to record the site
+ init(viewPageSite);
+
+ // ask to create the Viewer
+ modelExplorer = createViewer(part);
+
+ // Add the extension config if requested by the Viewer
+ if(modelExplorer instanceof IExecutableExtension) {
+ ((IExecutableExtension)modelExplorer).setInitializationData(cfig, null, null);
+ }
+ // Init the part
+ modelExplorer.init(viewPageSite, memento);
+ }
+
+ /**
+ * Create the viewer for this page. The Viewer is associated to the specified part.
+ *
+ * @param part
+ * The part associated to the Viewer.
+ *
+ * @return The Viewer to render in the page.
+ */
+ abstract protected IViewPart createViewer(IWorkbenchPart part);
+
+ /**
+ * Subclass must implement this method.
+ *
+ * @see org.eclipse.ui.part.Page#getControl()
+ *
+ * @return
+ */
+ @Override
+ abstract public Control getControl();
+
+ /**
+ * @see org.eclipse.ui.part.Page#setFocus()
+ *
+ */
+ @Override
+ public void setFocus() {
+ modelExplorer.setFocus();
+ }
+
+ /**
+ * Return the associated viewer
+ *
+ * @return
+ */
+ public IViewPart getViewer() {
+ return modelExplorer;
+ }
+
+ /**
+ * Forward to the
+ *
+ * @see org.eclipse.core.runtime.IAdaptable#getAdapter(java.lang.Class)
+ *
+ * @param adapter
+ * @return
+ */
+ @SuppressWarnings("rawtypes")
+ public Object getAdapter(Class adapter) {
+
+ if(modelExplorer instanceof IAdaptable)
+ return ((IAdaptable)modelExplorer).getAdapter(adapter);
+
+ // do nothing
+ return null;
+ }
+
+}
diff --git a/plugins/views/modelexplorer/org.eclipse.papyrus.modelexplorer/src/org/eclipse/papyrus/modelexplorer/Activator.java b/plugins/views/modelexplorer/org.eclipse.papyrus.modelexplorer/src/org/eclipse/papyrus/modelexplorer/Activator.java
new file mode 100644
index 00000000000..a2e5568e781
--- /dev/null
+++ b/plugins/views/modelexplorer/org.eclipse.papyrus.modelexplorer/src/org/eclipse/papyrus/modelexplorer/Activator.java
@@ -0,0 +1,263 @@
+/*****************************************************************************
+ * Copyright (c) 2010 CEA LIST.
+ *
+ *
+ * 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:
+ * Patrick Tessier (CEA LIST) Patrick.tessier@cea.fr - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.modelexplorer;
+
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
+import org.eclipse.core.runtime.FileLocator;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Path;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.emf.common.util.EList;
+import org.eclipse.emf.ecore.EClassifier;
+import org.eclipse.emf.ecore.EPackage;
+import org.eclipse.emf.edit.EMFEditPlugin;
+import org.eclipse.emf.facet.infra.browser.Messages;
+import org.eclipse.emf.facet.infra.browser.custom.MetamodelView;
+import org.eclipse.emf.facet.infra.browser.custom.TypeView;
+import org.eclipse.emf.facet.infra.browser.custom.core.CustomizationsCatalog;
+import org.eclipse.emf.facet.infra.browser.uicore.CustomizationManager;
+import org.eclipse.emf.facet.infra.facet.Facet;
+import org.eclipse.emf.facet.infra.facet.FacetSet;
+import org.eclipse.emf.facet.infra.facet.core.FacetSetCatalog;
+import org.eclipse.jface.resource.ImageDescriptor;
+import org.eclipse.osgi.util.NLS;
+import org.eclipse.papyrus.log.LogHelper;
+import org.eclipse.ui.plugin.AbstractUIPlugin;
+import org.osgi.framework.BundleContext;
+
+/**
+ * The activator class controls the plug-in life cycle
+ */
+@SuppressWarnings("restriction")
+public class Activator extends AbstractUIPlugin implements org.eclipse.ui.IStartup {
+
+ /** The plug-in ID */
+ public static final String PLUGIN_ID = "org.eclipse.papyrus.modelexplorer"; //$NON-NLS-1$
+
+ /** The plug-in shared instance */
+ private static Activator plugin;
+
+ /** The log service */
+ public static LogHelper log;
+
+ /** Default constructor */
+ public Activator() {
+ }
+
+ private CustomizationManager fCustomizationManager;
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * org.eclipse.ui.plugin.AbstractUIPlugin#start(org.osgi.framework.BundleContext
+ * )
+ */
+ public void start(BundleContext context) throws Exception {
+ super.start(context);
+ plugin = this;
+ log = new LogHelper(plugin);
+ EMFEditPlugin.getComposedAdapterFactoryDescriptorRegistry();
+
+ }
+
+ /**
+ * get the image descriptor from a string path
+ *
+ * @param pathString
+ * path of the image
+ * @return the image descriptor
+ */
+ public static ImageDescriptor getImageDescriptor(String pathString) {
+
+ IPath path = new Path(pathString);
+ URL uri = FileLocator.find(Activator.plugin.getBundle(), path, null);
+ if(uri == null) {
+ return null;
+ }
+ return ImageDescriptor.createFromURL(uri);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * org.eclipse.ui.plugin.AbstractUIPlugin#stop(org.osgi.framework.BundleContext
+ * )
+ */
+ public void stop(BundleContext context) throws Exception {
+ plugin = null;
+ super.stop(context);
+ }
+
+ /**
+ * Returns the shared instance
+ *
+ * @return the shared instance
+ */
+ public static Activator getDefault() {
+ return plugin;
+ }
+
+ /**
+ *
+ * @return the customization manager in charge to adapt element in modisco
+ */
+ public CustomizationManager getCustomizationManager() {
+ if(this.fCustomizationManager == null) {
+ this.fCustomizationManager = new CustomizationManager();
+ init(this.fCustomizationManager);
+ }
+ return this.fCustomizationManager;
+ }
+
+ private void init(final CustomizationManager customizationManager) {
+ // the appearance can be customized here:
+
+ customizationManager.setShowDerivedLinks(true);
+
+ try {
+
+ // load customizations defined as default through the customization
+ // extension
+ List<MetamodelView> registryDefaultCustomizations = CustomizationsCatalog.getInstance().getRegistryDefaultCustomizations();
+ for(MetamodelView metamodelView : registryDefaultCustomizations) {
+ customizationManager.registerCustomization(metamodelView);
+ }
+ customizationManager.loadCustomizations();
+ loadFacetsForCustomizations(registryDefaultCustomizations,customizationManager);
+
+ } catch (Throwable e) {
+ Activator.getDefault().getLog().log(new Status(IStatus.ERROR, Activator.PLUGIN_ID, "Error initializing customizations", e)); //$NON-NLS-1$
+ }
+ }
+
+ /**
+ * load the facets
+ *
+ * @param customizations
+ * list of customization
+ * @param customizationManager
+ * the Customization Manager
+ */
+ protected void loadFacetsForCustomizations(
+ final List<MetamodelView> customizations,
+ final CustomizationManager customizationManager) {
+ final Set<Facet> referencedFacets = new HashSet<Facet>();
+ final Collection<FacetSet> facetSets = FacetSetCatalog.getSingleton()
+ .getAllFacetSets();
+
+ for (MetamodelView customization : customizations) {
+ String metamodelURI = customization.getMetamodelURI();
+ // find customized FacetSet
+ FacetSet customizedFacetSet = null;
+ if (metamodelURI != null) {
+ for (FacetSet facetSet : facetSets) {
+ if (metamodelURI.equals(facetSet.getNsURI())) {
+ customizedFacetSet = facetSet;
+ break;
+ }
+ }
+ }
+ if (customizedFacetSet == null) {
+ continue;
+ }
+
+ // find customized Facets
+ EList<TypeView> types = customization.getTypes();
+ for (TypeView typeView : types) {
+ String metaclassName = typeView.getMetaclassName();
+ Facet facet = findFacetWithFullyQualifiedName(metaclassName,
+ customizedFacetSet);
+ if (facet != null) {
+ referencedFacets.add(facet);
+ } else {
+ Activator.log.warn(NLS
+ .bind(
+ Messages.BrowserActionBarContributor_missingRequiredFacet,
+ new Object[] {
+ metaclassName,
+ customizedFacetSet
+ .getName(),
+ customization.getName() }));
+ }
+ }
+
+ for (Facet referencedFacet : referencedFacets) {
+ customizationManager.loadFacet(referencedFacet);
+ }
+ }
+
+ //
+ // for modified facets
+ // customizationManager.getInstancesForMetaclasses().buildDerivationTree();
+ // customizationManager.getAppearanceConfiguration().touch();
+ // customizationManager.refreshDelayed(true);
+ }
+ /**
+ * fin a facet from
+ *
+ * @param metaclassName
+ * @param customizedFacetSet
+ * @return
+ */
+ private Facet findFacetWithFullyQualifiedName(final String metaclassName,
+ final FacetSet customizedFacetSet) {
+ EList<Facet> facets = customizedFacetSet.getFacets();
+ for (Facet facet : facets) {
+ String facetName = getMetaclassQualifiedName(facet);
+ if (metaclassName.equals(facetName)) {
+ return facet;
+ }
+ }
+ return null;
+ }
+
+ /** @return the qualified name of the given metaclass */
+ public static String getMetaclassQualifiedName(final EClassifier eClass) {
+ final ArrayList<String> qualifiedNameParts = new ArrayList<String>();
+ final StringBuilder builder = new StringBuilder();
+
+ EPackage ePackage = eClass.getEPackage();
+ while (ePackage != null) {
+ qualifiedNameParts.add(ePackage.getName());
+ ePackage = ePackage.getESuperPackage();
+ }
+
+ for (int i = qualifiedNameParts.size() - 1; i >= 0; i--) {
+ builder.append(qualifiedNameParts.get(i) + "."); //$NON-NLS-1$
+ }
+
+ builder.append(eClass.getName());
+
+ return builder.toString();
+ }
+
+ /**
+ *
+ * @see org.eclipse.ui.IStartup#earlyStartup()
+ *
+ */
+ public void earlyStartup() {
+
+ }
+
+}
diff --git a/plugins/views/modelexplorer/org.eclipse.papyrus.modelexplorer/src/org/eclipse/papyrus/modelexplorer/CommandContext.java b/plugins/views/modelexplorer/org.eclipse.papyrus.modelexplorer/src/org/eclipse/papyrus/modelexplorer/CommandContext.java
new file mode 100644
index 00000000000..7c4a493ba0c
--- /dev/null
+++ b/plugins/views/modelexplorer/org.eclipse.papyrus.modelexplorer/src/org/eclipse/papyrus/modelexplorer/CommandContext.java
@@ -0,0 +1,52 @@
+/*****************************************************************************
+ * Copyright (c) 2011 CEA LIST.
+ *
+ * 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:
+ *
+ * CEA LIST - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.modelexplorer;
+
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.ecore.EReference;
+
+/**
+ * Context holder for model element creation commands.
+ */
+public class CommandContext implements ICommandContext {
+
+ private EObject container;
+
+ private EReference reference;
+
+ /** Constructor */
+ public CommandContext(EObject container) {
+ this.container = container;
+ }
+
+ /** Constructor */
+ public CommandContext(EObject container, EReference reference) {
+ this.container = container;
+ this.reference = reference;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public EObject getContainer() {
+ return container;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public EReference getReference() {
+ return reference;
+ }
+}
diff --git a/plugins/views/modelexplorer/org.eclipse.papyrus.modelexplorer/src/org/eclipse/papyrus/modelexplorer/CustomCommonViewer.java b/plugins/views/modelexplorer/org.eclipse.papyrus.modelexplorer/src/org/eclipse/papyrus/modelexplorer/CustomCommonViewer.java
new file mode 100644
index 00000000000..4c48bb62466
--- /dev/null
+++ b/plugins/views/modelexplorer/org.eclipse.papyrus.modelexplorer/src/org/eclipse/papyrus/modelexplorer/CustomCommonViewer.java
@@ -0,0 +1,61 @@
+/*****************************************************************************
+ * Copyright (c) 2010 CEA LIST.
+ *
+ *
+ * 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:
+ * Patrick Tessier (CEA LIST) Patrick.tessier@cea.fr - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.modelexplorer;
+
+import org.eclipse.swt.dnd.DND;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.ui.internal.navigator.dnd.NavigatorDnDService;
+import org.eclipse.ui.navigator.CommonDragAdapter;
+import org.eclipse.ui.navigator.CommonDropAdapter;
+import org.eclipse.ui.navigator.CommonViewer;
+/**
+ * this class was created in order to access to the drop adapter
+ *
+ */
+@SuppressWarnings("restriction")
+public class CustomCommonViewer extends CommonViewer {
+ protected CommonDropAdapter dropAdapter;
+
+ public CustomCommonViewer(String aViewerId, Composite aParent, int aStyle) {
+ super(aViewerId, aParent, aStyle);
+ // TODO Auto-generated constructor stub
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ protected void initDragAndDrop() {
+ dropAdapter=null;
+ int operations = DND.DROP_COPY | DND.DROP_MOVE | DND.DROP_LINK;
+
+ CommonDragAdapter dragAdapter = createDragAdapter();
+ addDragSupport(operations, dragAdapter.getSupportedDragTransfers(),
+ dragAdapter);
+ dropAdapter = createDropAdapter();
+ addDropSupport(operations, dropAdapter.getSupportedDropTransfers(),
+ dropAdapter);
+
+ NavigatorDnDService dnd = (NavigatorDnDService)getNavigatorContentService().getDnDService();
+ dnd.setDropAdaptor(dropAdapter);
+ }
+
+ /**
+ * get the listener in order to parameterize during the runtime the drop
+ * @return the dropadapter
+ */
+ public CommonDropAdapter getDropAdapter() {
+ return dropAdapter;
+ }
+
+}
diff --git a/plugins/views/modelexplorer/org.eclipse.papyrus.modelexplorer/src/org/eclipse/papyrus/modelexplorer/ICommandContext.java b/plugins/views/modelexplorer/org.eclipse.papyrus.modelexplorer/src/org/eclipse/papyrus/modelexplorer/ICommandContext.java
new file mode 100644
index 00000000000..4923c8a7c04
--- /dev/null
+++ b/plugins/views/modelexplorer/org.eclipse.papyrus.modelexplorer/src/org/eclipse/papyrus/modelexplorer/ICommandContext.java
@@ -0,0 +1,37 @@
+/*****************************************************************************
+ * Copyright (c) 2011 CEA LIST.
+ *
+ * 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:
+ *
+ * CEA LIST - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.modelexplorer;
+
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.ecore.EReference;
+
+/**
+ * Interface for creation command context holder.
+ */
+public interface ICommandContext {
+
+ /**
+ * Get the container of the created element.
+ *
+ * @return the container.
+ */
+ public EObject getContainer();
+
+ /**
+ * Get the reference the created element relates.
+ *
+ * @return the EReference.
+ */
+ public EReference getReference();
+}
diff --git a/plugins/views/modelexplorer/org.eclipse.papyrus.modelexplorer/src/org/eclipse/papyrus/modelexplorer/ICommandFilter.java b/plugins/views/modelexplorer/org.eclipse.papyrus.modelexplorer/src/org/eclipse/papyrus/modelexplorer/ICommandFilter.java
new file mode 100644
index 00000000000..fa0ebfd10f0
--- /dev/null
+++ b/plugins/views/modelexplorer/org.eclipse.papyrus.modelexplorer/src/org/eclipse/papyrus/modelexplorer/ICommandFilter.java
@@ -0,0 +1,32 @@
+/*****************************************************************************
+ * Copyright (c) 2011 CEA LIST.
+ *
+ * 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:
+ *
+ * CEA LIST - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.modelexplorer;
+
+import java.util.List;
+
+import org.eclipse.gmf.runtime.emf.type.core.IElementType;
+
+/**
+ * Interface for creation command filter.
+ */
+public interface ICommandFilter {
+
+ /**
+ * Get the list of element type for which the creation command is visible.
+ *
+ * @return the list of allowed element types.
+ */
+ public List<IElementType> getVisibleCommands();
+
+}
diff --git a/plugins/views/modelexplorer/org.eclipse.papyrus.modelexplorer/src/org/eclipse/papyrus/modelexplorer/ITooltip.java b/plugins/views/modelexplorer/org.eclipse.papyrus.modelexplorer/src/org/eclipse/papyrus/modelexplorer/ITooltip.java
new file mode 100644
index 00000000000..0e14e56ffd7
--- /dev/null
+++ b/plugins/views/modelexplorer/org.eclipse.papyrus.modelexplorer/src/org/eclipse/papyrus/modelexplorer/ITooltip.java
@@ -0,0 +1,67 @@
+package org.eclipse.papyrus.modelexplorer;
+
+import org.eclipse.jface.viewers.CellLabelProvider;
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.swt.graphics.Point;
+
+/**
+ * Interface containing operations from {@Link org.eclipse.jface.viewers.CellLabelProvider}
+ * It's a design fault that no interface has been defined by jface in the first place.
+ *
+ * @author ansgar
+ *
+ */
+public interface ITooltip {
+ /**
+ * @see CellLabelProvider
+ *
+ * @param object
+ * the element for which the tool tip is shown
+ * @return {@link Image} or <code>null</code> if there is not image.
+ */
+
+ public Image getToolTipImage(Object object);
+
+ /**
+ * @see CellLabelProvider
+ *
+ *
+ * @param element
+ * the element for which the tool tip is shown
+ * @return the {@link String} or <code>null</code> if there is not text to
+ * display
+ */
+ public String getToolTipText(Object element);
+
+ /**
+ * Return the amount of pixels in x and y direction you want the tool tip to
+ * pop up from the mouse pointer. The default shift is 10px right and 0px
+ * below your mouse cursor. Be aware of the fact that you should at least
+ * position the tool tip 1px right to your mouse cursor else click events
+ * may not get propagated properly.
+ *
+ * @param object
+ * the element for which the tool tip is shown
+ * @return {@link Point} to shift of the tool tip or <code>null</code> if the
+ * default shift should be used.
+ */
+ public Point getToolTipShift(Object object);
+
+ /**
+ * The time in milliseconds the tool tip is shown for.
+ *
+ * @param object
+ * the {@link Object} for which the tool tip is shown
+ * @return time in milliseconds the tool tip is shown for
+ */
+ public int getToolTipTimeDisplayed(Object object);
+
+ /**
+ * The time in milliseconds until the tool tip is displayed.
+ *
+ * @param object
+ * the {@link Object} for which the tool tip is shown
+ * @return time in milliseconds until the tool tip is displayed
+ */
+ public int getToolTipDisplayDelayTime(Object object);
+}
diff --git a/plugins/views/modelexplorer/org.eclipse.papyrus.modelexplorer/src/org/eclipse/papyrus/modelexplorer/LinkHelper.java b/plugins/views/modelexplorer/org.eclipse.papyrus.modelexplorer/src/org/eclipse/papyrus/modelexplorer/LinkHelper.java
new file mode 100644
index 00000000000..c379d744849
--- /dev/null
+++ b/plugins/views/modelexplorer/org.eclipse.papyrus.modelexplorer/src/org/eclipse/papyrus/modelexplorer/LinkHelper.java
@@ -0,0 +1,100 @@
+/*****************************************************************************
+ * Copyright (c) 2010 CEA LIST.
+ *
+ *
+ * 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:
+ * Patrick Tessier (CEA LIST) Patrick.tessier@cea.fr - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.modelexplorer;
+
+import java.util.ArrayList;
+import java.util.Iterator;
+
+import org.eclipse.core.runtime.IAdaptable;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.gmf.runtime.gef.ui.internal.figures.DiamondFigure;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.jface.viewers.ITreeSelection;
+import org.eclipse.papyrus.core.editor.IMultiDiagramEditor;
+import org.eclipse.papyrus.core.ui.IRevealSemanticElement;
+import org.eclipse.papyrus.core.utils.EditorUtils;
+import org.eclipse.papyrus.core.utils.ServiceUtils;
+import org.eclipse.papyrus.sasheditor.editor.ISashWindowsContainer;
+import org.eclipse.ui.IEditorInput;
+import org.eclipse.ui.IEditorPart;
+import org.eclipse.ui.ISelectionService;
+import org.eclipse.ui.IWorkbenchPage;
+import org.eclipse.ui.navigator.ILinkHelper;
+/**
+ * This class is to link form the model explorer to diagram
+ * This code was to not put in the model explorer in order to avoid dependences with gmf in the more abstract explorer
+ *
+ */
+
+public class LinkHelper implements ILinkHelper {
+ /**
+ *
+ * @see org.eclipse.ui.navigator.ILinkHelper#findSelection(org.eclipse.ui.IEditorInput)
+ *
+ */
+ public IStructuredSelection findSelection(IEditorInput anInput) {
+ return null;
+ }
+ /**
+ *
+ * @see org.eclipse.ui.navigator.ILinkHelper#activateEditor(org.eclipse.ui.IWorkbenchPage, org.eclipse.jface.viewers.IStructuredSelection)
+ *
+ */
+ public void activateEditor(IWorkbenchPage aPage, IStructuredSelection aSelection) {
+ //no selection
+ if (aSelection == null || aSelection.isEmpty())
+ return;
+ ISelectionService selectService=aPage.getWorkbenchWindow().getSelectionService();
+ ISelection selection=selectService.getSelection();
+
+ //test if the selection come the tree viewer in order to avoid cycle: Diagram -> tree-> diagram
+ // if the diagram has been selected the selection is not a TreeSelection
+ if( selection instanceof ITreeSelection){
+ IMultiDiagramEditor papyrusEditor=EditorUtils.getMultiDiagramEditor();
+
+
+ try {
+ ISashWindowsContainer windowsContainer=ServiceUtils.getInstance().getISashWindowsContainer(papyrusEditor.getServicesRegistry());
+
+ Iterator<IEditorPart>iterPart=windowsContainer.getVisibleIEditorParts().iterator();
+
+ while(iterPart.hasNext()){
+ IEditorPart diagramEditor=iterPart.next();
+ if (diagramEditor instanceof IRevealSemanticElement){
+ if( aSelection instanceof IStructuredSelection){
+ Iterator<?> selectionIterator=((IStructuredSelection)aSelection).iterator();
+ ArrayList<Object> semanticElementList= new ArrayList<Object>();
+ while(selectionIterator.hasNext()) {
+ Object currentSelection = (Object)selectionIterator.next();
+ if( currentSelection instanceof IAdaptable){
+ Object semanticElement=((IAdaptable)currentSelection).getAdapter(EObject.class);
+ if( semanticElement!=null){
+ semanticElementList.add(semanticElement);
+ }
+ }
+
+ }
+ ((IRevealSemanticElement)diagramEditor).revealSemanticElement(semanticElementList);
+ }
+ }
+ }
+ } catch (Exception e) {
+ Activator.log.error("Impossible to acces to windows Container", e);
+ }
+ }
+ }
+
+
+}
diff --git a/plugins/views/modelexplorer/org.eclipse.papyrus.modelexplorer/src/org/eclipse/papyrus/modelexplorer/Messages.java b/plugins/views/modelexplorer/org.eclipse.papyrus.modelexplorer/src/org/eclipse/papyrus/modelexplorer/Messages.java
new file mode 100644
index 00000000000..d87a28021a5
--- /dev/null
+++ b/plugins/views/modelexplorer/org.eclipse.papyrus.modelexplorer/src/org/eclipse/papyrus/modelexplorer/Messages.java
@@ -0,0 +1,16 @@
+package org.eclipse.papyrus.modelexplorer;
+
+import org.eclipse.osgi.util.NLS;
+
+public class Messages extends NLS {
+ private static final String BUNDLE_NAME = "org.eclipse.papyrus.modelexplorer.messages"; //$NON-NLS-1$
+ public static String DoubleClickListener_Error_NoLoadManagerToOpen;
+ public static String MoDiscoLabelProvider_ProxyLabel;
+ static {
+ // initialize resource bundle
+ NLS.initializeMessages(BUNDLE_NAME, Messages.class);
+ }
+
+ private Messages() {
+ }
+}
diff --git a/plugins/views/modelexplorer/org.eclipse.papyrus.modelexplorer/src/org/eclipse/papyrus/modelexplorer/MoDiscoContentProvider.java b/plugins/views/modelexplorer/org.eclipse.papyrus.modelexplorer/src/org/eclipse/papyrus/modelexplorer/MoDiscoContentProvider.java
new file mode 100644
index 00000000000..270c67b62b7
--- /dev/null
+++ b/plugins/views/modelexplorer/org.eclipse.papyrus.modelexplorer/src/org/eclipse/papyrus/modelexplorer/MoDiscoContentProvider.java
@@ -0,0 +1,156 @@
+/*******************************************************************************
+ * Copyright (c) 2010 Mia-Software.
+ * 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:
+ * Nicolas Bros (Mia-Software) - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.papyrus.modelexplorer;
+
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+import org.eclipse.core.runtime.IAdaptable;
+import org.eclipse.emf.common.util.EList;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.facet.infra.browser.uicore.CustomizableModelContentProvider;
+import org.eclipse.gmf.runtime.notation.Diagram;
+import org.eclipse.papyrus.core.services.ServicesRegistry;
+import org.eclipse.papyrus.resource.ModelSet;
+import org.eclipse.papyrus.resource.ModelUtils;
+import org.eclipse.papyrus.resource.uml.UmlModel;
+import org.eclipse.papyrus.resource.uml.UmlUtils;
+import org.eclipse.papyrus.sasheditor.contentprovider.IPageMngr;
+import org.eclipse.papyrus.sasheditor.contentprovider.di.DiSashModelMngr;
+
+/**
+ * the content provider that inherits of modisco properties
+ */
+public class MoDiscoContentProvider extends CustomizableModelContentProvider {
+
+ /** The ModelSet containing all the models. This is the initial input. */
+ protected ModelSet modelSet;
+
+ /** The list of open pages (diagrams) */
+ protected IPageMngr pageMngr;
+
+ /**
+ * Creates a new MoDiscoContentProvider.
+ */
+ public MoDiscoContentProvider() {
+ super(Activator.getDefault().getCustomizationManager());
+ }
+
+ @Override
+ public boolean hasChildren(Object element) {
+ return getChildren(element).length > 0;
+ }
+
+ @Override
+ public Object[] getChildren(final Object parentElement) {
+ ArrayList<Object> result = new ArrayList<Object>();
+
+ Object[] arrayObject = super.getChildren(parentElement);
+ if(arrayObject != null) {
+ for(int i = 0; i < arrayObject.length; i++) {
+ result.add(arrayObject[i]);
+ }
+ }
+ /**
+ * Refactoring with bug 358732
+ */
+ //
+ // if (parentElement instanceof IAdaptable) {
+ // EObject eObject = (EObject)((IAdaptable)parentElement).getAdapter(EObject.class);
+ // if(eObject !=null) {
+ // List<Diagram> diagramList = findAllExistingDiagrams(eObject);
+ // Iterator<Diagram> iterator = diagramList.iterator();
+ // while (iterator.hasNext()) {
+ // result.add(iterator.next());
+ // }
+ // }
+ //
+ // }
+
+ return result.toArray();
+ }
+
+ /**
+ * @param owner
+ * the owner of the diagrams
+ * @return the list of diagrams contained by the given owner
+ */
+ private List<Diagram> findAllExistingDiagrams(EObject owner) {
+ ArrayList<Diagram> diagrams = new ArrayList<Diagram>();
+
+ // Walk on page (Diagram) references
+ for(Object page : pageMngr.allPages()) {
+ if(!(page instanceof Diagram)) {
+ continue;
+ }
+ // We have a GMF Diagram
+ Diagram diagram = (Diagram)page;
+ if(owner.equals(diagram.getElement())) {
+ diagrams.add(diagram);
+ }
+
+ }
+
+ return diagrams;
+ }
+
+ /**
+ * Return the initial values from the input.
+ * Input should be of type {@link UmlModel}.
+ *
+ * @see org.eclipse.gmt.modisco.infra.browser.uicore.CustomizableModelContentProvider#getRootElements(java.lang.Object)
+ *
+ * @param inputElement
+ * @return
+ */
+ @Override
+ public EObject[] getRootElements(Object inputElement) {
+
+ try {
+ if(!(inputElement instanceof ServicesRegistry)) {
+ return null;
+ }
+
+ ServicesRegistry servicesRegistry = (ServicesRegistry)inputElement;
+
+ modelSet = ModelUtils.getModelSetChecked(servicesRegistry);
+ pageMngr = servicesRegistry.getService(DiSashModelMngr.class).getIPageMngr();
+
+ return getRootElements(modelSet);
+ } catch (Exception e) {
+ Activator.log.error(e);
+ }
+
+ return new EObject[0];
+ }
+
+ /**
+ * Get the roots elements from the {@link ModelSet} provided as input.
+ *
+ * @return
+ */
+ protected EObject[] getRootElements(ModelSet modelSet) {
+ UmlModel umlModel = (UmlUtils.getUmlModel(modelSet));
+
+ if(umlModel == null)
+ return null;
+
+ EList<EObject> contents = umlModel.getResource().getContents();
+ ArrayList<EObject> result = new ArrayList<EObject>();
+ Iterator<EObject> iterator = contents.iterator();
+ while(iterator.hasNext()) {
+ EObject eObject = (EObject)iterator.next();
+ result.add(eObject);
+ }
+ return result.toArray(new EObject[result.size()]);
+ }
+}
diff --git a/plugins/views/modelexplorer/org.eclipse.papyrus.modelexplorer/src/org/eclipse/papyrus/modelexplorer/MoDiscoLabelProvider.java b/plugins/views/modelexplorer/org.eclipse.papyrus.modelexplorer/src/org/eclipse/papyrus/modelexplorer/MoDiscoLabelProvider.java
new file mode 100644
index 00000000000..df442baa8ee
--- /dev/null
+++ b/plugins/views/modelexplorer/org.eclipse.papyrus.modelexplorer/src/org/eclipse/papyrus/modelexplorer/MoDiscoLabelProvider.java
@@ -0,0 +1,183 @@
+/*****************************************************************************
+ * Copyright (c) 2010 CEA LIST.
+ *
+ *
+ * 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:
+ * Patrick Tessier (CEA LIST) Patrick.tessier@cea.fr - Initial API and implementation
+ * Emilien Perico (Atos Origin) emilien.perico@atosorigin.com - Initial API and implementation
+ * Amine EL KOUHEN (CEA LIST/LIFL) - Added the decorator Factory
+ *****************************************************************************/
+package org.eclipse.papyrus.modelexplorer;
+
+import org.eclipse.core.runtime.IAdaptable;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.ecore.InternalEObject;
+import org.eclipse.emf.facet.infra.browser.uicore.CustomizableModelLabelProvider;
+import org.eclipse.gmf.runtime.notation.Diagram;
+import org.eclipse.jface.resource.ImageDescriptor;
+import org.eclipse.osgi.util.NLS;
+import org.eclipse.papyrus.core.editorsfactory.IPageIconsRegistry;
+import org.eclipse.papyrus.core.editorsfactory.PageIconsRegistry;
+import org.eclipse.papyrus.core.services.ServiceException;
+import org.eclipse.papyrus.core.ui.pagebookview.ModelExplorerDecorationAdapter;
+import org.eclipse.papyrus.core.utils.EditorUtils;
+import org.eclipse.papyrus.decoration.DecorationService;
+import org.eclipse.papyrus.decoration.util.Decoration.PreferedPosition;
+import org.eclipse.papyrus.decoration.util.IDecoration;
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.ui.ISharedImages;
+import org.eclipse.ui.PlatformUI;
+
+/**
+ * the label provider that inherits of modisco label provider.
+ */
+public class MoDiscoLabelProvider extends CustomizableModelLabelProvider {
+
+ /** icon registry. */
+ private IPageIconsRegistry editorRegistry;
+
+ /** Decoration Service *. */
+ private DecorationService decorationService;
+
+ /**
+ * Creates a new MoDiscoLabelProvider.
+ */
+ public MoDiscoLabelProvider() {
+ super(Activator.getDefault().getCustomizationManager());
+ try {
+ decorationService = EditorUtils.getServiceRegistry().getService(DecorationService.class);
+ /* OR : decorationService = ServiceUtilsForActionHandlers.getInstance().getServiceRegistry().getService(DecorationService.class); */
+ } catch (ServiceException ex) {
+ Activator.log.error(ex);
+ }
+
+ }
+
+ /**
+ * Returns the message of the marker for the specified element.
+ *
+ * @param element
+ * the element for which the marker message should be found
+ * @return the message of the marker for the specified element
+ */
+ public String getMarkerMessage(Object element) {
+ return decorationService.getDecoration(element, false).getMessage();
+ }
+
+ /**
+ * return the image of an element in the model browser
+ * evaluates error markers.
+ *
+ * @param element
+ * the element
+ * @return the image
+ */
+ @Override
+ public Image getImage(Object element) {
+
+ // Get the Model Explorer Adapter
+ ModelExplorerDecorationAdapter adapter = new ModelExplorerDecorationAdapter(null);
+
+
+ //Set the decoration target
+ /**
+ * Useless since EMF Facet integration with bug 358732
+ */
+ if(element instanceof Diagram)
+ adapter.setDecoratorTarget(getEditorRegistry().getEditorIcon(element));
+ else
+ adapter.setDecoratorTarget(super.getImage(element));
+
+ //Set the decoration with default position
+ IDecoration decoration = decorationService.getDecoration(element, true);
+ decoration.setDecorationImage(getImageDescriptor(decoration.getSeverity()));
+ adapter.setDecoration(decoration.getDecorationImage(), PreferedPosition.DEFAULT);
+
+ //return the target decorated
+ return adapter.getDecoratedImage();
+
+ }
+
+ /**
+ * Gets the image descriptor from severity.
+ *
+ * @param severity
+ * the severity
+ * @return the image descriptor
+ */
+ private ImageDescriptor getImageDescriptor(int severity) {
+
+ ISharedImages sharedImages = PlatformUI.getWorkbench().getSharedImages();
+ ImageDescriptor overlay = null;
+ switch(severity) {
+ case 2://Error
+ overlay = sharedImages.getImageDescriptor(ISharedImages.IMG_DEC_FIELD_ERROR);
+ break;
+ case 1://Warning
+ overlay = sharedImages.getImageDescriptor(ISharedImages.IMG_DEC_FIELD_WARNING);
+ break;
+ }
+
+ return overlay;
+ }
+
+ /**
+ * Get the EditorRegistry used to create editor instances. This default
+ * implementation return the singleton eINSTANCE. This method can be
+ * subclassed to return another registry.
+ *
+ * @return the singleton eINSTANCE of editor registry
+ */
+ protected IPageIconsRegistry getEditorRegistry() {
+ if(editorRegistry == null) {
+ editorRegistry = createEditorRegistry();
+ }
+ return editorRegistry;
+ }
+
+ /**
+ * Return the EditorRegistry for nested editor descriptors. Subclass should
+ * implements this method in order to return the registry associated to the
+ * extension point namespace.
+ *
+ * @return the EditorRegistry for nested editor descriptors
+ */
+ protected IPageIconsRegistry createEditorRegistry() {
+ try {
+ return EditorUtils.getServiceRegistry().getService(IPageIconsRegistry.class);
+ } catch (ServiceException e) {
+ // Not found, return an empty one which return null for each
+ // request.
+ return new PageIconsRegistry();
+ }
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public String getText(Object element) {
+ String text = null;
+ if(element instanceof Diagram) {
+ Diagram diagram = (Diagram)element;
+ text = diagram.getName();
+ } else if(element instanceof IAdaptable) {
+ EObject obj = (EObject)((IAdaptable)element).getAdapter(EObject.class);
+ if(obj instanceof InternalEObject && obj.eIsProxy()) {
+ InternalEObject internal = (InternalEObject)obj;
+ text = NLS.bind(Messages.MoDiscoLabelProvider_ProxyLabel, obj.getClass().getSimpleName(), internal.eProxyURI().trimFragment());
+ // Messages.MoDiscoLabelProvider_0 + + Messages.MoDiscoLabelProvider_1 + ;;
+ } else {
+ text = super.getText(element);
+ }
+ } else {
+ text = super.getText(element);
+ }
+ return text;
+ }
+}
diff --git a/plugins/views/modelexplorer/org.eclipse.papyrus.modelexplorer/src/org/eclipse/papyrus/modelexplorer/MoDiscoLabelProviderWTooltips.java b/plugins/views/modelexplorer/org.eclipse.papyrus.modelexplorer/src/org/eclipse/papyrus/modelexplorer/MoDiscoLabelProviderWTooltips.java
new file mode 100644
index 00000000000..85a72ae406a
--- /dev/null
+++ b/plugins/views/modelexplorer/org.eclipse.papyrus.modelexplorer/src/org/eclipse/papyrus/modelexplorer/MoDiscoLabelProviderWTooltips.java
@@ -0,0 +1,92 @@
+/*****************************************************************************
+ * Copyright (c) 2010 CEA LIST.
+ *
+ *
+ * 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:
+ * Ansgar Radermacher (CEA LIST) ansgar.radermacher@cea.fr - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.modelexplorer;
+
+import org.eclipse.jface.viewers.ColumnLabelProvider;
+import org.eclipse.swt.graphics.Color;
+import org.eclipse.swt.graphics.Font;
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.swt.graphics.Point;
+
+/**
+ * the label provider that inherits of modisco label provider
+ *
+ */
+public class MoDiscoLabelProviderWTooltips extends ColumnLabelProvider {
+
+ private MoDiscoLabelProvider moDiscoLP;
+
+ public MoDiscoLabelProviderWTooltips() {
+ moDiscoLP = new MoDiscoLabelProvider ();
+ }
+
+ @Override
+ public String getToolTipText(Object element) {
+ return moDiscoLP.getMarkerMessage(element);
+ }
+
+ @Override
+ public Point getToolTipShift(Object object) {
+ return new Point(5, 5);
+ }
+
+ @Override
+ public int getToolTipDisplayDelayTime(Object object) {
+ return 1000;
+ }
+
+ @Override
+ public int getToolTipTimeDisplayed(Object object) {
+ return 10000;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.jface.viewers.IFontProvider#getFont(java.lang.Object)
+ */
+ public Font getFont(Object element) {
+ return moDiscoLP.getFont(element);
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.jface.viewers.IColorProvider#getBackground(java.lang.Object)
+ */
+ public Color getBackground(Object element) {
+ return moDiscoLP.getBackground(element);
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.jface.viewers.IColorProvider#getForeground(java.lang.Object)
+ */
+ public Color getForeground(Object element) {
+ return moDiscoLP.getForeground(element);
+ }
+
+
+ /**
+ * return the image of an element in the model browser
+ * evaluates error markers.
+ */
+ @Override
+ public Image getImage(Object element) {
+ return moDiscoLP.getImage(element);
+ }
+
+ /**
+ * @see org.eclipse.gmt.modisco.infra.browser.uicore.CustomizableModelLabelProvider#getText(java.lang.Object)
+ */
+ @Override
+ public String getText(Object element) {
+ return moDiscoLP.getText(element);
+ }
+}
diff --git a/plugins/views/modelexplorer/org.eclipse.papyrus.modelexplorer/src/org/eclipse/papyrus/modelexplorer/ModelExplorerPage.java b/plugins/views/modelexplorer/org.eclipse.papyrus.modelexplorer/src/org/eclipse/papyrus/modelexplorer/ModelExplorerPage.java
new file mode 100644
index 00000000000..c81c1988981
--- /dev/null
+++ b/plugins/views/modelexplorer/org.eclipse.papyrus.modelexplorer/src/org/eclipse/papyrus/modelexplorer/ModelExplorerPage.java
@@ -0,0 +1,75 @@
+/*****************************************************************************
+ * Copyright (c) 2010 LIFL & CEA LIST.
+ *
+ *
+ * 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:
+ * Cedric Dumoulin (LIFL) cedric.dumoulin@lifl.fr - Initial API and implementation
+ *
+ *****************************************************************************/
+
+package org.eclipse.papyrus.modelexplorer;
+
+import org.eclipse.papyrus.core.editor.IMultiDiagramEditor;
+import org.eclipse.papyrus.core.ui.pagebookview.ViewPartPage;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.ui.IViewPart;
+import org.eclipse.ui.IWorkbenchPart;
+
+
+/**
+ * Page handling the {@link ModelExplorerView} for the {@link ModelExplorerPageBookView}
+ * @author cedric dumoulin
+ *
+ */
+public class ModelExplorerPage extends ViewPartPage {
+
+ /**
+ * Constructor.
+ *
+ * @param part
+ */
+ public ModelExplorerPage() {
+ }
+
+ /**
+ * Create the Viewer for the requested part
+ * @param part The part to associate to the Viewer.
+ * @return
+ */
+ protected IViewPart createViewer(IWorkbenchPart part) {
+
+ // Part is of the right type because of call to isImportant()
+ return new ModelExplorerView((IMultiDiagramEditor)part);
+ }
+
+ /**
+ * Create control of the inner view
+ * @see org.eclipse.ui.part.Page#createControl(org.eclipse.swt.widgets.Composite)
+ *
+ * @param parent
+ */
+ @Override
+ public void createControl(Composite parent) {
+
+ getViewer().createPartControl(parent);
+ }
+
+ /**
+ * Return the control
+ *
+ * @see org.eclipse.papyrus.core.ui.pagebookview.ViewPartPage#getControl()
+ *
+ * @return
+ */
+ @Override
+ public Control getControl() {
+ return ((ModelExplorerView)getViewer()).getControl();
+ }
+
+}
diff --git a/plugins/views/modelexplorer/org.eclipse.papyrus.modelexplorer/src/org/eclipse/papyrus/modelexplorer/ModelExplorerPageBookView.java b/plugins/views/modelexplorer/org.eclipse.papyrus.modelexplorer/src/org/eclipse/papyrus/modelexplorer/ModelExplorerPageBookView.java
new file mode 100644
index 00000000000..323604b38bd
--- /dev/null
+++ b/plugins/views/modelexplorer/org.eclipse.papyrus.modelexplorer/src/org/eclipse/papyrus/modelexplorer/ModelExplorerPageBookView.java
@@ -0,0 +1,169 @@
+/*****************************************************************************
+ * Copyright (c) 2010 LIFL & CEA LIST.
+ *
+ *
+ * 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:
+ * Cedric Dumoulin (LIFL) cedric.dumoulin@lifl.fr - Initial API and implementation
+ * Ansgar Radermacher (CEA) ansgar.radermacher@cea.fr - Added support for IGotoMarker
+ *
+ *****************************************************************************/
+
+package org.eclipse.papyrus.modelexplorer;
+
+import static org.eclipse.papyrus.core.Activator.log;
+
+import java.util.LinkedList;
+
+import org.eclipse.core.resources.IMarker;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.Platform;
+import org.eclipse.emf.common.util.URI;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.ecore.EValidator;
+import org.eclipse.emf.edit.domain.EditingDomain;
+import org.eclipse.jface.viewers.ITreeContentProvider;
+import org.eclipse.jface.viewers.TreePath;
+import org.eclipse.jface.viewers.TreeSelection;
+import org.eclipse.jface.viewers.TreeViewer;
+import org.eclipse.papyrus.core.ui.pagebookview.MultiViewPageBookView;
+import org.eclipse.papyrus.core.ui.pagebookview.ViewPartPage;
+import org.eclipse.ui.IViewPart;
+import org.eclipse.ui.IWorkbenchPart;
+import org.eclipse.ui.ide.IGotoMarker;
+import org.eclipse.ui.navigator.CommonViewer;
+import org.eclipse.ui.views.properties.IPropertySheetPage;
+import org.eclipse.ui.views.properties.tabbed.ITabbedPropertySheetPageContributor;
+import org.eclipse.ui.views.properties.tabbed.TabbedPropertySheetPage;
+
+
+/**
+ * A Page Book containing one {@link ModelExplorerView} for each opened Papyrus Editor.
+ *
+ * @author cedric dumoulin
+ *
+ */
+public class ModelExplorerPageBookView extends MultiViewPageBookView implements IGotoMarker, ITabbedPropertySheetPageContributor {
+
+ /** ID of the view, as given in the plugin.xml file */
+ public static final String VIEW_ID = "org.eclipse.papyrus.modelexplorer.modelexplorer"; //$NON-NLS-1$
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ protected PageRec doCreatePage(IWorkbenchPart part) {
+
+ // part is of type IMultiDiagramEditor (because of isImportant() )
+
+ ViewPartPage page = new ModelExplorerPage();
+
+ // Init the page, and so the View
+ initPage(page, part);
+ page.createControl(getPageBook());
+ return new PageRec(part, page);
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ @SuppressWarnings("rawtypes")
+ @Override
+ public Object getAdapter(Class adapter) {
+
+ if(IPropertySheetPage.class == adapter) {
+ // Do not test if tabbedPropertySheetPage is null before calling new
+ // this is managed by Eclipse which only call current method when necessary
+ return new TabbedPropertySheetPage(this);
+ }
+
+ return super.getAdapter(adapter);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public String getContributorId() {
+ // return Activator.PLUGIN_ID;
+ return "TreeOutlinePage";
+
+ }
+
+ /**
+ * Find an Element within the tree (a ModelElementItem) when given an EObject
+ *
+ * @param eObjectToFind
+ * @param treeViewer
+ * @return
+ */
+ public Object findElementForEObject(TreeViewer treeViewer, EObject eObjectToFind) {
+ ITreeContentProvider contentProvider = (ITreeContentProvider) treeViewer.getContentProvider();
+ Object[] elements = contentProvider.getElements(treeViewer.getInput());
+
+ LinkedList<Object> elementsToHandle = new LinkedList<Object>();
+ for (Object element : elements) {
+ elementsToHandle.add(element);
+ }
+ while (!elementsToHandle.isEmpty()) {
+ Object e = elementsToHandle.removeFirst();
+ EObject eObject = (EObject) Platform.getAdapterManager().getAdapter(e, EObject.class);
+ if (eObject != null && eObject.equals(eObjectToFind)) {
+ return e;
+ }
+ if (contentProvider.hasChildren(e)) {
+ Object[] children = contentProvider.getChildren(e);
+ if (children != null) {
+ for (Object child : children) {
+ elementsToHandle.addLast(child);
+ }
+ }
+ }
+ }
+ return null;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void gotoMarker(IMarker marker) {
+ try {
+ if (marker.isSubtypeOf((EValidator.MARKER))) {
+ String uriAttribute = marker.getAttribute(EValidator.URI_ATTRIBUTE, null);
+ if(uriAttribute != null) {
+ URI uri = URI.createURI(uriAttribute);
+ IViewPart viewPart = getActiveView();
+ if (viewPart instanceof ModelExplorerView) {
+ ModelExplorerView modelExplorerView = (ModelExplorerView) viewPart;
+ EditingDomain domain = modelExplorerView.getEditingDomain();
+ EObject eObject = domain.getResourceSet().getEObject(uri, true);
+ if (eObject != null) {
+ CommonViewer treeViewer = ((ModelExplorerView) viewPart).getCommonViewer();
+ // The common viewer is in fact a tree viewer
+ Object modelElementItem = findElementForEObject (treeViewer, eObject);
+ if (modelElementItem != null) {
+ TreePath treePath = new TreePath(new Object[] {
+ modelElementItem
+ });
+ EObject parent = eObject.eContainer();
+ if (parent != null) {
+ // workaround: in case of a pseudo parent (like "ownedConnector", the expansion
+ // is not made automatically
+ Object parentElement = findElementForEObject (treeViewer, parent);
+ treeViewer.expandToLevel(parentElement, 1);
+ }
+ treeViewer.setSelection(new TreeSelection (treePath), true);
+ }
+ }
+ }
+ }
+ }
+ } catch (CoreException exception) {
+ log.error(exception);
+ }
+ }
+}
diff --git a/plugins/views/modelexplorer/org.eclipse.papyrus.modelexplorer/src/org/eclipse/papyrus/modelexplorer/ModelExplorerView.java b/plugins/views/modelexplorer/org.eclipse.papyrus.modelexplorer/src/org/eclipse/papyrus/modelexplorer/ModelExplorerView.java
new file mode 100644
index 00000000000..c819679afd5
--- /dev/null
+++ b/plugins/views/modelexplorer/org.eclipse.papyrus.modelexplorer/src/org/eclipse/papyrus/modelexplorer/ModelExplorerView.java
@@ -0,0 +1,622 @@
+/*****************************************************************************
+ * Copyright (c) 2010 CEA LIST.
+ *
+ *
+ * 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:
+ * Patrick Tessier (CEA LIST) Patrick.tessier@cea.fr - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.modelexplorer;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Set;
+import java.util.concurrent.atomic.AtomicBoolean;
+
+import org.eclipse.core.commands.operations.IUndoContext;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IAdaptable;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.ecore.EReference;
+import org.eclipse.emf.edit.domain.EditingDomain;
+import org.eclipse.emf.edit.domain.IEditingDomainProvider;
+import org.eclipse.emf.transaction.ResourceSetChangeEvent;
+import org.eclipse.emf.transaction.ResourceSetListener;
+import org.eclipse.emf.transaction.ResourceSetListenerImpl;
+import org.eclipse.emf.transaction.Transaction;
+import org.eclipse.emf.transaction.TransactionalEditingDomain;
+import org.eclipse.gmf.runtime.notation.Diagram;
+import org.eclipse.jface.viewers.ColumnViewerToolTipSupport;
+import org.eclipse.jface.viewers.ILabelProvider;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.jface.viewers.ITreeContentProvider;
+import org.eclipse.jface.viewers.StructuredSelection;
+import org.eclipse.jface.window.ToolTip;
+import org.eclipse.papyrus.core.editor.IMultiDiagramEditor;
+import org.eclipse.papyrus.core.lifecycleevents.IEditorInputChangedListener;
+import org.eclipse.papyrus.core.lifecycleevents.ISaveAndDirtyService;
+import org.eclipse.papyrus.core.services.ServiceException;
+import org.eclipse.papyrus.core.ui.IRevealSemanticElement;
+import org.eclipse.papyrus.core.utils.EditorUtils;
+import org.eclipse.papyrus.core.utils.ServiceUtils;
+import org.eclipse.papyrus.modelexplorer.listener.DoubleClickListener;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Tree;
+import org.eclipse.swt.widgets.TreeItem;
+import org.eclipse.ui.IActionBars;
+import org.eclipse.ui.IEditorPart;
+import org.eclipse.ui.IMemento;
+import org.eclipse.ui.ISaveablePart;
+import org.eclipse.ui.ISelectionListener;
+import org.eclipse.ui.IViewSite;
+import org.eclipse.ui.IWorkbenchPage;
+import org.eclipse.ui.IWorkbenchPart;
+import org.eclipse.ui.PartInitException;
+import org.eclipse.ui.PlatformUI;
+import org.eclipse.ui.actions.ActionFactory;
+import org.eclipse.ui.internal.navigator.NavigatorContentService;
+import org.eclipse.ui.internal.navigator.extensions.NavigatorContentDescriptor;
+import org.eclipse.ui.navigator.CommonNavigator;
+import org.eclipse.ui.navigator.CommonViewer;
+import org.eclipse.ui.operations.RedoActionHandler;
+import org.eclipse.ui.operations.UndoActionHandler;
+import org.eclipse.ui.part.FileEditorInput;
+import org.eclipse.ui.views.properties.IPropertySheetPage;
+import org.eclipse.ui.views.properties.tabbed.ITabbedPropertySheetPageContributor;
+import org.eclipse.ui.views.properties.tabbed.TabbedPropertySheetPage;
+
+/**
+ * Papyrus Model Explorer associated to one {@link IMultiDiagramEditor}.
+ * This ModelExplorer is linked to one single {@link IMultiDiagramEditor}. It doesn't change its
+ * source when the current Editor change. To allow to explore different Model, use a {@link ModelExplorerPageBookView}.
+ *
+ */
+public class ModelExplorerView extends CommonNavigator implements IRevealSemanticElement, IEditingDomainProvider {
+
+ /** The associated EditorPart */
+ private IMultiDiagramEditor editorPart;
+
+ /** The save aservice associated to the editor. */
+ private ISaveAndDirtyService saveAndDirtyService;
+
+ /** editing domain used to read/write the model */
+ private TransactionalEditingDomain editingDomain;
+
+ /** Flag to avoid reentrant call to refresh. */
+ private AtomicBoolean isRefreshing = new AtomicBoolean(false);
+
+ /**
+ * Listener on {@link ISaveAndDirtyService#addInputChangedListener(IEditorInputChangedListener)}
+ */
+ protected IEditorInputChangedListener editorInputChangedListener = new IEditorInputChangedListener() {
+
+ /**
+ * This method is called when the editor input is changed from the ISaveAndDirtyService.
+ *
+ * @see org.eclipse.papyrus.core.lifecycleevents.IEditorInputChangedListener#editorInputChanged(org.eclipse.ui.part.FileEditorInput)
+ *
+ * @param fileEditorInput
+ */
+ public void editorInputChanged(FileEditorInput fileEditorInput) {
+ // Change the editor input.
+ setPartName(fileEditorInput.getName());
+ }
+
+ /**
+ * The isDirty flag has changed, reflect its new value
+ *
+ * @see org.eclipse.papyrus.core.lifecycleevents.IEditorInputChangedListener#isDirtyChanged()
+ *
+ */
+ public void isDirtyChanged() {
+ firePropertyChange(IEditorPart.PROP_DIRTY);
+ }
+ };
+
+
+ /** Undo action handler */
+ UndoActionHandler undoHandler;
+
+ /** Redo action handler */
+ RedoActionHandler redoHandler;
+
+
+ /** The {@link IPropertySheetPage} this model explorer will use. */
+ private IPropertySheetPage propertySheetPage = null;
+
+ /**
+ *
+ * Constructor.
+ *
+ * @param part
+ * The part associated to this ModelExplorer
+ */
+ public ModelExplorerView(IMultiDiagramEditor part) {
+ this.editorPart = part;
+ setLinkingEnabled(true);
+
+ try {
+ this.saveAndDirtyService = editorPart.getServicesRegistry().getService(ISaveAndDirtyService.class);
+ } catch (ServiceException e) {
+ e.printStackTrace();
+ }
+ }
+
+ /**
+ * Handle a selection change in the editor.
+ *
+ * @param part
+ * @param selection
+ */
+ private void handleSelectionChangedFromDiagramEditor(IWorkbenchPart part, ISelection selection) {
+ // Handle selection from diagram editor
+ if(isLinkingEnabled()) {
+ if(part instanceof IEditorPart) {
+ if(selection instanceof IStructuredSelection) {
+ Iterator<?> selectionIterator = ((IStructuredSelection)selection).iterator();
+ ArrayList<Object> semanticElementList = new ArrayList<Object>();
+ while(selectionIterator.hasNext()) {
+ Object currentSelection = (Object)selectionIterator.next();
+ if(currentSelection instanceof IAdaptable) {
+ Object semanticElement = ((IAdaptable)currentSelection).getAdapter(EObject.class);
+ if(semanticElement != null) {
+ semanticElementList.add(semanticElement);
+ }
+ }
+
+ }
+ revealSemanticElement(semanticElementList);
+
+ }
+
+ }
+ }
+ }
+
+ /**
+ * look for the path the list of element (comes from the content provider) to go the eObject
+ *
+ * @param eobject
+ * that we look for.
+ * @param objects
+ * a list of elements where eobject can be wrapped.
+ * @return the list of modelElementItem ( from the root to the element that wrap the eobject)
+ */
+ protected List<Object> searchPath(EObject eobject, List<Object> objects) {
+ SemanticFromModelExplorer semanticGetter = new SemanticFromModelExplorer();
+ List<Object> path = new ArrayList<Object>();
+ ITreeContentProvider contentProvider = (ITreeContentProvider)getCommonViewer().getContentProvider();
+
+ for(Object o : objects) {
+ // Search matches in this level
+ if(!(o instanceof Diagram) && o instanceof IAdaptable) {
+ if(eobject.equals((EObject)((IAdaptable)o).getAdapter(EObject.class))) {
+ path.add(o);
+ return path;
+ }
+ }
+
+ // Find childs only for feature container
+ for(int i = 0; i < contentProvider.getChildren(o).length; i++) {
+ Object treeItem = contentProvider.getChildren(o)[i];
+
+ List<Object> tmppath = new ArrayList<Object>();
+ Object element = semanticGetter.getSemanticElement(treeItem);
+ if(element != null) {
+ if(element instanceof EReference) {
+ if(((EReference)element).isContainment() && (!((EReference)element).isDerived())) {
+ List<Object> childs = new ArrayList<Object>();
+ childs.add(treeItem);
+ tmppath = searchPath(eobject, childs);
+ }
+ }
+
+ else {
+ if(element instanceof EObject) {
+ List<Object> childs = new ArrayList<Object>();
+ childs.add(treeItem);
+ tmppath = searchPath(eobject, childs);
+ }
+ }
+ }
+
+ // if tmppath contains the wrapped eobject we have find the good path
+ if(tmppath.size() > 0) {
+ if(tmppath.get(tmppath.size() - 1) instanceof IAdaptable) {
+ if(eobject.equals((EObject)((IAdaptable)(tmppath.get(tmppath.size() - 1))).getAdapter(EObject.class))) {
+ path.add(o);
+ path.addAll(tmppath);
+ return path;
+ }
+ }
+ }
+ }
+ }
+
+ return new ArrayList<Object>();
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ // FIXME Use of internal class (NavigatorContentService) - in the hope that the bug gets fixed soon.
+ @Override
+ protected CommonViewer createCommonViewerObject(Composite aParent) {
+ CommonViewer viewer = new CustomCommonViewer(getViewSite().getId(), aParent, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL);
+ // enable tool-tips
+ // workaround for bug 311827: the Common Viewer always uses NavigatorDecoratingLabelProvider
+ // as a wrapper for the LabelProvider provided by the application. The NavigatorDecoratingLabelProvider
+ // does not delegate tooltip related functions but defines them as empty.
+ NavigatorContentService contentService = new NavigatorContentService(getViewSite().getId());
+ @SuppressWarnings("unchecked")
+ // get label provider from content service (which in turn evaluates extension points in
+ // function of the input)
+ Set<Object> descriptors = contentService.findDescriptorsByTriggerPoint(getInitialInput(), false);
+ for(Object descriptor : descriptors) {
+ if(descriptor instanceof NavigatorContentDescriptor) {
+ try {
+ ILabelProvider labelProvider = ((NavigatorContentDescriptor)descriptor).createLabelProvider();
+ viewer.setLabelProvider(labelProvider);
+ } catch (CoreException e) {
+ Activator.log.error(e);
+ }
+ break;
+ }
+ }
+ ColumnViewerToolTipSupport.enableFor(viewer, ToolTip.NO_RECREATE);
+
+ return viewer;
+ }
+
+ @Override
+ public void createPartControl(Composite aParent) {
+ super.createPartControl(aParent);
+ getCommonViewer().setSorter(null);
+ ((CustomCommonViewer)getCommonViewer()).getDropAdapter().setFeedbackEnabled(true);
+ getCommonViewer().addDoubleClickListener(new DoubleClickListener());
+ Tree tree = getCommonViewer().getTree();
+ Activator.getDefault().getCustomizationManager().installCustomPainter(tree);
+
+ }
+
+ /**
+ * Return the control used to render this View
+ *
+ * @see org.eclipse.papyrus.core.ui.pagebookview.IPageBookNestableViewPart#getControl()
+ *
+ * @return the main control of the navigator viewer
+ */
+ public Control getControl() {
+ return getCommonViewer().getControl();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void init(IViewSite site, IMemento aMemento) throws PartInitException {
+ super.init(site, aMemento);
+
+ // Hook undo/redo action
+ // hookGlobalHistoryHandler(site);
+
+ // page.addPartListener(partListener);
+ activate();
+
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void init(IViewSite site) throws PartInitException {
+ super.init(site);
+ IWorkbenchPage page = site.getPage();
+ // an ISelectionListener to react to workbench selection changes.
+
+ page.addSelectionListener(new ISelectionListener() {
+
+ public void selectionChanged(IWorkbenchPart part, ISelection selection) {
+ handleSelectionChangedFromDiagramEditor(part, selection);
+ }
+ });
+ }
+
+ /**
+ * Hook the global undo/redi actions.
+ */
+ private void hookGlobalHistoryHandler(IViewSite site) {
+ undoHandler = new UndoActionHandler(site, null);
+ redoHandler = new RedoActionHandler(site, null);
+
+ IActionBars actionBars = site.getActionBars();
+
+ actionBars.setGlobalActionHandler(ActionFactory.UNDO.getId(), undoHandler);
+ actionBars.setGlobalActionHandler(ActionFactory.REDO.getId(), redoHandler);
+ }
+
+ /**
+ * {@link ResourceSetListener} to listen and react to changes in the
+ * resource set.
+ */
+ private final ResourceSetListener resourceSetListener = new ResourceSetListenerImpl() {
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void resourceSetChanged(ResourceSetChangeEvent event) {
+ super.resourceSetChanged(event);
+ handleResourceSetChanged(event);
+ }
+ };
+
+ /** cache variable with last transaction which triggered a refresh */
+ private Transaction lastTrans = null;
+
+ /**
+ * Run in a UI thread to avoid non UI thread exception.
+ *
+ * @param event
+ */
+ private void handleResourceSetChanged(ResourceSetChangeEvent event) {
+ // avoid refreshing N times for the same transaction (called for each object in resource)
+ Transaction curTrans = event.getTransaction();
+ if(lastTrans != null && lastTrans.equals(curTrans)) {
+ return;
+ }
+ lastTrans = curTrans;
+ PlatformUI.getWorkbench().getDisplay().syncExec(new Runnable() {
+
+ /**
+ * {@inheritDoc}
+ */
+ public void run() {
+ refresh();
+ }
+ });
+ }
+
+ /**
+ * refresh the view.
+ */
+ public void refresh() {
+ // Need to refresh, even if (temporarily) invisible
+ // (Better alternative?: store refresh event and execute once visible again)
+ if(getControl().isDisposed())
+ return;
+
+ // avoid reentrant call
+ // Refresh only of we are not already refreshing.
+ if(isRefreshing.compareAndSet(false, true)) {
+ if(!getCommonViewer().isBusy())
+ getCommonViewer().refresh();
+
+ isRefreshing.set(false);
+ }
+
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ protected Object getInitialInput() {
+
+ if(editorPart != null) {
+ return editorPart.getServicesRegistry();
+ } else {
+ return super.getInitialInput();
+ }
+
+ }
+
+ /**
+ * Activate specified Part.
+ */
+ private void activate() {
+
+ if(editorPart != null) {
+
+ try {
+ this.editingDomain = ServiceUtils.getInstance().getTransactionalEditingDomain(editorPart.getServicesRegistry());
+ // this.editingDomain = EditorUtils.getTransactionalEditingDomain(editorPart.getServicesRegistry());
+ // Set Viewer input if it already exist
+ if(getCommonViewer() != null) {
+ getCommonViewer().setInput(editorPart.getServicesRegistry());
+ }
+ editingDomain.addResourceSetListener(resourceSetListener);
+ } catch (ServiceException e) {
+ // Can't get EditingDomain, skip
+ }
+
+ // Listen to isDirty flag
+ saveAndDirtyService.addInputChangedListener(editorInputChangedListener);
+
+ // Hook
+ // if(undoHandler != null){
+ // IUndoContext undoContext = getUndoContext(part);
+ // undoHandler.setContext(undoContext);
+ // undoHandler.update();
+ // redoHandler.setContext(undoContext);
+ // redoHandler.update();
+ // }
+ }
+ if(this.getCommonViewer() != null) {
+ refresh();
+ }
+
+ }
+
+ /**
+ * Get the undo context associated to the part.
+ *
+ * @param part
+ * @return
+ */
+ private IUndoContext getUndoContext(IMultiDiagramEditor part) {
+ return (IUndoContext)part.getAdapter(IUndoContext.class);
+ }
+
+ /**
+ * Deactivate the Model Explorer.
+ */
+ private void deactivate() {
+ // deactivate global handler
+ if(editorPart != null) {
+ if(Activator.log.isDebugEnabled()) {
+ Activator.log.debug("deactivate " + editorPart.getTitle()); //$NON-NLS-1$
+ }
+
+ // Stop Listenning to isDirty flag
+ saveAndDirtyService.removeInputChangedListener(editorInputChangedListener);
+
+ // unhook
+ // IUndoContext undoContext = getUndoContext(editorPart);
+ // undoHandler.setContext(undoContext);
+ // undoHandler.update();
+ // redoHandler.setContext(undoContext);
+ // redoHandler.update();
+
+ }
+
+ editorPart = null;
+ if(editingDomain != null) {
+ editingDomain.removeResourceSetListener(resourceSetListener);
+ }
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void dispose() {
+ deactivate();
+ super.dispose();
+
+ }
+
+ /**
+ * Retrieves the {@link IPropertySheetPage} that his Model Explorer uses.
+ *
+ * @return
+ */
+ private IPropertySheetPage getPropertySheetPage() {
+ final IMultiDiagramEditor multiDiagramEditor = EditorUtils.getMultiDiagramEditor();
+
+ if(multiDiagramEditor != null) {
+ if(propertySheetPage == null) {
+ if(multiDiagramEditor instanceof ITabbedPropertySheetPageContributor) {
+ ITabbedPropertySheetPageContributor contributor = (ITabbedPropertySheetPageContributor)multiDiagramEditor;
+ this.propertySheetPage = new TabbedPropertySheetPage(contributor);
+ }
+ }
+ return propertySheetPage;
+ }
+ return null;
+ }
+
+ /**
+ * in order to see element if the property view
+ */
+ @SuppressWarnings("rawtypes")
+ public Object getAdapter(Class adapter) {
+ if(IPropertySheetPage.class.equals(adapter)) {
+ return getPropertySheetPage();
+ }
+
+ if(IUndoContext.class.equals(adapter)) {
+ // Return the IUndoContext of the currently selected editor.
+ if(editorPart != null) {
+ return editorPart.getAdapter(IUndoContext.class);
+ }
+
+ // Let the parent return the adapter.
+ }
+
+ if(ISaveablePart.class.equals(adapter)) {
+ return saveAndDirtyService;
+ }
+
+ return super.getAdapter(adapter);
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @return the EditingDomain used by the properties view
+ */
+ public EditingDomain getEditingDomain() {
+ return editingDomain;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void selectReveal(ISelection selection) {
+ if(getCommonViewer() != null) {
+ getCommonViewer().setSelection(selection, true);
+ }
+ }
+
+
+ public void expandItems(List<Object> treeElementList, TreeItem[] list) {
+ //the treeElement has more tan one element
+ if(treeElementList.size() > 0) {
+ for(int i = 0; i < list.length; i++) {
+ if(list[i].getData() != null && list[i].getData().equals(treeElementList.get(0))) {
+ if(treeElementList.size() > 1) {//Do no expand the last
+ Object[] toexpand = { treeElementList.get(0) };
+ getCommonViewer().setExpandedElements(toexpand);
+ }
+ ArrayList<Object> tmpList = new ArrayList<Object>();
+ tmpList.addAll(treeElementList);
+ tmpList.remove(tmpList.get(0));
+ expandItems(tmpList, list[i].getItems());
+ }
+ }
+ }
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void revealSemanticElement(List<?> elementList) {
+ //for each element we reveal it
+ Iterator<?> elementListIterator = elementList.iterator();
+ ArrayList<Object> treeElementToSelect = new ArrayList<Object>();
+ while(elementListIterator.hasNext()) {
+ Object currentElement = (Object)elementListIterator.next();
+ //test if the type is an EObject
+ if(currentElement instanceof EObject) {
+ EObject currentEObject = (EObject)currentElement;
+ //the content provider exist?
+ if(getCommonViewer().getContentProvider() != null) {
+ //need the root in order to find all element in the tree
+ Object root = getCommonViewer().getInput();
+ //look for the path in order to access to this element
+ List<Object> path = searchPath(currentEObject, Arrays.asList(((ITreeContentProvider)getCommonViewer().getContentProvider()).getElements(root)));
+ if(path.size() > 0) {
+ //expand in the common viewer the path
+ expandItems(path, getCommonViewer().getTree().getItems());
+ treeElementToSelect.add(path.get(path.size() - 1));
+ }
+ }
+ }
+ selectReveal(new StructuredSelection(treeElementToSelect));
+ }
+ }
+
+}
diff --git a/plugins/views/modelexplorer/org.eclipse.papyrus.modelexplorer/src/org/eclipse/papyrus/modelexplorer/NavigatorUtils.java b/plugins/views/modelexplorer/org.eclipse.papyrus.modelexplorer/src/org/eclipse/papyrus/modelexplorer/NavigatorUtils.java
new file mode 100644
index 00000000000..35e92d11c27
--- /dev/null
+++ b/plugins/views/modelexplorer/org.eclipse.papyrus.modelexplorer/src/org/eclipse/papyrus/modelexplorer/NavigatorUtils.java
@@ -0,0 +1,310 @@
+package org.eclipse.papyrus.modelexplorer;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Iterator;
+import java.util.List;
+
+import org.eclipse.core.runtime.IAdaptable;
+import org.eclipse.core.runtime.Platform;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.ecore.EReference;
+import org.eclipse.gef.EditPart;
+import org.eclipse.gmf.runtime.diagram.ui.parts.IDiagramGraphicalViewer;
+import org.eclipse.gmf.runtime.emf.core.util.EMFCoreUtil;
+import org.eclipse.gmf.runtime.notation.Diagram;
+import org.eclipse.gmf.runtime.notation.NotationPackage;
+import org.eclipse.gmf.runtime.notation.View;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.viewers.StructuredSelection;
+import org.eclipse.papyrus.core.utils.EditorUtils;
+import org.eclipse.papyrus.sasheditor.contentprovider.IPageMngr;
+import org.eclipse.ui.IViewPart;
+import org.eclipse.ui.IViewReference;
+import org.eclipse.ui.IWorkbenchPage;
+import org.eclipse.ui.IWorkbenchPart;
+import org.eclipse.ui.PartInitException;
+import org.eclipse.ui.PlatformUI;
+
+/**
+ * Utility method for Model Navigator.
+ *
+ * @author <a href="mailto:jerome.benois@obeo.fr">Jerome Benois</a>
+ * @author <a href="mailto:fjcano@prodevelop.es">Francisco Javier Cano
+ * Muñoz</a>
+ * @author <a href="mailto:thomas.szadel@atosorigin.com">Thomas Szadel</a>:
+ * Remove Backbone dependency
+ **/
+public class NavigatorUtils {
+
+ /**
+ * Find a <IViewPart> by it's id string.
+ *
+ * @param viewID
+ * the view id
+ *
+ * @return the i view part
+ */
+ public static IViewPart findViewPart(String viewID) {
+ IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
+ if(page == null) {
+ return null;
+ }
+ IViewReference reference = page.findViewReference(viewID);
+ if(reference == null) {
+ return null;
+ }
+ IWorkbenchPart part = reference.getPart(false);
+ if(part instanceof IViewPart) {
+ return (IViewPart)part;
+ } else {
+ return null;
+ }
+ }
+
+ /**
+ * Resolve semantic element
+ *
+ * @param object
+ * the object to resolve
+ * @return <code>null</code> or the semantic element associated to the
+ * specified object
+ */
+ public static EObject resolveSemanticObject(Object object) {
+ if(object instanceof EObject) {
+ return (EObject)object;
+ } else if(object instanceof IAdaptable) {
+ IAdaptable adaptable = (IAdaptable)object;
+ if(adaptable.getAdapter(EObject.class) != null) {
+ return (EObject)adaptable.getAdapter(EObject.class);
+ }
+ }
+ return null;
+ }
+
+ /**
+ * Unwraps selection. Gets <EObject>s from <EditPart>s, from <View>s or from
+ * <EObject>s
+ *
+ * @param selection
+ * the selection
+ *
+ * @return the i selection
+ */
+ public static ISelection unwrapSelection(ISelection selection) {
+ if(selection instanceof StructuredSelection && !selection.isEmpty()) {
+ List<EObject> selectionList = new ArrayList<EObject>();
+ StructuredSelection structuredSelection = (StructuredSelection)selection;
+ for(Iterator<?> iterator = structuredSelection.iterator(); iterator.hasNext();) {
+ Object next = iterator.next();
+ if(next instanceof EditPart) {
+ Object model = ((EditPart)next).getModel();
+ EObject element = null;
+ if(model instanceof View) {
+ element = ((View)model).getElement();
+ } else if(model instanceof EObject) {
+ element = (EObject)model;
+ }
+ if(element != null) {
+ selectionList.add(element);
+ }
+ } else if(next instanceof View) {
+ EObject element = ((View)next).getElement();
+ if(element != null) {
+ selectionList.add(element);
+ }
+ }
+ EObject eObject = NavigatorUtils.resolveSemanticObject(next);
+ if(eObject != null) {
+ selectionList.add(eObject);
+ }
+ }
+ return new StructuredSelection(selectionList);
+ } else {
+ return selection;
+ }
+ }
+
+ /**
+ * Finds the <EditPart>s for the <EObject>s in the selection.
+ *
+ * @param selection
+ * the selection
+ * @param viewer
+ * the viewer
+ *
+ * @return the edits the parts from selection
+ */
+ public static List<EditPart> getEditPartsFromSelection(ISelection selection, IDiagramGraphicalViewer viewer) {
+ if(selection instanceof StructuredSelection && !selection.isEmpty()) {
+ StructuredSelection structuredSelection = (StructuredSelection)selection;
+ // look for Views of the EObjects in the selection
+ List<View> views = new ArrayList<View>();
+ for(Object o : structuredSelection.toList()) {
+ if(o instanceof EObject) {
+ List<Object> referencerViews = getEObjectViews((EObject)o);
+ for(Object ro : referencerViews) {
+ if(ro instanceof View) {
+ views.add((View)ro);
+ }
+ }
+ }
+ }
+ if(!views.isEmpty()) {
+ List<EditPart> editParts = new ArrayList<EditPart>();
+ for(View view : views) {
+ Object ep = viewer.getEditPartRegistry().get(view);
+ if(ep instanceof EditPart) {
+ editParts.add((EditPart)ep);
+ }
+ }
+ if(!editParts.isEmpty()) {
+ return editParts;
+ }
+ }
+ }
+ return Collections.emptyList();
+ }
+
+ /**
+ * Gets the given <EObject> views.
+ *
+ * @param element
+ * the element
+ *
+ * @return the e object views
+ */
+ // @unused
+ public static List<Object> getEObjectViews(EObject element) {
+ List<Object> views = new ArrayList<Object>();
+ if(element != null) {
+ EReference[] features = { NotationPackage.eINSTANCE.getView_Element() };
+ Collection<?> referencers = EMFCoreUtil.getReferencers(element, features);
+ views.addAll(referencers);
+ }
+ return views;
+ }
+
+ // // //
+ // // get an object name
+ // // //
+ //
+ // /**
+ // * Gets the object name or empty string.
+ // *
+ // * @param object
+ // * the object
+ // *
+ // * @return the object name or empty string
+ // */
+ // // @unused
+ // public static String getObjectNameOrEmptyString(Object object) {
+ // String name = getObjectName(object);
+ // return name == null ? "" : name;
+ // }
+ //
+ // /** The Constant getNameNames. */
+ // private static final String[] getNameNames = { "getName", "getname" };
+ //
+ // /**
+ // * Gets the object name.
+ // *
+ // * @param object
+ // * the object
+ // *
+ // * @return the object name
+ // */
+ // // @unused
+ // public static String getObjectName(Object object) {
+ // if (object == null) {
+ // return null;
+ // }
+ // Method method = null;
+ // Object o = null;
+ // for (String methodName : getNameNames) {
+ // try {
+ // method = object.getClass()
+ // .getMethod(methodName, (Class[]) null);
+ // } catch (NoSuchMethodException e) {
+ // method = null;
+ // }
+ // if (method != null) {
+ // break;
+ // }
+ // }
+ // if (method != null) {
+ // try {
+ // o = method.invoke(object, (Object[]) null);
+ // } catch (IllegalAccessException ex) {
+ // return null;
+ // } catch (InvocationTargetException ex) {
+ // return null;
+ // }
+ // if (o instanceof String) {
+ // return (String) o;
+ // }
+ // }
+ // return null;
+ // }
+
+ /**
+ * Opens a {@link Diagram} in the sash editor.
+ *
+ * @param diagram
+ */
+ // @unused
+ public static void openDiagram(Diagram diagram) {
+ IPageMngr pageManager = EditorUtils.getIPageMngr();
+ if(pageManager != null) {
+ pageManager.openPage(diagram);
+ }
+ }
+
+ /**
+ * Opens a view part in the workbench with the specified ID.
+ *
+ * @param viewPartID
+ */
+ // @unused
+ public static void openViewPart(String viewPartID) {
+ if(viewPartID == null) {
+ return;
+ }
+ try {
+ PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().showView(viewPartID);
+ } catch (PartInitException e) {
+ e.printStackTrace();
+ }
+ }
+
+ /**
+ * Opens the property sheets view.
+ */
+ public static void openPropertySheetsView() {
+ openViewPart("org.eclipse.ui.views.PropertySheet");
+ }
+
+ /**
+ * Use the IAdaptable mecanisme
+ *
+ * @param o
+ * @param theClass
+ * @return
+ */
+ public static <T> T getElement(Object o, Class<T> theClass) {
+ T result = null;
+ if(o instanceof IAdaptable) {
+ IAdaptable adaptable = (IAdaptable)o;
+ result = (T)adaptable.getAdapter(theClass);
+ }
+ if(result == null) {
+ result = (T)Platform.getAdapterManager().getAdapter(o, theClass);
+ }
+ if (result == null && theClass.isInstance(o))
+ {
+ result = (T)o ;
+ }
+ return result;
+ }
+}
diff --git a/plugins/views/modelexplorer/org.eclipse.papyrus.modelexplorer/src/org/eclipse/papyrus/modelexplorer/SemanticFromModelExplorer.java b/plugins/views/modelexplorer/org.eclipse.papyrus.modelexplorer/src/org/eclipse/papyrus/modelexplorer/SemanticFromModelExplorer.java
new file mode 100644
index 00000000000..0245ea8c30d
--- /dev/null
+++ b/plugins/views/modelexplorer/org.eclipse.papyrus.modelexplorer/src/org/eclipse/papyrus/modelexplorer/SemanticFromModelExplorer.java
@@ -0,0 +1,47 @@
+/*****************************************************************************
+ * Copyright (c) 2010 CEA LIST.
+ *
+ *
+ * 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:
+ * Patrick Tessier (CEA LIST) Patrick.tessier@cea.fr - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.modelexplorer;
+
+import org.eclipse.core.runtime.IAdaptable;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.ecore.EReference;
+import org.eclipse.gmf.runtime.notation.Diagram;
+import org.eclipse.papyrus.core.IElementWithSemantic;
+
+/**
+ * This class is used to obtain the semantic element for element of the model explorer
+ */
+public class SemanticFromModelExplorer implements IElementWithSemantic {
+
+ /**
+ * {@inheritDoc}
+ */
+ public Object getSemanticElement(Object wrapper) {
+ if( wrapper instanceof IAdaptable){
+ Object obj= ((IAdaptable)wrapper).getAdapter(EObject.class);
+ if(obj==null){
+ obj= ((IAdaptable)wrapper).getAdapter(EReference.class);
+ }
+ if(obj!=null){
+ return obj;
+ }
+ }
+
+ if( wrapper instanceof Diagram){
+ return wrapper;
+ }
+ return null;
+ }
+
+}
diff --git a/plugins/views/modelexplorer/org.eclipse.papyrus.modelexplorer/src/org/eclipse/papyrus/modelexplorer/actionprovider/AbstractCommonActionProvider.java b/plugins/views/modelexplorer/org.eclipse.papyrus.modelexplorer/src/org/eclipse/papyrus/modelexplorer/actionprovider/AbstractCommonActionProvider.java
new file mode 100644
index 00000000000..ba329d1ead5
--- /dev/null
+++ b/plugins/views/modelexplorer/org.eclipse.papyrus.modelexplorer/src/org/eclipse/papyrus/modelexplorer/actionprovider/AbstractCommonActionProvider.java
@@ -0,0 +1,104 @@
+/*******************************************************************************
+ * Copyright (c) 2008 Conselleria de Infraestructuras y Transporte, Generalitat
+ * de la Comunitat Valenciana, 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:
+ * Francisco Javier Cano Muñoz (Prodevelop) – Initial API implementation.
+ * Obeo
+ *
+ ******************************************************************************/
+package org.eclipse.papyrus.modelexplorer.actionprovider;
+
+import org.eclipse.core.runtime.IAdaptable;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.viewers.StructuredSelection;
+import org.eclipse.ui.actions.ActionContext;
+import org.eclipse.ui.navigator.CommonActionProvider;
+import org.eclipse.ui.navigator.CommonNavigator;
+import org.eclipse.ui.navigator.CommonViewer;
+
+/**
+ * Specialization of <CommonActionProvider> to be used as Papyrus action
+ * provider.
+ *
+ * @author fjcano
+ * @author <a href="mailto:jerome.benois@obeo.fr">Jerome Benois</a>
+ */
+public abstract class AbstractCommonActionProvider extends CommonActionProvider {
+
+ /**
+ * Gets the ID of the <CommonViewer> this <MOSKittCommonActionProvider> is
+ * associated to.
+ *
+ * @return the viewer id
+ */
+ // @unused
+ protected String getViewerID() {
+ return getActionSite().getViewSite().getId();
+ }
+
+ /**
+ * Gets the <MOSKittCommonNavigator> this <MOSKittCommonActionProvider> is
+ * associated with, via the viewerID.
+ *
+ * @return the common navigator
+ */
+ protected CommonNavigator getCommonNavigator() {
+
+ return ((CommonViewer)getActionSite().getStructuredViewer()).getCommonNavigator();
+// IViewPart part = org.eclipse.papyrus.modelexplorer.NavigatorUtils
+// .findViewPart(getViewerID());
+// if (part instanceof CommonNavigator) {
+// return ((CommonNavigator) part);
+// }
+// return null;
+ }
+
+ /**
+ * Gets the current context's selection.
+ *
+ * @return the selection
+ */
+ // @unused
+ protected ISelection getSelection() {
+ ActionContext context = getContext();
+ return (context != null) ? context.getSelection() : null;
+ }
+
+ /**
+ * Gets the first element of the current context's selection.
+ *
+ * @return the first selected element
+ */
+ protected Object getFirstSelectedElement() {
+ ISelection selection = getSelection();
+ if (selection instanceof StructuredSelection) {
+ return ((StructuredSelection) selection).getFirstElement();
+ }
+ return null;
+ }
+
+ /**
+ * Resolve semantic element
+ *
+ * @param object
+ * the object to resolve
+ * @return <code>null</code> or the semantic element associated to the
+ * specified object
+ */
+ protected EObject resolveSemanticObject(Object object) {
+ if (object instanceof EObject) {
+ return (EObject) object;
+ } else if (object instanceof IAdaptable) {
+ IAdaptable adaptable = (IAdaptable) object;
+ if (adaptable.getAdapter(EObject.class) != null) {
+ return (EObject) adaptable.getAdapter(EObject.class);
+ }
+ }
+ return null;
+ }
+}
diff --git a/plugins/views/modelexplorer/org.eclipse.papyrus.modelexplorer/src/org/eclipse/papyrus/modelexplorer/actionprovider/AbstractSubmenuActionProvider.java b/plugins/views/modelexplorer/org.eclipse.papyrus.modelexplorer/src/org/eclipse/papyrus/modelexplorer/actionprovider/AbstractSubmenuActionProvider.java
new file mode 100644
index 00000000000..9df54783232
--- /dev/null
+++ b/plugins/views/modelexplorer/org.eclipse.papyrus.modelexplorer/src/org/eclipse/papyrus/modelexplorer/actionprovider/AbstractSubmenuActionProvider.java
@@ -0,0 +1,124 @@
+/*******************************************************************************
+ * Copyright (c) 2008 Conselleria de Infraestructuras y Transporte, Generalitat
+ * de la Comunitat Valenciana, 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:
+ * Francisco Javier Cano Muñoz (Prodevelop) – Initial API implementation.
+ * Obeo
+ *
+ ******************************************************************************/
+package org.eclipse.papyrus.modelexplorer.actionprovider;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Iterator;
+import java.util.LinkedHashMap;
+import java.util.Map;
+import java.util.StringTokenizer;
+
+import org.eclipse.jface.action.IAction;
+import org.eclipse.jface.action.IContributionManager;
+import org.eclipse.jface.action.MenuManager;
+
+/**
+ * Specialization of <AbstractCommonActionProvider> to be used in menu and
+ * submenu contributions.
+ *
+ * @author fjcano
+ * @author <a href="mailto:jerome.benois@obeo.fr">Jerome Benois</a>
+ */
+public abstract class AbstractSubmenuActionProvider extends
+ AbstractCommonActionProvider {
+
+ /**
+ * Organizes the given <Collection> of <IActions>.
+ *
+ * @param createActions
+ * <Collection> of <IActions> to organize
+ * @param token
+ * <String> that the <StringTokenizer> will use to trim each
+ * <IAction>'s text.
+ *
+ * @return a <Map> associating <String>s to <Collection>s of <IAction>s.
+ */
+ protected Map<String, Collection<IAction>> extractSubmenuActions(
+ Collection<IAction> createActions, String token) {
+ Map<String, Collection<IAction>> createSubmenuActions = new LinkedHashMap<String, Collection<IAction>>();
+ if (createActions != null) {
+ for (Iterator<IAction> actions = createActions.iterator(); actions
+ .hasNext();) {
+ IAction action = actions.next();
+ StringTokenizer st = new StringTokenizer(action.getText(),
+ token);
+ if (st.countTokens() == 2) {
+ String text = st.nextToken().trim();
+ Collection<IAction> submenuActions = createSubmenuActions
+ .get(text);
+ if (submenuActions == null) {
+ createSubmenuActions.put(text,
+ submenuActions = new ArrayList<IAction>());
+ }
+ action.setText(st.nextToken().trim());
+ submenuActions.add(action);
+ actions.remove();
+ }
+ }
+ }
+ return createSubmenuActions;
+ }
+
+ /**
+ * Fills a <IContributionManager> with the given <Collection> of <IActions>.
+ *
+ * @param manager
+ * the manager
+ * @param actions
+ * the actions
+ * @param contributionID
+ * the contribution id
+ */
+ protected void populateManager(IContributionManager manager,
+ Collection<? extends IAction> actions, String contributionID) {
+ if (actions != null) {
+ for (IAction action : actions) {
+ if (contributionID != null) {
+ manager.insertBefore(contributionID, action);
+ } else {
+ manager.add(action);
+ }
+ }
+ }
+ }
+
+ /**
+ * Fills a <IContributionManager> with two levels of menus, as specified by
+ * the <Map> of <String>s to <Collection>s of <IAction>s.
+ *
+ * @param manager
+ * the manager
+ * @param submenuActions
+ * the submenu actions
+ * @param contributionID
+ * the contribution id
+ */
+ protected void populateManager(IContributionManager manager,
+ Map<String, Collection<IAction>> submenuActions,
+ String contributionID) {
+ if (submenuActions != null) {
+ for (Map.Entry<String, Collection<IAction>> entry : submenuActions
+ .entrySet()) {
+ MenuManager submenuManager = new MenuManager(entry.getKey());
+ if (contributionID != null) {
+ manager.insertBefore(contributionID, submenuManager);
+ } else {
+ manager.add(submenuManager);
+ }
+ populateManager(submenuManager, entry.getValue(), null);
+ }
+ }
+ }
+
+}
diff --git a/plugins/views/modelexplorer/org.eclipse.papyrus.modelexplorer/src/org/eclipse/papyrus/modelexplorer/actionprovider/CreateChildActionProvider.java b/plugins/views/modelexplorer/org.eclipse.papyrus.modelexplorer/src/org/eclipse/papyrus/modelexplorer/actionprovider/CreateChildActionProvider.java
new file mode 100644
index 00000000000..fcdecd436a2
--- /dev/null
+++ b/plugins/views/modelexplorer/org.eclipse.papyrus.modelexplorer/src/org/eclipse/papyrus/modelexplorer/actionprovider/CreateChildActionProvider.java
@@ -0,0 +1,125 @@
+/*******************************************************************************
+ * Copyright (c) 2009 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.papyrus.modelexplorer.actionprovider;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.List;
+import java.util.Map;
+
+import org.eclipse.emf.edit.command.CommandParameter;
+import org.eclipse.emf.edit.ui.action.CreateChildAction;
+import org.eclipse.emf.transaction.TransactionalEditingDomain;
+import org.eclipse.jface.action.IAction;
+import org.eclipse.jface.action.IMenuManager;
+import org.eclipse.jface.action.MenuManager;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.papyrus.core.utils.EditorUtils;
+import org.eclipse.ui.navigator.ICommonActionExtensionSite;
+
+/**
+ * The Class CreateChildActions.
+ *
+ * @deprecated
+ * @author <a href="mailto:jerome.benois@obeo.fr">Jerome Benois</a>
+ */
+public class CreateChildActionProvider extends AbstractSubmenuActionProvider {
+
+ protected Collection<IAction> createChildActions;
+
+ protected Map<String, Collection<IAction>> createChildSubmenuActions;
+
+ // @unused
+ protected IMenuManager createChildMenuManager;
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void init(ICommonActionExtensionSite site) {
+ super.init(site);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void fillContextMenu(IMenuManager menu) {
+ super.fillContextMenu(menu);
+ ISelection selection = getContext().getSelection();
+ Collection<?> newChildDescriptors = null;
+ Object selectedElement = null;
+ if(selection instanceof IStructuredSelection && ((IStructuredSelection)selection).size() == 1) {
+ selectedElement = resolveSemanticObject(((IStructuredSelection)selection).getFirstElement());
+ TransactionalEditingDomain domain = EditorUtils.getTransactionalEditingDomain();
+ if(domain == null) {
+ return;
+ }
+ newChildDescriptors = domain.getNewChildDescriptors(selectedElement, null);
+ }
+
+ createChildActions = generateCreateChildActions(newChildDescriptors, selection);
+ createChildSubmenuActions = extractSubmenuActions(createChildActions, "|");
+ MenuManager submenuManager = new MenuManager("New Child");
+ populateManager(submenuManager, createChildSubmenuActions, null);
+ populateManager(submenuManager, createChildActions, null);
+ menu.add(submenuManager);
+ }
+
+ /**
+ * Generate create child actions.
+ *
+ * @param descriptors
+ * the descriptors
+ * @param selection
+ * the selection
+ *
+ * @return the collection< i action>
+ */
+ protected Collection<IAction> generateCreateChildActions(Collection<?> descriptors, ISelection selection) {
+ List<IAction> createChildActions = (List<IAction>)generateCreateChildActionsGen(descriptors, selection);
+
+ Collections.<IAction> sort(createChildActions, new Comparator<IAction>() {
+
+ public int compare(IAction a1, IAction a2) {
+ return a1.getText().compareTo(a2.getText());
+ }
+ });
+
+ return createChildActions;
+ }
+
+ /**
+ * Generate create child actions gen.
+ *
+ * @param descriptors
+ * the descriptors
+ * @param selection
+ * the selection
+ *
+ * @return the collection< i action>
+ */
+ protected Collection<IAction> generateCreateChildActionsGen(Collection<?> descriptors, ISelection selection) {
+ Collection<IAction> actions = new ArrayList<IAction>();
+ if(descriptors != null) {
+ for(Object descriptor : descriptors) {
+ if(descriptor instanceof CommandParameter) {
+ actions.add(new CreateChildAction(EditorUtils.getTransactionalEditingDomain(), selection, descriptor));
+ }
+ }
+ }
+ return actions;
+ }
+
+}
diff --git a/plugins/views/modelexplorer/org.eclipse.papyrus.modelexplorer/src/org/eclipse/papyrus/modelexplorer/actionprovider/CreateDiagramActionProvider.java b/plugins/views/modelexplorer/org.eclipse.papyrus.modelexplorer/src/org/eclipse/papyrus/modelexplorer/actionprovider/CreateDiagramActionProvider.java
new file mode 100644
index 00000000000..e5cefc83665
--- /dev/null
+++ b/plugins/views/modelexplorer/org.eclipse.papyrus.modelexplorer/src/org/eclipse/papyrus/modelexplorer/actionprovider/CreateDiagramActionProvider.java
@@ -0,0 +1,53 @@
+/*******************************************************************************
+ * Copyright (c) 2009 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
+ * Tristan Faure (Atos Origin) tristan.faure@atosorigin.com - add condition to the create command (task #296902)
+ *******************************************************************************/
+package org.eclipse.papyrus.modelexplorer.actionprovider;
+
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.jface.action.IMenuManager;
+import org.eclipse.jface.action.MenuManager;
+import org.eclipse.papyrus.core.extension.commands.CreationCommandDescriptor;
+import org.eclipse.papyrus.core.extension.commands.CreationCommandRegistry;
+import org.eclipse.papyrus.core.extension.commands.ICreationCommandRegistry;
+import org.eclipse.papyrus.modelexplorer.actions.CreateDiagramAction;
+
+/**
+ * Provider used to create a new diagram actions
+ *
+ * @deprecated
+ */
+public class CreateDiagramActionProvider extends AbstractSubmenuActionProvider {
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void fillContextMenu(IMenuManager menu) {
+ Object selectedElement = resolveSemanticObject(getFirstSelectedElement());
+
+ if(selectedElement != null && selectedElement instanceof EObject) {
+ EObject eobject = (EObject)selectedElement;
+ MenuManager newDiagramMenu = new MenuManager("New Diagram");
+ menu.add(newDiagramMenu);
+ for(CreationCommandDescriptor desc : getCreationCommandRegistry().getCommandDescriptors()) {
+ if(desc.getCondition() == null || desc.getCondition().create(eobject)) {
+ CreateDiagramAction createDiagramAction = new CreateDiagramAction(eobject, desc);
+ newDiagramMenu.add(createDiagramAction);
+ }
+ }
+ }
+ }
+
+ private static ICreationCommandRegistry getCreationCommandRegistry() {
+ return CreationCommandRegistry.getInstance(org.eclipse.papyrus.core.Activator.PLUGIN_ID);
+ }
+
+}
diff --git a/plugins/views/modelexplorer/org.eclipse.papyrus.modelexplorer/src/org/eclipse/papyrus/modelexplorer/actionprovider/DiagramActionProvider.java b/plugins/views/modelexplorer/org.eclipse.papyrus.modelexplorer/src/org/eclipse/papyrus/modelexplorer/actionprovider/DiagramActionProvider.java
new file mode 100644
index 00000000000..abddd56690b
--- /dev/null
+++ b/plugins/views/modelexplorer/org.eclipse.papyrus.modelexplorer/src/org/eclipse/papyrus/modelexplorer/actionprovider/DiagramActionProvider.java
@@ -0,0 +1,75 @@
+/*******************************************************************************
+ * Copyright (c) 2009 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
+ * Vincent Lorenzo (vincent.lorenzo@cea.fr) - @deprecated
+ *******************************************************************************/
+package org.eclipse.papyrus.modelexplorer.actionprovider;
+
+import org.eclipse.gmf.runtime.notation.Diagram;
+import org.eclipse.jface.action.IMenuManager;
+import org.eclipse.papyrus.core.utils.EditorUtils;
+import org.eclipse.papyrus.modelexplorer.actions.CloseAllDiagramsAction;
+import org.eclipse.papyrus.modelexplorer.actions.CloseDiagramAction;
+import org.eclipse.papyrus.modelexplorer.actions.DeleteDiagramAction;
+import org.eclipse.papyrus.modelexplorer.actions.DuplicateDiagramAction;
+import org.eclipse.papyrus.modelexplorer.actions.OpenDiagramAction;
+import org.eclipse.papyrus.modelexplorer.actions.RenameDiagramAction;
+import org.eclipse.papyrus.sasheditor.contentprovider.IPageMngr;
+
+/**
+ * Provider used to create actions applicable on diagrams
+ *
+ * @author <a href="mailto:jerome.benois@obeo.fr">Jerome Benois</a>
+ */
+@Deprecated
+/**
+ * @deprecated use the command/handler/org.eclipse.ui.menus to do these actions
+ */
+public class DiagramActionProvider extends AbstractSubmenuActionProvider {
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void fillContextMenu(IMenuManager menu) {
+ Object selectedElement = resolveSemanticObject(getFirstSelectedElement());
+
+ if(selectedElement != null && selectedElement instanceof Diagram) {
+ Diagram diagram = (Diagram)selectedElement;
+ // Get the Editor IPageMngr. It should be Transactional.
+ IPageMngr pageMngr = EditorUtils.getIPageMngr();
+
+ // Create Rename Diagram action
+ RenameDiagramAction renameDiagramAction = new RenameDiagramAction(diagram);
+ menu.add(renameDiagramAction);
+
+ // Create Delete Diagram action
+ OpenDiagramAction openDiagramAction = new OpenDiagramAction(pageMngr, diagram);
+ menu.add(openDiagramAction);
+
+ // Create Delete Diagram action
+ CloseDiagramAction closeDiagramAction = new CloseDiagramAction(pageMngr, diagram);
+ menu.add(closeDiagramAction);
+
+ // Create Close all diagrams action
+ // fjcano #287948 :: close all diagrams action
+ CloseAllDiagramsAction closeAllDiagramsAction = new CloseAllDiagramsAction(pageMngr);
+ menu.add(closeAllDiagramsAction);
+
+ // Create Delete Diagram action
+ DeleteDiagramAction deleteDiagramAction = new DeleteDiagramAction(pageMngr, diagram);
+ menu.add(deleteDiagramAction);
+
+ // Create Duplicate Diagram action
+ DuplicateDiagramAction duplicateDiagramAction = new DuplicateDiagramAction(pageMngr, diagram);
+ menu.add(duplicateDiagramAction);
+ }
+ }
+
+}
diff --git a/plugins/views/modelexplorer/org.eclipse.papyrus.modelexplorer/src/org/eclipse/papyrus/modelexplorer/actionprovider/EditingDomainActionProvider.java b/plugins/views/modelexplorer/org.eclipse.papyrus.modelexplorer/src/org/eclipse/papyrus/modelexplorer/actionprovider/EditingDomainActionProvider.java
new file mode 100644
index 00000000000..d0c56d82cd4
--- /dev/null
+++ b/plugins/views/modelexplorer/org.eclipse.papyrus.modelexplorer/src/org/eclipse/papyrus/modelexplorer/actionprovider/EditingDomainActionProvider.java
@@ -0,0 +1,295 @@
+/*******************************************************************************
+ * Copyright (c) 2009 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
+ * Emilien Perico - use extension point to define dynamically registered actions
+ *******************************************************************************/
+package org.eclipse.papyrus.modelexplorer.actionprovider;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.eclipse.core.runtime.IConfigurationElement;
+import org.eclipse.core.runtime.Platform;
+import org.eclipse.emf.transaction.TransactionalEditingDomain;
+import org.eclipse.jface.action.Action;
+import org.eclipse.jface.action.ActionContributionItem;
+import org.eclipse.jface.action.IMenuManager;
+import org.eclipse.jface.action.Separator;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.jface.viewers.StructuredSelection;
+import org.eclipse.papyrus.core.utils.EditorUtils;
+import org.eclipse.papyrus.modelexplorer.factory.IActionHandlerFactory;
+import org.eclipse.ui.IActionBars;
+import org.eclipse.ui.navigator.CommonNavigator;
+import org.eclipse.ui.navigator.ICommonActionExtensionSite;
+import org.osgi.framework.Bundle;
+
+/**
+ * Provider used to create actions applicable on semantic elements
+ *
+ * @author <a href="mailto:jerome.benois@obeo.fr">Jerome Benois</a>
+ * @author Emilien Perico - see extension point
+ * org.eclipse.papyrus.navigator.actionHandler to add specific action
+ */
+public class EditingDomainActionProvider extends AbstractSubmenuActionProvider {
+
+ public static final String ACTION_HANDLER_EXTENSION_POINT_ID = "org.eclipse.papyrus.modelexplorer.actionHandler";
+
+ protected CommonNavigator activeViewPart;
+
+ protected Map<IActionHandlerFactory, ActionProperties> actionsFactoriesMap;
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void init(ICommonActionExtensionSite site) {
+ super.init(site);
+
+ this.activeViewPart = getCommonNavigator();
+ this.actionsFactoriesMap = new HashMap<IActionHandlerFactory, ActionProperties>();
+ TransactionalEditingDomain editingDomain = EditorUtils
+ .getTransactionalEditingDomain();
+
+ IConfigurationElement[] registry = Platform.getExtensionRegistry()
+ .getConfigurationElementsFor(ACTION_HANDLER_EXTENSION_POINT_ID);
+ for (IConfigurationElement elt : registry) {
+ try {
+ final String actionId = elt.getAttribute("actionId");
+ final String afterAction = elt.getAttribute("afterAction");
+ boolean needSeparator = Boolean.valueOf(elt
+ .getAttribute("needSeparator"));
+ ActionProperties properties = new ActionProperties(actionId,
+ afterAction, needSeparator);
+
+ IActionHandlerFactory factory = (IActionHandlerFactory) createExtension(
+ elt, elt.getAttribute("actionHandler"));
+ // create registered actions
+ factory.createActions(editingDomain);
+
+ actionsFactoriesMap.put(factory, properties);
+ } catch (Exception exception) {
+ exception.printStackTrace();
+ }
+ }
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void fillActionBars(IActionBars actionBars) {
+ super.fillActionBars(actionBars);
+ for (IActionHandlerFactory factory : actionsFactoriesMap.keySet()) {
+ factory.fillActionBars(actionBars);
+ }
+ }
+
+ /**
+ * Load an instance of a class
+ *
+ * @param element
+ * the extension point
+ * @param classAttribute
+ * the name of the class to load
+ * @return the loaded Class
+ * @throws Exception
+ * if the class is not loaded
+ */
+ @SuppressWarnings("rawtypes")
+ private static Object createExtension(final IConfigurationElement element,
+ final String classAttribute) throws Exception {
+ try {
+ Bundle extensionBundle = Platform.getBundle(element
+ .getDeclaringExtension().getNamespaceIdentifier());
+ Class clazz = extensionBundle.loadClass(classAttribute);
+ Object obj = clazz.newInstance();
+ return obj;
+ // return element.createExecutableExtension(classAttribute);
+ } catch (Exception e) {
+ throw new Exception("unable to create Extension " + e);
+ }
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void fillContextMenu(IMenuManager menu) {
+ update();
+ // sort factories from "afterAction" property
+ List<IActionHandlerFactory> sortedFactories = sortFactories(actionsFactoriesMap);
+
+ // Add the edit menu actions
+ for (IActionHandlerFactory factory : sortedFactories) {
+ ActionProperties actionProperties = actionsFactoriesMap
+ .get(factory);
+ if (actionProperties != null && actionProperties.isNeedSeparator()) {
+ menu.add(new Separator());
+ }
+ for (Action action : factory.getActions()) {
+ menu.add(new ActionContributionItem(action));
+ }
+ }
+ activate();
+ }
+
+ /**
+ * Update actions
+ */
+ public void update() {
+ ISelection selection = getCommonNavigator().getCommonViewer()
+ .getSelection();
+ IStructuredSelection structuredSelection = StructuredSelection.EMPTY;
+ if (selection instanceof IStructuredSelection) {
+ structuredSelection = (IStructuredSelection) selection;
+ }
+
+ for (IActionHandlerFactory factory : actionsFactoriesMap.keySet()) {
+ factory.update(structuredSelection);
+ }
+ }
+
+ /**
+ * Activate actions
+ */
+ public void activate() {
+ for (IActionHandlerFactory factory : actionsFactoriesMap.keySet()) {
+ factory.activate(activeViewPart);
+ }
+ update();
+ }
+
+ /**
+ * Deactivate actions
+ */
+ // @unused
+ public void deactivate() {
+ for (IActionHandlerFactory factory : actionsFactoriesMap.keySet()) {
+ factory.deactivate(activeViewPart);
+ }
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void updateActionBars() {
+ super.updateActionBars();
+ activate();
+ update();
+ }
+
+ /**
+ * Sort factories.
+ *
+ * @param actionsFactoriesMap
+ * the actions factories map
+ *
+ * @return the sorted list of factories
+ */
+ private List<IActionHandlerFactory> sortFactories(
+ final Map<IActionHandlerFactory, ActionProperties> actionsFactoriesMap) {
+
+ List<IActionHandlerFactory> factories = new ArrayList<IActionHandlerFactory>(
+ actionsFactoriesMap.keySet());
+
+ Collections.sort(factories, new Comparator<IActionHandlerFactory>() {
+
+ public int compare(IActionHandlerFactory factory1,
+ IActionHandlerFactory factory2) {
+
+ ActionProperties properties1 = getDefaultForNull(actionsFactoriesMap
+ .get(factory1));
+ ActionProperties properties2 = getDefaultForNull(actionsFactoriesMap
+ .get(factory2));
+ String after1 = properties1.getAfterAction();
+ String after2 = properties2.getAfterAction();
+
+ if (properties1.getActionId().equals(properties2.getActionId())) {
+ return 0;
+ } else if (properties1.getActionId().equals(after2)) {
+ return -1;
+ } else if (properties2.getActionId().equals(after1)) {
+ return 1;
+ } else if (after1 == null) {
+ return -1;
+ } else if (after2 == null) {
+ return 1;
+ }
+ return 0;
+ }
+
+ private ActionProperties getDefaultForNull(
+ ActionProperties actionProperties) {
+ if (actionProperties == null) {
+ actionProperties = new ActionProperties("", "", false);
+ }
+ return actionProperties;
+ }
+ });
+
+ return factories;
+ }
+
+ /**
+ * The Class ActionProperties to store properties for a registered action
+ * from extension point org.eclipse.papyrus.navigator.actionHandler
+ */
+ private class ActionProperties {
+
+ private final String actionId;
+
+ private final String afterAction;
+
+ private final boolean needSeparator;
+
+ /**
+ * @param actionId
+ * @param afterAction
+ * @param needSeparator
+ */
+ // @unused
+ public ActionProperties(String actionId, String afterAction,
+ boolean needSeparator) {
+ super();
+ this.actionId = actionId;
+ this.afterAction = afterAction;
+ this.needSeparator = needSeparator;
+ }
+
+ /**
+ * @return the actionId
+ */
+ public String getActionId() {
+ return actionId;
+ }
+
+ /**
+ * @return the afterAction
+ */
+ public String getAfterAction() {
+ return afterAction;
+ }
+
+ /**
+ * @return the needSeparator
+ */
+ public boolean isNeedSeparator() {
+ return needSeparator;
+ }
+
+ }
+
+}
diff --git a/plugins/views/modelexplorer/org.eclipse.papyrus.modelexplorer/src/org/eclipse/papyrus/modelexplorer/actionprovider/GenericTransformActionProvider.java b/plugins/views/modelexplorer/org.eclipse.papyrus.modelexplorer/src/org/eclipse/papyrus/modelexplorer/actionprovider/GenericTransformActionProvider.java
new file mode 100644
index 00000000000..4b7477bd4e8
--- /dev/null
+++ b/plugins/views/modelexplorer/org.eclipse.papyrus.modelexplorer/src/org/eclipse/papyrus/modelexplorer/actionprovider/GenericTransformActionProvider.java
@@ -0,0 +1,219 @@
+/***************************************************
+ * Copyright (c) 2010 Atos Origin.
+
+ *
+ * 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:
+ * Atos Origin - Initial API and implementation
+ *
+ ****************************************************/
+package org.eclipse.papyrus.modelexplorer.actionprovider;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import org.eclipse.emf.common.notify.AdapterFactory;
+import org.eclipse.emf.common.util.URI;
+import org.eclipse.emf.converter.util.ConverterUtil;
+import org.eclipse.emf.ecore.EClass;
+import org.eclipse.emf.ecore.EClassifier;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.ecore.EPackage;
+import org.eclipse.emf.ecore.EStructuralFeature;
+import org.eclipse.emf.ecore.resource.Resource;
+import org.eclipse.emf.ecore.util.EcoreUtil;
+import org.eclipse.emf.edit.provider.IItemLabelProvider;
+import org.eclipse.emf.edit.ui.provider.ExtendedImageRegistry;
+import org.eclipse.jface.action.Action;
+import org.eclipse.jface.action.IAction;
+import org.eclipse.jface.action.IMenuManager;
+import org.eclipse.jface.action.MenuManager;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.papyrus.modelexplorer.actions.GenericTransformAction;
+import org.eclipse.papyrus.modelexplorer.actions.GenericTransformer;
+
+/**
+ * GenericTransformActionProvider class provides GenericTransformAction actions
+ * available for a given element.
+ */
+public class GenericTransformActionProvider extends
+ AbstractSubmenuActionProvider {
+
+ /** Group label */
+ private static final String TRANSFORM_INTO_LABEL = "Transform into";
+
+ /** The factories of appropriate EClass */
+ private Map<String, AdapterFactory> factories = new HashMap<String, AdapterFactory>();
+
+ /** The appropriate EClass for element's transformation */
+ private Set<EClassifier> eClassifiers = new HashSet<EClassifier>();
+
+ /**
+ * Adds all actions to transform an EObject
+ */
+ @Override
+ public void fillContextMenu(IMenuManager menu) {
+ super.fillContextMenu(menu);
+ ISelection selection = getContext().getSelection();
+ if (selection instanceof IStructuredSelection
+ && ((IStructuredSelection) selection).size() == 1) {
+ Object selectedElement = resolveSemanticObject(((IStructuredSelection) selection)
+ .getFirstElement());
+ if (selectedElement != null && selectedElement instanceof EObject) {
+ fillEClassifiers((EObject) selectedElement);
+ }
+ }
+
+ Collection<IAction> genericTransformActions = generateTransformActions(selection);
+ MenuManager submenuManager = new MenuManager(TRANSFORM_INTO_LABEL);
+ populateManager(submenuManager, genericTransformActions, null);
+ menu.add(submenuManager);
+ }
+
+ /**
+ * From an EObject we get the epackage corresponding to the resource
+ * extension of the file and get the imported epackage correspondant
+ *
+ * @param selectionEObject
+ */
+ private void fillEClassifiers(EObject selectionEObject) {
+ Resource r = selectionEObject.eResource();
+ URI uri = r.getURI();
+ String extension = uri.fileExtension();
+ for (Object p : EPackage.Registry.INSTANCE.values()) {
+ if (p instanceof EPackage) {
+ EPackage pack = (EPackage) p;
+ if (pack.getNsPrefix() != null
+ && extension.toLowerCase().equals(
+ pack.getNsPrefix().toLowerCase())) {
+ addClassifiers(pack, eClassifiers);
+ factories.put(pack.getNsURI(), GenericTransformer
+ .getFactory(pack.getNsURI()));
+ List<EPackage> packages = ConverterUtil
+ .computeRequiredPackages(pack);
+ for (EPackage pTmp : packages) {
+ addClassifiers(pTmp, eClassifiers);
+ factories.put(pTmp.getNsURI(), GenericTransformer
+ .getFactory(pTmp.getNsURI()));
+ }
+ break;
+ }
+ }
+ }
+
+ }
+
+ /**
+ * Register all classifiers contained in the package
+ *
+ * @param pack
+ * the package
+ * @param result
+ * results at which classifiers must be added
+ */
+ private void addClassifiers(EPackage pack, Set<EClassifier> result) {
+ for (EClassifier c : pack.getEClassifiers()) {
+ result.add(c);
+ }
+ }
+
+ /**
+ * Generate the sorted list of transformation actions.
+ *
+ * @param descriptors
+ * the descriptors
+ * @param selection
+ * the selection
+ *
+ * @return the collection< i action>
+ */
+ protected Collection<IAction> generateTransformActions(ISelection selection) {
+ List<IAction> transformActions = (List<IAction>) generateTransformActionsCore(selection);
+
+ Collections.<IAction> sort(transformActions, new Comparator<IAction>() {
+
+ public int compare(IAction a1, IAction a2) {
+ return a1.getText().compareTo(a2.getText());
+ }
+ });
+
+ return transformActions;
+ }
+
+ /**
+ * Generate transformation actions.
+ *
+ * @param descriptors
+ * the descriptors
+ * @param selection
+ * the selection
+ *
+ * @return the collection< i action>
+ */
+ protected Collection<IAction> generateTransformActionsCore(
+ ISelection selection) {
+ Collection<IAction> actions = new ArrayList<IAction>();
+ if (eClassifiers != null) {
+ for (EClassifier descriptor : eClassifiers) {
+ Object selected = ((IStructuredSelection) selection)
+ .getFirstElement();
+ if (selected instanceof EObject) {
+ final EObject selectedElement = (EObject) selected;
+ if (descriptor instanceof EClass
+ && selectedElement.eContainingFeature() != null) {
+ final EClass eclass = (EClass) descriptor;
+ EStructuralFeature containingFeature = selectedElement
+ .eContainingFeature();
+ // to be candidate an eclass has to have a common
+ // parent, to not be the selection
+ // and to not be abstract
+ EClass containgType = (EClass) containingFeature
+ .getEType();
+ if ((GenericTransformer.getAllSuperTypes(eclass)
+ .contains(containgType) || EcoreUtil.equals(
+ eclass, containgType))
+ && !eclass.equals(selectedElement.eClass())
+ && !eclass.isAbstract()) {
+ if (selection instanceof IStructuredSelection
+ && ((IStructuredSelection) selection)
+ .size() == 1) {
+
+ AdapterFactory adapterFactory = factories
+ .get(eclass.getEPackage().getNsURI());
+ Action transformAction = new GenericTransformAction(
+ eclass, adapterFactory, selectedElement);
+ actions.add(transformAction);
+ if (adapterFactory != null) {
+ EObject tmpEobject = eclass.getEPackage()
+ .getEFactoryInstance().create(
+ eclass);
+ IItemLabelProvider provider = (IItemLabelProvider) adapterFactory
+ .adapt(tmpEobject,
+ IItemLabelProvider.class);
+ transformAction
+ .setImageDescriptor(ExtendedImageRegistry.INSTANCE
+ .getImageDescriptor(provider
+ .getImage(tmpEobject)));
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ return actions;
+ }
+
+}
diff --git a/plugins/views/modelexplorer/org.eclipse.papyrus.modelexplorer/src/org/eclipse/papyrus/modelexplorer/actions/CloseAllDiagramsAction.java b/plugins/views/modelexplorer/org.eclipse.papyrus.modelexplorer/src/org/eclipse/papyrus/modelexplorer/actions/CloseAllDiagramsAction.java
new file mode 100644
index 00000000000..dbefd664e5c
--- /dev/null
+++ b/plugins/views/modelexplorer/org.eclipse.papyrus.modelexplorer/src/org/eclipse/papyrus/modelexplorer/actions/CloseAllDiagramsAction.java
@@ -0,0 +1,71 @@
+/*******************************************************************************
+ * Copyright (c) 2009 Conselleria de Infraestructuras y Transporte, Generalitat
+ * de la Comunitat Valenciana . 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: Francisco Javier Cano Muñoz (Prodevelop) - Initial implementation
+ * Vincent Lorenzo (vincent.lorenzo@cea.fr) - @deprecated
+ ******************************************************************************/
+package org.eclipse.papyrus.modelexplorer.actions;
+
+import org.eclipse.jface.action.Action;
+import org.eclipse.papyrus.modelexplorer.handler.CloseHandler;
+import org.eclipse.papyrus.sasheditor.contentprovider.IPageMngr;
+import org.eclipse.ui.ISharedImages;
+import org.eclipse.ui.PlatformUI;
+
+/**
+ * Action used to close all open diagrams.
+ *
+ * @author <a href="mailto:fjcano@prodevelop.es">Francisco Javier Cano
+ * Muñoz</a>
+ * @see <a href="https://bugs.eclipse.org/bugs/show_bug.cgi?id=287948">Bug #287948</a>
+ *
+ * @deprecated
+ * you should use {@link CloseHandler}
+ */
+@Deprecated
+public class CloseAllDiagramsAction extends Action {
+
+ IPageMngr pageMngr;
+
+ protected IPageMngr getPageMngr() {
+ return pageMngr;
+ }
+
+ public CloseAllDiagramsAction(IPageMngr pageMngr) {
+ if(pageMngr == null) {
+ throw new IllegalArgumentException("An IPageMngr must be specified");
+ }
+ this.pageMngr = pageMngr;
+ ISharedImages sharedImages = PlatformUI.getWorkbench().getSharedImages();
+ setImageDescriptor(sharedImages.getImageDescriptor(ISharedImages.IMG_TOOL_CUT));
+ setText("Close all diagrams");
+ // this action is enabled when there is at least one diagram open.
+ boolean aDiagramIsOpen = false;
+ for(Object identifier : pageMngr.allPages()) {
+ if(pageMngr.isOpen(identifier)) {
+ aDiagramIsOpen = true;
+ }
+ }
+ setEnabled(aDiagramIsOpen);
+ }
+
+ /**
+ * Delete the given diagram
+ *
+ * @see org.eclipse.jface.action.Action#run()
+ */
+ @Override
+ public void run() {
+ // close all open diagrams
+ for(Object identifier : pageMngr.allPages()) {
+ if(getPageMngr().isOpen(identifier)) {
+ getPageMngr().closePage(identifier);
+ }
+ }
+ }
+
+}
diff --git a/plugins/views/modelexplorer/org.eclipse.papyrus.modelexplorer/src/org/eclipse/papyrus/modelexplorer/actions/CloseDiagramAction.java b/plugins/views/modelexplorer/org.eclipse.papyrus.modelexplorer/src/org/eclipse/papyrus/modelexplorer/actions/CloseDiagramAction.java
new file mode 100644
index 00000000000..9a9401048e7
--- /dev/null
+++ b/plugins/views/modelexplorer/org.eclipse.papyrus.modelexplorer/src/org/eclipse/papyrus/modelexplorer/actions/CloseDiagramAction.java
@@ -0,0 +1,57 @@
+/*****************************************************************************
+ * Copyright (c) 2010 CEA LIST.
+ *
+ *
+ * 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:
+ * Patrick Tessier (CEA LIST) Patrick.tessier@cea.fr - Initial API and implementation
+ * Vincent Lorenzo (vincent.lorenzo@cea.fr) - @deprecated
+ *****************************************************************************/
+
+package org.eclipse.papyrus.modelexplorer.actions;
+
+import org.eclipse.gmf.runtime.notation.Diagram;
+import org.eclipse.jface.action.Action;
+import org.eclipse.papyrus.modelexplorer.handler.CloseHandler;
+import org.eclipse.papyrus.sasheditor.contentprovider.IPageMngr;
+import org.eclipse.ui.ISharedImages;
+import org.eclipse.ui.PlatformUI;
+
+/**
+ * Action used to open the given diagram
+ *
+ * @author cedric dumoulin
+ * @deprecated you should use {@link CloseHandler}
+ */
+@Deprecated
+public class CloseDiagramAction extends Action {
+
+ Diagram diagram;
+
+ IPageMngr pageMngr;
+
+ public CloseDiagramAction(IPageMngr pageMngr, Diagram diagram) {
+ this.diagram = diagram;
+ this.pageMngr = pageMngr;
+
+ ISharedImages sharedImages = PlatformUI.getWorkbench().getSharedImages();
+ setImageDescriptor(sharedImages.getImageDescriptor(ISharedImages.IMG_TOOL_CUT));
+ setText("Close");
+ setEnabled(pageMngr.isOpen(diagram));
+ }
+
+ /**
+ * Delete the given diagram
+ *
+ * @see org.eclipse.jface.action.Action#run()
+ */
+ @Override
+ public void run() {
+
+ pageMngr.closePage(diagram);
+ }
+}
diff --git a/plugins/views/modelexplorer/org.eclipse.papyrus.modelexplorer/src/org/eclipse/papyrus/modelexplorer/actions/CreateDiagramAction.java b/plugins/views/modelexplorer/org.eclipse.papyrus.modelexplorer/src/org/eclipse/papyrus/modelexplorer/actions/CreateDiagramAction.java
new file mode 100644
index 00000000000..c606ef8f85f
--- /dev/null
+++ b/plugins/views/modelexplorer/org.eclipse.papyrus.modelexplorer/src/org/eclipse/papyrus/modelexplorer/actions/CreateDiagramAction.java
@@ -0,0 +1,88 @@
+/*******************************************************************************
+ * Copyright (c) 2009 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.papyrus.modelexplorer.actions;
+
+import static org.eclipse.papyrus.modelexplorer.Activator.log;
+
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.jface.action.Action;
+import org.eclipse.papyrus.core.extension.NotFoundException;
+import org.eclipse.papyrus.core.extension.commands.CreationCommandDescriptor;
+import org.eclipse.papyrus.core.extension.commands.CreationCommandRegistry;
+import org.eclipse.papyrus.core.extension.commands.ICreationCommand;
+import org.eclipse.papyrus.core.extension.commands.ICreationCommandRegistry;
+import org.eclipse.papyrus.core.utils.EditorUtils;
+
+/**
+ * Action used to create a new diagram for given type modified to remove link
+ * toUML
+ *
+ * @deprecated
+ */
+public class CreateDiagramAction extends Action {
+
+ private final EObject container;
+
+ private final CreationCommandDescriptor commandDescriptor;
+
+ /**
+ * Constructor
+ *
+ * @param selectedObject
+ * the selected Element on which the diagram is to be associated
+ */
+ public CreateDiagramAction(EObject eObject, CreationCommandDescriptor commandDescriptor) {
+ this.container = eObject;
+ this.commandDescriptor = commandDescriptor;
+ setText(commandDescriptor.getLabel());
+ setImageDescriptor(commandDescriptor.getIcon());
+ }
+
+ /**
+ * @see org.eclipse.jface.action.Action#isEnabled()
+ */
+ @Override
+ public boolean isEnabled() {
+ return container != null;
+ }
+
+ /**
+ * This methods creates a new Diagram to be associated with the given domain
+ * element
+ *
+ * @see org.eclipse.jface.action.Action#run()
+ */
+ @Override
+ public void run() {
+
+ // Start LOG
+ if(log.isDebugEnabled()) {
+ log.debug("Start - CreateDiagramAction#run"); //$NON-NLS-1$
+ }
+
+ try {
+ ICreationCommand creationCommand = getCreationCommandRegistry().getCommand(commandDescriptor.getCommandId());
+ creationCommand.createDiagram(EditorUtils.getDiResourceSet(), container, null);
+ } catch (NotFoundException e) {
+ log.error(e);
+ }
+
+ // END LOG
+ if(log.isDebugEnabled()) {
+ log.debug("End - CreateDiagramAction#run"); //$NON-NLS-1$
+ }
+ }
+
+ private static ICreationCommandRegistry getCreationCommandRegistry() {
+ return CreationCommandRegistry.getInstance(org.eclipse.papyrus.core.Activator.PLUGIN_ID);
+ }
+
+}
diff --git a/plugins/views/modelexplorer/org.eclipse.papyrus.modelexplorer/src/org/eclipse/papyrus/modelexplorer/actions/CreateQueryAction.java b/plugins/views/modelexplorer/org.eclipse.papyrus.modelexplorer/src/org/eclipse/papyrus/modelexplorer/actions/CreateQueryAction.java
new file mode 100644
index 00000000000..d7173b6f1d8
--- /dev/null
+++ b/plugins/views/modelexplorer/org.eclipse.papyrus.modelexplorer/src/org/eclipse/papyrus/modelexplorer/actions/CreateQueryAction.java
@@ -0,0 +1,64 @@
+/*****************************************************************************
+ * Copyright (c) 2010 CEA LIST.
+ *
+ *
+ * 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:
+ * Patrick Tessier (CEA LIST) Patrick.tessier@cea.fr - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.modelexplorer.actions;
+
+import java.util.ArrayList;
+import java.util.Iterator;
+
+import org.eclipse.core.runtime.IAdaptable;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.jface.action.IAction;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.jface.viewers.StructuredSelection;
+
+public class CreateQueryAction extends
+ org.eclipse.emf.facet.infra.query.ui.actions.CreateQueryAction {
+
+ public CreateQueryAction() {
+ // nothing here
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @SuppressWarnings("rawtypes")
+ public void selectionChanged(final IAction action,
+ final ISelection selection) {
+ if (selection instanceof IStructuredSelection) {
+ ArrayList<EObject> select = new ArrayList<EObject>();
+ Iterator iterator = ((IStructuredSelection) selection).toList()
+ .iterator();
+ while (iterator.hasNext()) {
+ Object object = (Object) iterator.next();
+ if (object instanceof IAdaptable) {
+ EObject eObject = (EObject) ((IAdaptable) object)
+ .getAdapter(EObject.class);
+ if (eObject != null) {
+ select.add(eObject);
+ }
+
+ }
+
+ }
+ if (select.size() > 0) {
+ super.selectionChanged(action, new StructuredSelection(select));
+ } else {
+ super.selectionChanged(action, new StructuredSelection(
+ selection));
+ }
+ }
+
+ }
+}
diff --git a/plugins/views/modelexplorer/org.eclipse.papyrus.modelexplorer/src/org/eclipse/papyrus/modelexplorer/actions/DeleteDiagramAction.java b/plugins/views/modelexplorer/org.eclipse.papyrus.modelexplorer/src/org/eclipse/papyrus/modelexplorer/actions/DeleteDiagramAction.java
new file mode 100644
index 00000000000..8f69abf8e13
--- /dev/null
+++ b/plugins/views/modelexplorer/org.eclipse.papyrus.modelexplorer/src/org/eclipse/papyrus/modelexplorer/actions/DeleteDiagramAction.java
@@ -0,0 +1,82 @@
+/*******************************************************************************
+ * Copyright (c) 2009 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
+ * Vincent Lorenzo (vincent.lorenzo@cea.fr) - @deprecated
+ *******************************************************************************/
+package org.eclipse.papyrus.modelexplorer.actions;
+
+import org.eclipse.emf.common.command.Command;
+import org.eclipse.emf.common.command.CompoundCommand;
+import org.eclipse.emf.common.util.EList;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.edit.command.RemoveCommand;
+import org.eclipse.emf.transaction.RecordingCommand;
+import org.eclipse.emf.transaction.TransactionalEditingDomain;
+import org.eclipse.gmf.runtime.notation.Diagram;
+import org.eclipse.jface.action.Action;
+import org.eclipse.papyrus.core.utils.EditorUtils;
+import org.eclipse.papyrus.modelexplorer.handler.DeleteDiagramHandler;
+import org.eclipse.papyrus.sasheditor.contentprovider.IPageMngr;
+import org.eclipse.ui.ISharedImages;
+import org.eclipse.ui.PlatformUI;
+
+/**
+ * Action used to delete the given diagram
+ *
+ * @author <a href="mailto:jerome.benois@obeo.fr">Jerome Benois</a>
+ * @author cedric dumoulin
+ * @deprecated you should use {@link DeleteDiagramHandler}
+ */
+@Deprecated
+public class DeleteDiagramAction extends Action {
+
+ Diagram diagram;
+
+ IPageMngr pageMngr;
+
+ public DeleteDiagramAction(IPageMngr pageMngr, Diagram diagram) {
+ this.diagram = diagram;
+ this.pageMngr = pageMngr;
+
+ ISharedImages sharedImages = PlatformUI.getWorkbench().getSharedImages();
+ setImageDescriptor(sharedImages.getImageDescriptor(ISharedImages.IMG_TOOL_DELETE));
+ setText("Delete");
+ setEnabled(true);
+ }
+
+ /**
+ * Delete the given diagram
+ *
+ * @see org.eclipse.jface.action.Action#run()
+ */
+ @Override
+ public void run() {
+ TransactionalEditingDomain editingDomain = EditorUtils.getTransactionalEditingDomain();
+ if(editingDomain != null) {
+
+ // Create a compound command containing removing of the sash and
+ // removing from GMF
+ // resource.
+ CompoundCommand command = new CompoundCommand();
+ Command sashRemoveComd = new RecordingCommand(editingDomain) {
+
+ @Override
+ protected void doExecute() {
+ pageMngr.removePage(diagram);
+ }
+ };
+
+ EList<EObject> diagrams = diagram.eResource().getContents();
+ // TODO : synchronize with Cedric
+ command.append(sashRemoveComd);
+ command.append(new RemoveCommand(editingDomain, diagrams, diagram));
+ editingDomain.getCommandStack().execute(command);
+ }
+ }
+}
diff --git a/plugins/views/modelexplorer/org.eclipse.papyrus.modelexplorer/src/org/eclipse/papyrus/modelexplorer/actions/DuplicateDiagramAction.java b/plugins/views/modelexplorer/org.eclipse.papyrus.modelexplorer/src/org/eclipse/papyrus/modelexplorer/actions/DuplicateDiagramAction.java
new file mode 100644
index 00000000000..960df68b9dd
--- /dev/null
+++ b/plugins/views/modelexplorer/org.eclipse.papyrus.modelexplorer/src/org/eclipse/papyrus/modelexplorer/actions/DuplicateDiagramAction.java
@@ -0,0 +1,92 @@
+/*******************************************************************************
+ * Copyright (c) 2009 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
+ * Vincent Lorenzo (vincent.lorenzo@cea.fr) - @deprecated
+ *******************************************************************************/
+package org.eclipse.papyrus.modelexplorer.actions;
+
+import org.eclipse.emf.common.command.Command;
+import org.eclipse.emf.common.command.CompoundCommand;
+import org.eclipse.emf.ecore.util.EcoreUtil;
+import org.eclipse.emf.edit.command.AddCommand;
+import org.eclipse.emf.transaction.RecordingCommand;
+import org.eclipse.emf.transaction.TransactionalEditingDomain;
+import org.eclipse.gmf.runtime.notation.Diagram;
+import org.eclipse.jface.action.Action;
+import org.eclipse.papyrus.core.utils.EditorUtils;
+import org.eclipse.papyrus.modelexplorer.Activator;
+import org.eclipse.papyrus.sasheditor.contentprovider.IPageMngr;
+
+/**
+ * Action used to duplicate the given diagram
+ *
+ * @author <a href="mailto:jerome.benois@obeo.fr">Jerome Benois</a>
+ * @deprecated you should use DuplicateDiagramHandler
+ */
+@Deprecated
+public class DuplicateDiagramAction extends Action {
+
+ Diagram diagram;
+
+ IPageMngr pageMngr;
+
+ public DuplicateDiagramAction(IPageMngr pageMngr, Diagram diagram) {
+ this.diagram = diagram;
+ this.pageMngr = pageMngr;
+
+ setImageDescriptor(Activator.getImageDescriptor("icons/etool16/duplicate.png"));
+ setText("Duplicate");
+ setEnabled(true);
+ }
+
+ /**
+ * Duplicate the given diagram
+ *
+ * @see org.eclipse.jface.action.Action#run()
+ */
+ @Override
+ public void run() {
+ TransactionalEditingDomain editingDomain = EditorUtils.getTransactionalEditingDomain();
+ if(editingDomain != null) {
+
+ // Create a compound command containing removing of the sash and
+ // removing from GMF
+ // resource.
+ CompoundCommand command = new CompoundCommand();
+
+ // Clone the current diagram
+ final Diagram newDiagram = EcoreUtil.copy(diagram);
+ // Give a new name
+ newDiagram.setName("Copy of " + diagram.getName());
+
+ Command addGmfDiagramCmd = new AddCommand(editingDomain, diagram.eResource().getContents(), newDiagram);
+ // EMFCommandOperation operation = new
+ // EMFCommandOperation(editingDomain,
+ // addGmfDiagramCmd);
+
+ Command sashOpenComd = new RecordingCommand(editingDomain) {
+
+ @Override
+ protected void doExecute() {
+ pageMngr.openPage(newDiagram);
+ }
+ };
+
+ // TODO : synchronize with Cedric
+ // command.append(operation.getCommand());
+ command.append(addGmfDiagramCmd);
+ command.append(sashOpenComd);
+ // Execute changes through a Command so that Undo/Redo is supported
+ editingDomain.getCommandStack().execute(command);
+
+ }
+
+ }
+
+}
diff --git a/plugins/views/modelexplorer/org.eclipse.papyrus.modelexplorer/src/org/eclipse/papyrus/modelexplorer/actions/ExecuteQueryAction.java b/plugins/views/modelexplorer/org.eclipse.papyrus.modelexplorer/src/org/eclipse/papyrus/modelexplorer/actions/ExecuteQueryAction.java
new file mode 100644
index 00000000000..417f5213756
--- /dev/null
+++ b/plugins/views/modelexplorer/org.eclipse.papyrus.modelexplorer/src/org/eclipse/papyrus/modelexplorer/actions/ExecuteQueryAction.java
@@ -0,0 +1,70 @@
+/*****************************************************************************
+ * Copyright (c) 2010 CEA LIST.
+ *
+ *
+ * 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:
+ * Patrick Tessier (CEA LIST) Patrick.tessier@cea.fr - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.modelexplorer.actions;
+
+import java.util.ArrayList;
+import java.util.Iterator;
+
+import org.eclipse.core.runtime.IAdaptable;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.jface.action.IAction;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.jface.viewers.StructuredSelection;
+
+/**
+ * This class is used to execute an action (modisco query)
+ */
+public class ExecuteQueryAction extends
+ org.eclipse.emf.facet.infra.query.ui.actions.ExecuteQueryAction {
+
+ /**
+ * Create a new ExecuteQueryAction.
+ */
+ public ExecuteQueryAction() {
+ // nothing here
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @SuppressWarnings("rawtypes")
+ public void selectionChanged(final IAction action,
+ final ISelection selection) {
+ if (selection instanceof IStructuredSelection) {
+ ArrayList<EObject> select = new ArrayList<EObject>();
+ Iterator iterator = ((IStructuredSelection) selection).toList()
+ .iterator();
+ while (iterator.hasNext()) {
+ Object object = (Object) iterator.next();
+ if (object instanceof IAdaptable) {
+ EObject eObject = (EObject) ((IAdaptable) object)
+ .getAdapter(EObject.class);
+ if (eObject != null) {
+ select.add(eObject);
+ }
+
+ }
+
+ }
+ if (select.size() > 0) {
+ super.selectionChanged(action, new StructuredSelection(select));
+ } else {
+ super.selectionChanged(action, new StructuredSelection(
+ selection));
+ }
+ }
+
+ }
+}
diff --git a/plugins/views/modelexplorer/org.eclipse.papyrus.modelexplorer/src/org/eclipse/papyrus/modelexplorer/actions/GenericTransformAction.java b/plugins/views/modelexplorer/org.eclipse.papyrus.modelexplorer/src/org/eclipse/papyrus/modelexplorer/actions/GenericTransformAction.java
new file mode 100644
index 00000000000..e1dc6e4215a
--- /dev/null
+++ b/plugins/views/modelexplorer/org.eclipse.papyrus.modelexplorer/src/org/eclipse/papyrus/modelexplorer/actions/GenericTransformAction.java
@@ -0,0 +1,121 @@
+/***************************************************
+ * Copyright (c) 2010 Atos Origin.
+
+ *
+ * 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:
+ * Atos Origin - Initial API and implementation
+ *
+ ****************************************************/
+package org.eclipse.papyrus.modelexplorer.actions;
+
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.MultiStatus;
+import org.eclipse.emf.common.notify.AdapterFactory;
+import org.eclipse.emf.ecore.EClass;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.edit.provider.IItemLabelProvider;
+import org.eclipse.emf.edit.ui.provider.ExtendedImageRegistry;
+import org.eclipse.jface.action.Action;
+import org.eclipse.jface.dialogs.ErrorDialog;
+import org.eclipse.jface.dialogs.IDialogConstants;
+import org.eclipse.jface.dialogs.MessageDialog;
+import org.eclipse.jface.window.Window;
+import org.eclipse.papyrus.modelexplorer.Activator;
+import org.eclipse.papyrus.modelexplorer.preferences.INavigatorPreferenceConstants;
+import org.eclipse.papyrus.ui.toolbox.dialog.InformationDialog;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.widgets.Display;
+
+/**
+ * GenericTransformAction is an action which transforms and EObject by changing
+ * its eclass.
+ */
+public class GenericTransformAction extends Action {
+
+ /** title of error dialog */
+ private static final String ERROR_TITLE = "Impossible to continue transformation.";
+
+ /** message in error dialog */
+ private static final String ERROR_MESSAGE = "The transformation can not continue.\n"
+ + "Some objects referencing your selection could not be able to reference the result of the transformation.\n"
+ + "For UML and SysML, applied stereotypes could not be applicable on the result of the transformation.\n"
+ + "Before performing the transformation please delete or unapply the elements listed bellow.";
+
+ /** title of error dialog */
+ private static final String WARNING_TITLE = "Warning: transformation command";
+
+ /** WARNING_MESSAGE for transform command execution */
+ private static final String WARNING_MESSAGE = "You are trying to transform an element typed %s into %s.\nThis operation will copy all the common elements between the two eclasses.\nDo you want to continue ?";
+
+ /** The EClass to transform into. */
+ private EClass targetEClass = null;
+
+ /** The element to transform. */
+ private EObject element;
+
+ /**
+ * Constructor for a new action.
+ *
+ * @param transformationEClass
+ * the eclass element must be transformed into
+ * @param adapterFactory
+ * the adapter factory for providing label image
+ * @param elementToTransform
+ * the element to transform
+ */
+ public GenericTransformAction(EClass transformationEClass,
+ AdapterFactory adapterFactory, EObject elementToTransform) {
+ super(transformationEClass.getName());
+ targetEClass = transformationEClass;
+ element = elementToTransform;
+
+ if (adapterFactory != null) {
+ EObject tmpEobject = transformationEClass.getEPackage()
+ .getEFactoryInstance().create(transformationEClass);
+ IItemLabelProvider provider = (IItemLabelProvider) adapterFactory
+ .adapt(tmpEobject, IItemLabelProvider.class);
+ setImageDescriptor(ExtendedImageRegistry.INSTANCE
+ .getImageDescriptor(provider.getImage(tmpEobject)));
+ }
+ }
+
+ /**
+ * Transform the element and update referencing diagrams.
+ *
+ * @see org.eclipse.jface.action.Action#run()
+ */
+ @Override
+ public void run() {
+ GenericTransformer transformer = new GenericTransformer(element);
+ MultiStatus messages = transformer
+ .isTransformationPossible(targetEClass);
+ if (messages != null && messages.getChildren().length == 0) {
+ String message = String.format(WARNING_MESSAGE, this.element
+ .eClass().getName(), targetEClass.getName());
+ InformationDialog dialog = new InformationDialog(
+ Display.getDefault().getActiveShell(),
+ WARNING_TITLE,
+ message,
+ Activator.getDefault().getPreferenceStore(),
+ INavigatorPreferenceConstants.PREF_NAVIGATOR_TRANSFORM_INTO_SHOW_POPUP,
+ SWT.YES | SWT.NO, MessageDialog.INFORMATION, new String[] {
+ IDialogConstants.YES_LABEL,
+ IDialogConstants.NO_LABEL });
+ int result = dialog.open();
+ if (result == SWT.YES || result == Window.OK) {
+ transformer.transform(targetEClass);
+ }
+ } else {
+ ErrorDialog errorDialog = new ErrorDialog(Display.getDefault()
+ .getActiveShell(), ERROR_TITLE, ERROR_MESSAGE, messages,
+ IStatus.WARNING);
+ errorDialog.open();
+ }
+ }
+
+}
diff --git a/plugins/views/modelexplorer/org.eclipse.papyrus.modelexplorer/src/org/eclipse/papyrus/modelexplorer/actions/GenericTransformer.java b/plugins/views/modelexplorer/org.eclipse.papyrus.modelexplorer/src/org/eclipse/papyrus/modelexplorer/actions/GenericTransformer.java
new file mode 100644
index 00000000000..4d510fdbf94
--- /dev/null
+++ b/plugins/views/modelexplorer/org.eclipse.papyrus.modelexplorer/src/org/eclipse/papyrus/modelexplorer/actions/GenericTransformer.java
@@ -0,0 +1,489 @@
+/***************************************************
+ * Copyright (c) 2010 Atos Origin.
+
+ *
+ * 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:
+ * Atos Origin - Initial API and implementation
+ *
+ ****************************************************/
+package org.eclipse.papyrus.modelexplorer.actions;
+
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
+import org.eclipse.core.commands.ExecutionException;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IAdaptable;
+import org.eclipse.core.runtime.IConfigurationElement;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.MultiStatus;
+import org.eclipse.core.runtime.Platform;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.draw2d.geometry.Point;
+import org.eclipse.emf.common.notify.AdapterFactory;
+import org.eclipse.emf.ecore.EClass;
+import org.eclipse.emf.ecore.EClassifier;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.ecore.EReference;
+import org.eclipse.emf.ecore.EStructuralFeature;
+import org.eclipse.emf.ecore.EStructuralFeature.Setting;
+import org.eclipse.emf.ecore.util.ECrossReferenceAdapter;
+import org.eclipse.emf.edit.domain.AdapterFactoryEditingDomain;
+import org.eclipse.emf.transaction.TransactionalEditingDomain;
+import org.eclipse.gef.EditPart;
+import org.eclipse.gef.commands.Command;
+import org.eclipse.gef.commands.CommandStack;
+import org.eclipse.gef.editparts.AbstractGraphicalEditPart;
+import org.eclipse.gef.requests.GroupRequest;
+import org.eclipse.gmf.runtime.common.core.command.CommandResult;
+import org.eclipse.gmf.runtime.common.core.command.CompositeCommand;
+import org.eclipse.gmf.runtime.common.ui.services.editor.EditorService;
+import org.eclipse.gmf.runtime.diagram.core.preferences.PreferencesHint;
+import org.eclipse.gmf.runtime.diagram.core.util.ViewRefactorHelper;
+import org.eclipse.gmf.runtime.diagram.core.util.ViewUtil;
+import org.eclipse.gmf.runtime.diagram.ui.commands.ICommandProxy;
+import org.eclipse.gmf.runtime.diagram.ui.editparts.DiagramEditPart;
+import org.eclipse.gmf.runtime.diagram.ui.parts.IDiagramEditDomain;
+import org.eclipse.gmf.runtime.diagram.ui.parts.IDiagramWorkbenchPart;
+import org.eclipse.gmf.runtime.diagram.ui.requests.CreateViewRequest.ViewDescriptor;
+import org.eclipse.gmf.runtime.diagram.ui.requests.DropObjectsRequest;
+import org.eclipse.gmf.runtime.diagram.ui.requests.RequestConstants;
+import org.eclipse.gmf.runtime.emf.commands.core.command.AbstractTransactionalCommand;
+import org.eclipse.gmf.runtime.emf.core.util.EMFCoreUtil;
+import org.eclipse.gmf.runtime.notation.Diagram;
+import org.eclipse.gmf.runtime.notation.Edge;
+import org.eclipse.gmf.runtime.notation.LayoutConstraint;
+import org.eclipse.gmf.runtime.notation.Location;
+import org.eclipse.gmf.runtime.notation.Node;
+import org.eclipse.gmf.runtime.notation.NotationPackage;
+import org.eclipse.gmf.runtime.notation.View;
+import org.eclipse.jface.dialogs.MessageDialog;
+import org.eclipse.papyrus.core.utils.EditorUtils;
+import org.eclipse.papyrus.core.utils.PapyrusEcoreUtils;
+import org.eclipse.papyrus.modelexplorer.Activator;
+import org.eclipse.papyrus.modelexplorer.commands.EObjectInheritanceCopyCommand;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.ui.IEditorPart;
+import org.eclipse.ui.IWorkbenchPage;
+import org.eclipse.ui.PlatformUI;
+
+/**
+ * The Class GenericTransformer. Permits to transform an eobject of eclass to
+ * another eclass
+ */
+public class GenericTransformer {
+
+ /** The factories to create eObjects */
+ private static HashMap<String, AdapterFactory> factories = new HashMap<String, AdapterFactory>();
+
+ /** extension to recover factories */
+ private static final String EXT_FACTORIES = "org.eclipse.emf.edit.itemProviderAdapterFactories";
+
+ /** title of the warning dialog */
+ private static final String WARNING_TITLE = "Problems during transformation";
+
+ /** message of the warning dialog */
+ private static final String WARNING_MSG = "It seems the transformation you want to perform can't be executed";
+
+ /** command to execute the whole transformation */
+ private CompositeCommand globalCommand;
+
+ /** element to transform */
+ private EObject element;
+
+ /** views referencing the element */
+ private Set<View> referencingViews = new HashSet<View>();
+
+ /** command to execute the model transformation */
+ private EObjectInheritanceCopyCommand commandModel;
+
+ /** whether the graphical edit parts must also be transformed */
+ private boolean graphCopy = true;
+
+ /** the command to import new graphical edit parts */
+ private ImporterCommand importerCommand;
+
+ /**
+ * Instantiates a new generic transformer.
+ *
+ * @param currentNode
+ * the current node
+ */
+ public GenericTransformer(AbstractGraphicalEditPart currentNode) {
+ this(currentNode, true);
+ }
+
+ /**
+ * Instantiates a new generic transformer. and specify if we have to perform
+ * graphical copy
+ *
+ * @param currentNode
+ * the current node
+ * @param graphCopy
+ * the graph copy
+ */
+ public GenericTransformer(AbstractGraphicalEditPart currentNode,
+ boolean graphCopy) {
+ this.graphCopy = graphCopy;
+ if (currentNode != null) {
+ Object model = currentNode.getModel();
+ if (model instanceof View) {
+ this.element = ((View) model).getElement();
+ }
+ }
+ }
+
+ /**
+ * Instantiates a new generic transformer.
+ *
+ * @param currentEobject
+ * the current eobject
+ */
+ public GenericTransformer(EObject currentEobject) {
+ this.element = currentEobject;
+ }
+
+ /**
+ * Transform the element to the given eclass.
+ *
+ * @param eclass
+ * the targeted eclass
+ */
+ public void transform(EClass eclass) {
+
+ IWorkbenchPage page = PlatformUI.getWorkbench()
+ .getActiveWorkbenchWindow().getActivePage();
+ IEditorPart editor = page.getActiveEditor();
+ CommandStack stack = (CommandStack) editor
+ .getAdapter(CommandStack.class);
+ globalCommand = new CompositeCommand("Generic Transformation");
+
+ if (graphCopy) {
+ if (element != null) {
+ EReference[] features = { NotationPackage.eINSTANCE
+ .getView_Element() };
+ Collection<?> views = EMFCoreUtil.getReferencers(element,
+ features);
+ for (Object view : views) {
+ if (view instanceof View) {
+ referencingViews.add((View) view);
+ }
+ }
+ }
+ }
+ if (stack != null) {
+ // maybe extension point for stereotypes
+ EObject model = (EObject) AdapterFactoryEditingDomain
+ .unwrap(element);
+ // get mixed editing domain to do transaction
+ TransactionalEditingDomain domain = EditorUtils
+ .getTransactionalEditingDomain();
+ commandModel = new EObjectInheritanceCopyCommand(model, eclass,
+ domain);
+ globalCommand.add(commandModel);
+ if (graphCopy) {
+ importerCommand = new ImporterCommand(domain);
+ if (importerCommand.canExecute()) {
+ globalCommand.add(importerCommand);
+ }
+
+ }
+ if (globalCommand.canExecute()) {
+ try {
+ // drop caches about input element
+ ECrossReferenceAdapter cross = ECrossReferenceAdapter
+ .getCrossReferenceAdapter(element);
+ if (cross != null) {
+ cross.unsetTarget(element);
+ }
+ stack.execute(new ICommandProxy(globalCommand));
+ } catch (Exception e) {
+ MessageDialog.openWarning(Display.getDefault()
+ .getActiveShell(), WARNING_TITLE, WARNING_MSG);
+ e.printStackTrace();
+ }
+ } else {
+ MessageDialog.openWarning(
+ Display.getDefault().getActiveShell(), WARNING_TITLE,
+ WARNING_MSG);
+ }
+ }
+ }
+
+ /**
+ * The Class ImporterCommand. permits to add the importer in the compound
+ * command
+ */
+ private class ImporterCommand extends AbstractTransactionalCommand {
+
+ /**
+ * Constructor.
+ *
+ * @param domain
+ * transactional editing domain
+ */
+ public ImporterCommand(TransactionalEditingDomain domain) {
+ super(domain, "Import graphical nodes", null);
+ }
+
+ /**
+ * Execute the command
+ *
+ * @param monitor
+ * progress monitor
+ * @param info
+ * the info
+ * @return the command result
+ * @throws ExecutionException
+ */
+ protected CommandResult doExecuteWithResult(IProgressMonitor monitor,
+ IAdaptable info) throws ExecutionException {
+ graphCopy(null, commandModel.getResultEobject());
+ return CommandResult.newOKCommandResult();
+ }
+
+ /**
+ * Graph copy, make a drag and drop of the new object on all diagrams
+ *
+ * @param diagramDomain
+ * the mixed domain
+ * @param target
+ * the target
+ * @param globalCommand2
+ * @param graphElement
+ * the graph element
+ * @param oldLocation
+ * the old location
+ * @param editpart
+ * the editpart
+ */
+ private void graphCopy(IDiagramEditDomain domain, EObject target) {
+ for (View graphElement : referencingViews) {
+ View parent = ViewUtil.getContainerView(graphElement);
+ if (parent == null || graphElement.getDiagram() == null) {
+ // this is an orphaned view. Skip it
+ continue;
+ }
+ IWorkbenchPage page = PlatformUI.getWorkbench()
+ .getActiveWorkbenchWindow().getActivePage();
+ // Get the edit part of the diagram containing the view.
+ DiagramEditPart diagramEditPart = null;
+ IEditorPart activeEditorPart = page.getActiveEditor();
+ if (activeEditorPart instanceof IDiagramWorkbenchPart) {
+ if (graphElement.getDiagram().equals(
+ ((IDiagramWorkbenchPart) activeEditorPart)
+ .getDiagram())) {
+ diagramEditPart = ((IDiagramWorkbenchPart) activeEditorPart)
+ .getDiagramEditPart();
+ }
+ }
+ if (diagramEditPart == null) {
+ // search in other editor parts than the active one
+ List<?> editorParts = EditorService.getInstance()
+ .getRegisteredEditorParts();
+ for (Object editorPart : editorParts) {
+ if (editorPart instanceof IDiagramWorkbenchPart) {
+ if (graphElement.getDiagram().equals(
+ ((IDiagramWorkbenchPart) editorPart)
+ .getDiagram())) {
+ diagramEditPart = ((IDiagramWorkbenchPart) editorPart)
+ .getDiagramEditPart();
+ }
+ }
+ }
+ }
+
+ if (diagramEditPart != null) {
+ EditPart containerPart = (EditPart) diagramEditPart
+ .getViewer().getEditPartRegistry().get(parent);
+ // create the new transformed view
+ DropObjectsRequest req = new DropObjectsRequest();
+ req.setObjects(Collections.singletonList(target));
+ if (graphElement instanceof Node) {
+ LayoutConstraint constraint = ((Node) graphElement)
+ .getLayoutConstraint();
+ if (constraint instanceof Location) {
+ Location location = (Location) constraint;
+ req.setLocation(new Point(location.getX(), location
+ .getY()));
+ }
+ }
+ if (req.getLocation() == null) {
+ req.setLocation(new Point());
+ }
+ Command partCreationCmd = containerPart.getCommand(req);
+ partCreationCmd.execute();
+ View newView = null;
+ if (partCreationCmd instanceof ICommandProxy) {
+ CommandResult res = ((ICommandProxy) partCreationCmd)
+ .getICommand().getCommandResult();
+ Object newValue = res.getReturnValue();
+ if (newValue instanceof Collection<?>) {
+ for (Object value : (Collection<?>) newValue) {
+ if (value instanceof ViewDescriptor) {
+ newView = (View) ((ViewDescriptor) value)
+ .getAdapter(View.class);
+ }
+ }
+ } else if (newValue instanceof ViewDescriptor) {
+ newView = (View) ((ViewDescriptor) newValue)
+ .getAdapter(View.class);
+ }
+ }
+ // with ViewRefactorHelper, copy view properties on the old
+ // one
+ if (newView != null) {
+ ViewTransformerHelper helper = new ViewTransformerHelper(
+ diagramEditPart.getDiagramPreferencesHint());
+ helper.copyMixedViewFeatures(graphElement, newView);
+ }
+ // delete the old view
+ GroupRequest deleteReq = new GroupRequest(
+ RequestConstants.REQ_DELETE);
+ EditPart oldPart = (EditPart) diagramEditPart.getViewer()
+ .getEditPartRegistry().get(graphElement);
+ Command partDeletionCmd = oldPart.getCommand(deleteReq);
+ partDeletionCmd.execute();
+ }
+ }
+
+ }
+
+ }
+
+ /**
+ * ViewTransformerHelper allow to refactor a view to copy properties from
+ * another view
+ */
+ private static class ViewTransformerHelper extends ViewRefactorHelper {
+
+ /**
+ * Constructor.
+ *
+ * @param preferencesHint
+ * the diagram preferences hint
+ */
+ public ViewTransformerHelper(PreferencesHint preferencesHint) {
+ super(preferencesHint);
+ }
+
+ /**
+ * Copy common features from a view to another
+ *
+ * @param oldView
+ * the old view to copy from
+ * @param newView
+ * the new view to copy to
+ */
+ public void copyMixedViewFeatures(View oldView, View newView) {
+ if (oldView instanceof Diagram && newView instanceof Diagram) {
+ copyDiagramFeatures((Diagram) oldView, (Diagram) newView);
+ } else if (oldView instanceof Node && newView instanceof Node) {
+ copyNodeFeatures((Node) oldView, (Node) newView);
+ } else if (oldView instanceof Edge && newView instanceof Edge) {
+ copyEdgeFeatures((Edge) oldView, (Edge) newView);
+ } else {
+ copyViewFeatures(oldView, newView);
+ }
+ }
+
+ }
+
+ /**
+ * Gets all the super types.
+ *
+ * @param class1
+ * the class
+ *
+ * @return super types
+ */
+ public static HashSet<EClass> getAllSuperTypes(EClass class1) {
+ HashSet<EClass> results = new HashSet<EClass>();
+ results.addAll(class1.getEAllSuperTypes());
+ return results;
+ }
+
+ /**
+ * Gets the factory from uri.
+ *
+ * @param uri
+ * the uri
+ *
+ * @return the factory
+ */
+ public static AdapterFactory getFactory(String uri) {
+ AdapterFactory factory = factories.get(uri);
+ if (factory == null) {
+ IConfigurationElement[] extensions = Platform
+ .getExtensionRegistry().getConfigurationElementsFor(
+ EXT_FACTORIES);
+ for (IConfigurationElement e : extensions) {
+ if (uri.equals(e.getAttribute("uri"))) {
+ try {
+ factory = (AdapterFactory) e
+ .createExecutableExtension("class");
+ if (factory != null) {
+ factories.put(uri, factory);
+ }
+ } catch (CoreException e1) {
+ // do nothing
+ }
+ }
+ }
+ }
+ return factory;
+ }
+
+ /**
+ * Checks if a transformation is possible.
+ *
+ * @param eclass
+ * the eclass
+ *
+ * @return the multi status
+ */
+ public MultiStatus isTransformationPossible(EClass eclass) {
+ MultiStatus result = new MultiStatus(Activator.PLUGIN_ID, 0,
+ "Type incompatibility", null);
+ if (element != null) {
+ Collection<Setting> usages = PapyrusEcoreUtils.getUsages(element);
+ if (usages != null) {
+ for (EStructuralFeature.Setting nonNavigableInverseReference : usages) {
+ EStructuralFeature structuralFeature = nonNavigableInverseReference
+ .getEStructuralFeature();
+ if (!(nonNavigableInverseReference.getEObject() instanceof View)) {
+ boolean compatible = EObjectInheritanceCopyCommand
+ .isCompatible(structuralFeature.getEType(),
+ eclass);
+ if (!compatible) {
+ String econtainer = structuralFeature.eContainer() instanceof EClassifier ? ((EClassifier) structuralFeature
+ .eContainer()).getName()
+ + " ( "
+ + nonNavigableInverseReference.getEObject()
+ .toString() + " )"
+ : structuralFeature.eContainer().toString();
+ Status s = new Status(
+ Status.WARNING,
+ Activator.PLUGIN_ID,
+ String.format(
+ "an element typed %s references your selection, we can not assign instead of your selection an object typed %s",
+ econtainer, eclass.getName()));
+ result.add(s);
+ }
+ }
+ }
+ }
+ }
+ return result;
+ }
+
+}
diff --git a/plugins/views/modelexplorer/org.eclipse.papyrus.modelexplorer/src/org/eclipse/papyrus/modelexplorer/actions/OpenDiagramAction.java b/plugins/views/modelexplorer/org.eclipse.papyrus.modelexplorer/src/org/eclipse/papyrus/modelexplorer/actions/OpenDiagramAction.java
new file mode 100644
index 00000000000..d3b53ef739a
--- /dev/null
+++ b/plugins/views/modelexplorer/org.eclipse.papyrus.modelexplorer/src/org/eclipse/papyrus/modelexplorer/actions/OpenDiagramAction.java
@@ -0,0 +1,74 @@
+/*****************************************************************************
+ * Copyright (c) 2010 CEA LIST.
+ *
+ *
+ * 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:
+ * Patrick Tessier (CEA LIST) Patrick.tessier@cea.fr - Initial API and implementation
+ * Vincent Lorenzo (vincent.lorenzo@cea.fr) - @deprecated
+ *****************************************************************************/
+
+package org.eclipse.papyrus.modelexplorer.actions;
+
+import org.eclipse.gmf.runtime.notation.Diagram;
+import org.eclipse.jface.action.Action;
+import org.eclipse.papyrus.sasheditor.contentprovider.IPageMngr;
+import org.eclipse.ui.ISharedImages;
+import org.eclipse.ui.PlatformUI;
+
+/**
+ * Action used to open the given diagram. The diagram is open in a new tab, even
+ * if it is already open.
+ *
+ * @author cedric dumoulin
+ * @deprecated you should use OpenHandler
+ */
+@Deprecated
+public class OpenDiagramAction extends Action {
+
+ private final Diagram diagram;
+
+ private final IPageMngr pageMngr;
+
+ public OpenDiagramAction(IPageMngr pageMngr, Diagram diagram) {
+ this.diagram = diagram;
+ this.pageMngr = pageMngr;
+
+ ISharedImages sharedImages = PlatformUI.getWorkbench().getSharedImages();
+ if(pageMngr.isOpen(diagram)) {
+ setText("Open in New Tab");
+ setImageDescriptor(sharedImages.getImageDescriptor(ISharedImages.IMG_TOOL_FORWARD));
+ } else {
+ setText("Open");
+ setImageDescriptor(sharedImages.getImageDescriptor(ISharedImages.IMG_TOOL_BACK));
+ }
+
+ setEnabled(true);
+ }
+
+ /**
+ * Delete the given diagram
+ *
+ * @see org.eclipse.jface.action.Action#run()
+ */
+ @Override
+ public void run() {
+
+ pageMngr.openPage(diagram);
+ // TransactionalEditingDomain editingDomain =
+ // NavigatorUtils.getTransactionalEditingDomain();
+ // if (editingDomain != null) {
+ //
+ //
+ // EList<EObject> diagrams = diagram.eResource().getContents();
+ // //TODO : synchronize with Cedric
+ // Command command = new RemoveCommand(editingDomain, diagrams,
+ // diagram);
+ // editingDomain.getCommandStack().execute(command);
+ // }
+ }
+}
diff --git a/plugins/views/modelexplorer/org.eclipse.papyrus.modelexplorer/src/org/eclipse/papyrus/modelexplorer/actions/PasteShapeOrElementAction.java b/plugins/views/modelexplorer/org.eclipse.papyrus.modelexplorer/src/org/eclipse/papyrus/modelexplorer/actions/PasteShapeOrElementAction.java
new file mode 100644
index 00000000000..20137e686cc
--- /dev/null
+++ b/plugins/views/modelexplorer/org.eclipse.papyrus.modelexplorer/src/org/eclipse/papyrus/modelexplorer/actions/PasteShapeOrElementAction.java
@@ -0,0 +1,62 @@
+/*****************************************************************************
+ * Copyright (c) 2009 CEA LIST.
+ *
+ *
+ * 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:
+ * Ansgar Radermacher (CEA LIST) ansgar.radermacher@cea.fr - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.modelexplorer.actions;
+
+import java.util.Collection;
+
+import org.eclipse.emf.common.command.Command;
+import org.eclipse.emf.edit.command.AddCommand;
+import org.eclipse.emf.edit.domain.EditingDomain;
+import org.eclipse.emf.edit.ui.action.PasteAction;
+import org.eclipse.gmf.runtime.notation.View;
+
+/**
+ * Action used for pasting either a model element or a shape (i.e. the model element reprented
+ * by the shape). Delegates to PasteShapeOrElementCommand
+ *
+ * @author Ansgar Radermacher (CEA LIST)
+ */
+public class PasteShapeOrElementAction extends PasteAction
+{
+ public PasteShapeOrElementAction (EditingDomain domain) {
+ super (domain);
+ }
+
+ @Override
+ public Command createCommand(Collection<?> selection)
+ {
+ if ((selection.size () == 1) && (domain != null)) {
+ Object owner = selection.iterator().next ();
+
+ boolean onlyViewsInClipboard = true;
+ boolean foundView = false;
+ if (domain.getClipboard () != null) {
+ for (Object clipObject : domain.getClipboard ()) {
+ if (clipObject instanceof View) {
+ foundView = true;
+ }
+ else {
+ onlyViewsInClipboard = false;
+ }
+ }
+ }
+ // TODO: currently only works for a single element to be copied.
+ if (onlyViewsInClipboard && foundView) {
+ View shape = (View) domain.getClipboard ().iterator ().next ();
+ return AddCommand.create (domain, owner, null, shape.getElement ());
+ }
+ }
+ return super.createCommand (selection);
+ }
+}
diff --git a/plugins/views/modelexplorer/org.eclipse.papyrus.modelexplorer/src/org/eclipse/papyrus/modelexplorer/actions/RenameDiagramAction.java b/plugins/views/modelexplorer/org.eclipse.papyrus.modelexplorer/src/org/eclipse/papyrus/modelexplorer/actions/RenameDiagramAction.java
new file mode 100644
index 00000000000..0726e635ab4
--- /dev/null
+++ b/plugins/views/modelexplorer/org.eclipse.papyrus.modelexplorer/src/org/eclipse/papyrus/modelexplorer/actions/RenameDiagramAction.java
@@ -0,0 +1,71 @@
+/*******************************************************************************
+ * Copyright (c) 2009 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
+ * Vincent Lorenzo (vincent.lorenzo@cea.fr) - @deprecated
+ *******************************************************************************/
+package org.eclipse.papyrus.modelexplorer.actions;
+
+import org.eclipse.emf.common.command.Command;
+import org.eclipse.emf.transaction.RecordingCommand;
+import org.eclipse.emf.transaction.TransactionalEditingDomain;
+import org.eclipse.gmf.runtime.notation.Diagram;
+import org.eclipse.jface.action.Action;
+import org.eclipse.jface.dialogs.InputDialog;
+import org.eclipse.jface.window.Window;
+import org.eclipse.papyrus.core.utils.EditorUtils;
+import org.eclipse.papyrus.modelexplorer.Activator;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.widgets.Display;
+
+/**
+ * Action used to rename the given diagram
+ *
+ * @author <a href="mailto:jerome.benois@obeo.fr">Jerome Benois</a>
+ * @deprecated you should use RenameDiagramHandler
+ */
+@Deprecated
+public class RenameDiagramAction extends Action {
+
+ Diagram diagram;
+
+ public RenameDiagramAction(Diagram diagram) {
+ this.diagram = diagram;
+ setImageDescriptor(Activator.getImageDescriptor("icons/etool16/rename.gif"));
+ setText("Rename...");
+ setAccelerator(SWT.F2);
+ }
+
+ /**
+ * Rename the given diagram
+ *
+ * @see org.eclipse.jface.action.Action#run()
+ */
+ @Override
+ public void run() {
+ TransactionalEditingDomain editingDomain = EditorUtils.getTransactionalEditingDomain();
+ if(editingDomain != null) {
+ InputDialog dialog = new InputDialog(Display.getCurrent().getActiveShell(), "Rename an existing diagram", "New name:", diagram.getName(), null);
+ if(dialog.open() == Window.OK) {
+ final String name = dialog.getValue();
+ if(name != null && name.length() > 0) {
+
+ Command command = new RecordingCommand(editingDomain) {
+
+ @Override
+ protected void doExecute() {
+ diagram.setName(name);
+ }
+ };
+
+ editingDomain.getCommandStack().execute(command);
+ }
+ }
+ }
+ }
+}
diff --git a/plugins/views/modelexplorer/org.eclipse.papyrus.modelexplorer/src/org/eclipse/papyrus/modelexplorer/commands/EObjectInheritanceCopyCommand.java b/plugins/views/modelexplorer/org.eclipse.papyrus.modelexplorer/src/org/eclipse/papyrus/modelexplorer/commands/EObjectInheritanceCopyCommand.java
new file mode 100644
index 00000000000..832c12b0839
--- /dev/null
+++ b/plugins/views/modelexplorer/org.eclipse.papyrus.modelexplorer/src/org/eclipse/papyrus/modelexplorer/commands/EObjectInheritanceCopyCommand.java
@@ -0,0 +1,444 @@
+/***************************************************
+ * Copyright (c) 2010 Atos Origin.
+
+ *
+ * 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:
+ * Atos Origin - Initial API and implementation
+ *
+ ****************************************************/
+package org.eclipse.papyrus.modelexplorer.commands;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.LinkedList;
+import java.util.List;
+
+import org.eclipse.core.commands.ExecutionException;
+import org.eclipse.core.runtime.IAdaptable;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.emf.common.util.EList;
+import org.eclipse.emf.ecore.EClass;
+import org.eclipse.emf.ecore.EClassifier;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.ecore.EReference;
+import org.eclipse.emf.ecore.EStructuralFeature;
+import org.eclipse.emf.transaction.TransactionalEditingDomain;
+import org.eclipse.gmf.runtime.common.core.command.CompositeCommand;
+import org.eclipse.gmf.runtime.emf.type.core.commands.DestroyElementCommand;
+import org.eclipse.gmf.runtime.emf.type.core.commands.SetValueCommand;
+import org.eclipse.gmf.runtime.emf.type.core.requests.DestroyElementRequest;
+import org.eclipse.gmf.runtime.emf.type.core.requests.SetRequest;
+import org.eclipse.gmf.runtime.notation.Diagram;
+import org.eclipse.gmf.runtime.notation.View;
+import org.eclipse.papyrus.core.utils.PapyrusEcoreUtils;
+
+/**
+ * The Class EObjectInheritanceCopyCommand. it takes an eobject in parameter and
+ * copy all the elements contained in the source to the target and adds the
+ * target to the container of the source
+ */
+public class EObjectInheritanceCopyCommand extends CompositeCommand {
+
+ private final EObject sourceEObject;
+
+ private final EObject targetEObject;
+
+ private final TransactionalEditingDomain editingDomain;
+
+ private Collection<Object> alreadyManaged = new LinkedList<Object>();
+
+ public EObjectInheritanceCopyCommand(EObject source, EClass target,
+ TransactionalEditingDomain adapterFactoryEditingDomain) {
+ super("Inheritance copy");
+ this.sourceEObject = source;
+ this.targetEObject = target.getEPackage().getEFactoryInstance().create(
+ target);
+ this.editingDomain = adapterFactoryEditingDomain;
+ if (sourceEObject == null || targetEObject == null
+ || editingDomain == null) {
+ throw new IllegalArgumentException(
+ "Please provide non null arguments");
+ }
+ init();
+ if (sourceEObject.eContainingFeature().isMany()) {
+ replace(sourceEObject.eContainer(), sourceEObject, targetEObject,
+ sourceEObject.eContainingFeature());
+ } else {
+ add(new CustomSetCommand(editingDomain, sourceEObject.eContainer(),
+ sourceEObject.eContainingFeature(), targetEObject,
+ sourceEObject, sourceEObject.eContainingFeature()));
+ add(new DestroyElementCommand(new DestroyElementRequest(
+ editingDomain, sourceEObject, false)));
+ }
+ }
+
+ private void init() {
+ modelCopy(sourceEObject, targetEObject);
+ crossReference(sourceEObject, targetEObject);
+ }
+
+ /**
+ * Model copy, copy the eobject source attributes to target's
+ *
+ * @param mixedDomain
+ * the mixed domain
+ * @param source
+ * the source
+ * @param target
+ * the target
+ */
+ private void modelCopy(EObject source, EObject target) {
+ EClass eclass = source.eClass();
+ if (eclass != null) {
+ EList<EStructuralFeature> eAllStructuralFeatures = eclass
+ .getEAllStructuralFeatures();
+ for (EStructuralFeature e : eAllStructuralFeatures) {
+ if (contains(target.eClass(), e)
+ && isCompatible(e.getEType(), target.eClass()
+ .getEStructuralFeature(e.getName()).getEType())) {
+ manageFeature(source, target, e);
+ }
+ }
+ }
+ }
+
+ /**
+ * Contains. check if the target eclass contains a estructuralfeature with
+ * the same name less rigorous can work for many cases
+ *
+ * @param target
+ * the target
+ * @param e
+ * the e
+ *
+ * @return true, if successful
+ */
+ private boolean contains(EClass target, EStructuralFeature e) {
+ EList<EStructuralFeature> features = target.getEAllStructuralFeatures();
+ for (EStructuralFeature f : features) {
+ if (f.getName().equals(e.getName())) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ /**
+ * Manage feature for cross.
+ *
+ * @param mixedDomain
+ * the mixed domain
+ * @param theObjectWithCross
+ * the the object with cross
+ * @param source
+ * the source
+ * @param target
+ * the target
+ * @param structuralFeature
+ * the structural feature
+ */
+ private void manageFeatureForCross(EObject theObjectWithCross,
+ EObject source, EObject target, EStructuralFeature structuralFeature) {
+ boolean compatible = isCompatible(structuralFeature.getEType(), target
+ .eClass());
+
+ if (compatible && structuralFeature.isChangeable()
+ && !structuralFeature.isDerived()) {
+ if (structuralFeature.isMany()) {
+ replace(theObjectWithCross, source, target, structuralFeature);
+ } else {
+ add(new SetValueCommand(new SetRequest(editingDomain,
+ theObjectWithCross, structuralFeature, target)));
+ }
+ } else if (!compatible) {
+ if (structuralFeature.isMany()) {
+ remove(theObjectWithCross, source, structuralFeature);
+ } else {
+ add(new SetValueCommand(new SetRequest(editingDomain,
+ theObjectWithCross, structuralFeature, null)));
+ }
+ }
+
+ }
+
+ private void remove(EObject owner, Object source,
+ EStructuralFeature structuralFeature) {
+ if (!alreadyManaged.contains(source)) {
+
+ if (owner == null && structuralFeature == null) {
+ if (source instanceof EObject) {
+ add(new DestroyElementCommand(new DestroyElementRequest(
+ editingDomain, (EObject) source, false)));
+ }
+ } else {
+ Object value = owner.eGet(structuralFeature);
+ if (value instanceof Collection<?>) {
+ List<Object> newList = new ArrayList<Object>(
+ (Collection<?>) value);
+ newList.remove(source);
+ add(new SetValueCommand(new SetRequest(editingDomain,
+ owner, structuralFeature, newList)));
+ } else if (source.equals(value)) {
+ add(new SetValueCommand(new SetRequest(editingDomain,
+ owner, structuralFeature, null)));
+ } else {
+ add(new SetValueCommand(new SetRequest(editingDomain,
+ owner, structuralFeature, null)));
+ }
+ }
+ alreadyManaged.add(source);
+ }
+ }
+
+ private void replace(EObject owner, Object source, Object target,
+ EStructuralFeature structuralFeature) {
+ if (!alreadyManaged.contains(source)) {
+
+ if (owner == null && structuralFeature == null) {
+ if (source instanceof EObject) {
+ add(new DestroyElementCommand(new DestroyElementRequest(
+ editingDomain, (EObject) source, false)));
+ }
+ } else {
+ Object value = owner.eGet(structuralFeature);
+ if (value instanceof Collection<?>) {
+ List<Object> newList = new ArrayList<Object>(
+ (Collection<?>) value);
+ int index = newList.indexOf(source);
+ if (index >= 0) {
+ newList.remove(index);
+ newList.add(index, target);
+ add(new SetValueCommand(new SetRequest(editingDomain,
+ owner, structuralFeature, newList)));
+ }
+ } else if (source.equals(value)) {
+ add(new SetValueCommand(new SetRequest(editingDomain,
+ owner, structuralFeature, target)));
+ } else {
+ add(new SetValueCommand(new SetRequest(editingDomain,
+ owner, structuralFeature, target)));
+ }
+ }
+ alreadyManaged.add(source);
+ }
+ }
+
+ @Override
+ public IStatus undo(IProgressMonitor progressMonitor, IAdaptable info)
+ throws ExecutionException {
+ return super.undo(progressMonitor, info);
+ }
+
+ /**
+ * Cross reference. Manage eobjects referencing the source eobject
+ *
+ * @param mixedDomain
+ * the mixed domain
+ * @param source
+ * the source eobject
+ * @param target
+ * the target eobject
+ */
+ private void crossReference(EObject source, EObject target) {
+ Collection<EStructuralFeature.Setting> collection = PapyrusEcoreUtils.getUsages(source);
+ if (collection != null) {
+ for (EStructuralFeature.Setting nonNavigableInverseReference : collection) {
+ EStructuralFeature structuralFeature = nonNavigableInverseReference
+ .getEStructuralFeature();
+ if (!(nonNavigableInverseReference.getEObject() instanceof View)) {
+ manageFeatureForCross(nonNavigableInverseReference
+ .getEObject(), source, target, structuralFeature);
+ } else if (nonNavigableInverseReference.getEObject() instanceof Diagram) {
+ Diagram di = (Diagram) nonNavigableInverseReference
+ .getEObject();
+ remove(null, di, null);
+ }
+ }
+ }
+ }
+
+ /**
+ * Checks if a type is compatible to another.
+ *
+ * @param type
+ * the type
+ * @param target
+ * the target
+ *
+ * @return true, if is compatible
+ */
+ public static boolean isCompatible(EClassifier type, EClassifier target) {
+ Collection<EClassifier> types = new LinkedList<EClassifier>();
+ if (target instanceof EClass) {
+ EClass eclass = (EClass) target;
+ types.addAll(eclass.getEAllSuperTypes());
+ }
+ if (!types.contains(target)) {
+ types.add(target);
+ }
+ return types.contains(type);
+ }
+
+ /**
+ * Manage a feature for the attribute's copy.
+ *
+ * @param mixedDomain
+ * the mixed domain
+ * @param source
+ * the source
+ * @param target
+ * the target
+ * @param feature
+ * the e
+ */
+ @SuppressWarnings("unchecked")
+ private void manageFeature(EObject source, EObject target,
+ EStructuralFeature feature) {
+ EStructuralFeature targetFeature = getFeature(target, feature.getName());
+
+ if (feature.getUpperBound() <= targetFeature.getUpperBound()
+ && feature.getLowerBound() >= targetFeature.getLowerBound()) {
+ if (feature.isChangeable() && !feature.isDerived()) {
+ Object value = source.eGet(feature);
+ if (feature.isMany() && targetFeature.isMany()) {
+ Collection<EObject> list = (Collection<EObject>) value;
+ if (list != null && !list.isEmpty()) {
+ Collection<EObject> newList = new LinkedList<EObject>();
+ newList.addAll(list);
+ if (feature instanceof EReference
+ && !((EReference) feature).isContainment()) {
+ add(new SetValueCommand(new SetRequest(
+ editingDomain, target, targetFeature,
+ newList)));
+ } else if (feature instanceof EReference
+ && ((EReference) feature).isContainment()) {
+ Collection<Object> toTreat = new LinkedList<Object>();
+ for (Object o : newList) {
+ if (!alreadyManaged.contains(o)) {
+ toTreat.add(o);
+ alreadyManaged.add(o);
+ }
+ }
+ add(new CustomAddCommand(editingDomain, target,
+ targetFeature, newList, source, feature));
+ }
+ }
+ } else if (!feature.isMany() && !targetFeature.isMany()) {
+ if (value != null) {
+ if (!alreadyManaged.contains(value)) {
+ alreadyManaged.add(value);
+ add(new CustomSetCommand(editingDomain, target,
+ targetFeature, value, source, feature));
+ }
+ }
+ }
+ }
+ }
+
+ }
+
+ /**
+ * Gets a feature from a name
+ *
+ * @param eobject
+ * the eobject
+ * @param name
+ * the name
+ *
+ * @return the feature
+ */
+ private EStructuralFeature getFeature(EObject eobject, String name) {
+ return eobject.eClass().getEStructuralFeature(name);
+ }
+
+ /**
+ * Gets the result eobject.
+ *
+ * @return the result eobject
+ */
+ public EObject getResultEobject() {
+ return targetEObject;
+ }
+
+ /**
+ * The Class CustomSetCommand. permits to change a value from an eobject to
+ * eanother
+ */
+ private class CustomSetCommand extends SetValueCommand {
+
+ private EObject oldObject = null;
+
+ private EStructuralFeature oldFeature = null;
+
+ private Object oldValue = null;
+
+ public CustomSetCommand(TransactionalEditingDomain domain,
+ EObject owner, EStructuralFeature feature, Object value,
+ EObject old, EStructuralFeature structuralFeature) {
+ super(new SetRequest(domain, owner, feature, value));
+ oldObject = old;
+ oldFeature = structuralFeature;
+ oldValue = value;
+ }
+
+ @Override
+ protected IStatus doUndo(IProgressMonitor monitor, IAdaptable info)
+ throws ExecutionException {
+ IStatus result = super.doUndo(monitor, info);
+ oldObject.eSet(oldFeature, oldValue);
+ return result;
+ }
+
+ }
+
+ /**
+ * The Class CustomSetCommand. permits to change a value from an eobject to
+ * eanother
+ */
+ private class CustomAddCommand extends SetValueCommand {
+
+ private EObject oldObject = null;
+
+ private EStructuralFeature oldFeature;
+
+ private EStructuralFeature newFeature;
+
+ public CustomAddCommand(TransactionalEditingDomain editingDomain,
+ EObject target, EStructuralFeature targetFeature,
+ Collection<EObject> newList, EObject source,
+ EStructuralFeature e) {
+ super(new SetRequest(editingDomain, target, targetFeature, newList));
+ oldObject = source;
+ oldFeature = e;
+ newFeature = targetFeature;
+ }
+
+ @SuppressWarnings({ "rawtypes", "unchecked" })
+ @Override
+ protected IStatus doUndo(IProgressMonitor monitor, IAdaptable info)
+ throws ExecutionException {
+ Object values = getElementToEdit().eGet(newFeature);
+ IStatus result = super.doUndo(monitor, info);
+ // this test permit to avoid modification from other command
+ // if getOwner list is empty it will perform error we avoid it
+ if (values instanceof Collection<?>
+ && !((Collection<?>) values).isEmpty()) {
+ Collection<?> collection = (Collection<?>) values;
+ Collection<Object> collecOldObject = (Collection) oldObject
+ .eGet(oldFeature);
+ for (Object o : collection) {
+ if (!collecOldObject.contains(o)) {
+ collecOldObject.add(o);
+ }
+ }
+ }
+ return result;
+ }
+ }
+}
diff --git a/plugins/views/modelexplorer/org.eclipse.papyrus.modelexplorer/src/org/eclipse/papyrus/modelexplorer/dialog/NavigatorSearchDialog.java b/plugins/views/modelexplorer/org.eclipse.papyrus.modelexplorer/src/org/eclipse/papyrus/modelexplorer/dialog/NavigatorSearchDialog.java
new file mode 100644
index 00000000000..60d001cbd39
--- /dev/null
+++ b/plugins/views/modelexplorer/org.eclipse.papyrus.modelexplorer/src/org/eclipse/papyrus/modelexplorer/dialog/NavigatorSearchDialog.java
@@ -0,0 +1,370 @@
+/*******************************************************************************
+ * Copyright (c) 2009 Conselleria de Infraestructuras y Transporte, Generalitat
+ * de la Comunitat Valenciana . 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: Francisco Javier Cano Muñoz (Prodevelop) - initial api contribution
+ *
+ ******************************************************************************/
+package org.eclipse.papyrus.modelexplorer.dialog;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.List;
+
+import org.eclipse.core.runtime.IAdaptable;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.gmf.runtime.notation.Diagram;
+import org.eclipse.jface.dialogs.IDialogConstants;
+import org.eclipse.jface.dialogs.TrayDialog;
+import org.eclipse.jface.viewers.IContentProvider;
+import org.eclipse.jface.viewers.ILabelProvider;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.viewers.ISelectionProvider;
+import org.eclipse.jface.viewers.ITreeContentProvider;
+import org.eclipse.jface.viewers.StructuredSelection;
+import org.eclipse.jface.viewers.TreeViewer;
+import org.eclipse.jface.viewers.Viewer;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.KeyEvent;
+import org.eclipse.swt.events.KeyListener;
+import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.events.SelectionListener;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Button;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.swt.widgets.Text;
+import org.eclipse.ui.navigator.CommonNavigator;
+
+/**
+ * A dialog that allows searching elements in the Model navigator by name.
+ *
+ * @author <a href="mailto:fjcano@prodevelop.es">Francisco Javier Cano Munoz</a>
+ *
+ * @author cedric dumoulin
+ */
+public class NavigatorSearchDialog extends TrayDialog {
+
+ private ITreeContentProvider contentProvider = null;
+
+ private ILabelProvider labelProvider = null;
+
+ private Object root = null;
+
+ private ISelectionProvider viewer = null;
+
+ private List<Object> matchedObjects = Collections.emptyList();
+
+ private Label matchesLabel;
+
+ private Text searchText;
+
+ private Button backButton;
+
+ private Button nextButton;
+
+ private Button caseButton;
+
+ /**
+ *
+ * Constructor.
+ *
+ * @param shell
+ * @param modelNavigator
+ * @deprecated Use {@link #NavigatorSearchDialog(Shell, TreeViewer)}
+ */
+ public NavigatorSearchDialog(Shell shell, CommonNavigator modelNavigator) {
+ super(shell);
+ IContentProvider cprovider = modelNavigator.getCommonViewer()
+ .getContentProvider();
+ if(cprovider instanceof ITreeContentProvider) {
+ contentProvider = (ITreeContentProvider)cprovider;
+ }
+ root = modelNavigator.getCommonViewer().getInput();
+ viewer = modelNavigator.getCommonViewer();
+ labelProvider = (ILabelProvider)modelNavigator.getCommonViewer()
+ .getLabelProvider();
+
+ }
+
+ /**
+ * Constructor.
+ *
+ * @param shell Shell used to show this Dialog
+ * @param viewer
+ * @param contentProvider
+ * @param labelProvider
+ * @param root
+ */
+ public NavigatorSearchDialog(Shell shell, TreeViewer viewer) {
+ super(shell);
+ this.viewer = viewer;
+ try {
+ this.labelProvider = (ILabelProvider)viewer.getLabelProvider();
+ this.contentProvider = (ITreeContentProvider)viewer.getContentProvider();
+ } catch (ClassCastException e) {
+ // Content or label provider are not of appropriate type.
+ // let them null
+ }
+ this.root = viewer.getInput();
+ }
+
+
+ /**
+ * Constructor.
+ *
+ * @param shell Shell used to show this Dialog
+ * @param viewer
+ * @param contentProvider
+ * @param labelProvider
+ * @param root
+ */
+ public NavigatorSearchDialog(Shell shell, Viewer viewer, ITreeContentProvider contentProvider, ILabelProvider labelProvider, Object root) {
+ super(shell);
+ this.viewer = viewer;
+ this.contentProvider = contentProvider;
+ this.labelProvider = labelProvider;
+ this.root = root;
+ }
+
+ /**
+ * Sets a new selection for the associated {@link ISelectionProvider} and optionally makes it visible.
+ * <p>
+ * Subclasses must implement this method.
+ * </p>
+ *
+ * @param selection the new selection
+ * @param reveal <code>true</code> if the selection is to be made
+ * visible, and <code>false</code> otherwise
+ */
+ private void fireSetSelection( ISelection selection, boolean reveal) {
+ // Note : if we want to force reveal, it is possible to check if
+ // selectionProvider instanceof Viewer, and then call selectionProvider.setSelection(selection, true).
+ // By default a TreeViewer reveal the selection.
+ viewer.setSelection(selection);
+ }
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * org.eclipse.jface.dialogs.Dialog#createDialogArea(org.eclipse.swt.widgets
+ * .Composite)
+ */
+ @Override
+ protected Control createDialogArea(Composite parent) {
+ Composite background = new Composite(parent, SWT.None);
+ GridData bgData = new GridData(GridData.FILL_BOTH);
+ bgData.minimumWidth = 300;
+ background.setLayoutData(bgData);
+ GridLayout bgLayout = new GridLayout();
+ bgLayout.numColumns = 2;
+ background.setLayout(bgLayout);
+
+ createSearchTextComposite(background);
+ return background;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * org.eclipse.jface.dialogs.Dialog#createButtonsForButtonBar(org.eclipse
+ * .swt.widgets.Composite)
+ */
+ @Override
+ protected void createButtonsForButtonBar(Composite parent) {
+
+ backButton = createButton(parent, IDialogConstants.BACK_ID,
+ IDialogConstants.BACK_LABEL, false);
+ nextButton = createButton(parent, IDialogConstants.NEXT_ID,
+ IDialogConstants.NEXT_LABEL, false);
+ createButton(parent, IDialogConstants.OK_ID, IDialogConstants.OK_LABEL,
+ true);
+
+ backButton.setEnabled(false);
+ nextButton.setEnabled(false);
+
+ nextButton.addSelectionListener(new SelectionListener() {
+
+ public void widgetDefaultSelected(SelectionEvent e) {
+ }
+
+ public void widgetSelected(SelectionEvent e) {
+ ISelection sel = viewer.getSelection();
+ if(!(sel instanceof StructuredSelection)) {
+ return;
+ }
+ StructuredSelection ssel = (StructuredSelection)sel;
+
+ int index = matchedObjects.lastIndexOf(ssel.getFirstElement());
+ if(index == matchedObjects.size() - 1) {
+ index = -1;
+ }
+ index++;
+ fireSetSelection(new StructuredSelection(matchedObjects.get(index)), true);
+ }
+
+ });
+
+ backButton.addSelectionListener(new SelectionListener() {
+
+ public void widgetDefaultSelected(SelectionEvent e) {
+ }
+
+ public void widgetSelected(SelectionEvent e) {
+ ISelection sel = viewer.getSelection();
+ if(!(sel instanceof StructuredSelection)) {
+ return;
+ }
+ StructuredSelection ssel = (StructuredSelection)sel;
+
+ int index = matchedObjects.lastIndexOf(ssel.getFirstElement());
+ if(index == 0) {
+ index = matchedObjects.size() - 1;
+ }
+ index--;
+ fireSetSelection(new StructuredSelection(matchedObjects.get(index)), true);
+ }
+
+ });
+ }
+
+ private void createSearchTextComposite(Composite background) {
+ Label searchLabel = new Label(background, SWT.None);
+ searchLabel.setText("Search:");
+ searchLabel.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_END));
+
+ searchText = new Text(background, SWT.SEARCH);
+ searchText.setFocus();
+ searchText.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
+ searchText.addKeyListener(getKeyListener());
+
+ caseButton = new Button(background, SWT.CHECK);
+ caseButton.setText("Case sensitive?");
+ GridData caseButtonData = new GridData(
+ GridData.HORIZONTAL_ALIGN_BEGINNING);
+ caseButtonData.horizontalSpan = 2;
+ caseButton.setSelection(false);
+ caseButton.setLayoutData(caseButtonData);
+ caseButton.addSelectionListener(new SelectionListener() {
+
+ public void widgetDefaultSelected(SelectionEvent e) {
+ }
+
+ public void widgetSelected(SelectionEvent e) {
+ updateMatches();
+ }
+
+ });
+
+ Label resultsLabel = new Label(background, SWT.None);
+ resultsLabel.setText("Results:");
+ resultsLabel.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_END));
+
+ matchesLabel = new Label(background, SWT.None);
+ matchesLabel.setText("No matchings.");
+ matchesLabel
+ .setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING
+ | GridData.FILL_HORIZONTAL));
+
+ }
+
+ private void updateMatches() {
+ if(contentProvider == null && labelProvider == null) {
+ return;
+ }
+
+ String pattern = searchText.getText();
+ if(pattern.length() == 0) {
+ matchedObjects = Collections.emptyList();
+ backButton.setEnabled(false);
+ nextButton.setEnabled(false);
+ matchesLabel.setText("No matchings.");
+ return;
+ }
+
+ if(!caseButton.getSelection()) {
+ pattern = pattern.toUpperCase();
+ }
+
+ matchedObjects = searchPattern(pattern, Arrays.asList(contentProvider
+ .getElements(root)));
+
+ // Update matches label
+ matchesLabel.setText(matchedObjects.size() + " matches found");
+
+ // Select first match and update buttons
+ if(!matchedObjects.isEmpty()) {
+ fireSetSelection(new StructuredSelection(matchedObjects.get(0)), true);
+ nextButton.setEnabled(true);
+ backButton.setEnabled(true);
+ } else {
+ nextButton.setEnabled(false);
+ backButton.setEnabled(false);
+ }
+
+ }
+
+ private List<Object> searchPattern(String pattern, List<Object> objects) {
+ List<Object> matches = new ArrayList<Object>();
+
+ List<Object> childs = new ArrayList<Object>();
+ String objectLabel;
+ boolean caseSensitive = caseButton.getSelection();
+ for(Object o : objects) {
+ // Search matches in this level
+ if(!(o instanceof Diagram)) {
+ objectLabel = caseSensitive ? labelProvider.getText(o)
+ : labelProvider.getText(o).toUpperCase();
+
+ if(objectLabel.contains(pattern)) {
+ matches.add(o);
+ }
+
+ // Find childs
+
+ EObject parentEObj = (EObject)((IAdaptable)o).getAdapter(EObject.class);
+
+ for(int i = 0; i < contentProvider.getChildren(o).length; i++) {
+ Object child = contentProvider.getChildren(o)[i];
+ if(child instanceof IAdaptable) {
+ EObject eObject = (EObject)((IAdaptable)child).getAdapter(EObject.class);
+
+ if(eObject != null && eObject.eContainer() != null && eObject.eContainer().equals(parentEObj)) {
+ childs.add(child);
+ }
+ }
+ }
+ }
+ }
+ if(!childs.isEmpty()) {
+ matches.addAll(searchPattern(pattern, childs));
+ }
+
+ return matches;
+ }
+
+ protected KeyListener getKeyListener() {
+ return new KeyListener() {
+
+ public void keyPressed(KeyEvent e) {
+ // TODO Auto-generated method stub
+
+ }
+
+ public void keyReleased(KeyEvent e) {
+ updateMatches();
+
+ }
+
+ };
+ }
+
+}
diff --git a/plugins/views/modelexplorer/org.eclipse.papyrus.modelexplorer/src/org/eclipse/papyrus/modelexplorer/dnd/CommonDropAdapterAssistant.java b/plugins/views/modelexplorer/org.eclipse.papyrus.modelexplorer/src/org/eclipse/papyrus/modelexplorer/dnd/CommonDropAdapterAssistant.java
new file mode 100644
index 00000000000..3a1608412c9
--- /dev/null
+++ b/plugins/views/modelexplorer/org.eclipse.papyrus.modelexplorer/src/org/eclipse/papyrus/modelexplorer/dnd/CommonDropAdapterAssistant.java
@@ -0,0 +1,452 @@
+/*****************************************************************************
+ * Copyright (c) 2010 CEA LIST.
+ *
+ *
+ * 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:
+ * Patrick Tessier (CEA LIST) Patrick.tessier@cea.fr - Initial API and implementation
+ *
+ *****************************************************************************/
+
+package org.eclipse.papyrus.modelexplorer.dnd;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Iterator;
+import java.util.List;
+
+import org.eclipse.core.runtime.IAdaptable;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.emf.common.command.Command;
+import org.eclipse.emf.common.command.UnexecutableCommand;
+import org.eclipse.emf.common.util.EList;
+import org.eclipse.emf.ecore.EClass;
+import org.eclipse.emf.ecore.EClassifier;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.ecore.EReference;
+import org.eclipse.emf.ecore.EStructuralFeature;
+import org.eclipse.emf.ecore.util.EcoreUtil;
+import org.eclipse.emf.facet.infra.browser.uicore.internal.model.LinkItem;
+import org.eclipse.emf.facet.infra.browser.uicore.internal.model.ModelElementItem;
+import org.eclipse.emf.transaction.TransactionalEditingDomain;
+import org.eclipse.gmf.runtime.common.core.command.ICommand;
+import org.eclipse.gmf.runtime.emf.type.core.requests.MoveRequest;
+import org.eclipse.gmf.runtime.emf.type.core.requests.SetRequest;
+import org.eclipse.gmf.runtime.notation.Diagram;
+import org.eclipse.gmf.runtime.notation.NotationPackage;
+import org.eclipse.jface.util.LocalSelectionTransfer;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.jface.viewers.ViewerDropAdapter;
+import org.eclipse.papyrus.core.editor.BackboneException;
+import org.eclipse.papyrus.core.editor.IMultiDiagramEditor;
+import org.eclipse.papyrus.core.extension.commands.CreationCommandDescriptor;
+import org.eclipse.papyrus.core.extension.commands.CreationCommandRegistry;
+import org.eclipse.papyrus.core.extension.commands.ICreationCommand;
+import org.eclipse.papyrus.core.extension.commands.ICreationCommandRegistry;
+import org.eclipse.papyrus.core.utils.EditorUtils;
+import org.eclipse.papyrus.modelexplorer.Activator;
+import org.eclipse.papyrus.commands.wrappers.GMFtoEMFCommandWrapper;
+import org.eclipse.papyrus.service.edit.service.ElementEditServiceUtils;
+import org.eclipse.papyrus.service.edit.service.IElementEditService;
+import org.eclipse.swt.dnd.DND;
+import org.eclipse.swt.dnd.DropTargetEvent;
+import org.eclipse.swt.dnd.TransferData;
+import org.eclipse.ui.IEditorPart;
+import org.eclipse.ui.PlatformUI;
+import org.eclipse.ui.navigator.CommonDropAdapter;
+
+/**
+ * this class manage the drop inside the model explorer
+ */
+public class CommonDropAdapterAssistant extends org.eclipse.ui.navigator.CommonDropAdapterAssistant {
+
+ public CommonDropAdapterAssistant() {
+ }
+
+ @Override
+ public IStatus handleDrop(CommonDropAdapter dropAdapter,
+ DropTargetEvent dropTargetEvent, Object dropTarget) {
+ Object targetElement = (Object) dropTarget;
+ execute(getDrop(targetElement));
+ return null;
+ }
+
+ /**
+ * get the list of command to put an eobject into another EObject,
+ * if the parameter eref is null,It will look for the good role of the child eobject
+ * @param domain the Transactional Domain , cannot be null
+ * @param targetOwner the eobject that will contain the drop object, cannot be null
+ * @param childElement that we want to move, cannot be null
+ * @param the EREFERENCE for the role of the child element, can be null
+ * @return the list of commands to to the drop
+ */
+ protected List<Command> getDropIntoCommand(TransactionalEditingDomain domain,EObject targetOwner, EObject childElement,EReference eref){
+ ArrayList<Command> commandList= new ArrayList<Command>();
+ MoveRequest moveRequest= new MoveRequest(targetOwner, childElement);
+ IElementEditService provider = ElementEditServiceUtils.getCommandProvider(targetOwner);
+ if(provider != null) {
+ // Retrieve delete command from the Element Edit service
+ ICommand command = provider.getEditCommand(moveRequest);
+
+ if(command != null) {
+ commandList.add( new GMFtoEMFCommandWrapper(command));
+ }
+
+ }
+ return commandList;
+ }
+
+ /**
+ * Get the creation command registry to test when diagrams can be created
+ * @return instance
+ */
+ private static ICreationCommandRegistry getCreationCommandRegistry() {
+ return CreationCommandRegistry.getInstance(org.eclipse.papyrus.core.Activator.PLUGIN_ID);
+ }
+
+ /**
+ * get a list that contains command to move a diagram into a new element
+ * @param domain the transactionnal edit domain, cannot be null
+ * @param targetOwner the target of the drop, cannot be null
+ * @param childElement the diagram that will move, cannot be null
+ * @return a list that contains one command to move the diagram
+ */
+ protected List<Command> getDropDiagramIntoCommand(TransactionalEditingDomain domain,EObject targetOwner, Diagram childElement){
+ List<Command> commandList = new ArrayList<Command>();
+ EReference eref = NotationPackage.eINSTANCE.getView_Element();
+ if(eref != null) {
+ String diagType = childElement.getType();
+ ICreationCommand correctCommandDescription = null;
+ // check if diagram can exist in new location
+ for(CreationCommandDescriptor desc : getCreationCommandRegistry().getCommandDescriptors()) {
+ if(desc.getCondition() == null || desc.getCondition().create(targetOwner)) {
+ try {
+ ICreationCommand cmd = desc.getCommand();
+ String type = cmd.getCreatedDiagramType();
+ if(diagType == null || diagType.equals(type)) {
+ // the descriptor correspond to existing diagram's type
+ correctCommandDescription = cmd;
+ break;
+ }
+ } catch (BackboneException e) {
+ Activator.log.error(e);
+ // stop here with unexecutable command
+ commandList.add(UnexecutableCommand.INSTANCE);
+ return commandList;
+ }
+ }
+ }
+ // check if diagram can be moved
+ if(correctCommandDescription != null && correctCommandDescription.isParentReassignable()) {
+ SetRequest setRequest = new SetRequest(childElement, eref, targetOwner);
+ IElementEditService provider = ElementEditServiceUtils.getCommandProvider(childElement);
+ if(provider != null) {
+ // Retrieve reassignment command from the Element Edit service
+ ICommand command = provider.getEditCommand(setRequest);
+
+ if(command != null) {
+ commandList.add(new GMFtoEMFCommandWrapper(command));
+ return commandList;
+ }
+ }
+ }
+ }
+ // Failed : stop here with unexecutable command
+ commandList.add(UnexecutableCommand.INSTANCE);
+ return commandList;
+ }
+ /**
+ * get the list of command to put an eobject before or after another EObject
+ * It will look for the good role of the child eobject
+ * @param domain the Transactional Domain, cannot be null
+ * @param targetOwner the eobject that will contain the drop object , cannot be null
+ * @param objectLocation the object where we want to drop the object
+ * @param newElement that we want to move, cannot be null
+ * @return the list of commands to to the drop
+ */
+ protected List<Command> getOrderChangeCommand(TransactionalEditingDomain domain,EObject targetOwner,EObject objectLocation, EObject newElement, boolean before){
+ ArrayList<Command> commandList= new ArrayList<Command>();
+ ArrayList<EStructuralFeature> possibleEFeatures= new ArrayList<EStructuralFeature>();
+ EList<EStructuralFeature> featureList=targetOwner.eClass().getEAllStructuralFeatures();
+
+ // Abort when trying to change order moving the element in one of its children
+ if (EcoreUtil.isAncestor(newElement, targetOwner)) {
+ return Collections.emptyList();
+ }
+
+ //find the feature between childreen and owner
+ Iterator<EStructuralFeature> iterator= featureList.iterator();
+ while (iterator.hasNext()) {
+ EStructuralFeature eStructuralFeature = (EStructuralFeature) iterator.next();
+
+ if( eStructuralFeature instanceof EReference){
+ EReference ref= (EReference)eStructuralFeature;
+
+ if( ref.isContainment()){
+
+ if( isSubClass(ref.getEType(),newElement.eClass() )){
+ possibleEFeatures.add(eStructuralFeature);
+ }
+
+ }
+ }
+ }
+
+ //create the command
+ Iterator<EStructuralFeature> iteratorFeature= possibleEFeatures.iterator();
+ while (iteratorFeature.hasNext()) {
+ EStructuralFeature eStructuralFeature = (EStructuralFeature) iteratorFeature
+ .next();
+ ArrayList<EObject> tmp=new ArrayList<EObject>();
+ if(targetOwner.eGet(eStructuralFeature) instanceof Collection<?>){
+ //get all element of this efeature
+ tmp.addAll((Collection<EObject>)targetOwner.eGet(eStructuralFeature));
+
+ if(!newElement.equals(objectLocation)){
+ tmp.remove(newElement);
+ //normally tmp.indexOf(objectLocation)!= -1
+ //if this the case objectlocation=new element and
+ //it has been removed
+ int indexObject=tmp.indexOf(objectLocation);
+ if( before&& indexObject!=-1){
+ tmp.add(tmp.indexOf(objectLocation), newElement);
+ }
+ else if( !before&& indexObject!=-1){
+ tmp.add(tmp.indexOf(objectLocation)+1, newElement);
+ }
+ }
+ }
+ else{tmp.add(newElement);
+ }
+
+ SetRequest setRequest= new SetRequest(targetOwner, eStructuralFeature, tmp);
+ IElementEditService provider = ElementEditServiceUtils.getCommandProvider(targetOwner);
+ if(provider != null) {
+ // Retrieve delete command from the Element Edit service
+ ICommand command = provider.getEditCommand(setRequest);
+
+ if(command != null) {
+ commandList.add( new GMFtoEMFCommandWrapper(command));
+ }
+ }
+ }
+ return commandList;
+ }
+
+
+ /**
+ * verify from a list of command if it can be dropped
+ * @param commandList, cannot be null but can be an empty list
+ *
+ * @return true or false
+ */
+ protected boolean canDrop(List<Command> commandList){
+ Iterator<Command> iterator= commandList.iterator();
+ while (iterator.hasNext()) {
+ Command abstractCommand = (Command) iterator.next();
+ if(abstractCommand.canExecute()){
+ return true;
+ }
+ }
+ return false;
+ }
+
+ /**
+ * execute command for the drop
+ * @param commandList
+ *
+ * @return true or false
+ */
+ protected void execute(List<Command> commandList){
+ Iterator<Command> iterator= commandList.iterator();
+ while (iterator.hasNext()) {
+ Command abstractCommand = (Command) iterator.next();
+ if(abstractCommand.canExecute()){
+ getEditingDomain().getCommandStack().execute(abstractCommand);
+ }
+ }
+ }
+
+ /**
+ * get the list of good command by taking in account if this is a change order or a drop into
+ * @param target the target object of the drop
+ * @return the list of command
+ */
+ public List<Command> getDrop (Object target) {
+ CommonDropAdapter dropAdapter =getCommonDropAdapter();
+ List<Command> commandList=new ArrayList<Command>();
+ switch (dropAdapter.getCurrentOperation()) {
+ case DND.DROP_MOVE:
+ if(dropAdapter.getCurrentLocation()==ViewerDropAdapter.LOCATION_BEFORE){
+ if(target instanceof ModelElementItem){
+ commandList=getOrderChangeCommand(target, true);
+ }
+ }
+ else if(dropAdapter.getCurrentLocation()==ViewerDropAdapter.LOCATION_AFTER){
+ if(target instanceof ModelElementItem){
+ commandList=getOrderChangeCommand(target, false);
+ }
+ }
+ else if(dropAdapter.getCurrentLocation()==ViewerDropAdapter.LOCATION_ON){
+ if(target instanceof ModelElementItem){
+ commandList=getDropIntoCommand(target, null);}
+ if(target instanceof LinkItem){
+ commandList=getDropIntoCommand(((LinkItem)target).getParent(),((LinkItem)target).getReference() );}
+ }
+
+ else if(dropAdapter.getCurrentLocation()==ViewerDropAdapter.LOCATION_NONE){
+ }
+ break;
+ }
+ return commandList;
+ }
+ /**
+ * Test if a possibleSub eclass is a sub eclass
+ * @param aclass, cannot be null
+ * @param possibleSubClasse, cannot be null
+ * @return true if possible eclass is a subtype of a eclass or false
+ */
+ public boolean isSubClass(EClassifier aclass, EClass possibleSubClasse){
+ if(aclass.equals(possibleSubClasse)){
+ return true;
+ }
+ EList<EClass> superTypeList=possibleSubClasse.getEAllSuperTypes();
+ if(superTypeList.contains(aclass)){
+ return true;
+ }
+ return false;
+ }
+
+ @Override
+ public IStatus validateDrop(Object target, int operation,
+ TransferData transferType) {
+ List<Command> commandList=getDrop(target);
+ //List<Command> commandList=getDropCommand(target);
+ if(canDrop(commandList)){
+ return Status.OK_STATUS;
+ }
+ return Status.CANCEL_STATUS;
+ }
+
+ /**
+ * get the list of commands to drop an element
+ * @param target, can be null but do nothing
+ * @param the role where there is a drop ( can be null)
+ * @return the list of the commands
+ */
+ protected List<Command> getDropIntoCommand(final Object target, EReference eref) {
+
+ //init
+ ArrayList<Command> result= new ArrayList<Command>();
+ EObject targetEObject=null;
+
+ //target is an EObject?
+ if(target instanceof EObject){
+ targetEObject= ((EObject)target);
+ }
+ if(target instanceof IAdaptable){
+ targetEObject= ((EObject)((IAdaptable)target).getAdapter(EObject.class));
+ }
+ if(targetEObject==null){
+ return result;
+ }
+
+ //get Command from the selection
+ ISelection selection = LocalSelectionTransfer.getTransfer().getSelection();
+ if (selection instanceof IStructuredSelection) {
+ List<?> selectedElements = ((IStructuredSelection) selection).toList();
+ Iterator<?> it=selectedElements.iterator();
+ while (it.hasNext()) {
+ Object object = it.next();
+ EObject eObjectchild=null;
+ if (object instanceof IAdaptable) {
+ eObjectchild = (EObject) ((IAdaptable) object).getAdapter(EObject.class);
+ }
+ else if(object instanceof EObject){
+ eObjectchild=(EObject)object;
+ }
+
+ if(eObjectchild instanceof Diagram){
+ result.addAll(getDropDiagramIntoCommand(getEditingDomain(), targetEObject,(Diagram) eObjectchild));
+ }
+ //test if object is an eobject
+ else if(eObjectchild!=null){
+
+ result.addAll(getDropIntoCommand(getEditingDomain(), targetEObject, eObjectchild, eref));
+ }
+
+ }
+ }
+
+ return result;
+ }
+
+ /**
+ * get the list of commands to drop an element
+ * @param target, can be null but do nothing
+ * @return the list of the commands
+ */
+ protected List<Command> getOrderChangeCommand(final Object target, boolean before) {
+
+ //init
+ ArrayList<Command> result= new ArrayList<Command>();
+ EObject objectLocation=null;
+ EObject objectOwner=null;
+
+ //target is an EObject?
+ if(target instanceof IAdaptable){
+ objectLocation= ((EObject)((IAdaptable)target).getAdapter(EObject.class));
+ objectOwner=objectLocation.eContainer();
+ }
+ if(objectLocation==null){
+ return result;
+ }
+
+ //get Command from the selection
+ ISelection selection = LocalSelectionTransfer.getTransfer().getSelection();
+ if (selection instanceof IStructuredSelection) {
+ List<?> selectedElements = ((IStructuredSelection) selection).toList();
+ Iterator<?> it=selectedElements.iterator();
+ while (it.hasNext()) {
+ Object object = it.next();
+ if (object instanceof IAdaptable) {
+ EObject eObjectchild = (EObject) ((IAdaptable) object).getAdapter(EObject.class);
+ //test if object is an eobject
+ if(eObjectchild!=null&& objectOwner!=null){
+
+ result.addAll(getOrderChangeCommand(getEditingDomain(), objectOwner, objectLocation, eObjectchild, before));
+ }
+ }
+ }
+ }
+ return result;
+ }
+
+ /**
+ * get the editing domain
+ * @return get the Transaction Editing Domain
+ */
+ protected TransactionalEditingDomain getEditingDomain() {
+ return EditorUtils.getTransactionalEditingDomain();
+ }
+
+ /**
+ *
+ * @return multiDiagramEditor
+ */
+ protected IMultiDiagramEditor getMultiDiagramEditor() {
+ IEditorPart editorPart = PlatformUI.getWorkbench()
+ .getActiveWorkbenchWindow().getActivePage().getActiveEditor();
+ if (editorPart instanceof IMultiDiagramEditor) {
+ return (IMultiDiagramEditor) editorPart;
+ }
+ return null;
+ }
+}
diff --git a/plugins/views/modelexplorer/org.eclipse.papyrus.modelexplorer/src/org/eclipse/papyrus/modelexplorer/dnd/EObjectDragAdapterAssistant.java b/plugins/views/modelexplorer/org.eclipse.papyrus.modelexplorer/src/org/eclipse/papyrus/modelexplorer/dnd/EObjectDragAdapterAssistant.java
new file mode 100644
index 00000000000..cf70c639a6c
--- /dev/null
+++ b/plugins/views/modelexplorer/org.eclipse.papyrus.modelexplorer/src/org/eclipse/papyrus/modelexplorer/dnd/EObjectDragAdapterAssistant.java
@@ -0,0 +1,77 @@
+/*****************************************************************************
+ * Copyright (c) 2011 CEA LIST.
+ *
+ *
+ * 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:
+ * Vincent Lorenzo (CEA LIST) vincent.lorenzo@cea.fr - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.modelexplorer.dnd;
+
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+import org.eclipse.core.runtime.IAdaptable;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.edit.ui.dnd.LocalTransfer;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.jface.viewers.StructuredSelection;
+import org.eclipse.swt.dnd.DragSourceEvent;
+import org.eclipse.swt.dnd.Transfer;
+import org.eclipse.ui.navigator.CommonDragAdapterAssistant;
+
+/**
+ * This class allows to provides Drag&Drop between the Model Explorer and the Tables (or others View/Editors)
+ *
+ *
+ *
+ */
+public class EObjectDragAdapterAssistant extends CommonDragAdapterAssistant {
+
+ /**
+ *
+ * @see org.eclipse.ui.navigator.CommonDragAdapterAssistant#getSupportedTransferTypes()
+ *
+ * @return
+ */
+ @Override
+ public Transfer[] getSupportedTransferTypes() {
+ return new Transfer[]{ LocalTransfer.getInstance() };
+ }
+
+ /**
+ *
+ * @see org.eclipse.ui.navigator.CommonDragAdapterAssistant#setDragData(org.eclipse.swt.dnd.DragSourceEvent,
+ * org.eclipse.jface.viewers.IStructuredSelection)
+ *
+ * @param anEvent
+ * @param aSelection
+ * @return
+ */
+ @Override
+ public boolean setDragData(DragSourceEvent anEvent, IStructuredSelection aSelection) {
+ Iterator<?> iter = aSelection.iterator();
+ List<Object> selectedElements = new ArrayList<Object>();
+
+ while(iter.hasNext()) {
+ Object current = iter.next();
+ if(current instanceof IAdaptable) {
+ EObject eobject = (EObject)((IAdaptable)current).getAdapter(EObject.class);
+ if(eobject != null) {
+ selectedElements.add(eobject);
+ }
+ }
+ }
+
+ if(!selectedElements.isEmpty()) {
+ anEvent.data = new StructuredSelection(selectedElements);
+ }
+ return anEvent.data != null;
+ }
+}
diff --git a/plugins/views/modelexplorer/org.eclipse.papyrus.modelexplorer/src/org/eclipse/papyrus/modelexplorer/factory/DefaultEMFActionsFactory.java b/plugins/views/modelexplorer/org.eclipse.papyrus.modelexplorer/src/org/eclipse/papyrus/modelexplorer/factory/DefaultEMFActionsFactory.java
new file mode 100644
index 00000000000..69ef9cc563b
--- /dev/null
+++ b/plugins/views/modelexplorer/org.eclipse.papyrus.modelexplorer/src/org/eclipse/papyrus/modelexplorer/factory/DefaultEMFActionsFactory.java
@@ -0,0 +1,182 @@
+/*****************************************************************************
+ * Copyright (c) 2009 Atos Origin.
+ *
+ *
+ * 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:
+ * Emilien Perico (Atos Origin) emilien.perico@atosorigin.com - Initial API and implementation
+ * Vincent Lorenzo (CEA-LIST) vincent.lorenzo@cea.fr @deprecated
+ *****************************************************************************/
+package org.eclipse.papyrus.modelexplorer.factory;
+
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.LinkedList;
+import java.util.List;
+
+import org.eclipse.emf.edit.domain.EditingDomain;
+import org.eclipse.emf.edit.ui.action.CopyAction;
+import org.eclipse.emf.edit.ui.action.CutAction;
+import org.eclipse.emf.edit.ui.action.LoadResourceAction;
+import org.eclipse.emf.edit.ui.action.PasteAction;
+import org.eclipse.emf.workspace.ui.actions.RedoActionWrapper;
+import org.eclipse.emf.workspace.ui.actions.UndoActionWrapper;
+import org.eclipse.jface.action.Action;
+import org.eclipse.jface.viewers.ISelectionProvider;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.jface.viewers.StructuredSelection;
+import org.eclipse.papyrus.modelexplorer.NavigatorUtils;
+import org.eclipse.ui.IActionBars;
+import org.eclipse.ui.ISharedImages;
+import org.eclipse.ui.PlatformUI;
+import org.eclipse.ui.actions.ActionFactory;
+import org.eclipse.ui.navigator.CommonNavigator;
+
+/**
+ * The Class DefaultEMFActionsFactory for creating a default action from EMF.
+ * Undefined actions are not still in use or might be overridden
+ *
+ * @author Emilien Perico
+ * @deprecated These actions are now rewritten using the Eclipse Framework
+ */
+@Deprecated
+public class DefaultEMFActionsFactory implements IActionHandlerFactory {
+
+ protected List<Action> actions = new LinkedList<Action>();
+
+ protected CutAction cutAction;
+
+ protected CopyAction copyAction;
+
+ protected PasteAction pasteAction;
+
+ protected UndoActionWrapper undoAction;
+
+ protected RedoActionWrapper redoAction;
+
+ protected LoadResourceAction loadResourceAction;
+
+ /**
+ * {@inheritDoc}
+ */
+ public List<Action> createActions(EditingDomain editingDomain) {
+ ISharedImages sharedImages = PlatformUI.getWorkbench().getSharedImages();
+
+ // Create Cut action
+ this.cutAction = new CutAction(editingDomain);
+ this.cutAction.setImageDescriptor(sharedImages.getImageDescriptor(ISharedImages.IMG_TOOL_CUT));
+ actions.add(cutAction);
+
+ // Create Copy action
+ this.copyAction = new CopyAction(editingDomain);
+ this.copyAction.setImageDescriptor(sharedImages.getImageDescriptor(ISharedImages.IMG_TOOL_COPY));
+ actions.add(copyAction);
+
+ // Create Paste action
+ this.pasteAction = new PasteAction(editingDomain);
+ this.pasteAction.setImageDescriptor(sharedImages.getImageDescriptor(ISharedImages.IMG_TOOL_PASTE));
+ actions.add(pasteAction);
+
+ // Undo action
+ this.undoAction = new UndoActionWrapper();
+ this.undoAction.setImageDescriptor(sharedImages.getImageDescriptor(ISharedImages.IMG_TOOL_UNDO));
+ actions.add(undoAction);
+
+ // Redo action
+ this.redoAction = new RedoActionWrapper();
+ this.redoAction.setImageDescriptor(sharedImages.getImageDescriptor(ISharedImages.IMG_TOOL_REDO));
+ actions.add(redoAction);
+
+ // Load Resource action
+ this.loadResourceAction = new LoadResourceAction(editingDomain);
+ actions.add(loadResourceAction);
+
+ return actions;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void activate(CommonNavigator activeViewPart) {
+ cutAction.setActiveWorkbenchPart(activeViewPart);
+ copyAction.setActiveWorkbenchPart(activeViewPart);
+ pasteAction.setActiveWorkbenchPart(activeViewPart);
+ undoAction.setActiveWorkbenchPart(activeViewPart);
+ redoAction.setActiveWorkbenchPart(activeViewPart);
+ loadResourceAction.setActiveWorkbenchPart(activeViewPart);
+
+ ISelectionProvider selectionProvider = null;
+ if(activeViewPart.getCommonViewer() instanceof ISelectionProvider) {
+ selectionProvider = activeViewPart.getCommonViewer();
+ selectionProvider.addSelectionChangedListener(cutAction);
+ selectionProvider.addSelectionChangedListener(copyAction);
+ selectionProvider.addSelectionChangedListener(pasteAction);
+ }
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void deactivate(CommonNavigator activeViewPart) {
+ cutAction.setActiveWorkbenchPart(null);
+ copyAction.setActiveWorkbenchPart(null);
+ pasteAction.setActiveWorkbenchPart(null);
+ undoAction.setActiveWorkbenchPart(null);
+ redoAction.setActiveWorkbenchPart(null);
+ loadResourceAction.setActiveWorkbenchPart(null);
+
+ ISelectionProvider selectionProvider = null;
+ if(activeViewPart.getCommonViewer() instanceof ISelectionProvider) {
+ selectionProvider = activeViewPart.getCommonViewer();
+ selectionProvider.removeSelectionChangedListener(cutAction);
+ selectionProvider.removeSelectionChangedListener(copyAction);
+ selectionProvider.removeSelectionChangedListener(pasteAction);
+ }
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void fillActionBars(IActionBars actionBars) {
+ actionBars.setGlobalActionHandler(ActionFactory.CUT.getId(), cutAction);
+ actionBars.setGlobalActionHandler(ActionFactory.COPY.getId(), copyAction);
+ actionBars.setGlobalActionHandler(ActionFactory.PASTE.getId(), pasteAction);
+ actionBars.setGlobalActionHandler(ActionFactory.UNDO.getId(), undoAction);
+ actionBars.setGlobalActionHandler(ActionFactory.REDO.getId(), redoAction);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @SuppressWarnings({ "rawtypes", "unchecked" })
+ public void update(IStructuredSelection structuredSelection) {
+ ArrayList array = new ArrayList();
+ Iterator iterator = structuredSelection.iterator();
+ while(iterator.hasNext()) {
+ Object object = iterator.next();
+ if(NavigatorUtils.resolveSemanticObject(object) != null) {
+ array.add(NavigatorUtils.resolveSemanticObject(object));
+ }
+ }
+ StructuredSelection st = new StructuredSelection(array);
+ cutAction.updateSelection(st);
+ cutAction.setEnabled((cutAction.createCommand(st.toList())).canExecute());
+ copyAction.updateSelection(st);
+ copyAction.setEnabled((copyAction.createCommand(st.toList())).canExecute());
+ pasteAction.updateSelection(st);
+ pasteAction.setEnabled((pasteAction.createCommand(st.toList())).canExecute());
+ loadResourceAction.update();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public List<Action> getActions() {
+ return actions;
+ }
+
+}
diff --git a/plugins/views/modelexplorer/org.eclipse.papyrus.modelexplorer/src/org/eclipse/papyrus/modelexplorer/factory/IActionHandlerFactory.java b/plugins/views/modelexplorer/org.eclipse.papyrus.modelexplorer/src/org/eclipse/papyrus/modelexplorer/factory/IActionHandlerFactory.java
new file mode 100644
index 00000000000..fc413bb4357
--- /dev/null
+++ b/plugins/views/modelexplorer/org.eclipse.papyrus.modelexplorer/src/org/eclipse/papyrus/modelexplorer/factory/IActionHandlerFactory.java
@@ -0,0 +1,85 @@
+/*****************************************************************************
+ * Copyright (c) 2009 Atos Origin.
+ *
+ *
+ * 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:
+ * Emilien Perico (Atos Origin) emilien.perico@atosorigin.com - Initial API and implementation
+ * Vincent Lorenzo (CEA-LIST) @deprecated
+ *****************************************************************************/
+package org.eclipse.papyrus.modelexplorer.factory;
+
+import java.util.List;
+
+import org.eclipse.emf.edit.domain.EditingDomain;
+import org.eclipse.jface.action.Action;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.ui.IActionBars;
+import org.eclipse.ui.navigator.CommonNavigator;
+
+/**
+ * A factory for creating Action objects from org.eclipse.jface.action
+ *
+ * @deprecated The actions should be written using the Eclipse Framework (org.eclipse.ui.menu, org.eclipse.ui.handler, org.eclipse.ui.command)
+ */
+@Deprecated
+public interface IActionHandlerFactory {
+
+ /**
+ * Creates a new IActionHandler object.
+ *
+ * @param editingDomain
+ * the editing domain
+ *
+ * @return the list of created actions
+ */
+ List<Action> createActions(EditingDomain editingDomain);
+
+ /**
+ * Gets the actions.
+ *
+ * @return the actions list
+ */
+ List<Action> getActions();
+
+ /**
+ * Activate the action.
+ *
+ * @param activeViewPart
+ * the active view part
+ */
+ void activate(CommonNavigator activeViewPart);
+
+ /**
+ * Deactivate the action.
+ *
+ * @param activeViewPart
+ * the active view part
+ */
+ void deactivate(CommonNavigator activeViewPart);
+
+ /**
+ * Update action from the selection
+ *
+ * @param structuredSelection
+ * the structured selection
+ */
+ void update(IStructuredSelection structuredSelection);
+
+ /**
+ * Adds the applicable actions to a part's action bars, including setting
+ * any global action handlers.
+ * <p>
+ * The default implementation does nothing.
+ * </p>
+ *
+ * @param actionBars
+ * the part's action bars
+ */
+ void fillActionBars(IActionBars actionBars);
+
+}
diff --git a/plugins/views/modelexplorer/org.eclipse.papyrus.modelexplorer/src/org/eclipse/papyrus/modelexplorer/handler/AbstractCommandHandler.java b/plugins/views/modelexplorer/org.eclipse.papyrus.modelexplorer/src/org/eclipse/papyrus/modelexplorer/handler/AbstractCommandHandler.java
new file mode 100644
index 00000000000..d0fec5d2660
--- /dev/null
+++ b/plugins/views/modelexplorer/org.eclipse.papyrus.modelexplorer/src/org/eclipse/papyrus/modelexplorer/handler/AbstractCommandHandler.java
@@ -0,0 +1,178 @@
+/*****************************************************************************
+ * Copyright (c) 2010 CEA LIST.
+ *
+ *
+ * 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:
+ *
+ * Patrick Tessier (CEA LIST) Patrick.tessier@cea.fr - Initial API and implementation
+ * Vincent Lorenzo (CEA-LIST) vincent.lorenzo@cea.fr
+ *****************************************************************************/
+package org.eclipse.papyrus.modelexplorer.handler;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.eclipse.core.commands.ExecutionEvent;
+import org.eclipse.core.commands.ExecutionException;
+import org.eclipse.core.runtime.IAdaptable;
+import org.eclipse.core.runtime.Platform;
+import org.eclipse.emf.common.command.Command;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.transaction.TransactionalEditingDomain;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.papyrus.core.services.ServiceException;
+import org.eclipse.papyrus.core.utils.BusinessModelResolver;
+import org.eclipse.papyrus.core.utils.ServiceUtilsForActionHandlers;
+import org.eclipse.papyrus.modelexplorer.Activator;
+import org.eclipse.ui.IWorkbenchWindow;
+import org.eclipse.ui.PlatformUI;
+
+/**
+ * <pre>
+ *
+ * This abstract command handler manages:
+ * - current selection in order to build a list of the selected {@link EObject}
+ * - execute the command (returned by children) in Papyrus {@link TransactionalEditingDomain}
+ * - calculate the command enablement and visibility regarding the command executability
+ * (the command is now shown in menu if not executable).
+ *
+ * </pre>
+ */
+public abstract class AbstractCommandHandler extends AbstractModelExplorerHandler {
+
+ /**
+ * <pre>
+ *
+ * Returns the command to execute (to be implemented
+ * in children implementing this class)
+ *
+ * @return the command to execute
+ *
+ * </pre>
+ */
+ protected abstract Command getCommand();
+
+ /**
+ * <pre>
+ * Get the selected element, the first selected element if several are selected or null
+ * if no selection or the selection is not an {@link EObject}.
+ *
+ * @return selected {@link EObject} or null
+ * </pre>
+ *
+ */
+ protected EObject getSelectedElement() {
+ EObject eObject = null;
+
+ // Get current selection
+ IWorkbenchWindow activeWorkbenchWindow = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
+ Object selection = (activeWorkbenchWindow != null) ? activeWorkbenchWindow.getSelectionService().getSelection() : null;
+
+ // Treat non-null selected object (try to adapt and return EObject)
+ if(selection != null) {
+
+ // Get first element if the selection is an IStructuredSelection
+ if(selection instanceof IStructuredSelection) {
+ IStructuredSelection structuredSelection = (IStructuredSelection)selection;
+ selection = structuredSelection.getFirstElement();
+ }
+
+ if(selection instanceof IAdaptable) {
+ selection = ((IAdaptable)selection).getAdapter(EObject.class);
+ }
+
+ Object businessObject = BusinessModelResolver.getInstance().getBusinessModel(selection);
+ if(businessObject instanceof EObject) {
+ eObject = (EObject)businessObject;
+ }
+ }
+
+ return eObject;
+ }
+
+ /**
+ * <pre>
+ * Parse current selection and extract the list of {@link EObject} from
+ * this selection.
+ *
+ * This also tries to adapt selected element into {@link EObject}
+ * (for example to get the {@link EObject} from a selection in the ModelExplorer).
+ *
+ * @return a list of currently selected {@link EObject}
+ * </pre>
+ *
+ */
+ protected List<EObject> getSelectedElements() {
+
+ List<EObject> selectedEObjects = new ArrayList<EObject>();
+
+ // Get current selection
+ IWorkbenchWindow activeWorkbenchWindow = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
+ Object selection = (activeWorkbenchWindow != null) ? activeWorkbenchWindow.getSelectionService().getSelection() : null;
+
+ // Treat non-null selected object (try to adapt and return EObject)
+ if(selection != null) {
+
+ // Parse current selection
+ if(selection instanceof IStructuredSelection) {
+ IStructuredSelection structuredSelection = (IStructuredSelection)selection;
+ for(Object current : structuredSelection.toArray()) {
+ // Adapt current selection to EObject
+ if(current instanceof IAdaptable) {
+ EObject selectedElement = (EObject)((IAdaptable)current).getAdapter(EObject.class);
+ if(selectedElement != null) {//we avoid to add null element in the list!
+ selectedEObjects.add(selectedElement);
+ }
+ }
+ }
+ } else { // Not a IStructuredSelection
+ // Adapt current selection to EObject
+ EObject selectedElement = null;
+ if(selection instanceof IAdaptable) {
+ selectedElement = (EObject)((IAdaptable)selection).getAdapter(EObject.class);
+ }
+ if(selectedElement == null) {
+ selectedElement = (EObject)Platform.getAdapterManager().getAdapter(selection, EObject.class);
+ }
+ if(selectedElement != null) { //we avoid to add null element in the list!
+ selectedEObjects.add(selectedElement);
+ }
+ }
+ }
+
+ return selectedEObjects;
+ }
+
+ /**
+ *
+ * @see org.eclipse.core.commands.AbstractHandler#execute(org.eclipse.core.commands.ExecutionEvent)
+ *
+ * @param event
+ * @return null
+ * @throws ExecutionException
+ */
+ public Object execute(ExecutionEvent event) throws ExecutionException {
+ try {
+ ServiceUtilsForActionHandlers.getInstance().getTransactionalEditingDomain().getCommandStack().execute(getCommand());
+ } catch (ServiceException e) {
+ Activator.log.error("Unexpected error while executing command.", e); //$NON-NLS-1$
+ }
+
+ return null;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public boolean isEnabled() {
+ Command command = getCommand();
+ return command != null && getCommand().canExecute();
+ }
+
+}
diff --git a/plugins/views/modelexplorer/org.eclipse.papyrus.modelexplorer/src/org/eclipse/papyrus/modelexplorer/handler/AbstractModelExplorerHandler.java b/plugins/views/modelexplorer/org.eclipse.papyrus.modelexplorer/src/org/eclipse/papyrus/modelexplorer/handler/AbstractModelExplorerHandler.java
new file mode 100644
index 00000000000..6f41b2117e5
--- /dev/null
+++ b/plugins/views/modelexplorer/org.eclipse.papyrus.modelexplorer/src/org/eclipse/papyrus/modelexplorer/handler/AbstractModelExplorerHandler.java
@@ -0,0 +1,106 @@
+/*****************************************************************************
+ * Copyright (c) 2011 CEA LIST.
+ *
+ *
+ * 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:
+ * Vincent Lorenzo (CEA LIST) vincent.lorenzo@cea.fr - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.modelexplorer.handler;
+
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+import org.eclipse.core.commands.AbstractHandler;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.transaction.TransactionalEditingDomain;
+import org.eclipse.gmf.runtime.notation.Diagram;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.papyrus.core.services.ServiceException;
+import org.eclipse.papyrus.modelexplorer.NavigatorUtils;
+import org.eclipse.papyrus.sasheditor.contentprovider.IPageMngr;
+import org.eclipse.ui.PlatformUI;
+
+/**
+ * This provides facilities to get the TransactionEditingDomain and the PageManager from the Model Explorer
+ *
+ *
+ *
+ */
+public abstract class AbstractModelExplorerHandler extends AbstractHandler {
+
+ /**
+ * Returns the
+ *
+ * @return
+ * the current editing domain
+ */
+ protected TransactionalEditingDomain getEditingDomain() {
+ TransactionalEditingDomain editingDomain = null;
+ try {
+ editingDomain = org.eclipse.papyrus.core.utils.ServiceUtilsForActionHandlers.getInstance().getTransactionalEditingDomain();
+ } catch (ServiceException e) {
+ //we are closing the editor, so the model explorer has nothing to display
+ // e.printStackTrace();
+ }
+ return editingDomain;
+ }
+
+ /**
+ * Returns the page manager
+ *
+ * @return
+ * the page manager
+ */
+ protected IPageMngr getPageManager() {
+ IPageMngr pageMngr = null;
+ try {
+ pageMngr = org.eclipse.papyrus.core.utils.ServiceUtilsForActionHandlers.getInstance().getIPageMngr();
+ } catch (ServiceException e) {
+ //we are closing the editor, so the model explorer has nothing to display
+ // e.printStackTrace();
+ }
+ return pageMngr;
+ }
+
+ /**
+ * Returns the list of selected diagrams
+ *
+ * @return
+ * the list of selected diagrams
+ */
+ protected List<Diagram> getSelectedDiagrams() {
+ List<Diagram> diagrams = new ArrayList<Diagram>();
+ ISelection selection = null;
+
+ // Get current selection
+ selection = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getSelectionService().getSelection();
+
+ // Get first element if the selection is an IStructuredSelection
+ if(selection instanceof IStructuredSelection) {
+ IStructuredSelection structuredSelection = (IStructuredSelection)selection;
+ Iterator<?> iter = structuredSelection.iterator();
+ while(iter.hasNext()) {
+ Object current = iter.next();
+ /**
+ * Get the diagram object.
+ * This getElement is used in order to use IAdaptabel mechanisme
+ * For example for Facet Elements
+ */
+ EObject diag = NavigatorUtils.getElement(current, EObject.class);
+ if(diag instanceof Diagram) {
+ diagrams.add((Diagram)diag);
+ }
+ }
+ }
+
+ return diagrams;
+ }
+}
diff --git a/plugins/views/modelexplorer/org.eclipse.papyrus.modelexplorer/src/org/eclipse/papyrus/modelexplorer/handler/CloseHandler.java b/plugins/views/modelexplorer/org.eclipse.papyrus.modelexplorer/src/org/eclipse/papyrus/modelexplorer/handler/CloseHandler.java
new file mode 100644
index 00000000000..96dd8232a70
--- /dev/null
+++ b/plugins/views/modelexplorer/org.eclipse.papyrus.modelexplorer/src/org/eclipse/papyrus/modelexplorer/handler/CloseHandler.java
@@ -0,0 +1,94 @@
+/*****************************************************************************
+ * Copyright (c) 2011 CEA LIST.
+ *
+ *
+ * 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:
+ * Vincent Lorenzo (CEA LIST) vincent.lorenzo@cea.fr - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.modelexplorer.handler;
+
+import java.util.Hashtable;
+import java.util.Iterator;
+
+import org.eclipse.core.commands.ExecutionEvent;
+import org.eclipse.core.commands.ExecutionException;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IConfigurationElement;
+import org.eclipse.core.runtime.IExecutableExtension;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.papyrus.sasheditor.contentprovider.IPageMngr;
+import org.eclipse.ui.handlers.HandlerUtil;
+
+/**
+ * This handler allows to Close Diagrams and Tables
+ *
+ *
+ *
+ */
+public class CloseHandler extends AbstractModelExplorerHandler implements IExecutableExtension {
+
+ /** parameters for this action */
+ /**
+ * close all open elements
+ */
+ public static final String PARAMETER_ALL = "all"; //$NON-NLS-1$
+
+ /**
+ * Close only the selected elements
+ */
+ public static final String PARAMETER_SELECTION = "selection"; //$NON-NLS-1$
+
+ /** parameter for this handler */
+ protected String parameter = null;
+
+ /** parameter ID */
+ protected String parameterID = "close_parameter"; //$NON-NLS-1$
+
+ /**
+ *
+ * @see org.eclipse.core.commands.AbstractHandler#execute(org.eclipse.core.commands.ExecutionEvent)
+ *
+ * @param event
+ * @return
+ * @throws ExecutionException
+ */
+ public Object execute(ExecutionEvent event) throws ExecutionException {
+ ISelection selection = HandlerUtil.getCurrentSelection(event);
+ IPageMngr pageMngr = getPageManager();
+ if(selection instanceof IStructuredSelection && pageMngr != null) {
+ if(PARAMETER_SELECTION.equals(parameter)) {
+ Iterator<?> iter = ((IStructuredSelection)selection).iterator();
+ while(iter.hasNext()) {
+ pageMngr.closePage(iter.next());
+ }
+ } else if(PARAMETER_ALL.equals(parameter)) {
+ pageMngr.closeAllOpenedPages();
+ }
+ }
+ return null;
+ }
+
+ /**
+ *
+ * @see org.eclipse.core.runtime.IExecutableExtension#setInitializationData(org.eclipse.core.runtime.IConfigurationElement, java.lang.String,
+ * java.lang.Object)
+ *
+ * @param config
+ * @param propertyName
+ * @param data
+ * @throws CoreException
+ */
+ public void setInitializationData(IConfigurationElement config, String propertyName, Object data) throws CoreException {
+ if(data instanceof Hashtable && this.parameterID != null) {
+ this.parameter = (String)((Hashtable)data).get(this.parameterID);
+ }
+ }
+
+}
diff --git a/plugins/views/modelexplorer/org.eclipse.papyrus.modelexplorer/src/org/eclipse/papyrus/modelexplorer/handler/CopyHandler.java b/plugins/views/modelexplorer/org.eclipse.papyrus.modelexplorer/src/org/eclipse/papyrus/modelexplorer/handler/CopyHandler.java
new file mode 100644
index 00000000000..041fa52f077
--- /dev/null
+++ b/plugins/views/modelexplorer/org.eclipse.papyrus.modelexplorer/src/org/eclipse/papyrus/modelexplorer/handler/CopyHandler.java
@@ -0,0 +1,42 @@
+/*****************************************************************************
+ * Copyright (c) 2011 CEA LIST.
+ *
+ *
+ * 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:
+ * Vincent Lorenzo (CEA LIST) vincent.lorenzo@cea.fr - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.modelexplorer.handler;
+
+import java.util.List;
+
+import org.eclipse.emf.common.command.Command;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.edit.command.CopyToClipboardCommand;
+
+/**
+ * Handler for the Copy Action
+ *
+ *
+ *
+ */
+public class CopyHandler extends AbstractCommandHandler {
+
+ /**
+ *
+ * @see org.eclipse.papyrus.modelexplorer.handler.AbstractCommandHandler#getCommand()
+ *
+ * @return
+ */
+ @Override
+ protected Command getCommand() {
+ List<EObject> selection = getSelectedElements();
+ return CopyToClipboardCommand.create(getEditingDomain(), selection);
+ }
+
+}
diff --git a/plugins/views/modelexplorer/org.eclipse.papyrus.modelexplorer/src/org/eclipse/papyrus/modelexplorer/handler/CutHandler.java b/plugins/views/modelexplorer/org.eclipse.papyrus.modelexplorer/src/org/eclipse/papyrus/modelexplorer/handler/CutHandler.java
new file mode 100644
index 00000000000..78c04ac6b46
--- /dev/null
+++ b/plugins/views/modelexplorer/org.eclipse.papyrus.modelexplorer/src/org/eclipse/papyrus/modelexplorer/handler/CutHandler.java
@@ -0,0 +1,47 @@
+/*****************************************************************************
+ * Copyright (c) 2011 CEA LIST.
+ *
+ *
+ * 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:
+ * Vincent Lorenzo (CEA LIST) vincent.lorenzo@cea.fr - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.modelexplorer.handler;
+
+import java.util.List;
+
+import org.eclipse.emf.common.command.Command;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.edit.command.CutToClipboardCommand;
+
+/**
+ * Handler for the Cur Action
+ *
+ *
+ *
+ */
+public class CutHandler extends AbstractCommandHandler {
+
+ /**
+ *
+ * @see org.eclipse.papyrus.modelexplorer.handler.AbstractCommandHandler#getCommand()
+ *
+ * @return
+ */
+ @Override
+ protected Command getCommand() {
+ List<EObject> selection = getSelectedElements();
+ return CutToClipboardCommand.create(getEditingDomain(), selection);
+ }
+ @Override
+ public boolean isEnabled() {
+ //done explicitly inorder to desactivate it.
+ return false;
+ }
+
+}
diff --git a/plugins/views/modelexplorer/org.eclipse.papyrus.modelexplorer/src/org/eclipse/papyrus/modelexplorer/handler/DeleteCommandHandler.java b/plugins/views/modelexplorer/org.eclipse.papyrus.modelexplorer/src/org/eclipse/papyrus/modelexplorer/handler/DeleteCommandHandler.java
new file mode 100644
index 00000000000..a584d1c97f2
--- /dev/null
+++ b/plugins/views/modelexplorer/org.eclipse.papyrus.modelexplorer/src/org/eclipse/papyrus/modelexplorer/handler/DeleteCommandHandler.java
@@ -0,0 +1,198 @@
+/*****************************************************************************
+ * Copyright (c) 2010 CEA LIST.
+ *
+ *
+ * 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:
+ *
+ * Yann Tanguy (CEA LIST) yann.tanguy@cea.fr - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.modelexplorer.handler;
+
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.eclipse.core.commands.IHandler;
+import org.eclipse.emf.common.command.Command;
+import org.eclipse.emf.common.command.UnexecutableCommand;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.ecore.resource.Resource;
+import org.eclipse.emf.ecore.resource.ResourceSet;
+import org.eclipse.emf.ecore.resource.URIConverter;
+import org.eclipse.emf.edit.domain.AdapterFactoryEditingDomain;
+import org.eclipse.emf.edit.domain.EditingDomain;
+import org.eclipse.gmf.runtime.common.core.command.CompositeCommand;
+import org.eclipse.gmf.runtime.common.core.command.ICommand;
+import org.eclipse.gmf.runtime.emf.type.core.requests.DestroyElementRequest;
+import org.eclipse.papyrus.service.edit.service.ElementEditServiceUtils;
+import org.eclipse.papyrus.service.edit.service.IElementEditService;
+
+/**
+ * Default handler for Delete command used in the ModelExplorer contextual menu.
+ *
+ */
+public class DeleteCommandHandler extends AbstractCommandHandler implements IHandler {
+
+ /** Current deleteCommand for selection (updated in {@link DeleteCommandHandler#isEnabled()}) */
+ private Command deleteCommand;
+
+ /**
+ * <pre>
+ *
+ * Build the delete command for a set of EObject selected in the ModelExplorer.
+ * The delete command is given by the {@link IElementEditService} of selected
+ * elements.
+ *
+ * @return the composite deletion command for current selection
+ *
+ * @TODO : Manage possible Diagrams listed in the selection
+ *
+ * </pre>
+ */
+ private Command buildCommand() {
+
+ ICommand gmfCommand = null;
+
+ // Parameters store the Request parameters of the previous request
+ // if multiple elements are selected for deletion.
+ Map parameters = new HashMap();
+
+ for(EObject selectedEObject : getSelectedElements()) {
+
+ if(selectedEObject == null) {
+ continue;
+ }
+
+ IElementEditService provider = ElementEditServiceUtils.getCommandProvider(selectedEObject);
+ if(provider == null) {
+ continue;
+ }
+
+ // Retrieve delete command from the Element Edit service
+ DestroyElementRequest request = new DestroyElementRequest(selectedEObject, false);
+ // Add parameters (contains the list of previously dependents to be deleted
+ // by previous commands.
+ request.getParameters().putAll(parameters);
+
+ ICommand deleteCommand = provider.getEditCommand(request);
+
+ // Add current EObject destroy command to the global command
+ gmfCommand = CompositeCommand.compose(gmfCommand, deleteCommand);
+
+ // Store the new parameters for next delete command.
+ parameters.clear();
+ parameters.putAll(request.getParameters());
+ }
+
+ if(gmfCommand == null) {
+ return UnexecutableCommand.INSTANCE;
+ }
+
+ Command emfCommand = new org.eclipse.papyrus.commands.wrappers.GMFtoEMFCommandWrapper(gmfCommand.reduce());
+ return emfCommand;
+ }
+
+ /**
+ *
+ * @see org.eclipse.papyrus.modelexplorer.handler.AbstractCommandHandler#getCommand()
+ *
+ * @return current command (only built here when the stored command is null)
+ */
+ protected Command getCommand() {
+ // Don't cache the command, as it is no more refreshed by isEnabled().
+ return buildCommand();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public boolean isEnabled() {
+ //we need to test if selected element is not a meta-class
+
+ List<EObject> selectedElements = getSelectedElements();
+ for(EObject current : selectedElements) {
+ //FIXME use the method isReadOnly provided by the class EMFHelper
+ //TODO after the refactoring (currently, there is circular dependencies)
+ if(isReadOnly(current)) {
+ return false;
+ }
+ //the root of the model can't be deleted!
+ if(current.eContainer() == null) {
+ return false;
+ }
+ }
+
+ if(selectedElements.size()==0){
+ return false;
+ }
+ // Don't compute the delete command to know if it is enabled,
+ // it can be WAY too slow...
+ return true;
+ }
+
+ /**
+ * Tests if an EObject is read only
+ * Delegates to the EObject's editing domain if it can be found
+ *
+ * @param eObject
+ * @return
+ * True if the EObject is read only
+ */
+ public static boolean isReadOnly(EObject eObject) {
+ if(eObject != null) {
+ EditingDomain domain = AdapterFactoryEditingDomain.getEditingDomainFor(eObject);
+ return isReadOnly(eObject, domain);
+ }
+ return false;
+ }
+
+ /**
+ * Tests if an EObject is read only
+ * Delegates to the given editing domain if it isn't null
+ *
+ * @param eObject
+ * @param domain
+ * @return
+ * True if the EObject is read only
+ */
+ public static boolean isReadOnly(EObject eObject, EditingDomain domain) {
+ return isReadOnly(eObject.eResource(), domain);
+ }
+
+ /**
+ * Tests if the Resource is read only
+ * Delegates to the given editing domain if it isn't null
+ *
+ * @param resource
+ * @param domain
+ * @return
+ * True if the Resource is read only
+ */
+ public static boolean isReadOnly(Resource resource, EditingDomain domain) {
+ if(domain instanceof AdapterFactoryEditingDomain) {
+ return ((AdapterFactoryEditingDomain)domain).isReadOnly(resource);
+ }
+
+ if(resource == null) {
+ return false;
+ }
+
+ ResourceSet resourceSet = resource.getResourceSet();
+
+ if(resourceSet == null) {
+ return false;
+ }
+
+ Map<String, ?> attributes = resourceSet.getURIConverter().getAttributes(resource.getURI(), null);
+ Boolean readOnly = (Boolean)attributes.get(URIConverter.ATTRIBUTE_READ_ONLY);
+
+ return readOnly == null ? false : readOnly;
+ }
+}
diff --git a/plugins/views/modelexplorer/org.eclipse.papyrus.modelexplorer/src/org/eclipse/papyrus/modelexplorer/handler/DeleteDiagramHandler.java b/plugins/views/modelexplorer/org.eclipse.papyrus.modelexplorer/src/org/eclipse/papyrus/modelexplorer/handler/DeleteDiagramHandler.java
new file mode 100644
index 00000000000..1fb2a8b5d64
--- /dev/null
+++ b/plugins/views/modelexplorer/org.eclipse.papyrus.modelexplorer/src/org/eclipse/papyrus/modelexplorer/handler/DeleteDiagramHandler.java
@@ -0,0 +1,73 @@
+/*****************************************************************************
+ * Copyright (c) 2011 CEA LIST.
+ *
+ *
+ * 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:
+ * Vincent Lorenzo (CEA LIST) vincent.lorenzo@cea.fr - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.modelexplorer.handler;
+
+import java.util.List;
+
+import org.eclipse.emf.common.command.Command;
+import org.eclipse.emf.common.command.CompoundCommand;
+import org.eclipse.emf.common.command.UnexecutableCommand;
+import org.eclipse.emf.common.util.EList;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.edit.command.RemoveCommand;
+import org.eclipse.emf.transaction.RecordingCommand;
+import org.eclipse.emf.transaction.TransactionalEditingDomain;
+import org.eclipse.gmf.runtime.notation.Diagram;
+import org.eclipse.papyrus.sasheditor.contentprovider.IPageMngr;
+
+/**
+ * Handler for the delete Diagram action
+ *
+ *
+ *
+ */
+public class DeleteDiagramHandler extends AbstractCommandHandler {
+
+
+ /**
+ *
+ * @see org.eclipse.papyrus.modelexplorer.handler.AbstractCommandHandler#getCommand()
+ *
+ * @return
+ */
+ @Override
+ protected Command getCommand() {
+ TransactionalEditingDomain editingDomain = getEditingDomain();
+ final IPageMngr pageMngr = getPageManager();
+
+ List<Diagram> diagrams = getSelectedDiagrams();
+
+ if(editingDomain != null && pageMngr != null && !diagrams.isEmpty()) {
+ CompoundCommand command = new CompoundCommand();
+
+ for(final Diagram diagram : diagrams) {
+ Command sashRemoveComd = new RecordingCommand(editingDomain) {
+
+ @Override
+ protected void doExecute() {
+ if(pageMngr.isOpen(diagram)) {
+ pageMngr.closePage(diagram);
+ }
+ pageMngr.removePage(diagram);
+ }
+ };
+ EList<EObject> diags = diagram.eResource().getContents();
+ command.append(sashRemoveComd);
+ command.append(new RemoveCommand(editingDomain, diags, diagram));
+ }
+ return command.isEmpty() ? UnexecutableCommand.INSTANCE : command;
+ }
+ return UnexecutableCommand.INSTANCE;
+ }
+}
diff --git a/plugins/views/modelexplorer/org.eclipse.papyrus.modelexplorer/src/org/eclipse/papyrus/modelexplorer/handler/DuplicateDiagramHandler.java b/plugins/views/modelexplorer/org.eclipse.papyrus.modelexplorer/src/org/eclipse/papyrus/modelexplorer/handler/DuplicateDiagramHandler.java
new file mode 100644
index 00000000000..e92bbd1a0e6
--- /dev/null
+++ b/plugins/views/modelexplorer/org.eclipse.papyrus.modelexplorer/src/org/eclipse/papyrus/modelexplorer/handler/DuplicateDiagramHandler.java
@@ -0,0 +1,79 @@
+/*****************************************************************************
+ * Copyright (c) 2011 CEA LIST.
+ *
+ *
+ * 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:
+ * Vincent Lorenzo (CEA LIST) vincent.lorenzo@cea.fr - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.modelexplorer.handler;
+
+import java.util.List;
+
+import org.eclipse.emf.common.command.Command;
+import org.eclipse.emf.common.command.CompoundCommand;
+import org.eclipse.emf.common.command.UnexecutableCommand;
+import org.eclipse.emf.ecore.util.EcoreUtil;
+import org.eclipse.emf.edit.command.AddCommand;
+import org.eclipse.emf.transaction.RecordingCommand;
+import org.eclipse.emf.transaction.TransactionalEditingDomain;
+import org.eclipse.gmf.runtime.notation.Diagram;
+import org.eclipse.papyrus.modelexplorer.messages.Messages;
+import org.eclipse.papyrus.sasheditor.contentprovider.IPageMngr;
+
+/**
+ * This handler provides the duplicate action for the diagrams
+ *
+ *
+ *
+ */
+public class DuplicateDiagramHandler extends AbstractCommandHandler {
+
+ /**
+ *
+ * @see org.eclipse.papyrus.modelexplorer.handler.AbstractCommandHandler#getCommand()
+ *
+ * @return
+ */
+ @Override
+ protected Command getCommand() {
+ TransactionalEditingDomain editingDomain = getEditingDomain();
+ final IPageMngr pageManager = getPageManager();
+ List<Diagram> diagrams = getSelectedDiagrams();
+
+ if(editingDomain != null && pageManager != null && !diagrams.isEmpty()) {
+ CompoundCommand command = new CompoundCommand();
+ for(Diagram diagram : diagrams) {
+
+ // Clone the current diagram
+ final Diagram newDiagram = EcoreUtil.copy(diagram);
+ // Give a new name
+ newDiagram.setName(Messages.DuplicateDiagramHandler_copy_of + diagram.getName());
+ Command addGmfDiagramCmd = new AddCommand(editingDomain, diagram.eResource().getContents(), newDiagram);
+ // EMFCommandOperation operation = new
+ // EMFCommandOperation(editingDomain,
+ // addGmfDiagramCmd);
+
+ Command sashOpenComd = new RecordingCommand(editingDomain) {
+
+ @Override
+ protected void doExecute() {
+ pageManager.openPage(newDiagram);
+ }
+ };
+
+ // TODO : synchronize with Cedric
+ // command.append(operation.getCommand());
+ command.append(addGmfDiagramCmd);
+ command.append(sashOpenComd);
+ }
+ return command.isEmpty() ? UnexecutableCommand.INSTANCE : command;
+ }
+ return UnexecutableCommand.INSTANCE;
+ }
+}
diff --git a/plugins/views/modelexplorer/org.eclipse.papyrus.modelexplorer/src/org/eclipse/papyrus/modelexplorer/handler/GMFtoEMFCommandWrapper.java b/plugins/views/modelexplorer/org.eclipse.papyrus.modelexplorer/src/org/eclipse/papyrus/modelexplorer/handler/GMFtoEMFCommandWrapper.java
new file mode 100644
index 00000000000..2a61b90c4f8
--- /dev/null
+++ b/plugins/views/modelexplorer/org.eclipse.papyrus.modelexplorer/src/org/eclipse/papyrus/modelexplorer/handler/GMFtoEMFCommandWrapper.java
@@ -0,0 +1,40 @@
+/***************************************************************************
+ * Copyright (c) 2007 Conselleria de Infraestructuras y Transporte,
+ * Generalitat de la Comunitat Valenciana . 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: Mario Cervera Ubeda (Prodevelop)
+ *
+ *
+ *
+ * <pre>
+ * @TODO : This class is copied as is from oep.diagram.common to avoid adding
+ * an undesired dependency between the model explorer plug-in and oep.diagram.common.
+ * oep.diagram.common should probably be split, moving general utility classes
+ * like this wrapper in a separate plug-in.
+ * </pre>
+ *
+ ******************************************************************************/
+package org.eclipse.papyrus.modelexplorer.handler;
+
+import org.eclipse.gmf.runtime.common.core.command.ICommand;
+
+/**
+ * A EMF Command that wraps a GMF command. Each method is redirected to the GMF one.
+ *
+ * @deprecated use {@link org.eclipse.papyrus.commands.wrappers.GMFtoEMFCommandWrapper} instead
+ */
+public class GMFtoEMFCommandWrapper extends org.eclipse.papyrus.commands.wrappers.GMFtoEMFCommandWrapper {
+
+ /**
+ * Constructor.
+ *
+ * @param gmfCommand
+ * the gmf command
+ */
+ public GMFtoEMFCommandWrapper(ICommand gmfCommand) {
+ super(gmfCommand);
+ }
+}
diff --git a/plugins/views/modelexplorer/org.eclipse.papyrus.modelexplorer/src/org/eclipse/papyrus/modelexplorer/handler/LoadBrowserCustomization.java b/plugins/views/modelexplorer/org.eclipse.papyrus.modelexplorer/src/org/eclipse/papyrus/modelexplorer/handler/LoadBrowserCustomization.java
new file mode 100644
index 00000000000..b36017df690
--- /dev/null
+++ b/plugins/views/modelexplorer/org.eclipse.papyrus.modelexplorer/src/org/eclipse/papyrus/modelexplorer/handler/LoadBrowserCustomization.java
@@ -0,0 +1,316 @@
+/*****************************************************************************
+ * Copyright (c) 2010 CEA LIST.
+ *
+ *
+ * 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:
+ * Patrick Tessier (CEA LIST) Patrick.tessier@cea.fr - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.modelexplorer.handler;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
+import org.eclipse.core.commands.AbstractHandler;
+import org.eclipse.core.commands.ExecutionEvent;
+import org.eclipse.core.commands.ExecutionException;
+import org.eclipse.core.expressions.EvaluationContext;
+import org.eclipse.emf.common.util.EList;
+import org.eclipse.emf.ecore.EClass;
+import org.eclipse.emf.ecore.EClassifier;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.ecore.EPackage;
+import org.eclipse.emf.facet.infra.browser.Messages;
+import org.eclipse.emf.facet.infra.browser.custom.MetamodelView;
+import org.eclipse.emf.facet.infra.browser.custom.TypeView;
+import org.eclipse.emf.facet.infra.browser.custom.ui.dialogs.LoadCustomizationsDialog;
+import org.eclipse.emf.facet.infra.browser.uicore.CustomizationManager;
+import org.eclipse.emf.facet.infra.facet.Facet;
+import org.eclipse.emf.facet.infra.facet.FacetSet;
+import org.eclipse.emf.facet.infra.facet.core.FacetSetCatalog;
+import org.eclipse.jface.viewers.TreeViewer;
+import org.eclipse.jface.window.Window;
+import org.eclipse.osgi.util.NLS;
+import org.eclipse.papyrus.core.services.ServiceException;
+import org.eclipse.papyrus.core.services.ServicesRegistry;
+import org.eclipse.papyrus.core.ui.pagebookview.MultiViewPageBookView;
+import org.eclipse.papyrus.core.utils.DiResourceSet;
+import org.eclipse.papyrus.core.utils.EditorUtils;
+import org.eclipse.papyrus.core.utils.ServiceUtils;
+import org.eclipse.papyrus.core.utils.ServiceUtilsForActionHandlers;
+import org.eclipse.papyrus.modelexplorer.Activator;
+import org.eclipse.papyrus.modelexplorer.CustomCommonViewer;
+import org.eclipse.papyrus.modelexplorer.ModelExplorerPageBookView;
+import org.eclipse.papyrus.modelexplorer.ModelExplorerView;
+import org.eclipse.papyrus.sasheditor.contentprovider.IPageMngr;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.swt.widgets.Tree;
+import org.eclipse.ui.IViewPart;
+import org.eclipse.ui.IWorkbenchPart;
+import org.eclipse.ui.PlatformUI;
+import org.eclipse.ui.navigator.CommonNavigator;
+
+/**
+ * This is a class that launches the button load Customization. this code comes
+ * from the {@link LoadCustomizationsDialog}
+ */
+public class LoadBrowserCustomization extends AbstractHandler {
+
+ /**
+ *
+ *
+ * @return the common navigator
+ */
+ protected CommonNavigator getCommonNavigator() {
+ IViewPart part = org.eclipse.papyrus.modelexplorer.NavigatorUtils.findViewPart(ModelExplorerPageBookView.VIEW_ID);
+ // the part is only a book, retrieving correct page
+ if (part instanceof ModelExplorerPageBookView) {
+ IViewPart page = ((ModelExplorerPageBookView)part).getActiveView();
+ if(page instanceof CommonNavigator) {
+ return ((CommonNavigator)page);
+ }
+ }
+ return null;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public Object execute(ExecutionEvent event) throws ExecutionException {
+
+ if (Activator.getDefault().getCustomizationManager() != null) {
+ CustomizationManager customizationManager = Activator.getDefault()
+ .getCustomizationManager();
+ final List<MetamodelView> registeredCustomizations = customizationManager
+ .getRegisteredCustomizations();
+
+ final LoadCustomizationsDialog loadCustomizationsDialog = new LoadCustomizationsDialog(new Shell(), registeredCustomizations, getMetamodels());
+ if (Window.OK == loadCustomizationsDialog.open() ) {
+ try {
+
+ customizationManager.clearCustomizations();
+ List<MetamodelView> selectedCustomizations = loadCustomizationsDialog
+ .getSelectedCustomizations();
+ //before loading, clean all facet to prevent to let not interesting facets.
+ customizationManager.clearFacets();
+ if (loadCustomizationsDialog.isLoadRequiredFacetsSelected()) {
+ // load facets corresponding to customizations
+
+ loadFacetsForCustomizations(selectedCustomizations,
+ customizationManager);
+ }
+ for (MetamodelView metamodelView : selectedCustomizations) {
+ customizationManager
+ .registerCustomization(metamodelView);
+ }
+ customizationManager.loadCustomizations();
+ if (getCommonNavigator() != null) {
+ Tree tree = getCommonNavigator().getCommonViewer().getTree();
+ customizationManager.installCustomPainter(tree);
+ tree.redraw();
+ }
+ // Activator.getDefault().getCustomizationManager().loadCustomizations(selectedCustomizations);
+
+ } catch (final Exception e) {
+ Activator.log.error(e);
+ }
+ }
+ // load customizations defined as default through the customization
+ // extension
+ if (getCommonNavigator() != null) {
+ getCommonNavigator().getCommonViewer().refresh();
+ }
+ }
+ return null;
+ }
+
+
+ /**
+ *
+ * @return the RessourceSet
+ */
+ private DiResourceSet getDiResourceSet() {
+ return EditorUtils.getDiResourceSet();
+ }
+
+ /**
+ * load the facets
+ *
+ * @param customizations
+ * list of customization
+ * @param customizationManager
+ * the Customization Manager
+ */
+ protected void loadFacetsForCustomizations(
+ final List<MetamodelView> customizations,
+ final CustomizationManager customizationManager) {
+ final Set<Facet> referencedFacets = new HashSet<Facet>();
+ final Collection<FacetSet> facetSets = FacetSetCatalog.getSingleton()
+ .getAllFacetSets();
+
+ for (MetamodelView customization : customizations) {
+ String metamodelURI = customization.getMetamodelURI();
+ // find customized FacetSet
+ FacetSet customizedFacetSet = null;
+ if (metamodelURI != null) {
+ for (FacetSet facetSet : facetSets) {
+ if (metamodelURI.equals(facetSet.getNsURI())) {
+ customizedFacetSet = facetSet;
+ break;
+ }
+ }
+ }
+ if (customizedFacetSet == null) {
+ continue;
+ }
+
+ // find customized Facets
+ EList<TypeView> types = customization.getTypes();
+ for (TypeView typeView : types) {
+ String metaclassName = typeView.getMetaclassName();
+ Facet facet = findFacetWithFullyQualifiedName(metaclassName,
+ customizedFacetSet);
+ if (facet != null) {
+ referencedFacets.add(facet);
+ } else {
+ Activator.log.warn(NLS
+ .bind(
+ Messages.BrowserActionBarContributor_missingRequiredFacet,
+ new Object[] {
+ metaclassName,
+ customizedFacetSet
+ .getName(),
+ customization.getName() }));
+ }
+ }
+
+ for (Facet referencedFacet : referencedFacets) {
+ customizationManager.loadFacet(referencedFacet);
+ }
+ }
+
+ //
+ // for modified facets
+ // customizationManager.getInstancesForMetaclasses().buildDerivationTree();
+ // customizationManager.getAppearanceConfiguration().touch();
+ // customizationManager.refreshDelayed(true);
+ }
+
+ /**
+ * fin a facet from
+ *
+ * @param metaclassName
+ * @param customizedFacetSet
+ * @return
+ */
+ private Facet findFacetWithFullyQualifiedName(final String metaclassName,
+ final FacetSet customizedFacetSet) {
+ EList<Facet> facets = customizedFacetSet.getFacets();
+ for (Facet facet : facets) {
+ String facetName = getMetaclassQualifiedName(facet);
+ if (metaclassName.equals(facetName)) {
+ return facet;
+ }
+ }
+ return null;
+ }
+
+ /** @return the qualified name of the given metaclass */
+ public static String getMetaclassQualifiedName(final EClassifier eClass) {
+ final ArrayList<String> qualifiedNameParts = new ArrayList<String>();
+ final StringBuilder builder = new StringBuilder();
+
+ EPackage ePackage = eClass.getEPackage();
+ while (ePackage != null) {
+ qualifiedNameParts.add(ePackage.getName());
+ ePackage = ePackage.getESuperPackage();
+ }
+
+ for (int i = qualifiedNameParts.size() - 1; i >= 0; i--) {
+ builder.append(qualifiedNameParts.get(i) + "."); //$NON-NLS-1$
+ }
+
+ builder.append(eClass.getName());
+
+ return builder.toString();
+ }
+
+ /**
+ * Get the metmodel URI
+ * **/
+ public String getMetamodelURI() {
+
+ try {
+ EList<EObject> contents = getDiResourceSet().getModelResource()
+ .getContents();
+ if (contents.size() > 0) {
+ EObject eObject = contents.get(0);
+ EClass eClass = eObject.eClass();
+ if (eClass != null) {
+ return eClass.getEPackage().getNsURI();
+ }
+ }
+ } catch (Exception e) {
+ Activator.log.error(e);
+ }
+ return ""; //$NON-NLS-1$
+ }
+
+ /**
+ * Get the metmodel URI
+ * **/
+ public List<EPackage> getMetamodels() {
+ List<EPackage> ePackages = new ArrayList<EPackage>();
+ ServicesRegistry serviceRegistry = null;
+ try {
+ serviceRegistry = ServiceUtilsForActionHandlers.getInstance()
+ .getServiceRegistry();
+ } catch (ServiceException e) {
+ Activator.log.error(e);
+ }
+
+ /*we look for the current editors, because their are represented in the model explorer
+ using specific facet and uiCustom. (see bug 359692) */
+ IPageMngr pageMngr = null;
+ try {
+ pageMngr = ServiceUtils.getInstance().getIPageMngr(serviceRegistry);
+ } catch (ServiceException e) {
+ Activator.log.error(e);
+ }
+ List<Object> pages = pageMngr.allPages();
+ for (int i = 0; i < pages.size(); i++) {
+ if (pages.get(i) instanceof EObject) {
+ EPackage ePackage = ((EObject) pages.get(i)).eClass()
+ .getEPackage();
+ if (!ePackages.contains(ePackage)) {
+ ePackages.add(ePackage);
+ }
+ }
+ }
+
+ try {
+ EList<EObject> contents = getDiResourceSet().getModelResource()
+ .getContents();
+ if (contents.size() > 0) {
+ EObject eObject = contents.get(0);
+ EClass eClass = eObject.eClass();
+ if (eClass != null) {
+ ePackages.add(eClass.getEPackage());
+ }
+ }
+ } catch (Exception e) {
+ Activator.log.error(e);
+ }
+ return ePackages;
+ }
+
+}
diff --git a/plugins/views/modelexplorer/org.eclipse.papyrus.modelexplorer/src/org/eclipse/papyrus/modelexplorer/handler/OpenHandler.java b/plugins/views/modelexplorer/org.eclipse.papyrus.modelexplorer/src/org/eclipse/papyrus/modelexplorer/handler/OpenHandler.java
new file mode 100644
index 00000000000..5fe5d8cf2c8
--- /dev/null
+++ b/plugins/views/modelexplorer/org.eclipse.papyrus.modelexplorer/src/org/eclipse/papyrus/modelexplorer/handler/OpenHandler.java
@@ -0,0 +1,147 @@
+/*****************************************************************************
+ * Copyright (c) 2011 CEA LIST.
+ *
+ *
+ * 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:
+ * Vincent Lorenzo (CEA LIST) vincent.lorenzo@cea.fr - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.modelexplorer.handler;
+
+import java.util.Hashtable;
+import java.util.Iterator;
+
+import org.eclipse.core.commands.ExecutionEvent;
+import org.eclipse.core.commands.ExecutionException;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IConfigurationElement;
+import org.eclipse.core.runtime.IExecutableExtension;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.papyrus.sasheditor.contentprovider.IPageMngr;
+import org.eclipse.ui.PlatformUI;
+import org.eclipse.ui.handlers.HandlerUtil;
+
+/**
+ * This handler allows to Open Diagrams and Tables
+ *
+ *
+ *
+ */
+public class OpenHandler extends AbstractModelExplorerHandler implements IExecutableExtension {
+
+
+
+
+ /** parameters for this action */
+ /**
+ * close all open elements
+ */
+ public static final String PARAMETER_CLOSE = "close"; //$NON-NLS-1$
+
+ /**
+ * Close only the selected elements
+ */
+ public static final String PARAMETER_ALREADY_OPEN = "already_open"; //$NON-NLS-1$
+
+
+ /** parameter ID */
+ protected String parameterID = "open_parameter"; //$NON-NLS-1$
+
+ /** parameter for this handler */
+ protected String parameter = null;
+
+
+ /**
+ *
+ * @see org.eclipse.core.commands.AbstractHandler#execute(org.eclipse.core.commands.ExecutionEvent)
+ *
+ * @param event
+ * @return
+ * @throws ExecutionException
+ */
+ public Object execute(ExecutionEvent event) throws ExecutionException {
+ ISelection selection = HandlerUtil.getCurrentSelection(event);
+ IPageMngr pageMngr = getPageManager();
+
+ if(selection instanceof IStructuredSelection && pageMngr != null) {
+ Iterator<?> iter = ((IStructuredSelection)selection).iterator();
+ while(iter.hasNext()) {
+ pageMngr.openPage(iter.next());
+ }
+ }
+ return null;
+ }
+
+ /**
+ *
+ * @see org.eclipse.core.commands.AbstractHandler#isEnabled()
+ *
+ * @return
+ */
+ @Override
+ public boolean isEnabled() {
+ IPageMngr pageMngr = getPageManager();
+ if(pageMngr != null) {
+ IStructuredSelection selection = getSelectedElement();
+ Iterator<?> iter = selection.iterator();
+ if(selection != null) {
+ if(PARAMETER_CLOSE.equals(this.parameter)) {
+ while(iter.hasNext()) {
+ if(pageMngr.isOpen(iter.next())) {
+ return false;
+ }
+ }
+ return true;
+ } else if(PARAMETER_ALREADY_OPEN.equals(this.parameter)) {
+ while(iter.hasNext()) {
+ if(pageMngr.isOpen(iter.next())) {
+ return true;
+ }
+ }
+ return false;
+ }
+ }
+ }
+ return false;
+ }
+
+ /**
+ *
+ * @see org.eclipse.core.runtime.IExecutableExtension#setInitializationData(org.eclipse.core.runtime.IConfigurationElement, java.lang.String,
+ * java.lang.Object)
+ *
+ * @param config
+ * @param propertyName
+ * @param data
+ * @throws CoreException
+ */
+ public void setInitializationData(IConfigurationElement config, String propertyName, Object data) throws CoreException {
+ if(data instanceof Hashtable && this.parameterID != null) {
+ this.parameter = (String)((Hashtable)data).get(this.parameterID);
+ }
+ }
+
+ /**
+ * Returns the selected elements
+ *
+ * @return
+ * the selected elements
+ */
+ protected IStructuredSelection getSelectedElement() {
+ ISelection selection = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getSelectionService().getSelection();
+ if(selection instanceof IStructuredSelection) {
+ return (IStructuredSelection)selection;
+ }
+ return null;
+ }
+
+
+
+
+}
diff --git a/plugins/views/modelexplorer/org.eclipse.papyrus.modelexplorer/src/org/eclipse/papyrus/modelexplorer/handler/PasteHandler.java b/plugins/views/modelexplorer/org.eclipse.papyrus.modelexplorer/src/org/eclipse/papyrus/modelexplorer/handler/PasteHandler.java
new file mode 100644
index 00000000000..2eff7be4b15
--- /dev/null
+++ b/plugins/views/modelexplorer/org.eclipse.papyrus.modelexplorer/src/org/eclipse/papyrus/modelexplorer/handler/PasteHandler.java
@@ -0,0 +1,46 @@
+/*****************************************************************************
+ * Copyright (c) 2011 CEA LIST.
+ *
+ *
+ * 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:
+ * Vincent Lorenzo (CEA LIST) vincent.lorenzo@cea.fr - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.modelexplorer.handler;
+
+import java.util.List;
+
+import org.eclipse.emf.common.command.Command;
+import org.eclipse.emf.common.command.UnexecutableCommand;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.edit.command.PasteFromClipboardCommand;
+
+/**
+ * Handler for the Paste Action
+ *
+ *
+ *
+ */
+public class PasteHandler extends AbstractCommandHandler {
+
+ /**
+ *
+ * @see org.eclipse.papyrus.modelexplorer.handler.AbstractCommandHandler#getCommand()
+ *
+ * @return
+ */
+ @Override
+ protected Command getCommand() {
+ List<EObject> selection = getSelectedElements();
+ if(selection.size() == 1) {
+ return PasteFromClipboardCommand.create(getEditingDomain(), selection.get(0), null);
+ }
+ return UnexecutableCommand.INSTANCE;
+ }
+
+}
diff --git a/plugins/views/modelexplorer/org.eclipse.papyrus.modelexplorer/src/org/eclipse/papyrus/modelexplorer/handler/RedoHandler.java b/plugins/views/modelexplorer/org.eclipse.papyrus.modelexplorer/src/org/eclipse/papyrus/modelexplorer/handler/RedoHandler.java
new file mode 100644
index 00000000000..d2d9ac56e5d
--- /dev/null
+++ b/plugins/views/modelexplorer/org.eclipse.papyrus.modelexplorer/src/org/eclipse/papyrus/modelexplorer/handler/RedoHandler.java
@@ -0,0 +1,51 @@
+/*****************************************************************************
+ * Copyright (c) 2011 CEA LIST.
+ *
+ *
+ * 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:
+ * Vincent Lorenzo (CEA LIST) vincent.lorenzo@cea.fr - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.modelexplorer.handler;
+
+import org.eclipse.core.commands.ExecutionEvent;
+import org.eclipse.core.commands.ExecutionException;
+
+/**
+ * Handler for the Redo Action
+ *
+ *
+ *
+ */
+public class RedoHandler extends AbstractModelExplorerHandler {
+
+
+ /**
+ *
+ * @see org.eclipse.core.commands.AbstractHandler#execute(org.eclipse.core.commands.ExecutionEvent)
+ *
+ * @param event
+ * @return
+ * @throws ExecutionException
+ */
+ public Object execute(ExecutionEvent event) throws ExecutionException {
+ getEditingDomain().getCommandStack().redo();
+ return null;
+ }
+
+ /**
+ *
+ * @see org.eclipse.core.commands.AbstractHandler#isEnabled()
+ *
+ * @return
+ */
+ @Override
+ public boolean isEnabled() {
+ return getEditingDomain().getCommandStack().canRedo();
+ }
+}
diff --git a/plugins/views/modelexplorer/org.eclipse.papyrus.modelexplorer/src/org/eclipse/papyrus/modelexplorer/handler/RenameDiagramHandler.java b/plugins/views/modelexplorer/org.eclipse.papyrus.modelexplorer/src/org/eclipse/papyrus/modelexplorer/handler/RenameDiagramHandler.java
new file mode 100644
index 00000000000..ed3a0024ad0
--- /dev/null
+++ b/plugins/views/modelexplorer/org.eclipse.papyrus.modelexplorer/src/org/eclipse/papyrus/modelexplorer/handler/RenameDiagramHandler.java
@@ -0,0 +1,78 @@
+/*****************************************************************************
+ * Copyright (c) 2011 CEA LIST.
+ *
+ *
+ * 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:
+ * Vincent Lorenzo (CEA LIST) vincent.lorenzo@cea.fr - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.modelexplorer.handler;
+
+import java.util.List;
+
+import org.eclipse.core.commands.ExecutionException;
+import org.eclipse.core.runtime.IAdaptable;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.emf.common.command.Command;
+import org.eclipse.emf.common.command.UnexecutableCommand;
+import org.eclipse.emf.transaction.TransactionalEditingDomain;
+import org.eclipse.gmf.runtime.common.core.command.CommandResult;
+import org.eclipse.gmf.runtime.emf.commands.core.command.AbstractTransactionalCommand;
+import org.eclipse.gmf.runtime.notation.Diagram;
+import org.eclipse.jface.dialogs.InputDialog;
+import org.eclipse.jface.window.Window;
+import org.eclipse.papyrus.modelexplorer.messages.Messages;
+import org.eclipse.swt.widgets.Display;
+
+/**
+ * This handler provides the method to rename a Diagram
+ *
+ *
+ *
+ */
+public class RenameDiagramHandler extends AbstractCommandHandler {
+
+
+ /**
+ *
+ * @see org.eclipse.papyrus.modelexplorer.handler.AbstractCommandHandler#getCommand()
+ *
+ * @return
+ */
+ @Override
+ protected Command getCommand() {
+ TransactionalEditingDomain editingDomain = getEditingDomain();
+ List<Diagram> diagrams = getSelectedDiagrams();
+ if(editingDomain != null && diagrams.size() == 1) {
+
+ final Diagram diag = diagrams.get(0);
+ final String currentName = diag.getName();
+ if(currentName != null) {
+
+ AbstractTransactionalCommand cmd = new AbstractTransactionalCommand(editingDomain, "RenameDiagramCommand", null) { //$NON-NLS-1$
+
+ @Override
+ protected CommandResult doExecuteWithResult(IProgressMonitor monitor, IAdaptable info) throws ExecutionException {
+ InputDialog dialog = new InputDialog(Display.getCurrent().getActiveShell(), Messages.RenameDiagramHandler_rename_an_existing_diagram, Messages.RenameDiagramHandler_new_name, currentName, null);
+ if(dialog.open() == Window.OK) {
+ final String name = dialog.getValue();
+ if(name != null && name.length() > 0) {
+ diag.setName(name);
+ }
+ return CommandResult.newOKCommandResult();
+ } else {
+ return CommandResult.newCancelledCommandResult();
+ }
+ }
+ };
+ return new org.eclipse.papyrus.commands.wrappers.GMFtoEMFCommandWrapper(cmd);
+ }
+ }
+ return UnexecutableCommand.INSTANCE;
+ }
+}
diff --git a/plugins/views/modelexplorer/org.eclipse.papyrus.modelexplorer/src/org/eclipse/papyrus/modelexplorer/handler/SearchElementHandler.java b/plugins/views/modelexplorer/org.eclipse.papyrus.modelexplorer/src/org/eclipse/papyrus/modelexplorer/handler/SearchElementHandler.java
new file mode 100644
index 00000000000..5d4222f81da
--- /dev/null
+++ b/plugins/views/modelexplorer/org.eclipse.papyrus.modelexplorer/src/org/eclipse/papyrus/modelexplorer/handler/SearchElementHandler.java
@@ -0,0 +1,84 @@
+/*****************************************************************************
+ * Copyright (c) 2010 CEA LIST.
+ *
+ *
+ * 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:
+ * Patrick Tessier (CEA LIST) Patrick.tessier@cea.fr - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.modelexplorer.handler;
+
+import org.eclipse.core.commands.AbstractHandler;
+import org.eclipse.core.commands.ExecutionEvent;
+import org.eclipse.core.commands.ExecutionException;
+import org.eclipse.core.expressions.EvaluationContext;
+import org.eclipse.jface.viewers.TreeViewer;
+import org.eclipse.papyrus.core.ui.pagebookview.MultiViewPageBookView;
+import org.eclipse.papyrus.modelexplorer.ModelExplorerView;
+import org.eclipse.papyrus.modelexplorer.dialog.NavigatorSearchDialog;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.ui.IViewPart;
+import org.eclipse.ui.IWorkbenchPart;
+import org.eclipse.ui.PlatformUI;
+import org.eclipse.ui.handlers.HandlerUtil;
+import org.eclipse.ui.navigator.CommonNavigator;
+
+/**
+ * this handler is used to look for element
+ *
+ */
+public class SearchElementHandler extends AbstractHandler {
+
+ public Object execute(ExecutionEvent event) throws ExecutionException {
+ Shell shell = HandlerUtil.getActiveShell(event);
+ if(shell == null) {
+ return null;
+ }
+ NavigatorSearchDialog dialog = new NavigatorSearchDialog(shell, getSelectedTreeViewer(event));
+ dialog.open();
+ return null;
+ }
+
+ protected TreeViewer getSelectedTreeViewer(ExecutionEvent event) {
+
+ IWorkbenchPart activePart;
+ // Try to get the active part
+
+ // Try to get the TreeViewer from the evaluation context
+ if(event.getApplicationContext() instanceof EvaluationContext) {
+ EvaluationContext context = (EvaluationContext)event.getApplicationContext();
+ // activeEditor, activeSite, selection, activeShell, activePart
+ Object site = context.getVariable("activeSite");
+ activePart = (IWorkbenchPart)context.getVariable("activePart");
+ } else {
+ activePart = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActivePart();
+ }
+
+ if(activePart instanceof TreeViewer)
+ return (TreeViewer)activePart;
+
+ if(activePart instanceof MultiViewPageBookView) {
+ MultiViewPageBookView pageBookView = (MultiViewPageBookView)activePart;
+ IViewPart viewPart = pageBookView.getActiveView();
+ if(viewPart instanceof ModelExplorerView) {
+ return ((ModelExplorerView)viewPart).getCommonViewer();
+ }
+ }
+
+ // Not found
+ return null;
+ }
+
+ protected CommonNavigator getCommonNavigator() {
+ IViewPart part = org.eclipse.papyrus.modelexplorer.NavigatorUtils.findViewPart("org.eclipse.papyrus.modelexplorer.modelexplorer");
+ if(part instanceof CommonNavigator) {
+ return ((CommonNavigator)part);
+ }
+ return null;
+ }
+}
diff --git a/plugins/views/modelexplorer/org.eclipse.papyrus.modelexplorer/src/org/eclipse/papyrus/modelexplorer/handler/SortElementHandler.java b/plugins/views/modelexplorer/org.eclipse.papyrus.modelexplorer/src/org/eclipse/papyrus/modelexplorer/handler/SortElementHandler.java
new file mode 100644
index 00000000000..32e999b3487
--- /dev/null
+++ b/plugins/views/modelexplorer/org.eclipse.papyrus.modelexplorer/src/org/eclipse/papyrus/modelexplorer/handler/SortElementHandler.java
@@ -0,0 +1,101 @@
+/*****************************************************************************
+ * Copyright (c) 2010 CEA LIST.
+ *
+ *
+ * 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:
+ * Patrick Tessier (CEA LIST) Patrick.tessier@cea.fr - Initial API and implementation
+ *
+ *****************************************************************************/
+
+package org.eclipse.papyrus.modelexplorer.handler;
+
+import org.eclipse.core.commands.AbstractHandler;
+import org.eclipse.core.commands.ExecutionEvent;
+import org.eclipse.core.commands.ExecutionException;
+import org.eclipse.core.expressions.EvaluationContext;
+import org.eclipse.emf.facet.infra.browser.uicore.CustomizationManager;
+import org.eclipse.jface.viewers.TreeViewer;
+import org.eclipse.papyrus.core.ui.pagebookview.MultiViewPageBookView;
+import org.eclipse.papyrus.modelexplorer.Activator;
+import org.eclipse.papyrus.modelexplorer.CustomCommonViewer;
+import org.eclipse.papyrus.modelexplorer.ModelExplorerView;
+import org.eclipse.swt.widgets.Event;
+import org.eclipse.swt.widgets.ToolItem;
+import org.eclipse.ui.IViewPart;
+import org.eclipse.ui.IWorkbenchPart;
+import org.eclipse.ui.PlatformUI;
+import org.eclipse.ui.navigator.CommonViewerSorter;
+/**
+ * this handler is used to set a sorter on the model explorer
+ *
+ */
+public class SortElementHandler extends AbstractHandler {
+
+ /**
+ * {@inheritDoc}
+ */
+ public Object execute(ExecutionEvent event) throws ExecutionException {
+ if (Activator.getDefault().getCustomizationManager() != null) {
+ CustomizationManager customizationManager = Activator.getDefault()
+ .getCustomizationManager();
+ if(((ToolItem)((Event)event.getTrigger()).widget).getSelection()){
+ getSelectedTreeViewer(event).setSorter(new CommonViewerSorter());
+ if(getSelectedTreeViewer(event) instanceof CustomCommonViewer){
+ ((CustomCommonViewer)getSelectedTreeViewer(event)).getDropAdapter().setFeedbackEnabled(false);
+ }
+ }
+ else{
+ getSelectedTreeViewer(event).setSorter(null);
+ if(getSelectedTreeViewer(event) instanceof CustomCommonViewer){
+ ((CustomCommonViewer)getSelectedTreeViewer(event)).getDropAdapter().setFeedbackEnabled(true);
+ }
+
+ }
+ getSelectedTreeViewer(event).refresh();
+ }
+ return null;
+ }
+
+ /**
+ * used to obtain the tree viewer of the model explorer
+ * @param event
+ * @return
+ */
+ protected TreeViewer getSelectedTreeViewer(ExecutionEvent event) {
+
+ IWorkbenchPart activePart;
+ // Try to get the active part
+
+ // Try to get the TreeViewer from the evaluation context
+ if( event.getApplicationContext() instanceof EvaluationContext) {
+ EvaluationContext context = (EvaluationContext)event.getApplicationContext();
+ // activeEditor, activeSite, selection, activeShell, activePart
+ Object site = context.getVariable("activeSite");
+ activePart = (IWorkbenchPart)context.getVariable("activePart");
+ }
+ else {
+ activePart = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActivePart();
+ }
+
+ if(activePart instanceof TreeViewer)
+ return (TreeViewer)activePart;
+
+ if( activePart instanceof MultiViewPageBookView)
+ {
+ MultiViewPageBookView pageBookView =(MultiViewPageBookView)activePart;
+ IViewPart viewPart = pageBookView.getActiveView();
+ if(viewPart instanceof ModelExplorerView)
+ {
+ return ((ModelExplorerView)viewPart).getCommonViewer();
+ }
+ }
+
+ // Not found
+ return null;
+ }
+}
diff --git a/plugins/views/modelexplorer/org.eclipse.papyrus.modelexplorer/src/org/eclipse/papyrus/modelexplorer/handler/UndoHandler.java b/plugins/views/modelexplorer/org.eclipse.papyrus.modelexplorer/src/org/eclipse/papyrus/modelexplorer/handler/UndoHandler.java
new file mode 100644
index 00000000000..295a917cd71
--- /dev/null
+++ b/plugins/views/modelexplorer/org.eclipse.papyrus.modelexplorer/src/org/eclipse/papyrus/modelexplorer/handler/UndoHandler.java
@@ -0,0 +1,53 @@
+/*****************************************************************************
+ * Copyright (c) 2011 CEA LIST.
+ *
+ *
+ * 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:
+ * Vincent Lorenzo (CEA LIST) vincent.lorenzo@cea.fr - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.modelexplorer.handler;
+
+import org.eclipse.core.commands.ExecutionEvent;
+import org.eclipse.core.commands.ExecutionException;
+
+/**
+ * Handler for the Undo Action
+ *
+ *
+ *
+ */
+public class UndoHandler extends AbstractModelExplorerHandler {
+
+ /**
+ *
+ * @see org.eclipse.core.commands.AbstractHandler#execute(org.eclipse.core.commands.ExecutionEvent)
+ *
+ * @param event
+ * @return
+ * @throws ExecutionException
+ */
+ public Object execute(ExecutionEvent event) throws ExecutionException {
+ getEditingDomain().getCommandStack().undo();
+ return null;
+ }
+
+ /**
+ *
+ * @see org.eclipse.core.commands.AbstractHandler#isEnabled()
+ *
+ * @return
+ */
+ @Override
+ public boolean isEnabled() {
+ return getEditingDomain().getCommandStack().canUndo();
+ }
+
+
+
+}
diff --git a/plugins/views/modelexplorer/org.eclipse.papyrus.modelexplorer/src/org/eclipse/papyrus/modelexplorer/listener/DoubleClickListener.java b/plugins/views/modelexplorer/org.eclipse.papyrus.modelexplorer/src/org/eclipse/papyrus/modelexplorer/listener/DoubleClickListener.java
new file mode 100644
index 00000000000..e47f90e9951
--- /dev/null
+++ b/plugins/views/modelexplorer/org.eclipse.papyrus.modelexplorer/src/org/eclipse/papyrus/modelexplorer/listener/DoubleClickListener.java
@@ -0,0 +1,70 @@
+/*****************************************************************************
+ * Copyright (c) 2010 CEA LIST.
+ *
+ *
+ * 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:
+ * Patrick Tessier (CEA LIST) Patrick.tessier@cea.fr - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.modelexplorer.listener;
+
+import java.util.Iterator;
+
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.jface.viewers.DoubleClickEvent;
+import org.eclipse.jface.viewers.IDoubleClickListener;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.papyrus.core.utils.ServiceUtilsForActionHandlers;
+import org.eclipse.papyrus.modelexplorer.Activator;
+import org.eclipse.papyrus.modelexplorer.Messages;
+import org.eclipse.papyrus.modelexplorer.NavigatorUtils;
+import org.eclipse.papyrus.sasheditor.contentprovider.IPageMngr;
+
+/**
+ * this class is a listener in charge to manage double on element of the model explorer
+ *
+ */
+public class DoubleClickListener implements IDoubleClickListener {
+
+ /**
+ *
+ * @see org.eclipse.jface.viewers.IDoubleClickListener#doubleClick(org.eclipse.jface.viewers.DoubleClickEvent)
+ *
+ */
+ public void doubleClick(DoubleClickEvent event) {
+ ISelection selection = event.getSelection();
+ IPageMngr pageMngr = null;
+ //get the page Manager
+ try {
+ pageMngr = ServiceUtilsForActionHandlers.getInstance().getIPageMngr();
+ } catch (Exception e) {
+ Activator.log.error(Messages.DoubleClickListener_Error_NoLoadManagerToOpen, e);
+ }
+ if(pageMngr != null) {
+ if(selection instanceof IStructuredSelection) {
+ Iterator<?> iter = ((IStructuredSelection)selection).iterator();
+ while(iter.hasNext()) {
+ Object currentObject = iter.next();
+ EObject diag = NavigatorUtils.getElement(currentObject, EObject.class);
+ if(pageMngr.allPages().contains(diag)) {
+ /**
+ * Close the diagram if it was already open
+ */
+ if(pageMngr.isOpen(diag)) {
+ pageMngr.closePage(diag);
+ }
+ pageMngr.openPage(diag);
+ }
+ }
+ }
+
+ }
+ }
+
+}
diff --git a/plugins/views/modelexplorer/org.eclipse.papyrus.modelexplorer/src/org/eclipse/papyrus/modelexplorer/messages.properties b/plugins/views/modelexplorer/org.eclipse.papyrus.modelexplorer/src/org/eclipse/papyrus/modelexplorer/messages.properties
new file mode 100644
index 00000000000..809af86755d
--- /dev/null
+++ b/plugins/views/modelexplorer/org.eclipse.papyrus.modelexplorer/src/org/eclipse/papyrus/modelexplorer/messages.properties
@@ -0,0 +1,15 @@
+##########################################################################################
+# Copyright (c) 2011 CEA LIST.
+#
+#
+# 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:
+# Remi Schnekenburger (CEA LIST) remi.schnekenburger@cea.fr - Initial API and implementation
+#
+########################################################################################
+MoDiscoLabelProvider_ProxyLabel=Unreachable {0} in {1}
+DoubleClickListener_Error_NoLoadManagerToOpen=Impossibility to load the page manager
diff --git a/plugins/views/modelexplorer/org.eclipse.papyrus.modelexplorer/src/org/eclipse/papyrus/modelexplorer/messages/Messages.java b/plugins/views/modelexplorer/org.eclipse.papyrus.modelexplorer/src/org/eclipse/papyrus/modelexplorer/messages/Messages.java
new file mode 100644
index 00000000000..d72da2264dc
--- /dev/null
+++ b/plugins/views/modelexplorer/org.eclipse.papyrus.modelexplorer/src/org/eclipse/papyrus/modelexplorer/messages/Messages.java
@@ -0,0 +1,34 @@
+/*****************************************************************************
+ * Copyright (c) 2011 CEA LIST.
+ *
+ *
+ * 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:
+ * Vincent Lorenzo (CEA LIST) vincent.lorenzo@cea.fr - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.modelexplorer.messages;
+
+import org.eclipse.osgi.util.NLS;
+
+public class Messages extends NLS {
+
+ private static final String BUNDLE_NAME = "org.eclipse.papyrus.modelexplorer.messages.messages"; //$NON-NLS-1$
+
+ public static String DuplicateDiagramHandler_copy_of;
+
+ public static String RenameDiagramHandler_new_name;
+
+ public static String RenameDiagramHandler_rename_an_existing_diagram;
+ static {
+ // initialize resource bundle
+ NLS.initializeMessages(BUNDLE_NAME, Messages.class);
+ }
+
+ private Messages() {
+ }
+}
diff --git a/plugins/views/modelexplorer/org.eclipse.papyrus.modelexplorer/src/org/eclipse/papyrus/modelexplorer/messages/messages.properties b/plugins/views/modelexplorer/org.eclipse.papyrus.modelexplorer/src/org/eclipse/papyrus/modelexplorer/messages/messages.properties
new file mode 100644
index 00000000000..59481552d33
--- /dev/null
+++ b/plugins/views/modelexplorer/org.eclipse.papyrus.modelexplorer/src/org/eclipse/papyrus/modelexplorer/messages/messages.properties
@@ -0,0 +1,3 @@
+DuplicateDiagramHandler_copy_of=Copy of
+RenameDiagramHandler_new_name=New name:
+RenameDiagramHandler_rename_an_existing_diagram=Rename an existing diagram
diff --git a/plugins/views/modelexplorer/org.eclipse.papyrus.modelexplorer/src/org/eclipse/papyrus/modelexplorer/preferences/INavigatorPreferenceConstants.java b/plugins/views/modelexplorer/org.eclipse.papyrus.modelexplorer/src/org/eclipse/papyrus/modelexplorer/preferences/INavigatorPreferenceConstants.java
new file mode 100644
index 00000000000..40e2a4e3cbd
--- /dev/null
+++ b/plugins/views/modelexplorer/org.eclipse.papyrus.modelexplorer/src/org/eclipse/papyrus/modelexplorer/preferences/INavigatorPreferenceConstants.java
@@ -0,0 +1,28 @@
+/*****************************************************************************
+ * Copyright (c) 2010 Atos Origin.
+ *
+ *
+ * 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:
+ * Emilien Perico (Atos Origin) emilien.perico@atosorigin.com - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.modelexplorer.preferences;
+
+/**
+ * Defines specific preference constants for papyrus navigator.
+ *
+ * @noimplement This interface is not intended to be implemented by clients.
+ */
+public interface INavigatorPreferenceConstants {
+
+ /**
+ * the preference for displaying the warning popup when element will be
+ * transform into another one
+ */
+ public static final String PREF_NAVIGATOR_TRANSFORM_INTO_SHOW_POPUP = "org.eclipse.papyrus.navigator.TransformInto.showPopupDialog"; //$NON-NLS-1$
+}
diff --git a/plugins/views/modelexplorer/org.eclipse.papyrus.modelexplorer/src/org/eclipse/papyrus/modelexplorer/preferences/NavigatorPreferenceInitializer.java b/plugins/views/modelexplorer/org.eclipse.papyrus.modelexplorer/src/org/eclipse/papyrus/modelexplorer/preferences/NavigatorPreferenceInitializer.java
new file mode 100644
index 00000000000..cabfc12e615
--- /dev/null
+++ b/plugins/views/modelexplorer/org.eclipse.papyrus.modelexplorer/src/org/eclipse/papyrus/modelexplorer/preferences/NavigatorPreferenceInitializer.java
@@ -0,0 +1,46 @@
+/*****************************************************************************
+ * Copyright (c) 2010 Atos Origin.
+ *
+ *
+ * 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:
+ * Emilien Perico (Atos Origin) emilien.perico@atosorigin.com - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.modelexplorer.preferences;
+
+import org.eclipse.core.runtime.preferences.AbstractPreferenceInitializer;
+import org.eclipse.jface.preference.IPreferenceStore;
+import org.eclipse.papyrus.modelexplorer.Activator;
+
+/**
+ * This preference initializer initializes diagram preferences specific to the
+ * activity diagram.
+ */
+public class NavigatorPreferenceInitializer extends
+ AbstractPreferenceInitializer {
+
+ /**
+ * Initialize default preferences specific to the activity diagram
+ */
+ public void initializeDefaultPreferences() {
+ IPreferenceStore store = getPreferenceStore();
+
+ // preference for showing popup dialog when transform element command is
+ // performed
+ store.setDefault(
+ INavigatorPreferenceConstants.PREF_NAVIGATOR_TRANSFORM_INTO_SHOW_POPUP,
+ false);
+ }
+
+ /**
+ * Get the preference store
+ */
+ protected IPreferenceStore getPreferenceStore() {
+ return Activator.getDefault().getPreferenceStore();
+ }
+}
diff --git a/plugins/views/modelexplorer/org.eclipse.papyrus.modelexplorer/src/org/eclipse/papyrus/modelexplorer/preferences/NavigatorPreferencePage.java b/plugins/views/modelexplorer/org.eclipse.papyrus.modelexplorer/src/org/eclipse/papyrus/modelexplorer/preferences/NavigatorPreferencePage.java
new file mode 100644
index 00000000000..175e4f85025
--- /dev/null
+++ b/plugins/views/modelexplorer/org.eclipse.papyrus.modelexplorer/src/org/eclipse/papyrus/modelexplorer/preferences/NavigatorPreferencePage.java
@@ -0,0 +1,68 @@
+/*****************************************************************************
+ * Copyright (c) 2010 Atos Origin.
+ *
+ *
+ * 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:
+ * Emilien Perico (Atos Origin) emilien.perico@atosorigin.com - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.modelexplorer.preferences;
+
+import org.eclipse.jface.preference.IPreferenceStore;
+import org.eclipse.papyrus.modelexplorer.Activator;
+import org.eclipse.papyrus.preferences.pages.AbstractPapyrusNodePreferencePage;
+import org.eclipse.swt.widgets.Composite;
+
+public class NavigatorPreferencePage extends AbstractPapyrusNodePreferencePage {
+
+ /**
+ * @generated
+ */
+ @Override
+ protected String getBundleId() {
+ return Activator.PLUGIN_ID;
+ }
+
+ /**
+ * @generated
+ */
+ public static void initDefaults(IPreferenceStore store) {
+
+ // String elementName = "Model Explorer";
+ // PreferenceConverter.setDefault(store,
+ // PreferenceConstantHelper.getElementConstant(elementName,
+ // PreferenceConstantHelper.COLOR_FILL), new
+ // org.eclipse.swt.graphics.RGB(255, 255, 255));
+ // PreferenceConverter.setDefault(store,
+ // PreferenceConstantHelper.getElementConstant(elementName,
+ // PreferenceConstantHelper.COLOR_LINE), new
+ // org.eclipse.swt.graphics.RGB(0, 0, 0));
+ //
+ // // Set the default for the gradient
+ // store.setDefault(PreferenceConstantHelper.getElementConstant(elementName,
+ // PreferenceConstantHelper.GRADIENT_POLICY), false);
+ // GradientPreferenceConverter gradientPreferenceConverter = new
+ // GradientPreferenceConverter(new org.eclipse.swt.graphics.RGB(255,
+ // 255, 255), new org.eclipse.swt.graphics.RGB(0, 0, 0), 0, 0);
+ // store.setDefault(PreferenceConstantHelper.getElementConstant(elementName,
+ // PreferenceConstantHelper.COLOR_GRADIENT),
+ // gradientPreferenceConverter.getPreferenceValue());
+
+ }
+
+ @Override
+ protected void createPageContents(Composite parent) {
+ // super.createPageContents(parent);
+
+ // show popup dialog
+ TransformCommandShowPopupDialogGroup groupComposite = new TransformCommandShowPopupDialogGroup(
+ parent, getTitle(), this);
+ addAbstractGroup(groupComposite);
+ }
+
+}
diff --git a/plugins/views/modelexplorer/org.eclipse.papyrus.modelexplorer/src/org/eclipse/papyrus/modelexplorer/preferences/TransformCommandShowPopupDialogGroup.java b/plugins/views/modelexplorer/org.eclipse.papyrus.modelexplorer/src/org/eclipse/papyrus/modelexplorer/preferences/TransformCommandShowPopupDialogGroup.java
new file mode 100644
index 00000000000..c6af2d8637d
--- /dev/null
+++ b/plugins/views/modelexplorer/org.eclipse.papyrus.modelexplorer/src/org/eclipse/papyrus/modelexplorer/preferences/TransformCommandShowPopupDialogGroup.java
@@ -0,0 +1,69 @@
+/*****************************************************************************
+ * Copyright (c) 2010 Atos Origin.
+ *
+ *
+ * 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:
+ * Emilien Perico (Atos Origin) emilien.perico@atosorigin.com - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.modelexplorer.preferences;
+
+import org.eclipse.jface.dialogs.DialogPage;
+import org.eclipse.jface.preference.BooleanFieldEditor;
+import org.eclipse.papyrus.preferences.ui.AbstractGroup;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Group;
+
+public class TransformCommandShowPopupDialogGroup extends AbstractGroup {
+
+ private static final String SHOW_POPUP_DIALOG_GROUP_TITLE = "Transform into Action";
+
+ private static final String SHOW_POPUP_DIALOG_GROUP_MESSAGE = "Do not show popup dialog when transform command is performed";
+
+ /** Editor for deciding to show the warning popup */
+ private BooleanFieldEditor showPopupDialogBooleanFieldEditor;
+
+ /**
+ * Creation of an ActivityEdgeLabelVisibilityGroup Composite.
+ *
+ * @param parent
+ * the parent of the composite
+ * @param dialogPage
+ * to set the page in field editor
+ * @param title
+ * the title
+ */
+ public TransformCommandShowPopupDialogGroup(Composite parent, String title,
+ DialogPage dialogPage) {
+ super(parent, title, dialogPage);
+ createContent(parent);
+ }
+
+ /**
+ * Creates the content.
+ *
+ * @param parent
+ * the parent
+ */
+ public void createContent(Composite parent) {
+ Group visibilityGroup = new Group(parent, SWT.SCROLL_PAGE);
+ visibilityGroup.setLayout(new GridLayout());
+ visibilityGroup.setText(SHOW_POPUP_DIALOG_GROUP_TITLE);
+
+ // field for name label visibility
+ showPopupDialogBooleanFieldEditor = new BooleanFieldEditor(
+ INavigatorPreferenceConstants.PREF_NAVIGATOR_TRANSFORM_INTO_SHOW_POPUP,
+ SHOW_POPUP_DIALOG_GROUP_MESSAGE, visibilityGroup);
+ showPopupDialogBooleanFieldEditor.setPage(dialogPage);
+
+ addFieldEditor(showPopupDialogBooleanFieldEditor);
+
+ }
+}
diff --git a/plugins/views/modelexplorer/org.eclipse.papyrus.modelexplorer/src/org/eclipse/papyrus/modelexplorer/provider/ActionStateSourceProvider.java b/plugins/views/modelexplorer/org.eclipse.papyrus.modelexplorer/src/org/eclipse/papyrus/modelexplorer/provider/ActionStateSourceProvider.java
new file mode 100644
index 00000000000..892608565b8
--- /dev/null
+++ b/plugins/views/modelexplorer/org.eclipse.papyrus.modelexplorer/src/org/eclipse/papyrus/modelexplorer/provider/ActionStateSourceProvider.java
@@ -0,0 +1,268 @@
+/*****************************************************************************
+ * Copyright (c) 2010 CEA LIST.
+ *
+ *
+ * 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:
+ * Vincent Lorenzo (CEA LIST) vincent.lorenzo@cea.fr - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.modelexplorer.provider;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.papyrus.modelexplorer.ModelExplorerPageBookView;
+import org.eclipse.papyrus.modelexplorer.handler.DeleteCommandHandler;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.ui.AbstractSourceProvider;
+import org.eclipse.ui.IPartListener;
+import org.eclipse.ui.IPartService;
+import org.eclipse.ui.ISelectionListener;
+import org.eclipse.ui.ISelectionService;
+import org.eclipse.ui.ISources;
+import org.eclipse.ui.IWorkbench;
+import org.eclipse.ui.IWorkbenchPart;
+import org.eclipse.ui.IWorkbenchWindow;
+import org.eclipse.ui.PlatformUI;
+
+/**
+ *
+ * This class provides the state for the Delete Action in the Model Explorer.
+ * This state is used to refresh the status of this action in the Edit Menu.
+ *
+ * To get the status, we listen the selection service AND the part service!
+ * The part service is used to know if the selection is in the Model Explorer or not!
+ * When the selection is not in the model explorer, the handlers listening the variable need to be disabled
+ * FIXME : I think it is better to use PropertyTester which doesn't need listener
+ */
+
+public class ActionStateSourceProvider extends AbstractSourceProvider {
+
+ /**
+ * The name of the variable to check.
+ */
+ public static final String DELETE_IN_MODEL_EXPLORER = "deleteInModelExplorer"; //$NON-NLS-1$
+
+ /**
+ * The enabled state value.
+ */
+ private static final String ENABLED = "enabled"; //$NON-NLS-1$
+
+ /**
+ * The disabled state value.
+ */
+ private static final String DISABLED = "disabled"; //$NON-NLS-1$
+
+ /**
+ * Map used to register the state of the actions
+ */
+ private final HashMap<String, String> currentState = new HashMap<String, String>(2);
+
+ /**
+ * The selection service
+ */
+ private ISelectionService selectionService;
+
+ /**
+ * The listener for the selection service
+ */
+ private ISelectionListener selectionListener;
+
+ /**
+ * the listener for the part service
+ */
+ private IPartService partService;
+
+ /**
+ * The listener for the part service
+ */
+ private IPartListener partListener;
+
+ /**
+ * the current activated part
+ */
+ private IWorkbenchPart currentActivatedPart = null;
+
+ /**
+ *
+ * Constructor.
+ *
+ */
+ public ActionStateSourceProvider() {
+ currentState.put(DELETE_IN_MODEL_EXPLORER, DISABLED);
+ selectionListener = new SelectionListener();
+ partListener = new PartListener();
+ }
+
+ /**
+ *
+ * @see org.eclipse.ui.ISourceProvider#dispose()
+ *
+ */
+ public void dispose() {
+ if(selectionService != null) {
+ selectionService.removeSelectionListener(selectionListener);
+ }
+ if(partService != null) {
+ partService.removePartListener(partListener);
+ }
+ }
+
+ /**
+ *
+ * @see org.eclipse.ui.ISourceProvider#getCurrentState()
+ *
+ * @return
+ */
+ public Map<String, String> getCurrentState() {
+ addSelectionListener();
+ addPartListener();
+ return currentState;
+ }
+
+ /**
+ *
+ * @see org.eclipse.ui.ISourceProvider#getProvidedSourceNames()
+ *
+ * @return
+ */
+ public String[] getProvidedSourceNames() {
+ return new String[]{ DELETE_IN_MODEL_EXPLORER };
+ }
+
+ /**
+ * Adds a listener on the selection service if the field {@link #selectionService} is <code>null</code>
+ */
+ protected void addSelectionListener() {
+ if(this.selectionService == null) {
+ Display.getDefault().asyncExec(new Runnable() {
+
+ public void run() {
+ IWorkbench workbench = PlatformUI.getWorkbench();
+ selectionService = (ISelectionService)workbench.getService(ISelectionService.class);
+ IWorkbenchWindow activeWorkbench = workbench.getActiveWorkbenchWindow();
+ if(activeWorkbench != null) {
+ selectionService = activeWorkbench.getSelectionService();
+ if(selectionService != null) {
+ selectionService.addSelectionListener(selectionListener);
+ }
+ }
+ }
+ });
+ }
+ }
+
+ protected void addPartListener() {
+ if(this.partService == null) {
+ Display.getDefault().asyncExec(new Runnable() {
+
+ public void run() {
+ IWorkbench workbench = PlatformUI.getWorkbench();
+ partService = (IPartService)workbench.getService(IPartService.class);
+ IWorkbenchWindow activeWorkbench = workbench.getActiveWorkbenchWindow();
+ if(activeWorkbench != null) {
+ partService = activeWorkbench.getPartService();
+ if(partService != null) {
+ partService.addPartListener(partListener);
+ }
+ }
+ }
+ });
+ }
+ }
+
+ /**
+ * Refresh the state of the Delete Action
+ */
+ protected boolean testDeleteFromModelExplorer() {
+ DeleteCommandHandler handler = new DeleteCommandHandler();
+ return isSelectionInModelExplorer() && handler.isEnabled();
+ }
+
+ /**
+ * Tests if the Delete action can be executed
+ *
+ * @return
+ * <code>true</code> if the Delete action can be executed <code>false</code> if not
+ */
+ protected void refreshDeleteAction() {
+ String oldState = currentState.get(DELETE_IN_MODEL_EXPLORER);
+ String newState = (testDeleteFromModelExplorer() ? ENABLED : DISABLED);
+
+ if(oldState != newState) {
+ currentState.put(DELETE_IN_MODEL_EXPLORER, newState);
+ fireSourceChanged(ISources.WORKBENCH, currentState);
+ }
+ }
+
+ /**
+ * Test if the current ActivePart is the Model Explorer
+ *
+ * @return
+ * <code>true</code> if the current activePart is the Model Explorer <code>false</code> if not
+ */
+ protected boolean isSelectionInModelExplorer() {
+ return (currentActivatedPart instanceof ModelExplorerPageBookView);
+ }
+
+ /**
+ * The class {@link PartListener}
+ */
+ public class PartListener implements IPartListener {
+
+ /**
+ * {@inheritDoc}
+ */
+ public void partOpened(IWorkbenchPart part) {
+ // nothing here
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void partDeactivated(IWorkbenchPart part) {
+ // nothing here
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void partClosed(IWorkbenchPart part) {
+ // nothing here
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void partBroughtToTop(IWorkbenchPart part) {
+ // nothing here
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void partActivated(IWorkbenchPart part) {
+ currentActivatedPart = part;
+ refreshDeleteAction();
+ }
+ }
+
+ /**
+ * This class provides the listener for the selection service
+ */
+ public class SelectionListener implements ISelectionListener {
+
+ /**
+ * {@inheritDoc}
+ */
+ public void selectionChanged(IWorkbenchPart part, ISelection selection) {
+ refreshDeleteAction();
+ }
+ }
+}
diff --git a/plugins/views/modelexplorer/org.eclipse.papyrus.modelexplorer/src/org/eclipse/papyrus/modelexplorer/provider/PropertyTester.java b/plugins/views/modelexplorer/org.eclipse.papyrus.modelexplorer/src/org/eclipse/papyrus/modelexplorer/provider/PropertyTester.java
new file mode 100644
index 00000000000..d4377323e0f
--- /dev/null
+++ b/plugins/views/modelexplorer/org.eclipse.papyrus.modelexplorer/src/org/eclipse/papyrus/modelexplorer/provider/PropertyTester.java
@@ -0,0 +1,198 @@
+/*****************************************************************************
+ * Copyright (c) 2011 CEA LIST.
+ *
+ *
+ * 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:
+ * Vincent Lorenzo (CEA LIST) vincent.lorenzo@cea.fr - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.modelexplorer.provider;
+
+import java.util.Iterator;
+
+import org.eclipse.core.runtime.IAdaptable;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.gmf.runtime.notation.Diagram;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.papyrus.core.services.ServiceException;
+import org.eclipse.papyrus.core.utils.ServiceUtilsForActionHandlers;
+import org.eclipse.papyrus.modelexplorer.ModelExplorerPageBookView;
+import org.eclipse.papyrus.modelexplorer.NavigatorUtils;
+import org.eclipse.papyrus.sasheditor.contentprovider.IPageMngr;
+import org.eclipse.ui.IWorkbenchPart;
+
+/**
+ * This class provides test called by the plugin.xml in order to know if handlers should be active or not.
+ *
+ * Sometimes these test can be done directly in the plugin.xml in the activeWhen (with instanceof, adapt, ...),
+ * but in this case, Eclipse doesn't refresh correctly the status of the command in the menu Edit or in other menu.
+ *
+ *
+ *
+ */
+public class PropertyTester extends org.eclipse.core.expressions.PropertyTester {
+
+ /** property to test if the selected element are open in the editor */
+ public static final String IS_DIAGRAM = "isDiagram"; //$NON-NLS-1$
+
+ /** property to test if the selected elements is an eObject */
+ public static final String IS_EOBJECT = "isEObject"; //$NON-NLS-1$
+
+ /** property to test if the current activePart is the ModelExplorer */
+ public static final String IS_MODEL_EXPLORER = "isModelExplorer"; //$NON-NLS-1$
+
+ /** indicate if the element can be open in a tab */
+ public static final String IS_PAGE = "isPage";//$NON-NLS-1$
+
+ /**
+ *
+ * @see org.eclipse.core.expressions.IPropertyTester#test(java.lang.Object, java.lang.String, java.lang.Object[], java.lang.Object)
+ *
+ * @param receiver
+ * @param property
+ * @param args
+ * @param expectedValue
+ * @return
+ */
+ public boolean test(Object receiver, String property, Object[] args, Object expectedValue) {
+ if(IS_DIAGRAM.equals(property) && receiver instanceof IStructuredSelection) {
+ boolean answer = isDiagram((IStructuredSelection)receiver);
+ return new Boolean(answer).equals(expectedValue);
+ }
+
+ if(IS_EOBJECT.equals(property) && receiver instanceof IStructuredSelection) {
+ boolean answer = isObject((IStructuredSelection)receiver);
+ return new Boolean(answer).equals(expectedValue);
+ }
+ if(IS_MODEL_EXPLORER.equals(property) && receiver instanceof IWorkbenchPart) {
+ boolean answer = isModelExplorer((IWorkbenchPart)receiver);
+ return new Boolean(answer).equals(expectedValue);
+ }
+ if(IS_PAGE.equals(property) && receiver instanceof IStructuredSelection) {
+ boolean answer = isPage((IStructuredSelection)receiver);
+ return new Boolean(answer).equals(expectedValue);
+ }
+ return false;
+ }
+
+ /**
+ *
+ * @param selection
+ * the current selection
+ * @return
+ * <code>true</code> if all selected elements are pages
+ */
+ private boolean isPage(IStructuredSelection selection) {
+ IPageMngr pageMngr = getPageManager();
+ if(pageMngr != null) {
+ if(!selection.isEmpty()) {
+ Iterator<?> iter = selection.iterator();
+ while(iter.hasNext()) {
+ Object current = iter.next();
+ if(current instanceof IAdaptable) {
+ EObject eObject = (EObject)((IAdaptable)current).getAdapter(EObject.class);
+ if(!pageMngr.allPages().contains(eObject)) {
+ return false;
+ }
+ } else if(!pageMngr.allPages().contains(current)) {//table of diagram!
+ return false;
+ }
+ }
+ return true;
+ }
+ }
+ return false;
+ }
+
+ /**
+ * Returns the page manager
+ *
+ * @return
+ * the page manager
+ */
+ protected IPageMngr getPageManager() {
+ IPageMngr pageMngr = null;
+ try {
+ ServiceUtilsForActionHandlers instance = org.eclipse.papyrus.core.utils.ServiceUtilsForActionHandlers.getInstance();
+ if(instance != null) {
+ pageMngr = instance.getIPageMngr();
+ }
+ } catch (NullPointerException npe) {
+ //NPE
+ } catch (ServiceException e) {
+ //we are closing the editor, so the model explorer has nothing to display
+ // e.printStackTrace();
+ }
+ return pageMngr;
+ }
+
+ /**
+ * Tests if the current activePart is the Model Explorer
+ *
+ * @param receiver
+ * @return
+ */
+ private boolean isModelExplorer(IWorkbenchPart receiver) {
+ return receiver instanceof ModelExplorerPageBookView;
+ }
+
+ /**
+ * Tests if all elements in the selection are EObject
+ *
+ * @param selection
+ * @return
+ */
+ private boolean isObject(IStructuredSelection selection) {
+ if(!selection.isEmpty()) {
+ Iterator<?> iter = selection.iterator();
+ while(iter.hasNext()) {
+ Object current = iter.next();
+ if(current instanceof IAdaptable) {
+ EObject eObject = (EObject)((IAdaptable)current).getAdapter(EObject.class);
+ if(eObject == null) {
+ return false;
+ }
+ } else {
+ return false;
+ }
+ }
+ return true;
+ }
+ return false;
+ }
+
+ /**
+ * Tests the selection in order to know if it contains only {@link Diagram}
+ *
+ * @param selection
+ * @return
+ * <code>true</code> if the selection is composed by {@link Diagram}
+ *
+ * FIXME : we should call the method isDiagram in
+ * oep.diagram.common#DiagramPropertyTester
+ */
+ private boolean isDiagram(IStructuredSelection selection) {
+ if(!selection.isEmpty()) {
+ Iterator<?> iter = selection.iterator();
+ while(iter.hasNext()) {
+ /**
+ * Set to use the IAdaptable mechanism
+ * Used for example for facet elements
+ */
+ final Object next = iter.next();
+ EObject diag = NavigatorUtils.getElement(next, EObject.class);
+ if(!(diag instanceof Diagram)) {
+ return false;
+ }
+ }
+ return true;
+ }
+ return false;
+ }
+
+}
diff --git a/plugins/views/modelexplorer/org.eclipse.papyrus.modelexplorer/src/org/eclipse/papyrus/modelexplorer/queries/AbstractEditorContainerQuery.java b/plugins/views/modelexplorer/org.eclipse.papyrus.modelexplorer/src/org/eclipse/papyrus/modelexplorer/queries/AbstractEditorContainerQuery.java
new file mode 100644
index 00000000000..7172b793184
--- /dev/null
+++ b/plugins/views/modelexplorer/org.eclipse.papyrus.modelexplorer/src/org/eclipse/papyrus/modelexplorer/queries/AbstractEditorContainerQuery.java
@@ -0,0 +1,45 @@
+/*****************************************************************************
+ * Copyright (c) 2011 CEA LIST.
+ *
+ *
+ * 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:
+ * Vincent Lorenzo (CEA LIST) vincent.lorenzo@cea.fr - Initial API and implementation
+ *
+ *****************************************************************************/
+
+package org.eclipse.papyrus.modelexplorer.queries;
+
+import org.eclipse.papyrus.core.editor.IMultiDiagramEditor;
+import org.eclipse.papyrus.core.services.ServiceException;
+import org.eclipse.papyrus.core.services.ServicesRegistry;
+import org.eclipse.papyrus.core.utils.EditorUtils;
+import org.eclipse.papyrus.core.utils.ServiceUtils;
+import org.eclipse.papyrus.sasheditor.contentprovider.IPageMngr;
+
+/**
+ *
+ * An abstract class to get the pageMngr
+ *
+ */
+public abstract class AbstractEditorContainerQuery {//we don't need to implements IJavaModelQuery here
+
+ /**
+ *
+ * @return
+ * @throws ServiceException
+ */
+ protected IPageMngr getPageMngr() throws ServiceException {
+ // pageMngr can't be static, because there is a new IPageMngr each time we open a Papyrus Editor
+ IMultiDiagramEditor papyrusEditor = EditorUtils.getMultiDiagramEditor();
+ if (papyrusEditor != null) {
+ ServicesRegistry serviceRegistry = papyrusEditor.getServicesRegistry();
+ return ServiceUtils.getInstance().getIPageMngr(serviceRegistry);
+ }
+ throw new ServiceException("Can't retrieve the IPageMngr");
+ }
+}
diff --git a/plugins/views/modelexplorer/org.eclipse.papyrus.modelexplorer/src/org/eclipse/papyrus/modelexplorer/queries/AbstractGetEditorIconQuery.java b/plugins/views/modelexplorer/org.eclipse.papyrus.modelexplorer/src/org/eclipse/papyrus/modelexplorer/queries/AbstractGetEditorIconQuery.java
new file mode 100644
index 00000000000..e6a6c1f9518
--- /dev/null
+++ b/plugins/views/modelexplorer/org.eclipse.papyrus.modelexplorer/src/org/eclipse/papyrus/modelexplorer/queries/AbstractGetEditorIconQuery.java
@@ -0,0 +1,69 @@
+/*****************************************************************************
+ * Copyright (c) 2011 CEA LIST.
+ *
+ *
+ * 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:
+ * Vincent Lorenzo (CEA LIST) vincent.lorenzo@cea.fr - Initial API and implementation
+ *
+ *****************************************************************************/
+
+package org.eclipse.papyrus.modelexplorer.queries;
+
+import org.eclipse.papyrus.core.editorsfactory.IPageIconsRegistry;
+import org.eclipse.papyrus.core.editorsfactory.IPageIconsRegistryExtended;
+import org.eclipse.papyrus.core.editorsfactory.PageIconsRegistry;
+import org.eclipse.papyrus.core.services.ServiceException;
+import org.eclipse.papyrus.core.utils.EditorUtils;
+
+/**
+ *
+ * An abstract class to get the iconRegistery
+ *
+ */
+public abstract class AbstractGetEditorIconQuery{//we don't need to implements IJavaModelQuery here
+
+ /**
+ * the icon registry
+ */
+ private static IPageIconsRegistry editorRegistry;
+
+ /**
+ * Get the EditorRegistry used to create editor instances. This default
+ * implementation return the singleton eINSTANCE. This method can be
+ * subclassed to return another registry.
+ *
+ * @return the singleton eINSTANCE of editor registry
+ */
+ protected IPageIconsRegistryExtended getEditorRegistry() {
+ if(editorRegistry == null) {
+ editorRegistry = createEditorRegistry();
+ }
+ if(!(editorRegistry instanceof IPageIconsRegistryExtended)) {
+ throw new RuntimeException("The editor registry do not implement IPageIconsRegistryExtended");////$NON-NLS-1$
+ }
+ return (IPageIconsRegistryExtended)editorRegistry;
+ }
+
+ /**
+ * Return the EditorRegistry for nested editor descriptors. Subclass should
+ * implements this method in order to return the registry associated to the
+ * extension point namespace.
+ *
+ * @return the EditorRegistry for nested editor descriptors
+ * FIXME : use a deprecated method
+ */
+ protected IPageIconsRegistry createEditorRegistry() {
+ try {
+ return EditorUtils.getServiceRegistry().getService(IPageIconsRegistry.class);
+ } catch (ServiceException e) {
+ // Not found, return an empty one which return null for each
+ // request.
+ return new PageIconsRegistry();
+ }
+ }
+}

Back to the top