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