/** @generated */
 private static boolean openEditor(IWorkbench workbench, URI fileURI) {
   IWorkbenchWindow workbenchWindow = workbench.getActiveWorkbenchWindow();
   IWorkbenchPage page = workbenchWindow.getActivePage();
   IEditorDescriptor editorDescriptor =
       workbench.getEditorRegistry().getDefaultEditor(fileURI.toFileString());
   if (editorDescriptor == null) {
     MessageDialog.openError(
         workbenchWindow.getShell(),
         Messages.DiagramEditorActionBarAdvisor_DefaultFileEditorTitle,
         NLS.bind(
             Messages.DiagramEditorActionBarAdvisor_DefaultFileEditorMessage,
             fileURI.toFileString()));
     return false;
   } else {
     try {
       page.openEditor(new URIEditorInput(fileURI), editorDescriptor.getId());
     } catch (PartInitException exception) {
       MessageDialog.openError(
           workbenchWindow.getShell(),
           Messages.DiagramEditorActionBarAdvisor_DefaultEditorOpenErrorTitle,
           exception.getMessage());
       return false;
     }
   }
   return true;
 }
 public static Image createImage(final PackerItem item) {
   Image result = null;
   IWorkbench workbench = PlatformUI.getWorkbench();
   if (item.isDirectory()) {
     result = workbench.getSharedImages().getImage(ISharedImages.IMG_OBJ_FOLDER);
   } else {
     ImageDescriptor descriptor =
         workbench.getEditorRegistry().getImageDescriptor(item.getFileName());
     if (descriptor == null) {
       result = workbench.getSharedImages().getImage(ISharedImages.IMG_OBJ_FILE);
     } else {
       result = descriptor.createImage();
     }
     if (result == null) {
       result = workbench.getSharedImages().getImage(ISharedImages.IMG_OBJ_FILE);
     }
   }
   return result;
 }
  /**
   * Do the work after everything is specified.
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   *
   * @generated
   */
  @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);

                // 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) {
                WebPageEditorPlugin.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(),
            WebPageEditorPlugin.INSTANCE.getString("_UI_OpenEditorError_label"),
            exception.getMessage());
        return false;
      }

      return true;
    } catch (Exception exception) {
      WebPageEditorPlugin.INSTANCE.log(exception);
      return false;
    }
  }
  @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) {

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

              // Add the initial model object to the contents.
              //
              MDescriptorList 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, "UTF-8");

              for (Iterator<?> i = selection.iterator(); i.hasNext(); ) {
                Object object = i.next();
                if (object instanceof MCommonPackageVersionedItem) {
                  MCommonPackageVersionedItem versionedItem = (MCommonPackageVersionedItem) object;
                  EObject root = EcoreUtil.getRootContainer(versionedItem);
                  String libraryID =
                      LibraryAdapterFactory.getAdapterFactory()
                          .getLibraryID(root.eClass().getName());
                  LibraryAdapter adapter =
                      LibraryAdapterFactory.getAdapterFactory().getAdapter(libraryID);
                  if (adapter != null) {
                    try {
                      ILibraryEncoder encoder =
                          (ILibraryEncoder) adapter.adapt(ILibraryEncoder.class);
                      if (encoder != null) {
                        List<MDescriptor> descriptors = encoder.getDescriptors(versionedItem);
                        rootObject.getDescriptors().addAll(descriptors);
                      }
                    } catch (LibraryManagerException e) {
                      MICOBSPlugin.INSTANCE.log(e);
                    }
                  }
                } else if (object instanceof MCommonPackageItem) {
                  MCommonPackageItem item = (MCommonPackageItem) object;
                  EObject root = EcoreUtil.getRootContainer(item);
                  String libraryID =
                      LibraryAdapterFactory.getAdapterFactory()
                          .getLibraryID(root.eClass().getName());
                  LibraryAdapter adapter =
                      LibraryAdapterFactory.getAdapterFactory().getAdapter(libraryID);
                  if (adapter != null) {
                    try {
                      ILibraryEncoder encoder =
                          (ILibraryEncoder) adapter.adapt(ILibraryEncoder.class);
                      if (encoder != null) {
                        List<MDescriptor> descriptors = encoder.getDescriptors(item);
                        rootObject.getDescriptors().addAll(descriptors);
                      }
                    } catch (LibraryManagerException e) {
                      MICOBSPlugin.INSTANCE.log(e);
                    }
                  }
                } else if (object instanceof MCommonPackage) {
                  MCommonPackage pack = (MCommonPackage) object;
                  EObject root = EcoreUtil.getRootContainer(pack);
                  String libraryID =
                      LibraryAdapterFactory.getAdapterFactory()
                          .getLibraryID(root.eClass().getName());
                  LibraryAdapter adapter =
                      LibraryAdapterFactory.getAdapterFactory().getAdapter(libraryID);
                  if (adapter != null) {
                    try {
                      ILibraryEncoder encoder =
                          (ILibraryEncoder) adapter.adapt(ILibraryEncoder.class);
                      if (encoder != null) {
                        List<MDescriptor> descriptors = encoder.getDescriptors(pack);
                        rootObject.getDescriptors().addAll(descriptors);
                      }
                    } catch (LibraryManagerException e) {
                      MICOBSPlugin.INSTANCE.log(e);
                    }
                  }
                } else if (object instanceof MCommonLibrary) {
                  MCommonLibrary library = (MCommonLibrary) object;
                  String libraryID =
                      LibraryAdapterFactory.getAdapterFactory()
                          .getLibraryID(library.eClass().getName());
                  LibraryAdapter adapter =
                      LibraryAdapterFactory.getAdapterFactory().getAdapter(libraryID);
                  if (adapter != null) {
                    try {
                      ILibraryEncoder encoder =
                          (ILibraryEncoder) adapter.adapt(ILibraryEncoder.class);
                      if (encoder != null) {
                        for (MCommonPackage pack : library.getPackages()) {
                          rootObject.getDescriptors().addAll(encoder.getDescriptors(pack));
                        }
                      }
                    } catch (LibraryManagerException e) {
                      MICOBSPlugin.INSTANCE.log(e);
                    }
                  }
                }
                LibraryDescriptor.removeDuplicatedDescriptors(rootObject);
              }
              try {
                resource.save(options);
              } catch (IOException e) {
                MICOBSPlugin.INSTANCE.log(e);
              }
              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(),
            MICOBSPlugin.INSTANCE.getString("_UI_OpenEditorError_label"),
            exception.getMessage());
        return false;
      }

      return true;
    } catch (Exception exception) {
      MICOBSPlugin.INSTANCE.log(exception);
      return false;
    }
  }