Skip to content

Commit ac4f34c

Browse files
committed
Select the cloned template right after creation
1 parent 5e6e87b commit ac4f34c

File tree

3 files changed

+60
-15
lines changed

3 files changed

+60
-15
lines changed

logicaldoc-gui/src/main/java/com/logicaldoc/gui/common/client/util/GridUtil.java

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,47 @@ public void run() {
6060
timer.schedule(100);
6161
}
6262
}
63+
64+
/**
65+
* Scrolls the grid all down
66+
*
67+
* @param listGrid the grid to process
68+
* @param listener optional listener inoked at the end of the scroll
69+
*/
70+
public static void scrollDownGrid(ListGrid listGrid, EndScrollListener listener) {
71+
if (listGrid.getTotalRows() > 0) {
72+
LD.contactingServer();
73+
74+
listGrid.scrollToRow(0);
75+
listGrid.draw();
76+
77+
if (listGrid.getVisibleRows()[0] == -1) {
78+
LD.clearPrompt();
79+
return;
80+
}
81+
82+
/*
83+
* With a timer we scroll the grid in order to fetch all the data
84+
*/
85+
final Timer timer = new Timer() {
86+
public void run() {
87+
Integer[] visibleRows = listGrid.getVisibleRows();
88+
if (visibleRows[1] >= listGrid.getTotalRows() - 1) {
89+
try {
90+
if (listener != null)
91+
listener.endScroll(listGrid);
92+
} finally {
93+
LD.clearPrompt();
94+
}
95+
} else if (visibleRows[0] != -1 && visibleRows[1] < listGrid.getTotalRows() - 1) {
96+
listGrid.scrollToRow(visibleRows[1] + 1);
97+
schedule(100);
98+
}
99+
}
100+
};
101+
timer.schedule(100);
102+
}
103+
}
63104

64105
/**
65106
* Prints a grid

logicaldoc-gui/src/main/java/com/logicaldoc/gui/frontend/client/document/DocumentToolbar.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -481,8 +481,7 @@ private void addScan() {
481481

482482
private void addUpload() {
483483
add.addClickHandler(event -> {
484-
DocumentsUploader uploader = new DocumentsUploader();
485-
uploader.show();
484+
new DocumentsUploader().show();
486485
event.cancel();
487486
});
488487
addButton(add);

logicaldoc-gui/src/main/java/com/logicaldoc/gui/frontend/client/metadata/template/TemplatesPanel.java

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
import com.smartgwt.client.widgets.grid.ListGrid;
2020
import com.smartgwt.client.widgets.grid.ListGridField;
2121
import com.smartgwt.client.widgets.grid.ListGridRecord;
22-
import com.smartgwt.client.widgets.grid.events.DataArrivedEvent;
2322
import com.smartgwt.client.widgets.layout.Layout;
2423
import com.smartgwt.client.widgets.layout.VLayout;
2524
import com.smartgwt.client.widgets.menu.Menu;
@@ -46,6 +45,8 @@ public class TemplatesPanel extends VLayout {
4645

4746
static final Canvas SELECT_TEMPLATE = new HTMLPanel("&nbsp;" + I18N.message("selecttemplate"));
4847

48+
protected Long templateIdToSelect;
49+
4950
public TemplatesPanel() {
5051
setWidth100();
5152
}
@@ -152,8 +153,18 @@ public void onSuccess(GUITemplate template) {
152153
});
153154
});
154155

155-
list.addDataArrivedHandler((DataArrivedEvent event) -> infoPanel
156-
.setMessage(I18N.message("showtemplates", Integer.toString(list.getTotalRows()))));
156+
list.addDataArrivedHandler(event -> {
157+
infoPanel.setMessage(I18N.message("showtemplates", Integer.toString(list.getTotalRows())));
158+
if (templateIdToSelect != null)
159+
for (ListGridRecord rec : list.getRecords()) {
160+
if (templateIdToSelect.longValue() == rec.getAttributeAsDouble("id").longValue()) {
161+
list.scrollToRow(list.getRowNum(rec));
162+
list.selectRecord(rec);
163+
break;
164+
}
165+
}
166+
templateIdToSelect = null;
167+
});
157168

158169
detailsContainer.setAlign(Alignment.CENTER);
159170
detailsContainer.addMember(details);
@@ -191,6 +202,7 @@ public void onSuccess(Void result) {
191202
clone.setTitle(I18N.message("clone"));
192203
clone.addClickHandler(event -> TemplateService.Instance.get().clone(selectedTemplateId,
193204
selectedRecord.getAttribute("name") + "-Clone", new AsyncCallback<GUITemplate>() {
205+
194206
@Override
195207
public void onFailure(Throwable caught) {
196208
GuiLog.serverError(caught);
@@ -199,18 +211,11 @@ public void onFailure(Throwable caught) {
199211
@Override
200212
public void onSuccess(GUITemplate templateClone) {
201213
list.deselectAllRecords();
202-
ListGridRecord newRecord = new ListGridRecord();
203-
newRecord.setAttribute("id", templateClone.getId());
204-
newRecord.setAttribute("readonly", "" + templateClone.isReadonly());
205-
newRecord.setAttribute("name", templateClone.getName());
206-
newRecord.setAttribute(LABEL,
207-
templateClone.getLabel() != null ? templateClone.getLabel() : templateClone.getName());
208-
newRecord.setAttribute(DESCRIPTION, templateClone.getDescription());
209-
list.addData(newRecord);
210-
list.selectRecord(newRecord);
211-
list.scrollToRow(list.getRowNum(newRecord));
214+
list.refresh(new TemplatesDS(false, null, GUITemplate.TYPE_DEFAULT));
215+
templateIdToSelect = templateClone.getId();
212216
showTemplateDetails(templateClone);
213217
}
218+
214219
}));
215220

216221
contextMenu.setItems(clone, delete);

0 commit comments

Comments
 (0)