Search in sources :

Example 26 with OutlineItem

use of org.eclipse.mylyn.wikitext.parser.outline.OutlineItem in project mylyn.docs by eclipse.

the class DefaultWikiTextSourceEditorOutline method createControl.

@Override
public void createControl(Composite parent) {
    super.createControl(parent);
    TreeViewer viewer = getTreeViewer();
    viewer.setUseHashlookup(true);
    viewer.setAutoExpandLevel(AbstractTreeViewer.ALL_LEVELS);
    viewer.setContentProvider(new BaseWorkbenchContentProvider());
    viewer.setLabelProvider(WorkbenchLabelProvider.getDecoratingWorkbenchLabelProvider());
    viewer.setInput(getEditor().getAdapter(OutlineItem.class));
    viewer.addOpenListener(new IOpenListener() {

        public void open(OpenEvent event) {
            revealInEditor(event.getSelection());
        }
    });
    viewer.addPostSelectionChangedListener(new ISelectionChangedListener() {

        public void selectionChanged(SelectionChangedEvent event) {
            revealInEditor(event.getSelection());
        }
    });
    viewer.expandAll();
    updateSelectionToMatchEditor();
    new ToolTip(viewer.getControl(), ToolTip.RECREATE, false) {

        @Override
        protected Composite createToolTipContentArea(Event event, Composite parent) {
            Composite comp = new Composite(parent, SWT.NONE);
            comp.setBackground(parent.getDisplay().getSystemColor(SWT.COLOR_INFO_BACKGROUND));
            GridLayout gl = new GridLayout(1, false);
            gl.marginBottom = 2;
            gl.marginTop = 2;
            gl.marginHeight = 0;
            gl.marginWidth = 0;
            gl.marginLeft = 2;
            gl.marginRight = 2;
            gl.verticalSpacing = 1;
            comp.setLayout(gl);
            Object tipItem = getToolTipItem(new Point(event.x, event.y));
            if (tipItem instanceof OutlineItem) {
                OutlineItem outlineItem = (OutlineItem) tipItem;
                Label label = new Label(comp, SWT.WRAP);
                label.setBackground(comp.getBackground());
                label.setText(outlineItem.getTooltip());
            }
            return comp;
        }

        @Override
        protected boolean shouldCreateToolTip(Event event) {
            final Object eventItem = getToolTipItem(new Point(event.x, event.y));
            boolean shouldCreate = eventItem != null && eventItem instanceof OutlineItem && super.shouldCreateToolTip(event);
            if (!shouldCreate) {
                hide();
            }
            return shouldCreate;
        }

        protected Object getToolTipItem(Point point) {
            TreeItem item = ((Tree) getTreeViewer().getControl()).getItem(point);
            if (item != null) {
                return item.getData();
            }
            return null;
        }
    };
    // $NON-NLS-1$
    MenuManager manager = new MenuManager("#PopUp");
    manager.setRemoveAllWhenShown(true);
    manager.addMenuListener(new IMenuListener() {

        public void menuAboutToShow(IMenuManager menuManager) {
            contextMenuAboutToShow(menuManager);
        }
    });
    viewer.getTree().setMenu(manager.createContextMenu(viewer.getTree()));
}
Also used : ToolTip(org.eclipse.jface.window.ToolTip) Composite(org.eclipse.swt.widgets.Composite) TreeItem(org.eclipse.swt.widgets.TreeItem) AbstractTreeViewer(org.eclipse.jface.viewers.AbstractTreeViewer) TreeViewer(org.eclipse.jface.viewers.TreeViewer) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) Label(org.eclipse.swt.widgets.Label) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) Point(org.eclipse.swt.graphics.Point) IMenuListener(org.eclipse.jface.action.IMenuListener) OutlineItem(org.eclipse.mylyn.wikitext.parser.outline.OutlineItem) IOpenListener(org.eclipse.jface.viewers.IOpenListener) GridLayout(org.eclipse.swt.layout.GridLayout) BaseWorkbenchContentProvider(org.eclipse.ui.model.BaseWorkbenchContentProvider) MenuManager(org.eclipse.jface.action.MenuManager) IMenuManager(org.eclipse.jface.action.IMenuManager) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) Event(org.eclipse.swt.widgets.Event) OpenEvent(org.eclipse.jface.viewers.OpenEvent) Tree(org.eclipse.swt.widgets.Tree) IMenuManager(org.eclipse.jface.action.IMenuManager) OpenEvent(org.eclipse.jface.viewers.OpenEvent)

