import javax.jcr.Item;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
import org.argeo.cms.ui.forms.FormStyle;
import org.argeo.cms.ui.util.CmsUiUtils;
import org.argeo.cms.ui.viewers.EditablePart;
/** {@link EditablePart} for multiple terms. */
public class MultiTermsPart extends AbstractTermsPart {
private static final long serialVersionUID = -4961135649177920808L;
+ private final static Log log = LogFactory.getLog(MultiTermsPart.class);
public MultiTermsPart(Composite parent, int style, Item item, TermsManager termsManager, String typology) {
super(parent, style, item, termsManager, typology);
@Override
protected Control createControl(Composite box, String style) {
Composite placeholder = new Composite(box, SWT.NONE);
- RowLayout rl = new RowLayout(SWT.HORIZONTAL | SWT.WRAP);
+
+ boolean vertical = SWT.VERTICAL == (getStyle() & SWT.VERTICAL);
+ RowLayout rl = new RowLayout(vertical ? SWT.VERTICAL : SWT.HORIZONTAL);
+ rl = CmsUiUtils.noMarginsRowLayout(rl);
+// rl.wrap = true;
+// rl.justify = true;
placeholder.setLayout(rl);
List<Term> currentValue = getValue();
- if (currentValue != null && !currentValue.isEmpty())
+ if (currentValue != null && !currentValue.isEmpty()) {
for (Term value : currentValue) {
Composite block = new Composite(placeholder, SWT.NONE);
block.setLayout(CmsUiUtils.noSpaceGridLayout(3));
- Label lbl = new Label(block, SWT.SINGLE);
+ Label lbl = new Label(block, SWT.NONE);
String display = getTermLabel(value);
lbl.setText(display);
CmsUiUtils.style(lbl, style == null ? FormStyle.propertyText.style() : style);
- if (editable)
+ processTermListLabel(value, lbl);
+ if (isEditable())
lbl.addMouseListener((MouseDoubleClick) (e) -> {
startEditing();
});
}
}
- else {// empty
- if (editable && !isEditing()) {
+ } else {// empty
+ if (isEditable() && !isEditing()) {
ToolBar toolBar = new ToolBar(placeholder, SWT.HORIZONTAL);
ToolItem addItem = new ToolItem(toolBar, SWT.FLAT);
styleAdd(addItem);
List<String> curr = Jcr.getMultiple(getNode(), property);
List<Term> res = new ArrayList<>();
if (curr != null)
- for (String str : curr) {
+ terms: for (String str : curr) {
Term term = termsManager.getTerm(str);
+ if (term == null) {
+ log.warn("Ignoring term " + str + " for " + getNode() + ", as it was not found.");
+ continue terms;
+ }
res.add(term);
}
return res;