Skip to content

Commit 368b5fb

Browse files
committed
fixed format converter lookup
1 parent ab5d5cc commit 368b5fb

File tree

6 files changed

+270
-4
lines changed

6 files changed

+270
-4
lines changed

logicaldoc-core/src/main/java/com/logicaldoc/core/conversion/FormatConverterManager.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -455,8 +455,9 @@ public FormatConverter getConverter(String inFileName, String outFileName) {
455455
// Check if a special binding is configured and points to an enabled
456456
// converter
457457
String currentConverter = config.getProperty("converter." + inOutkey);
458+
458459
if (StringUtils.isNotEmpty(currentConverter) && formatConverters != null)
459-
formatConverters.stream()
460+
converter = formatConverters.stream()
460461
.filter(conv -> conv.getClass().getName().equals(currentConverter) && conv.isEnabled()).findFirst()
461462
.orElse(null);
462463

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
package com.logicaldoc.gui.frontend.client.ai.model;
2+
3+
import com.smartgwt.client.data.DataSource;
4+
import com.smartgwt.client.data.fields.DataSourceTextField;
5+
6+
/**
7+
* Datasource to handle type of samplers drop-down lists. It is based on Xml
8+
* parsing
9+
*
10+
* @author Marco Meschieri - LogicalDOC
11+
* @since 9.2
12+
*/
13+
public class ModelDS extends DataSource {
14+
15+
public ModelDS() {
16+
init("data/ai.xml?object=model");
17+
}
18+
19+
private void init(String url) {
20+
setRecordXPath("/list/model");
21+
22+
DataSourceTextField id = new DataSourceTextField("id");
23+
id.setPrimaryKey(true);
24+
id.setHidden(true);
25+
id.setRequired(true);
26+
27+
DataSourceTextField name = new DataSourceTextField("name");
28+
DataSourceTextField label = new DataSourceTextField("label");
29+
DataSourceTextField description = new DataSourceTextField("description");
30+
DataSourceTextField typeField = new DataSourceTextField("type");
31+
32+
setFields(id, name, label, description, typeField);
33+
setClientOnly(true);
34+
35+
setDataURL("data/ai.xml?object=sampler");
36+
}
37+
}
Lines changed: 226 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,226 @@
1+
package com.logicaldoc.gui.frontend.client.ai.model;
2+
3+
import java.util.ArrayList;
4+
import java.util.List;
5+
6+
import com.logicaldoc.gui.common.client.DefaultAsyncCallback;
7+
import com.logicaldoc.gui.common.client.grid.IdListGridField;
8+
import com.logicaldoc.gui.common.client.grid.RefreshableListGrid;
9+
import com.logicaldoc.gui.common.client.i18n.I18N;
10+
import com.logicaldoc.gui.common.client.util.LD;
11+
import com.logicaldoc.gui.common.client.widgets.HTMLPanel;
12+
import com.logicaldoc.gui.common.client.widgets.InfoPanel;
13+
import com.logicaldoc.gui.frontend.client.ai.AIService;
14+
import com.smartgwt.client.data.AdvancedCriteria;
15+
import com.smartgwt.client.data.Record;
16+
import com.smartgwt.client.types.Alignment;
17+
import com.smartgwt.client.types.AutoFitWidthApproach;
18+
import com.smartgwt.client.types.OperatorId;
19+
import com.smartgwt.client.types.SelectionStyle;
20+
import com.smartgwt.client.widgets.Canvas;
21+
import com.smartgwt.client.widgets.grid.ListGrid;
22+
import com.smartgwt.client.widgets.grid.ListGridField;
23+
import com.smartgwt.client.widgets.grid.ListGridRecord;
24+
import com.smartgwt.client.widgets.layout.Layout;
25+
import com.smartgwt.client.widgets.layout.VLayout;
26+
import com.smartgwt.client.widgets.menu.Menu;
27+
import com.smartgwt.client.widgets.menu.MenuItem;
28+
import com.smartgwt.client.widgets.toolbar.ToolStrip;
29+
import com.smartgwt.client.widgets.toolbar.ToolStripButton;
30+
31+
/**
32+
* Panel showing the list of models
33+
*
34+
* @author Marco Meschieri - LogicalDOC
35+
* @since 9.2
36+
*/
37+
public class ModelsPanel extends VLayout {
38+
39+
private static final String LABEL = "label";
40+
41+
private static final String DESCRIPTION = "description";
42+
43+
protected Layout detailsContainer;
44+
45+
protected RefreshableListGrid list;
46+
47+
protected Canvas details = SELECT_SAMPLER;
48+
49+
static final Canvas SELECT_SAMPLER = new HTMLPanel(" " + I18N.message("selecttasampler"));
50+
51+
public ModelsPanel() {
52+
setWidth100();
53+
}
54+
55+
@Override
56+
public void onDraw() {
57+
InfoPanel infoPanel = new InfoPanel("");
58+
59+
final Layout listing = new VLayout();
60+
detailsContainer = new VLayout();
61+
details = SELECT_SAMPLER;
62+
63+
// Initialize the listing panel
64+
listing.setAlign(Alignment.CENTER);
65+
listing.setHeight("55%");
66+
listing.setShowResizeBar(true);
67+
68+
ListGridField id = new IdListGridField();
69+
70+
ListGridField name = new ListGridField("name", I18N.message("name"));
71+
name.setCanFilter(true);
72+
name.setCanSort(true);
73+
name.setAutoFit(AutoFitWidthApproach.BOTH);
74+
75+
ListGridField label = new ListGridField(LABEL, I18N.message(LABEL), 200);
76+
label.setCanFilter(true);
77+
label.setCanSort(true);
78+
79+
ListGridField description = new ListGridField(DESCRIPTION, I18N.message(DESCRIPTION), 300);
80+
description.setCanFilter(true);
81+
description.setCanSort(false);
82+
83+
ListGridField samplerType = new ListGridField("type", I18N.message("type"));
84+
samplerType.setAutoFit(AutoFitWidthApproach.BOTH);
85+
86+
list = new RefreshableListGrid();
87+
list.setEmptyMessage(I18N.message("notitemstoshow"));
88+
list.setShowAllRecords(true);
89+
list.setAutoFetchData(true);
90+
list.setWidth100();
91+
list.setHeight100();
92+
list.setFields(id, name, label, samplerType, description);
93+
list.setSelectionType(SelectionStyle.SINGLE);
94+
list.setShowRecordComponents(true);
95+
list.setShowRecordComponentsByCell(true);
96+
list.setCanFreezeFields(true);
97+
list.setFilterOnKeypress(true);
98+
list.setDataSource(new ModelDS());
99+
100+
listing.addMember(infoPanel);
101+
listing.addMember(list);
102+
103+
ToolStrip toolStrip = new ToolStrip();
104+
toolStrip.setHeight(20);
105+
toolStrip.setWidth100();
106+
toolStrip.addSpacer(2);
107+
108+
ToolStripButton refresh = new ToolStripButton();
109+
refresh.setTitle(I18N.message("refresh"));
110+
refresh.addClickHandler(event -> {
111+
list.refresh(new ModelDS());
112+
detailsContainer.removeMembers(detailsContainer.getMembers());
113+
details = SELECT_SAMPLER;
114+
detailsContainer.setMembers(details);
115+
});
116+
toolStrip.addButton(refresh);
117+
118+
ToolStripButton add = new ToolStripButton();
119+
add.setTitle(I18N.message("addmodel"));
120+
toolStrip.addButton(add);
121+
add.addClickHandler(event -> onAddSampler());
122+
123+
toolStrip.addFill();
124+
125+
list.addCellContextClickHandler(event -> {
126+
showContextMenu();
127+
event.cancel();
128+
});
129+
130+
list.addSelectionChangedHandler(event -> {
131+
Record rec = list.getSelectedRecord();
132+
if (rec != null)
133+
AIService.Instance.get().getModel(rec.getAttributeAsLong("id"), new DefaultAsyncCallback<>() {
134+
@Override
135+
public void onSuccess(GUIModel model) {
136+
showModelDetails(model);
137+
}
138+
});
139+
});
140+
141+
list.addDataArrivedHandler(event -> infoPanel
142+
.setMessage(I18N.message("showattributesets", Integer.toString(list.getTotalRows()))));
143+
144+
detailsContainer.setAlign(Alignment.CENTER);
145+
detailsContainer.addMember(details);
146+
147+
setMembers(toolStrip, listing, detailsContainer);
148+
}
149+
150+
private void showContextMenu() {
151+
Menu contextMenu = new Menu();
152+
153+
final ListGridRecord[] selection = list.getSelectedRecords();
154+
List<Long> ids = new ArrayList<>();
155+
for (ListGridRecord rec : selection)
156+
ids.add(rec.getAttributeAsLong("id"));
157+
158+
MenuItem delete = new MenuItem();
159+
delete.setTitle(I18N.message("ddelete"));
160+
delete.addClickHandler(event -> LD.ask(I18N.message("question"), I18N.message("confirmdelete"), confirm -> {
161+
if (Boolean.TRUE.equals(confirm)) {
162+
AIService.Instance.get().deleteModels(ids, new DefaultAsyncCallback<>() {
163+
@Override
164+
public void onSuccess(Void result) {
165+
list.removeSelectedData();
166+
list.deselectAllRecords();
167+
showModelDetails(null);
168+
}
169+
});
170+
}
171+
}));
172+
173+
contextMenu.setItems(delete);
174+
contextMenu.showContextMenu();
175+
}
176+
177+
protected void showModelDetails(GUIModel model) {
178+
// if (!(details instanceof SamplerDetailsPanel)) {
179+
// detailsContainer.removeMember(details);
180+
// details = new SamplerDetailsPanel(this);
181+
// detailsContainer.addMember(details);
182+
// }
183+
// ((SamplerDetailsPanel) details).setSampler(sampler);
184+
}
185+
186+
public ListGrid getList() {
187+
return list;
188+
}
189+
190+
/**
191+
* Updates the selected rec with new data
192+
*
193+
* @param model the model to take data from
194+
*/
195+
public void updateRecord(GUIModel model) {
196+
Record rec = list.find(new AdvancedCriteria("id", OperatorId.EQUALS, model.getId()));
197+
if (rec == null) {
198+
rec = new ListGridRecord();
199+
// Append a new rec
200+
rec.setAttribute("id", model.getId());
201+
list.addData(rec);
202+
list.selectRecord(rec);
203+
}
204+
205+
rec.setAttribute("name", model.getName());
206+
rec.setAttribute(LABEL, model.getLabel() != null ? model.getLabel() : model.getName());
207+
rec.setAttribute(DESCRIPTION, model.getDescription());
208+
list.refreshRow(list.getRecordIndex(rec));
209+
210+
}
211+
212+
protected void onAddSampler() {
213+
list.deselectAllRecords();
214+
showModelDetails(new GUIModel());
215+
}
216+
217+
@Override
218+
public boolean equals(Object other) {
219+
return super.equals(other);
220+
}
221+
222+
@Override
223+
public int hashCode() {
224+
return super.hashCode();
225+
}
226+
}

logicaldoc-gui/src/main/java/com/logicaldoc/gui/frontend/client/ai/sampler/SamplerDS.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,10 @@ public SamplerDS(String type) {
2121

2222
DataSourceTextField name = new DataSourceTextField("name");
2323
DataSourceTextField label = new DataSourceTextField("label");
24+
DataSourceTextField description = new DataSourceTextField("description");
2425
DataSourceTextField typeField = new DataSourceTextField("type");
2526

26-
setFields(id, name, label, typeField);
27+
setFields(id, name, label, description, typeField);
2728
setClientOnly(true);
2829

2930
String url = "data/ai.xml?object=sampler";

logicaldoc-gui/src/main/java/com/logicaldoc/gui/frontend/client/ai/sampler/SamplersPanel.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ public ListGrid getList() {
190190
/**
191191
* Updates the selected rec with new data
192192
*
193-
* @param sampler the sampler to update
193+
* @param sampler the sampler to take data from
194194
*/
195195
public void updateRecord(GUISampler sampler) {
196196
Record rec = list.find(new AdvancedCriteria("id", OperatorId.EQUALS, sampler.getId()));

logicaldoc-i18n/src/main/resources/i18n/messages.properties

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2655,4 +2655,5 @@ chain = Chain
26552655
sampler = Sampler
26562656
quote = Quote
26572657
delimiter = Delimiter
2658-
categoryattribute = Category attribute
2658+
categoryattribute = Category attribute
2659+
addmodel = Add model

0 commit comments

Comments
 (0)