コード例 #1
0
 /**
  * Returns the source part, or <code>null</code> if there is no applicable source part
  *
  * <p>This implementation returns the current part in the window. Subclasses may extend or
  * reimplement.
  *
  * @return the source part or <code>null</code>
  */
 private IWorkbenchPart getSourcePart() {
   IWorkbenchPage page = getWindow().getActivePage();
   if (page != null) {
     return page.getActivePart();
   }
   return null;
 }
コード例 #2
0
  protected void setInitialSelection() {
    // Use the selection, if any
    Object input;
    IWorkbenchPage page = getSite().getPage();
    ISelection selection = null;
    if (page != null) selection = page.getSelection();
    if (selection instanceof ITextSelection) {
      IWorkbenchWindow activeWorkbenchWindow = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
      IWorkbenchPage activePage = activeWorkbenchWindow.getActivePage();
      if (activePage != null) {
        Object part = activePage.getActivePart();
        if (part instanceof IEditorPart) {
          setSelectionFromEditor((IEditorPart) part);
          if (fViewer.getSelection() != null) return;
        }
      }
    }

    // Use saved selection from memento
    if (selection == null || selection.isEmpty()) selection = restoreSelectionState(fMemento);

    if (selection == null || selection.isEmpty()) {
      // Use the input of the page
      input = getSite().getPage().getInput();
      if (!(input instanceof IModelElement)) {
        if (input instanceof IAdaptable)
          input = ((IAdaptable) input).getAdapter(IModelElement.class);
        else return;
      }
      selection = new StructuredSelection(input);
    }
    selectionChanged(null, selection);
  }
コード例 #3
0
  public static StatusLineContributionItem getStatusLineCItem(final String statusLineId) {
    IWorkbench wb = PlatformUI.getWorkbench();
    IWorkbenchWindow win = wb.getActiveWorkbenchWindow();

    if (win == null) return null;
    IWorkbenchPage page = win.getActivePage();

    if (page == null) return null;
    IWorkbenchPart part = page.getActivePart();
    if (part == null) return null;
    IWorkbenchPartSite site = part.getSite();

    IViewSite vSite = (IViewSite) site;

    IActionBars actionBars = vSite.getActionBars();

    if (actionBars == null) return null;

    IStatusLineManager statusLineManager = actionBars.getStatusLineManager();

    if (statusLineManager == null) return null;

    StatusLineContributionItem StatusLineCItem =
        (StatusLineContributionItem) statusLineManager.find(statusLineId);
    return StatusLineCItem;
  }
コード例 #4
0
 /**
  * Returns the active part in the current workbench window.
  *
  * @return the active part
  */
 public static IWorkbenchPart getActivePart() {
   IWorkbenchPage workbenchPage = getActivePage();
   if (workbenchPage == null) {
     return null;
   }
   return workbenchPage.getActivePart();
 }
コード例 #5
0
  @Override
  public boolean isEnabled() {

    // Check if we are closing down
    IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
    if (window == null) {
      return false;
    }

    // Get the selection
    IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
    IWorkbenchPart part = page.getActivePart();
    if (part == null) {
      return false;
    }
    ISelectionProvider selectionProvider = part.getSite().getSelectionProvider();
    if (selectionProvider == null) {
      return false;
    }
    ISelection selection = selectionProvider.getSelection();

    // Make sure there is only one selection and that it is an experiment
    fExperiment = null;
    if (selection instanceof TreeSelection) {
      TreeSelection sel = (TreeSelection) selection;
      // There should be only one item selected as per the plugin.xml
      Object element = sel.getFirstElement();
      if (element instanceof TmfExperimentElement) {
        fExperiment = (TmfExperimentElement) element;
      }
    }

    return (fExperiment != null);
  }
コード例 #6
0
 protected IWorkbenchPart getBootstrapPart() {
   IWorkbenchPage page = getSite().getPage();
   if (page != null) {
     return page.getActivePart();
   }
   return null;
 }
