carbidecpp22devenv/plugins/org.eclipse.gmf.templates.legacy_1.0.0.v20090614-0839/codegen.templates/xpt/editor/DiagramEditorUtil.xpt
author cawthron
Fri, 04 Dec 2009 11:06:59 -0600
changeset 422 033392511bf7
permissions -rw-r--r--
add files for RCL_2_2
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
422
033392511bf7 add files for RCL_2_2
cawthron
parents:
diff changeset
     1
/*
033392511bf7 add files for RCL_2_2
cawthron
parents:
diff changeset
     2
 * Copyright (c) 2007, 2008 Borland Software Corporation
033392511bf7 add files for RCL_2_2
cawthron
parents:
diff changeset
     3
 * 
033392511bf7 add files for RCL_2_2
cawthron
parents:
diff changeset
     4
 * All rights reserved. This program and the accompanying materials
033392511bf7 add files for RCL_2_2
cawthron
parents:
diff changeset
     5
 * are made available under the terms of the Eclipse Public License v1.0
033392511bf7 add files for RCL_2_2
cawthron
parents:
diff changeset
     6
 * which accompanies this distribution, and is available at
033392511bf7 add files for RCL_2_2
cawthron
parents:
diff changeset
     7
 * http://www.eclipse.org/legal/epl-v10.html
033392511bf7 add files for RCL_2_2
cawthron
parents:
diff changeset
     8
 *
033392511bf7 add files for RCL_2_2
cawthron
parents:
diff changeset
     9
 * Contributors:
033392511bf7 add files for RCL_2_2
cawthron
parents:
diff changeset
    10
 *    Artem Tikhomirov (Borland) - initial API and implementation
033392511bf7 add files for RCL_2_2
cawthron
parents:
diff changeset
    11
 */
033392511bf7 add files for RCL_2_2
cawthron
parents:
diff changeset
    12
«IMPORT "http://www.eclipse.org/gmf/2008/GenModel"»
033392511bf7 add files for RCL_2_2
cawthron
parents:
diff changeset
    13
«IMPORT "http://www.eclipse.org/emf/2002/GenModel"»
033392511bf7 add files for RCL_2_2
cawthron
parents:
diff changeset
    14
«IMPORT "http://www.eclipse.org/emf/2002/Ecore"»
033392511bf7 add files for RCL_2_2
cawthron
parents:
diff changeset
    15
«EXTENSION xpt::editor::GenDiagram»
033392511bf7 add files for RCL_2_2
cawthron
parents:
diff changeset
    16
«EXTENSION xpt::GenModelUtils»
033392511bf7 add files for RCL_2_2
cawthron
parents:
diff changeset
    17
«EXTENSION xpt::editor::Utils»
033392511bf7 add files for RCL_2_2
cawthron
parents:
diff changeset
    18
033392511bf7 add files for RCL_2_2
cawthron
parents:
diff changeset
    19
«DEFINE DiagramEditorUtil FOR gmfgen::GenDiagram-»
033392511bf7 add files for RCL_2_2
cawthron
parents:
diff changeset
    20
	«EXPAND xpt::Common::copyright FOR editorGen-»
033392511bf7 add files for RCL_2_2
cawthron
parents:
diff changeset
    21
package «editorGen.editor.packageName»;
033392511bf7 add files for RCL_2_2
cawthron
parents:
diff changeset
    22
033392511bf7 add files for RCL_2_2
cawthron
parents:
diff changeset
    23
«EXPAND xpt::Common::generatedClassComment»
033392511bf7 add files for RCL_2_2
cawthron
parents:
diff changeset
    24
