Search in sources :

Example 1 with IExecutionDelegatable

use of org.eclipse.wst.sse.core.internal.text.IExecutionDelegatable in project webtools.sourceediting by eclipse.

the class StructuredTextEditor method dispose.

/*
	 * (non-Javadoc)
	 * 
	 * @see org.eclipse.ui.IWorkbenchPart#dispose()
	 */
public void dispose() {
    // $NON-NLS-1$ //$NON-NLS-2$
    Logger.trace("Source Editor", "StructuredTextEditor::dispose entry");
    if (org.eclipse.wst.sse.core.internal.util.Debug.perfTestAdapterClassLoading) {
        // $NON-NLS-1$
        System.out.println("Total calls to getAdapter: " + adapterRequests);
        // $NON-NLS-1$
        System.out.println("Total time in getAdapter: " + adapterTime);
        // $NON-NLS-1$
        System.out.println("Average time per call: " + (adapterTime / adapterRequests));
    }
    ISourceViewer viewer = getSourceViewer();
    if (viewer instanceof ITextViewerExtension)
        ((ITextViewerExtension) viewer).removeVerifyKeyListener(fPairInserter);
    // dispose of information presenter
    if (fInformationPresenter != null) {
        fInformationPresenter.dispose();
        fInformationPresenter = null;
    }
    if (fOutlineHandler != null) {
        fOutlineHandler.dispose();
        fOutlineHandler = null;
    }
    // dispose of selection history
    if (fSelectionHistory != null) {
        fSelectionHistory.dispose();
        fSelectionHistory = null;
    }
    if (fProjectionSupport != null) {
        fProjectionSupport.dispose();
        fProjectionSupport = null;
    }
    if (fFoldingGroup != null) {
        fFoldingGroup.dispose();
        fFoldingGroup = null;
    }
    // dispose of menus that were being tracked
    if (fTextContextMenu != null) {
        fTextContextMenu.dispose();
        fTextContextMenu = null;
    }
    if (fRulerContextMenu != null) {
        fRulerContextMenu.dispose();
        fRulerContextMenu = null;
    }
    if (fTextContextMenuManager != null) {
        fTextContextMenuManager.removeMenuListener(getContextMenuListener());
        fTextContextMenuManager.removeAll();
        fTextContextMenuManager.dispose();
    }
    if (fRulerContextMenuManager != null) {
        fRulerContextMenuManager.removeMenuListener(getContextMenuListener());
        fRulerContextMenuManager.removeAll();
        fRulerContextMenuManager.dispose();
    }
    // less severe.
    if (fStructuredModel != null) {
        fStructuredModel.removeModelStateListener(getInternalModelStateListener());
    // fStructuredModel.setStructuredDocument(null);
    /* BUG398460 - Editor is still marked dirty when relaunching editor after closing without saving changes */
    // fStructuredModel = null;
    }
    // to document, so nothing to remove
    if (getDocumentProvider() != null) {
        IDocument doc = getDocumentProvider().getDocument(getEditorInput());
        if (doc != null) {
            if (doc instanceof IExecutionDelegatable) {
                ((IExecutionDelegatable) doc).setExecutionDelegate(null);
            }
        }
    }
    // up after themselves
    if (fOutlinePage != null) {
        if (fOutlinePage instanceof ConfigurableContentOutlinePage && fOutlinePageListener != null) {
            ((ConfigurableContentOutlinePage) fOutlinePage).removeDoubleClickListener(fOutlinePageListener);
        }
        if (fOutlinePageListener != null) {
            fOutlinePage.removeSelectionChangedListener(fOutlinePageListener);
            fOutlinePageListener = null;
        }
        fOutlinePage = null;
    }
    fEditorDisposed = true;
    disposeModelDependentFields();
    if (fDropTarget != null)
        fDropTarget.dispose();
    if (fPartListener != null) {
        getSite().getWorkbenchWindow().getPartService().removePartListener(fPartListener);
        fPartListener = null;
    }
    uninstallSemanticHighlighting();
    if (fPairInserter != null) {
        fPairInserter.dispose();
        fPairInserter = null;
    }
    setPreferenceStore(null);
    /*
		 * Strictly speaking, but following null outs should not be needed,
		 * but in the event of a memory leak, they make the memory leak less
		 * severe
		 */
    fDropAdapter = null;
    fDropTarget = null;
    if (fStructuredSelectionProvider != null) {
        fStructuredSelectionProvider.dispose();
        fStructuredSelectionProvider = null;
    }
    if (fStatusLineLabelProvider != null) {
        fStatusLineLabelProvider.dispose();
        fStatusLineLabelProvider = null;
    }
    setStatusLineMessage(null);
    super.dispose();
    // $NON-NLS-1$ //$NON-NLS-2$
    Logger.trace("Source Editor", "StructuredTextEditor::dispose exit");
}
Also used : ITextViewerExtension(org.eclipse.jface.text.ITextViewerExtension) ConfigurableContentOutlinePage(org.eclipse.wst.sse.ui.internal.contentoutline.ConfigurableContentOutlinePage) IExecutionDelegatable(org.eclipse.wst.sse.core.internal.text.IExecutionDelegatable) ISourceViewer(org.eclipse.jface.text.source.ISourceViewer) IDocument(org.eclipse.jface.text.IDocument)

