001: /*******************************************************************************
002: * Copyright (c) 2007 IBM Corporation and others.
003: * All rights reserved. This program and the accompanying materials
004: * are made available under the terms of the Eclipse Public License v1.0
005: * which accompanies this distribution, and is available at
006: * http://www.eclipse.org/legal/epl-v10.html
007: *
008: * Contributors:
009: * IBM Corporation - initial API and implementation
010: *******************************************************************************/package org.eclipse.pde.internal.ui.editor.toc;
011:
012: import org.eclipse.jface.text.hyperlink.IHyperlinkDetector;
013: import org.eclipse.jface.viewers.ILabelProvider;
014: import org.eclipse.jface.viewers.ITreeContentProvider;
015: import org.eclipse.jface.viewers.ViewerComparator;
016: import org.eclipse.pde.internal.core.text.IDocumentAttributeNode;
017: import org.eclipse.pde.internal.core.text.IDocumentElementNode;
018: import org.eclipse.pde.internal.core.text.IDocumentRange;
019: import org.eclipse.pde.internal.core.text.toc.TocModel;
020: import org.eclipse.pde.internal.core.text.toc.TocObject;
021: import org.eclipse.pde.internal.ui.IHelpContextIds;
022: import org.eclipse.pde.internal.ui.PDEPlugin;
023: import org.eclipse.pde.internal.ui.PDEUIMessages;
024: import org.eclipse.pde.internal.ui.editor.PDEFormEditor;
025: import org.eclipse.pde.internal.ui.editor.XMLSourcePage;
026:
027: /**
028: * TocSourcePage
029: */
030: public class TocSourcePage extends XMLSourcePage {
031:
032: /**
033: * @param editor
034: * @param id
035: * @param title
036: */
037: public TocSourcePage(PDEFormEditor editor, String id, String title) {
038: super (editor, id, title);
039: }
040:
041: /* (non-Javadoc)
042: * @see org.eclipse.pde.internal.ui.editor.PDEProjectionSourcePage#isQuickOutlineEnabled()
043: */
044: public boolean isQuickOutlineEnabled() {
045: return true;
046: }
047:
048: /* (non-Javadoc)
049: * @see org.eclipse.pde.internal.ui.editor.PDESourcePage#createOutlineComparator()
050: */
051: public ViewerComparator createOutlineComparator() {
052: return null;
053: }
054:
055: /* (non-Javadoc)
056: * @see org.eclipse.pde.internal.ui.editor.PDESourcePage#createOutlineContentProvider()
057: */
058: public ITreeContentProvider createOutlineContentProvider() {
059: return new TocContentProvider();
060: }
061:
062: /* (non-Javadoc)
063: * @see org.eclipse.pde.internal.ui.editor.PDESourcePage#createOutlineLabelProvider()
064: */
065: public ILabelProvider createOutlineLabelProvider() {
066: return PDEPlugin.getDefault().getLabelProvider();
067: }
068:
069: /* (non-Javadoc)
070: * @see org.eclipse.ui.part.EditorPart#setPartName(java.lang.String)
071: */
072: protected void setPartName(String partName) {
073: super .setPartName(PDEUIMessages.EditorSourcePage_name);
074: }
075:
076: protected boolean isSelectionListener() {
077: return true;
078: }
079:
080: public Object getAdapter(Class adapter) {
081: if (IHyperlinkDetector.class.equals(adapter))
082: return new TocHyperlinkDetector(this );
083: return super .getAdapter(adapter);
084: }
085:
086: /* (non-Javadoc)
087: * @see org.eclipse.pde.internal.ui.editor.PDESourcePage#updateSelection(java.lang.Object)
088: */
089: public void updateSelection(Object object) {
090: if ((object instanceof IDocumentElementNode)
091: && !((IDocumentElementNode) object).isErrorNode()) {
092: fSelection = object;
093: setHighlightRange((IDocumentElementNode) object, true);
094: setSelectedRange((IDocumentElementNode) object, false);
095: }
096: }
097:
098: protected IDocumentRange findRange() {
099: if (fSelection instanceof IDocumentElementNode) {
100: return (IDocumentElementNode) fSelection;
101: }
102:
103: return null;
104: }
105:
106: public IDocumentRange getRangeElement(int offset,
107: boolean searchChildren) {
108: TocObject toc = ((TocModel) getInputContext().getModel())
109: .getToc();
110: return findNode(toc, offset, searchChildren);
111: }
112:
113: protected void synchronizeOutlinePage(int offset) {
114: IDocumentRange rangeElement = getRangeElement(offset, true);
115: updateHighlightRange(rangeElement);
116: // TODO: MP: TEO: LOW: Generalize for parent - search children = true and handle attributes
117: if (rangeElement instanceof IDocumentAttributeNode) {
118: rangeElement = ((IDocumentAttributeNode) rangeElement)
119: .getEnclosingElement();
120: }
121: updateOutlinePageSelection(rangeElement);
122: }
123:
124: protected void initializeEditor() {
125: super.initializeEditor();
126: setHelpContextId(IHelpContextIds.TOC_EDITOR);
127: }
128: }
|