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));
}
}
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();
}
Aggregations