コード例 #7
0
 public void partVisible(IWorkbenchPartReference ref) {
   if (ref != null && ref.getId() == getSite().getId()) {
     fProcessSelectionEvents = true;
     IWorkbenchPage page = getSite().getWorkbenchWindow().getActivePage();
     if (page != null) selectionChanged(page.getActivePart(), page.getSelection());
   }
 }
コード例 #8
0
  /**
   * Opens the editor currently associated with the given element (DartElement, IFile, IStorage...)
   *
   * @return an open editor or <code>null</code> if an external editor was opened
   * @throws PartInitException if the editor could not be opened or the input element is not valid
   */
  public static IEditorPart openInEditor(Object inputElement, boolean activate)
      throws DartModelException, PartInitException {

    if (inputElement instanceof IFile) {
      return openInEditor((IFile) inputElement, activate);
    }
    DartX.todo();
    if (inputElement instanceof ImportElement) {
      inputElement = ((ImportElement) inputElement).getImportedLibrary();
    }
    if (inputElement instanceof Element) {
      CompilationUnitElement cu = getCompilationUnit((Element) inputElement);
      IWorkbenchPage page = DartToolsPlugin.getActivePage();
      if (cu != null && page != null) {
        IEditorPart editor = page.getActiveEditor();
        if (editor != null) {
          Element editorCU = EditorUtility.getEditorInputDartElement2(editor, false);
          if (cu.equals(editorCU)) {
            if (activate && page.getActivePart() != editor) {
              page.activate(editor);
            }
            return editor;
          }
        }
      }
    }

    IEditorInput input = getEditorInput(inputElement);

    if (input == null) {
      return null;
    }

    return openInEditor(input, getEditorID(input), activate);
  }
コード例 #9
0
 private IWorkbenchPart getActivePart() {
   IWorkbenchWindow activeWindow = getWorkbench().getActiveWorkbenchWindow();
   if (activeWindow != null) {
     IWorkbenchPage activePage = activeWindow.getActivePage();
     if (activePage != null) {
       return activePage.getActivePart();
     }
   }
   return null;
 }
コード例 #10
0
 @SuppressWarnings("unused")
 private IWorkbenchSite getSite() {
   IWorkbenchPage page = DartToolsPlugin.getActivePage();
   if (page != null) {
     IWorkbenchPart part = page.getActivePart();
     if (part != null) {
       return part.getSite();
     }
   }
   return null;
 }
  private PackageExplorerPart getActivePackageExplorer() {
    PackageExplorerPart explorerPart = PackageExplorerPart.getFromActivePerspective();
    if (explorerPart == null) return null;

    IWorkbenchPage activePage = explorerPart.getViewSite().getWorkbenchWindow().getActivePage();
    if (activePage == null) return null;

    if (activePage.getActivePart() != explorerPart) return null;

    return explorerPart;
  }
コード例 #12
0
  public IEditorPart getActiveEditor() {
    IWorkbenchPage activePage = fWorkbenchWindow.getActivePage();
    if (activePage == null) return null;

    IWorkbenchPart activePart = activePage.getActivePart();
    if (activePart == null) return null;

    IEditorPart activeEditor = activePage.getActiveEditor();
    if (activeEditor == activePart || isOldSearchView(activePart)) return activeEditor;

    return null;
  }
 /**
  * Runs with either the active editor or workbench selection.
  *
  * @see IAction#run()
  */
 public void run() {
   IWorkbenchWindow wb = DebugUIPlugin.getActiveWorkbenchWindow();
   if (wb != null) {
     IWorkbenchPage page = wb.getActivePage();
     if (page != null) {
       if (page.getActivePart() == page.getActiveEditor()) {
         IEditorPart editor = page.getActiveEditor();
         if (editor != null) {
           fShortcut.launch(editor, fMode);
         }
       } else if (page.getActivePart() instanceof IJobSettingsView) {
         ISelection selection = ((IJobSettingsView) page.getActivePart()).getSelection();
         fShortcut.launch(selection, fMode);
       } else {
         ISelection selection = page.getSelection();
         if (selection instanceof IStructuredSelection) {
           fShortcut.launch(selection, fMode);
         }
       }
     }
   }
 }
