diff options
author | cdamus | 2013-02-21 22:38:54 +0000 |
---|---|---|
committer | cdamus | 2013-02-21 22:38:54 +0000 |
commit | e83f0b973099301b17cc6f354cbb26724fd17f7b (patch) | |
tree | d8e69186c799023a58a12a88a01d261e023e7f08 | |
parent | f44153e5ea46ae793040c4e62e93d4976e596104 (diff) | |
download | org.eclipse.papyrus-e83f0b973099301b17cc6f354cbb26724fd17f7b.tar.gz org.eclipse.papyrus-e83f0b973099301b17cc6f354cbb26724fd17f7b.tar.xz org.eclipse.papyrus-e83f0b973099301b17cc6f354cbb26724fd17f7b.zip |
CDO storage provider for the New Papyrus Model wizard.
https://bugs.eclipse.org/bugs/show_bug.cgi?id=401197
16 files changed, 940 insertions, 0 deletions
diff --git a/plugins/cdo/org.eclipse.papyrus.cdo.uml.diagram.ui/.classpath b/plugins/cdo/org.eclipse.papyrus.cdo.uml.diagram.ui/.classpath new file mode 100644 index 00000000000..64c5e31b7a2 --- /dev/null +++ b/plugins/cdo/org.eclipse.papyrus.cdo.uml.diagram.ui/.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/cdo/org.eclipse.papyrus.cdo.uml.diagram.ui/.project b/plugins/cdo/org.eclipse.papyrus.cdo.uml.diagram.ui/.project new file mode 100644 index 00000000000..fadca311785 --- /dev/null +++ b/plugins/cdo/org.eclipse.papyrus.cdo.uml.diagram.ui/.project @@ -0,0 +1,28 @@ +<?xml version="1.0" encoding="UTF-8"?> +<projectDescription> + <name>org.eclipse.papyrus.cdo.uml.diagram.ui</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/cdo/org.eclipse.papyrus.cdo.uml.diagram.ui/.settings/org.eclipse.jdt.core.prefs b/plugins/cdo/org.eclipse.papyrus.cdo.uml.diagram.ui/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 00000000000..af0f20f97a5 --- /dev/null +++ b/plugins/cdo/org.eclipse.papyrus.cdo.uml.diagram.ui/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,7 @@ +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/cdo/org.eclipse.papyrus.cdo.uml.diagram.ui/.settings/org.eclipse.jdt.ui.prefs b/plugins/cdo/org.eclipse.papyrus.cdo.uml.diagram.ui/.settings/org.eclipse.jdt.ui.prefs new file mode 100644 index 00000000000..86087cd06ce --- /dev/null +++ b/plugins/cdo/org.eclipse.papyrus.cdo.uml.diagram.ui/.settings/org.eclipse.jdt.ui.prefs @@ -0,0 +1,3 @@ +eclipse.preferences.version=1 +org.eclipse.jdt.ui.javadoc=true +org.eclipse.jdt.ui.text.custom_code_templates=<?xml version\="1.0" encoding\="UTF-8" standalone\="no"?><templates><template autoinsert\="true" context\="gettercomment_context" deleted\="false" description\="Comment for getter method" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.gettercomment" name\="gettercomment">/**\n * @return the ${bare_field_name}\n */</template><template autoinsert\="true" context\="settercomment_context" deleted\="false" description\="Comment for setter method" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.settercomment" name\="settercomment">/**\n * @param ${param} the ${bare_field_name} to set\n */</template><template autoinsert\="true" context\="constructorcomment_context" deleted\="false" description\="Comment for created constructors" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.constructorcomment" name\="constructorcomment">/**\n * ${tags}\n */</template><template autoinsert\="false" context\="filecomment_context" deleted\="false" description\="Comment for created Java files" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.filecomment" name\="filecomment">/*****************************************************************************\n * Copyright (c) ${year} CEA LIST.\n * \n * All rights reserved. This program and the accompanying materials\n * are made available under the terms of the Eclipse Public License v1.0\n * which accompanies this distribution, and is available at\n * http\://www.eclipse.org/legal/epl-v10.html\n *\n * Contributors\:\n * CEA LIST - Initial API and implementation\n *****************************************************************************/</template><template autoinsert\="false" context\="typecomment_context" deleted\="false" description\="Comment for created types" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.typecomment" name\="typecomment">/**\n * This is the ${type_name} type. Enjoy.\n */</template><template autoinsert\="true" context\="fieldcomment_context" deleted\="false" description\="Comment for fields" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.fieldcomment" name\="fieldcomment">/**\n * \n */</template><template autoinsert\="true" context\="methodcomment_context" deleted\="false" description\="Comment for non-overriding methods" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.methodcomment" name\="methodcomment">/**\n * ${tags}\n */</template><template autoinsert\="false" context\="overridecomment_context" deleted\="false" description\="Comment for overriding methods" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.overridecomment" name\="overridecomment"/><template autoinsert\="true" context\="delegatecomment_context" deleted\="false" description\="Comment for delegate methods" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.delegatecomment" name\="delegatecomment">/**\n * ${tags}\n * ${see_to_target}\n */</template><template autoinsert\="true" context\="newtype_context" deleted\="false" description\="Newly created files" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.newtype" name\="newtype">${filecomment}\n${package_declaration}\n\n${typecomment}\n${type_declaration}</template><template autoinsert\="true" context\="classbody_context" deleted\="false" description\="Code in new class type bodies" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.classbody" name\="classbody">\n</template><template autoinsert\="true" context\="interfacebody_context" deleted\="false" description\="Code in new interface type bodies" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.interfacebody" name\="interfacebody">\n</template><template autoinsert\="true" context\="enumbody_context" deleted\="false" description\="Code in new enum type bodies" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.enumbody" name\="enumbody">\n</template><template autoinsert\="true" context\="annotationbody_context" deleted\="false" description\="Code in new annotation type bodies" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.annotationbody" name\="annotationbody">\n</template><template autoinsert\="true" context\="catchblock_context" deleted\="false" description\="Code in new catch blocks" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.catchblock" name\="catchblock">// ${todo} Auto-generated catch block\n${exception_var}.printStackTrace();</template><template autoinsert\="true" context\="methodbody_context" deleted\="false" description\="Code in created method stubs" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.methodbody" name\="methodbody">// ${todo} Auto-generated method stub\n${body_statement}</template><template autoinsert\="true" context\="constructorbody_context" deleted\="false" description\="Code in created constructor stubs" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.constructorbody" name\="constructorbody">${body_statement}\n// ${todo} Auto-generated constructor stub</template><template autoinsert\="true" context\="getterbody_context" deleted\="false" description\="Code in created getters" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.getterbody" name\="getterbody">return ${field};</template><template autoinsert\="true" context\="setterbody_context" deleted\="false" description\="Code in created setters" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.setterbody" name\="setterbody">${field} \= ${param};</template></templates> diff --git a/plugins/cdo/org.eclipse.papyrus.cdo.uml.diagram.ui/META-INF/MANIFEST.MF b/plugins/cdo/org.eclipse.papyrus.cdo.uml.diagram.ui/META-INF/MANIFEST.MF new file mode 100644 index 00000000000..d9ac409ef60 --- /dev/null +++ b/plugins/cdo/org.eclipse.papyrus.cdo.uml.diagram.ui/META-INF/MANIFEST.MF @@ -0,0 +1,21 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: %pluginName +Bundle-SymbolicName: org.eclipse.papyrus.cdo.uml.diagram.ui;singleton:=true +Bundle-Version: 0.10.0.qualifier +Bundle-Activator: org.eclipse.papyrus.cdo.uml.diagram.internal.ui.Activator +Bundle-Vendor: %providerName +Require-Bundle: org.eclipse.ui, + org.eclipse.core.runtime, + org.eclipse.papyrus.infra.core.log;bundle-version="0.10.0", + org.eclipse.papyrus.cdo.core;bundle-version="0.10.0", + org.eclipse.papyrus.cdo.ui;bundle-version="0.10.0", + org.eclipse.papyrus.uml.diagram.wizards;bundle-version="0.10.0" +Bundle-RequiredExecutionEnvironment: J2SE-1.5 +Bundle-ActivationPolicy: lazy +Bundle-Localization: plugin +Export-Package: org.eclipse.papyrus.cdo.uml.diagram.internal.ui, + org.eclipse.papyrus.cdo.uml.diagram.internal.ui.handlers, + org.eclipse.papyrus.cdo.uml.diagram.internal.ui.wizards +Import-Package: com.google.common.base, + com.google.common.eventbus;version="10.0.1" diff --git a/plugins/cdo/org.eclipse.papyrus.cdo.uml.diagram.ui/about.html b/plugins/cdo/org.eclipse.papyrus.cdo.uml.diagram.ui/about.html new file mode 100644 index 00000000000..209103075a7 --- /dev/null +++ b/plugins/cdo/org.eclipse.papyrus.cdo.uml.diagram.ui/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>November 14, 2008</p>
+<h3>License</h3>
+
+<p>The Eclipse Foundation makes available all content in this plug-in ("Content"). Unless otherwise
+indicated below, the Content is provided to you under the terms and conditions of the
+Eclipse Public License Version 1.0 ("EPL"). 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, "Program" 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 ("Redistributor") 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/cdo/org.eclipse.papyrus.cdo.uml.diagram.ui/build.properties b/plugins/cdo/org.eclipse.papyrus.cdo.uml.diagram.ui/build.properties new file mode 100644 index 00000000000..92ba4c54284 --- /dev/null +++ b/plugins/cdo/org.eclipse.papyrus.cdo.uml.diagram.ui/build.properties @@ -0,0 +1,10 @@ +source.. = src/ +output.. = bin/ +bin.includes = META-INF/,\ + .,\ + plugin.properties,\ + about.html,\ + plugin.xml,\ + icons/ +bin.excludes = icons/**/*.pxm +src.includes = about.html diff --git a/plugins/cdo/org.eclipse.papyrus.cdo.uml.diagram.ui/icons/full/elcl16/newmodel_co.gif b/plugins/cdo/org.eclipse.papyrus.cdo.uml.diagram.ui/icons/full/elcl16/newmodel_co.gif Binary files differnew file mode 100644 index 00000000000..a0de332274a --- /dev/null +++ b/plugins/cdo/org.eclipse.papyrus.cdo.uml.diagram.ui/icons/full/elcl16/newmodel_co.gif diff --git a/plugins/cdo/org.eclipse.papyrus.cdo.uml.diagram.ui/icons/full/elcl16/newmodel_co.pxm b/plugins/cdo/org.eclipse.papyrus.cdo.uml.diagram.ui/icons/full/elcl16/newmodel_co.pxm Binary files differnew file mode 100644 index 00000000000..e096c73ffea --- /dev/null +++ b/plugins/cdo/org.eclipse.papyrus.cdo.uml.diagram.ui/icons/full/elcl16/newmodel_co.pxm diff --git a/plugins/cdo/org.eclipse.papyrus.cdo.uml.diagram.ui/plugin.properties b/plugins/cdo/org.eclipse.papyrus.cdo.uml.diagram.ui/plugin.properties new file mode 100644 index 00000000000..24fbf5135d8 --- /dev/null +++ b/plugins/cdo/org.eclipse.papyrus.cdo.uml.diagram.ui/plugin.properties @@ -0,0 +1,13 @@ +# Copyright (c) 2013 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 +# + +pluginName = Papyrus CDO UML Diagrams UI (Incubation) +providerName = Eclipse Modeling Project diff --git a/plugins/cdo/org.eclipse.papyrus.cdo.uml.diagram.ui/plugin.xml b/plugins/cdo/org.eclipse.papyrus.cdo.uml.diagram.ui/plugin.xml new file mode 100644 index 00000000000..e6178471d35 --- /dev/null +++ b/plugins/cdo/org.eclipse.papyrus.cdo.uml.diagram.ui/plugin.xml @@ -0,0 +1,68 @@ +<?xml version="1.0" encoding="UTF-8"?> +<?eclipse version="3.4"?> +<plugin> + <extension + point="org.eclipse.papyrus.uml.diagram.wizards.newModelStorageProviders"> + <provider + class="org.eclipse.papyrus.cdo.uml.diagram.internal.ui.wizards.CDONewModelStorageProvider" + name="In a model repository"> + <enablement> + <iterate> + <or> + <adapt + type="org.eclipse.emf.ecore.EObject"> + <test + property="org.eclipse.papyrus.cdo.core.isCDOObject"> + </test> + </adapt> + <adapt + type="org.eclipse.emf.cdo.eresource.CDOResourceNode"> + </adapt> + <adapt + type="org.eclipse.papyrus.cdo.core.IPapyrusRepository"> + </adapt> + </or> + </iterate> + </enablement> + </provider> + </extension> + + + <extension + point="org.eclipse.ui.menus"> + <menuContribution + locationURI="popup:org.eclipse.papyrus.cdo.ui.ModelRepositoriesView?after=createActions"> + <command + commandId="org.eclipse.papyrus.cdo.uml.diagram.ui.commands.newModel" + icon="$nl$/icons/full/elcl16/newmodel_co.gif" + label="New Papyrus Model"> + </command> + </menuContribution> + </extension> + <extension + point="org.eclipse.ui.commands"> + <command + id="org.eclipse.papyrus.cdo.uml.diagram.ui.commands.newModel" + name="New Papyrus Model"> + </command> + </extension> + <extension + point="org.eclipse.ui.handlers"> + <handler + class="org.eclipse.papyrus.cdo.uml.diagram.internal.ui.handlers.NewModelHandler" + commandId="org.eclipse.papyrus.cdo.uml.diagram.ui.commands.newModel"> + <enabledWhen> + <iterate operator="and" ifEmpty="false"> + <or> + <adapt + type="org.eclipse.emf.cdo.eresource.CDOResourceNode"> + </adapt> + <adapt + type="org.eclipse.papyrus.cdo.core.IPapyrusRepository"> + </adapt> + </or> + </iterate> + </enabledWhen> + </handler> + </extension> +</plugin> diff --git a/plugins/cdo/org.eclipse.papyrus.cdo.uml.diagram.ui/src/org/eclipse/papyrus/cdo/uml/diagram/internal/ui/Activator.java b/plugins/cdo/org.eclipse.papyrus.cdo.uml.diagram.ui/src/org/eclipse/papyrus/cdo/uml/diagram/internal/ui/Activator.java new file mode 100644 index 00000000000..2d392b5bbb4 --- /dev/null +++ b/plugins/cdo/org.eclipse.papyrus.cdo.uml.diagram.ui/src/org/eclipse/papyrus/cdo/uml/diagram/internal/ui/Activator.java @@ -0,0 +1,52 @@ +package org.eclipse.papyrus.cdo.uml.diagram.internal.ui; + +import org.eclipse.papyrus.infra.core.log.LogHelper; +import org.eclipse.ui.plugin.AbstractUIPlugin; +import org.osgi.framework.BundleContext; + +/** + * The activator class controls the plug-in life cycle + */ +public class Activator extends AbstractUIPlugin { + + // The plug-in ID + public static final String PLUGIN_ID = "org.eclipse.papyrus.cdo.uml.diagram.ui"; //$NON-NLS-1$ + + // The shared instance + private static Activator plugin; + + /** Logging helper */ + public static LogHelper log = new LogHelper(); + + /** + * The constructor + */ + public Activator() { + super(); + } + + public void start(BundleContext context) throws Exception { + super.start(context); + plugin = this; + + // register the log helper + log.setPlugin(plugin); + + } + + public void stop(BundleContext context) throws Exception { + log = null; + plugin = null; + super.stop(context); + } + + /** + * Returns the shared instance + * + * @return the shared instance + */ + public static Activator getDefault() { + return plugin; + } + +} diff --git a/plugins/cdo/org.eclipse.papyrus.cdo.uml.diagram.ui/src/org/eclipse/papyrus/cdo/uml/diagram/internal/ui/handlers/NewModelHandler.java b/plugins/cdo/org.eclipse.papyrus.cdo.uml.diagram.ui/src/org/eclipse/papyrus/cdo/uml/diagram/internal/ui/handlers/NewModelHandler.java new file mode 100644 index 00000000000..75b2ee6ecb4 --- /dev/null +++ b/plugins/cdo/org.eclipse.papyrus.cdo.uml.diagram.ui/src/org/eclipse/papyrus/cdo/uml/diagram/internal/ui/handlers/NewModelHandler.java @@ -0,0 +1,51 @@ +/***************************************************************************** + * Copyright (c) 2013 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.cdo.uml.diagram.internal.ui.handlers; + +import org.eclipse.core.commands.AbstractHandler; +import org.eclipse.core.commands.ExecutionEvent; +import org.eclipse.core.commands.ExecutionException; +import org.eclipse.jface.viewers.ISelection; +import org.eclipse.jface.viewers.IStructuredSelection; +import org.eclipse.jface.wizard.WizardDialog; +import org.eclipse.papyrus.uml.diagram.wizards.InitModelWizard; +import org.eclipse.ui.handlers.HandlerUtil; + +/** + * This is the NewModelHandler type. Enjoy. + */ +public class NewModelHandler + extends AbstractHandler { + + public NewModelHandler() { + super(); + } + + public Object execute(ExecutionEvent event) + throws ExecutionException { + + ISelection selection = HandlerUtil.getCurrentSelection(event); + if (selection instanceof IStructuredSelection) { + InitModelWizard wizard = new InitModelWizard(); + + wizard.init(HandlerUtil.getActiveWorkbenchWindow(event) + .getWorkbench(), (IStructuredSelection) selection); + + WizardDialog dlg = new WizardDialog( + HandlerUtil.getActiveShell(event), wizard); + dlg.open(); + } + + return null; + } + +} diff --git a/plugins/cdo/org.eclipse.papyrus.cdo.uml.diagram.ui/src/org/eclipse/papyrus/cdo/uml/diagram/internal/ui/wizards/CDONewModelStorageProvider.java b/plugins/cdo/org.eclipse.papyrus.cdo.uml.diagram.ui/src/org/eclipse/papyrus/cdo/uml/diagram/internal/ui/wizards/CDONewModelStorageProvider.java new file mode 100644 index 00000000000..7f153e579cb --- /dev/null +++ b/plugins/cdo/org.eclipse.papyrus.cdo.uml.diagram.ui/src/org/eclipse/papyrus/cdo/uml/diagram/internal/ui/wizards/CDONewModelStorageProvider.java @@ -0,0 +1,188 @@ +/***************************************************************************** + * Copyright (c) 2013 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.cdo.uml.diagram.internal.ui.wizards; + +import static org.eclipse.papyrus.uml.diagram.wizards.utils.WizardsHelper.adapt; + +import java.util.Arrays; +import java.util.Collections; +import java.util.List; + +import org.eclipse.core.runtime.IStatus; +import org.eclipse.emf.cdo.CDOObject; +import org.eclipse.emf.cdo.eresource.CDOResourceNode; +import org.eclipse.emf.common.util.URI; +import org.eclipse.emf.ecore.EObject; +import org.eclipse.jface.operation.IRunnableContext; +import org.eclipse.jface.viewers.IStructuredSelection; +import org.eclipse.jface.wizard.IWizardPage; +import org.eclipse.papyrus.cdo.core.IPapyrusRepository; +import org.eclipse.papyrus.cdo.internal.core.CDOUtils; +import org.eclipse.papyrus.cdo.internal.core.PapyrusRepositoryManager; +import org.eclipse.papyrus.uml.diagram.wizards.AbstractNewModelStorageProvider; +import org.eclipse.papyrus.uml.diagram.wizards.CreateModelWizard; +import org.eclipse.papyrus.uml.diagram.wizards.InitModelWizard; + +import com.google.common.base.Supplier; +import com.google.common.eventbus.EventBus; + +/** + * This is the CDONewModelStorageProvider type. Enjoy. + */ +public class CDONewModelStorageProvider + extends AbstractNewModelStorageProvider { + + private final EventBus bus = new EventBus("NewCDOModelWizard"); + + private CreateModelWizard wizard; + + private RepositorySelectionPart selectProviderPart; + + private NewModelPage newModelPage; + + public CDONewModelStorageProvider() { + super(); + } + + public boolean canHandle(IStructuredSelection initialSelection) { + boolean result = false; + + for (Object next : initialSelection.toList()) { + if (CDOUtils.isCDOObject(adapt(next, EObject.class))) { + result = true; + break; + } + } + + return result; + } + + public void init(CreateModelWizard wizard, IStructuredSelection selection) { + super.init(wizard, selection); + + this.wizard = wizard; + newModelPage = createNewModelPage(selection); + createSelectProviderPart(); + + IPapyrusRepository repo = getRepository(selection); + if (repo != null) { + bus.post(repo); + } + } + + /** + * Gets the contextual repository, if any, from a selection. + * + * @param selection + * a selection + * + * @return the repository that is or contains the {@code selection} + */ + static IPapyrusRepository getRepository(IStructuredSelection selection) { + IPapyrusRepository result = null; + + if (!selection.isEmpty()) { + result = adapt(selection.getFirstElement(), + IPapyrusRepository.class); + if (result == null) { + CDOResourceNode node = adapt(selection.getFirstElement(), + CDOResourceNode.class); + if (node == null) { + EObject object = adapt(selection.getFirstElement(), + EObject.class); + if (object != null) { + CDOObject cdo = CDOUtils.getCDOObject(object); + if (cdo != null) { + node = cdo.cdoResource(); + } + } + } + + if (node != null) { + result = PapyrusRepositoryManager.INSTANCE + .getRepositoryForURI(node.getURI()); + } + } + } + + return result; + } + + public List<? extends IWizardPage> createPages() { + if (newModelPage == null) { + return Collections.emptyList(); + } + + return Arrays.asList(newModelPage); + } + + public IStatus validateDiagramCategories(String... newCategories) { + if (newModelPage != null) { + String firstCategory = newCategories.length > 0 + ? newCategories[0] + : null; + if (newCategories.length > 0) { + // 316943 - [Wizard] Wrong suffix for file name when creating a + // profile model + return newModelPage.diagramExtensionChanged(wizard + .getDiagramFileExtension(firstCategory)); + } + } + + return super.validateDiagramCategories(newCategories); + } + + /** + * Creates the new model page, if required. + * + * @param selection + * the selection + * + * @return the new model page, or {@code null} if none + */ + protected NewModelPage createNewModelPage(IStructuredSelection selection) { + if (wizard.isCreateProjectWizard() + || wizard.isCreateMultipleModelsWizard()) { + + return null; + } + + // TODO: Handle creation from existing domain model + + return new NewModelPage(selection, bus, wizard.getModelKindName()); + } + + protected boolean isCreateFromExistingDomainModel() { + return wizard.isInitModelWizard() + && ((InitModelWizard) wizard).isCreateFromExistingDomainModel(); + } + + public URI createNewModelURI(String categoryId) { + return newModelPage.createNewModelResourceURI(); + } + + @Override + public ISelectProviderPart createSelectProviderPart() { + if (selectProviderPart == null) { + selectProviderPart = new RepositorySelectionPart( + PapyrusRepositoryManager.INSTANCE, bus, + new Supplier<IRunnableContext>() { + + public IRunnableContext get() { + return wizard.getContainer(); + } + }); + } + + return selectProviderPart; + } +} diff --git a/plugins/cdo/org.eclipse.papyrus.cdo.uml.diagram.ui/src/org/eclipse/papyrus/cdo/uml/diagram/internal/ui/wizards/NewModelPage.java b/plugins/cdo/org.eclipse.papyrus.cdo.uml.diagram.ui/src/org/eclipse/papyrus/cdo/uml/diagram/internal/ui/wizards/NewModelPage.java new file mode 100644 index 00000000000..f9ef94ab75b --- /dev/null +++ b/plugins/cdo/org.eclipse.papyrus.cdo.uml.diagram.ui/src/org/eclipse/papyrus/cdo/uml/diagram/internal/ui/wizards/NewModelPage.java @@ -0,0 +1,384 @@ +/***************************************************************************** + * Copyright (c) 2013 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.cdo.uml.diagram.internal.ui.wizards; + +import static org.eclipse.papyrus.uml.diagram.wizards.utils.WizardsHelper.adapt; + +import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.Path; +import org.eclipse.core.runtime.Status; +import org.eclipse.emf.cdo.eresource.CDOResourceFolder; +import org.eclipse.emf.cdo.eresource.CDOResourceNode; +import org.eclipse.emf.cdo.util.CDOURIUtil; +import org.eclipse.emf.cdo.view.CDOView; +import org.eclipse.emf.common.util.URI; +import org.eclipse.jface.layout.GridDataFactory; +import org.eclipse.jface.viewers.DecoratingLabelProvider; +import org.eclipse.jface.viewers.ISelectionChangedListener; +import org.eclipse.jface.viewers.IStructuredSelection; +import org.eclipse.jface.viewers.SelectionChangedEvent; +import org.eclipse.jface.viewers.StructuredSelection; +import org.eclipse.jface.viewers.TreeViewer; +import org.eclipse.jface.wizard.WizardPage; +import org.eclipse.osgi.util.NLS; +import org.eclipse.papyrus.cdo.core.IPapyrusRepository; +import org.eclipse.papyrus.cdo.internal.core.IInternalPapyrusRepository; +import org.eclipse.papyrus.cdo.internal.ui.views.ModelRepositoryItemProvider; +import org.eclipse.papyrus.uml.diagram.wizards.Activator; +import org.eclipse.papyrus.uml.diagram.wizards.Messages; +import org.eclipse.swt.SWT; +import org.eclipse.swt.events.ModifyEvent; +import org.eclipse.swt.events.ModifyListener; +import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Label; +import org.eclipse.swt.widgets.Text; +import org.eclipse.ui.PlatformUI; + +import com.google.common.base.Strings; +import com.google.common.eventbus.EventBus; +import com.google.common.eventbus.Subscribe; + +/** + * This is the NewModelPage type. Enjoy. + */ +public class NewModelPage + extends WizardPage { + + public static final String PAGE_ID = "NewCDOModel"; //$NON-NLS-1$ + + private Text folderText; + + private TreeViewer foldersTree; + + private Text nameText; + + private IPapyrusRepository repository; + + private CDOResourceNode selectedNode; + + private boolean synchronizingFolderSelection; + + public NewModelPage(IStructuredSelection selection, EventBus bus, + String modelKindName) { + + super(PAGE_ID); + + setTitle(NLS.bind("New {0} Model", modelKindName)); + setDescription(NLS.bind("Create a new {0} model", modelKindName)); + + if (!selection.isEmpty()) { + selectedNode = adapt(selection.getFirstElement(), + CDOResourceNode.class); + if ((selectedNode != null) + && !(selectedNode instanceof CDOResourceFolder)) { + selectedNode = selectedNode.getFolder(); + } + } + + bus.register(this); + } + + public void createControl(Composite parent) { + Composite myComposite = new Composite(parent, SWT.NONE); + GridDataFactory.fillDefaults().grab(true, true).applyTo(myComposite); + myComposite.setLayout(new GridLayout(2, false)); + + Label label = new Label(myComposite, SWT.NONE); + label.setText("Enter or select the parent folder:"); + GridDataFactory.swtDefaults().span(2, 1).applyTo(label); + + folderText = new Text(myComposite, SWT.BORDER); + GridDataFactory.fillDefaults().grab(true, false).span(2, 1) + .applyTo(folderText); + updateFolderSelection(); + + foldersTree = new TreeViewer(myComposite, SWT.BORDER | SWT.V_SCROLL + | SWT.H_SCROLL); + GridDataFactory.fillDefaults().grab(true, true).span(2, 1) + .applyTo(foldersTree.getControl()); + ModelRepositoryItemProvider itemProvider = new ModelRepositoryItemProvider( + null); + foldersTree.setContentProvider(itemProvider); + foldersTree + .setLabelProvider(new DecoratingLabelProvider(itemProvider, + PlatformUI.getWorkbench().getDecoratorManager() + .getLabelDecorator())); + foldersTree.setSorter(itemProvider); + if (getRepository() != null) { + foldersTree.setInput(getRepository()); + } + if (selectedNode != null) { + foldersTree.setSelection(new StructuredSelection(selectedNode)); + } + + new Label(myComposite, SWT.NONE).setText("Resource name:"); + + nameText = new Text(myComposite, SWT.BORDER); + GridDataFactory.fillDefaults().grab(true, false).applyTo(nameText); + nameText.setText(suggestName("model", "di")); + + setControl(myComposite); + + folderText.addModifyListener(new ModifyListener() { + + public void modifyText(ModifyEvent e) { + findFolderSelection(); + validatePage(); + } + }); + + foldersTree + .addSelectionChangedListener(new ISelectionChangedListener() { + + public void selectionChanged(SelectionChangedEvent event) { + IStructuredSelection selection = (IStructuredSelection) event + .getSelection(); + selectedNode = selection.isEmpty() + ? null + : adapt(selection.getFirstElement(), + CDOResourceNode.class); + updateFolderSelection(); + validatePage(); + } + }); + + nameText.addModifyListener(new ModifyListener() { + + public void modifyText(ModifyEvent e) { + validatePage(); + } + }); + + validatePage(); + } + + @Subscribe + public void setRepository(IPapyrusRepository repository) { + this.repository = repository; + + if (foldersTree != null) { + foldersTree.setInput(repository); + } + + validatePage(); + } + + private IInternalPapyrusRepository getRepository() { + return ((IInternalPapyrusRepository) repository); + } + + CDOView getView() { + IInternalPapyrusRepository repo = getRepository(); + return (repo == null) + ? null + : repo.getMasterView(); + } + + String getSelectedFolderPath() { + return folderText.getText().trim(); + } + + void updateFolderSelection() { + whileSynchronizingFolderSelection(new Runnable() { + + public void run() { + CDOResourceFolder selected = null; + if (selectedNode instanceof CDOResourceFolder) { + selected = (CDOResourceFolder) selectedNode; + } else if (selectedNode != null) { + // will be null if the selectedNode is contained by the root + // resource + selected = selectedNode.getFolder(); + } + + if (selected == null) { + folderText.setText(""); + } else { + folderText.setText(selected.getPath()); + } + } + }); + } + + void findFolderSelection() { + whileSynchronizingFolderSelection(new Runnable() { + + public void run() { + String folder = folderText.getText().trim(); + CDOView view = getView(); + if (view != null) { + try { + foldersTree.setSelection(new StructuredSelection(view + .getResourceNode(folder))); + } catch (Exception e) { + // normal occurrence when the folder doesn't exist + } + } + } + }); + } + + private void whileSynchronizingFolderSelection(Runnable runnable) { + if (!synchronizingFolderSelection) { + synchronizingFolderSelection = true; + + try { + runnable.run(); + } finally { + synchronizingFolderSelection = false; + } + } + } + + String suggestName(String baseName, String extension) { + String result = String.format("%s.%s", baseName, extension); + CDOView view = getView(); + + if (view != null) { + for (int i = 1;; i++) { + if (!view.hasResource(getNewResourcePath(result))) { + break; + } else { + // use %s instead of %d to avoid any thousands separators + // (hah! that there should be so many models) + result = String.format("%s%s.%s", baseName, i, extension); + } + } + } + + return result; + } + + String getNewResourcePath(String name) { + String result = null; + String path = getSelectedFolderPath(); + + if (path.equals("")) { + // it's a resource in the root + path = "/"; + } else { + StringBuilder buf = new StringBuilder(); + + if (!path.startsWith("/")) { + buf.append("/"); + } + buf.append(path); + if (!path.endsWith("/")) { + buf.append("/"); + } + buf.append(name); + + result = buf.toString(); + } + + return result; + } + + String getNewResourceName() { + return (nameText == null) + ? null + : nameText.getText().trim(); + } + + void setNewResourceName(String newName) { + nameText.setText(newName.trim()); + } + + public URI createNewModelResourceURI() { + return CDOURIUtil.createResourceURI(getView(), + getNewResourcePath(getNewResourceName())); + } + + private String getExtension() { + String result = null; + String name = getNewResourceName(); + + if (name != null) { + // the proper extension is whatever follows the *last* '.', + // but for our purposes we need e.g. "profile.uml" to be + // an extension + int dot = name.indexOf('.'); + if (dot >= 0) { + result = name.substring(dot + 1); + } + } + + return result; + } + + /** + * Diagram extension changed. + * + * @param newExtension + * the new extension + * @return result of validation of the new extension + */ + public IStatus diagramExtensionChanged(String newExtension) { + String currentExtension = getExtension(); + if (!newExtension.equals(currentExtension)) { + + String oldFileName = getNewResourceName(); + String newFileName = suggestName("model", newExtension); + + setNewResourceName(newFileName); + + String message1 = Messages.NewModelFilePage_new_diagram_category_needs_specific_extension; + String message2 = Messages.bind( + Messages.NewModelFilePage_diagram_file_was_renamed, + oldFileName, newFileName); + String message = message1 + message2; + Status resultStatus = new Status(Status.INFO, Activator.PLUGIN_ID, + message); + + String errorMessage = getErrorMessage(); + if (errorMessage != null) { + resultStatus = new Status(Status.ERROR, Activator.PLUGIN_ID, + errorMessage); + } + return resultStatus; + } + return Status.OK_STATUS; + } + + void validatePage() { + setMessage(null, NONE); + setPageComplete(true); + + String name = getNewResourceName(); + if (getView() == null) { + setMessage("No repository is selected.", ERROR); + setPageComplete(false); + } else if (Strings.isNullOrEmpty(name)) { + setMessage("The new model resource name is required.", ERROR); + setPageComplete(false); + } else { + String path = getNewResourcePath(name); + if (getView().hasResource(path)) { + setMessage( + NLS.bind("The resource \"{0}\" already exists.", path), + ERROR); + setPageComplete(false); + } else { + // check existence of folder (if any) + String folderPath = getSelectedFolderPath(); + if (!Strings.isNullOrEmpty(folderPath)) { + if (!getView().hasResource(folderPath)) { + setMessage( + "The specified folder does not exist and will be created.", + WARNING); + } + } + } + } + } +} diff --git a/plugins/cdo/org.eclipse.papyrus.cdo.uml.diagram.ui/src/org/eclipse/papyrus/cdo/uml/diagram/internal/ui/wizards/RepositorySelectionPart.java b/plugins/cdo/org.eclipse.papyrus.cdo.uml.diagram.ui/src/org/eclipse/papyrus/cdo/uml/diagram/internal/ui/wizards/RepositorySelectionPart.java new file mode 100644 index 00000000000..beaee4e54cc --- /dev/null +++ b/plugins/cdo/org.eclipse.papyrus.cdo.uml.diagram.ui/src/org/eclipse/papyrus/cdo/uml/diagram/internal/ui/wizards/RepositorySelectionPart.java @@ -0,0 +1,80 @@ +/***************************************************************************** + * Copyright (c) 2013 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.cdo.uml.diagram.internal.ui.wizards; + +import org.eclipse.jface.operation.IRunnableContext; +import org.eclipse.papyrus.cdo.core.IPapyrusRepository; +import org.eclipse.papyrus.cdo.core.IPapyrusRepositoryManager; +import org.eclipse.papyrus.cdo.internal.ui.wizards.RepositorySelectionBlock; +import org.eclipse.papyrus.uml.diagram.wizards.AbstractSelectStorageProviderPart; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Control; + +import com.google.common.base.Supplier; +import com.google.common.eventbus.EventBus; +import com.google.common.eventbus.Subscribe; + +/** + * This is the RepositorySelectionPart type. Enjoy. + */ +public class RepositorySelectionPart + extends AbstractSelectStorageProviderPart { + + private final IPapyrusRepositoryManager repoMan; + + private final Supplier<? extends IRunnableContext> runnableContext; + + private final EventBus bus; + + private RepositorySelectionBlock repoSelectionBlock; + + public RepositorySelectionPart(IPapyrusRepositoryManager repoMan, + EventBus bus, Supplier<? extends IRunnableContext> runnableContext) { + + super(); + + this.repoMan = repoMan; + this.runnableContext = runnableContext; + this.bus = bus; + } + + public Control createControl(Composite parent) { + bus.register(this); + + repoSelectionBlock = new RepositorySelectionBlock(repoMan, bus, + runnableContext); + + return repoSelectionBlock.createControl(parent); + } + + @Override + protected void enableControls(boolean enabled) { + repoSelectionBlock.setEnabled(enabled); + } + + public IPapyrusRepository getSelectedRepository() { + return (repoSelectionBlock == null) + ? null + : repoSelectionBlock.getSelectedRepository(); + } + + @Subscribe + public void setSelectedRepository(IPapyrusRepository repository) { + firePartCompleteChanged(); + } + + public boolean isPartComplete() { + return (getSelectedRepository() != null) + && getSelectedRepository().isConnected(); + } + +} |