Example 2 with IExecutionDelegatable

use of org.eclipse.wst.sse.core.internal.text.IExecutionDelegatable in project webtools.sourceediting by eclipse.

the class StructuredTextEditor method tryToGetModel.

/**
 * <p>Attempts to get the {@link IStructuredModel} for the given {@link IEditorInput}</p>
 *
 * @param input the {@link IEditorInput} to try and get the {@link IStructuredModel} for
 *
 * @return The {@link IStructuredModel} associated with the given {@link IEditorInput} or
 * <code>null</code> if no associated {@link IStructuredModel} could be found.
 */
private IStructuredModel tryToGetModel(IEditorInput input) {
    IStructuredModel model = null;
    IDocument newDocument = getDocumentProvider().getDocument(input);
    if (newDocument instanceof IExecutionDelegatable) {
        ((IExecutionDelegatable) newDocument).setExecutionDelegate(new EditorExecutionContext(this));
    }
    // if we have a Model provider, get the model from it
    if (getDocumentProvider() instanceof IModelProvider) {
        model = ((IModelProvider) getDocumentProvider()).getModel(getEditorInput());
        if (!model.isShared()) {
            EditorModelUtil.addFactoriesTo(model);
        }
    } else if (newDocument instanceof IStructuredDocument) {
        // corresponding releaseFromEdit occurs in dispose()
        model = StructuredModelManager.getModelManager().getModelForEdit((IStructuredDocument) newDocument);
        EditorModelUtil.addFactoriesTo(model);
    }
    return model;
}
Also used : IExecutionDelegatable(org.eclipse.wst.sse.core.internal.text.IExecutionDelegatable) IStructuredDocument(org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument) IStructuredModel(org.eclipse.wst.sse.core.internal.provisional.IStructuredModel) IModelProvider(org.eclipse.wst.sse.ui.internal.IModelProvider) IDocument(org.eclipse.jface.text.IDocument)

Example 3 with IExecutionDelegatable

use of org.eclipse.wst.sse.core.internal.text.IExecutionDelegatable in project webtools.sourceediting by eclipse.

the class StructuredTextEditor method doSetInput.

/*
	 * (non-Javadoc)
	 * 
	 * @see org.eclipse.ui.texteditor.AbstractTextEditor#doSetInput(org.eclipse.ui.IEditorInput)
	 */