コード例 #14
0
ファイル: EclipseUtil.java プロジェクト: debabratahazra/DS
 /**
  * Utility method that returns IStatusLineManager, useful for handling the status line.
  *
  * @return
  */
 private static IStatusLineManager getStatusLine() {
   IStatusLineManager statusLineManager = null;
   IWorkbenchPage activePage =
       PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
   if (activePage != null) {
     IWorkbenchPart activePart = activePage.getActivePart();
     if (activePart instanceof IViewPart) {
       statusLineManager =
           ((IViewPart) activePart).getViewSite().getActionBars().getStatusLineManager();
     } else if (activePart instanceof IEditorPart) {
       statusLineManager =
           ((IEditorPart) activePart).getEditorSite().getActionBars().getStatusLineManager();
     }
   }
   return statusLineManager;
 }
コード例 #15
0
ファイル: UIUtils.java プロジェクト: ralic/dbeaver
 @Nullable
 public static IWorkbenchPartSite getWorkbenchPartSite(IServiceLocator serviceLocator) {
   IWorkbenchPartSite partSite = serviceLocator.getService(IWorkbenchPartSite.class);
   if (partSite == null) {
     IWorkbenchPart activePart = serviceLocator.getService(IWorkbenchPart.class);
     if (activePart == null) {
       IWorkbenchWindow workbenchWindow = DBeaverUI.getActiveWorkbenchWindow();
       if (workbenchWindow != null) {
         IWorkbenchPage activePage = workbenchWindow.getActivePage();
         if (activePage != null) {
           activePart = activePage.getActivePart();
         }
       }
     }
     if (activePart != null) {
       partSite = activePart.getSite();
     }
   }
   return partSite;
 }
コード例 #16
0
  private void configureDialog(ElementSelectionDialog dialog) {
    dialog.setDialogSettings(getClass().getName());
    dialog.setVisibleTypes(VISIBLE_TYPES);
    dialog.setTitle(Messages.OpenTypeInHierarchyAction_title);
    dialog.setUpperListLabel(Messages.OpenTypeInHierarchyAction_upperListLabel);
    dialog.setMessage(Messages.OpenTypeInHierarchyAction_message);

    if (fWorkbenchWindow != null) {
      IWorkbenchPage page = fWorkbenchWindow.getActivePage();
      if (page != null) {
        IWorkbenchPart part = page.getActivePart();
        if (part instanceof ITextEditor) {
          ISelection sel = ((ITextEditor) part).getSelectionProvider().getSelection();
          if (sel instanceof ITextSelection) {
            String txt = ((ITextSelection) sel).getText();
            if (txt.length() > 0 && txt.length() < 80) {
              dialog.setFilter(txt, true);
            }
          }
        }
      }
    }
  }
コード例 #17
0
  /**
   * Return true if the <code>DiagramPropertiesProvider</code> would return true for this operation
   * and we are on a Browse Diagram.
   *
   * @param operation IOperation that we will check if we provide for
   */
  public boolean provides(IOperation operation) {

    if (operation instanceof ApplyModifiersOperation) {

      IWorkbench workbench = PlatformUI.getWorkbench();

      if (workbench != null) {
        IWorkbenchWindow window = workbench.getActiveWorkbenchWindow();

        if (window != null) {
          IWorkbenchPage page = window.getActivePage();

          if (page != null) {
            IWorkbenchPart part = page.getActivePart();

            return part instanceof IReadOnlyDiagramPropertySheetPageContributor
                || (part instanceof DiagramEditor && !((DiagramEditor) part).isWritable());
          }
        }
      }
    }

    return false;
  }
