@Override public boolean performFinish() { try { // Remember the file. // final IFile modelFile = getModelFile(); // Do the work within an operation. // WorkspaceModifyOperation operation = new WorkspaceModifyOperation() { @Override protected void execute(IProgressMonitor progressMonitor) { try { // Create a resource set // ResourceSet resourceSet = new ResourceSetImpl(); // Get the URI of the model file. // URI fileURI = URI.createPlatformResourceURI(modelFile.getFullPath().toString(), true); // Create a resource for this file. // Resource resource = resourceSet.createResource(fileURI, Ecore2EcorePackage.eCONTENT_TYPE); // Add the initial model object to the contents. // EObject rootObject = createInitialModel(); if (rootObject != null) { resource.getContents().add(rootObject); } // Save the contents of the resource to the file system. // Map<Object, Object> options = new HashMap<Object, Object>(); options.put(XMLResource.OPTION_ENCODING, initialObjectCreationPage.getEncoding()); resource.save(options); } catch (Exception exception) { Ecore2EcoreEditorPlugin.INSTANCE.log(exception); } finally { progressMonitor.done(); } } }; getContainer().run(false, false, operation); // Select the new file resource in the current view. // IWorkbenchWindow workbenchWindow = workbench.getActiveWorkbenchWindow(); IWorkbenchPage page = workbenchWindow.getActivePage(); final IWorkbenchPart activePart = page.getActivePart(); if (activePart instanceof ISetSelectionTarget) { final ISelection targetSelection = new StructuredSelection(modelFile); getShell().getDisplay().asyncExec (new Runnable() { public void run() { ((ISetSelectionTarget)activePart).selectReveal(targetSelection); } }); } // Open an editor on the new file. // try { page.openEditor (new FileEditorInput(modelFile), workbench.getEditorRegistry().getDefaultEditor(modelFile.getFullPath().toString()).getId()); } catch (PartInitException exception) { MessageDialog.openError(workbenchWindow.getShell(), Ecore2EcoreEditorPlugin.INSTANCE.getString("_UI_OpenEditorError_label"), exception.getMessage()); return false; } return true; } catch (Exception exception) { Ecore2EcoreEditorPlugin.INSTANCE.log(exception); return false; } } /** * This is the one page of the wizard. * <!-- begin-user-doc --> * <!-- end-user-doc --> * @generated */ public class Ecore2EcoreModelWizardNewFileCreationPage extends WizardNewFileCreationPage { /** * Pass in the selection. * <!-- begin-user-doc --> * <!-- end-user-doc --> * @generated */ public Ecore2EcoreModelWizardNewFileCreationPage(String pageId, IStructuredSelection selection) { super(pageId, selection); } /** * The framework calls this to see if the file is correct. * <!-- begin-user-doc --> * <!-- end-user-doc --> * @generated */ @Override protected boolean validatePage() { if (super.validatePage()) { String extension = new Path(getFileName()).getFileExtension(); if (extension == null || !FILE_EXTENSIONS.contains(extension)) { String key = FILE_EXTENSIONS.size() > 1 ? "_WARN_FilenameExtensions" : "_WARN_FilenameExtension"; setErrorMessage(Ecore2EcoreEditorPlugin.INSTANCE.getString(key, new Object [] { FORMATTED_FILE_EXTENSIONS })); return false; } return true; } return false; } /** * <!-- begin-user-doc --> * <!-- end-user-doc --> * @generated */ public IFile getModelFile() { return ResourcesPlugin.getWorkspace().getRoot().getFile(getContainerFullPath().append(getFileName()));
@Override public boolean performFinish() { try { // Remember the file. // final IFile modelFile = getModelFile(); // Do the work within an operation. // WorkspaceModifyOperation operation = new WorkspaceModifyOperation() { @Override protected void execute(IProgressMonitor progressMonitor) { try { // Create a resource set // ResourceSet resourceSet = new ResourceSetImpl(); // Get the URI of the model file. // URI fileURI = URI.createPlatformResourceURI(modelFile.getFullPath().toString(), true); // Create a resource for this file. // Resource resource = resourceSet.createResource(fileURI, Ecore2XMLPackage.eCONTENT_TYPE); // Add the initial model object to the contents. // EObject rootObject = createInitialModel(); if (rootObject != null) { resource.getContents().add(rootObject); } // Save the contents of the resource to the file system. // Map<Object, Object> options = new HashMap<Object, Object>(); options.put(XMLResource.OPTION_ENCODING, initialObjectCreationPage.getEncoding()); resource.save(options); } catch (Exception exception) { Ecore2XMLUIPlugin.INSTANCE.log(exception); } finally { progressMonitor.done(); } } }; getContainer().run(false, false, operation); // Select the new file resource in the current view. // IWorkbenchWindow workbenchWindow = workbench.getActiveWorkbenchWindow(); IWorkbenchPage page = workbenchWindow.getActivePage(); final IWorkbenchPart activePart = page.getActivePart(); if (activePart instanceof ISetSelectionTarget) { final ISelection targetSelection = new StructuredSelection(modelFile); getShell().getDisplay().asyncExec (new Runnable() { public void run() { ((ISetSelectionTarget)activePart).selectReveal(targetSelection); } }); } // Open an editor on the new file. // try { page.openEditor (new FileEditorInput(modelFile), workbench.getEditorRegistry().getDefaultEditor(modelFile.getFullPath().toString()).getId()); } catch (PartInitException exception) { MessageDialog.openError(workbenchWindow.getShell(), Ecore2XMLUIPlugin.INSTANCE.getString("_UI_OpenEditorError_label"), exception.getMessage()); //$NON-NLS-1$ return false; } return true; } catch (Exception exception) { Ecore2XMLUIPlugin.INSTANCE.log(exception); return false; } } /** * This is the one page of the wizard. * <!-- begin-user-doc --> * <!-- end-user-doc --> * @generated */ public class Ecore2XMLModelWizardNewFileCreationPage extends WizardNewFileCreationPage { /** * Pass in the selection. * <!-- begin-user-doc --> * <!-- end-user-doc --> * @generated */ public Ecore2XMLModelWizardNewFileCreationPage(String pageId, IStructuredSelection selection) { super(pageId, selection); } /** * The framework calls this to see if the file is correct. * <!-- begin-user-doc --> * <!-- end-user-doc --> * @generated */ @Override protected boolean validatePage() { if (super.validatePage()) { String extension = new Path(getFileName()).getFileExtension(); if (extension == null || !FILE_EXTENSIONS.contains(extension)) { String key = FILE_EXTENSIONS.size() > 1 ? "_WARN_FilenameExtensions" : "_WARN_FilenameExtension"; //$NON-NLS-1$ //$NON-NLS-2$ setErrorMessage(Ecore2XMLUIPlugin.INSTANCE.getString(key, new Object [] { FORMATTED_FILE_EXTENSIONS })); return false; } return true; } return false; } /** * <!-- begin-user-doc --> * <!-- end-user-doc --> * @generated */ public IFile getModelFile() { return ResourcesPlugin.getWorkspace().getRoot().getFile(getContainerFullPath().append(getFileName()));
Clone fragments detected by clone detection tool
File path: /emf-2.4.1/src/org/eclipse/emf/mapping/ecore2ecore/presentation/Ecore2EcoreModelWizard.java File path: /emf-2.4.1/src/org/eclipse/emf/mapping/ecore2xml/presentation/Ecore2XMLModelWizard.java
Method name: Method name:
Number of AST nodes: 0 Number of AST nodes: 0
1
@Override
1
@Override
2
  public boolean performFinish()
2
  public boolean performFinish()
3
  {
3
  {
4
    try
4
    try
5
    {
5
    {
6
      // Remember the file.
6
      // Remember the file.
7
      //
7
      //
8
      final IFile modelFile = getModelFile();
8
      final IFile modelFile = getModelFile();
9
      // Do the work within an operation.
9
      // Do the work within an operation.
10
      //
10
      //
11
      WorkspaceModifyOperation operation =
11
      WorkspaceModifyOperation operation =
12
        new WorkspaceModifyOperation()
12
        new WorkspaceModifyOperation()
13
        {
13
        {
14
          @Override
14
          @Override
15
          protected void execute(IProgressMonitor progressMonitor)
15
          protected void execute(IProgressMonitor progressMonitor)
16
          {
16
          {
17
            try
17
            try
18
            {
18
            {
19
              // Create a resource set
19
              // Create a resource set
20
              //
20
              //
21
              ResourceSet resourceSet = new ResourceSetImpl();
21
              ResourceSet resourceSet = new ResourceSetImpl();
22
              // Get the URI of the model file.
22
              // Get the URI of the model file.
23
              //
23
              //
24
              URI fileURI = URI.createPlatformResourceURI(modelFile.getFullPath().toString(), true);
24
              URI fileURI = URI.createPlatformResourceURI(modelFile.getFullPath().toString(), true);
25
              // Create a resource for this file.
25
              // Create a resource for this file.
26
              //
26
              //
27
              Resource resource = resourceSet.createResource(fileURI, Ecore2EcorePackage.eCONTENT_TYPE);
27
              Resource resource = resourceSet.createResource(fileURI, Ecore2XMLPackage.eCONTENT_TYPE);
28
              // Add the initial model object to the contents.
28
              // Add the initial model object to the contents.
29
              //
29
              //
30
              EObject rootObject = createInitialModel();
30
              EObject rootObject = createInitialModel();
31
              if (rootObject != null)
31
              if (rootObject != null)
32
              {
32
              {
33
                resource.getContents().add(rootObject);
33
                resource.getContents().add(rootObject);
34
              }
34
              }
35
              // Save the contents of the resource to the file system.
35
              // Save the contents of the resource to the file system.
36
              //
36
              //
37
              Map<Object, Object> options = new HashMap<Object, Object>();
37
              Map<Object, Object> options = new HashMap<Object, Object>();
38
              options.put(XMLResource.OPTION_ENCODING, initialObjectCreationPage.getEncoding());
38
              options.put(XMLResource.OPTION_ENCODING, initialObjectCreationPage.getEncoding());
39
              resource.save(options);
39
              resource.save(options);
40
            }
40
            }
41
            catch (Exception exception)
41
            catch (Exception exception)
42
            {
42
            {
43
              Ecore2EcoreEditorPlugin.INSTANCE.log(exception);
43
              Ecore2XMLUIPlugin.INSTANCE.log(exception);
44
            }
44
            }
45
            finally
45
            finally
46
            {
46
            {
47
              progressMonitor.done();
47
              progressMonitor.done();
48
            }
48
            }
49
          }
49
          }
50
        };
50
        };
51
      getContainer().run(false, false, operation);
51
      getContainer().run(false, false, operation);
52
      // Select the new file resource in the current view.
52
      // Select the new file resource in the current view.
53
      //
53
      //
54
      IWorkbenchWindow workbenchWindow = workbench.getActiveWorkbenchWindow();
54
      IWorkbenchWindow workbenchWindow = workbench.getActiveWorkbenchWindow();
55
      IWorkbenchPage page = workbenchWindow.getActivePage();
55
      IWorkbenchPage page = workbenchWindow.getActivePage();
56
      final IWorkbenchPart activePart = page.getActivePart();
56
      final IWorkbenchPart activePart = page.getActivePart();
57
      if (activePart instanceof ISetSelectionTarget)
57
      if (activePart instanceof ISetSelectionTarget)
58
      {
58
      {
59
        final ISelection targetSelection = new StructuredSelection(modelFile);
59
        final ISelection targetSelection = new StructuredSelection(modelFile);
60
        getShell().getDisplay().asyncExec
60
        getShell().getDisplay().asyncExec
61
          (new Runnable()
61
          (new Runnable()
62
           {
62
           {
63
             public void run()
63
             public void run()
64
             {
64
             {
65
               ((ISetSelectionTarget)activePart).selectReveal(targetSelection);
65
               ((ISetSelectionTarget)activePart).selectReveal(targetSelection);
66
             }
66
             }
67
           });
67
           });
68
      }
68
      }
69
      // Open an editor on the new file.
69
      // Open an editor on the new file.
70
      //
70
      //
71
      try
71
      try
72
      {
72
      {
73
        page.openEditor
73
        page.openEditor
74
          (new FileEditorInput(modelFile),
74
          (new FileEditorInput(modelFile),
75
           workbench.getEditorRegistry().getDefaultEditor(modelFile.getFullPath().toString()).getId());
75
           workbench.getEditorRegistry().getDefaultEditor(modelFile.getFullPath().toString()).getId());
76
      }
76
      }
77
      catch (PartInitException exception)
77
      catch (PartInitException exception)
78
      {
78
      {
79
        MessageDialog.openError(workbenchWindow.getShell(), Ecore2EcoreEditorPlugin.INSTANCE.getString("_UI_OpenEditorError_label"), exception.getMessage());
79
        MessageDialog.openError(workbenchWindow.getShell(), Ecore2XMLUIPlugin.INSTANCE.getString("_UI_OpenEditorError_label"), exception.getMessage()); //$NON-NLS-1$
80
        return false;
80
        return false;
81
      }
81
      }
82
      return true;
82
      return true;
83
    }
83
    }
84
    catch (Exception exception)
84
    catch (Exception exception)
85
    {
85
    {
86
      Ecore2EcoreEditorPlugin.INSTANCE.log(exception);
86
      Ecore2XMLUIPlugin.INSTANCE.log(exception);
87
      return false;
87
      return false;
88
    }
88
    }
89
  }
89
  }
90
  /**
90
  /**
91
   * This is the one page of the wizard.
91
   * This is the one page of the wizard.
92
   * <!-- begin-user-doc -->
92
   * <!-- begin-user-doc -->
93
   * <!-- end-user-doc -->
93
   * <!-- end-user-doc -->
94
   * @generated
94
   * @generated
95
   */
95
   */
96
  public class Ecore2EcoreModelWizardNewFileCreationPage extends WizardNewFileCreationPage
96
  public class Ecore2XMLModelWizardNewFileCreationPage extends WizardNewFileCreationPage
97
  {
97
  {
98
    /**
98
    /**
99
     * Pass in the selection.
99
     * Pass in the selection.
100
     * <!-- begin-user-doc -->
100
     * <!-- begin-user-doc -->
101
     * <!-- end-user-doc -->
101
     * <!-- end-user-doc -->
102
     * @generated
102
     * @generated
103
     */
103
     */
104
    public Ecore2EcoreModelWizardNewFileCreationPage(String pageId, IStructuredSelection selection)
104
    public Ecore2XMLModelWizardNewFileCreationPage(String pageId, IStructuredSelection selection)
105
    {
105
    {
106
      super(pageId, selection);
106
      super(pageId, selection);
107
    }
107
    }
108
    /**
108
    /**
109
     * The framework calls this to see if the file is correct.
109
     * The framework calls this to see if the file is correct.
110
     * <!-- begin-user-doc -->
110
     * <!-- begin-user-doc -->
111
     * <!-- end-user-doc -->
111
     * <!-- end-user-doc -->
112
     * @generated
112
     * @generated
113
     */
113
     */
114
    @Override
114
    @Override
115
    protected boolean validatePage()
115
    protected boolean validatePage()
116
    {
116
    {
117
      if (super.validatePage())
117
      if (super.validatePage())
118
      {
118
      {
119
        String extension = new Path(getFileName()).getFileExtension();
119
        String extension = new Path(getFileName()).getFileExtension();
120
        if (extension == null || !FILE_EXTENSIONS.contains(extension))
120
        if (extension == null || !FILE_EXTENSIONS.contains(extension))
121
        {
121
        {
122
          String key = FILE_EXTENSIONS.size() > 1 ? "_WARN_FilenameExtensions" : "_WARN_FilenameExtension";
122
          String key = FILE_EXTENSIONS.size() > 1 ? "_WARN_FilenameExtensions" : "_WARN_FilenameExtension"; //$NON-NLS-1$ //$NON-NLS-2$
123
          setErrorMessage(Ecore2EcoreEditorPlugin.INSTANCE.getString(key, new Object [] { FORMATTED_FILE_EXTENSIONS }));
123
          setErrorMessage(Ecore2XMLUIPlugin.INSTANCE.getString(key, new Object [] { FORMATTED_FILE_EXTENSIONS }));
124
          return false;
124
          return false;
125
        }
125
        }
126
        return true;
126
        return true;
127
      }
127
      }
128
      return false;
128
      return false;
129
    }
129
    }
130
    /**
130
    /**
131
     * <!-- begin-user-doc -->
131
     * <!-- begin-user-doc -->
132
     * <!-- end-user-doc -->
132
     * <!-- end-user-doc -->
133
     * @generated
133
     * @generated
134
     */
134
     */
135
    public IFile getModelFile()
135
    public IFile getModelFile()
136
    {
136
    {
137
      return ResourcesPlugin.getWorkspace().getRoot().getFile(getContainerFullPath().append(getFileName()));
137
      return ResourcesPlugin.getWorkspace().getRoot().getFile(getContainerFullPath().append(getFileName()));
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