CCM NG/ccm-cms: Moving attached images works now

git-svn-id: https://svn.libreccm.org/ccm/ccm_ng@4901 8810af33-2d31-482b-a856-94f89814c4df
ccm-docs
jensp 2017-08-09 15:19:04 +00:00
parent ab697c06ac
commit 075e94e0ee
4 changed files with 23 additions and 12 deletions

View File

@ -33,18 +33,18 @@ import org.librecms.contentsection.ItemAttachmentManager;
*
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
*/
public class ItemAttachmentSelectionModel implements SingleSelectionModel<Long>{
public class ItemAttachmentSelectionModel implements SingleSelectionModel<Long> {
private final SingleSelectionModel<Long> model;
public ItemAttachmentSelectionModel(final LongParameter parameter) {
this.model = new ParameterSingleSelectionModel<>(parameter);
}
public ItemAttachmentSelectionModel(final String parameterName) {
this(new LongParameter(parameterName));
}
@Override
public boolean isSelected(final PageState state) {
return model.isSelected(state);
@ -71,12 +71,16 @@ public class ItemAttachmentSelectionModel implements SingleSelectionModel<Long>{
public ItemAttachment<?> getSelectedAttachment(final PageState state) {
final Long key = getSelectedKey(state);
final ItemAttachmentManager manager = CdiUtil
.createCdiUtil()
.findBean(ItemAttachmentManager.class);
return manager.findById(key).get();
if (key == null) {
return null;
} else {
final ItemAttachmentManager manager = CdiUtil
.createCdiUtil()
.findBean(ItemAttachmentManager.class);
return manager.findById(key).get();
}
}
@Override
public void clearSelection(final PageState state) {
model.clearSelection(state);
@ -96,5 +100,5 @@ public class ItemAttachmentSelectionModel implements SingleSelectionModel<Long>{
public ParameterModel getStateParameter() {
return model.getStateParameter();
}
}

View File

@ -133,11 +133,12 @@ class AssignedImagesTable extends Table {
switch (column.getModelIndex()) {
case COL_MOVE:
if (moveAttachmentModel
.getSelectedAttachment(state) == null) {
.getSelectedKey(state) == null) {
moveAttachmentModel
.setSelectedKey(state,
Long.parseLong(column.getKey()));
Long.parseLong((String) event
.getRowKey()));
} else {
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
final ImageStepController controller = cdiUtil
@ -151,6 +152,7 @@ class AssignedImagesTable extends Table {
.parseLong((String) event.getRowKey());
controller.moveAfter(selectedAttachment, destId);
moveAttachmentModel.setSelectedKey(state, null);
}
break;
case COL_REMOVE:

View File

@ -146,6 +146,8 @@ public class ImageStep extends ResettableContainer {
.findBean(ImageStepController.class);
controller.moveToFirst(toMove);
moveAttachmentModel.setSelectedKey(state, null);
});
assignedImagesTable = new AssignedImagesTable(itemSelectionModel,
@ -197,6 +199,8 @@ public class ImageStep extends ResettableContainer {
page.setVisibleDefault(addImageHeader, false);
page.setVisibleDefault(cancelAddImage, false);
page.setVisibleDefault(availableImages, false);
page.addComponentStateParam(assignedImagesTable, moveAttachmentParam);
}
protected void showAssignedImages(final PageState state) {

View File

@ -53,6 +53,7 @@ public class ItemAttachmentManager {
@Inject
private AssetManager assetManager;
@Transactional(Transactional.TxType.REQUIRED)
public Optional<ItemAttachment<?>> findById(final long attachmentId) {
final TypedQuery<ItemAttachment> query = entityManager