コード例 #18
0
  /**
   * Opens a dialog to let the user decide where to add the new element.
   *
   * @param sourceUFIs All possible source fragment UFIs.
   * @return The user-chosen UFI.
   */
  public URI showSelectSourceFragmentGUI(List<URI> sourceUFIs) {
    IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();

    ElementListSelectionDialog ld =
        new ElementListSelectionDialog(
            page.getActivePart().getSite().getShell(), new LabelProvider()) {
          protected void createButtonsForButtonBar(Composite parent) {
            // create only OK button
            createButton(parent, IDialogConstants.OK_ID, IDialogConstants.OK_LABEL, true);
            // createButton(parent, IDialogConstants.CANCEL_ID,
            // IDialogConstants.CANCEL_LABEL, false);
          }
        };
    Object[] options = sourceUFIs.toArray();
    ld.setElements(options);
    ld.setMultipleSelection(false);
    ld.setTitle("Backpropagation Conflict");
    String text = "To which source fragment should the new element be propagated?";
    ld.setMessage(text);
    ld.open();

    Object answer = ld.getResult()[0];
    return (URI) answer;
  }
コード例 #19
0
  /**
   * 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;
    }
  }
コード例 #20
0
  /**
   * selectionChanged() event handler. Fills the list of managed-built projects based on the
   * selection. If some non-managed-built projects are selected, disables the action.
   *
   * @param action The action
   * @param selection The selection
   */
  protected void onSelectionChanged(IAction action, ISelection selection) {
    fProjects.clear();

    boolean badObject = false;

    if (selection != null) {
      if (selection instanceof IStructuredSelection) {
        if (selection.isEmpty()) {
          // could be a form editor or something.  try to get the project from the active part
          IWorkbenchPage page = CUIPlugin.getActivePage();
          if (page != null) {
            IWorkbenchPart part = page.getActivePart();
            if (part != null) {
              Object o = part.getAdapter(IResource.class);
              if (o != null && o instanceof IResource) {
                fProjects.add(((IResource) o).getProject());
              }
            }
          }
        }
        Iterator<?> iter = ((IStructuredSelection) selection).iterator();
        while (iter.hasNext()) {
          Object selItem = iter.next();
          IProject project = null;
          if (selItem instanceof ICElement) {
            ICProject cproject = ((ICElement) selItem).getCProject();
            if (cproject != null) project = cproject.getProject();
          } else if (selItem instanceof IResource) {
            project = ((IResource) selItem).getProject();
          } else if (selItem instanceof IncludeRefContainer) {
            ICProject fCProject = ((IncludeRefContainer) selItem).getCProject();
            if (fCProject != null) project = fCProject.getProject();
          } else if (selItem instanceof IncludeReferenceProxy) {
            IncludeRefContainer irc = ((IncludeReferenceProxy) selItem).getIncludeRefContainer();
            if (irc != null) {
              ICProject fCProject = irc.getCProject();
              if (fCProject != null) project = fCProject.getProject();
            }
          } else if (selItem instanceof IAdaptable) {
            Object adapter = ((IAdaptable) selItem).getAdapter(IProject.class);
            if (adapter != null && adapter instanceof IProject) {
              project = (IProject) adapter;
            }
          }
          // Check whether the project is CDT project
          if (project != null) {
            if (!CoreModel.getDefault().isNewStyleProject(project)) project = null;
            else {
              ICConfigurationDescription[] tmp = getCfgs(project);
              if (tmp.length == 0) project = null;
            }
          }
          if (project != null) {
            fProjects.add(project);
          } else {
            badObject = true;
            break;
          }
        }
      } else if (selection instanceof ITextSelection) {
        // If a text selection check the selected part to see if we can find
        // an editor part that we can adapt to a resource and then
        // back to a project.
        IWorkbenchWindow window = CUIPlugin.getActiveWorkbenchWindow();
        if (window != null) {
          IWorkbenchPage page = window.getActivePage();
          if (page != null) {
            IWorkbenchPart part = page.getActivePart();
            if (part instanceof IEditorPart) {
              IEditorPart epart = (IEditorPart) part;
              IResource resource = epart.getEditorInput().getAdapter(IResource.class);
              if (resource != null) {
                IProject project = resource.getProject();
                badObject = !(project != null && CoreModel.getDefault().isNewStyleProject(project));

                if (!badObject) {
                  fProjects.add(project);
                }
              }
            }
          }
        }

      } else if (selection instanceof ImaginarySelection) {
        fProjects.add(((ImaginarySelection) selection).getProject());
      }
    }

    boolean enable = false;
    if (!badObject && !fProjects.isEmpty()) {
      Iterator<IProject> iter = fProjects.iterator();
      ICConfigurationDescription[] firstConfigs = getCfgs(iter.next());
      if (firstConfigs != null) {
        for (ICConfigurationDescription firstConfig : firstConfigs) {
          boolean common = true;
          Iterator<IProject> iter2 = fProjects.iterator();
          while (iter2.hasNext()) {
            ICConfigurationDescription[] currentConfigs = getCfgs(iter2.next());
            int j = 0;
            for (; j < currentConfigs.length; j++) {
              if (firstConfig.getName().equals(currentConfigs[j].getName())) break;
            }
            if (j == currentConfigs.length) {
              common = false;
              break;
            }
          }
          if (common) {
            enable = true;
            break;
          }
        }
      }
    }
    action.setEnabled(enable);

    // Bug 375760
    // If focus is on a view that doesn't provide a resource/project context. Use the selection in a
    // project/resource view. We support three views. If more than one is open, nevermind. If
    // there's only
    // one project in the workspace and it's a CDT one, use it unconditionally.
    //
    // Note that whatever project we get here is just a candidate; it's tested for suitability when
    // we
    // call ourselves recursively
    //
    if (badObject || fProjects.isEmpty()) {
      // Check for lone CDT project in workspace
      IProject[] projects = ResourcesPlugin.getWorkspace().getRoot().getProjects();
      if (projects != null && projects.length == 1) {
        IProject project = projects[0];
        if (CoreModel.getDefault().isNewStyleProject(project) && (getCfgs(project).length > 0)) {
          onSelectionChanged(action, new ImaginarySelection(project));
          return;
        }
      }

      // Check the three supported views
      IWorkbenchPage page = CUIPlugin.getActivePage();
      int viewCount = 0;
      if (page != null) {
        IViewReference theViewRef = null;
        IViewReference viewRef = null;

        theViewRef = page.findViewReference("org.eclipse.cdt.ui.CView"); // $NON-NLS-1$
        viewCount += (theViewRef != null) ? 1 : 0;

        viewRef = page.findViewReference("org.eclipse.ui.navigator.ProjectExplorer"); // $NON-NLS-1$
        viewCount += (viewRef != null) ? 1 : 0;
        theViewRef = (theViewRef == null) ? viewRef : theViewRef;

        viewRef = page.findViewReference("org.eclipse.ui.views.ResourceNavigator"); // $NON-NLS-1$
        viewCount += (viewRef != null) ? 1 : 0;
        theViewRef = (theViewRef == null) ? viewRef : theViewRef;

        if (theViewRef != null && viewCount == 1) {
          IViewPart view = theViewRef.getView(false);
          if (view != null) {
            ISelection cdtSelection = view.getSite().getSelectionProvider().getSelection();
            if (cdtSelection != null) {
              if (!cdtSelection.isEmpty()) {
                if (!cdtSelection.equals(selection)) { // avoids infinite recursion
                  onSelectionChanged(action, cdtSelection);
                }
              }
            }
          }
        }
      }
    }
  }
コード例 #21
0
  @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;
    }
  }