Skip to main content
summaryrefslogtreecommitdiffstats
blob: b13dc94cd6ff788513c8762865e9c145f6edcf6d (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
«REM»
 Copyright (c) 2004 - 2011 Eike Stepper (Berlin, Germany) and others.
 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 emf»
«IMPORT genmodel»
«IMPORT ecore»
«IMPORT dawngenmodel»
«IMPORT dawnEmfGenmodel»

«EXTENSION org::eclipse::emf::cdo::dawn::codegen::util::Utils»

«DEFINE main FOR DawnEMFGenerator»
  
  «setDiagramPackage(this.emfGenModel.modelPluginID)»
  
  «EXPAND dawnEditor FOR this»
  «EXPAND dawnWizard FOR this»
  «EXPAND fragmentXML FOR this»
  «EXPAND manifestMF FOR this»
  «EXPAND buildPROPERTIES FOR this»
  «EXPAND classpath FOR this»
«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"»<?xml version="1.0" encoding="UTF-8"?>
<?eclipse version="3.4"?>
<fragment>
   <extension point="org.eclipse.ui.newWizards">
      <wizard
            id="«this.emfGenModel.modelPluginID».presentation.Dawn«this.emfGenModel.modelName»ModelWizardID"
            name="Dawn «this.emfGenModel.modelName» Model"
            class="«this.emfGenModel.modelPluginID».presentation.Dawn«this.emfGenModel.modelName»ModelWizard"
            category="org.eclipse.emf.cdo.dawn.ui.category.examples"
            icon="platform:/plugin/«this.emfGenModel.editPluginID»/icons/full/obj16/«this.emfGenModel.modelName»ModelFile.gif">
         <description>A Dawn editor for «this.emfGenModel.modelName» models</description>
         <selection class="org.eclipse.core.resources.IResource"/>
      </wizard>
   </extension>

   <extension point="org.eclipse.ui.editors">
      <editor
            id="«this.emfGenModel.modelPluginID».presentation.«this.dawnEditorClassName»ID"
            name="Dawn «this.emfGenModel.modelName» model Editor"
            icon="platform:/plugin/«this.emfGenModel.editPluginID»/icons/full/obj16/«this.emfGenModel.modelName»ModelFile.gif"
            extensions="«getEMFFileName(this.emfGenModel.genPackages)»"
            class="«this.emfGenModel.modelPluginID».presentation.«this.dawnEditorClassName»"
            contributorClass="«this.emfGenModel.modelPluginID».presentation.«this.emfGenModel.modelName»ActionBarContributor">
      </editor>
   </extension>
</fragment>

«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"»<?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>
«ENDFILE»
«ENDDEFINE»

Back to the top