Skip to content

Commit

Permalink
Some more refactoring and updated the readme
Browse files Browse the repository at this point in the history
  • Loading branch information
hallvard committed Apr 13, 2021
1 parent f9fe62a commit a0320c7
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 27 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ Note that the version numbers of the plantuml.lib plugin are a bit special, sinc
## [1.1.25](https://github.com/hallvard/plantuml/releases/tag/1.1.25)
- Updated to use PlantUML library version 1.2021.3 (see [changes](https://plantuml.com/changes)).
- Added new extension point that supports generating several alternative diagrams for the same content ([issue #109](https://github.com/hallvard/plantuml/issues/109)) and delays the computation of the diagram so it can run on a non-UI thread ([issue #82](https://github.com/hallvard/plantuml/issues/82)). Uses of old extension point should still work, but should be updated to use new one.
- I needed to remove (for now) the feature that recomputes saved diagram images during builds, when their source have changed.
- Experimental PlantUML SVG view that handles zooming better ([issue #116](https://github.com/hallvard/plantuml/issues/116))
- Association is generated when type is Optional and for methods with a specific signature. (thanks to [dpolivaev](https://github.com/dpolivaev))
- Changes generated diagrams to use `name : type` UML format for attributes instead of java style `type name` ([issue #115](https://github.com/hallvard/plantuml/issues/115))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@

import net.sourceforge.plantuml.eclipse.utils.DiagramTextProvider;
import net.sourceforge.plantuml.eclipse.utils.ILinkOpener;
import net.sourceforge.plantuml.eclipse.utils.PlantumlUtil;
import net.sourceforge.plantuml.preferences.DiagramIntentProvidersPreferencePage;
import net.sourceforge.plantuml.util.DiagramIntentProvider;
import net.sourceforge.plantuml.util.DiagramTextIntentProvider;
Expand Down Expand Up @@ -60,7 +59,7 @@ public Activator() {
public void start(final BundleContext context) throws Exception {
super.start(context);
plugin = this;
resourceListener = PlantumlUtil.createResourceListener();
resourceListener = null; // TODO: re-enable PlantumlUtil.createResourceListener();
if (resourceListener != null) {
ResourcesPlugin.getWorkspace().addResourceChangeListener(resourceListener, IResourceChangeEvent.POST_BUILD);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ public class PlantumlUtil {

public static final String PLANTUML_MARKER = "plantumlmarker";
public static final String ORIGINAL_PATH_ATTRIBUTE = "original";
public static final String DIAGRAM_INTENT_PROVIDER_ID_ATTRIBUTE = "diagramIntentProviderId";
public static final String DIAGRAM_SOURCE_ATTRIBUTE = "diagramSource";
public static final String TARGET_PATH_ATTRIBUTE = "target";

Expand Down Expand Up @@ -103,22 +104,27 @@ public boolean visit(final IResourceDelta delta) throws CoreException {
final IMarker marker = getPlantUmlMarker((IFile) resource, false);
if (marker != null) {
final Object target = marker.getAttribute(TARGET_PATH_ATTRIBUTE);
final Object diagramIntentProviderId = marker.getAttribute(DIAGRAM_INTENT_PROVIDER_ID_ATTRIBUTE);
if (target != null) {
final IPath path = resource.getFullPath();
final WorkspaceDiagramIntentProviderContext intentProviderContext = new WorkspaceDiagramIntentProviderContext(path);
for (final DiagramIntentProvider diagramIntentProvider : Activator.getDefault().getDiagramIntentProviders(null)) {
final Collection<? extends DiagramIntent> diagramInfos = diagramIntentProvider.getDiagramInfos(intentProviderContext);
for (final DiagramIntent diagramIntent : diagramInfos) {
final String textDiagram = diagramIntent.getDiagramText();
if (textDiagram != null) {
final DiagramData diagram = new DiagramData(textDiagram);
diagram.setOriginal(path);
try {
saveDiagramImage(path, textDiagram, diagram.getImage(), new Path(target.toString()), false);
} catch (final Exception e) {
System.err.println(e);
if (diagramIntentProviderId == null || diagramIntentProviderId.toString().equals(Activator.getDefault().getDiagramIntentProviderId(diagramIntentProvider))) {
final Collection<? extends DiagramIntent> diagramInfos = diagramIntentProvider.getDiagramInfos(intentProviderContext);
if (diagramInfos != null) {
for (final DiagramIntent diagramIntent : diagramInfos) {
final String textDiagram = diagramIntent.getDiagramText();
if (textDiagram != null) {
final DiagramData diagram = new DiagramData(textDiagram);
diagram.setOriginal(path);
try {
saveDiagramImage(path, textDiagram, diagram.getImage(), new Path(target.toString()), false);
} catch (final Exception e) {
System.err.println(e);
}
return false;
}
}
break;
}
}
}
Expand All @@ -131,7 +137,7 @@ public boolean visit(final IResourceDelta delta) throws CoreException {

public static void saveDiagramImage(final DiagramImageData diagramImageData, final IPath path, final boolean b) throws Exception {
final Function<Integer, String> fileNameProvider = PlantumlUtil.getImageFileNameProvider(path.lastSegment());
final DiagramData diagram = diagramImageData.getDiagram();
final DiagramData diagram = diagramImageData.getDiagramData();
if (fileNameProvider != null) {
final IPath folderPath = path.removeLastSegments(1);
final int imageCount = diagram.getImageCount();
Expand All @@ -148,7 +154,7 @@ public static void saveDiagramImage(final IPath sourcePath, final String textDia
saveDiagramImage(sourcePath, textDiagram, 0, image, targetPath, create);
}

public static void saveDiagramImage(final IPath sourcePath, final String textDiagram, final int imageNum, final ImageData image, final IPath targetPath, final boolean create) throws Exception {
private static void saveDiagramImage(final IPath sourcePath, final String textDiagram, final int imageNum, final ImageData image, final IPath targetPath, final boolean create) throws Exception {
final IFile file = ResourcesPlugin.getWorkspace().getRoot().getFile(targetPath);
if (file != null && (create || file.exists())) {
final String ext = targetPath.getFileExtension();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ protected void updateDiagramMarkers() {
}
}
}

private Collection<ILinkOpener> linkOpeners = null;

private Collection<ILinkOpener> getLinkOpeners() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public void run() {
String s = "empty";
try {
final DiagramImageData diagramImageData = getDiagramImageData();
final String source = diagramImageData.getDiagram().getTextDiagram();
final String source = diagramImageData.getDiagramData().getTextDiagram();
final SourceStringReader sourceStringReader = new SourceStringReader(source);
final ByteArrayOutputStream os = new ByteArrayOutputStream();
sourceStringReader.outputImage(os, diagramImageData.getImageNum(), new FileFormatOption(FileFormat.ATXT));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public void run() {
final String filePathName = fDialog.getFilterPath() + System.getProperty("file.separator") + fileName;
final String ext = fileName.substring(fileName.lastIndexOf(".") + 1);
if ("svg".equals(ext)) {
createImageFileSvg(filePathName, getDiagramImageData().getDiagram().getTextDiagram());
createImageFileSvg(filePathName, getDiagramImageData().getDiagramData().getTextDiagram());
} else {
createImageFile(filePathName, ext);
}
Expand All @@ -54,9 +54,9 @@ public void run() {
private void createImageFile(final String filePathName, final String format) {
final Function<Integer, String> fileNameProvider = PlantumlUtil.getImageFileNameProvider(filePathName);
if (fileNameProvider != null) {
final int imageCount = getDiagramImageData().getDiagram().getImageCount();
final int imageCount = getDiagramImageData().getDiagramData().getImageCount();
for (int i = 0; i < imageCount; i++) {
createImageFile(fileNameProvider.apply(i), format, getDiagramImageData().getDiagram().getImage(i, null));
createImageFile(fileNameProvider.apply(i), format, getDiagramImageData().getDiagramData().getImage(i, null));
}
} else {
createImageFile(filePathName, format, getImage());
Expand All @@ -77,7 +77,7 @@ private void createImageFile(final String filePathName, final String format, fin
private void createImageFileSvg(final String filePathName, final String textDiagram) {
final Function<Integer, String> fileNameProvider = PlantumlUtil.getImageFileNameProvider(filePathName);
if (fileNameProvider != null) {
final int imageCount = getDiagramImageData().getDiagram().getImageCount();
final int imageCount = getDiagramImageData().getDiagramData().getImageCount();
for (int i = 0; i < imageCount; i++) {
createImageFileSvg(fileNameProvider.apply(i), textDiagram, i);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,16 @@

public class DiagramImageData {

private final DiagramData diagram;
private final DiagramData diagramData;
private final int imageNum;

private ImageData imageData;

private final Collection<LinkData> links = new ArrayList<LinkData>();

public DiagramImageData(final DiagramData diagram, final int imageNum, final ImageData imageData) {
super();
this.diagram = diagram;
this.diagramData = diagram;
this.imageNum = imageNum;
this.imageData = imageData;
}
Expand All @@ -36,15 +37,15 @@ public DiagramImageData(final DiagramData diagram) {
}

public DiagramImageData withImageNum(final int imageNum) {
return new DiagramImageData(diagram, imageNum);
return new DiagramImageData(diagramData, imageNum);
}

public DiagramData getDiagram() {
return diagram;
public DiagramData getDiagramData() {
return diagramData;
}

public IPath getSourcePath() {
return diagram.getOriginal();
return diagramData.getOriginal();
}

public int getImageNum() {
Expand All @@ -53,7 +54,7 @@ public int getImageNum() {

public ImageData getImage() {
if (imageData == null) {
imageData = diagram.getImage(imageNum, links);
imageData = diagramData.getImage(imageNum, links);
}
return imageData;
}
Expand Down

0 comments on commit a0320c7

Please sign in to comment.