Search in sources :

Example 1 with SaveablesLifecycleEvent

use of org.eclipse.ui.SaveablesLifecycleEvent 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 SaveablesLifecycleEvent

use of org.eclipse.ui.SaveablesLifecycleEvent 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)

Example 3 with SaveablesLifecycleEvent

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

the class NavigatorSaveablesService method recomputeSaveablesAndNotify.

private void recomputeSaveablesAndNotify(boolean recomputeProviders, String startedBundleIdOrNull) {
    if (recomputeProviders && startedBundleIdOrNull == null && saveablesProviders != null) {
        // TODO optimize this
        for (int i = 0; i < saveablesProviders.length; i++) {
            saveablesProviders[i].dispose();
        }
        saveablesProviders = null;
    } else if (startedBundleIdOrNull != null) {
        if (inactivePluginsWithSaveablesProviders.containsKey(startedBundleIdOrNull)) {
            updateSaveablesProviders(startedBundleIdOrNull);
        }
    }
    Set oldSaveables = new HashSet(Arrays.asList(currentSaveables));
    currentSaveables = computeSaveables();
    Set newSaveables = new HashSet(Arrays.asList(currentSaveables));
    final Set removedSaveables = new HashSet(oldSaveables);
    removedSaveables.removeAll(newSaveables);
    final Set addedSaveables = new HashSet(newSaveables);
    addedSaveables.removeAll(oldSaveables);
    if (addedSaveables.size() > 0) {
        Display.getDefault().asyncExec(new Runnable() {

            public void run() {
                if (isDisposed()) {
                    return;
                }
                outsideListener.handleLifecycleEvent(new SaveablesLifecycleEvent(saveablesSource, SaveablesLifecycleEvent.POST_OPEN, (Saveable[]) addedSaveables.toArray(new Saveable[addedSaveables.size()]), false));
            }
        });
    }
    // an appropriate PRE_CLOSE
    if (removedSaveables.size() > 0) {
        Display.getDefault().asyncExec(new Runnable() {

            public void run() {
                if (isDisposed()) {
                    return;
                }
                outsideListener.handleLifecycleEvent(new SaveablesLifecycleEvent(saveablesSource, SaveablesLifecycleEvent.PRE_CLOSE, (Saveable[]) removedSaveables.toArray(new Saveable[removedSaveables.size()]), true));
                outsideListener.handleLifecycleEvent(new SaveablesLifecycleEvent(saveablesSource, SaveablesLifecycleEvent.POST_CLOSE, (Saveable[]) removedSaveables.toArray(new Saveable[removedSaveables.size()]), false));
            }
        });
    }
}
Also used : Saveable(org.eclipse.ui.Saveable) HashSet(java.util.HashSet) Set(java.util.Set) HashSet(java.util.HashSet) SaveablesLifecycleEvent(org.eclipse.ui.SaveablesLifecycleEvent)

Example 4 with SaveablesLifecycleEvent

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

the class SaveablesProvider method fireSaveablesClosing.

/**
 * Notifies the listener that the given models are about to be closed in
 * this model provider. This method must be called on the UI thread.
 *
 * @param models
 * @param force
 *            true if the closing may be canceled by the user
 * @return true if the listener vetoed the closing (may be ignored if force
 *         is true)
 */
protected final boolean fireSaveablesClosing(Saveable[] models, boolean force) {
    SaveablesLifecycleEvent saveablesLifecycleEvent = new SaveablesLifecycleEvent(this, SaveablesLifecycleEvent.PRE_CLOSE, models, force);
    listener.handleLifecycleEvent(saveablesLifecycleEvent);
    return saveablesLifecycleEvent.isVeto();
}
Also used : SaveablesLifecycleEvent(org.eclipse.ui.SaveablesLifecycleEvent)

Aggregations

SaveablesLifecycleEvent (org.eclipse.ui.SaveablesLifecycleEvent)4 ISaveablesLifecycleListener (org.eclipse.ui.ISaveablesLifecycleListener)2 HashSet (java.util.HashSet)1 Set (java.util.Set)1 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 Saveable (org.eclipse.ui.Saveable)1 OperationHistoryActionHandler (org.eclipse.ui.operations.OperationHistoryActionHandler)1