public class «diagramEditorUtilClassName» {
033392511bf7 add files for RCL_2_2
cawthron
parents:
diff changeset
    25
033392511bf7 add files for RCL_2_2
cawthron
parents:
diff changeset
    26
«EXPAND saveOptions-»
033392511bf7 add files for RCL_2_2
cawthron
parents:
diff changeset
    27
033392511bf7 add files for RCL_2_2
cawthron
parents:
diff changeset
    28
«EXPAND openDiagramMethod-»
033392511bf7 add files for RCL_2_2
cawthron
parents:
diff changeset
    29
«IF editorGen.application == null-»
033392511bf7 add files for RCL_2_2
cawthron
parents:
diff changeset
    30
033392511bf7 add files for RCL_2_2
cawthron
parents:
diff changeset
    31
	«EXPAND setCharsetMethods-»
033392511bf7 add files for RCL_2_2
cawthron
parents:
diff changeset
    32
«ENDIF-»
033392511bf7 add files for RCL_2_2
cawthron
parents:
diff changeset
    33
033392511bf7 add files for RCL_2_2
cawthron
parents:
diff changeset
    34
«EXPAND getUniqueFileNameMethod-»
033392511bf7 add files for RCL_2_2
cawthron
parents:
diff changeset
    35
033392511bf7 add files for RCL_2_2
cawthron
parents:
diff changeset
    36
«IF editorGen.application != null»
033392511bf7 add files for RCL_2_2
cawthron
parents:
diff changeset
    37
	/**
033392511bf7 add files for RCL_2_2
cawthron
parents:
diff changeset
    38
	 * Allows user to select file and loads it as a model.
033392511bf7 add files for RCL_2_2
cawthron
parents:
diff changeset
    39
	 * 
033392511bf7 add files for RCL_2_2
cawthron
parents:
diff changeset
    40
	 * @generated
033392511bf7 add files for RCL_2_2
cawthron
parents:
diff changeset
    41
	 */
033392511bf7 add files for RCL_2_2
cawthron
parents:
diff changeset
    42
	public static org.eclipse.emf.ecore.resource.Resource openModel(
033392511bf7 add files for RCL_2_2
cawthron
parents:
diff changeset
    43
			org.eclipse.swt.widgets.Shell shell, String description, org.eclipse.emf.transaction.TransactionalEditingDomain editingDomain) {
033392511bf7 add files for RCL_2_2
cawthron
parents:
diff changeset
    44
		org.eclipse.swt.widgets.FileDialog fileDialog = new org.eclipse.swt.widgets.FileDialog(shell, org.eclipse.swt.SWT.OPEN);
033392511bf7 add files for RCL_2_2
cawthron
parents:
diff changeset
    45
		if (description != null) {
033392511bf7 add files for RCL_2_2
cawthron
parents:
diff changeset
    46
			fileDialog.setText(description);
033392511bf7 add files for RCL_2_2
cawthron
parents:
diff changeset
    47
		}
033392511bf7 add files for RCL_2_2
cawthron
parents:
diff changeset
    48
		fileDialog.open();
033392511bf7 add files for RCL_2_2
cawthron
parents:
diff changeset
    49
		String fileName = fileDialog.getFileName();
033392511bf7 add files for RCL_2_2
cawthron
parents:
diff changeset
    50
		if (fileName == null || fileName.length() == 0) {
033392511bf7 add files for RCL_2_2
cawthron
parents:
diff changeset
    51
			return null;
033392511bf7 add files for RCL_2_2
cawthron
parents:
diff changeset
    52
		}
033392511bf7 add files for RCL_2_2
cawthron
parents:
diff changeset
    53
		if (fileDialog.getFilterPath() != null) {
033392511bf7 add files for RCL_2_2
cawthron
parents:
diff changeset
    54
			fileName = fileDialog.getFilterPath() + java.io.File.separator + fileName;
033392511bf7 add files for RCL_2_2
cawthron
parents:
diff changeset
    55
		}
033392511bf7 add files for RCL_2_2
cawthron
parents:
diff changeset
    56
		org.eclipse.emf.common.util.URI uri = org.eclipse.emf.common.util.URI.createFileURI(fileName);
033392511bf7 add files for RCL_2_2
cawthron
parents:
diff changeset
    57
		org.eclipse.emf.ecore.resource.Resource resource = null;
033392511bf7 add files for RCL_2_2
cawthron
parents:
diff changeset
    58
		try {
033392511bf7 add files for RCL_2_2
cawthron
parents:
diff changeset
    59
			resource = editingDomain.getResourceSet().getResource(uri, true);
033392511bf7 add files for RCL_2_2
cawthron
parents:
diff changeset
    60
		} catch (org.eclipse.emf.common.util.WrappedException we) {
033392511bf7 add files for RCL_2_2
cawthron
parents:
diff changeset
    61
			«editorGen.plugin.getActivatorQualifiedClassName()».getInstance().logError("Unable to load resource: " + uri, we); «EXPAND xpt::Common::nonNLS»
033392511bf7 add files for RCL_2_2
cawthron
parents:
diff changeset
    62
			org.eclipse.jface.dialogs.MessageDialog.openError(shell, 
033392511bf7 add files for RCL_2_2
cawthron
parents:
diff changeset
    63
                «EXPAND xpt::Externalizer::accessorCall(i18nKeyForOpenModelResourceErrorDialog().titleKey()) FOR editorGen»,
033392511bf7 add files for RCL_2_2
cawthron
parents:
diff changeset
    64
				org.eclipse.osgi.util.NLS.bind(
033392511bf7 add files for RCL_2_2
cawthron
parents:
diff changeset
    65
				    «EXPAND xpt::Externalizer::accessorCall(i18nKeyForOpenModelResourceErrorDialog().messageKey()) FOR editorGen»,
033392511bf7 add files for RCL_2_2
cawthron
parents:
diff changeset
    66
				    fileName));
033392511bf7 add files for RCL_2_2
cawthron
parents:
diff changeset
    67
		}
033392511bf7 add files for RCL_2_2
cawthron
parents:
diff changeset
    68
		return resource;
033392511bf7 add files for RCL_2_2
cawthron
parents:
diff changeset
    69
	}
033392511bf7 add files for RCL_2_2
cawthron
parents:
diff changeset
    70
«ENDIF»
033392511bf7 add files for RCL_2_2
cawthron
parents:
diff changeset
    71
033392511bf7 add files for RCL_2_2
cawthron
parents:
diff changeset
    72
	/**
033392511bf7 add files for RCL_2_2
cawthron
parents:
diff changeset
    73
	 * Runs the wizard in a dialog.
033392511bf7 add files for RCL_2_2
cawthron
parents:
diff changeset
    74
	 * 
033392511bf7 add files for RCL_2_2
cawthron
parents:
diff changeset
    75
	 * @generated
033392511bf7 add files for RCL_2_2
cawthron
parents:
diff changeset
    76
	 */
033392511bf7 add files for RCL_2_2
cawthron
parents:
diff changeset
    77
	public static void runWizard(org.eclipse.swt.widgets.Shell shell, org.eclipse.jface.wizard.Wizard wizard, String settingsKey) {
033392511bf7 add files for RCL_2_2
cawthron
parents:
diff changeset
    78
		org.eclipse.jface.dialogs.IDialogSettings pluginDialogSettings = «editorGen.plugin.getActivatorQualifiedClassName()».getInstance().getDialogSettings();
033392511bf7 add files for RCL_2_2
cawthron
parents:
diff changeset
    79
		org.eclipse.jface.dialogs.IDialogSettings wizardDialogSettings = pluginDialogSettings.getSection(settingsKey);
033392511bf7 add files for RCL_2_2
cawthron
parents:
diff changeset
    80
		if (wizardDialogSettings == null) {
033392511bf7 add files for RCL_2_2
cawthron
parents:
diff changeset
    81
			wizardDialogSettings = pluginDialogSettings.addNewSection(settingsKey);
033392511bf7 add files for RCL_2_2
cawthron
parents:
diff changeset
    82
		}
033392511bf7 add files for RCL_2_2
cawthron
parents:
diff changeset
    83
		wizard.setDialogSettings(wizardDialogSettings);
033392511bf7 add files for RCL_2_2
cawthron
parents:
diff changeset
    84
		org.eclipse.jface.wizard.WizardDialog dialog = new org.eclipse.jface.wizard.WizardDialog(shell, wizard);
033392511bf7 add files for RCL_2_2
cawthron
parents:
diff changeset
    85
		dialog.create();
033392511bf7 add files for RCL_2_2
cawthron
parents:
diff changeset
    86
		dialog.getShell().setSize(Math.max(500, dialog.getShell().getSize().x), 500);
033392511bf7 add files for RCL_2_2
cawthron
parents:
diff changeset
    87
		dialog.open();
033392511bf7 add files for RCL_2_2
cawthron
parents:
diff changeset
    88
	}
033392511bf7 add files for RCL_2_2
cawthron
parents:
diff changeset
    89
033392511bf7 add files for RCL_2_2
cawthron
parents:
diff changeset
    90
«EXPAND createDiagramMethod-»
033392511bf7 add files for RCL_2_2
cawthron
parents:
diff changeset
    91
«IF domainDiagramElement != null»
033392511bf7 add files for RCL_2_2
cawthron
parents:
diff changeset
    92
	«EXPAND createInitialModelMethod»
033392511bf7 add files for RCL_2_2
cawthron
parents:
diff changeset
    93
	«EXPAND attachModelMethod»
033392511bf7 add files for RCL_2_2
cawthron
parents:
diff changeset
    94
	«IF hasDocumentRoot()»«EXPAND createDocumentRootMethod»«ENDIF»
033392511bf7 add files for RCL_2_2
cawthron
parents:
diff changeset
    95
«ENDIF»
033392511bf7 add files for RCL_2_2
cawthron
parents:
diff changeset
    96
033392511bf7 add files for RCL_2_2
cawthron
parents:
diff changeset
    97
«EXPAND selectElementsMethod»
033392511bf7 add files for RCL_2_2
cawthron
parents:
diff changeset
    98
«EXPAND findElementsMethod»
033392511bf7 add files for RCL_2_2
cawthron
parents:
diff changeset
    99
«EXPAND findViewMethod»
033392511bf7 add files for RCL_2_2
cawthron
parents:
diff changeset
   100
033392511bf7 add files for RCL_2_2
cawthron
parents:
diff changeset
   101
«EXPAND additions»
033392511bf7 add files for RCL_2_2
cawthron
parents:
diff changeset
   102
}
033392511bf7 add files for RCL_2_2
cawthron
parents:
diff changeset
   103
«ENDDEFINE»
033392511bf7 add files for RCL_2_2
cawthron
parents:
diff changeset
   104
033392511bf7 add files for RCL_2_2
cawthron
parents:
diff changeset
   105
«DEFINE additions FOR gmfgen::GenDiagram»«ENDDEFINE»
033392511bf7 add files for RCL_2_2
cawthron
parents:
diff changeset
   106
033392511bf7 add files for RCL_2_2
cawthron
parents:
diff changeset
   107
«DEFINE saveOptions FOR gmfgen::GenDiagram-»
033392511bf7 add files for RCL_2_2
cawthron
parents:
diff changeset
   108
	«EXPAND xpt::Common::generatedMemberComment»
033392511bf7 add files for RCL_2_2
cawthron
parents:
diff changeset
   109
	public static java.util.Map getSaveOptions() {
033392511bf7 add files for RCL_2_2
cawthron
parents:
diff changeset
   110
		java.util.Map saveOptions = new java.util.HashMap();
033392511bf7 add files for RCL_2_2
cawthron
parents:
diff changeset
   111
		saveOptions.put(org.eclipse.emf.ecore.xmi.XMLResource.OPTION_ENCODING, "UTF-8"); «EXPAND xpt::Common::nonNLS»
033392511bf7 add files for RCL_2_2
cawthron
parents:
diff changeset
   112
		saveOptions.put(org.eclipse.emf.ecore.resource.Resource.OPTION_SAVE_ONLY_IF_CHANGED, org.eclipse.emf.ecore.resource.Resource.OPTION_SAVE_ONLY_IF_CHANGED_MEMORY_BUFFER);
033392511bf7 add files for RCL_2_2
cawthron
parents:
diff changeset
   113
		return saveOptions;
033392511bf7 add files for RCL_2_2
cawthron
parents:
diff changeset
   114
	}
