Package org.eclipse.core.runtime

Examples of org.eclipse.core.runtime.MultiStatus


            Throwable exception) {

        Assert.isTrue(message != null);
        Assert.isTrue(message.trim().length() != 0);

        return new MultiStatus(WorkbenchPlugin.PI_WORKBENCH, IStatus.ERROR,
                stati, message, exception);
    }
View Full Code Here


  /**
   * @see org.eclipse.ui.IPersistable
   */
  public IStatus restoreState(IMemento memento) {
    // Restore the editor area workbooks layout/relationship
    final MultiStatus result = new MultiStatus(PlatformUI.PLUGIN_ID,
        IStatus.OK,
        WorkbenchMessages.EditorManager_problemsRestoringEditors, null);
    final String activeWorkbookID[] = new String[1];
    final ArrayList visibleEditors = new ArrayList(5);
    final IEditorReference activeEditor[] = new IEditorReference[1];

    IMemento areaMem = memento.getChild(IWorkbenchConstants.TAG_AREA);
    if (areaMem != null) {
      result.add(editorPresentation.restoreState(areaMem));
      activeWorkbookID[0] = areaMem
          .getString(IWorkbenchConstants.TAG_ACTIVE_WORKBOOK);
    }

    // Loop through the editors.

    IMemento[] editorMems = memento
        .getChildren(IWorkbenchConstants.TAG_EDITOR);
    for (int x = 0; x < editorMems.length; x++) {
      // for dynamic UI - call restoreEditorState to replace code which is
      // commented out
      restoreEditorState(editorMems[x], visibleEditors, activeEditor,
          result);
    }

    // restore the presentation
    if (areaMem != null) {
      result.add(editorPresentation.restorePresentationState(areaMem));
    }
    try {
      StartupThreading.runWithThrowable(new StartupRunnable(){

        public void runWithException() throws Throwable {
          // Update each workbook with its visible editor.
          for (int i = 0; i < visibleEditors.size(); i++) {
            setVisibleEditor((IEditorReference) visibleEditors.get(i),
                false);
          }

          // Update the active workbook
          if (activeWorkbookID[0] != null) {
            editorPresentation
                .setActiveEditorWorkbookFromID(activeWorkbookID[0]);
          }

          if (activeEditor[0] != null) {
            IWorkbenchPart editor = activeEditor[0].getPart(true);

            if (editor != null) {
              page.activate(editor);
            }
          }
        }});
    }
    catch (Throwable t) {
      // The exception is already logged.
      result
          .add(new Status(
              IStatus.ERROR,
              PlatformUI.PLUGIN_ID,
              0,
              WorkbenchMessages.EditorManager_exceptionRestoringEditor,
View Full Code Here

  /**
   * @see IPersistablePart
   */
  public IStatus saveState(final IMemento memento) {

    final MultiStatus result = new MultiStatus(PlatformUI.PLUGIN_ID,
        IStatus.OK,
        WorkbenchMessages.EditorManager_problemsSavingEditors, null);

    // Save the editor area workbooks layout/relationship
    IMemento editorAreaMem = memento
        .createChild(IWorkbenchConstants.TAG_AREA);
    result.add(editorPresentation.saveState(editorAreaMem));

    // Save the active workbook id
    editorAreaMem.putString(IWorkbenchConstants.TAG_ACTIVE_WORKBOOK,
        editorPresentation.getActiveEditorWorkbookID());

View Full Code Here

  protected void saveEditorState(IMemento mem, IEditorReference ed,
      MultiStatus res) {
    final EditorReference editorRef = (EditorReference) ed;
    final IEditorPart editor = ed.getEditor(false);
    final IMemento memento = mem;
    final MultiStatus result = res;
    if (!(editor.getEditorSite() instanceof EditorSite)) {
      return;
    }
    final EditorSite site = (EditorSite) editor.getEditorSite();
    if (site.getPane() instanceof MultiEditorInnerPane) {
      return;
    }

    SafeRunner.run(new SafeRunnable() {
      public void run() {
        // Get the input.
        IEditorInput input = editor.getEditorInput();
        IPersistableElement persistable = input.getPersistable();
        if (persistable == null) {
          return;
        }

        // Save editor.
        IMemento editorMem = memento
            .createChild(IWorkbenchConstants.TAG_EDITOR);
        editorMem.putString(IWorkbenchConstants.TAG_TITLE, editorRef
            .getTitle());
        editorMem.putString(IWorkbenchConstants.TAG_NAME, editorRef
            .getName());
        editorMem.putString(IWorkbenchConstants.TAG_ID, editorRef
            .getId());
        editorMem.putString(IWorkbenchConstants.TAG_TOOLTIP, editorRef
            .getTitleToolTip());

        editorMem.putString(IWorkbenchConstants.TAG_PART_NAME,
            editorRef.getPartName());
       
        if (editor instanceof IWorkbenchPart3) {
          Map properties = ((IWorkbenchPart3) editor)
              .getPartProperties();
          if (!properties.isEmpty()) {
            IMemento propBag = editorMem
                .createChild(IWorkbenchConstants.TAG_PROPERTIES);
            Iterator i = properties.entrySet().iterator();
            while (i.hasNext()) {
              Map.Entry entry = (Map.Entry) i.next();
              IMemento p = propBag.createChild(
                  IWorkbenchConstants.TAG_PROPERTY,
                  (String) entry.getKey());
              p.putTextData((String) entry.getValue());
            }
          }
        }

        if (editorRef.isPinned()) {
          editorMem.putString(IWorkbenchConstants.TAG_PINNED, "true"); //$NON-NLS-1$
        }

        EditorPane editorPane = (EditorPane) ((EditorSite) editor
            .getEditorSite()).getPane();
        editorMem.putString(IWorkbenchConstants.TAG_WORKBOOK,
            editorPane.getWorkbook().getID());

        if (editor == page.getActivePart()) {
          editorMem.putString(IWorkbenchConstants.TAG_ACTIVE_PART,
              "true"); //$NON-NLS-1$
        }

        if (editorPane == editorPane.getWorkbook().getSelection()) {
          editorMem.putString(IWorkbenchConstants.TAG_FOCUS, "true"); //$NON-NLS-1$
        }

        if (input instanceof IPathEditorInput) {
          IPath path = ((IPathEditorInput) input).getPath();
          if (path != null) {
            editorMem.putString(IWorkbenchConstants.TAG_PATH, path
                .toString());
          }
        }

        // Save input.
        IMemento inputMem = editorMem
            .createChild(IWorkbenchConstants.TAG_INPUT);
        inputMem.putString(IWorkbenchConstants.TAG_FACTORY_ID,
            persistable.getFactoryId());
        persistable.saveState(inputMem);
       
        // any editors that want to persist state
        if (editor instanceof IPersistableEditor) {
          IMemento editorState = editorMem
              .createChild(IWorkbenchConstants.TAG_EDITOR_STATE);
          ((IPersistableEditor) editor).saveState(editorState);
        }
      }

      public void handleException(Throwable e) {
        result
            .add(new Status(
                IStatus.ERROR,
                PlatformUI.PLUGIN_ID,
                0,
                NLS
View Full Code Here

        PerspectiveRegistry perspRegistry = (PerspectiveRegistry) WorkbenchPlugin
                .getDefault().getPerspectiveRegistry();
        try {
            IMemento memento = perspRegistry.getCustomPersp(persp.getId());
            // Restore the layout state.
            MultiStatus status = new MultiStatus(
                    PlatformUI.PLUGIN_ID,
                    IStatus.OK,
                    NLS.bind(WorkbenchMessages.Perspective_unableToRestorePerspective, persp.getLabel()),
                    null);
            status.merge(restoreState(memento));
            status.merge(restoreState());
            if (status.getSeverity() != IStatus.OK) {
                unableToOpenPerspective(persp, status);
            }
        } catch (IOException e) {
            unableToOpenPerspective(persp, null);
        } catch (WorkbenchException e) {
View Full Code Here

    /**
     * Fills a presentation with layout data.
     * Note: This method should not modify the current state of the perspective.
     */
    public IStatus restoreState(IMemento memento) {
        MultiStatus result = new MultiStatus(
                PlatformUI.PLUGIN_ID,
                IStatus.OK,
                WorkbenchMessages.Perspective_problemsRestoringPerspective, null);

        // Create persp descriptor.
        descriptor = new PerspectiveDescriptor(null, null, null);
        result.add(descriptor.restoreState(memento));
        PerspectiveDescriptor desc = (PerspectiveDescriptor) WorkbenchPlugin
                .getDefault().getPerspectiveRegistry().findPerspectiveWithId(
                        descriptor.getId());
        if (desc != null) {
      descriptor = desc;
    }

        this.memento = memento;
        // Add the visible views.
        IMemento views[] = memento.getChildren(IWorkbenchConstants.TAG_VIEW);
        result.merge(createReferences(views));

        memento = memento.getChild(IWorkbenchConstants.TAG_FAST_VIEWS);
        if (memento != null) {
            views = memento.getChildren(IWorkbenchConstants.TAG_VIEW);
            result.merge(createReferences(views));
        }
        return result;
    }
View Full Code Here

        }
        return result;
    }

    IStatus createReferences(IMemento views[]) {
        MultiStatus result = new MultiStatus(PlatformUI.PLUGIN_ID, IStatus.OK,
                WorkbenchMessages.Perspective_problemsRestoringViews, null);

        for (int x = 0; x < views.length; x++) {
            // Get the view details.
            IMemento childMem = views[x];
            String id = childMem.getString(IWorkbenchConstants.TAG_ID);
            // skip creation of the intro reference -  it's handled elsewhere.
            if (id.equals(IIntroConstants.INTRO_VIEW_ID)) {
        continue;
      }

            String secondaryId = ViewFactory.extractSecondaryId(id);
            if (secondaryId != null) {
                id = ViewFactory.extractPrimaryId(id);
            }
            // Create and open the view.
            try {
                if (!"true".equals(childMem.getString(IWorkbenchConstants.TAG_REMOVED))) { //$NON-NLS-1$
                    viewFactory.createView(id, secondaryId);
                }
            } catch (PartInitException e) {
                childMem.putString(IWorkbenchConstants.TAG_REMOVED, "true"); //$NON-NLS-1$
                result.add(StatusUtil.newStatus(IStatus.ERROR,
                        e.getMessage() == null ? "" : e.getMessage(), //$NON-NLS-1$
                        e));
            }
        }
        return result;
View Full Code Here

    public IStatus restoreState() {
        if (this.memento == null) {
      return new Status(IStatus.OK, PlatformUI.PLUGIN_ID, 0, "", null); //$NON-NLS-1$
    }

        MultiStatus result = new MultiStatus(
                PlatformUI.PLUGIN_ID,
                IStatus.OK,
                WorkbenchMessages.Perspective_problemsRestoringPerspective, null);

        IMemento memento = this.memento;
        this.memento = null;

        final IMemento boundsMem = memento.getChild(IWorkbenchConstants.TAG_WINDOW);
        if (boundsMem != null) {
          final Rectangle r = new Rectangle(0, 0, 0, 0);
            r.x = boundsMem.getInteger(IWorkbenchConstants.TAG_X).intValue();
            r.y = boundsMem.getInteger(IWorkbenchConstants.TAG_Y).intValue();
            r.height = boundsMem.getInteger(IWorkbenchConstants.TAG_HEIGHT)
                    .intValue();
            r.width = boundsMem.getInteger(IWorkbenchConstants.TAG_WIDTH)
                    .intValue();
          StartupThreading.runWithoutExceptions(new StartupRunnable() {

        public void runWithException() throws Throwable {
          if (page.getWorkbenchWindow().getPages().length == 0) {
                    page.getWorkbenchWindow().getShell().setBounds(r);
                }
        }
      });

        }

        // Create an empty presentation..
        final PerspectiveHelper [] presArray = new PerspectiveHelper[1];
        StartupThreading.runWithoutExceptions(new StartupRunnable() {

      public void runWithException() throws Throwable {
        ViewSashContainer mainLayout = new ViewSashContainer(page, getClientComposite());
        presArray[0] = new PerspectiveHelper(page, mainLayout, Perspective.this);
      }});
        final PerspectiveHelper pres = presArray[0];

        // Read the layout.
        result.merge(pres.restoreState(memento
                .getChild(IWorkbenchConstants.TAG_LAYOUT)));

        StartupThreading.runWithoutExceptions(new StartupRunnable() {

      public void runWithException() throws Throwable {
        // Add the editor workbook. Do not hide it now.
            pres.replacePlaceholderWithPart(editorArea);
      }});

        // Add the visible views.
        IMemento[] views = memento.getChildren(IWorkbenchConstants.TAG_VIEW);

        for (int x = 0; x < views.length; x++) {
            // Get the view details.
            IMemento childMem = views[x];
            String id = childMem.getString(IWorkbenchConstants.TAG_ID);
            String secondaryId = ViewFactory.extractSecondaryId(id);
            if (secondaryId != null) {
                id = ViewFactory.extractPrimaryId(id);
            }

            // skip the intro as it is restored higher up in workbench.
            if (id.equals(IIntroConstants.INTRO_VIEW_ID)) {
        continue;
      }
           
            // Create and open the view.
            IViewReference viewRef = viewFactory.getView(id, secondaryId);
            WorkbenchPartReference ref = (WorkbenchPartReference) viewRef;

            // report error
            if (ref == null) {
                String key = ViewFactory.getKey(id, secondaryId);
                result.add(new Status(IStatus.ERROR, PlatformUI.PLUGIN_ID, 0,
                        NLS.bind(WorkbenchMessages.Perspective_couldNotFind,  key ), null));
                continue;
            }
            boolean willPartBeVisible = pres.willPartBeVisible(ref.getId(),
                    secondaryId);
View Full Code Here

    /**
     * Save the layout.
     */
    public IStatus saveState(IMemento memento) {
        MultiStatus result = new MultiStatus(
                PlatformUI.PLUGIN_ID,
                IStatus.OK,
                WorkbenchMessages.Perspective_problemsSavingPerspective, null);

        result.merge(saveState(memento, descriptor, true));

        return result;
    }
View Full Code Here

    /**
     * Save the layout.
     */
    private IStatus saveState(IMemento memento, PerspectiveDescriptor p,
            boolean saveInnerViewState) {
        MultiStatus result = new MultiStatus(
                PlatformUI.PLUGIN_ID,
                IStatus.OK,
                WorkbenchMessages.Perspective_problemsSavingPerspective, null);

        if (this.memento != null) {
            memento.putMemento(this.memento);
            return result;
        }

        // Save the version number.
        memento.putString(IWorkbenchConstants.TAG_VERSION, VERSION_STRING);
        result.add(p.saveState(memento));
        if (!saveInnerViewState) {
            Rectangle bounds = page.getWorkbenchWindow().getShell().getBounds();
            IMemento boundsMem = memento
                    .createChild(IWorkbenchConstants.TAG_WINDOW);
            boundsMem.putInteger(IWorkbenchConstants.TAG_X, bounds.x);
            boundsMem.putInteger(IWorkbenchConstants.TAG_Y, bounds.y);
            boundsMem.putInteger(IWorkbenchConstants.TAG_HEIGHT, bounds.height);
            boundsMem.putInteger(IWorkbenchConstants.TAG_WIDTH, bounds.width);
        }


        // Save the "always on" action sets.
        Iterator itr = alwaysOnActionSets.iterator();
        while (itr.hasNext()) {
            IActionSetDescriptor desc = (IActionSetDescriptor) itr.next();
            IMemento child = memento
                    .createChild(IWorkbenchConstants.TAG_ALWAYS_ON_ACTION_SET);
            child.putString(IWorkbenchConstants.TAG_ID, desc.getId());
        }

        // Save the "always off" action sets.
        itr = alwaysOffActionSets.iterator();
        while (itr.hasNext()) {
            IActionSetDescriptor desc = (IActionSetDescriptor) itr.next();
            IMemento child = memento
                    .createChild(IWorkbenchConstants.TAG_ALWAYS_OFF_ACTION_SET);
            child.putString(IWorkbenchConstants.TAG_ID, desc.getId());
        }

        // Save "show view actions"
        itr = showViewShortcuts.iterator();
        while (itr.hasNext()) {
            String str = (String) itr.next();
            IMemento child = memento
                    .createChild(IWorkbenchConstants.TAG_SHOW_VIEW_ACTION);
            child.putString(IWorkbenchConstants.TAG_ID, str);
        }

        // Save "show in times"
        itr = showInTimes.keySet().iterator();
        while (itr.hasNext()) {
            String id = (String) itr.next();
            Long time = (Long) showInTimes.get(id);
            IMemento child = memento
                    .createChild(IWorkbenchConstants.TAG_SHOW_IN_TIME);
            child.putString(IWorkbenchConstants.TAG_ID, id);
            child.putString(IWorkbenchConstants.TAG_TIME, time.toString());
        }

        // Save "new wizard actions".
        itr = newWizardShortcuts.iterator();
        while (itr.hasNext()) {
            String str = (String) itr.next();
            IMemento child = memento
                    .createChild(IWorkbenchConstants.TAG_NEW_WIZARD_ACTION);
            child.putString(IWorkbenchConstants.TAG_ID, str);
        }

        // Save "perspective actions".
        itr = perspectiveShortcuts.iterator();
        while (itr.hasNext()) {
            String str = (String) itr.next();
            IMemento child = memento
                    .createChild(IWorkbenchConstants.TAG_PERSPECTIVE_ACTION);
            child.putString(IWorkbenchConstants.TAG_ID, str);
        }

        // Get visible views.
        List viewPanes = new ArrayList(5);
        presentation.collectViewPanes(viewPanes);

        // Save the views.
        itr = viewPanes.iterator();
        int errors = 0;
        while (itr.hasNext()) {
            ViewPane pane = (ViewPane) itr.next();
            IViewReference ref = pane.getViewReference();
            IMemento viewMemento = memento
                    .createChild(IWorkbenchConstants.TAG_VIEW);
            viewMemento.putString(IWorkbenchConstants.TAG_ID, ViewFactory
                    .getKey(ref));
        }

        // save all fastview state
        if (fastViewManager != null)
          fastViewManager.saveState(memento);
     
        // Save the view layout recs.
        for (Iterator i = mapIDtoViewLayoutRec.keySet().iterator(); i.hasNext();) {
            String compoundId = (String) i.next();
            ViewLayoutRec rec = (ViewLayoutRec) mapIDtoViewLayoutRec
                    .get(compoundId);
            if (rec != null
                    && (!rec.isCloseable || !rec.isMoveable || rec.isStandalone)) {
                IMemento layoutMemento = memento
                        .createChild(IWorkbenchConstants.TAG_VIEW_LAYOUT_REC);
                layoutMemento.putString(IWorkbenchConstants.TAG_ID, compoundId);
                if (!rec.isCloseable) {
                    layoutMemento.putString(IWorkbenchConstants.TAG_CLOSEABLE,
                            IWorkbenchConstants.FALSE);
                }
                if (!rec.isMoveable) {
                    layoutMemento.putString(IWorkbenchConstants.TAG_MOVEABLE,
                            IWorkbenchConstants.FALSE);
                }
                if (rec.isStandalone) {
                    layoutMemento.putString(IWorkbenchConstants.TAG_STANDALONE,
                            IWorkbenchConstants.TRUE);
                    layoutMemento.putString(IWorkbenchConstants.TAG_SHOW_TITLE,
                            String.valueOf(rec.showTitle));
                }
            }
        }

        if (errors > 0) {
            String message = WorkbenchMessages.Perspective_multipleErrors;
            if (errors == 1) {
        message = WorkbenchMessages.Perspective_oneError;
      }
            MessageDialog.openError(null,
                    WorkbenchMessages.Error, message);
        }

        // Save the layout.
        IMemento childMem = memento.createChild(IWorkbenchConstants.TAG_LAYOUT);
        result.add(presentation.saveState(childMem));

        // Save the editor visibility state
        if (isEditorAreaVisible()) {
      memento.putInteger(IWorkbenchConstants.TAG_AREA_VISIBLE, 1);
    } else {
View Full Code Here

TOP

Related Classes of org.eclipse.core.runtime.MultiStatus

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.