Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JBPM-7916 - Stunner BPMN Process Documentation Feature #2363

Merged
merged 7 commits into from Jan 19, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -46,6 +46,7 @@
import org.kie.workbench.common.stunner.core.client.session.Session;
import org.kie.workbench.common.stunner.core.client.session.impl.EditorSession;
import org.kie.workbench.common.stunner.core.client.session.impl.ViewerSession;
import org.kie.workbench.common.stunner.core.documentation.DocumentationView;
import org.kie.workbench.common.stunner.forms.client.event.RefreshFormPropertiesEvent;
import org.kie.workbench.common.stunner.project.client.editor.AbstractProjectDiagramEditor;
import org.kie.workbench.common.stunner.project.client.editor.event.OnDiagramFocusEvent;
Expand Down Expand Up @@ -92,6 +93,7 @@ public class DMNDiagramEditor extends AbstractProjectDiagramEditor<DMNDiagramRes

@Inject
public DMNDiagramEditor(final View view,
final DocumentationView documentationView,
final PlaceManager placeManager,
final ErrorPopupPresenter errorPopupPresenter,
final Event<ChangeTitleWidgetEvent> changeTitleNotificationEvent,
Expand All @@ -115,6 +117,7 @@ public DMNDiagramEditor(final View view,
final LayoutHelper layoutHelper,
final DataTypesPage dataTypesPage) {
super(view,
documentationView,
placeManager,
errorPopupPresenter,
changeTitleNotificationEvent,
Expand Down
Expand Up @@ -33,6 +33,7 @@
import org.kie.workbench.common.stunner.core.client.canvas.AbstractCanvasHandler;
import org.kie.workbench.common.stunner.core.client.command.SessionCommandManager;
import org.kie.workbench.common.stunner.core.client.components.layout.LayoutHelper;
import org.kie.workbench.common.stunner.core.documentation.DocumentationView;
import org.kie.workbench.common.stunner.forms.client.event.RefreshFormPropertiesEvent;
import org.kie.workbench.common.stunner.project.client.editor.AbstractProjectDiagramEditor;
import org.kie.workbench.common.stunner.project.client.editor.AbstractProjectDiagramEditorTest;
Expand Down Expand Up @@ -100,6 +101,9 @@ public class DMNDiagramEditorTest extends AbstractProjectDiagramEditorTest {

private DMNDiagramEditor diagramEditor;

@Mock
private DocumentationView documentationView;

@Before
public void before() {
when(kieView.getMultiPage()).thenReturn(multiPage);
Expand All @@ -124,6 +128,7 @@ protected DMNDiagramResourceType mockResourceType() {
@Override
protected AbstractProjectDiagramEditor createDiagramEditor() {
diagramEditor = spy(new DMNDiagramEditor(view,
documentationView,
placeManager,
errorPopupPresenter,
changeTitleNotificationEvent,
Expand Down
Expand Up @@ -87,8 +87,7 @@ private static FlowPanel buildPanel(final String className,
final int clipY) {
final FlowPanel panel = new FlowPanel();
panel.addStyleName(className);
panel.getElement().getStyle().setPropertyPx("backgroundPositionX", clipX);
panel.getElement().getStyle().setPropertyPx("backgroundPositionY", clipY);
panel.getElement().setAttribute("style", "background-position: " + clipX + "px " + clipY + "px !important");
return panel;
}
}
Expand Up @@ -49,6 +49,11 @@
<scope>provided</scope>
</dependency>

<dependency>
<groupId>com.google.jsinterop</groupId>
<artifactId>jsinterop-annotations</artifactId>
</dependency>

<!-- Uberfire & Errai. -->
<dependency>
<groupId>org.jboss.errai</groupId>
Expand Down
@@ -0,0 +1,29 @@
/*
* Copyright 2018 Red Hat, Inc. and/or its affiliates.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.kie.workbench.common.stunner.core.documentation.model;

import jsinterop.annotations.JsPackage;
import jsinterop.annotations.JsType;
import org.kie.workbench.common.stunner.core.diagram.Diagram;

/**
* Represents a process documentation of {@link Diagram}, containing all the processed data.
*/
@JsType(isNative = true, namespace = JsPackage.GLOBAL)
public interface DiagramDocumentation {

}
@@ -0,0 +1,32 @@
/*
* Copyright 2019 Red Hat, Inc. and/or its affiliates.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.kie.workbench.common.stunner.core.documentation.model;

public class DocumentationOutput {

public static final DocumentationOutput EMPTY = new DocumentationOutput("");

private String value;

public DocumentationOutput(String value) {
this.value = value;
}

public String getValue() {
return value;
}
}
@@ -0,0 +1,30 @@
/*
* Copyright 2019 Red Hat, Inc. and/or its affiliates.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.kie.workbench.common.stunner.core.documentation.model;

public class HTMLDocumentationTemplate {

private String template;

public HTMLDocumentationTemplate(String template) {
this.template = template;
}

public String getTemplate() {
return template;
}
}
@@ -0,0 +1,54 @@
/*
* Copyright 2018 Red Hat, Inc. and/or its affiliates.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.kie.workbench.common.stunner.core.documentation.service;

import org.kie.workbench.common.stunner.core.diagram.Diagram;
import org.kie.workbench.common.stunner.core.documentation.model.DiagramDocumentation;
import org.kie.workbench.common.stunner.core.documentation.model.DocumentationOutput;
import org.kie.workbench.common.stunner.core.documentation.model.HTMLDocumentationTemplate;

public interface DiagramDocumentationService<D extends Diagram, R extends DiagramDocumentation,
T extends HTMLDocumentationTemplate, P extends DocumentationOutput> {

/**
* Process the diagram generating the documentation output bean.
* @param diagram
* @return
*/
R processDocumentation(D diagram);

/**
* Returns the template to be used to build the serialized documentation.
* @return
*/
T getDocumentationTemplate();

/**
* Generates the documentation serialized output based on the given template.
* @param template
* @param diagramDocumentation
* @return
*/
DocumentationOutput buildDocumentation(T template, R diagramDocumentation);

/**
* This is the method that executed the full documentations process.
* @param diagram
* @return the processed documentation output
*/
DocumentationOutput generate(D diagram);
}
Expand Up @@ -29,6 +29,7 @@
<source path="command"/>
<source path="definition"/>
<source path="diagram"/>
<source path="documentation"/>
<source path="domainobject"/>
<source path="graph"/>
<source path="factory"/>
Expand Down
Expand Up @@ -68,7 +68,16 @@
<scope>provided</scope>
</dependency>

<dependency>
<groupId>com.google.jsinterop</groupId>
<artifactId>jsinterop-annotations</artifactId>
</dependency>

<!-- Uberfire & Errai. -->
<dependency>
<groupId>org.uberfire</groupId>
<artifactId>uberfire-workbench-client-views-patternfly</artifactId>
</dependency>

<dependency>
<groupId>org.jboss.errai</groupId>
Expand Down
Expand Up @@ -21,9 +21,11 @@
import java.util.logging.Logger;

import javax.enterprise.context.ApplicationScoped;
import javax.enterprise.event.Event;
import javax.inject.Inject;

import org.kie.workbench.common.stunner.core.client.canvas.AbstractCanvasHandler;
import org.kie.workbench.common.stunner.core.client.canvas.event.selection.CanvasClearSelectionEvent;
import org.kie.workbench.common.stunner.core.client.canvas.export.CanvasExport;
import org.kie.workbench.common.stunner.core.client.canvas.export.CanvasExportSettings;
import org.kie.workbench.common.stunner.core.client.canvas.export.CanvasURLExportSettings;
Expand Down Expand Up @@ -53,12 +55,14 @@ public class CanvasFileExport {
private final FileExport<PdfDocument> pdfFileExport;
private final FileExportsPreferences preferences;
private final SvgFileExport svgFileExport;
private final Event<CanvasClearSelectionEvent> clearSelectionEvent;

protected CanvasFileExport() {
this(null,
null,
null,
null,
null,
null);
}

Expand All @@ -67,40 +71,51 @@ public CanvasFileExport(final CanvasExport<AbstractCanvasHandler> canvasExport,
final FileExport<ImageDataUriContent> imageFileExport,
final FileExport<PdfDocument> pdfFileExport,
final FileExportsPreferences preferences,
final SvgFileExport svgFileExport) {
final SvgFileExport svgFileExport,
final Event<CanvasClearSelectionEvent> clearSelectionEvent) {
this.canvasExport = canvasExport;
this.imageFileExport = imageFileExport;
this.pdfFileExport = pdfFileExport;
this.preferences = preferences;
this.svgFileExport = svgFileExport;
this.clearSelectionEvent = clearSelectionEvent;
}

public void exportToSvg(final AbstractCanvasHandler canvasHandler,
final String fileName) {
clearSelection(canvasHandler);
final String fullFileName = fileName + "." + getFileExtension(CanvasExport.URLDataType.SVG);
svgFileExport.export(canvasExport.toContext2D(canvasHandler, CanvasExportSettings.build()), fullFileName);
}

private void clearSelection(AbstractCanvasHandler canvasHandler) {
clearSelectionEvent.fire(new CanvasClearSelectionEvent(canvasHandler));
}

public String exportToSvg(final AbstractCanvasHandler canvasHandler) {
clearSelection(canvasHandler);
return canvasExport.toContext2D(canvasHandler, CanvasExportSettings.build()).getSerializedSvg();
}

public void exportToJpg(final AbstractCanvasHandler canvasHandler,
final String fileName) {
clearSelection(canvasHandler);
exportImage(canvasHandler,
CanvasExport.URLDataType.JPG,
fileName);
}

public void exportToPng(final AbstractCanvasHandler canvasHandler,
final String fileName) {
clearSelection(canvasHandler);
exportImage(canvasHandler,
CanvasExport.URLDataType.PNG,
fileName);
}

public void exportToPdf(final AbstractCanvasHandler canvasHandler,
final String fileName) {
clearSelection(canvasHandler);
loadFileExportPreferences(prefs -> exportToPdf(canvasHandler,
fileName,
prefs.getPdfPreferences()));
Expand Down
Expand Up @@ -21,7 +21,6 @@
import org.kie.workbench.common.stunner.core.client.session.ClientSession;
import org.kie.workbench.common.stunner.core.client.session.command.AbstractClientSessionCommand;
import org.kie.workbench.common.stunner.core.client.session.impl.AbstractSession;
import org.kie.workbench.common.stunner.core.client.session.impl.EditorSession;
import org.uberfire.backend.vfs.Path;

public abstract class AbstractExportSessionCommand extends AbstractClientSessionCommand<AbstractSession<AbstractCanvas, AbstractCanvasHandler>> {
Expand All @@ -39,11 +38,6 @@ public boolean accepts(final ClientSession session) {

@Override
public <T> void execute(final Callback<T> callback) {
//prevents to render selection on canvas
if (getSession() instanceof EditorSession) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is no need clear selection anymore?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, every time we are generating SVG or any other images, before that we are clearing the selection on canvas, to avoid showing up the Toolbox, but now I centralized it on the CanvasExport, it is better to keep only on one place IMO, see https://github.com/kiegroup/kie-wb-common/pull/2363/files#diff-0121e8ab393e44ea36b71825a5f6b861

((EditorSession) getSession()).getSelectionControl().clearSelection();
}

final String fileName = getFileName();
export(fileName);
callback.onSuccess();
Expand Down
Expand Up @@ -82,11 +82,6 @@ protected void onSaveDiagram(@Observes SaveDiagramSessionCommandExecutedEvent ev

final Metadata diagramMetadata = getCanvasHandler().getDiagram().getMetadata();
if (Objects.equals(diagramMetadata.getCanvasRootUUID(), event.getDiagramUUID())) {

//prevents to render selection on canvas
getSession().getSelectionControl().clearSelection();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is no need clear selection anymore?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, every time we are generating SVG or any other images, before that we are clearing the selection on canvas, to avoid showing up the Toolbox, but now I centralized it on the CanvasExport, it is better to keep only on one place IMO, see https://github.com/kiegroup/kie-wb-common/pull/2363/files#diff-0121e8ab393e44ea36b71825a5f6b861


//This is a workaround to overcome the animations executed on canvas when clear selection
final String rawSvg = canvasExport.exportToSvg(getCanvasHandler());
diagramService.saveOrUpdateSvg(diagramMetadata.getPath(), rawSvg, new ServiceCallback<Path>() {
@Override
Expand Down
@@ -0,0 +1,21 @@
<!--
~ Copyright 2018 Red Hat, Inc. and/or its affiliates.
~
~ Licensed under the Apache License, Version 2.0 (the "License");
~ you may not use this file except in compliance with the License.
~ You may obtain a copy of the License at
~
~ http://www.apache.org/licenses/LICENSE-2.0
~
~ Unless required by applicable law or agreed to in writing, software
~ distributed under the License is distributed on an "AS IS" BASIS,
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
~ See the License for the specific language governing permissions and
~ limitations under the License.
-->

<div data-field="documentationPanel" style="width: 100%;">
<div style="padding-top: 10px">
<h1>Documentation not available.</h1>
</div>
</div>