033392511bf7 add files for RCL_2_2
cawthron
parents:
diff changeset
   115
«ENDDEFINE»
033392511bf7 add files for RCL_2_2
cawthron
parents:
diff changeset
   116
033392511bf7 add files for RCL_2_2
cawthron
parents:
diff changeset
   117
«DEFINE openDiagramMethod FOR gmfgen::GenDiagram-»
033392511bf7 add files for RCL_2_2
cawthron
parents:
diff changeset
   118
	«EXPAND xpt::Common::generatedMemberComment»
033392511bf7 add files for RCL_2_2
cawthron
parents:
diff changeset
   119
	public static boolean openDiagram(org.eclipse.emf.ecore.resource.Resource diagram) throws org.eclipse.ui.PartInitException {
033392511bf7 add files for RCL_2_2
cawthron
parents:
diff changeset
   120
«IF editorGen.application == null-»
033392511bf7 add files for RCL_2_2
cawthron
parents:
diff changeset
   121
		String path = diagram.getURI().toPlatformString(true);
033392511bf7 add files for RCL_2_2
cawthron
parents:
diff changeset
   122
		org.eclipse.core.resources.IResource workspaceResource = org.eclipse.core.resources.ResourcesPlugin.getWorkspace().getRoot().findMember(new org.eclipse.core.runtime.Path(path));
033392511bf7 add files for RCL_2_2
cawthron
parents:
diff changeset
   123
		if (workspaceResource instanceof org.eclipse.core.resources.IFile) {
033392511bf7 add files for RCL_2_2
cawthron
parents:
diff changeset
   124
			org.eclipse.ui.IWorkbenchPage page = org.eclipse.ui.PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
033392511bf7 add files for RCL_2_2
cawthron
parents:
diff changeset
   125
			return null != page.openEditor(new org.eclipse.ui.part.FileEditorInput((org.eclipse.core.resources.IFile) workspaceResource), «editorGen.editor.getQualifiedClassName()».ID);
033392511bf7 add files for RCL_2_2
cawthron
parents:
diff changeset
   126
		}
033392511bf7 add files for RCL_2_2
cawthron
parents:
diff changeset
   127
		return false;
033392511bf7 add files for RCL_2_2
cawthron
parents:
diff changeset
   128
«ELSE-»
033392511bf7 add files for RCL_2_2
cawthron
parents:
diff changeset
   129
		org.eclipse.ui.IWorkbenchPage page = org.eclipse.ui.PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
033392511bf7 add files for RCL_2_2
cawthron
parents:
diff changeset
   130
		page.openEditor(new org.eclipse.emf.common.ui.URIEditorInput(diagram.getURI()), «editorGen.editor.getQualifiedClassName()».ID);
033392511bf7 add files for RCL_2_2
cawthron
parents:
diff changeset
   131
		return true;
033392511bf7 add files for RCL_2_2
cawthron
parents:
diff changeset
   132
«ENDIF-»
033392511bf7 add files for RCL_2_2
cawthron
parents:
diff changeset
   133
	}
033392511bf7 add files for RCL_2_2
cawthron
parents:
diff changeset
   134
«ENDDEFINE»
033392511bf7 add files for RCL_2_2
cawthron
parents:
diff changeset
   135
033392511bf7 add files for RCL_2_2
cawthron
parents:
diff changeset
   136
«DEFINE setCharsetMethods FOR gmfgen::GenDiagram-»
033392511bf7 add files for RCL_2_2
cawthron
parents:
diff changeset
   137
	«EXPAND xpt::Common::generatedMemberComment»
033392511bf7 add files for RCL_2_2
cawthron
parents:
diff changeset
   138
	public static void setCharset(org.eclipse.core.resources.IFile file) {
033392511bf7 add files for RCL_2_2
cawthron
parents:
diff changeset
   139
		if (file == null) {
033392511bf7 add files for RCL_2_2
cawthron
parents:
diff changeset
   140
			return;
033392511bf7 add files for RCL_2_2
cawthron
parents:
diff changeset
   141
		}
033392511bf7 add files for RCL_2_2
cawthron
parents:
diff changeset
   142
		try {
033392511bf7 add files for RCL_2_2
cawthron
parents:
diff changeset
   143
			file.setCharset("UTF-8", new org.eclipse.core.runtime.NullProgressMonitor()); «EXPAND xpt::Common::nonNLS»
033392511bf7 add files for RCL_2_2
cawthron
parents:
diff changeset
   144
		} catch (org.eclipse.core.runtime.CoreException e) {
033392511bf7 add files for RCL_2_2
cawthron
parents:
diff changeset
   145
			«editorGen.plugin.getActivatorQualifiedClassName()».getInstance().logError("Unable to set charset for file " + file.getFullPath(), e); «EXPAND xpt::Common::nonNLS»
033392511bf7 add files for RCL_2_2
cawthron
parents:
diff changeset
   146
		}
033392511bf7 add files for RCL_2_2
cawthron
parents:
diff changeset
   147
	}	
033392511bf7 add files for RCL_2_2
cawthron
parents:
diff changeset
   148
«ENDDEFINE»
033392511bf7 add files for RCL_2_2
cawthron
parents:
diff changeset
   149
033392511bf7 add files for RCL_2_2
cawthron
parents:
diff changeset
   150
«DEFINE getUniqueFileNameMethod FOR gmfgen::GenDiagram-»
033392511bf7 add files for RCL_2_2
cawthron
parents:
diff changeset
   151
	«EXPAND xpt::Common::generatedMemberComment»
033392511bf7 add files for RCL_2_2
cawthron
parents:
diff changeset
   152
	public static String getUniqueFileName(org.eclipse.core.runtime.IPath containerFullPath, String fileName, String extension) {
033392511bf7 add files for RCL_2_2
cawthron
parents:
diff changeset
   153
		if (containerFullPath == null) {
033392511bf7 add files for RCL_2_2
cawthron
parents:
diff changeset
   154
			containerFullPath = new org.eclipse.core.runtime.Path(""); «EXPAND xpt::Common::nonNLS»
033392511bf7 add files for RCL_2_2
cawthron
parents:
diff changeset
   155
		}
033392511bf7 add files for RCL_2_2
cawthron
parents:
diff changeset
   156
		if (fileName == null || fileName.trim().length() == 0) {
033392511bf7 add files for RCL_2_2
cawthron
parents:
diff changeset
   157
			fileName = "default"; «EXPAND xpt::Common::nonNLS»
033392511bf7 add files for RCL_2_2
cawthron
parents:
diff changeset
   158
		}
033392511bf7 add files for RCL_2_2
cawthron
parents:
diff changeset
   159
		org.eclipse.core.runtime.IPath filePath = containerFullPath.append(fileName);
033392511bf7 add files for RCL_2_2
cawthron
parents:
diff changeset
   160
		if (extension != null && !extension.equals(filePath.getFileExtension())) {
033392511bf7 add files for RCL_2_2
cawthron
parents:
diff changeset
   161
			filePath = filePath.addFileExtension(extension);
033392511bf7 add files for RCL_2_2
cawthron
parents:
diff changeset
   162
		}
033392511bf7 add files for RCL_2_2
cawthron
parents:
diff changeset
   163
		extension = filePath.getFileExtension();
033392511bf7 add files for RCL_2_2
cawthron
parents:
diff changeset
   164
		fileName = filePath.removeFileExtension().lastSegment();
033392511bf7 add files for RCL_2_2
cawthron
parents:
diff changeset
   165
		int i = 1;
033392511bf7 add files for RCL_2_2
cawthron
parents:
diff changeset
   166
		while (
033392511bf7 add files for RCL_2_2
cawthron
parents:
diff changeset
   167
		«IF editorGen.application == null-»
033392511bf7 add files for RCL_2_2
cawthron
parents:
diff changeset
   168
			org.eclipse.core.resources.ResourcesPlugin.getWorkspace().getRoot().exists(filePath)
033392511bf7 add files for RCL_2_2
cawthron
parents:
diff changeset
   169
		«ELSE-»
033392511bf7 add files for RCL_2_2
cawthron
parents:
diff changeset
   170
			filePath.toFile().exists()
033392511bf7 add files for RCL_2_2
cawthron
parents:
diff changeset
   171
		«ENDIF-»
033392511bf7 add files for RCL_2_2
cawthron
parents:
diff changeset
   172
		) {
033392511bf7 add files for RCL_2_2
cawthron
parents:
diff changeset
   173
			i++;
033392511bf7 add files for RCL_2_2
cawthron
parents:
diff changeset
   174
			filePath = containerFullPath.append(fileName + i);
033392511bf7 add files for RCL_2_2
cawthron
parents:
diff changeset
   175
			if (extension != null) {
033392511bf7 add files for RCL_2_2
cawthron
parents:
diff changeset
   176
				filePath = filePath.addFileExtension(extension);
033392511bf7 add files for RCL_2_2
cawthron
parents:
diff changeset
   177
			}
033392511bf7 add files for RCL_2_2
cawthron
parents:
diff changeset
   178
		}
033392511bf7 add files for RCL_2_2
cawthron
parents:
diff changeset
   179
		return filePath.lastSegment();
033392511bf7 add files for RCL_2_2
cawthron
parents:
diff changeset
   180
	}
