Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/org.eclipse.gmf.codegen/templates.migrated/impl/actions/CreateShortcutAction.xpt')
-rw-r--r--plugins/org.eclipse.gmf.codegen/templates.migrated/impl/actions/CreateShortcutAction.xpt98
1 files changed, 98 insertions, 0 deletions
diff --git a/plugins/org.eclipse.gmf.codegen/templates.migrated/impl/actions/CreateShortcutAction.xpt b/plugins/org.eclipse.gmf.codegen/templates.migrated/impl/actions/CreateShortcutAction.xpt
new file mode 100644
index 000000000..3684ac32f
--- /dev/null
+++ b/plugins/org.eclipse.gmf.codegen/templates.migrated/impl/actions/CreateShortcutAction.xpt
@@ -0,0 +1,98 @@
+/*
+ * Copyright (c) 2006, 2008 Borland Software Corporation
+ *
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Alexander Shatalin (Borland) - initial API and implementation
+ * Artem Tikhomirov (Borland) - [174961] migration to Commands/Handlers
+ */
+
+«IMPORT 'http://www.eclipse.org/gmf/2008/GenModel'»
+«EXTENSION xpt::editor::Utils»
+«EXTENSION xpt::StringOperations»
+
+«DEFINE Main FOR gmfgen::CreateShortcutAction-»
+«EXPAND xpt::Common::copyright FOR owner.editorGen-»
+«EXPAND xpt::Common::packageStatement FOR qualifiedClassName»
+
+«EXPAND xpt::Common::generatedClassComment»
+public class «qualifiedClassName.xpandSplit('\.')->last()»«EXPAND extendsList»«EXPAND implementsList» {
+«EXPAND executeMethod»
+«EXPAND additions-»
+}
+«ENDDEFINE»
+
+«DEFINE extendsList FOR gmfgen::CreateShortcutAction» extends org.eclipse.core.commands.AbstractHandler«ENDDEFINE»
+«DEFINE implementsList FOR gmfgen::CreateShortcutAction»«ENDDEFINE»
+
+«DEFINE executeMethod FOR gmfgen::CreateShortcutAction-»
+ «EXPAND xpt::Common::generatedMemberComment»
+ public Object execute(org.eclipse.core.commands.ExecutionEvent event) throws org.eclipse.core.commands.ExecutionException {
+ org.eclipse.ui.IEditorPart diagramEditor = org.eclipse.ui.handlers.HandlerUtil.getActiveEditorChecked(event);
+ org.eclipse.swt.widgets.Shell shell = diagramEditor.getEditorSite().getShell();
+ «EXPAND xpt::Common::_assert('diagramEditor instanceof org.eclipse.gmf.runtime.diagram.ui.parts.DiagramEditor')-»
+ org.eclipse.emf.transaction.TransactionalEditingDomain editingDomain = ((org.eclipse.gmf.runtime.diagram.ui.parts.DiagramEditor) diagramEditor).getEditingDomain();
+ org.eclipse.jface.viewers.ISelection selection = org.eclipse.ui.handlers.HandlerUtil.getCurrentSelectionChecked(event);
+ «EXPAND xpt::Common::_assert('selection instanceof org.eclipse.jface.viewers.IStructuredSelection')-»
+ «EXPAND xpt::Common::_assert('((org.eclipse.jface.viewers.IStructuredSelection) selection).size() == 1')-»
+ «EXPAND xpt::Common::_assert('((org.eclipse.jface.viewers.IStructuredSelection) selection).getFirstElement() instanceof org.eclipse.gef.EditPart')-»
+ org.eclipse.gef.EditPart selectedDiagramPart = (org.eclipse.gef.EditPart) ((org.eclipse.jface.viewers.IStructuredSelection) selection).getFirstElement();
+ final org.eclipse.gmf.runtime.notation.View view = (org.eclipse.gmf.runtime.notation.View) selectedDiagramPart.getModel();
+«IF null = owner.editorGen.application-»
+ «owner.editorGen.diagram.getElementChooserQualifiedClassName()» elementChooser = new «owner.editorGen.diagram.getElementChooserQualifiedClassName()»(shell, view);
+ int result = elementChooser.open();
+ if (result != org.eclipse.jface.window.Window.OK) {
+ return null;
+ }
+ org.eclipse.emf.common.util.URI selectedModelElementURI = elementChooser.getSelectedModelElementURI();
+ final org.eclipse.emf.ecore.EObject selectedElement;
+ try {
+ selectedElement = editingDomain.getResourceSet().getEObject(selectedModelElementURI, true);
+ } catch (org.eclipse.emf.common.util.WrappedException e) {
+ «owner.editorGen.plugin.getActivatorQualifiedClassName()».getInstance().logError("Exception while loading object: " + selectedModelElementURI.toString(), e);«EXPAND xpt::Common::nonNLS»
+ return null;
+ }
+
+ if (selectedElement == null) {
+ return null;
+ }
+ org.eclipse.gmf.runtime.diagram.ui.requests.CreateViewRequest.ViewDescriptor viewDescriptor = new org.eclipse.gmf.runtime.diagram.ui.requests.CreateViewRequest.ViewDescriptor(new org.eclipse.gmf.runtime.emf.core.util.EObjectAdapter(selectedElement), org.eclipse.gmf.runtime.notation.Node.class, null, «EXPAND xpt::plugin::Activator::preferenceHintAccess FOR owner.editorGen»);
+ org.eclipse.gmf.runtime.common.core.command.ICommand command = new org.eclipse.gmf.runtime.diagram.ui.commands.CreateCommand(editingDomain, viewDescriptor, view);
+ command = command.compose(new «owner.editorGen.diagram.getCreateShortcutDecorationsCommandQualifiedClassName()»(editingDomain, view, viewDescriptor));
+ try {
+ org.eclipse.core.commands.operations.OperationHistoryFactory.getOperationHistory().execute(command, new org.eclipse.core.runtime.NullProgressMonitor(), null);
+ } catch (org.eclipse.core.commands.ExecutionException e) {
+ «owner.editorGen.plugin.getActivatorQualifiedClassName()».getInstance().logError("Unable to create shortcut", e);«EXPAND xpt::Common::nonNLS»
+ }
+«ELSE-»
+ org.eclipse.emf.ecore.resource.Resource resource = «owner.editorGen.diagram.getDiagramEditorUtilQualifiedClassName()».openModel(shell, «EXPAND xpt::Externalizer::accessorCall(titleKey(i18nKeyForCreateShortcutOpenModel())) FOR owner.editorGen», editingDomain);
+ if (resource == null || resource.getContents().isEmpty()) {
+ return null;
+ }
+ «EXPAND xpt::editor::ShortcutCreationWizard::qualifiedClassName FOR owner.editorGen.diagram» wizard = new «EXPAND xpt::editor::ShortcutCreationWizard::qualifiedClassName FOR owner.editorGen.diagram»((org.eclipse.emf.ecore.EObject) resource.getContents().get(0), view, editingDomain);
+ wizard.setWindowTitle(«EXPAND xpt::Externalizer::accessorCall(titleKey(i18nKeyForCreateShortcutWizard())) FOR owner.editorGen»);
+ «owner.editorGen.diagram.getDiagramEditorUtilQualifiedClassName()».runWizard(myShell, wizard, "CreateShortcut");«EXPAND xpt::Common::nonNLS»
+«ENDIF-»
+ return null;
+ }
+«ENDDEFINE»
+
+«DEFINE additions FOR gmfgen::CreateShortcutAction»«ENDDEFINE»
+
+«DEFINE i18nValues FOR gmfgen::GenDiagram-»
+«IF null <> editorGen.application-»
+«EXPAND xpt::Externalizer::messageEntry(titleKey(i18nKeyForCreateShortcutOpenModel()), 'Select model to reference')-»
+«EXPAND xpt::Externalizer::messageEntry(titleKey(i18nKeyForCreateShortcutWizard()), 'Create shortcut')-»
+«ENDIF-»
+«ENDDEFINE»
+
+«DEFINE i18nAccessors FOR gmfgen::GenDiagram-»
+«IF null <> editorGen.application-»
+«EXPAND xpt::Externalizer::accessorField(titleKey(i18nKeyForCreateShortcutOpenModel()))-»
+«EXPAND xpt::Externalizer::accessorField(titleKey(i18nKeyForCreateShortcutWizard()))-»
+«ENDIF-»
+«ENDDEFINE» \ No newline at end of file

Back to the top