Search in sources :

Example 41 with OutlineItem

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

the class MarkupEditorOutline 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(editor.getOutlineModel());
    viewer.addOpenListener(new IOpenListener() {

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

        public void selectionChanged(SelectionChangedEvent event) {
            revealInEditor(event.getSelection(), false);
        }
    });
    viewer.expandAll();
    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;
        }
    };
    IPageSite site = getSite();
    site.setSelectionProvider(viewer);
    configureActionBars(site);
    // $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()));
    // $NON-NLS-1$
    site.registerContextMenu(MarkupEditor.ID + ".outlineContextMenu", manager, viewer);
    configureDnd();
    configureActions();
}
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) IPageSite(org.eclipse.ui.part.IPageSite) 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 42 with OutlineItem

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

the class OutlineParserTest method testPrevious.

public void testPrevious() {
    String textile = "h1. First Header\n\nh2. Second Header\n\nh1. Third Header\n";
    OutlineItem outline = outlineParser.parse(textile);
    assertNull(outline.getPrevious());
    assertSame(outline, outline.getChildren().get(0).getPrevious());
    assertSame(outline.getChildren().get(0), outline.getChildren().get(1).getPrevious());
    assertSame(outline.getChildren().get(0), outline.getChildren().get(0).getChildren().get(0).getPrevious());
}
Also used : OutlineItem(org.eclipse.mylyn.wikitext.parser.outline.OutlineItem)

Example 43 with OutlineItem

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

the class OutlineParserTest method testNearestItem.

public void testNearestItem() {
    String textile = "h1. First Header\n\nh2. Second Header\n\nh1. Third Header\n";
    OutlineItem outline = outlineParser.parse(textile);
    int idxOfH2 = textile.indexOf("h2. Second");
    assertTrue(idxOfH2 != -1);
    OutlineItem h2Item = outline.findNearestMatchingOffset(idxOfH2);
    assertNotNull(h2Item);
    assertSame(outline.getChildren().get(0), h2Item.getParent());
    assertEquals(2, h2Item.getLevel());
    OutlineItem h1Item = outline.findNearestMatchingOffset(idxOfH2 - 1);
    assertNotNull(h1Item);
    assertSame(outline.getChildren().get(0), h1Item);
    assertEquals(1, h1Item.getLevel());
    int secondIdxOfH1 = textile.indexOf("h1. Third");
    OutlineItem secondH1Item = outline.findNearestMatchingOffset(secondIdxOfH1);
    assertNotNull(secondH1Item);
    assertSame(outline.getChildren().get(1), secondH1Item);
    assertEquals(1, secondH1Item.getLevel());
    OutlineItem h2Item2 = outline.findNearestMatchingOffset(secondIdxOfH1 - 1);
    assertSame(h2Item, h2Item2);
}
Also used : OutlineItem(org.eclipse.mylyn.wikitext.parser.outline.OutlineItem)

Example 44 with OutlineItem

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

the class OutlineParserTest method testHeadersWithHtmlTags.

public void testHeadersWithHtmlTags() {
    // bug 374019
    outlineParser = new OutlineParser(new MediaWikiLanguage());
    OutlineItem outline = outlineParser.parse("= <span style=\"font-family:monospace\">Heading Text</span> =\n\n text");
    assertEquals(1, outline.getChildren().size());
    OutlineItem headingItem = outline.getChildren().get(0);
    assertEquals("Heading_Text", headingItem.getId());
    assertEquals("Heading Text", headingItem.getLabel());
}
Also used : OutlineParser(org.eclipse.mylyn.wikitext.parser.outline.OutlineParser) MediaWikiLanguage(org.eclipse.mylyn.wikitext.mediawiki.MediaWikiLanguage) OutlineItem(org.eclipse.mylyn.wikitext.parser.outline.OutlineItem)

Example 45 with OutlineItem

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

the class WikiTextContextUiBridge method open.

@Override
public void open(IInteractionElement element) {
    AbstractContextStructureBridge structureBridge = ContextCore.getStructureBridge(WikiTextContextStructureBridge.CONTENT_TYPE);
    if (structureBridge instanceof WikiTextContextStructureBridge) {
        Object object = structureBridge.getObjectForHandle(element.getHandleIdentifier());
        OutlineItem item = null;
        if (object instanceof OutlineItem) {
            item = (OutlineItem) object;
            object = ((WikiTextContextStructureBridge) structureBridge).getFile(item);
        }
        if (object instanceof IFile) {
            FileEditorInput editorInput = new FileEditorInput((IFile) object);
            try {
                IEditorPart editor = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().openEditor(editorInput, // $NON-NLS-1$
                "org.eclipse.mylyn.wikitext.ui.editor.markupEditor");
                if (item != null && editor instanceof IShowInTarget) {
                    ((IShowInTarget) editor).show(new ShowInContext(editorInput, new StructuredSelection(item)));
                }
            } catch (PartInitException e) {
                WikiTextContextUiPlugin.getDefault().log(e);
            }
        }
    }
}
Also used : IShowInTarget(org.eclipse.ui.part.IShowInTarget) AbstractContextStructureBridge(org.eclipse.mylyn.context.core.AbstractContextStructureBridge) IFile(org.eclipse.core.resources.IFile) ShowInContext(org.eclipse.ui.part.ShowInContext) FileEditorInput(org.eclipse.ui.part.FileEditorInput) IFileEditorInput(org.eclipse.ui.IFileEditorInput) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) IEditorPart(org.eclipse.ui.IEditorPart) PartInitException(org.eclipse.ui.PartInitException) 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