033392511bf7 add files for RCL_2_2
cawthron
parents:
diff changeset
   181
«ENDDEFINE»
033392511bf7 add files for RCL_2_2
cawthron
parents:
diff changeset
   182
033392511bf7 add files for RCL_2_2
cawthron
parents:
diff changeset
   183
«DEFINE createDiagramMethod FOR gmfgen::GenDiagram-»
033392511bf7 add files for RCL_2_2
cawthron
parents:
diff changeset
   184
	«EXPAND xpt::Common::generatedMemberComment(editorGen.application == null ? "This method should be called within a workspace modify operation since it creates resources." : "")»
033392511bf7 add files for RCL_2_2
cawthron
parents:
diff changeset
   185
	public static org.eclipse.emf.ecore.resource.Resource createDiagram(org.eclipse.emf.common.util.URI diagramURI,«IF standaloneDomainModel()» org.eclipse.emf.common.util.URI modelURI,«ENDIF» org.eclipse.core.runtime.IProgressMonitor progressMonitor) {
033392511bf7 add files for RCL_2_2
cawthron
parents:
diff changeset
   186
		org.eclipse.emf.transaction.TransactionalEditingDomain editingDomain = org.eclipse.gmf.runtime.emf.core.GMFEditingDomainFactory.INSTANCE.createEditingDomain();
033392511bf7 add files for RCL_2_2
cawthron
parents:
diff changeset
   187
		progressMonitor.beginTask(«EXPAND xpt::Externalizer::accessorCall(i18nKeyForCreateDiagramProgressTask()) FOR editorGen», 3);
033392511bf7 add files for RCL_2_2
cawthron
parents:
diff changeset
   188
		final org.eclipse.emf.ecore.resource.Resource diagramResource = editingDomain.getResourceSet().createResource(diagramURI);
033392511bf7 add files for RCL_2_2
cawthron
parents:
diff changeset
   189
«IF standaloneDomainModel()-»
033392511bf7 add files for RCL_2_2
cawthron
parents:
diff changeset
   190
		final org.eclipse.emf.ecore.resource.Resource modelResource = editingDomain.getResourceSet().createResource(modelURI);
033392511bf7 add files for RCL_2_2
cawthron
parents:
diff changeset
   191
«ELSEIF domainDiagramElement != null && hasDocumentRoot() /*for standalone models, we assume its resourcefactory would be able to set extendedMetaData option*/-»
033392511bf7 add files for RCL_2_2
cawthron
parents:
diff changeset
   192
		((org.eclipse.emf.ecore.xmi.XMLResource) diagramResource).getDefaultSaveOptions().put(org.eclipse.emf.ecore.xmi.XMLResource.OPTION_EXTENDED_META_DATA, Boolean.TRUE);
033392511bf7 add files for RCL_2_2
cawthron
parents:
diff changeset
   193
		((org.eclipse.emf.ecore.xmi.XMLResource) diagramResource).getDefaultLoadOptions().put(org.eclipse.emf.ecore.xmi.XMLResource.OPTION_EXTENDED_META_DATA, Boolean.TRUE);
033392511bf7 add files for RCL_2_2
cawthron
parents:
diff changeset
   194
«ENDIF-»
033392511bf7 add files for RCL_2_2
cawthron
parents:
diff changeset
   195
		final String diagramName = diagramURI.lastSegment();
033392511bf7 add files for RCL_2_2
cawthron
parents:
diff changeset
   196
		org.eclipse.gmf.runtime.emf.commands.core.command.AbstractTransactionalCommand command = new org.eclipse.gmf.runtime.emf.commands.core.command.AbstractTransactionalCommand(editingDomain, «EXPAND xpt::Externalizer::accessorCall(i18nKeyForCreateDiagramCommandLabel()) FOR editorGen», java.util.Collections.EMPTY_LIST) {
033392511bf7 add files for RCL_2_2
cawthron
parents:
diff changeset
   197
			protected org.eclipse.gmf.runtime.common.core.command.CommandResult doExecuteWithResult(org.eclipse.core.runtime.IProgressMonitor monitor, org.eclipse.core.runtime.IAdaptable info) throws org.eclipse.core.commands.ExecutionException {
033392511bf7 add files for RCL_2_2
cawthron
parents:
diff changeset
   198
«IF domainDiagramElement != null-»
033392511bf7 add files for RCL_2_2
cawthron
parents:
diff changeset
   199
				«EXPAND MetaModel::QualifiedClassName FOR domainDiagramElement» model = createInitialModel();
033392511bf7 add files for RCL_2_2
cawthron
parents:
diff changeset
   200
				attachModelToResource(model, «IF standaloneDomainModel()»model«ELSE»diagram«ENDIF»Resource);
033392511bf7 add files for RCL_2_2
cawthron
parents:
diff changeset
   201
«ENDIF»
033392511bf7 add files for RCL_2_2
cawthron
parents:
diff changeset
   202
				org.eclipse.gmf.runtime.notation.Diagram diagram = org.eclipse.gmf.runtime.diagram.core.services.ViewService.createDiagram(
033392511bf7 add files for RCL_2_2
cawthron
parents:
diff changeset
   203
«IF domainDiagramElement != null-»
033392511bf7 add files for RCL_2_2
cawthron
parents:
diff changeset
   204
				«IF domainDiagramElement.isExternalInterface()»(org.eclipse.emf.ecore.EObject) «ENDIF»model, 
033392511bf7 add files for RCL_2_2
cawthron
parents:
diff changeset
   205
«ENDIF-»
033392511bf7 add files for RCL_2_2
cawthron
parents:
diff changeset
   206
					«EXPAND xpt::editor::VisualIDRegistry::modelID»,	«editorGen.plugin.getActivatorQualifiedClassName()».DIAGRAM_PREFERENCES_HINT);
033392511bf7 add files for RCL_2_2
cawthron
parents:
diff changeset
   207
				if (diagram != null) {
033392511bf7 add files for RCL_2_2
cawthron
parents:
diff changeset
   208
					diagramResource.getContents().add(diagram);
033392511bf7 add files for RCL_2_2
cawthron
parents:
diff changeset
   209
					diagram.setName(diagramName);
033392511bf7 add files for RCL_2_2
cawthron
parents:
diff changeset
   210
«IF domainDiagramElement != null-»
033392511bf7 add files for RCL_2_2
cawthron
parents:
diff changeset
   211
					diagram.setElement(«IF domainDiagramElement.isExternalInterface()»(org.eclipse.emf.ecore.EObject) «ENDIF»model);
033392511bf7 add files for RCL_2_2
cawthron
parents:
diff changeset
   212
«ENDIF-»
033392511bf7 add files for RCL_2_2
cawthron
parents:
diff changeset
   213
				}
033392511bf7 add files for RCL_2_2
cawthron
parents:
diff changeset
   214
				
033392511bf7 add files for RCL_2_2
cawthron
parents:
diff changeset
   215
				try {
033392511bf7 add files for RCL_2_2
cawthron
parents:
diff changeset
   216
					«IF standaloneDomainModel()»modelResource.save(«EXPAND xpt::Common::getSaveOptions»);«ENDIF»
033392511bf7 add files for RCL_2_2
cawthron
parents:
diff changeset
   217
					diagramResource.save(«EXPAND xpt::Common::getSaveOptions»);
033392511bf7 add files for RCL_2_2
cawthron
parents:
diff changeset
   218
				} catch (java.io.IOException e) {
033392511bf7 add files for RCL_2_2
cawthron
parents:
diff changeset
   219
					«/* TODO CommandResult.newErrorCommandResult(e) would be better? Or even throw ExecutionEx?*/»
033392511bf7 add files for RCL_2_2
cawthron
parents:
diff changeset
   220
					«editorGen.plugin.getActivatorQualifiedClassName()».getInstance().logError("Unable to store model and diagram resources", e); «EXPAND xpt::Common::nonNLS»
033392511bf7 add files for RCL_2_2
cawthron
parents:
diff changeset
   221
				}
033392511bf7 add files for RCL_2_2
cawthron
parents:
diff changeset
   222
				return org.eclipse.gmf.runtime.common.core.command.CommandResult.newOKCommandResult();
033392511bf7 add files for RCL_2_2
cawthron
parents:
diff changeset
   223
			}
033392511bf7 add files for RCL_2_2
cawthron
parents:
diff changeset
   224
		};
033392511bf7 add files for RCL_2_2
cawthron
parents:
diff changeset
   225
		try {
033392511bf7 add files for RCL_2_2
cawthron
parents:
diff changeset
   226
			org.eclipse.core.commands.operations.OperationHistoryFactory.getOperationHistory().execute(command, new org.eclipse.core.runtime.SubProgressMonitor(progressMonitor, 1), null);
033392511bf7 add files for RCL_2_2
cawthron
parents:
diff changeset
   227
		} catch (org.eclipse.core.commands.ExecutionException e) {
033392511bf7 add files for RCL_2_2
cawthron
parents:
diff changeset
   228
			«editorGen.plugin.getActivatorQualifiedClassName()».getInstance().logError("Unable to create model and diagram", e); «EXPAND xpt::Common::nonNLS»
033392511bf7 add files for RCL_2_2
cawthron
parents:
diff changeset
   229
		}
033392511bf7 add files for RCL_2_2
cawthron
parents:
diff changeset
   230
«IF editorGen.application == null-»
033392511bf7 add files for RCL_2_2
cawthron
parents:
diff changeset
   231
		«IF standaloneDomainModel()»setCharset(org.eclipse.emf.workspace.util.WorkspaceSynchronizer.getFile(modelResource));«ENDIF»
033392511bf7 add files for RCL_2_2
cawthron
parents:
diff changeset
   232
		setCharset(org.eclipse.emf.workspace.util.WorkspaceSynchronizer.getFile(diagramResource));
033392511bf7 add files for RCL_2_2
cawthron
parents:
diff changeset
   233
«ENDIF-»
033392511bf7 add files for RCL_2_2
cawthron
parents:
diff changeset
   234
		return diagramResource;
033392511bf7 add files for RCL_2_2
cawthron
parents:
diff changeset
   235
	}
