Search in sources :

Example 1 with ISaveablesLifecycleListener

use of org.eclipse.ui.ISaveablesLifecycleListener in project eclipse.platform.text by eclipse.

the class AbstractTextEditor method doSetInput.

/**
 * Called directly from <code>setInput</code> and from within a workspace
 * runnable from <code>init</code>, this method does the actual setting
 * of the editor input. Closes the editor if <code>input</code> is
 * <code>null</code>. Disconnects from any previous editor input and its
 * document provider and connects to the new one.
 * <p>
 * Subclasses may extend.
 * </p>
 *
 * @param input the input to be set
 * @exception CoreException if input cannot be connected to the document
 *            provider
 */
protected void doSetInput(IEditorInput input) throws CoreException {
    ISaveablesLifecycleListener listener = getSite().getService(ISaveablesLifecycleListener.class);
    if (listener == null)
        fSavable = null;
    if (input == null) {
        close(isSaveOnCloseNeeded());
        if (fSavable != null) {
            listener.handleLifecycleEvent(new SaveablesLifecycleEvent(this, SaveablesLifecycleEvent.POST_CLOSE, getSaveables(), false));
            fSavable.disconnectEditor();
            fSavable = null;
        }
    } else {
        boolean mustSendLifeCycleEvent = false;
        if (fSavable != null) {
            listener.handleLifecycleEvent(new SaveablesLifecycleEvent(this, SaveablesLifecycleEvent.POST_CLOSE, getSaveables(), false));
            fSavable.disconnectEditor();
            fSavable = null;
            mustSendLifeCycleEvent = true;
        }
        IEditorInput oldInput = getEditorInput();
        if (oldInput != null)
            getDocumentProvider().disconnect(oldInput);
        super.setInput(input);
        updateDocumentProvider(input);
        IDocumentProvider provider = getDocumentProvider();
        if (provider == null) {
            IStatus s = new Status(IStatus.ERROR, PlatformUI.PLUGIN_ID, IStatus.OK, EditorMessages.Editor_error_no_provider, null);
            throw new CoreException(s);
        }
        provider.connect(input);
        initializeTitle(input);
        if (fSourceViewer != null) {
            initializeSourceViewer(input);
            // Reset the undo context for the undo and redo action handlers
            IAction undoAction = getAction(ITextEditorActionConstants.UNDO);
            IAction redoAction = getAction(ITextEditorActionConstants.REDO);
            boolean areOperationActionHandlersInstalled = undoAction instanceof OperationHistoryActionHandler && redoAction instanceof OperationHistoryActionHandler;
            IUndoContext undoContext = getUndoContext();
            if (undoContext != null && areOperationActionHandlersInstalled) {
                ((OperationHistoryActionHandler) undoAction).setContext(undoContext);
                ((OperationHistoryActionHandler) redoAction).setContext(undoContext);
            } else {
                createUndoRedoActions();
            }
        }
        if (fIsOverwriting)
            toggleOverwriteMode();
        setInsertMode(getLegalInsertModes().get(0));
        updateCaret();
        updateStatusField(ITextEditorActionConstants.STATUS_CATEGORY_ELEMENT_STATE);
        if (fSelectionListener != null)
            fSelectionListener.setDocument(getDocumentProvider().getDocument(input));
        IVerticalRuler ruler = getVerticalRuler();
        if (ruler instanceof CompositeRuler)
            updateContributedRulerColumns((CompositeRuler) ruler);
        // Send savable life-cycle if needed.
        if (mustSendLifeCycleEvent && listener != null)
            listener.handleLifecycleEvent(new SaveablesLifecycleEvent(this, SaveablesLifecycleEvent.POST_OPEN, getSaveables(), false));
    }
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) OperationHistoryActionHandler(org.eclipse.ui.operations.OperationHistoryActionHandler) IStatus(org.eclipse.core.runtime.IStatus) IAction(org.eclipse.jface.action.IAction) IVerticalRuler(org.eclipse.jface.text.source.IVerticalRuler) CompositeRuler(org.eclipse.jface.text.source.CompositeRuler) ISaveablesLifecycleListener(org.eclipse.ui.ISaveablesLifecycleListener) IUndoContext(org.eclipse.core.commands.operations.IUndoContext) CoreException(org.eclipse.core.runtime.CoreException) IEditorInput(org.eclipse.ui.IEditorInput) SaveablesLifecycleEvent(org.eclipse.ui.SaveablesLifecycleEvent)

Example 2 with ISaveablesLifecycleListener

use of org.eclipse.ui.ISaveablesLifecycleListener in project polymap4-core by Polymap4.

the class CommonNavigator method createPartControl.

