Use released Argeo Maven plugin
[gpl/argeo-suite.git] / publishing / org.argeo.publishing.ui / src / org / argeo / docbook / ui / DbkContextMenu.java
index 24a759c60ff06c963f2511da6e3fcd1f09ef99a6..6046bf2c9ce5c537761c43101131dff5ba789268 100644 (file)
@@ -5,8 +5,6 @@ import java.util.List;
 
 import javax.jcr.Node;
 
-import org.argeo.cms.text.Paragraph;
-import org.argeo.cms.text.TextSection;
 import org.argeo.cms.ui.CmsEditable;
 import org.argeo.cms.ui.util.CmsUiUtils;
 import org.argeo.cms.ui.viewers.EditablePart;
@@ -15,7 +13,6 @@ import org.argeo.cms.ui.viewers.Section;
 import org.argeo.cms.ui.viewers.SectionPart;
 import org.argeo.cms.ui.widgets.EditableText;
 import org.argeo.cms.ui.widgets.Img;
-import org.argeo.cms.ui.widgets.TextStyles;
 import org.argeo.docbook.DbkMsg;
 import org.argeo.docbook.DbkUtils;
 import org.argeo.eclipse.ui.MouseDown;
@@ -33,7 +30,7 @@ import org.eclipse.swt.widgets.Label;
 import org.eclipse.swt.widgets.Shell;
 
 /** Dialog to edit a text part. */
-class DbkContextMenu implements TextStyles {
+class DbkContextMenu {
        private final AbstractDbkViewer textViewer;
 
        private Shell shell;
@@ -61,15 +58,16 @@ class DbkContextMenu implements TextStyles {
                if (editablePart instanceof Paragraph) {
                        Paragraph paragraph = (Paragraph) editablePart;
                        deletePartB(parent, DbkMsg.deleteParagraph.lead(), paragraph);
-                       insertMediaB(parent, DbkMsg.insertMedia.lead(), paragraph);
+                       insertMediaB(parent,  paragraph);
 
                } else if (editablePart instanceof Img) {
                        Img img = (Img) editablePart;
                        deletePartB(parent, DbkMsg.deleteMedia.lead(), img);
-                       insertMediaB(parent, DbkMsg.insertMedia.lead(), img);
+                       insertMediaB(parent, img);
+                       insertParagraphB(parent, DbkMsg.insertParagraph.lead(), img);
 
-               } else if (editablePart instanceof DocBookSectionTitle) {
-                       DocBookSectionTitle sectionTitle = (DocBookSectionTitle) editablePart;
+               } else if (editablePart instanceof DbkSectionTitle) {
+                       DbkSectionTitle sectionTitle = (DbkSectionTitle) editablePart;
                        TextSection section = sectionTitle.getSection();
                        if (!section.isTitleReadOnly()) {
                                Label deleteB = new Label(shell, SWT.NONE);
@@ -79,7 +77,7 @@ class DbkContextMenu implements TextStyles {
                                        hide();
                                });
                        }
-                       insertMediaB(parent, DbkMsg.insertMedia.lead(), sectionTitle.getSection(), sectionTitle);
+                       insertMediaB(parent,  sectionTitle.getSection(), sectionTitle);
                }
 
                StyledToolMouseListener stml = new StyledToolMouseListener(editablePart);
@@ -130,22 +128,39 @@ class DbkContextMenu implements TextStyles {
                shell.setVisible(false);
        }
 
-       protected void insertMediaB(Composite parent, String msg, SectionPart sectionPart) {
-               insertMediaB(parent, msg, sectionPart.getSection(), sectionPart);
+       protected void insertMediaB(Composite parent, SectionPart sectionPart) {
+               insertMediaB(parent,  sectionPart.getSection(), sectionPart);
        }
 
-       protected void insertMediaB(Composite parent, String msg, Section section, NodePart nodePart) {
-               Label insertMediaB = new Label(parent, SWT.NONE);
-               insertMediaB.setText(DbkMsg.insertMedia.lead());
-               insertMediaB.addMouseListener((MouseDown) (e) -> {
+       protected void insertMediaB(Composite parent, Section section, NodePart nodePart) {
+               Label insertPictureB = new Label(parent, SWT.NONE);
+               insertPictureB.setText(DbkMsg.insertPicture.lead());
+               insertPictureB.addMouseListener((MouseDown) (e) -> {
                        Node newNode = DbkUtils.insertImageAfter(nodePart.getNode());
                        Jcr.save(newNode);
                        textViewer.insertPart(section, newNode);
                        hide();
                });
+               Label insertVideoB = new Label(parent, SWT.NONE);
+               insertVideoB.setText(DbkMsg.insertVideo.lead());
+               insertVideoB.addMouseListener((MouseDown) (e) -> {
+                       Node newNode = DbkUtils.insertVideoAfter(nodePart.getNode());
+                       Jcr.save(newNode);
+                       textViewer.insertPart(section, newNode);
+                       hide();
+               });
 
        }
 
+       protected void insertParagraphB(Composite parent, String msg, SectionPart sectionPart) {
+               Label insertMediaB = new Label(parent, SWT.NONE);
+               insertMediaB.setText(msg);
+               insertMediaB.addMouseListener((MouseDown) (e) -> {
+                       textViewer.addParagraph(sectionPart, null);
+                       hide();
+               });
+       }
+
        protected void deletePartB(Composite parent, String msg, SectionPart sectionPart) {
                Label deleteB = new Label(shell, SWT.NONE);
                deleteB.setText(msg);