033392511bf7 add files for RCL_2_2
cawthron
parents:
diff changeset
   236
«ENDDEFINE»
033392511bf7 add files for RCL_2_2
cawthron
parents:
diff changeset
   237
033392511bf7 add files for RCL_2_2
cawthron
parents:
diff changeset
   238
«DEFINE createInitialModelMethod FOR gmfgen::GenDiagram»
033392511bf7 add files for RCL_2_2
cawthron
parents:
diff changeset
   239
	«EXPAND xpt::Common::generatedMemberComment("Create a new instance of domain element associated with canvas.\n<!-- begin-user-doc -->\n<!-- end-user-doc -->")»
033392511bf7 add files for RCL_2_2
cawthron
parents:
diff changeset
   240
	private static «EXPAND MetaModel::QualifiedClassName FOR domainDiagramElement» createInitialModel() {
033392511bf7 add files for RCL_2_2
cawthron
parents:
diff changeset
   241
		return «EXPAND MetaModel::NewInstance FOR domainDiagramElement»;
033392511bf7 add files for RCL_2_2
cawthron
parents:
diff changeset
   242
	}
033392511bf7 add files for RCL_2_2
cawthron
parents:
diff changeset
   243
«ENDDEFINE»
033392511bf7 add files for RCL_2_2
cawthron
parents:
diff changeset
   244
033392511bf7 add files for RCL_2_2
cawthron
parents:
diff changeset
   245
«DEFINE attachModelMethod FOR gmfgen::GenDiagram»
033392511bf7 add files for RCL_2_2
cawthron
parents:
diff changeset
   246
	«EXPAND xpt::Common::generatedMemberComment("Store model element in the resource.\n<!-- begin-user-doc -->\n<!-- end-user-doc -->")»
033392511bf7 add files for RCL_2_2
cawthron
parents:
diff changeset
   247
	private static void attachModelToResource(«EXPAND MetaModel::QualifiedClassName FOR domainDiagramElement» model, org.eclipse.emf.ecore.resource.Resource resource) {
033392511bf7 add files for RCL_2_2
cawthron
parents:
diff changeset
   248
		resource.getContents().add(«IF hasDocumentRoot()»createDocumentRoot(model)«ELSE»«IF domainDiagramElement.isExternalInterface()»(org.eclipse.emf.ecore.EObject) «ENDIF»model«ENDIF»);
033392511bf7 add files for RCL_2_2
cawthron
parents:
diff changeset
   249
	}
033392511bf7 add files for RCL_2_2
cawthron
parents:
diff changeset
   250
«ENDDEFINE»
033392511bf7 add files for RCL_2_2
cawthron
parents:
diff changeset
   251
033392511bf7 add files for RCL_2_2
cawthron
parents:
diff changeset
   252
// invoke only when there's DocumentRoot in the domain model
033392511bf7 add files for RCL_2_2
cawthron
parents:
diff changeset
   253
«DEFINE createDocumentRootMethod FOR gmfgen::GenDiagram»
033392511bf7 add files for RCL_2_2
cawthron
parents:
diff changeset
   254
	«EXPAND xpt::Common::generatedMemberComment»
033392511bf7 add files for RCL_2_2
cawthron
parents:
diff changeset
   255
	private static «EXPAND MetaModel::QualifiedClassName FOR getDocumentRoot()» createDocumentRoot(«EXPAND MetaModel::QualifiedClassName FOR domainDiagramElement» model) {
033392511bf7 add files for RCL_2_2
cawthron
parents:
diff changeset
   256
		«EXPAND MetaModel::NewInstance("docRoot") FOR getDocumentRoot()»
033392511bf7 add files for RCL_2_2
cawthron
parents:
diff changeset
   257
«LET getDocumentRootSetFeature() AS f»«IF f == null-»
033392511bf7 add files for RCL_2_2
cawthron
parents:
diff changeset
   258
		docRoot.set«domainDiagramElement.ecoreClass.name»(model); // FIXME name of the set method is pure guess«ELSE-»
033392511bf7 add files for RCL_2_2
cawthron
parents:
diff changeset
   259
		«EXPAND MetaModel::setFeatureValue("docRoot", getDocumentRoot(), "model") FOR f»;«ENDIF»
033392511bf7 add files for RCL_2_2
cawthron
parents:
diff changeset
   260
«ENDLET-»
033392511bf7 add files for RCL_2_2
cawthron
parents:
diff changeset
   261
		return docRoot;
033392511bf7 add files for RCL_2_2
cawthron
parents:
diff changeset
   262
	}
