public code v1
This commit is contained in:
@@ -0,0 +1,7 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<classpath>
|
||||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/>
|
||||
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
|
||||
<classpathentry kind="src" path="src"/>
|
||||
<classpathentry kind="output" path="bin"/>
|
||||
</classpath>
|
||||
@@ -0,0 +1,14 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>flintstones.group</groupId>
|
||||
<artifactId>flintstones.bundles</artifactId>
|
||||
<version>1.0.0-SNAPSHOT</version>
|
||||
</parent>
|
||||
<artifactId>flintstones.application.perspective.documentation.ui</artifactId>
|
||||
<version>1.0.0-SNAPSHOT</version>
|
||||
<packaging>eclipse-plugin</packaging>
|
||||
<name>[bundle] Ui</name>
|
||||
</project>
|
||||
@@ -0,0 +1,45 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<projectDescription>
|
||||
<name>flintstones.application.perspective.documentation.ui</name>
|
||||
<comment></comment>
|
||||
<projects>
|
||||
</projects>
|
||||
<buildSpec>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.jdt.core.javabuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.pde.ManifestBuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.pde.SchemaBuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.m2e.core.maven2Builder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
</buildSpec>
|
||||
<natures>
|
||||
<nature>org.eclipse.m2e.core.maven2Nature</nature>
|
||||
<nature>org.eclipse.pde.PluginNature</nature>
|
||||
<nature>org.eclipse.jdt.core.javanature</nature>
|
||||
</natures>
|
||||
<filteredResources>
|
||||
<filter>
|
||||
<id>1779484362526</id>
|
||||
<name></name>
|
||||
<type>30</type>
|
||||
<matcher>
|
||||
<id>org.eclipse.core.resources.regexFilterMatcher</id>
|
||||
<arguments>node_modules|\.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__</arguments>
|
||||
</matcher>
|
||||
</filter>
|
||||
</filteredResources>
|
||||
</projectDescription>
|
||||
+2
@@ -0,0 +1,2 @@
|
||||
eclipse.preferences.version=1
|
||||
encoding/<project>=UTF-8
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
eclipse.preferences.version=1
|
||||
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
|
||||
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
|
||||
org.eclipse.jdt.core.compiler.compliance=1.8
|
||||
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
|
||||
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
|
||||
org.eclipse.jdt.core.compiler.source=1.8
|
||||
+4
@@ -0,0 +1,4 @@
|
||||
activeProfiles=
|
||||
eclipse.preferences.version=1
|
||||
resolveWorkspaceProjects=true
|
||||
version=1
|
||||
@@ -0,0 +1,20 @@
|
||||
Manifest-Version: 1.0
|
||||
Bundle-ManifestVersion: 2
|
||||
Bundle-Name: Ui
|
||||
Bundle-SymbolicName: flintstones.application.perspective.documentation.ui;singleton:=true
|
||||
Bundle-Version: 1.0.0.qualifier
|
||||
Require-Bundle: org.eclipse.e4.ui.model.workbench,
|
||||
org.eclipse.e4.core.di,
|
||||
org.eclipse.e4.core.contexts,
|
||||
flintstones.application,
|
||||
org.eclipse.e4.core.services,
|
||||
flintstones.model.ui.service,
|
||||
org.eclipse.jface,
|
||||
flintstones.application.constants,
|
||||
org.eclipse.e4.ui.di,
|
||||
flintstones.helper.html,
|
||||
flintstones.helper.data,
|
||||
javax.annotation
|
||||
Automatic-Module-Name: flintstones.application.perspective.documentation.ui
|
||||
Bundle-RequiredExecutionEnvironment: JavaSE-11
|
||||
Import-Package: javax.inject;version="1.0.0"
|
||||
@@ -0,0 +1,6 @@
|
||||
output.. = bin/
|
||||
bin.includes = META-INF/,\
|
||||
.,\
|
||||
fragment.e4xmi,\
|
||||
plugin.xml
|
||||
source.. = src/
|
||||
@@ -0,0 +1,20 @@
|
||||
<?xml version="1.0" encoding="ASCII"?>
|
||||
<fragment:ModelFragments xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:advanced="http://www.eclipse.org/ui/2010/UIModel/application/ui/advanced" xmlns:basic="http://www.eclipse.org/ui/2010/UIModel/application/ui/basic" xmlns:commands="http://www.eclipse.org/ui/2010/UIModel/application/commands" xmlns:fragment="http://www.eclipse.org/ui/2010/UIModel/fragment" xmlns:menu="http://www.eclipse.org/ui/2010/UIModel/application/ui/menu" xmi:id="_p4uAAB78Eemjkpq3ZNFQaA">
|
||||
<fragments xsi:type="fragment:StringModelFragment" xmi:id="_p4uAAh78Eemjkpq3ZNFQaA" featurename="handlers" parentElementId="flintstones.application.application">
|
||||
<elements xsi:type="commands:Handler" xmi:id="_p4uAAx78Eemjkpq3ZNFQaA" elementId="flintstones.application.handler.documentation" contributionURI="bundleclass://flintstones.application.perspective.documentation.ui/flintstones.application.perspective.documentation.ui.handler.DocumentationHandler" command="_rsQaMR78Eemjkpq3ZNFQaA"/>
|
||||
</fragments>
|
||||
<fragments xsi:type="fragment:StringModelFragment" xmi:id="_rsQaMB78Eemjkpq3ZNFQaA" featurename="commands" parentElementId="flintstones.application.application">
|
||||
<elements xsi:type="commands:Command" xmi:id="_rsQaMR78Eemjkpq3ZNFQaA" elementId="flintstones.application.command.documentation" commandName="Documentación"/>
|
||||
</fragments>
|
||||
<fragments xsi:type="fragment:StringModelFragment" xmi:id="_ue79MB78Eemjkpq3ZNFQaA" featurename="children" parentElementId="flintstones.application.menu.main">
|
||||
<elements xsi:type="menu:HandledMenuItem" xmi:id="_ue79MR78Eemjkpq3ZNFQaA" elementId="flintstones.application.handledmenuitem.documentation" visible="false" label="Documentación" command="_rsQaMR78Eemjkpq3ZNFQaA"/>
|
||||
</fragments>
|
||||
<fragments xsi:type="fragment:StringModelFragment" xmi:id="_-EYoEB78Eemjkpq3ZNFQaA" featurename="children" parentElementId="flintstones.application.perspectivestack.modes">
|
||||
<elements xsi:type="advanced:Perspective" xmi:id="_-EYoER78Eemjkpq3ZNFQaA" elementId="flintstones.application.perspective.documentation" label="Documentación">
|
||||
<children xsi:type="basic:PartSashContainer" xmi:id="_reIpMB79Eemjkpq3ZNFQaA" elementId="flintstones.application.perspective.documentation.ui.partsashcontainer.0" horizontal="true">
|
||||
<children xsi:type="basic:Part" xmi:id="_te_GoB79Eemjkpq3ZNFQaA" elementId="flintstones.application.perspective.documentation.ui.part.0" contributionURI="bundleclass://flintstones.application.perspective.documentation.ui/flintstones.application.perspective.documentation.ui.DocumentationSelectorPart"/>
|
||||
<children xsi:type="basic:Part" xmi:id="_t0k8IB79Eemjkpq3ZNFQaA" elementId="flintstones.application.perspective.documentation.ui.part.1" visible="false" contributionURI="bundleclass://flintstones.application.perspective.documentation.ui/flintstones.application.perspective.documentation.ui.DocumentationInformation"/>
|
||||
</children>
|
||||
</elements>
|
||||
</fragments>
|
||||
</fragment:ModelFragments>
|
||||
@@ -0,0 +1,12 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<plugin>
|
||||
|
||||
<extension
|
||||
id="flintstones.application.perspective.documentation.ui.fragment"
|
||||
point="org.eclipse.e4.workbench.model">
|
||||
<fragment
|
||||
uri="fragment.e4xmi">
|
||||
</fragment>
|
||||
</extension>
|
||||
|
||||
</plugin>
|
||||
+87
@@ -0,0 +1,87 @@
|
||||
package flintstones.application.perspective.documentation.ui;
|
||||
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
import javax.inject.Inject;
|
||||
|
||||
import org.eclipse.e4.core.contexts.IEclipseContext;
|
||||
import org.eclipse.e4.core.di.annotations.Optional;
|
||||
import org.eclipse.e4.core.services.events.IEventBroker;
|
||||
import org.eclipse.e4.ui.di.UIEventTopic;
|
||||
import org.eclipse.e4.ui.model.application.ui.basic.MPart;
|
||||
import org.eclipse.swt.SWT;
|
||||
import org.eclipse.swt.widgets.Composite;
|
||||
|
||||
import flintstones.application.constants.FrameworkConstants;
|
||||
import flintstones.helper.FileHelper;
|
||||
import flintstones.helper.html.HtmlMarkdown;
|
||||
import flintstones.model.ui.service.UiService;
|
||||
|
||||
public class DocumentationInformation {
|
||||
|
||||
|
||||
@Inject
|
||||
IEclipseContext context;
|
||||
|
||||
@Inject
|
||||
IEventBroker broker;
|
||||
|
||||
@Inject
|
||||
MPart part;
|
||||
|
||||
Composite markdownBase;
|
||||
|
||||
@PostConstruct
|
||||
public void init(Composite parent) {
|
||||
|
||||
UiService.setGridLayout(parent, 1);
|
||||
UiService.setGridData(parent, 9, 9, true, true);
|
||||
|
||||
markdownBase = new Composite(parent,SWT.BORDER);
|
||||
UiService.setGridLayout(markdownBase, 1);
|
||||
UiService.setGridData(markdownBase, 9, 9, true, true);
|
||||
|
||||
}
|
||||
|
||||
private void draw(String path) {
|
||||
|
||||
|
||||
// FaqHelper faq = ContextInjectionFactory.make(FaqHelper.class, context);
|
||||
String content = null;
|
||||
try {
|
||||
content = FileHelper.readFile(path);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
HtmlMarkdown markdownViewer = new HtmlMarkdown(markdownBase);
|
||||
markdownViewer.setFile(content);
|
||||
markdownViewer.render();
|
||||
|
||||
|
||||
part.setVisible(true);
|
||||
|
||||
}
|
||||
|
||||
private void hide() {
|
||||
part.setVisible(false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Subscribe.
|
||||
*
|
||||
* @param event the event
|
||||
*/
|
||||
@Inject
|
||||
@Optional
|
||||
private void subscribe(@UIEventTopic(FrameworkConstants.TOPIC_SELECTION_DOCUMENTATION) String path) {
|
||||
if( path != null )
|
||||
draw(path);
|
||||
else
|
||||
hide();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
+90
@@ -0,0 +1,90 @@
|
||||
package flintstones.application.perspective.documentation.ui;
|
||||
|
||||
import java.io.File;
|
||||
import java.text.DateFormat;
|
||||
import java.util.Arrays;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
import javax.inject.Inject;
|
||||
|
||||
import org.eclipse.e4.core.contexts.IEclipseContext;
|
||||
import org.eclipse.e4.core.services.events.IEventBroker;
|
||||
import org.eclipse.jface.viewers.DelegatingStyledCellLabelProvider;
|
||||
import org.eclipse.jface.viewers.TreeViewer;
|
||||
import org.eclipse.jface.viewers.TreeViewerColumn;
|
||||
import org.eclipse.swt.SWT;
|
||||
import org.eclipse.swt.events.SelectionAdapter;
|
||||
import org.eclipse.swt.events.SelectionEvent;
|
||||
import org.eclipse.swt.widgets.Composite;
|
||||
import org.eclipse.swt.widgets.Tree;
|
||||
import org.eclipse.swt.widgets.TreeItem;
|
||||
|
||||
import flintstones.application.constants.FrameworkConstants;
|
||||
import flintstones.application.perspective.documentation.ui.provider.FileModifiedLabelProvider;
|
||||
import flintstones.application.perspective.documentation.ui.provider.ViewContentProvider;
|
||||
import flintstones.application.perspective.documentation.ui.provider.ViewLabelProvider;
|
||||
import flintstones.model.ui.service.UiService;
|
||||
|
||||
public class DocumentationSelectorPart {
|
||||
|
||||
|
||||
@Inject
|
||||
IEclipseContext context;
|
||||
|
||||
@Inject
|
||||
IEventBroker broker;
|
||||
|
||||
TreeViewer viewer;
|
||||
|
||||
private static final DateFormat dateFormat = DateFormat.getDateInstance();
|
||||
|
||||
@PostConstruct
|
||||
public void init(Composite parent) {
|
||||
|
||||
viewer = new TreeViewer(parent, SWT.H_SCROLL | SWT.V_SCROLL);
|
||||
viewer.setContentProvider(new ViewContentProvider());
|
||||
viewer.getTree().setHeaderVisible(true);
|
||||
|
||||
TreeViewerColumn mainColumn = new TreeViewerColumn(viewer, SWT.NONE);
|
||||
mainColumn.getColumn().setText("Name");
|
||||
mainColumn.getColumn().setWidth(300);
|
||||
mainColumn.setLabelProvider(new DelegatingStyledCellLabelProvider(new ViewLabelProvider(UiService.getImage("new.png"))));
|
||||
|
||||
TreeViewerColumn modifiedColumn = new TreeViewerColumn(viewer, SWT.NONE);
|
||||
modifiedColumn.getColumn().setText("Last Modified");
|
||||
modifiedColumn.getColumn().setWidth(100);
|
||||
modifiedColumn.getColumn().setAlignment(SWT.RIGHT);
|
||||
modifiedColumn.setLabelProvider(new DelegatingStyledCellLabelProvider(new FileModifiedLabelProvider(dateFormat)));
|
||||
|
||||
File folder = new File("C:\\Users\\igmunoz\\Desktop\\wiki");
|
||||
File[] files = Arrays.stream(folder.listFiles()).filter(k -> k.getName().contains(".md")).toArray(File[]::new);
|
||||
|
||||
viewer.setInput(files);
|
||||
|
||||
|
||||
|
||||
// parent.addControlListener(new ControlAdapter() {
|
||||
// @Override
|
||||
// public void controlResized(ControlEvent e) {
|
||||
// Composite composite = (Composite) e.widget;
|
||||
// int width = composite.getBounds().width;
|
||||
// mainColumn.getColumn().setWidth(width);
|
||||
// }
|
||||
// });
|
||||
|
||||
Tree tree = (Tree) viewer.getControl();
|
||||
tree.addSelectionListener(new SelectionAdapter() {
|
||||
@Override
|
||||
public void widgetSelected(SelectionEvent e) {
|
||||
TreeItem item = (TreeItem) e.item;
|
||||
|
||||
File file = (File) item.getData();
|
||||
String path = file.getAbsolutePath();
|
||||
broker.send(FrameworkConstants.TOPIC_SELECTION_DOCUMENTATION, path);
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
+22
@@ -0,0 +1,22 @@
|
||||
|
||||
package flintstones.application.perspective.documentation.ui.handler;
|
||||
|
||||
import flintstones.application.handlers.PerspectiveSwitcher;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
import org.eclipse.e4.core.contexts.ContextInjectionFactory;
|
||||
import org.eclipse.e4.core.contexts.IEclipseContext;
|
||||
import org.eclipse.e4.core.di.annotations.Execute;
|
||||
|
||||
public class DocumentationHandler {
|
||||
|
||||
@Inject
|
||||
IEclipseContext context;
|
||||
|
||||
@Execute
|
||||
public void execute() {
|
||||
ContextInjectionFactory.make(PerspectiveSwitcher.class, context).changePerspective("flintstones.application.perspective.documentation");
|
||||
}
|
||||
|
||||
}
|
||||
+28
@@ -0,0 +1,28 @@
|
||||
package flintstones.application.perspective.documentation.ui.provider;
|
||||
|
||||
import java.io.File;
|
||||
import java.text.DateFormat;
|
||||
import java.util.Date;
|
||||
|
||||
import org.eclipse.jface.viewers.DelegatingStyledCellLabelProvider.IStyledLabelProvider;
|
||||
import org.eclipse.jface.viewers.LabelProvider;
|
||||
import org.eclipse.jface.viewers.StyledString;
|
||||
|
||||
public class FileModifiedLabelProvider extends LabelProvider implements IStyledLabelProvider {
|
||||
|
||||
private DateFormat dateLabelFormat;
|
||||
|
||||
public FileModifiedLabelProvider(DateFormat dateFormat) {
|
||||
dateLabelFormat = dateFormat;
|
||||
}
|
||||
|
||||
@Override
|
||||
public StyledString getStyledText(Object element) {
|
||||
if (element instanceof File) {
|
||||
File file = (File) element;
|
||||
long lastModified = file.lastModified();
|
||||
return new StyledString(dateLabelFormat.format(new Date(lastModified)));
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
+42
@@ -0,0 +1,42 @@
|
||||
package flintstones.application.perspective.documentation.ui.provider;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
import org.eclipse.jface.viewers.ITreeContentProvider;
|
||||
import org.eclipse.jface.viewers.Viewer;
|
||||
|
||||
public class ViewContentProvider implements ITreeContentProvider {
|
||||
public void inputChanged(Viewer v, Object oldInput, Object newInput) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void dispose() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object[] getElements(Object inputElement) {
|
||||
return (File[]) inputElement;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object[] getChildren(Object parentElement) {
|
||||
File file = (File) parentElement;
|
||||
return file.listFiles();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getParent(Object element) {
|
||||
File file = (File) element;
|
||||
return file.getParentFile();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasChildren(Object element) {
|
||||
File file = (File) element;
|
||||
if (file.isDirectory()) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
+70
@@ -0,0 +1,70 @@
|
||||
package flintstones.application.perspective.documentation.ui.provider;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
import org.eclipse.jface.resource.ImageDescriptor;
|
||||
import org.eclipse.jface.resource.JFaceResources;
|
||||
import org.eclipse.jface.resource.LocalResourceManager;
|
||||
import org.eclipse.jface.resource.ResourceManager;
|
||||
import org.eclipse.jface.viewers.DelegatingStyledCellLabelProvider.IStyledLabelProvider;
|
||||
import org.eclipse.jface.viewers.LabelProvider;
|
||||
import org.eclipse.jface.viewers.StyledString;
|
||||
import org.eclipse.swt.graphics.Image;
|
||||
|
||||
public class ViewLabelProvider extends LabelProvider implements IStyledLabelProvider {
|
||||
|
||||
private ImageDescriptor directoryImage;
|
||||
private ResourceManager resourceManager;
|
||||
|
||||
public ViewLabelProvider(ImageDescriptor directoryImage) {
|
||||
this.directoryImage = directoryImage;
|
||||
}
|
||||
|
||||
@Override
|
||||
public StyledString getStyledText(Object element) {
|
||||
if (element instanceof File) {
|
||||
File file = (File) element;
|
||||
StyledString styledString = new StyledString(getFileName(file));
|
||||
String[] files = file.list();
|
||||
if (files != null) {
|
||||
styledString.append(" ( " + files.length + " ) ", StyledString.COUNTER_STYLER);
|
||||
}
|
||||
return styledString;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Image getImage(Object element) {
|
||||
if (element instanceof File) {
|
||||
if (((File) element).isDirectory()) {
|
||||
return getResourceManager().createImage(directoryImage);
|
||||
}
|
||||
}
|
||||
|
||||
return super.getImage(element);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void dispose() {
|
||||
// garbage collection system resources
|
||||
if (resourceManager != null) {
|
||||
resourceManager.dispose();
|
||||
resourceManager = null;
|
||||
}
|
||||
}
|
||||
|
||||
protected ResourceManager getResourceManager() {
|
||||
if (resourceManager == null) {
|
||||
resourceManager = new LocalResourceManager(JFaceResources.getResources());
|
||||
}
|
||||
return resourceManager;
|
||||
}
|
||||
|
||||
private String getFileName(File file) {
|
||||
|
||||
String name = file.getName();
|
||||
name = name.replace("_",".").replace("-"," ").replace(".md","");
|
||||
return name.isEmpty() ? file.getPath() : name;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user