From: Mathieu Baudier Date: Mon, 18 Jan 2021 10:38:33 +0000 (+0100) Subject: Style setter for DocBook. X-Git-Tag: argeo-suite-2.1.18~33 X-Git-Url: https://git.argeo.org/?p=gpl%2Fargeo-suite.git;a=commitdiff_plain;h=4f4e2b4985cc4cc910da83398e8a9cd37645ef9c Style setter for DocBook. --- diff --git a/publishing/org.argeo.publishing.ui/src/org/argeo/docbook/ui/AbstractDbkViewer.java b/publishing/org.argeo.publishing.ui/src/org/argeo/docbook/ui/AbstractDbkViewer.java index 245c15e..1b8a237 100644 --- a/publishing/org.argeo.publishing.ui/src/org/argeo/docbook/ui/AbstractDbkViewer.java +++ b/publishing/org.argeo.publishing.ui/src/org/argeo/docbook/ui/AbstractDbkViewer.java @@ -4,6 +4,7 @@ import static org.argeo.cms.ui.util.CmsUiUtils.fillWidth; import java.util.ArrayList; import java.util.Iterator; +import java.util.List; import java.util.Map; import java.util.Observer; @@ -75,7 +76,7 @@ public abstract class AbstractDbkViewer extends AbstractPageViewer implements Ke if (getCmsEditable().canEdit()) { fileUploadListener = new FUL(); - styledTools = new DbkContextMenu(this, parent.getDisplay()); + styledTools = new DbkContextMenu(this, parent.getShell()); } this.mainSection = parent; initModelIfNeeded(mainSection.getNode()); @@ -332,10 +333,15 @@ public abstract class AbstractDbkViewer extends AbstractPageViewer implements Ke void setParagraphStyle(Paragraph paragraph, String style) { try { Node paragraphNode = paragraph.getNode(); - paragraphNode.setProperty(DocBookNames.DBK_ROLE, style); + if (style == null) {// default + if (paragraphNode.hasProperty(DocBookNames.DBK_ROLE)) + paragraphNode.getProperty(DocBookNames.DBK_ROLE).remove(); + } else { + paragraphNode.setProperty(DocBookNames.DBK_ROLE, style); + } persistChanges(paragraphNode); updateContent(paragraph); - layout(paragraph); + layoutPage(); } catch (RepositoryException e1) { throw new JcrException("Cannot set style " + style + " on " + paragraph, e1); } @@ -818,8 +824,10 @@ public abstract class AbstractDbkViewer extends AbstractPageViewer implements Ke edit(composite, source.toDisplay(point)); } else if (e.button == 3) { EditablePart composite = findDataParent((Control) e.getSource()); - if (styledTools != null) - styledTools.show(composite, new Point(e.x, e.y)); + if (styledTools != null) { + List styles = getAvailableStyles(composite); + styledTools.show(composite, new Point(e.x, e.y), styles); + } } } } @@ -829,6 +837,10 @@ public abstract class AbstractDbkViewer extends AbstractPageViewer implements Ke } } + protected List getAvailableStyles(EditablePart editablePart) { + return new ArrayList<>(); + } + // FILE UPLOAD LISTENER private class FUL implements FileUploadListener { public void uploadProgress(FileUploadEvent event) { diff --git a/publishing/org.argeo.publishing.ui/src/org/argeo/docbook/ui/DbkContextMenu.java b/publishing/org.argeo.publishing.ui/src/org/argeo/docbook/ui/DbkContextMenu.java index 928fb77..bccdbb8 100644 --- a/publishing/org.argeo.publishing.ui/src/org/argeo/docbook/ui/DbkContextMenu.java +++ b/publishing/org.argeo.publishing.ui/src/org/argeo/docbook/ui/DbkContextMenu.java @@ -4,8 +4,9 @@ import java.util.ArrayList; import java.util.List; import org.argeo.cms.text.Paragraph; +import org.argeo.cms.ui.util.CmsUiUtils; import org.argeo.cms.ui.viewers.EditablePart; -import org.argeo.cms.ui.viewers.SectionPart; +import org.argeo.cms.ui.widgets.EditableText; import org.argeo.cms.ui.widgets.TextStyles; import org.eclipse.rap.rwt.RWT; import org.eclipse.swt.SWT; @@ -16,63 +17,74 @@ import org.eclipse.swt.graphics.Point; import org.eclipse.swt.layout.GridLayout; import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Control; -import org.eclipse.swt.widgets.Display; import org.eclipse.swt.widgets.Label; import org.eclipse.swt.widgets.Shell; /** Dialog to edit a text part. */ class DbkContextMenu implements TextStyles { - private final static String[] DEFAULT_TEXT_STYLES = { TextStyles.TEXT_DEFAULT, TextStyles.TEXT_PRE, - TextStyles.TEXT_QUOTE }; +// private final static String[] DEFAULT_TEXT_STYLES = { TextStyles.TEXT_DEFAULT, TextStyles.TEXT_PRE, +// TextStyles.TEXT_QUOTE }; private final AbstractDbkViewer textViewer; - private List styleButtons = new ArrayList(); - - private Label deleteButton, publishButton, editButton; +// private List styleButtons = new ArrayList(); +// +// private Label deleteButton, publishButton, editButton; private EditablePart currentTextPart; private Shell shell; - public DbkContextMenu(AbstractDbkViewer textViewer, Display display) { - shell = new Shell(display, SWT.NO_TRIM | SWT.BORDER | SWT.ON_TOP); + public DbkContextMenu(AbstractDbkViewer textViewer, Shell parentShell) { +// shell = new Shell(display, SWT.NO_TRIM | SWT.BORDER | SWT.ON_TOP); + shell = new Shell(parentShell, SWT.BORDER); // super(display, SWT.NO_TRIM | SWT.BORDER | SWT.ON_TOP); this.textViewer = textViewer; shell.setLayout(new GridLayout()); - shell.setData(RWT.CUSTOM_VARIANT, TEXT_STYLED_TOOLS_DIALOG); + // shell.setData(RWT.CUSTOM_VARIANT, TEXT_STYLED_TOOLS_DIALOG); + + shell.addShellListener(new ToolsShellListener()); + } + + public void show(EditablePart source, Point location, List availableStyles) { + if (shell.isVisible()) + shell.setVisible(false); + CmsUiUtils.clear(shell); + + if (availableStyles.isEmpty()) + return; StyledToolMouseListener stml = new StyledToolMouseListener(); + List styleButtons = new ArrayList(); if (textViewer.getCmsEditable().isEditing()) { - for (String style : DEFAULT_TEXT_STYLES) { + for (String style : availableStyles) { StyleButton styleButton = new StyleButton(shell, SWT.WRAP); - styleButton.getLabel().setData(RWT.CUSTOM_VARIANT, style); - styleButton.getLabel().setData(RWT.MARKUP_ENABLED, true); - styleButton.getLabel().addMouseListener(stml); + if (!"".equals(style)) + styleButton.setStyle(style); + else + styleButton.setStyle(null); +// if (!"".equals(style)) +// styleButton.getLabel().setData(RWT.CUSTOM_VARIANT, style); +// styleButton.getLabel().setData(RWT.MARKUP_ENABLED, true); + styleButton.setMouseListener(stml); styleButtons.add(styleButton); } - // Delete - deleteButton = new Label(shell, SWT.NONE); - deleteButton.setText("Delete"); - deleteButton.addMouseListener(stml); - - // Publish - publishButton = new Label(shell, SWT.NONE); - publishButton.setText("Publish"); - publishButton.addMouseListener(stml); +// // Delete +// deleteButton = new Label(shell, SWT.NONE); +// deleteButton.setText("Delete"); +// deleteButton.addMouseListener(stml); +// +// // Publish +// publishButton = new Label(shell, SWT.NONE); +// publishButton.setText("Publish"); +// publishButton.addMouseListener(stml); } else if (textViewer.getCmsEditable().canEdit()) { // Edit - editButton = new Label(shell, SWT.NONE); + Label editButton = new Label(shell, SWT.NONE); editButton.setText("Edit"); editButton.addMouseListener(stml); } - shell.addShellListener(new ToolsShellListener()); - } - - public void show(EditablePart source, Point location) { - if (shell.isVisible()) - shell.setVisible(false); this.currentTextPart = source; @@ -81,29 +93,50 @@ class DbkContextMenu implements TextStyles { String text = textViewer.getRawParagraphText((Paragraph) currentTextPart); String textToShow = text.length() > size ? text.substring(0, size - 3) + "..." : text; for (StyleButton styleButton : styleButtons) { - styleButton.getLabel().setText(textToShow); + styleButton.setText((styleButton.style == null ? "default" : styleButton.style) + " : " + textToShow); } } shell.pack(); shell.layout(); - if (source instanceof Control) - shell.setLocation(((Control) source).toDisplay(location.x, location.y)); + if (source instanceof Control) { + int height = shell.getSize().y; + int parentShellHeight = shell.getShell().getSize().y; + if ((location.y + height) < parentShellHeight) { + shell.setLocation(((Control) source).toDisplay(location.x, location.y)); + } else { + shell.setLocation(((Control) source).toDisplay(location.x, location.y - parentShellHeight)); + } + } shell.open(); } - class StyleButton extends Composite { + class StyleButton extends EditableText { private static final long serialVersionUID = 7731102609123946115L; - private Label label; - public StyleButton(Composite parent, int swtStyle) { - super(parent, SWT.NONE); - label = new Label(this, swtStyle); + String style; + + public StyleButton(Composite parent, int style) { + super(parent, style); } - public Label getLabel() { - return label; + @Override + public void setStyle(String style) { + this.style = style; + super.setStyle(style); } +// private Label label; +// +// public StyleButton(Composite parent, int swtStyle) { +// super(parent, SWT.NONE); +// setLayout(new GridLayout()); +// label = new Label(this, swtStyle); +// } +// +// public Label getLabel() { +// return label; +// } + } class StyledToolMouseListener extends MouseAdapter { @@ -111,18 +144,19 @@ class DbkContextMenu implements TextStyles { @Override public void mouseDown(MouseEvent e) { - Object eventSource = e.getSource(); - if (eventSource instanceof StyleButton) { - StyleButton sb = (StyleButton) e.getSource(); - String style = sb.getData(RWT.CUSTOM_VARIANT).toString(); - textViewer.setParagraphStyle((Paragraph) currentTextPart, style); - } else if (eventSource == deleteButton) { - textViewer.deletePart((SectionPart) currentTextPart); - } else if (eventSource == editButton) { - textViewer.getCmsEditable().startEditing(); - } else if (eventSource == publishButton) { - textViewer.getCmsEditable().stopEditing(); - } +// Object eventSource = e.getSource(); +//// if (eventSource instanceof StyleButton) { + // TODO make it more robust. + Label sb = (Label) e.getSource(); + Object style = sb.getData(RWT.CUSTOM_VARIANT); + textViewer.setParagraphStyle((Paragraph) currentTextPart, style == null ? null : style.toString()); +// } +// } else if (eventSource == deleteButton) { +// textViewer.deletePart((SectionPart) currentTextPart); +// } else if (eventSource == editButton) { +// textViewer.getCmsEditable().startEditing(); +// } else if (eventSource == publishButton) { +// textViewer.getCmsEditable().stopEditing(); shell.setVisible(false); } } diff --git a/publishing/org.argeo.publishing.ui/src/org/argeo/docbook/ui/DocBookSectionTitle.java b/publishing/org.argeo.publishing.ui/src/org/argeo/docbook/ui/DocBookSectionTitle.java index 1ece09e..587bc85 100644 --- a/publishing/org.argeo.publishing.ui/src/org/argeo/docbook/ui/DocBookSectionTitle.java +++ b/publishing/org.argeo.publishing.ui/src/org/argeo/docbook/ui/DocBookSectionTitle.java @@ -1,17 +1,13 @@ package org.argeo.docbook.ui; import javax.jcr.Node; -import javax.jcr.Property; import javax.jcr.RepositoryException; import org.argeo.cms.text.TextSection; import org.argeo.cms.ui.viewers.EditablePart; import org.argeo.cms.ui.viewers.NodePart; import org.argeo.cms.ui.widgets.EditableText; -import org.eclipse.swt.SWT; -import org.eclipse.swt.layout.GridData; import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Control; /** The title of a section, based on an XML text node. */ public class DocBookSectionTitle extends EditableText implements EditablePart, NodePart {