033392511bf7 add files for RCL_2_2
cawthron
parents:
diff changeset
   263
«ENDDEFINE»
033392511bf7 add files for RCL_2_2
cawthron
parents:
diff changeset
   264
033392511bf7 add files for RCL_2_2
cawthron
parents:
diff changeset
   265
«DEFINE selectElementsMethod FOR gmfgen::GenDiagram»
033392511bf7 add files for RCL_2_2
cawthron
parents:
diff changeset
   266
	«EXPAND xpt::Common::generatedMemberComment»
033392511bf7 add files for RCL_2_2
cawthron
parents:
diff changeset
   267
	public static void selectElementsInDiagram(org.eclipse.gmf.runtime.diagram.ui.parts.IDiagramWorkbenchPart diagramPart, java.util.List/*EditPart*/ editParts) {
033392511bf7 add files for RCL_2_2
cawthron
parents:
diff changeset
   268
		diagramPart.getDiagramGraphicalViewer().deselectAll();
033392511bf7 add files for RCL_2_2
cawthron
parents:
diff changeset
   269
033392511bf7 add files for RCL_2_2
cawthron
parents:
diff changeset
   270
		org.eclipse.gef.EditPart firstPrimary = null;
033392511bf7 add files for RCL_2_2
cawthron
parents:
diff changeset
   271
		for (java.util.Iterator it = editParts.iterator(); it.hasNext();) {
033392511bf7 add files for RCL_2_2
cawthron
parents:
diff changeset
   272
			org.eclipse.gef.EditPart nextPart = (org.eclipse.gef.EditPart) it.next();
033392511bf7 add files for RCL_2_2
cawthron
parents:
diff changeset
   273
			diagramPart.getDiagramGraphicalViewer().appendSelection(nextPart);
033392511bf7 add files for RCL_2_2
cawthron
parents:
diff changeset
   274
			if(firstPrimary == null && nextPart instanceof org.eclipse.gmf.runtime.diagram.ui.editparts.IPrimaryEditPart) {
033392511bf7 add files for RCL_2_2
cawthron
parents:
diff changeset
   275
				firstPrimary = nextPart;
033392511bf7 add files for RCL_2_2
cawthron
parents:
diff changeset
   276
			}
033392511bf7 add files for RCL_2_2
cawthron
parents:
diff changeset
   277
		}
033392511bf7 add files for RCL_2_2
cawthron
parents:
diff changeset
   278
033392511bf7 add files for RCL_2_2
cawthron
parents:
diff changeset
   279
		if(!editParts.isEmpty()) {
033392511bf7 add files for RCL_2_2
cawthron
parents:
diff changeset
   280
			diagramPart.getDiagramGraphicalViewer().reveal(firstPrimary != null ? firstPrimary : (org.eclipse.gef.EditPart)editParts.get(0));
033392511bf7 add files for RCL_2_2
cawthron
parents:
diff changeset
   281
		}
033392511bf7 add files for RCL_2_2
cawthron
parents:
diff changeset
   282
	}
033392511bf7 add files for RCL_2_2
cawthron
parents:
diff changeset
   283
«ENDDEFINE»
033392511bf7 add files for RCL_2_2
cawthron
parents:
diff changeset
   284
033392511bf7 add files for RCL_2_2
cawthron
parents:
diff changeset
   285
«DEFINE findElementsMethod FOR gmfgen::GenDiagram»
033392511bf7 add files for RCL_2_2
cawthron
parents:
diff changeset
   286
	«EXPAND xpt::Common::generatedMemberComment»
033392511bf7 add files for RCL_2_2
cawthron
parents:
diff changeset
   287
	private static int findElementsInDiagramByID(org.eclipse.gmf.runtime.diagram.ui.editparts.DiagramEditPart diagramPart, org.eclipse.emf.ecore.EObject element, java.util.List editPartCollector) {
033392511bf7 add files for RCL_2_2
cawthron
parents:
diff changeset
   288
		org.eclipse.gmf.runtime.diagram.ui.parts.IDiagramGraphicalViewer viewer = (org.eclipse.gmf.runtime.diagram.ui.parts.IDiagramGraphicalViewer) diagramPart.getViewer();
033392511bf7 add files for RCL_2_2
cawthron
parents:
diff changeset
   289
		final int intialNumOfEditParts = editPartCollector.size();
033392511bf7 add files for RCL_2_2
cawthron
parents:
diff changeset
   290
		
033392511bf7 add files for RCL_2_2
cawthron
parents:
diff changeset
   291
		if (element instanceof org.eclipse.gmf.runtime.notation.View) { // support notation element lookup
033392511bf7 add files for RCL_2_2
cawthron
parents:
diff changeset
   292
			org.eclipse.gef.EditPart editPart = (org.eclipse.gef.EditPart) viewer.getEditPartRegistry().get(element);
033392511bf7 add files for RCL_2_2
cawthron
parents:
diff changeset
   293
			if (editPart != null) {
033392511bf7 add files for RCL_2_2
cawthron
parents:
diff changeset
   294
				editPartCollector.add(editPart);
033392511bf7 add files for RCL_2_2
cawthron
parents:
diff changeset
   295
				return 1;
033392511bf7 add files for RCL_2_2
cawthron
parents:
diff changeset
   296
			}
033392511bf7 add files for RCL_2_2
cawthron
parents:
diff changeset
   297
		}
033392511bf7 add files for RCL_2_2
cawthron
parents:
diff changeset
   298
033392511bf7 add files for RCL_2_2
cawthron
parents:
diff changeset
   299
		String elementID = org.eclipse.gmf.runtime.emf.core.util.EMFCoreUtil.getProxyID(element);
033392511bf7 add files for RCL_2_2
cawthron
parents:
diff changeset
   300
		java.util.List associatedParts = viewer.findEditPartsForElement(elementID, org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart.class);
033392511bf7 add files for RCL_2_2
cawthron
parents:
diff changeset
   301
		// perform the possible hierarchy disjoint -> take the top-most parts only
033392511bf7 add files for RCL_2_2
cawthron
parents:
diff changeset
   302
		for (java.util.Iterator editPartIt = associatedParts.iterator(); editPartIt.hasNext();) {
033392511bf7 add files for RCL_2_2
cawthron
parents:
diff changeset
   303
			org.eclipse.gef.EditPart nextPart = (org.eclipse.gef.EditPart) editPartIt.next();
033392511bf7 add files for RCL_2_2
cawthron
parents:
diff changeset
   304
			org.eclipse.gef.EditPart parentPart = nextPart.getParent();
033392511bf7 add files for RCL_2_2
cawthron
parents:
diff changeset
   305
			while (parentPart != null && !associatedParts.contains(parentPart)) {
033392511bf7 add files for RCL_2_2
cawthron
parents:
diff changeset
   306
				parentPart = parentPart.getParent();
033392511bf7 add files for RCL_2_2
cawthron
parents:
diff changeset
   307
			}
033392511bf7 add files for RCL_2_2
cawthron
parents:
diff changeset
   308
			if (parentPart == null) {
033392511bf7 add files for RCL_2_2
cawthron
parents:
diff changeset
   309
				editPartCollector.add(nextPart);
033392511bf7 add files for RCL_2_2
cawthron
parents:
diff changeset
   310
			}
033392511bf7 add files for RCL_2_2
cawthron
parents:
diff changeset
   311
		}
033392511bf7 add files for RCL_2_2
cawthron
parents:
diff changeset
   312
033392511bf7 add files for RCL_2_2
cawthron
parents:
diff changeset
   313
		if (intialNumOfEditParts == editPartCollector.size()) {
033392511bf7 add files for RCL_2_2
cawthron
parents:
diff changeset
   314
			if (!associatedParts.isEmpty()) {
033392511bf7 add files for RCL_2_2
cawthron
parents:
diff changeset
   315
				editPartCollector.add(associatedParts.iterator().next());
033392511bf7 add files for RCL_2_2
cawthron
parents:
diff changeset
   316
			} else {
033392511bf7 add files for RCL_2_2
cawthron
parents:
diff changeset
   317
				if (element.eContainer() != null) {
033392511bf7 add files for RCL_2_2
cawthron
parents:
diff changeset
   318
					return findElementsInDiagramByID(diagramPart, element.eContainer(), editPartCollector);
033392511bf7 add files for RCL_2_2
cawthron
parents:
diff changeset
   319
				}
033392511bf7 add files for RCL_2_2
cawthron
parents:
diff changeset
   320
			}
033392511bf7 add files for RCL_2_2
cawthron
parents:
diff changeset
   321
		}
033392511bf7 add files for RCL_2_2
cawthron
parents:
diff changeset
   322
		return editPartCollector.size() - intialNumOfEditParts;
033392511bf7 add files for RCL_2_2
cawthron
parents:
diff changeset
   323
	}
