@Override public boolean isDirty() { return ((BasicCommandStack)editingDomain.getCommandStack()).isSaveNeeded(); } /** * This is for implementing {@link IEditorPart} and simply saves the model file. * <!-- begin-user-doc --> * <!-- end-user-doc --> * @generated */ @Override public void doSave(IProgressMonitor progressMonitor) { // Save only resources that have actually changed. // final Map<Object, Object> saveOptions = new HashMap<Object, Object>(); saveOptions.put(Resource.OPTION_SAVE_ONLY_IF_CHANGED, Resource.OPTION_SAVE_ONLY_IF_CHANGED_MEMORY_BUFFER); // Do the work within an operation because this is a long running activity that modifies the workbench. // WorkspaceModifyOperation operation = new WorkspaceModifyOperation() { // This is the method that gets invoked when the operation runs. // @Override public void execute(IProgressMonitor monitor) { // Save the resources to the file system. // boolean first = true; for (Resource resource : editingDomain.getResourceSet().getResources()) { if ((first || !resource.getContents().isEmpty() || isPersisted(resource)) && !editingDomain.isReadOnly(resource)) { try { long timeStamp = resource.getTimeStamp(); resource.save(saveOptions); if (resource.getTimeStamp() != timeStamp) { savedResources.add(resource); } } catch (Exception exception) { resourceToDiagnosticMap.put(resource, analyzeResourceProblems(resource, exception)); } first = false; } } } }; updateProblemIndication = false; try { // This runs the options, and shows progress. // new ProgressMonitorDialog(getSite().getShell()).run(true, false, operation); // Refresh the necessary state. // ((BasicCommandStack)editingDomain.getCommandStack()).saveIsDone(); firePropertyChange(IEditorPart.PROP_DIRTY); } catch (Exception exception) { // Something went wrong that shouldn't. // EcoreEditorPlugin.INSTANCE.log(exception); } updateProblemIndication = true; updateProblemIndication(); } /** * This returns whether something has been persisted to the URI of the specified resource. * The implementation uses the URI converter from the editor's resource set to try to open an input stream. * <!-- begin-user-doc --> * <!-- end-user-doc --> * @generated */ protected boolean isPersisted(Resource resource) { boolean result = false; try { InputStream stream = editingDomain.getResourceSet().getURIConverter().createInputStream(resource.getURI()); if (stream != null) { result = true; stream.close(); } } catch (IOException e) { // Ignore } return result; } /** * This always returns true because it is not currently supported. * <!-- begin-user-doc --> * <!-- end-user-doc --> * @generated */ @Override public boolean isSaveAsAllowed() { return true;
@Override public boolean isDirty() { return ((BasicCommandStack)editingDomain.getCommandStack()).isSaveNeeded(); } /** * This is for implementing {@link IEditorPart} and simply saves the model file. * <!-- begin-user-doc --> * <!-- end-user-doc --> * @generated */ @Override public void doSave(IProgressMonitor progressMonitor) { // Save only resources that have actually changed. // final Map<Object, Object> saveOptions = new HashMap<Object, Object>(); saveOptions.put(Resource.OPTION_SAVE_ONLY_IF_CHANGED, Resource.OPTION_SAVE_ONLY_IF_CHANGED_MEMORY_BUFFER); // Do the work within an operation because this is a long running activity that modifies the workbench. // WorkspaceModifyOperation operation = new WorkspaceModifyOperation() { // This is the method that gets invoked when the operation runs. // @Override public void execute(IProgressMonitor monitor) { // Save the resources to the file system. // boolean first = true; for (Resource resource : editingDomain.getResourceSet().getResources()) { if ((first || !resource.getContents().isEmpty() || isPersisted(resource)) && !editingDomain.isReadOnly(resource)) { try { long timeStamp = resource.getTimeStamp(); resource.save(saveOptions); if (resource.getTimeStamp() != timeStamp) { savedResources.add(resource); } } catch (Exception exception) { resourceToDiagnosticMap.put(resource, analyzeResourceProblems(resource, exception)); } first = false; } } } }; updateProblemIndication = false; try { // This runs the options, and shows progress. // new ProgressMonitorDialog(getSite().getShell()).run(true, false, operation); // Refresh the necessary state. // ((BasicCommandStack)editingDomain.getCommandStack()).saveIsDone(); firePropertyChange(IEditorPart.PROP_DIRTY); } catch (Exception exception) { // Something went wrong that shouldn't. // Ecore2XMLUIPlugin.INSTANCE.log(exception); } updateProblemIndication = true; updateProblemIndication(); } /** * This returns whether something has been persisted to the URI of the specified resource. * The implementation uses the URI converter from the editor's resource set to try to open an input stream. * <!-- begin-user-doc --> * <!-- end-user-doc --> * @generated */ protected boolean isPersisted(Resource resource) { boolean result = false; try { InputStream stream = editingDomain.getResourceSet().getURIConverter().createInputStream(resource.getURI()); if (stream != null) { result = true; stream.close(); } } catch (IOException e) { // Ignore } return result; } /** * This always returns true because it is not currently supported. * <!-- begin-user-doc --> * <!-- end-user-doc --> * @generated */ @Override public boolean isSaveAsAllowed() { return true;
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
@Override
1
@Override
2
  public boolean isDirty()
2
  public boolean isDirty()
3
  {
3
  {
4
    return ((BasicCommandStack)editingDomain.getCommandStack()).isSaveNeeded();
4
    return ((BasicCommandStack)editingDomain.getCommandStack()).isSaveNeeded();
5
  }
5
  }
6
  /**
6
  /**
7
   * This is for implementing {@link IEditorPart} and simply saves the model file.
7
   * This is for implementing {@link IEditorPart} and simply saves the model file.
8
   * <!-- begin-user-doc -->
8
   * <!-- begin-user-doc -->
9
   * <!-- end-user-doc -->
9
   * <!-- end-user-doc -->
10
   * @generated
10
   * @generated
11
   */
11
   */
12
  @Override
12
  @Override
13
  public void doSave(IProgressMonitor progressMonitor)
13
  public void doSave(IProgressMonitor progressMonitor)
14
  {
14
  {
15
    // Save only resources that have actually changed.
15
    // Save only resources that have actually changed.
16
    //
16
    //
17
    final Map<Object, Object> saveOptions = new HashMap<Object, Object>();
17
    final Map<Object, Object> saveOptions = new HashMap<Object, Object>();
18
    saveOptions.put(Resource.OPTION_SAVE_ONLY_IF_CHANGED, Resource.OPTION_SAVE_ONLY_IF_CHANGED_MEMORY_BUFFER);
18
    saveOptions.put(Resource.OPTION_SAVE_ONLY_IF_CHANGED, Resource.OPTION_SAVE_ONLY_IF_CHANGED_MEMORY_BUFFER);
19
    // Do the work within an operation because this is a long running activity that modifies the workbench.
19
    // Do the work within an operation because this is a long running activity that modifies the workbench.
20
    //
20
    //
21
    WorkspaceModifyOperation operation =
21
    WorkspaceModifyOperation operation =
22
      new WorkspaceModifyOperation()
22
      new WorkspaceModifyOperation()
23
      {
23
      {
24
        // This is the method that gets invoked when the operation runs.
24
        // This is the method that gets invoked when the operation runs.
25
        //
25
        //
26
        @Override
26
        @Override
27
        public void execute(IProgressMonitor monitor)
27
        public void execute(IProgressMonitor monitor)
28
        {
28
        {
29
          // Save the resources to the file system.
29
          // Save the resources to the file system.
30
          //
30
          //
31
          boolean first = true;
31
          boolean first = true;
32
          for (Resource resource : editingDomain.getResourceSet().getResources())
32
          for (Resource resource : editingDomain.getResourceSet().getResources())
33
          {
33
          {
34
            if ((first || !resource.getContents().isEmpty() || isPersisted(resource)) && !editingDomain.isReadOnly(resource))
34
            if ((first || !resource.getContents().isEmpty() || isPersisted(resource)) && !editingDomain.isReadOnly(resource))
35
            {
35
            {
36
              try
36
              try
37
              {
37
              {
38
                long timeStamp = resource.getTimeStamp();
38
                long timeStamp = resource.getTimeStamp();
39
                resource.save(saveOptions);
39
                resource.save(saveOptions);
40
                if (resource.getTimeStamp() != timeStamp)
40
                if (resource.getTimeStamp() != timeStamp)
41
                {
41
                {
42
                  savedResources.add(resource);
42
                  savedResources.add(resource);
43
                }
43
                }
44
              }
44
              }
45
              catch (Exception exception)
45
              catch (Exception exception)
46
              {
46
              {
47
                resourceToDiagnosticMap.put(resource, analyzeResourceProblems(resource, exception));
47
                resourceToDiagnosticMap.put(resource, analyzeResourceProblems(resource, exception));
48
              }
48
              }
49
              first = false;
49
              first = false;
50
            }
50
            }
51
          }
51
          }
52
        }
52
        }
53
      };
53
      };
54
    updateProblemIndication = false;
54
    updateProblemIndication = false;
55
    try
55
    try
56
    {
56
    {
57
      // This runs the options, and shows progress.
57
      // This runs the options, and shows progress.
58
      //
58
      //
59
      new ProgressMonitorDialog(getSite().getShell()).run(true, false, operation);
59
      new ProgressMonitorDialog(getSite().getShell()).run(true, false, operation);
60
      // Refresh the necessary state.
60
      // Refresh the necessary state.
61
      //
61
      //
62
      ((BasicCommandStack)editingDomain.getCommandStack()).saveIsDone();
62
      ((BasicCommandStack)editingDomain.getCommandStack()).saveIsDone();
63
      firePropertyChange(IEditorPart.PROP_DIRTY);
63
      firePropertyChange(IEditorPart.PROP_DIRTY);
64
    }
64
    }
65
    catch (Exception exception)
65
    catch (Exception exception)
66
    {
66
    {
67
      // Something went wrong that shouldn't.
67
      // Something went wrong that shouldn't.
68
      //
68
      //
69
      EcoreEditorPlugin.INSTANCE.log(exception);
69
      Ecore2XMLUIPlugin.INSTANCE.log(exception);
70
    }
70
    }
71
    updateProblemIndication = true;
71
    updateProblemIndication = true;
72
    updateProblemIndication();
72
    updateProblemIndication();
73
  }
73
  }
74
  /**
74
  /**
75
   * This returns whether something has been persisted to the URI of the specified resource.
75
   * This returns whether something has been persisted to the URI of the specified resource.
76
   * The implementation uses the URI converter from the editor's resource set to try to open an input stream. 
76
   * The implementation uses the URI converter from the editor's resource set to try to open an input stream. 
77
   * <!-- begin-user-doc -->
77
   * <!-- begin-user-doc -->
78
   * <!-- end-user-doc -->
78
   * <!-- end-user-doc -->
79
   * @generated
79
   * @generated
80
   */
80
   */
81
  protected boolean isPersisted(Resource resource)
81
  protected boolean isPersisted(Resource resource)
82
  {
82
  {
83
    boolean result = false;
83
    boolean result = false;
84
    try
84
    try
85
    {
85
    {
86
      InputStream stream = editingDomain.getResourceSet().getURIConverter().createInputStream(resource.getURI());
86
      InputStream stream = editingDomain.getResourceSet().getURIConverter().createInputStream(resource.getURI());
87
      if (stream != null)
87
      if (stream != null)
88
      {
88
      {
89
        result = true;
89
        result = true;
90
        stream.close();
90
        stream.close();
91
      }
91
      }
92
    }
92
    }
93
    catch (IOException e)
93
    catch (IOException e)
94
    {
94
    {
95
      // Ignore
95
      // Ignore
96
    }
96
    }
97
    return result;
97
    return result;
98
  }
98
  }
99
  /**
99
  /**
100
   * This always returns true because it is not currently supported.
100
   * This always returns true because it is not currently supported.
101
   * <!-- begin-user-doc -->
101
   * <!-- begin-user-doc -->
102
   * <!-- end-user-doc -->
102
   * <!-- end-user-doc -->
103
   * @generated
103
   * @generated
104
   */
104
   */
105
  @Override
105
  @Override
106
  public boolean isSaveAsAllowed()
106
  public boolean isSaveAsAllowed()
107
  {
107
  {
108
    return true;
108
    return true;
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