X-Git-Url: https://git.argeo.org/?p=gpl%2Fargeo-suite.git;a=blobdiff_plain;f=org.argeo.entity.ui%2Fsrc%2Forg%2Fargeo%2Fentity%2Fui%2Fforms%2FAbstractTermsPart.java;fp=org.argeo.entity.ui%2Fsrc%2Forg%2Fargeo%2Fentity%2Fui%2Fforms%2FAbstractTermsPart.java;h=a7f240fe238baf37732611590f27a42f0c3f40a5;hp=0000000000000000000000000000000000000000;hb=5401f7a23b5251bb37514f5495b75f79320bedc0;hpb=62fe0d412eea802492a6d2a3fee8384ec1d685ae diff --git a/org.argeo.entity.ui/src/org/argeo/entity/ui/forms/AbstractTermsPart.java b/org.argeo.entity.ui/src/org/argeo/entity/ui/forms/AbstractTermsPart.java new file mode 100644 index 0000000..a7f240f --- /dev/null +++ b/org.argeo.entity.ui/src/org/argeo/entity/ui/forms/AbstractTermsPart.java @@ -0,0 +1,109 @@ +package org.argeo.entity.ui.forms; + +import javax.jcr.Item; + +import org.argeo.cms.ui.CmsTheme; +import org.argeo.cms.ui.util.CmsIcon; +import org.argeo.cms.ui.viewers.EditablePart; +import org.argeo.cms.ui.widgets.ContextOverlay; +import org.argeo.cms.ui.widgets.StyledControl; +import org.argeo.entity.TermsManager; +import org.eclipse.swt.SWT; +import org.eclipse.swt.graphics.Color; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Label; +import org.eclipse.swt.widgets.Text; +import org.eclipse.swt.widgets.ToolItem; + +/** Common logic between single and mutliple terms editable part. */ +public abstract class AbstractTermsPart extends StyledControl implements EditablePart { + private static final long serialVersionUID = -5497097995341927710L; + protected final TermsManager termsManager; + protected final String typology; + + protected final boolean editable; + + private CmsIcon deleteIcon; + private CmsIcon addIcon; + private CmsIcon cancelIcon; + + private Color highlightColor; + private Composite highlight; + + protected final CmsTheme theme; + + public AbstractTermsPart(Composite parent, int style, Item item, TermsManager termsManager, + String typology) { + super(parent, style, item); + this.termsManager = termsManager; + this.typology = typology; + this.theme = CmsTheme.getCmsTheme(parent); + editable = !(SWT.READ_ONLY == (style & SWT.READ_ONLY)); + highlightColor = parent.getDisplay().getSystemColor(SWT.COLOR_GRAY); + } + + protected void createHighlight(Composite block) { + highlight = new Composite(block, SWT.NONE); + highlight.setBackground(highlightColor); + GridData highlightGd = new GridData(SWT.FILL, SWT.FILL, false, false); + highlightGd.widthHint = 5; + highlightGd.heightHint = 3; + highlight.setLayoutData(highlightGd); + + } + + protected String getTermLabel(String name) { + return name; + } + + protected abstract void refresh(ContextOverlay contextArea, String filter, Text txt); + + protected boolean isTermSelectable(String term) { + return true; + } + + protected void processTermListLabel(String term, Label label) { + + } + + // + // STYLING + // + public void setDeleteIcon(CmsIcon deleteIcon) { + this.deleteIcon = deleteIcon; + } + + public void setAddIcon(CmsIcon addIcon) { + this.addIcon = addIcon; + } + + public void setCancelIcon(CmsIcon cancelIcon) { + this.cancelIcon = cancelIcon; + } + + protected TermsManager getTermsManager() { + return termsManager; + } + + protected void styleDelete(ToolItem deleteItem) { + if (deleteIcon != null) + deleteItem.setImage(deleteIcon.getSmallIcon(theme)); + else + deleteItem.setText("-"); + } + + protected void styleCancel(ToolItem cancelItem) { + if (cancelIcon != null) + cancelItem.setImage(cancelIcon.getSmallIcon(theme)); + else + cancelItem.setText("X"); + } + + protected void styleAdd(ToolItem addItem) { + if (addIcon != null) + addItem.setImage(addIcon.getSmallIcon(theme)); + else + addItem.setText("+"); + } +}