private void doSaveImage(final String diagramFileString, BpmnMemoryModel model) { boolean saveImage = PreferencesUtil.getBooleanPreference(Preferences.SAVE_IMAGE, ActivitiPlugin.getDefault()); if (saveImage) { List<String> languages = PreferencesUtil.getStringArray( Preferences.ACTIVITI_LANGUAGES, ActivitiPlugin.getDefault()); if (languages != null && languages.size() > 0) { for (String language : languages) { for (Process process : model.getBpmnModel().getProcesses()) { fillContainerWithLanguage(process, language); } ProcessDiagramGenerator processDiagramGenerator = new DefaultProcessDiagramGenerator(); InputStream imageStream = processDiagramGenerator.generatePngDiagram(model.getBpmnModel()); if (imageStream != null) { String imageFileName = null; if (diagramFileString.endsWith(".bpmn20.xml")) { imageFileName = diagramFileString.substring(0, diagramFileString.length() - 11) + "_" + language + ".png"; } else { imageFileName = diagramFileString.substring(0, diagramFileString.lastIndexOf(".")) + "_" + language + ".png"; } File imageFile = new File(imageFileName); FileOutputStream outStream = null; ByteArrayOutputStream baos = null; try { outStream = new FileOutputStream(imageFile); baos = new ByteArrayOutputStream(); IOUtils.copy(imageStream, baos); baos.writeTo(outStream); } catch (Exception e) { e.printStackTrace(); } finally { if (outStream != null) { IOUtils.closeQuietly(outStream); } if (baos != null) { IOUtils.closeQuietly(baos); } } } } } else { marshallImage(model, diagramFileString); } } }
public void addOverlay(final GC imageGC, String modelFileName, BpmnMemoryModel model) { if (PreferencesUtil.getBooleanPreference( Preferences.SAVE_IMAGE_ADD_OVERLAY, ActivitiPlugin.getDefault())) { final ImageOverlayCreator creator = new ImageOverlayCreator(imageGC); creator.addOverlay(modelFileName, model); } }
@Override public void setValue(String value, IDirectEditingContext context) { final PictogramElement pe = context.getPictogramElement(); final TextAnnotation annotation = (TextAnnotation) getBusinessObjectForPictogramElement(pe); BpmnExtensionUtil.setTextAnnotationText(annotation, value, ActivitiPlugin.getDefault()); updatePictogramElement(((Shape) pe).getContainer()); }
@Override public String getInitialValue(final IDirectEditingContext context) { final PictogramElement pe = context.getPictogramElement(); final TextAnnotation annotation = (TextAnnotation) getBusinessObjectForPictogramElement(pe); return BpmnExtensionUtil.getTextAnnotationText(annotation, ActivitiPlugin.getDefault()); }
@Override public PictogramElement createShape( Object businessObject, ContainerShape layoutParent, int width, int height, IAddContext context) { final IPeCreateService peCreateService = Graphiti.getPeCreateService(); final ContainerShape containerShape = peCreateService.createContainerShape(layoutParent, true); final IGaService gaService = Graphiti.getGaService(); Diagram diagram = getFeatureProvider().getDiagramTypeProvider().getDiagram(); final Pool addedPool = (Pool) context.getNewObject(); // check whether the context has a size (e.g. from a create feature) // otherwise define a default size for the shape width = width <= 0 ? 500 : width; height = height <= 0 ? 150 : height; // create invisible outer rectangle expanded by // the width needed for the anchor final Rectangle invisibleRectangle = gaService.createInvisibleRectangle(containerShape); gaService.setLocationAndSize(invisibleRectangle, context.getX(), context.getY(), width, height); // create and set visible rectangle inside invisible rectangle Rectangle rectangle = gaService.createRectangle(invisibleRectangle); rectangle.setParentGraphicsAlgorithm(invisibleRectangle); rectangle.setStyle(StyleUtil.getStyleForPool(diagram)); gaService.setLocationAndSize(rectangle, 0, 0, width, height); // create shape for text final Shape shape = peCreateService.createShape(containerShape, false); // create and set text graphics algorithm String name = BpmnExtensionUtil.getPoolName(addedPool, ActivitiPlugin.getDefault()); final Text text = gaService.createDefaultText(diagram, shape, name); text.setStyle(StyleUtil.getStyleForEvent(diagram)); text.setHorizontalAlignment(Orientation.ALIGNMENT_CENTER); text.setVerticalAlignment(Orientation.ALIGNMENT_MIDDLE); gaService.setLocationAndSize(text, 0, 0, 20, height); text.setAngle(-90); Font font = null; if (OSUtil.getOperatingSystem() == OSEnum.Mac) { font = gaService.manageFont(diagram, text.getFont().getName(), 11, false, true); } else { font = gaService.manageDefaultFont(diagram, false, true); } text.setFont(font); // create link and wire it getFeatureProvider().link(shape, addedPool); return containerShape; }
@Override public PictogramElement createShape( Object businessObject, ContainerShape layoutParent, int width, int height, IAddContext context) { final IPeCreateService peCreateService = Graphiti.getPeCreateService(); final ContainerShape containerShape = peCreateService.createContainerShape(layoutParent, true); final IGaService gaService = Graphiti.getGaService(); Diagram diagram = getFeatureProvider().getDiagramTypeProvider().getDiagram(); final TextAnnotation annotation = (TextAnnotation) businessObject; height = Math.max(50, height); width = Math.max(100, width); final int commentEdge = 20; final Rectangle rect = gaService.createInvisibleRectangle(containerShape); gaService.setLocationAndSize(rect, context.getX(), context.getY(), width, height); final Shape lineShape = peCreateService.createShape(containerShape, false); final Polyline line = gaService.createPolyline( lineShape, new int[] {commentEdge, 0, 0, 0, 0, height, commentEdge, height}); line.setStyle(StyleUtil.getStyleForTask(diagram)); line.setLineWidth(2); gaService.setLocationAndSize(line, 0, 0, commentEdge, height); final Shape textShape = peCreateService.createShape(containerShape, false); String annotationText = BpmnExtensionUtil.getTextAnnotationText(annotation, ActivitiPlugin.getDefault()); final MultiText text = gaService.createDefaultMultiText(diagram, textShape, annotationText); text.setStyle(StyleUtil.getStyleForTask(diagram)); text.setVerticalAlignment(Orientation.ALIGNMENT_TOP); if (OSUtil.getOperatingSystem() == OSEnum.Mac) { text.setFont(gaService.manageFont(diagram, text.getFont().getName(), 11)); } gaService.setLocationAndSize(text, 5, 5, width - 5, height - 5); getFeatureProvider().link(textShape, annotation); peCreateService.createChopboxAnchor(containerShape); return containerShape; }
@Override protected void setInput(IEditorInput input) { super.setInput(input); final ActivitiDiagramEditorInput adei = (ActivitiDiagramEditorInput) input; final IFile dataFile = adei.getDataFile(); final BpmnMemoryModel model = new BpmnMemoryModel(getDiagramTypeProvider().getFeatureProvider(), dataFile); ModelHandler.addModel(EcoreUtil.getURI(getDiagramTypeProvider().getDiagram()), model); String filePath = dataFile.getLocationURI().getPath(); File bpmnFile = new File(filePath); try { if (bpmnFile.exists() == false) { model.setBpmnModel(new BpmnModel()); model.addMainProcess(); bpmnFile.createNewFile(); dataFile.refreshLocal(IResource.DEPTH_INFINITE, null); } else { FileInputStream fileStream = new FileInputStream(bpmnFile); XMLInputFactory xif = XMLInputFactory.newInstance(); InputStreamReader in = new InputStreamReader(fileStream, "UTF-8"); XMLStreamReader xtr = xif.createXMLStreamReader(in); BpmnXMLConverter bpmnConverter = new BpmnXMLConverter(); bpmnConverter.setUserTaskFormTypes( PreferencesUtil.getStringArray( Preferences.ALFRESCO_FORMTYPES_USERTASK, ActivitiPlugin.getDefault())); bpmnConverter.setStartEventFormTypes( PreferencesUtil.getStringArray( Preferences.ALFRESCO_FORMTYPES_STARTEVENT, ActivitiPlugin.getDefault())); BpmnModel bpmnModel = null; try { bpmnModel = bpmnConverter.convertToBpmnModel(xtr); } catch (Exception e) { bpmnModel = new BpmnModel(); } model.setBpmnModel(bpmnModel); if (bpmnModel.getLocationMap().size() == 0) { BpmnAutoLayout layout = new BpmnAutoLayout(bpmnModel); layout.execute(); } BasicCommandStack basicCommandStack = (BasicCommandStack) getEditingDomain().getCommandStack(); if (input instanceof DiagramEditorInput) { basicCommandStack.execute( new RecordingCommand(getEditingDomain()) { @Override protected void doExecute() { importDiagram(model); } }); } basicCommandStack.saveIsDone(); basicCommandStack.flush(); } } catch (Exception e) { e.printStackTrace(); } }