Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/org.eclipse.gmf.codegen/templates.migrated/xpt/editor/ElementChooser.xpt')
-rw-r--r--plugins/org.eclipse.gmf.codegen/templates.migrated/xpt/editor/ElementChooser.xpt414
1 files changed, 414 insertions, 0 deletions
diff --git a/plugins/org.eclipse.gmf.codegen/templates.migrated/xpt/editor/ElementChooser.xpt b/plugins/org.eclipse.gmf.codegen/templates.migrated/xpt/editor/ElementChooser.xpt
new file mode 100644
index 000000000..4481be47b
--- /dev/null
+++ b/plugins/org.eclipse.gmf.codegen/templates.migrated/xpt/editor/ElementChooser.xpt
@@ -0,0 +1,414 @@
+/*
+ * Copyright (c) 2007, 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
+ */
+
+«IMPORT 'http://www.eclipse.org/gmf/2008/GenModel'»
+«IMPORT 'http://www.eclipse.org/emf/2002/Ecore'»
+«EXTENSION xpt::editor::Utils»
+
+«DEFINE ElementChooser FOR gmfgen::GenDiagram-»
+ «EXPAND xpt::Common::copyright FOR editorGen-»
+package «editorGen.editor.packageName»;
+
+ «EXPAND xpt::Common::generatedClassComment»
+public class «elementChooserClassName» extends org.eclipse.jface.dialogs.Dialog {
+
+ «EXPAND attributes-»
+
+ «EXPAND _constructor-»
+
+ «EXPAND createDialogArea-»
+
+ «EXPAND createButtonBar-»
+
+ «EXPAND createModelBrowser-»
+
+ «EXPAND setOkButtonEnabled-»
+
+ «EXPAND isValidModelFile-»
+
+ «EXPAND getSelectedModelElementURI-»
+
+ «EXPAND open-»
+
+ «EXPAND ModelElementsTreeContentProvider-»
+
+ «EXPAND ModelElementsTreeLabelProvider-»
+
+ «EXPAND ModelFilesFilter-»
+
+ «EXPAND OkButtonEnabler-»
+
+ «EXPAND additions-»
+}
+«ENDDEFINE»
+
+«DEFINE attributes FOR gmfgen::GenDiagram-»
+ «EXPAND xpt::Common::generatedMemberComment»
+private org.eclipse.jface.viewers.TreeViewer myTreeViewer;
+
+ «EXPAND xpt::Common::generatedMemberComment»
+private org.eclipse.emf.common.util.URI mySelectedModelElementURI;
+
+ «EXPAND xpt::Common::generatedMemberComment»
+private org.eclipse.gmf.runtime.notation.View myView;
+
+ «EXPAND xpt::Common::generatedMemberComment»
+private org.eclipse.emf.transaction.TransactionalEditingDomain myEditingDomain = org.eclipse.gmf.runtime.emf.core.GMFEditingDomainFactory.INSTANCE.createEditingDomain();
+«ENDDEFINE»
+
+«DEFINE _constructor FOR gmfgen::GenDiagram-»
+ «EXPAND xpt::Common::generatedMemberComment»
+public «elementChooserClassName»(org.eclipse.swt.widgets.Shell parentShell, org.eclipse.gmf.runtime.notation.View view) {
+ super(parentShell);
+ setShellStyle(getShellStyle() | org.eclipse.swt.SWT.RESIZE);
+ myView = view;
+}
+«ENDDEFINE»
+
+«DEFINE createDialogArea FOR gmfgen::GenDiagram-»
+ «EXPAND xpt::Common::generatedMemberComment»
+protected org.eclipse.swt.widgets.Control createDialogArea(org.eclipse.swt.widgets.Composite parent) {
+ org.eclipse.swt.widgets.Composite composite = (org.eclipse.swt.widgets.Composite) super.createDialogArea(parent);
+ getShell().setText(«EXPAND xpt::Externalizer::accessorCall(titleKey(i18nKeyForSelectModelElement(self))) FOR editorGen»);
+ createModelBrowser(composite);
+ return composite;
+}
+«ENDDEFINE»
+
+«DEFINE createButtonBar FOR gmfgen::GenDiagram-»
+ «EXPAND xpt::Common::generatedMemberComment»
+protected org.eclipse.swt.widgets.Control createButtonBar(org.eclipse.swt.widgets.Composite parent) {
+ org.eclipse.swt.widgets.Control buttonBar = super.createButtonBar(parent);
+ setOkButtonEnabled(false);
+ return buttonBar;
+}
+«ENDDEFINE»
+
+«DEFINE createModelBrowser FOR gmfgen::GenDiagram-»
+ «EXPAND xpt::Common::generatedMemberComment»
+private void createModelBrowser(org.eclipse.swt.widgets.Composite composite) {
+ myTreeViewer = new org.eclipse.jface.viewers.TreeViewer(composite, org.eclipse.swt.SWT.SINGLE | org.eclipse.swt.SWT.H_SCROLL | org.eclipse.swt.SWT.V_SCROLL | org.eclipse.swt.SWT.BORDER);
+ org.eclipse.swt.layout.GridData layoutData = new org.eclipse.swt.layout.GridData(org.eclipse.swt.layout.GridData.FILL_BOTH);
+ layoutData.heightHint = 300;
+ layoutData.widthHint = 300;
+ myTreeViewer.getTree().setLayoutData(layoutData);
+ myTreeViewer.setContentProvider(new ModelElementsTreeContentProvider());
+ myTreeViewer.setLabelProvider(new ModelElementsTreeLabelProvider());
+ myTreeViewer.setInput(org.eclipse.core.resources.ResourcesPlugin.getWorkspace().getRoot());
+ myTreeViewer.addFilter(new ModelFilesFilter());
+ myTreeViewer.addSelectionChangedListener(new OkButtonEnabler());
+}
+«ENDDEFINE»
+
+«DEFINE setOkButtonEnabled FOR gmfgen::GenDiagram-»
+ «EXPAND xpt::Common::generatedMemberComment»
+private void setOkButtonEnabled(boolean enabled) {
+ getButton(org.eclipse.jface.dialogs.IDialogConstants.OK_ID).setEnabled(enabled);
+}
+«ENDDEFINE»
+
+«DEFINE isValidModelFile FOR gmfgen::GenDiagram-»
+ «EXPAND xpt::Common::generatedMemberComment»
+private boolean isValidModelFile(org.eclipse.core.resources.IFile file) {
+ String fileExtension = file.getFullPath().getFileExtension();
+ return «EXPAND compareModelFileExtension FOREACH containsShortcutsTo SEPARATOR ' || '»; «EXPAND xpt::Common::nonNLS FOR containsShortcutsTo->asSequence()»
+}
+«ENDDEFINE»
+
+«DEFINE compareModelFileExtension FOR String»"«self»".equals(fileExtension)«ENDDEFINE»
+
+«DEFINE getSelectedModelElementURI FOR gmfgen::GenDiagram-»
+ «EXPAND xpt::Common::generatedMemberComment»
+public org.eclipse.emf.common.util.URI getSelectedModelElementURI() {
+ return mySelectedModelElementURI;
+}
+«ENDDEFINE»
+
+«DEFINE open FOR gmfgen::GenDiagram-»
+ «EXPAND xpt::Common::generatedMemberComment»
+public int open() {
+ int result = super.open();
+ for (java.util.Iterator it = myEditingDomain.getResourceSet().getResources().iterator(); it.hasNext();) {
+ org.eclipse.emf.ecore.resource.Resource resource = (org.eclipse.emf.ecore.resource.Resource) it.next();
+ resource.unload();
+ }
+ myEditingDomain.dispose();
+ return result;
+}
+«ENDDEFINE»
+
+«DEFINE ModelElementsTreeContentProvider FOR gmfgen::GenDiagram-»
+ «EXPAND xpt::Common::generatedClassComment»
+private class ModelElementsTreeContentProvider implements org.eclipse.jface.viewers.ITreeContentProvider {
+
+ «EXPAND METCP_attributes-»
+
+ «EXPAND METCP_getChildren-»
+
+ «EXPAND METCP_getParent-»
+
+ «EXPAND METCP_hasChildren-»
+
+ «EXPAND METCP_getElements-»
+
+ «EXPAND METCP_dispose-»
+
+ «EXPAND METCP_inputChanged-»
+
+ «EXPAND METCP_additions-»
+}
+«ENDDEFINE»
+
+«DEFINE METCP_attributes FOR gmfgen::GenDiagram-»
+ «EXPAND xpt::Common::generatedMemberComment»
+private org.eclipse.jface.viewers.ITreeContentProvider myWorkbenchContentProvider = new «IF null = editorGen.application»org.eclipse.ui.model.WorkbenchContentProvider«ELSE»org.eclipse.ui.model.BaseWorkbenchContentProvider«ENDIF»();
+
+ «EXPAND xpt::Common::generatedMemberComment»
+private org.eclipse.emf.edit.ui.provider.AdapterFactoryContentProvider myAdapterFctoryContentProvier = new org.eclipse.emf.edit.ui.provider.AdapterFactoryContentProvider(«editorGen.plugin.getActivatorQualifiedClassName()».getInstance().getItemProvidersAdapterFactory());
+«ENDDEFINE»
+
+«DEFINE METCP_getChildren FOR gmfgen::GenDiagram-»
+ «EXPAND xpt::Common::generatedMemberComment»
+public Object[] getChildren(Object parentElement) {
+ Object[] result = myWorkbenchContentProvider.getChildren(parentElement);
+ if (result != null && result.length > 0) {
+ return result;
+ }
+ if (parentElement instanceof org.eclipse.core.resources.IFile) {
+ org.eclipse.core.resources.IFile modelFile = (org.eclipse.core.resources.IFile) parentElement;
+ org.eclipse.core.runtime.IPath resourcePath = modelFile.getFullPath();
+ org.eclipse.emf.ecore.resource.ResourceSet resourceSet = myEditingDomain.getResourceSet();
+ try {
+ org.eclipse.emf.ecore.resource.Resource modelResource = resourceSet.getResource(org.eclipse.emf.common.util.URI.createPlatformResourceURI(resourcePath.toString(), true), true);
+ return myAdapterFctoryContentProvier.getChildren(modelResource);
+ } catch (org.eclipse.emf.common.util.WrappedException e) {
+ «editorGen.plugin.getActivatorQualifiedClassName()».getInstance().logError("Unable to load resource: " + resourcePath.toString(), e); «EXPAND xpt::Common::nonNLS»
+ }
+ return java.util.Collections.EMPTY_LIST.toArray();
+ }
+ return myAdapterFctoryContentProvier.getChildren(parentElement);
+}
+«ENDDEFINE»
+
+«DEFINE METCP_getParent FOR gmfgen::GenDiagram-»
+ «EXPAND xpt::Common::generatedMemberComment»
+public Object getParent(Object element) {
+ Object parent = myWorkbenchContentProvider.getParent(element);
+ if (parent != null) {
+ return parent;
+ }
+ if (element instanceof org.eclipse.emf.ecore.EObject) {
+ org.eclipse.emf.ecore.EObject eObject = (org.eclipse.emf.ecore.EObject) element;
+ if (eObject.eContainer() == null && eObject.eResource().getURI().isFile()) {
+ String path = eObject.eResource().getURI().path();
+ return org.eclipse.core.resources.ResourcesPlugin.getWorkspace().getRoot().getFileForLocation(new org.eclipse.core.runtime.Path(path));
+ }
+ return myAdapterFctoryContentProvier.getParent(eObject);
+ }
+ return null;
+}
+«ENDDEFINE»
+
+«DEFINE METCP_hasChildren FOR gmfgen::GenDiagram-»
+ «EXPAND xpt::Common::generatedMemberComment»
+public boolean hasChildren(Object element) {
+ if (element instanceof org.eclipse.core.resources.IFile) {
+ return isValidModelFile((org.eclipse.core.resources.IFile) element);
+ }
+ return myWorkbenchContentProvider.hasChildren(element) || myAdapterFctoryContentProvier.hasChildren(element);
+}
+«ENDDEFINE»
+
+«DEFINE METCP_getElements FOR gmfgen::GenDiagram-»
+ «EXPAND xpt::Common::generatedMemberComment»
+public Object[] getElements(Object inputElement) {
+ Object[] elements = myWorkbenchContentProvider.getElements(inputElement);
+ return elements;
+}
+«ENDDEFINE»
+
+«DEFINE METCP_dispose FOR gmfgen::GenDiagram-»
+ «EXPAND xpt::Common::generatedMemberComment»
+public void dispose() {
+ myWorkbenchContentProvider.dispose();
+ myAdapterFctoryContentProvier.dispose();
+}
+«ENDDEFINE»
+
+«DEFINE METCP_inputChanged FOR gmfgen::GenDiagram-»
+ «EXPAND xpt::Common::generatedMemberComment»
+public void inputChanged(org.eclipse.jface.viewers.Viewer viewer, Object oldInput, Object newInput) {
+ myWorkbenchContentProvider.inputChanged(viewer, oldInput, newInput);
+ myAdapterFctoryContentProvier.inputChanged(viewer, oldInput, newInput);
+}
+«ENDDEFINE»
+
+«DEFINE ModelElementsTreeLabelProvider FOR gmfgen::GenDiagram-»
+ «EXPAND xpt::Common::generatedClassComment»
+private class ModelElementsTreeLabelProvider implements org.eclipse.jface.viewers.ILabelProvider {
+
+ «EXPAND METLP_attributes-»
+
+ «EXPAND METLP_getImage-»
+
+ «EXPAND METLP_getText-»
+
+ «EXPAND METLP_addListener-»
+
+ «EXPAND METLP_dispose-»
+
+ «EXPAND METLP_isLabelProperty-»
+
+ «EXPAND METLP_removeListener-»
+
+ «EXPAND METLP_additions-»
+}
+«ENDDEFINE»
+
+
+«DEFINE METLP_attributes FOR gmfgen::GenDiagram-»
+ «EXPAND xpt::Common::generatedMemberComment»
+ private org.eclipse.ui.model.WorkbenchLabelProvider myWorkbenchLabelProvider = new org.eclipse.ui.model.WorkbenchLabelProvider();
+
+ «EXPAND xpt::Common::generatedMemberComment»
+ private org.eclipse.emf.edit.ui.provider.AdapterFactoryLabelProvider myAdapterFactoryLabelProvider = new org.eclipse.emf.edit.ui.provider.AdapterFactoryLabelProvider(«editorGen.plugin.getActivatorQualifiedClassName()».getInstance().getItemProvidersAdapterFactory());
+«ENDDEFINE»
+
+«DEFINE METLP_getImage FOR gmfgen::GenDiagram-»
+ «EXPAND xpt::Common::generatedMemberComment»
+public org.eclipse.swt.graphics.Image getImage(Object element) {
+ org.eclipse.swt.graphics.Image result = myWorkbenchLabelProvider.getImage(element);
+ return result != null ? result : myAdapterFactoryLabelProvider.getImage(element);
+}
+«ENDDEFINE»
+
+«DEFINE METLP_getText FOR gmfgen::GenDiagram-»
+ «EXPAND xpt::Common::generatedMemberComment»
+public String getText(Object element) {
+ String result = myWorkbenchLabelProvider.getText(element);
+ return result != null && result.length() > 0 ? result : myAdapterFactoryLabelProvider.getText(element);
+}
+«ENDDEFINE»
+
+«DEFINE METLP_addListener FOR gmfgen::GenDiagram-»
+ «EXPAND xpt::Common::generatedMemberComment»
+public void addListener(org.eclipse.jface.viewers.ILabelProviderListener listener) {
+ myWorkbenchLabelProvider.addListener(listener);
+ myAdapterFactoryLabelProvider.addListener(listener);
+}
+«ENDDEFINE»
+
+«DEFINE METLP_dispose FOR gmfgen::GenDiagram-»
+ «EXPAND xpt::Common::generatedMemberComment»
+public void dispose() {
+ myWorkbenchLabelProvider.dispose();
+ myAdapterFactoryLabelProvider.dispose();
+}
+«ENDDEFINE»
+
+«DEFINE METLP_isLabelProperty FOR gmfgen::GenDiagram-»
+ «EXPAND xpt::Common::generatedMemberComment»
+public boolean isLabelProperty(Object element, String property) {
+ return myWorkbenchLabelProvider.isLabelProperty(element, property) || myAdapterFactoryLabelProvider.isLabelProperty(element, property);
+}
+«ENDDEFINE»
+
+«DEFINE METLP_removeListener FOR gmfgen::GenDiagram-»
+ «EXPAND xpt::Common::generatedMemberComment»
+public void removeListener(org.eclipse.jface.viewers.ILabelProviderListener listener) {
+ myWorkbenchLabelProvider.removeListener(listener);
+ myAdapterFactoryLabelProvider.removeListener(listener);
+}
+«ENDDEFINE»
+
+«DEFINE ModelFilesFilter FOR gmfgen::GenDiagram-»
+ «EXPAND xpt::Common::generatedClassComment»
+private class ModelFilesFilter extends org.eclipse.jface.viewers.ViewerFilter {
+
+ «EXPAND MFF_select-»
+
+ «EXPAND MFF_additions-»
+}
+«ENDDEFINE»
+
+«DEFINE MFF_select FOR gmfgen::GenDiagram-»
+ «EXPAND xpt::Common::generatedMemberComment»
+public boolean select(org.eclipse.jface.viewers.Viewer viewer, Object parentElement, Object element) {
+ if (element instanceof org.eclipse.core.resources.IContainer) {
+ return true;
+ }
+ if (element instanceof org.eclipse.core.resources.IFile) {
+ org.eclipse.core.resources.IFile file = (org.eclipse.core.resources.IFile) element;
+ return isValidModelFile(file);
+ }
+ return true;
+}
+«ENDDEFINE»
+
+«DEFINE OkButtonEnabler FOR gmfgen::GenDiagram-»
+ «EXPAND xpt::Common::generatedClassComment»
+private class OkButtonEnabler implements org.eclipse.jface.viewers.ISelectionChangedListener {
+
+ «EXPAND OBE_selectionChanged-»
+
+ «EXPAND OBE_additions-»
+}
+«ENDDEFINE»
+
+«DEFINE OBE_selectionChanged FOR gmfgen::GenDiagram-»
+ «EXPAND xpt::Common::generatedMemberComment»
+public void selectionChanged(org.eclipse.jface.viewers.SelectionChangedEvent event) {
+ if (event.getSelection() instanceof org.eclipse.jface.viewers.IStructuredSelection) {
+ org.eclipse.jface.viewers.IStructuredSelection selection = (org.eclipse.jface.viewers.IStructuredSelection) event.getSelection();
+ if (selection.size() == 1) {
+ Object selectedElement = selection.getFirstElement();
+ if (selectedElement instanceof org.eclipse.emf.edit.provider.IWrapperItemProvider) {
+ selectedElement = ((org.eclipse.emf.edit.provider.IWrapperItemProvider) selectedElement).getValue();
+ }
+ if (selectedElement instanceof org.eclipse.emf.ecore.util.FeatureMap.Entry) {
+ selectedElement = ((org.eclipse.emf.ecore.util.FeatureMap.Entry) selectedElement).getValue();
+ }
+ if (selectedElement instanceof org.eclipse.emf.ecore.EObject) {
+ org.eclipse.emf.ecore.EObject selectedModelElement = (org.eclipse.emf.ecore.EObject) selectedElement;
+ setOkButtonEnabled(org.eclipse.gmf.runtime.diagram.core.services.ViewService.getInstance().provides(org.eclipse.gmf.runtime.notation.Node.class, new org.eclipse.gmf.runtime.emf.core.util.EObjectAdapter(selectedModelElement), myView, null, org.eclipse.gmf.runtime.diagram.core.util.ViewUtil.APPEND, true, «EXPAND xpt::plugin::Activator::preferenceHintAccess FOR editorGen»));
+ mySelectedModelElementURI = org.eclipse.emf.ecore.util.EcoreUtil.getURI(selectedModelElement);
+ return;
+ }
+ }
+ }
+ mySelectedModelElementURI = null;
+ setOkButtonEnabled(false);
+}
+«ENDDEFINE»
+
+«DEFINE METCP_additions FOR gmfgen::GenDiagram-»
+«ENDDEFINE»
+
+«DEFINE METLP_additions FOR gmfgen::GenDiagram-»
+«ENDDEFINE»
+
+«DEFINE MFF_additions FOR gmfgen::GenDiagram-»
+«ENDDEFINE»
+
+«DEFINE OBE_additions FOR gmfgen::GenDiagram-»
+«ENDDEFINE»
+
+«DEFINE additions FOR gmfgen::GenDiagram-»
+«ENDDEFINE»
+
+«DEFINE i18nValues FOR gmfgen::GenDiagram-»
+«EXPAND xpt::Externalizer::messageEntry(titleKey(i18nKeyForSelectModelElement(self)), 'Select model element')-»
+«ENDDEFINE»
+
+«DEFINE i18nAccessors FOR gmfgen::GenDiagram-»
+ «EXPAND xpt::Externalizer::accessorField(titleKey(i18nKeyForSelectModelElement(self)))-»
+«ENDDEFINE» \ No newline at end of file

Back to the top