X-Git-Url: https://git.argeo.org/?p=gpl%2Fargeo-suite.git;a=blobdiff_plain;f=org.argeo.suite.ui%2Fsrc%2Forg%2Fargeo%2Fsuite%2Fui%2FSuiteUiUtils.java;h=c98e6d64c800c677fb7ceaabd38b083ef9fd06fb;hp=28d775300f0b7c03a548e155453f8881d339ba41;hb=6a7ef2b05835eeb92678856262340d9f01677a71;hpb=dcab9f85ec830d3c8deeed5243eda43a4f82ef7d diff --git a/org.argeo.suite.ui/src/org/argeo/suite/ui/SuiteUiUtils.java b/org.argeo.suite.ui/src/org/argeo/suite/ui/SuiteUiUtils.java index 28d7753..c98e6d6 100644 --- a/org.argeo.suite.ui/src/org/argeo/suite/ui/SuiteUiUtils.java +++ b/org.argeo.suite.ui/src/org/argeo/suite/ui/SuiteUiUtils.java @@ -8,20 +8,30 @@ import javax.jcr.RepositoryException; import javax.jcr.Session; import org.argeo.api.NodeConstants; +import org.argeo.cms.Localized; +import org.argeo.cms.ui.CmsEditable; import org.argeo.cms.ui.dialogs.CmsWizardDialog; import org.argeo.cms.ui.util.CmsUiUtils; +import org.argeo.eclipse.ui.EclipseUiUtils; +import org.argeo.eclipse.ui.dialogs.LightweightDialog; import org.argeo.entity.EntityNames; import org.argeo.entity.EntityType; +import org.argeo.jcr.Jcr; import org.argeo.jcr.JcrException; import org.argeo.jcr.JcrUtils; import org.eclipse.jface.window.Window; import org.eclipse.jface.wizard.Wizard; import org.eclipse.swt.SWT; +import org.eclipse.swt.custom.ScrolledComposite; +import org.eclipse.swt.events.MouseEvent; +import org.eclipse.swt.events.MouseListener; import org.eclipse.swt.graphics.ImageData; +import org.eclipse.swt.graphics.Point; import org.eclipse.swt.layout.GridData; import org.eclipse.swt.layout.GridLayout; import org.eclipse.swt.widgets.Button; import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Control; import org.eclipse.swt.widgets.Label; import org.eclipse.swt.widgets.Shell; import org.eclipse.swt.widgets.Text; @@ -56,13 +66,17 @@ public class SuiteUiUtils { public static Label addFormLabel(Composite parent, String label) { Label lbl = new Label(parent, SWT.WRAP); lbl.setText(label); - lbl.setLayoutData(new GridData(SWT.LEAD, SWT.CENTER, true, true)); + // lbl.setLayoutData(new GridData(SWT.LEAD, SWT.CENTER, true, true)); CmsUiUtils.style(lbl, SuiteStyle.simpleLabel); return lbl; } public static Text addFormTextField(Composite parent, String text, String message) { - Text txt = new Text(parent, SWT.WRAP); + return addFormTextField(parent, text, message, SWT.NONE); + } + + public static Text addFormTextField(Composite parent, String text, String message, int style) { + Text txt = new Text(parent, style); if (text != null) txt.setText(text); if (message != null) @@ -89,10 +103,33 @@ public class SuiteUiUtils { public static Text addFormLine(Composite parent, String label, String text) { Composite lineComposite = new Composite(parent, SWT.NONE); lineComposite.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false)); - lineComposite.setLayout(new GridLayout(2, true)); + lineComposite.setLayout(new GridLayout(2, false)); CmsUiUtils.style(lineComposite, SuiteStyle.formLine); addFormLabel(lineComposite, label); Text txt = addFormTextField(lineComposite, text, null); + txt.setEditable(false); + txt.setLayoutData(CmsUiUtils.fillWidth()); + return txt; + } + + public static Text addFormLine(Composite parent, String label, Node node, String property, + CmsEditable cmsEditable) { + Composite lineComposite = new Composite(parent, SWT.NONE); + lineComposite.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false)); + lineComposite.setLayout(new GridLayout(2, false)); + CmsUiUtils.style(lineComposite, SuiteStyle.formLine); + addFormLabel(lineComposite, label); + String text = Jcr.get(node, property); +// int style = cmsEditable.isEditing() ? SWT.WRAP : SWT.WRAP; + Text txt = addFormTextField(lineComposite, text, null, SWT.WRAP); + if (cmsEditable != null && cmsEditable.isEditing()) { + txt.addModifyListener((e) -> { + Jcr.set(node, property, txt.getText()); + Jcr.save(node); + }); + } else { + txt.setEditable(false); + } txt.setLayoutData(CmsUiUtils.fillWidth()); return txt; } @@ -100,7 +137,7 @@ public class SuiteUiUtils { public static Text addFormInput(Composite parent, String label, String placeholder) { Composite lineComposite = new Composite(parent, SWT.NONE); lineComposite.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false)); - lineComposite.setLayout(new GridLayout(2, true)); + lineComposite.setLayout(new GridLayout(2, false)); CmsUiUtils.style(lineComposite, SuiteStyle.formLine); addFormLabel(lineComposite, label); Text txt = addFormInputField(lineComposite, placeholder); @@ -129,15 +166,45 @@ public class SuiteUiUtils { /** creates a single vertical-block composite for key:value display */ public static Text addFormColumn(Composite parent, String label, String text) { - Composite columnComposite = new Composite(parent, SWT.NONE); - columnComposite.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false)); - columnComposite.setLayout(new GridLayout(1, false)); - addFormLabel(columnComposite, label); - Text txt = addFormTextField(columnComposite, text, null); +// Composite columnComposite = new Composite(parent, SWT.NONE); +// columnComposite.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false)); +// columnComposite.setLayout(new GridLayout(1, false)); + addFormLabel(parent, label); + Text txt = addFormTextField(parent, text, null); + txt.setEditable(false); + txt.setLayoutData(CmsUiUtils.fillWidth()); + return txt; + } + + public static Text addFormColumn(Composite parent, String label, Node node, String property, + CmsEditable cmsEditable) { +// Composite columnComposite = new Composite(parent, SWT.NONE); +// columnComposite.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false)); +// columnComposite.setLayout(new GridLayout(1, false)); + addFormLabel(parent, label); + String text = Jcr.get(node, property); +// int style = cmsEditable.isEditing() ? SWT.WRAP : SWT.WRAP; + Text txt = addFormTextField(parent, text, null, SWT.WRAP); + if (cmsEditable != null && cmsEditable.isEditing()) { + txt.addModifyListener((e) -> { + Jcr.set(node, property, txt.getText()); + Jcr.save(node); + }); + } else { + txt.setEditable(false); + } txt.setLayoutData(CmsUiUtils.fillWidth()); return txt; } + public static Label createBoldLabel(Composite parent, Localized localized) { + Label label = new Label(parent, SWT.LEAD); + label.setText(localized.lead()); + label.setFont(EclipseUiUtils.getBoldFont(parent)); + label.setLayoutData(new GridData(SWT.LEAD, SWT.CENTER, false, false)); + return label; + } + public static Label addFormPicture(Composite parent, String label, Node fileNode) throws RepositoryException { Composite lineComposite = new Composite(parent, SWT.NONE); lineComposite.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false)); @@ -179,6 +246,52 @@ public class SuiteUiUtils { img.setText(CmsUiUtils.img(fileNode, width.toString(), height.toString())); if (parent.getLayout() instanceof GridLayout) img.setLayoutData(new GridData(SWT.CENTER, SWT.CENTER, false, false)); + img.addMouseListener(new MouseListener() { + + @Override + public void mouseUp(MouseEvent e) { + } + + @Override + public void mouseDown(MouseEvent e) { + } + + @Override + public void mouseDoubleClick(MouseEvent e) { + LightweightDialog dialog = new LightweightDialog(img.getShell()) { + + @Override + protected Control createDialogArea(Composite parent) { + parent.setLayout(new GridLayout()); + ScrolledComposite scroll = new ScrolledComposite(parent, SWT.H_SCROLL | SWT.V_SCROLL); + scroll.setLayoutData(CmsUiUtils.fillAll()); + scroll.setLayout(CmsUiUtils.noSpaceGridLayout()); + scroll.setExpandHorizontal(true); + scroll.setExpandVertical(true); + //scroll.setAlwaysShowScrollBars(true); + + Composite c = new Composite(scroll, SWT.NONE); + scroll.setContent(c); + c.setLayout(new GridLayout()); + c.setLayoutData(CmsUiUtils.fillAll()); + Label bigImg = new Label(c, SWT.NONE); + CmsUiUtils.markup(bigImg); + bigImg.setText(CmsUiUtils.img(fileNode, Jcr.get(content, EntityNames.SVG_WIDTH), + Jcr.get(content, EntityNames.SVG_HEIGHT))); + bigImg.setLayoutData(new GridData(SWT.CENTER, SWT.CENTER, true, true)); + return bigImg; + } + + @Override + protected Point getInitialSize() { + Point shellSize = img.getShell().getSize(); + return new Point(shellSize.x - 100, shellSize.y - 100); + } + + }; + dialog.open(); + } + }); return img; }