033392511bf7 add files for RCL_2_2
cawthron
parents:
diff changeset
   324
«ENDDEFINE»
033392511bf7 add files for RCL_2_2
cawthron
parents:
diff changeset
   325
033392511bf7 add files for RCL_2_2
cawthron
parents:
diff changeset
   326
«DEFINE findViewMethod FOR gmfgen::GenDiagram»
033392511bf7 add files for RCL_2_2
cawthron
parents:
diff changeset
   327
	«EXPAND xpt::Common::generatedMemberComment»
033392511bf7 add files for RCL_2_2
cawthron
parents:
diff changeset
   328
	public static org.eclipse.gmf.runtime.notation.View findView(org.eclipse.gmf.runtime.diagram.ui.editparts.DiagramEditPart diagramEditPart, org.eclipse.emf.ecore.EObject targetElement, LazyElement2ViewMap lazyElement2ViewMap) {
033392511bf7 add files for RCL_2_2
cawthron
parents:
diff changeset
   329
		boolean hasStructuralURI = false;						
033392511bf7 add files for RCL_2_2
cawthron
parents:
diff changeset
   330
		if(targetElement.eResource() instanceof org.eclipse.emf.ecore.xmi.XMLResource) {
033392511bf7 add files for RCL_2_2
cawthron
parents:
diff changeset
   331
			hasStructuralURI = ((org.eclipse.emf.ecore.xmi.XMLResource)targetElement.eResource()).getID(targetElement) == null;
033392511bf7 add files for RCL_2_2
cawthron
parents:
diff changeset
   332
		}
033392511bf7 add files for RCL_2_2
cawthron
parents:
diff changeset
   333
		
033392511bf7 add files for RCL_2_2
cawthron
parents:
diff changeset
   334
		org.eclipse.gmf.runtime.notation.View view = null;
033392511bf7 add files for RCL_2_2
cawthron
parents:
diff changeset
   335
		if(hasStructuralURI && !lazyElement2ViewMap.getElement2ViewMap().isEmpty()) {
033392511bf7 add files for RCL_2_2
cawthron
parents:
diff changeset
   336
			view = (org.eclipse.gmf.runtime.notation.View)lazyElement2ViewMap.getElement2ViewMap().get(targetElement);
033392511bf7 add files for RCL_2_2
cawthron
parents:
diff changeset
   337
		} else if (findElementsInDiagramByID(diagramEditPart, targetElement, lazyElement2ViewMap.editPartTmpHolder) > 0) {
033392511bf7 add files for RCL_2_2
cawthron
parents:
diff changeset
   338
			org.eclipse.gef.EditPart editPart = (org.eclipse.gef.EditPart) lazyElement2ViewMap.editPartTmpHolder.get(0);
033392511bf7 add files for RCL_2_2
cawthron
parents:
diff changeset
   339
			lazyElement2ViewMap.editPartTmpHolder.clear();
033392511bf7 add files for RCL_2_2
cawthron
parents:
diff changeset
   340
			view = editPart.getModel() instanceof org.eclipse.gmf.runtime.notation.View ? (org.eclipse.gmf.runtime.notation.View) editPart.getModel() : null;
033392511bf7 add files for RCL_2_2
cawthron
parents:
diff changeset
   341
		}
033392511bf7 add files for RCL_2_2
cawthron
parents:
diff changeset
   342
	
033392511bf7 add files for RCL_2_2
cawthron
parents:
diff changeset
   343
		return (view == null) ? diagramEditPart.getDiagramView() : view;
033392511bf7 add files for RCL_2_2
cawthron
parents:
diff changeset
   344
	}
033392511bf7 add files for RCL_2_2
cawthron
parents:
diff changeset
   345
033392511bf7 add files for RCL_2_2
cawthron
parents:
diff changeset
   346
	«EXPAND xpt::Common::generatedMemberComment»
