protected Viewer currentViewer; /** * This listens to which ever viewer is active. * <!-- begin-user-doc --> * <!-- end-user-doc --> * @generated */ protected ISelectionChangedListener selectionChangedListener; /** * This keeps track of all the {@link org.eclipse.jface.viewers.ISelectionChangedListener}s that are listening to this editor. * <!-- begin-user-doc --> * <!-- end-user-doc --> * @generated */ protected Collection<ISelectionChangedListener> selectionChangedListeners = new ArrayList<ISelectionChangedListener>(); /** * This keeps track of the selection of the editor as a whole. * <!-- begin-user-doc --> * <!-- end-user-doc --> * @generated */ protected ISelection editorSelection = StructuredSelection.EMPTY; /** * The MarkerHelper is responsible for creating workspace resource markers presented * in Eclipse's Problems View. * <!-- begin-user-doc --> * <!-- end-user-doc --> * @generated */ protected MarkerHelper markerHelper = new EditUIMarkerHelper(); /** * This listens for when the outline becomes active * <!-- begin-user-doc --> * <!-- end-user-doc --> * @generated */ protected IPartListener partListener = new IPartListener() { public void partActivated(IWorkbenchPart p) { if (p instanceof ContentOutline) { if (((ContentOutline)p).getCurrentPage() == contentOutlinePage) { getActionBarContributor().setActiveEditor(EcoreEditor.this); setCurrentViewer(contentOutlineViewer); } } else if (p instanceof PropertySheet) { if (((PropertySheet)p).getCurrentPage() == propertySheetPage) { getActionBarContributor().setActiveEditor(EcoreEditor.this); handleActivate(); } } else if (p == EcoreEditor.this) { handleActivate(); } } public void partBroughtToTop(IWorkbenchPart p) { // Ignore. } public void partClosed(IWorkbenchPart p) { // Ignore. } public void partDeactivated(IWorkbenchPart p) { // Ignore. } public void partOpened(IWorkbenchPart p) { // Ignore. } }; /** * Resources that have been removed since last activation. * <!-- begin-user-doc --> * <!-- end-user-doc --> * @generated */ protected Collection<Resource> removedResources = new ArrayList<Resource>(); /** * Resources that have been changed since last activation. * <!-- begin-user-doc --> * <!-- end-user-doc --> * @generated */ protected Collection<Resource> changedResources = new ArrayList<Resource>(); /** * Resources that have been saved. * <!-- begin-user-doc --> * <!-- end-user-doc --> * @generated */ protected Collection<Resource> savedResources = new ArrayList<Resource>(); /** * Map to store the diagnostic associated with a resource. * <!-- begin-user-doc --> * <!-- end-user-doc --> * @generated */ protected Map<Resource, Diagnostic> resourceToDiagnosticMap = new LinkedHashMap<Resource, Diagnostic>(); /** * Controls whether the problem indication should be updated. * <!-- begin-user-doc --> * <!-- end-user-doc --> * @generated */ protected boolean updateProblemIndication = true; /** * Adapter used to update the problem indication when resources are demanded loaded. * <!-- begin-user-doc --> * <!-- end-user-doc --> * @generated */ protected EContentAdapter problemIndicationAdapter = new EContentAdapter() { @Override public void notifyChanged(Notification notification) { if (notification.getNotifier() instanceof Resource) { switch (notification.getFeatureID(Resource.class)) { case Resource.RESOURCE__IS_LOADED: case Resource.RESOURCE__ERRORS: case Resource.RESOURCE__WARNINGS: { Resource resource = (Resource)notification.getNotifier(); Diagnostic diagnostic = analyzeResourceProblems(resource, null); if (diagnostic.getSeverity() != Diagnostic.OK) { resourceToDiagnosticMap.put(resource, diagnostic); } else { resourceToDiagnosticMap.remove(resource); } if (updateProblemIndication) { getSite().getShell().getDisplay().asyncExec (new Runnable() { public void run() { updateProblemIndication(); } }); } break; } } } else { super.notifyChanged(notification); } } @Override protected void setTarget(Resource target) { basicSetTarget(target); } @Override protected void unsetTarget(Resource target) { basicUnsetTarget(target); } }; /** * This listens for workspace changes. * <!-- begin-user-doc --> * <!-- end-user-doc --> * @generated */ protected IResourceChangeListener resourceChangeListener = new IResourceChangeListener() { public void resourceChanged(IResourceChangeEvent event) { IResourceDelta delta = event.getDelta(); try { class ResourceDeltaVisitor implements IResourceDeltaVisitor { protected ResourceSet resourceSet = editingDomain.getResourceSet(); protected Collection<Resource> changedResources = new ArrayList<Resource>(); protected Collection<Resource> removedResources = new ArrayList<Resource>(); public boolean visit(IResourceDelta delta) { if (delta.getResource().getType() == IResource.FILE) { if (delta.getKind() == IResourceDelta.REMOVED || delta.getKind() == IResourceDelta.CHANGED && delta.getFlags() != IResourceDelta.MARKERS) { Resource resource = resourceSet.getResource(URI.createURI(delta.getFullPath().toString()), false); if (resource != null) { if (delta.getKind() == IResourceDelta.REMOVED) { removedResources.add(resource); } else if (!savedResources.remove(resource)) { changedResources.add(resource); } } } } return true; } public Collection<Resource> getChangedResources() { return changedResources; } public Collection<Resource> getRemovedResources() { return removedResources; } } ResourceDeltaVisitor visitor = new ResourceDeltaVisitor(); delta.accept(visitor); if (!visitor.getRemovedResources().isEmpty()) { removedResources.addAll(visitor.getRemovedResources()); if (!isDirty()) { getSite().getShell().getDisplay().asyncExec (new Runnable() { public void run() { getSite().getPage().closeEditor(EcoreEditor.this, false); } }); } } if (!visitor.getChangedResources().isEmpty()) { changedResources.addAll(visitor.getChangedResources()); if (getSite().getPage().getActiveEditor() == EcoreEditor.this) { getSite().getShell().getDisplay().asyncExec (new Runnable() { public void run() { handleActivate(); } }); } } } catch (CoreException exception) { EcoreEditorPlugin.INSTANCE.log(exception); } } }; /** * Handles activation of the editor or it's associated views. * <!-- begin-user-doc --> * <!-- end-user-doc --> * @generated */ protected void handleActivate() { // Recompute the read only state. // if (editingDomain.getResourceToReadOnlyMap() != null) { editingDomain.getResourceToReadOnlyMap().clear(); // Refresh any actions that may become enabled or disabled. // setSelection(getSelection()); } if (!removedResources.isEmpty()) { if (handleDirtyConflict()) { getSite().getPage().closeEditor(EcoreEditor.this, false); } else { removedResources.clear(); changedResources.clear(); savedResources.clear(); } } else if (!changedResources.isEmpty()) { changedResources.removeAll(savedResources); handleChangedResources(); changedResources.clear(); savedResources.clear(); } } /** * Handles what to do with changed resources on activation. * <!-- begin-user-doc --> * <!-- end-user-doc --> * @generated */ protected void handleChangedResources() { if (!changedResources.isEmpty() && (!isDirty() || handleDirtyConflict())) { if (isDirty()) { changedResources.addAll(editingDomain.getResourceSet().getResources()); } editingDomain.getCommandStack().flush(); updateProblemIndication = false; for (Resource resource : changedResources) { if (resource.isLoaded()) { resource.unload(); try { resource.load(Collections.EMPTY_MAP); } catch (IOException exception) { if (!resourceToDiagnosticMap.containsKey(resource)) { resourceToDiagnosticMap.put(resource, analyzeResourceProblems(resource, exception)); } } } } if (AdapterFactoryEditingDomain.isStale(editorSelection)) { setSelection(StructuredSelection.EMPTY); } updateProblemIndication = true; updateProblemIndication(); } } /** * Updates the problems indication with the information described in the specified diagnostic. * <!-- begin-user-doc --> * <!-- end-user-doc --> * @generated */ protected void updateProblemIndication() { if (updateProblemIndication) { BasicDiagnostic diagnostic = new BasicDiagnostic (Diagnostic.OK, "org.eclipse.emf.ecore.editor", 0, null, new Object [] { editingDomain.getResourceSet() }); for (Diagnostic childDiagnostic : resourceToDiagnosticMap.values()) { if (childDiagnostic.getSeverity() != Diagnostic.OK) { diagnostic.add(childDiagnostic); } } int lastEditorPage = getPageCount() - 1; if (lastEditorPage >= 0 && getEditor(lastEditorPage) instanceof ProblemEditorPart) { ((ProblemEditorPart)getEditor(lastEditorPage)).setDiagnostic(diagnostic); if (diagnostic.getSeverity() != Diagnostic.OK) { setActivePage(lastEditorPage); } } else if (diagnostic.getSeverity() != Diagnostic.OK) { ProblemEditorPart problemEditorPart = new ProblemEditorPart(); problemEditorPart.setDiagnostic(diagnostic); problemEditorPart.setMarkerHelper(markerHelper); try { addPage(++lastEditorPage, problemEditorPart, getEditorInput()); setPageText(lastEditorPage, problemEditorPart.getPartName()); setActivePage(lastEditorPage); showTabs(); } catch (PartInitException exception) { EcoreEditorPlugin.INSTANCE.log(exception); } } if (markerHelper.hasMarkers(editingDomain.getResourceSet())) { markerHelper.deleteMarkers(editingDomain.getResourceSet()); if (diagnostic.getSeverity() != Diagnostic.OK) { try { markerHelper.createMarkers(diagnostic); } catch (CoreException exception) { EcoreEditorPlugin.INSTANCE.log(exception); } } } } } /** * Shows a dialog that asks if conflicting changes should be discarded. * <!-- begin-user-doc --> * <!-- end-user-doc --> * @generated */ protected boolean handleDirtyConflict() { return MessageDialog.openQuestion (getSite().getShell(), getString("_UI_FileConflict_label"), getString("_WARN_FileConflict")); } /** * This creates a model editor. * <!-- begin-user-doc --> * <!-- end-user-doc --> * @generated */ public EcoreEditor() { super(); initializeEditingDomain();
protected Viewer currentViewer; /** * This listens to which ever viewer is active. * <!-- begin-user-doc --> * <!-- end-user-doc --> * @generated */ protected ISelectionChangedListener selectionChangedListener; /** * This keeps track of all the {@link org.eclipse.jface.viewers.ISelectionChangedListener}s that are listening to this editor. * <!-- begin-user-doc --> * <!-- end-user-doc --> * @generated */ protected Collection<ISelectionChangedListener> selectionChangedListeners = new ArrayList<ISelectionChangedListener>(); /** * This keeps track of the selection of the editor as a whole. * <!-- begin-user-doc --> * <!-- end-user-doc --> * @generated */ protected ISelection editorSelection = StructuredSelection.EMPTY; /** * The MarkerHelper is responsible for creating workspace resource markers presented * in Eclipse's Problems View. * <!-- begin-user-doc --> * <!-- end-user-doc --> * @generated */ protected MarkerHelper markerHelper = new EditUIMarkerHelper(); /** * This listens for when the outline becomes active * <!-- begin-user-doc --> * <!-- end-user-doc --> * @generated */ protected IPartListener partListener = new IPartListener() { public void partActivated(IWorkbenchPart p) { if (p instanceof ContentOutline) { if (((ContentOutline)p).getCurrentPage() == contentOutlinePage) { getActionBarContributor().setActiveEditor(Ecore2XMLEditor.this); setCurrentViewer(contentOutlineViewer); } } else if (p instanceof PropertySheet) { if (((PropertySheet)p).getCurrentPage() == propertySheetPage) { getActionBarContributor().setActiveEditor(Ecore2XMLEditor.this); handleActivate(); } } else if (p == Ecore2XMLEditor.this) { handleActivate(); } } public void partBroughtToTop(IWorkbenchPart p) { // Ignore. } public void partClosed(IWorkbenchPart p) { // Ignore. } public void partDeactivated(IWorkbenchPart p) { // Ignore. } public void partOpened(IWorkbenchPart p) { // Ignore. } }; /** * Resources that have been removed since last activation. * @generated */ protected Collection<Resource> removedResources = new ArrayList<Resource>(); /** * Resources that have been changed since last activation. * @generated */ protected Collection<Resource> changedResources = new ArrayList<Resource>(); /** * Resources that have been saved. * @generated */ protected Collection<Resource> savedResources = new ArrayList<Resource>(); /** * Map to store the diagnostic associated with a resource. * <!-- begin-user-doc --> * <!-- end-user-doc --> * @generated */ protected Map<Resource, Diagnostic> resourceToDiagnosticMap = new LinkedHashMap<Resource, Diagnostic>(); /** * Controls whether the problem indication should be updated. * <!-- begin-user-doc --> * <!-- end-user-doc --> * @generated */ protected boolean updateProblemIndication = true; /** * Adapter used to update the problem indication when resources are demanded loaded. * <!-- begin-user-doc --> * <!-- end-user-doc --> * @generated */ protected EContentAdapter problemIndicationAdapter = new EContentAdapter() { @Override public void notifyChanged(Notification notification) { if (notification.getNotifier() instanceof Resource) { switch (notification.getFeatureID(Resource.class)) { case Resource.RESOURCE__IS_LOADED: case Resource.RESOURCE__ERRORS: case Resource.RESOURCE__WARNINGS: { Resource resource = (Resource)notification.getNotifier(); Diagnostic diagnostic = analyzeResourceProblems(resource, null); if (diagnostic.getSeverity() != Diagnostic.OK) { resourceToDiagnosticMap.put(resource, diagnostic); } else { resourceToDiagnosticMap.remove(resource); } if (updateProblemIndication) { getSite().getShell().getDisplay().asyncExec (new Runnable() { public void run() { updateProblemIndication(); } }); } break; } } } else { super.notifyChanged(notification); } } @Override protected void setTarget(Resource target) { basicSetTarget(target); } @Override protected void unsetTarget(Resource target) { basicUnsetTarget(target); } }; /** * This listens for workspace changes. * <!-- begin-user-doc --> * <!-- end-user-doc --> * @generated */ protected IResourceChangeListener resourceChangeListener = new IResourceChangeListener() { public void resourceChanged(IResourceChangeEvent event) { IResourceDelta delta = event.getDelta(); try { class ResourceDeltaVisitor implements IResourceDeltaVisitor { protected ResourceSet resourceSet = editingDomain.getResourceSet(); protected Collection<Resource> changedResources = new ArrayList<Resource>(); protected Collection<Resource> removedResources = new ArrayList<Resource>(); public boolean visit(IResourceDelta delta) { if (delta.getResource().getType() == IResource.FILE) { if (delta.getKind() == IResourceDelta.REMOVED || delta.getKind() == IResourceDelta.CHANGED && delta.getFlags() != IResourceDelta.MARKERS) { Resource resource = resourceSet.getResource(URI.createURI(delta.getFullPath().toString()), false); if (resource != null) { if (delta.getKind() == IResourceDelta.REMOVED) { removedResources.add(resource); } else if (!savedResources.remove(resource)) { changedResources.add(resource); } } } } return true; } public Collection<Resource> getChangedResources() { return changedResources; } public Collection<Resource> getRemovedResources() { return removedResources; } } ResourceDeltaVisitor visitor = new ResourceDeltaVisitor(); delta.accept(visitor); if (!visitor.getRemovedResources().isEmpty()) { removedResources.addAll(visitor.getRemovedResources()); if (!isDirty()) { getSite().getShell().getDisplay().asyncExec (new Runnable() { public void run() { getSite().getPage().closeEditor(Ecore2XMLEditor.this, false); } }); } } if (!visitor.getChangedResources().isEmpty()) { changedResources.addAll(visitor.getChangedResources()); if (getSite().getPage().getActiveEditor() == Ecore2XMLEditor.this) { getSite().getShell().getDisplay().asyncExec (new Runnable() { public void run() { handleActivate(); } }); } } } catch (CoreException exception) { Ecore2XMLUIPlugin.INSTANCE.log(exception); } } }; /** * Handles activation of the editor or it's associated views. * @generated */ protected void handleActivate() { // Recompute the read only state. // if (editingDomain.getResourceToReadOnlyMap() != null) { editingDomain.getResourceToReadOnlyMap().clear(); // Refresh any actions that may become enabled or disabled. // setSelection(getSelection()); } if (!removedResources.isEmpty()) { if (handleDirtyConflict()) { getSite().getPage().closeEditor(Ecore2XMLEditor.this, false); } else { removedResources.clear(); changedResources.clear(); savedResources.clear(); } } else if (!changedResources.isEmpty()) { changedResources.removeAll(savedResources); handleChangedResources(); changedResources.clear(); savedResources.clear(); } } /** * Handles what to do with changed resources on activation. * @generated */ protected void handleChangedResources() { if (!changedResources.isEmpty() && (!isDirty() || handleDirtyConflict())) { if (isDirty()) { changedResources.addAll(editingDomain.getResourceSet().getResources()); } editingDomain.getCommandStack().flush(); updateProblemIndication = false; for (Resource resource : changedResources) { if (resource.isLoaded()) { resource.unload(); try { resource.load(Collections.EMPTY_MAP); } catch (IOException exception) { if (!resourceToDiagnosticMap.containsKey(resource)) { resourceToDiagnosticMap.put(resource, analyzeResourceProblems(resource, exception)); } } } } if (AdapterFactoryEditingDomain.isStale(editorSelection)) { setSelection(StructuredSelection.EMPTY); } updateProblemIndication = true; updateProblemIndication(); } } /** * Updates the problems indication with the information described in the specified diagnostic. * <!-- begin-user-doc --> * <!-- end-user-doc --> * @generated */ protected void updateProblemIndication() { if (updateProblemIndication) { BasicDiagnostic diagnostic = new BasicDiagnostic (Diagnostic.OK, "org.eclipse.emf.mapping.ecore2xml.edit", //$NON-NLS-1$ 0, null, new Object [] { editingDomain.getResourceSet() }); for (Diagnostic childDiagnostic : resourceToDiagnosticMap.values()) { if (childDiagnostic.getSeverity() != Diagnostic.OK) { diagnostic.add(childDiagnostic); } } int lastEditorPage = getPageCount() - 1; if (lastEditorPage >= 0 && getEditor(lastEditorPage) instanceof ProblemEditorPart) { ((ProblemEditorPart)getEditor(lastEditorPage)).setDiagnostic(diagnostic); if (diagnostic.getSeverity() != Diagnostic.OK) { setActivePage(lastEditorPage); } } else if (diagnostic.getSeverity() != Diagnostic.OK) { ProblemEditorPart problemEditorPart = new ProblemEditorPart(); problemEditorPart.setDiagnostic(diagnostic); problemEditorPart.setMarkerHelper(markerHelper); try { addPage(++lastEditorPage, problemEditorPart, getEditorInput()); setPageText(lastEditorPage, problemEditorPart.getPartName()); setActivePage(lastEditorPage); showTabs(); } catch (PartInitException exception) { Ecore2XMLUIPlugin.INSTANCE.log(exception); } } if (markerHelper.hasMarkers(editingDomain.getResourceSet())) { markerHelper.deleteMarkers(editingDomain.getResourceSet()); if (diagnostic.getSeverity() != Diagnostic.OK) { try { markerHelper.createMarkers(diagnostic); } catch (CoreException exception) { Ecore2XMLUIPlugin.INSTANCE.log(exception); } } } } } /** * Shows a dialog that asks if conflicting changes should be discarded. * @generated */ protected boolean handleDirtyConflict() { return MessageDialog.openQuestion (getSite().getShell(), getString("_UI_FileConflict_label"), //$NON-NLS-1$ getString("_WARN_FileConflict")); //$NON-NLS-1$ } /** * This creates a model editor. * <!-- begin-user-doc --> * <!-- end-user-doc --> * @generated */ public Ecore2XMLEditor() { super(); initializeEditingDomain();
Clone fragments detected by clone detection tool
File path: /emf-2.4.1/src/org/eclipse/emf/ecore/presentation/EcoreEditor.java File path: /emf-2.4.1/src/org/eclipse/emf/mapping/ecore2xml/presentation/Ecore2XMLEditor.java
Method name: Method name:
Number of AST nodes: 0 Number of AST nodes: 0
1
protected Viewer currentViewer;
1
protected Viewer currentViewer;
2
  /**
2
  /**
3
   * This listens to which ever viewer is active.
3
   * This listens to which ever viewer is active.
4
   * <!-- begin-user-doc -->
4
   * <!-- begin-user-doc -->
5
   * <!-- end-user-doc -->
5
   * <!-- end-user-doc -->
6
   * @generated
6
   * @generated
7
   */
7
   */
8
  protected ISelectionChangedListener selectionChangedListener;
8
  protected ISelectionChangedListener selectionChangedListener;
9
  /**
9
  /**
10
   * This keeps track of all the {@link org.eclipse.jface.viewers.ISelectionChangedListener}s that are listening to this editor.
10
   * This keeps track of all the {@link org.eclipse.jface.viewers.ISelectionChangedListener}s that are listening to this editor.
11
   * <!-- begin-user-doc -->
11
   * <!-- begin-user-doc -->
12
   * <!-- end-user-doc -->
12
   * <!-- end-user-doc -->
13
   * @generated
13
   * @generated
14
   */
14
   */
15
  protected Collection<ISelectionChangedListener> selectionChangedListeners = new ArrayList<ISelectionChangedListener>();
15
  protected Collection<ISelectionChangedListener> selectionChangedListeners = new ArrayList<ISelectionChangedListener>();
16
  /**
16
  /**
17
   * This keeps track of the selection of the editor as a whole.
17
   * This keeps track of the selection of the editor as a whole.
18
   * <!-- begin-user-doc -->
18
   * <!-- begin-user-doc -->
19
   * <!-- end-user-doc -->
19
   * <!-- end-user-doc -->
20
   * @generated
20
   * @generated
21
   */
21
   */
22
  protected ISelection editorSelection = StructuredSelection.EMPTY;
22
  protected ISelection editorSelection = StructuredSelection.EMPTY;
23
  /**
23
  /**
24
   * The MarkerHelper is responsible for creating workspace resource markers presented
24
   * The MarkerHelper is responsible for creating workspace resource markers presented
25
   * in Eclipse's Problems View.
25
   * in Eclipse's Problems View.
26
   * <!-- begin-user-doc -->
26
   * <!-- begin-user-doc -->
27
   * <!-- end-user-doc -->
27
   * <!-- end-user-doc -->
28
   * @generated
28
   * @generated
29
   */
29
   */
30
  protected MarkerHelper markerHelper = new EditUIMarkerHelper();
30
  protected MarkerHelper markerHelper = new EditUIMarkerHelper();
31
  /**
31
  /**
32
   * This listens for when the outline becomes active
32
   * This listens for when the outline becomes active
33
   * <!-- begin-user-doc -->
33
   * <!-- begin-user-doc -->
34
   * <!-- end-user-doc -->
34
   * <!-- end-user-doc -->
35
   * @generated
35
   * @generated
36
   */
36
   */
37
  protected IPartListener partListener =
37
  protected IPartListener partListener =
38
    new IPartListener()
38
    new IPartListener()
39
    {
39
    {
40
      public void partActivated(IWorkbenchPart p)
40
      public void partActivated(IWorkbenchPart p)
41
      {
41
      {
42
        if (p instanceof ContentOutline)
42
        if (p instanceof ContentOutline)
43
        {
43
        {
44
          if (((ContentOutline)p).getCurrentPage() == contentOutlinePage)
44
          if (((ContentOutline)p).getCurrentPage() == contentOutlinePage)
45
          {
45
          {
46
            getActionBarContributor().setActiveEditor(EcoreEditor.this);
46
            getActionBarContributor().setActiveEditor(Ecore2XMLEditor.this);
47
            setCurrentViewer(contentOutlineViewer);
47
            setCurrentViewer(contentOutlineViewer);
48
          }
48
          }
49
        }
49
        }
50
        else if (p instanceof PropertySheet)
50
        else if (p instanceof PropertySheet)
51
        {
51
        {
52
          if (((PropertySheet)p).getCurrentPage() == propertySheetPage)
52
          if (((PropertySheet)p).getCurrentPage() == propertySheetPage)
53
          {
53
          {
54
            getActionBarContributor().setActiveEditor(EcoreEditor.this);
54
            getActionBarContributor().setActiveEditor(Ecore2XMLEditor.this);
55
            handleActivate();
55
            handleActivate();
56
          }
56
          }
57
        }
57
        }
58
        else if (p == EcoreEditor.this)
58
        else if (p == Ecore2XMLEditor.this)
59
        {
59
        {
60
          handleActivate();
60
          handleActivate();
61
        }
61
        }
62
      }
62
      }
63
      public void partBroughtToTop(IWorkbenchPart p)
63
      public void partBroughtToTop(IWorkbenchPart p)
64
      {
64
      {
65
        // Ignore.
65
        // Ignore.
66
      }
66
      }
67
      public void partClosed(IWorkbenchPart p)
67
      public void partClosed(IWorkbenchPart p)
68
      {
68
      {
69
        // Ignore.
69
        // Ignore.
70
      }
70
      }
71
      public void partDeactivated(IWorkbenchPart p)
71
      public void partDeactivated(IWorkbenchPart p)
72
      {
72
      {
73
        // Ignore.
73
        // Ignore.
74
      }
74
      }
75
      public void partOpened(IWorkbenchPart p)
75
      public void partOpened(IWorkbenchPart p)
76
      {
76
      {
77
        // Ignore.
77
        // Ignore.
78
      }
78
      }
79
    };
79
    };
80
  /**
80
  /**
81
   * Resources that have been removed since last activation.
81
   * Resources that have been removed since last activation.
82
   * <!-- begin-user-doc -->
83
   * <!-- end-user-doc -->
84
   * @generated
82
   * @generated
85
   */
83
   */
86
  protected Collection<Resource> removedResources = new ArrayList<Resource>();
84
  protected Collection<Resource> removedResources = new ArrayList<Resource>();
87
  /**
85
  /**
88
   * Resources that have been changed since last activation.
86
   * Resources that have been changed since last activation.
89
   * <!-- begin-user-doc -->
90
   * <!-- end-user-doc -->
91
   * @generated
87
   * @generated
92
   */
88
   */
93
  protected Collection<Resource> changedResources = new ArrayList<Resource>();
89
  protected Collection<Resource> changedResources = new ArrayList<Resource>();
94
  /**
90
  /**
95
   * Resources that have been saved.
91
   * Resources that have been saved.
96
   * <!-- begin-user-doc -->
97
   * <!-- end-user-doc -->
98
   * @generated
92
   * @generated
99
   */
93
   */
100
  protected Collection<Resource> savedResources = new ArrayList<Resource>();
94
  protected Collection<Resource> savedResources = new ArrayList<Resource>();
101
  /**
95
  /**
102
   * Map to store the diagnostic associated with a resource.
96
   * Map to store the diagnostic associated with a resource.
103
   * <!-- begin-user-doc -->
97
   * <!-- begin-user-doc -->
104
   * <!-- end-user-doc -->
98
   * <!-- end-user-doc -->
105
   * @generated
99
   * @generated
106
   */
100
   */
107
  protected Map<Resource, Diagnostic> resourceToDiagnosticMap = new LinkedHashMap<Resource, Diagnostic>();
101
  protected Map<Resource, Diagnostic> resourceToDiagnosticMap = new LinkedHashMap<Resource, Diagnostic>();
108
  /**
102
  /**
109
   * Controls whether the problem indication should be updated.
103
   * Controls whether the problem indication should be updated.
110
   * <!-- begin-user-doc -->
104
   * <!-- begin-user-doc -->
111
   * <!-- end-user-doc -->
105
   * <!-- end-user-doc -->
112
   * @generated
106
   * @generated
113
   */
107
   */
114
  protected boolean updateProblemIndication = true;
108
  protected boolean updateProblemIndication = true;
115
  /**
109
  /**
116
   * Adapter used to update the problem indication when resources are demanded loaded.
110
   * Adapter used to update the problem indication when resources are demanded loaded.
117
   * <!-- begin-user-doc -->
111
   * <!-- begin-user-doc -->
118
   * <!-- end-user-doc -->
112
   * <!-- end-user-doc -->
119
   * @generated
113
   * @generated
120
   */
114
   */
121
  protected EContentAdapter problemIndicationAdapter = 
115
  protected EContentAdapter problemIndicationAdapter = 
122
    new EContentAdapter()
116
    new EContentAdapter()
123
    {
117
    {
124
      @Override
118
      @Override
125
      public void notifyChanged(Notification notification)
119
      public void notifyChanged(Notification notification)
126
      {
120
      {
127
        if (notification.getNotifier() instanceof Resource)
121
        if (notification.getNotifier() instanceof Resource)
128
        {
122
        {
129
          switch (notification.getFeatureID(Resource.class))
123
          switch (notification.getFeatureID(Resource.class))
130
          {
124
          {
131
            case Resource.RESOURCE__IS_LOADED:
125
            case Resource.RESOURCE__IS_LOADED:
132
            case Resource.RESOURCE__ERRORS:
126
            case Resource.RESOURCE__ERRORS:
133
            case Resource.RESOURCE__WARNINGS:
127
            case Resource.RESOURCE__WARNINGS:
134
            {
128
            {
135
              Resource resource = (Resource)notification.getNotifier();
129
              Resource resource = (Resource)notification.getNotifier();
136
              Diagnostic diagnostic = analyzeResourceProblems(resource, null);
130
              Diagnostic diagnostic = analyzeResourceProblems(resource, null);
137
              if (diagnostic.getSeverity() != Diagnostic.OK)
131
              if (diagnostic.getSeverity() != Diagnostic.OK)
138
              {
132
              {
139
                resourceToDiagnosticMap.put(resource, diagnostic);
133
                resourceToDiagnosticMap.put(resource, diagnostic);
140
              }
134
              }
141
              else
135
              else
142
              {
136
              {
143
                resourceToDiagnosticMap.remove(resource);
137
                resourceToDiagnosticMap.remove(resource);
144
              }
138
              }
145
              if (updateProblemIndication)
139
              if (updateProblemIndication)
146
              {
140
              {
147
                getSite().getShell().getDisplay().asyncExec
141
                getSite().getShell().getDisplay().asyncExec
148
                  (new Runnable()
142
                  (new Runnable()
149
                   {
143
                   {
150
                     public void run()
144
                     public void run()
151
                     {
145
                     {
152
                       updateProblemIndication();
146
                       updateProblemIndication();
153
                     }
147
                     }
154
                   });
148
                   });
155
              }
149
              }
156
              break;
150
              break;
157
            }
151
            }
158
          }
152
          }
159
        }
153
        }
160
        else
154
        else
161
        {
155
        {
162
          super.notifyChanged(notification);
156
          super.notifyChanged(notification);
163
        }
157
        }
164
      }
158
      }
165
      @Override
159
      @Override
166
      protected void setTarget(Resource target)
160
      protected void setTarget(Resource target)
167
      {
161
      {
168
        basicSetTarget(target);
162
        basicSetTarget(target);
169
      }
163
      }
170
      @Override
164
      @Override
171
      protected void unsetTarget(Resource target)
165
      protected void unsetTarget(Resource target)
172
      {
166
      {
173
        basicUnsetTarget(target);
167
        basicUnsetTarget(target);
174
      }
168
      }
175
    };
169
    };
176
  /**
170
  /**
177
   * This listens for workspace changes.
171
   * This listens for workspace changes.
178
   * <!-- begin-user-doc -->
172
   * <!-- begin-user-doc -->
179
   * <!-- end-user-doc -->
173
   * <!-- end-user-doc -->
180
   * @generated
174
   * @generated
181
   */
175
   */
182
  protected IResourceChangeListener resourceChangeListener =
176
  protected IResourceChangeListener resourceChangeListener =
183
    new IResourceChangeListener()
177
    new IResourceChangeListener()
184
    {
178
    {
185
      public void resourceChanged(IResourceChangeEvent event)
179
      public void resourceChanged(IResourceChangeEvent event)
186
      {
180
      {
187
        IResourceDelta delta = event.getDelta();
181
        IResourceDelta delta = event.getDelta();
188
        try
182
        try
189
        {
183
        {
190
          class ResourceDeltaVisitor implements IResourceDeltaVisitor
184
          class ResourceDeltaVisitor implements IResourceDeltaVisitor
191
          {
185
          {
192
            protected ResourceSet resourceSet = editingDomain.getResourceSet();
186
            protected ResourceSet resourceSet = editingDomain.getResourceSet();
193
            protected Collection<Resource> changedResources = new ArrayList<Resource>();
187
            protected Collection<Resource> changedResources = new ArrayList<Resource>();
194
            protected Collection<Resource> removedResources = new ArrayList<Resource>();
188
            protected Collection<Resource> removedResources = new ArrayList<Resource>();
195
            public boolean visit(IResourceDelta delta)
189
            public boolean visit(IResourceDelta delta)
196
            {
190
            {
197
              if (delta.getResource().getType() == IResource.FILE)
191
              if (delta.getResource().getType() == IResource.FILE)
198
              {
192
              {
199
                if (delta.getKind() == IResourceDelta.REMOVED ||
193
                if (delta.getKind() == IResourceDelta.REMOVED ||
200
                    delta.getKind() == IResourceDelta.CHANGED && delta.getFlags() != IResourceDelta.MARKERS)
194
                    delta.getKind() == IResourceDelta.CHANGED && delta.getFlags() != IResourceDelta.MARKERS)
201
                {
195
                {
202
                  Resource resource = resourceSet.getResource(URI.createURI(delta.getFullPath().toString()), false);
196
                  Resource resource = resourceSet.getResource(URI.createURI(delta.getFullPath().toString()), false);
203
                  if (resource != null)
197
                  if (resource != null)
204
                  {
198
                  {
205
                    if (delta.getKind() == IResourceDelta.REMOVED)
199
                    if (delta.getKind() == IResourceDelta.REMOVED)
206
                    {
200
                    {
207
                      removedResources.add(resource);
201
                      removedResources.add(resource);
208
                    }
202
                    }
209
                    else if (!savedResources.remove(resource))
203
                    else if (!savedResources.remove(resource))
210
                    {
204
                    {
211
                      changedResources.add(resource);
205
                      changedResources.add(resource);
212
                    }
206
                    }
213
                  }
207
                  }
214
                }
208
                }
215
              }
209
              }
216
              return true;
210
              return true;
217
            }
211
            }
218
            public Collection<Resource> getChangedResources()
212
            public Collection<Resource> getChangedResources()
219
            {
213
            {
220
              return changedResources;
214
              return changedResources;
221
            }
215
            }
222
            public Collection<Resource> getRemovedResources()
216
            public Collection<Resource> getRemovedResources()
223
            {
217
            {
224
              return removedResources;
218
              return removedResources;
225
            }
219
            }
226
          }
220
          }
227
          ResourceDeltaVisitor visitor = new ResourceDeltaVisitor();
221
          ResourceDeltaVisitor visitor = new ResourceDeltaVisitor();
228
          delta.accept(visitor);
222
          delta.accept(visitor);
229
          if (!visitor.getRemovedResources().isEmpty())
223
          if (!visitor.getRemovedResources().isEmpty())
230
          {
224
          {
231
            removedResources.addAll(visitor.getRemovedResources());
225
            removedResources.addAll(visitor.getRemovedResources());
232
            if (!isDirty())
226
            if (!isDirty())
233
            {
227
            {
234
              getSite().getShell().getDisplay().asyncExec
228
              getSite().getShell().getDisplay().asyncExec
235
                (new Runnable()
229
                (new Runnable()
236
                 {
230
                 {
237
                   public void run()
231
                   public void run()
238
                   {
232
                   {
239
                     getSite().getPage().closeEditor(EcoreEditor.this, false);
233
                     getSite().getPage().closeEditor(Ecore2XMLEditor.this, false);
240
                   }
234
                   }
241
                 });
235
                 });
242
            }
236
            }
243
          }
237
          }
244
          if (!visitor.getChangedResources().isEmpty())
238
          if (!visitor.getChangedResources().isEmpty())
245
          {
239
          {
246
            changedResources.addAll(visitor.getChangedResources());
240
            changedResources.addAll(visitor.getChangedResources());
247
            if (getSite().getPage().getActiveEditor() == EcoreEditor.this)
241
            if (getSite().getPage().getActiveEditor() == Ecore2XMLEditor.this)
248
            {
242
            {
249
              getSite().getShell().getDisplay().asyncExec
243
              getSite().getShell().getDisplay().asyncExec
250
                (new Runnable()
244
                (new Runnable()
251
                 {
245
                 {
252
                   public void run()
246
                   public void run()
253
                   {
247
                   {
254
                     handleActivate();
248
                     handleActivate();
255
                   }
249
                   }
256
                 });
250
                 });
257
            }
251
            }
258
          }
252
          }
259
        }
253
        }
260
        catch (CoreException exception)
254
        catch (CoreException exception)
261
        {
255
        {
262
          EcoreEditorPlugin.INSTANCE.log(exception);
256
          Ecore2XMLUIPlugin.INSTANCE.log(exception);
263
        }
257
        }
264
      }
258
      }
265
    };
259
    };
266
  /**
260
  /**
267
   * Handles activation of the editor or it's associated views.
261
   * Handles activation of the editor or it's associated views.
268
   * <!-- begin-user-doc -->
269
   * <!-- end-user-doc -->
270
   * @generated
262
   * @generated
271
   */
263
   */
272
  protected void handleActivate()
264
  protected void handleActivate()
273
  {
265
  {
274
    // Recompute the read only state.
266
    // Recompute the read only state.
275
    //
267
    //
276
    if (editingDomain.getResourceToReadOnlyMap() != null)
268
    if (editingDomain.getResourceToReadOnlyMap() != null)
277
    {
269
    {
278
      editingDomain.getResourceToReadOnlyMap().clear();
270
      editingDomain.getResourceToReadOnlyMap().clear();
279
      // Refresh any actions that may become enabled or disabled.
271
      // Refresh any actions that may become enabled or disabled.
280
      //
272
      //
281
      setSelection(getSelection());
273
      setSelection(getSelection());
282
    }
274
    }
283
    if (!removedResources.isEmpty())
275
    if (!removedResources.isEmpty())
284
    {
276
    {
285
      if (handleDirtyConflict())
277
      if (handleDirtyConflict())
286
      {
278
      {
287
        getSite().getPage().closeEditor(EcoreEditor.this, false);
279
        getSite().getPage().closeEditor(Ecore2XMLEditor.this, false);
288
      }
280
      }
289
      else
281
      else
290
      {
282
      {
291
        removedResources.clear();
283
        removedResources.clear();
292
        changedResources.clear();
284
        changedResources.clear();
293
        savedResources.clear();
285
        savedResources.clear();
294
      }
286
      }
295
    }
287
    }
296
    else if (!changedResources.isEmpty())
288
    else if (!changedResources.isEmpty())
297
    {
289
    {
298
      changedResources.removeAll(savedResources);
290
      changedResources.removeAll(savedResources);
299
      handleChangedResources();
291
      handleChangedResources();
300
      changedResources.clear();
292
      changedResources.clear();
301
      savedResources.clear();
293
      savedResources.clear();
302
    }
294
    }
303
  }
295
  }
304
  /**
296
  /**
305
   * Handles what to do with changed resources on activation.
297
   * Handles what to do with changed resources on activation.
306
   * <!-- begin-user-doc -->
307
   * <!-- end-user-doc -->
308
   * @generated
298
   * @generated
309
   */
299
   */
310
  protected void handleChangedResources()
300
  protected void handleChangedResources()
311
  {
301
  {
312
    if (!changedResources.isEmpty() && (!isDirty() || handleDirtyConflict()))
302
    if (!changedResources.isEmpty() && (!isDirty() || handleDirtyConflict()))
313
    {
303
    {
314
      if (isDirty())
304
      if (isDirty())
315
      {
305
      {
316
        changedResources.addAll(editingDomain.getResourceSet().getResources());
306
        changedResources.addAll(editingDomain.getResourceSet().getResources());
317
      }
307
      }
318
      editingDomain.getCommandStack().flush();
308
      editingDomain.getCommandStack().flush();
319
      updateProblemIndication = false;
309
      updateProblemIndication = false;
320
      for (Resource resource : changedResources)
310
      for (Resource resource : changedResources)
321
      {
311
      {
322
        if (resource.isLoaded())
312
        if (resource.isLoaded())
323
        {
313
        {
324
          resource.unload();
314
          resource.unload();
325
          try
315
          try
326
          {
316
          {
327
            resource.load(Collections.EMPTY_MAP);
317
            resource.load(Collections.EMPTY_MAP);
328
          }
318
          }
329
          catch (IOException exception)
319
          catch (IOException exception)
330
          {
320
          {
331
            if (!resourceToDiagnosticMap.containsKey(resource))
321
            if (!resourceToDiagnosticMap.containsKey(resource))
332
            {
322
            {
333
              resourceToDiagnosticMap.put(resource, analyzeResourceProblems(resource, exception));
323
              resourceToDiagnosticMap.put(resource, analyzeResourceProblems(resource, exception));
334
            }
324
            }
335
          }
325
          }
336
        }
326
        }
337
      }
327
      }
338
      if (AdapterFactoryEditingDomain.isStale(editorSelection))
328
      if (AdapterFactoryEditingDomain.isStale(editorSelection))
339
      {
329
      {
340
        setSelection(StructuredSelection.EMPTY);
330
        setSelection(StructuredSelection.EMPTY);
341
      }
331
      }
342
      updateProblemIndication = true;
332
      updateProblemIndication = true;
343
      updateProblemIndication();
333
      updateProblemIndication();
344
    }
334
    }
345
  }
335
  }
346
  
336
  
347
  /**
337
  /**
348
   * Updates the problems indication with the information described in the specified diagnostic.
338
   * Updates the problems indication with the information described in the specified diagnostic.
349
   * <!-- begin-user-doc -->
339
   * <!-- begin-user-doc -->
350
   * <!-- end-user-doc -->
340
   * <!-- end-user-doc -->
351
   * @generated
341
   * @generated
352
   */
342
   */
353
  protected void updateProblemIndication()
343
  protected void updateProblemIndication()
354
  {
344
  {
355
    if (updateProblemIndication)
345
    if (updateProblemIndication)
356
    {
346
    {
357
      BasicDiagnostic diagnostic =
347
      BasicDiagnostic diagnostic =
358
        new BasicDiagnostic
348
        new BasicDiagnostic
359
          (Diagnostic.OK,
349
          (Diagnostic.OK,
360
           "org.eclipse.emf.ecore.editor",
350
           "org.eclipse.emf.mapping.ecore2xml.edit", //$NON-NLS-1$
361
           0,
351
           0,
362
           null,
352
           null,
363
           new Object [] { editingDomain.getResourceSet() });
353
           new Object [] { editingDomain.getResourceSet() });
364
      for (Diagnostic childDiagnostic : resourceToDiagnosticMap.values())
354
      for (Diagnostic childDiagnostic : resourceToDiagnosticMap.values())
365
      {
355
      {
366
        if (childDiagnostic.getSeverity() != Diagnostic.OK)
356
        if (childDiagnostic.getSeverity() != Diagnostic.OK)
367
        {
357
        {
368
          diagnostic.add(childDiagnostic);
358
          diagnostic.add(childDiagnostic);
369
        }
359
        }
370
      }
360
      }
371
      int lastEditorPage = getPageCount() - 1;
361
      int lastEditorPage = getPageCount() - 1;
372
      if (lastEditorPage >= 0 && getEditor(lastEditorPage) instanceof ProblemEditorPart)
362
      if (lastEditorPage >= 0 && getEditor(lastEditorPage) instanceof ProblemEditorPart)
373
      {
363
      {
374
        ((ProblemEditorPart)getEditor(lastEditorPage)).setDiagnostic(diagnostic);
364
        ((ProblemEditorPart)getEditor(lastEditorPage)).setDiagnostic(diagnostic);
375
        if (diagnostic.getSeverity() != Diagnostic.OK)
365
        if (diagnostic.getSeverity() != Diagnostic.OK)
376
        {
366
        {
377
          setActivePage(lastEditorPage);
367
          setActivePage(lastEditorPage);
378
        }
368
        }
379
      }
369
      }
380
      else if (diagnostic.getSeverity() != Diagnostic.OK)
370
      else if (diagnostic.getSeverity() != Diagnostic.OK)
381
      {
371
      {
382
        ProblemEditorPart problemEditorPart = new ProblemEditorPart();
372
        ProblemEditorPart problemEditorPart = new ProblemEditorPart();
383
        problemEditorPart.setDiagnostic(diagnostic);
373
        problemEditorPart.setDiagnostic(diagnostic);
384
        problemEditorPart.setMarkerHelper(markerHelper);
374
        problemEditorPart.setMarkerHelper(markerHelper);
385
        try
375
        try
386
        {
376
        {
387
          addPage(++lastEditorPage, problemEditorPart, getEditorInput());
377
          addPage(++lastEditorPage, problemEditorPart, getEditorInput());
388
          setPageText(lastEditorPage, problemEditorPart.getPartName());
378
          setPageText(lastEditorPage, problemEditorPart.getPartName());
389
          setActivePage(lastEditorPage);
379
          setActivePage(lastEditorPage);
390
          showTabs();
380
          showTabs();
391
        }
381
        }
392
        catch (PartInitException exception)
382
        catch (PartInitException exception)
393
        {
383
        {
394
          EcoreEditorPlugin.INSTANCE.log(exception);
384
          Ecore2XMLUIPlugin.INSTANCE.log(exception);
395
        }
385
        }
396
      }
386
      }
397
      if (markerHelper.hasMarkers(editingDomain.getResourceSet()))
387
      if (markerHelper.hasMarkers(editingDomain.getResourceSet()))
398
      {
388
      {
399
        markerHelper.deleteMarkers(editingDomain.getResourceSet());
389
        markerHelper.deleteMarkers(editingDomain.getResourceSet());
400
        if (diagnostic.getSeverity() != Diagnostic.OK)
390
        if (diagnostic.getSeverity() != Diagnostic.OK)
401
        {
391
        {
402
          try
392
          try
403
          {
393
          {
404
            markerHelper.createMarkers(diagnostic);
394
            markerHelper.createMarkers(diagnostic);
405
          }
395
          }
406
          catch (CoreException exception)
396
          catch (CoreException exception)
407
          {
397
          {
408
            EcoreEditorPlugin.INSTANCE.log(exception);
398
            Ecore2XMLUIPlugin.INSTANCE.log(exception);
409
          }
399
          }
410
        }
400
        }
411
      }
401
      }
412
    }
402
    }
413
  }
403
  }
414
  /**
404
  /**
415
   * Shows a dialog that asks if conflicting changes should be discarded.
405
   * Shows a dialog that asks if conflicting changes should be discarded.
416
   * <!-- begin-user-doc -->
417
   * <!-- end-user-doc -->
418
   * @generated
406
   * @generated
419
   */
407
   */
420
  protected boolean handleDirtyConflict()
408
  protected boolean handleDirtyConflict()
421
  {
409
  {
422
    return
410
    return
423
      MessageDialog.openQuestion
411
      MessageDialog.openQuestion
424
        (getSite().getShell(),
412
        (getSite().getShell(),
425
         getString("_UI_FileConflict_label"),
413
         getString("_UI_FileConflict_label"), //$NON-NLS-1$
426
         getString("_WARN_FileConflict"));
414
         getString("_WARN_FileConflict")); //$NON-NLS-1$
427
  }
415
  }
428
  /**
416
  /**
429
   * This creates a model editor.
417
   * This creates a model editor.
430
   * <!-- begin-user-doc -->
418
   * <!-- begin-user-doc -->
431
   * <!-- end-user-doc -->
419
   * <!-- end-user-doc -->
432
   * @generated
420
   * @generated
433
   */
421
   */
434
  public EcoreEditor()
422
  public Ecore2XMLEditor()
435
  {
423
  {
436
    super();
424
    super();
437
    initializeEditingDomain();
425
    initializeEditingDomain();
Summary
Number of common nesting structure subtrees0
Number of refactorable cases0
Number of non-refactorable cases0
Time elapsed for finding largest common nesting structure subtrees (ms)0.0
Clones location
Number of node comparisons0