«REM»
Copyright (c) 2004 - 2010 Eike Stepper (Berlin, Germany).
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:
Martin Fluegge - initial API and implementation
«ENDREM»
«IMPORT gmfgen»
«IMPORT gmfgraph»
«IMPORT emf»
«IMPORT genmodel»
«IMPORT ecore»
«IMPORT dawngenmodel»
«EXTENSION org::eclipse::emf::cdo::dawn::codegen::util::Utils»
«DEFINE main FOR DawnGenerator»
«setDiagramPackage(this.emfFragmentgenerator.emfGenModel.modelPluginID)»
«EXPAND dawnEditor FOR this.emfFragmentgenerator»
«EXPAND dawnWizard FOR this.emfFragmentgenerator»
«EXPAND fragmentXML FOR this.emfFragmentgenerator»
«EXPAND manifestMF FOR this.emfFragmentgenerator»
«EXPAND buildPROPERTIES FOR this.emfFragmentgenerator»
«EXPAND classpath FOR this.emfFragmentgenerator»
«ENDDEFINE»
«REM»############################################ Extended Editor ##################################################################«ENDREM»
«DEFINE dawnEditor FOR DawnEMFGenerator»
«FILE "src/"+getDiagramPackagePath()+"/presentation/"+this.dawnEditorClassName+".java"»
package «this.emfGenModel.modelPluginID».presentation;
import «this.emfGenModel.modelPluginID».presentation.«this.emfGenModel.modelName»Editor;
import org.eclipse.emf.cdo.dawn.editors.IDawnEditor;
import org.eclipse.emf.cdo.dawn.editors.IDawnEditorSupport;
import org.eclipse.emf.cdo.dawn.editors.impl.DawnEMFEditorSupport;
import org.eclipse.emf.cdo.dawn.ui.DawnEditorInput;
import org.eclipse.emf.cdo.dawn.ui.DawnLabelProvider;
import org.eclipse.emf.cdo.dawn.ui.DawnSelectionViewerAdapterFactoryContentProvider;
import org.eclipse.emf.cdo.dawn.util.connection.CDOConnectionUtil;
import org.eclipse.emf.cdo.eresource.CDOResource;
import org.eclipse.emf.cdo.transaction.CDOTransaction;
import org.eclipse.emf.cdo.view.CDOView;
import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.ecore.resource.ResourceSet;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.jface.viewers.StructuredSelection;
import org.eclipse.swt.widgets.Display;
import org.eclipse.ui.IEditorInput;
public class «this.dawnEditorClassName» extends «this.emfGenModel.modelName»Editor implements IDawnEditor
{
private IDawnEditorSupport dawnEditorSupport;
public static String ID = "«this.emfGenModel.modelPluginID».presentation.«this.dawnEditorClassName»ID";
public «this.dawnEditorClassName»()
{
super();
dawnEditorSupport = new DawnEMFEditorSupport(this);
}
@Override
protected void setInput(IEditorInput input)
{
super.setInput(input);
if (input instanceof DawnEditorInput)
{
dawnEditorSupport.setView(((DawnEditorInput)input).getView());
dawnEditorSupport.registerListeners();
}
}
@Override
protected void setInputWithNotify(IEditorInput input)
{
super.setInput(input);
if (input instanceof DawnEditorInput)
{
CDOResource resource = ((DawnEditorInput)input).getResource();
URI uri = URI.createURI(((DawnEditorInput)input).getURI().toString());
if (resource == null || resource.cdoView() == null)
{
ResourceSet resourceSet = editingDomain.getResourceSet();
CDOTransaction transaction = CDOConnectionUtil.instance.openCurrentTransaction(resourceSet, uri.toString());
resource = (CDOResource)resourceSet.getResource(uri, true);
if (resource == null || resource.cdoView() == null)
{
resource = transaction.getOrCreateResource(uri.toString());
}
}
((DawnEditorInput)input).setResource(resource);
dawnEditorSupport.setView(((DawnEditorInput)input).getView());
dawnEditorSupport.registerListeners();
}
}
@Override
public void createPages()
{
super.createPages();
selectionViewer.setContentProvider(new DawnSelectionViewerAdapterFactoryContentProvider(adapterFactory,
((DawnEditorInput)getEditorInput()).getResource()));
selectionViewer
.setLabelProvider(new DawnLabelProvider(adapterFactory, dawnEditorSupport.getView(), selectionViewer));
parentViewer.setLabelProvider(new DawnLabelProvider(adapterFactory, dawnEditorSupport.getView(), selectionViewer));
listViewer.setLabelProvider(new DawnLabelProvider(adapterFactory, dawnEditorSupport.getView(), selectionViewer));
treeViewer.setLabelProvider(new DawnLabelProvider(adapterFactory, dawnEditorSupport.getView(), selectionViewer));
tableViewer.setLabelProvider(new DawnLabelProvider(adapterFactory, dawnEditorSupport.getView(), selectionViewer));
treeViewerWithColumns.setLabelProvider(new DawnLabelProvider(adapterFactory, dawnEditorSupport.getView(),
selectionViewer));
CDOResource resource = ((DawnEditorInput)getEditorInput()).getResource();
selectionViewer.setInput(resource.getResourceSet());
selectionViewer.setSelection(new StructuredSelection(resource), true);
parentViewer.setContentProvider(new ReverseAdapterFactoryContentProvider(adapterFactory));
}
@Override
public void doSave(IProgressMonitor progressMonitor)
{
CDOView view = dawnEditorSupport.getView();
if (view instanceof CDOTransaction)
{
if (view.hasConflict())
{
MessageDialog.openError(Display.getDefault().getActiveShell(), "conflict",
"Your Resource is in conflict and cannot be committed");
}
else
{
super.doSave(progressMonitor);
}
}
}
public String getContributorID()
{
return null;
}
public CDOView getView()
{
return dawnEditorSupport.getView();
}
public void setDirty()
{
dawnEditorSupport.setDirty(true);
}
@Override
public void dispose()
{
try
{
super.dispose();
}
finally
{
dawnEditorSupport.close();
}
}
public String getContributorId()
{
return ID;
}
public IDawnEditorSupport getDawnEditorSupport()
{
return dawnEditorSupport;
}
}
«ENDFILE»
«ENDDEFINE»
«REM»############################################ Extended Wizard ##################################################################«ENDREM»
«DEFINE dawnWizard FOR DawnEMFGenerator»
«FILE "src/"+getDiagramPackagePath()+"/presentation/"+"Dawn"+this.emfGenModel.modelName+"ModelWizard.java"»
package «this.emfGenModel.modelPluginID».presentation;
import org.eclipse.emf.cdo.dawn.preferences.PreferenceConstants;
import org.eclipse.emf.cdo.dawn.ui.DawnEditorInput;
import org.eclipse.emf.cdo.dawn.ui.wizards.DawnCreateNewResourceWizardPage;
import org.eclipse.emf.cdo.dawn.util.connection.CDOConnectionUtil;
import org.eclipse.emf.cdo.eresource.CDOResource;
import org.eclipse.emf.cdo.session.CDOSession;
import org.eclipse.emf.cdo.transaction.CDOTransaction;
import org.eclipse.emf.cdo.view.CDOView;
import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.resource.ResourceSet;
import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.ui.INewWizard;
import org.eclipse.ui.IWorkbenchPage;
import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.ui.PartInitException;
import org.eclipse.ui.actions.WorkspaceModifyOperation;
import java.util.Collections;
public class Dawn«this.emfGenModel.modelName»ModelWizard extends «this.emfGenModel.modelName»ModelWizard implements INewWizard
{
private DawnCreateNewResourceWizardPage newResourceCreationPage;
private CDOView view;
private CDOResource resource;
public Dawn«this.emfGenModel.modelName»ModelWizard()
{
super();
CDOConnectionUtil.instance.init(PreferenceConstants.getRepositoryName(), PreferenceConstants.getProtocol(),
PreferenceConstants.getServerName());
CDOSession session = CDOConnectionUtil.instance.openSession();
view = CDOConnectionUtil.instance.openView(session);
}
@Override
public void addPages()
{
newResourceCreationPage = new DawnCreateNewResourceWizardPage("«getEMFFileName(this.emfGenModel.genPackages)»", true, view);
addPage(newResourceCreationPage);
initialObjectCreationPage = new «this.emfGenModel.modelName»ModelWizardInitialObjectCreationPage("Whatever2");
initialObjectCreationPage.setTitle(«this.emfGenModel.modelName»EditorPlugin.INSTANCE.getString("_UI_«this.emfGenModel.modelName»ModelWizard_label"));
initialObjectCreationPage.setDescription(«this.emfGenModel.modelName»EditorPlugin.INSTANCE
.getString("_UI_Wizard_initial_object_description"));
addPage(initialObjectCreationPage);
}
@Override
public boolean performFinish()
{
try
{
// Do the work within an operation.
//
WorkspaceModifyOperation operation = new WorkspaceModifyOperation()
{
@Override
protected void execute(IProgressMonitor progressMonitor)
{
try
{
ResourceSet resourceSet = new ResourceSetImpl();
URI resourceURI = newResourceCreationPage.getURI();
CDOTransaction transaction = CDOConnectionUtil.instance.openCurrentTransaction(resourceSet,
resourceURI.toString());
resource = transaction.getOrCreateResource(resourceURI.path());
EObject rootObject = createInitialModel();
if (rootObject != null)
{
resource.getContents().add(rootObject);
}
resource.save(Collections.EMPTY_MAP);
transaction.close();
}
catch (Exception exception)
{
«this.emfGenModel.modelName»EditorPlugin.INSTANCE.log(exception);
throw new RuntimeException(exception);
}
finally
{
progressMonitor.done();
}
}
};
getContainer().run(false, false, operation);
openEditor(newResourceCreationPage.getURI());
return true;
}
catch (Exception exception)
{
«this.emfGenModel.modelName»EditorPlugin.INSTANCE.log(exception);
return false;
}
}
private void openEditor(URI uri)
{
IWorkbenchWindow workbenchWindow = workbench.getActiveWorkbenchWindow();
IWorkbenchPage page = workbenchWindow.getActivePage();
DawnEditorInput dawnEditorInput = new DawnEditorInput(uri);
try
{
page.openEditor(dawnEditorInput, «this.dawnEditorClassName».ID);
}
catch (PartInitException exception)
{
MessageDialog.openError(workbenchWindow.getShell(),
«this.emfGenModel.modelName»EditorPlugin.INSTANCE.getString("_UI_OpenEditorError_label"), exception.getMessage());
throw new RuntimeException(exception);
}
}
}
«ENDFILE»
«ENDDEFINE»
«REM»########################################## fragment.xml ####################################################################«ENDREM»
«DEFINE fragmentXML FOR DawnEMFGenerator»
«FILE "fragment.xml"»
A Dawn editor for «this.emfGenModel.modelName» models
«ENDFILE»
«ENDDEFINE»
«REM»##############################################################################################################«ENDREM»
«DEFINE manifestMF FOR DawnEMFGenerator»
«FILE "META-INF/MANIFEST.MF"»Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: Dawn
Bundle-SymbolicName: «this.fragmentName»;singleton:=true
Bundle-Version: 1.0.0.qualifier
Fragment-Host: «this.emfGenModel.editorPluginID»
Bundle-RequiredExecutionEnvironment: J2SE-1.5
Require-Bundle: org.eclipse.emf.cdo.dawn;bundle-version="[1.0.0,2.0.0)",
org.eclipse.emf.cdo.dawn.ui;bundle-version="[1.0.0,2.0.0)",
org.eclipse.emf.cdo.dawn.util;bundle-version="[1.0.0,2.0.0)",
org.eclipse.emf.cdo.ui;bundle-version="[4.0.0,5.0.0)"
«ENDFILE»
«ENDDEFINE»
«DEFINE buildPROPERTIES FOR DawnEMFGenerator»
«FILE "build.properties"»source.. = src/
output.. = bin/
bin.includes = META-INF/,\
.,\
fragment.xml
«ENDFILE»
«ENDDEFINE»
«REM»################################### . classpath ###########################################################################«ENDREM»
«DEFINE classpath FOR DawnEMFGenerator»
«FILE ".classpath"»
«ENDFILE»
«ENDDEFINE»