033392511bf7 add files for RCL_2_2
cawthron
parents:
diff changeset
   347
	public static class LazyElement2ViewMap {
033392511bf7 add files for RCL_2_2
cawthron
parents:
diff changeset
   348
		«EXPAND xpt::Common::generatedMemberComment»
033392511bf7 add files for RCL_2_2
cawthron
parents:
diff changeset
   349
		private java.util.Map element2ViewMap;
033392511bf7 add files for RCL_2_2
cawthron
parents:
diff changeset
   350
033392511bf7 add files for RCL_2_2
cawthron
parents:
diff changeset
   351
		«EXPAND xpt::Common::generatedMemberComment»
033392511bf7 add files for RCL_2_2
cawthron
parents:
diff changeset
   352
		private org.eclipse.gmf.runtime.notation.View scope;
033392511bf7 add files for RCL_2_2
cawthron
parents:
diff changeset
   353
033392511bf7 add files for RCL_2_2
cawthron
parents:
diff changeset
   354
		«EXPAND xpt::Common::generatedMemberComment»
033392511bf7 add files for RCL_2_2
cawthron
parents:
diff changeset
   355
		private java.util.Set elementSet;
033392511bf7 add files for RCL_2_2
cawthron
parents:
diff changeset
   356
033392511bf7 add files for RCL_2_2
cawthron
parents:
diff changeset
   357
		«EXPAND xpt::Common::generatedMemberComment»
033392511bf7 add files for RCL_2_2
cawthron
parents:
diff changeset
   358
		public final java.util.List editPartTmpHolder = new java.util.ArrayList();
033392511bf7 add files for RCL_2_2
cawthron
parents:
diff changeset
   359
033392511bf7 add files for RCL_2_2
cawthron
parents:
diff changeset
   360
		«EXPAND xpt::Common::generatedMemberComment»
033392511bf7 add files for RCL_2_2
cawthron
parents:
diff changeset
   361
		public LazyElement2ViewMap(org.eclipse.gmf.runtime.notation.View scope, java.util.Set elements) {
033392511bf7 add files for RCL_2_2
cawthron
parents:
diff changeset
   362
			this.scope = scope;
033392511bf7 add files for RCL_2_2
cawthron
parents:
diff changeset
   363
			this.elementSet = elements;
033392511bf7 add files for RCL_2_2
cawthron
parents:
diff changeset
   364
		}
033392511bf7 add files for RCL_2_2
cawthron
parents:
diff changeset
   365
033392511bf7 add files for RCL_2_2
cawthron
parents:
diff changeset
   366
		«EXPAND xpt::Common::generatedMemberComment»
033392511bf7 add files for RCL_2_2
cawthron
parents:
diff changeset
   367
		public final java.util.Map getElement2ViewMap() {
033392511bf7 add files for RCL_2_2
cawthron
parents:
diff changeset
   368
			if(element2ViewMap == null) {
033392511bf7 add files for RCL_2_2
cawthron
parents:
diff changeset
   369
				element2ViewMap = new java.util.HashMap();
033392511bf7 add files for RCL_2_2
cawthron
parents:
diff changeset
   370
				// map possible notation elements to itself as these can't be found by view.getElement()
033392511bf7 add files for RCL_2_2
cawthron
parents:
diff changeset
   371
				for (java.util.Iterator it = elementSet.iterator(); it.hasNext();) {
033392511bf7 add files for RCL_2_2
cawthron
parents:
diff changeset
   372
					org.eclipse.emf.ecore.EObject element = (org.eclipse.emf.ecore.EObject) it.next();
033392511bf7 add files for RCL_2_2
cawthron
parents:
diff changeset
   373
					if(element instanceof org.eclipse.gmf.runtime.notation.View) {
033392511bf7 add files for RCL_2_2
cawthron
parents:
diff changeset
   374
						org.eclipse.gmf.runtime.notation.View view = (org.eclipse.gmf.runtime.notation.View) element;
033392511bf7 add files for RCL_2_2
cawthron
parents:
diff changeset
   375
						if(view.getDiagram() == scope.getDiagram()) {
033392511bf7 add files for RCL_2_2
cawthron
parents:
diff changeset
   376
							element2ViewMap.put(element, element); // take only those that part of our diagram
033392511bf7 add files for RCL_2_2
cawthron
parents:
diff changeset
   377
						}
033392511bf7 add files for RCL_2_2
cawthron
parents:
diff changeset
   378
					}
033392511bf7 add files for RCL_2_2
cawthron
parents:
diff changeset
   379
				}
033392511bf7 add files for RCL_2_2
cawthron
parents:
diff changeset
   380
				
033392511bf7 add files for RCL_2_2
cawthron
parents:
diff changeset
   381
				buildElement2ViewMap(scope, element2ViewMap, elementSet);					
033392511bf7 add files for RCL_2_2
cawthron
parents:
diff changeset
   382
			}
033392511bf7 add files for RCL_2_2
cawthron
parents:
diff changeset
   383
			return element2ViewMap;
033392511bf7 add files for RCL_2_2
cawthron
parents:
diff changeset
   384
		}
033392511bf7 add files for RCL_2_2
cawthron
parents:
diff changeset
   385
		«EXPAND xpt::Common::generatedMemberComment»
033392511bf7 add files for RCL_2_2
cawthron
parents:
diff changeset
   386
		static java.util.Map buildElement2ViewMap(org.eclipse.gmf.runtime.notation.View parentView, java.util.Map element2ViewMap, java.util.Set elements) {
033392511bf7 add files for RCL_2_2
cawthron
parents:
diff changeset
   387
			if(elements.size() == element2ViewMap.size()) return element2ViewMap;
033392511bf7 add files for RCL_2_2
cawthron
parents:
diff changeset
   388
033392511bf7 add files for RCL_2_2
cawthron
parents:
diff changeset
   389
			if(parentView.isSetElement() && !element2ViewMap.containsKey(parentView.getElement()) && elements.contains(parentView.getElement())) {
033392511bf7 add files for RCL_2_2
cawthron
parents:
diff changeset
   390
				element2ViewMap.put(parentView.getElement(), parentView);
033392511bf7 add files for RCL_2_2
cawthron
parents:
diff changeset
   391
				if(elements.size() == element2ViewMap.size()) return element2ViewMap;
033392511bf7 add files for RCL_2_2
cawthron
parents:
diff changeset
   392
			}
033392511bf7 add files for RCL_2_2
cawthron
parents:
diff changeset
   393
			
033392511bf7 add files for RCL_2_2
cawthron
parents:
diff changeset
   394
			for (java.util.Iterator it = parentView.getChildren().iterator(); it.hasNext();) {
033392511bf7 add files for RCL_2_2
cawthron
parents:
diff changeset
   395
				buildElement2ViewMap((org.eclipse.gmf.runtime.notation.View) it.next(), element2ViewMap, elements);			
033392511bf7 add files for RCL_2_2
cawthron
parents:
diff changeset
   396
				if(elements.size() == element2ViewMap.size()) return element2ViewMap;
033392511bf7 add files for RCL_2_2
cawthron
parents:
diff changeset
   397
			}
033392511bf7 add files for RCL_2_2
cawthron
parents:
diff changeset
   398
			for (java.util.Iterator it = parentView.getSourceEdges().iterator(); it.hasNext();) {
033392511bf7 add files for RCL_2_2
cawthron
parents:
diff changeset
   399
				buildElement2ViewMap((org.eclipse.gmf.runtime.notation.View) it.next(), element2ViewMap, elements);			
033392511bf7 add files for RCL_2_2
cawthron
parents:
diff changeset
   400
				if(elements.size() == element2ViewMap.size()) return element2ViewMap;
033392511bf7 add files for RCL_2_2
cawthron
parents:
diff changeset
   401
			}
033392511bf7 add files for RCL_2_2
cawthron
parents:
diff changeset
   402
			for (java.util.Iterator it = parentView.getSourceEdges().iterator(); it.hasNext();) {
033392511bf7 add files for RCL_2_2
cawthron
parents:
diff changeset
   403
				buildElement2ViewMap((org.eclipse.gmf.runtime.notation.View) it.next(), element2ViewMap, elements);			
033392511bf7 add files for RCL_2_2
cawthron
parents:
diff changeset
   404
				if(elements.size() == element2ViewMap.size()) return element2ViewMap;
033392511bf7 add files for RCL_2_2
cawthron
parents:
diff changeset
   405
			}	
033392511bf7 add files for RCL_2_2
cawthron
parents:
diff changeset
   406
			return element2ViewMap;
033392511bf7 add files for RCL_2_2
cawthron
parents:
diff changeset
   407
		}
033392511bf7 add files for RCL_2_2
cawthron
parents:
diff changeset
   408
	} //LazyElement2ViewMap	
033392511bf7 add files for RCL_2_2
cawthron
parents:
diff changeset
   409
«ENDDEFINE»
033392511bf7 add files for RCL_2_2
cawthron
parents:
diff changeset
   410
033392511bf7 add files for RCL_2_2
cawthron
parents:
diff changeset
   411
«DEFINE i18nAccessors FOR gmfgen::GenDiagram-»
033392511bf7 add files for RCL_2_2
cawthron
parents:
diff changeset
   412
«EXPAND xpt::Externalizer::accessorField(i18nKeyForOpenModelResourceErrorDialog().titleKey())-»
033392511bf7 add files for RCL_2_2
cawthron
parents:
diff changeset
   413
«EXPAND xpt::Externalizer::accessorField(i18nKeyForOpenModelResourceErrorDialog().messageKey())-»
033392511bf7 add files for RCL_2_2
cawthron
parents:
diff changeset
   414
«EXPAND xpt::Externalizer::accessorField(i18nKeyForCreateDiagramProgressTask())-»
033392511bf7 add files for RCL_2_2
cawthron
parents:
diff changeset
   415
«EXPAND xpt::Externalizer::accessorField(i18nKeyForCreateDiagramCommandLabel())-»
033392511bf7 add files for RCL_2_2
cawthron
parents:
diff changeset
   416
«ENDDEFINE»
033392511bf7 add files for RCL_2_2
cawthron
parents:
diff changeset
   417
033392511bf7 add files for RCL_2_2
cawthron
parents:
diff changeset
   418
«DEFINE i18nValues FOR gmfgen::GenDiagram-»
033392511bf7 add files for RCL_2_2
cawthron
parents:
diff changeset
   419
«EXPAND xpt::Externalizer::messageEntry(i18nKeyForOpenModelResourceErrorDialog().titleKey(), "Error")-»
033392511bf7 add files for RCL_2_2
cawthron
parents:
diff changeset
   420
«EXPAND xpt::Externalizer::messageEntry(i18nKeyForOpenModelResourceErrorDialog().messageKey(), "Failed to load model file {0}")-»
033392511bf7 add files for RCL_2_2
cawthron
parents:
diff changeset
   421
«EXPAND xpt::Externalizer::messageEntry(i18nKeyForCreateDiagramProgressTask(), "Creating diagram and model files")-»
033392511bf7 add files for RCL_2_2
cawthron
parents:
diff changeset
   422
«EXPAND xpt::Externalizer::messageEntry(i18nKeyForCreateDiagramCommandLabel(), "Creating diagram and model")-»
033392511bf7 add files for RCL_2_2
cawthron
parents:
diff changeset
   423
«ENDDEFINE»