HI,
Now I am trying to perform below task
As I mentioned before , We are trying to add a export menu option apart from "Export to BPMN 2.0". So that
If I click my menu it should trigger acme marshall and generate the XML.
If I click "Export to BPMN 2.0" option it should trigger bpmnexport marshall and generate in activiti format.
——–
I did the below things
1. Added the below code in ActivitiToolbehaviouirprovider class.
ContextMenuEntry subMenu1Export = new ContextMenuEntry(new SaveAcmeModelFeature(getFeatureProvider()),context);
subMenu1Export.setText("Export to My XML"); //$NON-NLS-1$
subMenu1Export.setSubmenu(false);
2. Created another class in GUI project for acme
package org.activiti.designer.features;
import org.activiti.designer.xml.BpmnXMLExport;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.IWorkspace;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.Path;
import org.eclipse.emf.common.util.URI;
import org.eclipse.graphiti.features.IFeatureProvider;
import org.eclipse.graphiti.features.context.ICustomContext;
import org.eclipse.graphiti.features.custom.AbstractCustomFeature;
public class SaveAcmeModelFeature extends AbstractCustomFeature{
public SaveAcmeModelFeature(IFeatureProvider fp) {
super(fp);
}
@Override
public String getName() {
return "Save to acme 2.0"; //$NON-NLS-1$
}
@Override
public String getDescription() {
return "Generate the acme 2.0 xml file"; //$NON-NLS-1$
}
@Override
public boolean canExecute(ICustomContext context) {
return true;
}
public void execute(ICustomContext context) {
try {
URI uri = getDiagram().eResource().getURI();
URI bpmnUri = uri.trimFragment();
bpmnUri = bpmnUri.trimFileExtension();
bpmnUri = bpmnUri.appendFileExtension("acme.xml");
IProject project = null;
String parentDiagramName = null;
if (bpmnUri.isPlatformResource()) {
String platformString = bpmnUri.toPlatformString(true);
IResource fileResource = ResourcesPlugin.getWorkspace().getRoot().findMember(platformString);
if(fileResource != null) {
project = fileResource.getProject();
parentDiagramName = uri.trimFragment().trimFileExtension().lastSegment();
}
}
boolean validBpmn = BpmnXMLExport.validateBpmn(getDiagram().eResource().getContents(), project, parentDiagramName);
if(validBpmn) {
BpmnXMLExport.createBpmnFile(bpmnUri, getDiagram(), project, parentDiagramName);
IWorkspace workspace = ResourcesPlugin.getWorkspace();
IPath location = Path.fromOSString(bpmnUri.toPlatformString(false));
IFile file = workspace.getRoot().getFile(location);
file.refreshLocal(IResource.DEPTH_INFINITE, null);
}
} catch(Exception e) {
e.printStackTrace();
}
}
}
But still it did not work in our way. Can you please help us.