Example 27 with OutlineItem

use of org.eclipse.mylyn.wikitext.parser.outline.OutlineItem in project mylyn.docs by eclipse.

the class MarkupToXslfoTask method processFile.

/**
 * process the file
 *
 * @param baseDir
 * @param source
 * @return
 * @return the lightweight markup, or null if the file was not written
 * @throws BuildException
 */
protected String processFile(MarkupLanguage markupLanguage, final File baseDir, final File source) throws BuildException {
    // $NON-NLS-1$
    log(MessageFormat.format(Messages.getString("MarkupToXslfoTask.7"), source), Project.MSG_VERBOSE);
    String markupContent = null;
    String name = source.getName();
    if (name.lastIndexOf('.') != -1) {
        name = name.substring(0, name.lastIndexOf('.'));
    }
    File outputFile = computeXslfoFile(source, name);
    if (targetdir != null) {
        outputFile = new File(targetdir, outputFile.getName());
    }
    if (!outputFile.exists() || overwrite || outputFile.lastModified() < source.lastModified()) {
        if (markupContent == null) {
            markupContent = readFully(source);
        }
        performValidation(source, markupContent);
        Writer out;
        try {
            // $NON-NLS-1$
            out = new OutputStreamWriter(new BufferedOutputStream(new FileOutputStream(outputFile)), "utf-8");
        } catch (Exception e) {
            throw new BuildException(MessageFormat.format(Messages.getString("MarkupToXslfoTask.8"), outputFile, e.getMessage()), // $NON-NLS-1$
            e);
        }
        try {
            XslfoDocumentBuilder builder = new XslfoDocumentBuilder(out);
            XslfoDocumentBuilder.Configuration configuration = this.configuration.clone();
            if (configuration.getTitle() == null) {
                configuration.setTitle(name);
            }
            builder.setConfiguration(configuration);
            builder.setBase(source.getParentFile().toURI());
            MarkupParser parser = new MarkupParser();
            parser.setMarkupLanguage(markupLanguage);
            parser.setBuilder(builder);
            if (generateBookmarks) {
                OutlineItem outline = new OutlineParser(markupLanguage).parse(markupContent);
                builder.setOutline(outline);
            }
            parser.parse(markupContent);
        } finally {
            try {
                out.close();
            } catch (Exception e) {
                throw new BuildException(MessageFormat.format(// $NON-NLS-1$
                Messages.getString("MarkupToXslfoTask.9"), // $NON-NLS-1$
                outputFile, e.getMessage()), e);
            }
        }
    }
    return markupContent;
}
Also used : BuildException(org.apache.tools.ant.BuildException) OutlineItem(org.eclipse.mylyn.wikitext.parser.outline.OutlineItem) OutlineParser(org.eclipse.mylyn.wikitext.parser.outline.OutlineParser) FileOutputStream(java.io.FileOutputStream) OutputStreamWriter(java.io.OutputStreamWriter) BuildException(org.apache.tools.ant.BuildException) File(java.io.File) BufferedOutputStream(java.io.BufferedOutputStream) Writer(java.io.Writer) OutputStreamWriter(java.io.OutputStreamWriter) XslfoDocumentBuilder(org.eclipse.mylyn.wikitext.parser.builder.XslfoDocumentBuilder) MarkupParser(org.eclipse.mylyn.wikitext.parser.MarkupParser)

Example 28 with OutlineItem

use of org.eclipse.mylyn.wikitext.parser.outline.OutlineItem in project mylyn.docs by eclipse.

the class AbstractTableOfContentsBlock method emitToc.

