Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 516288b8fde74a2590ecf37ff1aef148b0e04dda (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
/*
 * Copyright (c) 2010-2013, 2015 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
 *    Christian W. Damus (CEA) - bug 399933 NPE in editor when finishing Ecore wizard
 */
package org.eclipse.emf.cdo.dawn.ecore.presentation;

import org.eclipse.emf.cdo.dawn.editors.IDawnEditor;
import org.eclipse.emf.cdo.dawn.editors.IDawnEditorSupport;
import org.eclipse.emf.cdo.dawn.emf.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.presentation.EcoreEditor;
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 DawnEcoreEditor extends EcoreEditor implements IDawnEditor
{
  private IDawnEditorSupport dawnEditorSupport;

  public static String ID = "org.eclipse.emf.cdo.dawn.ecore.presentation.DawnEcoreEditorID";

  public DawnEcoreEditor()
  {
    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();

    if (!(getEditorInput() instanceof DawnEditorInput))
    {
      return;
    }

    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);
      }
    }
    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;
  }
}

Back to the top