コード例 #1
0
  /*
   * (non-Javadoc)
   *
   * @see
   * org.eclipse.ui.internal.e4.compatibility.WorkbenchPartReference#initialize
   * (org.eclipse.ui.IWorkbenchPart)
   */
  @Override
  public void initialize(IWorkbenchPart part) throws PartInitException {
    IConfigurationElement element = descriptor.getConfigurationElement();
    editorSite = new EditorSite(getModel(), part, this, element);
    if (element == null) {
      editorSite.setExtensionId(descriptor.getId());
    }
    editorSite.setActionBars(
        createEditorActionBars((WorkbenchPage) getPage(), descriptor, editorSite));
    IEditorPart editor = (IEditorPart) part;
    try {
      editor.init(editorSite, getEditorInput());
    } catch (PartInitException e) {
      if (editor instanceof ErrorEditorPart) {
        editor.init(editorSite, new NullEditorInput(this));
      } else {
        throw e;
      }
    }

    if (editor.getSite() != editorSite || editor.getEditorSite() != editorSite) {
      String id = descriptor == null ? getModel().getElementId() : descriptor.getId();
      throw new PartInitException(NLS.bind(WorkbenchMessages.EditorManager_siteIncorrect, id));
    }

    if (part instanceof IPersistableEditor) {
      if (editorState != null) {
        ((IPersistableEditor) part).restoreState(editorState);
      } else if (useIPersistableEditor()) {
        String mementoString = getModel().getPersistedState().get(MEMENTO_KEY);
        if (mementoString != null) {
          try {
            IMemento createReadRoot = XMLMemento.createReadRoot(new StringReader(mementoString));
            IMemento editorStateMemento =
                createReadRoot.getChild(IWorkbenchConstants.TAG_EDITOR_STATE);
            if (editorStateMemento != null) {
              ((IPersistableEditor) part).restoreState(editorStateMemento);
            }
          } catch (WorkbenchException e) {
            throw new PartInitException(e.getStatus());
          }
        }
      }
    }

    legacyPart = part;
    addPropertyListeners();
  }
コード例 #2
0
  private void openedByBrowser(Item item, URL url) {
    if (url == null || item == null) {
      return;
    }

    WebBrowserEditorInput input = new WebBrowserEditorInput(url);
    // add for bug TDI-21189 at 2012-6-8,that a document exist is only opened one time in studio
    try {
      IWorkbenchPage page = getActivePage();
      IEditorReference[] iEditorReference = page.getEditorReferences();
      for (IEditorReference editors : iEditorReference) {
        if (WebBrowserEditor.WEB_BROWSER_EDITOR_ID.equals(editors.getId())) {
          IEditorPart iEditorPart = editors.getEditor(true);
          if (iEditorPart != null && iEditorPart instanceof WebBrowserEditor) {
            WebBrowserEditorInput webBrowserEditorInput =
                (WebBrowserEditorInput) iEditorPart.getEditorInput();
            if (webBrowserEditorInput != null && url.equals(webBrowserEditorInput.getURL())) {
              // page.activate(iEditorPart);
              iEditorPart.init(iEditorPart.getEditorSite(), webBrowserEditorInput);
              DocumentationUtil.setPartItemId(
                  (WebBrowserEditor) iEditorPart,
                  item.getProperty().getId(),
                  ERepositoryObjectType.getItemType(item));
              return;
            }
          }
        }
      }
      input.setName(item.getProperty().getLabel());
      input.setToolTipText(
          item.getProperty().getLabel() + " " + item.getProperty().getVersion()); // $NON-NLS-1$
      IEditorPart editorPart = page.openEditor(input, WebBrowserEditor.WEB_BROWSER_EDITOR_ID);
      if (editorPart != null && editorPart instanceof WebBrowserEditor) {
        DocumentationUtil.setPartItemId(
            (WebBrowserEditor) editorPart,
            item.getProperty().getId(),
            ERepositoryObjectType.getItemType(item));
      }
    } catch (PartInitException e) {
      MessageBoxExceptionHandler.process(e);
    }
  }