private void emitToc(OutlineItem item, int level, Attributes nullAttributes) {
    if (item.getChildren().isEmpty()) {
        return;
    }
    if ((item.getLevel() + 1) > maxLevel) {
        return;
    }
    Attributes listAttributes = new Attributes(null, level == 0 ? cssClass : null, "list-style: " + style + ";", // $NON-NLS-1$ //$NON-NLS-2$
    null);
    builder.beginBlock(BlockType.NUMERIC_LIST, listAttributes);
    for (OutlineItem child : item.getChildren()) {
        builder.beginBlock(BlockType.LIST_ITEM, nullAttributes);
        builder.link('#' + child.getId(), child.getLabel());
        emitToc(child, level + 1, nullAttributes);
        builder.endBlock();
    }
    builder.endBlock();
}
Also used : Attributes(org.eclipse.mylyn.wikitext.parser.Attributes) OutlineItem(org.eclipse.mylyn.wikitext.parser.outline.OutlineItem)

Example 29 with OutlineItem

use of org.eclipse.mylyn.wikitext.parser.outline.OutlineItem in project mylyn.docs by eclipse.

the class TableOfContentsBlock method emitToc.

private void emitToc(OutlineItem item) {
    if (item.getChildren().isEmpty()) {
        return;
    }
    Attributes nullAttributes = new Attributes();
    builder.beginBlock(BlockType.NUMERIC_LIST, new Attributes());
    for (OutlineItem child : item.getChildren()) {
        builder.beginBlock(BlockType.LIST_ITEM, nullAttributes);
        builder.link('#' + child.getId(), child.getLabel());
        emitToc(child);
        builder.endBlock();
    }
    builder.endBlock();
}
Also used : Attributes(org.eclipse.mylyn.wikitext.parser.Attributes) OutlineItem(org.eclipse.mylyn.wikitext.parser.outline.OutlineItem)

Example 30 with OutlineItem

use of org.eclipse.mylyn.wikitext.parser.outline.OutlineItem in project mylyn.docs by eclipse.

the class TableOfContentsBlock method processLineContent.

@Override
public int processLineContent(String line, int offset) {
    if (blockLineNumber++ > 0) {
        setClosed(true);
        return 0;
    }
    if (!getMarkupLanguage().isFilterGenerativeContents()) {
        OutlineParser outlineParser = new OutlineParser(new TWikiLanguage());
        OutlineItem rootItem = outlineParser.parse(state.getMarkupContent());
        emitToc(rootItem);
    }
    return -1;
}
Also used : OutlineParser(org.eclipse.mylyn.wikitext.parser.outline.OutlineParser) TWikiLanguage(org.eclipse.mylyn.wikitext.twiki.TWikiLanguage) OutlineItem(org.eclipse.mylyn.wikitext.parser.outline.OutlineItem)

Aggregations

OutlineItem (org.eclipse.mylyn.wikitext.parser.outline.OutlineItem)58 OutlineParser (org.eclipse.mylyn.wikitext.parser.outline.OutlineParser)18 MediaWikiLanguage (org.eclipse.mylyn.wikitext.mediawiki.MediaWikiLanguage)9 Point (org.eclipse.swt.graphics.Point)8 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)7 ITextSelection (org.eclipse.jface.text.ITextSelection)5 Attributes (org.eclipse.mylyn.wikitext.parser.Attributes)5 MarkupLanguage (org.eclipse.mylyn.wikitext.parser.markup.MarkupLanguage)5 BufferedOutputStream (java.io.BufferedOutputStream)4 FileOutputStream (java.io.FileOutputStream)4 OutputStreamWriter (java.io.OutputStreamWriter)4 Writer (java.io.Writer)4 BuildException (org.apache.tools.ant.BuildException)4 ISelection (org.eclipse.jface.viewers.ISelection)4 AbstractMarkupLanguage (org.eclipse.mylyn.wikitext.parser.markup.AbstractMarkupLanguage)4 File (java.io.File)3 IOException (java.io.IOException)3 ArrayList (java.util.ArrayList)3 IMenuManager (org.eclipse.jface.action.IMenuManager)3 MenuManager (org.eclipse.jface.action.MenuManager)3