protected void doSetInput(IEditorInput input) throws CoreException {
    IEditorInput oldInput = getEditorInput();
    if (oldInput != null) {
        IDocument olddoc = getDocumentProvider().getDocument(oldInput);
        if (olddoc != null && olddoc instanceof IExecutionDelegatable) {
            ((IExecutionDelegatable) olddoc).setExecutionDelegate(null);
        }
    }
    if (fStructuredModel != null && !(getDocumentProvider() instanceof IModelProvider)) {
        fStructuredModel.releaseFromEdit();
    }
    // attempt to get the model for the given input
    super.doSetInput(input);
    IStructuredModel model = tryToGetModel(input);
    /* if could not get the model prompt user to update content type
		 * if preferences allow, then try to get model again
		 */
    if (model == null && SSEUIPlugin.getDefault().getPreferenceStore().getBoolean(EditorPreferenceNames.SHOW_UNKNOWN_CONTENT_TYPE_MSG)) {
        if (fInitializationData != null && fInitializationData.containsKey(PREFERRED_CONTENT_TYPE_WHEN_UNSUPPORTED)) {
            IContentType contentType = Platform.getContentTypeManager().getContentType(fInitializationData.get(PREFERRED_CONTENT_TYPE_WHEN_UNSUPPORTED).toString());
            if (contentType != null && !StringUtils.contains(contentType.getFileSpecs(IContentTypeSettings.FILE_NAME_SPEC), input.getName(), false)) {
                /*
					 * Display a dialog informing user of unknown content type,
					 * offering to update preferences for them
					 */
                UnknownContentTypeDialog2 dialog = new UnknownContentTypeDialog2(getSite().getShell(), SSEUIPlugin.getDefault().getPreferenceStore(), input.getName(), contentType);
                dialog.open();
            }
        } else {
            /*
				 * Display a dialog informing user of unknown content type,
				 * giving them chance to update preferences
				 */
            UnknownContentTypeDialog dialog = new UnknownContentTypeDialog(getSite().getShell(), SSEUIPlugin.getDefault().getPreferenceStore(), EditorPreferenceNames.SHOW_UNKNOWN_CONTENT_TYPE_MSG);
            dialog.open();
        }
        // try to get model again in hopes user updated preferences
        super.doSetInput(input);
        model = tryToGetModel(input);
        // still could not get the model to open this editor, so log
        if (model == null) {
            logUnexpectedDocumentKind(input);
        }
    }
    if (fStructuredModel != null || model != null) {
        setModel(model);
    }
    if (getInternalModel() != null) {
        updateEditorControlsForContentType(getInternalModel().getContentTypeIdentifier());
    } else {
        updateEditorControlsForContentType(null);
    }
    // start editor with smart insert mode
    setInsertMode(SMART_INSERT);
}
Also used : IExecutionDelegatable(org.eclipse.wst.sse.core.internal.text.IExecutionDelegatable) IContentType(org.eclipse.core.runtime.content.IContentType) UnknownContentTypeDialog2(org.eclipse.wst.sse.ui.internal.UnknownContentTypeDialog2) IModelProvider(org.eclipse.wst.sse.ui.internal.IModelProvider) IStructuredModel(org.eclipse.wst.sse.core.internal.provisional.IStructuredModel) UnknownContentTypeDialog(org.eclipse.wst.sse.ui.internal.UnknownContentTypeDialog) IEditorInput(org.eclipse.ui.IEditorInput) IDocument(org.eclipse.jface.text.IDocument)

Aggregations

IDocument (org.eclipse.jface.text.IDocument)3 IExecutionDelegatable (org.eclipse.wst.sse.core.internal.text.IExecutionDelegatable)3 IStructuredModel (org.eclipse.wst.sse.core.internal.provisional.IStructuredModel)2 IModelProvider (org.eclipse.wst.sse.ui.internal.IModelProvider)2 IContentType (org.eclipse.core.runtime.content.IContentType)1 ITextViewerExtension (org.eclipse.jface.text.ITextViewerExtension)1 ISourceViewer (org.eclipse.jface.text.source.ISourceViewer)1 IEditorInput (org.eclipse.ui.IEditorInput)1 IStructuredDocument (org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument)1 UnknownContentTypeDialog (org.eclipse.wst.sse.ui.internal.UnknownContentTypeDialog)1 UnknownContentTypeDialog2 (org.eclipse.wst.sse.ui.internal.UnknownContentTypeDialog2)1 ConfigurableContentOutlinePage (org.eclipse.wst.sse.ui.internal.contentoutline.ConfigurableContentOutlinePage)1