/**
 * <p>
 * Create the CommonViewer part control and setup the default providers as
 * necessary.
 * </p>
 *
 * @see org.eclipse.ui.part.WorkbenchPart#createPartControl(org.eclipse.swt.widgets.Composite)
 */
public void createPartControl(Composite aParent) {
    final PerformanceStats stats = PerformanceStats.getStats(PERF_CREATE_PART_CONTROL, this);
    stats.startRun();
    commonViewer = createCommonViewer(aParent);
    commonViewer.setCommonNavigator(this);
    try {
        commonViewer.getControl().setRedraw(false);
        INavigatorFilterService filterService = commonViewer.getNavigatorContentService().getFilterService();
        ViewerFilter[] visibleFilters = filterService.getVisibleFilters(true);
        for (int i = 0; i < visibleFilters.length; i++) {
            commonViewer.addFilter(visibleFilters[i]);
        }
        commonViewer.setSorter(new CommonViewerSorter());
        /*
			 * make sure input is set after sorters and filters to avoid unnecessary
			 * refreshes
			 */
        commonViewer.setInput(getInitialInput());
        getSite().setSelectionProvider(commonViewer);
        // $NON-NLS-1$
        setPartName(getConfigurationElement().getAttribute("name"));
    } finally {
        commonViewer.getControl().setRedraw(true);
    }
    commonViewer.createFrameList();
    /*
		 * Create the CommonNavigatorManager last because information about the
		 * state of the CommonNavigator is required for the initialization of
		 * the CommonNavigatorManager
		 */
    commonManager = createCommonManager();
    if (memento != null) {
        commonViewer.getNavigatorContentService().restoreState(memento);
    }
    commonActionGroup = createCommonActionGroup();
    commonActionGroup.fillActionBars(getViewSite().getActionBars());
    ISaveablesLifecycleListener saveablesLifecycleListener = new ISaveablesLifecycleListener() {

        ISaveablesLifecycleListener siteSaveablesLifecycleListener = (ISaveablesLifecycleListener) getSite().getService(ISaveablesLifecycleListener.class);

        public void handleLifecycleEvent(SaveablesLifecycleEvent event) {
            if (event.getEventType() == SaveablesLifecycleEvent.DIRTY_CHANGED) {
                firePropertyChange(PROP_DIRTY);
            }
            siteSaveablesLifecycleListener.handleLifecycleEvent(event);
        }
    };
    commonViewer.getNavigatorContentService().getSaveablesService().init(this, getCommonViewer(), saveablesLifecycleListener);
    commonViewer.addSelectionChangedListener(new ISelectionChangedListener() {

        public void selectionChanged(SelectionChangedEvent event) {
            firePropertyChange(PROP_DIRTY);
        }
    });
    String helpContext = commonViewer.getNavigatorContentService().getViewerDescriptor().getHelpContext();
    if (helpContext == null)
        helpContext = HELP_CONTEXT;
    PlatformUI.getWorkbench().getHelpSystem().setHelp(commonViewer.getControl(), helpContext);
    stats.endRun();
}
Also used : PerformanceStats(org.eclipse.core.runtime.PerformanceStats) ViewerFilter(org.eclipse.jface.viewers.ViewerFilter) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) ISaveablesLifecycleListener(org.eclipse.ui.ISaveablesLifecycleListener) SaveablesLifecycleEvent(org.eclipse.ui.SaveablesLifecycleEvent)

Aggregations

ISaveablesLifecycleListener (org.eclipse.ui.ISaveablesLifecycleListener)2 SaveablesLifecycleEvent (org.eclipse.ui.SaveablesLifecycleEvent)2 IUndoContext (org.eclipse.core.commands.operations.IUndoContext)1 CoreException (org.eclipse.core.runtime.CoreException)1 IStatus (org.eclipse.core.runtime.IStatus)1 PerformanceStats (org.eclipse.core.runtime.PerformanceStats)1 Status (org.eclipse.core.runtime.Status)1 IAction (org.eclipse.jface.action.IAction)1 CompositeRuler (org.eclipse.jface.text.source.CompositeRuler)1 IVerticalRuler (org.eclipse.jface.text.source.IVerticalRuler)1 ISelectionChangedListener (org.eclipse.jface.viewers.ISelectionChangedListener)1 SelectionChangedEvent (org.eclipse.jface.viewers.SelectionChangedEvent)1 ViewerFilter (org.eclipse.jface.viewers.ViewerFilter)1 IEditorInput (org.eclipse.ui.IEditorInput)1 OperationHistoryActionHandler (org.eclipse.ui.operations.OperationHistoryActionHandler)1