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
jensp 2017-08-09 15:19:04 +00:00
parent 5ac7e51438
commit b1fba0f19e
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> * @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; private final SingleSelectionModel<Long> model;
public ItemAttachmentSelectionModel(final LongParameter parameter) { public ItemAttachmentSelectionModel(final LongParameter parameter) {
this.model = new ParameterSingleSelectionModel<>(parameter); this.model = new ParameterSingleSelectionModel<>(parameter);
} }
public ItemAttachmentSelectionModel(final String parameterName) { public ItemAttachmentSelectionModel(final String parameterName) {
this(new LongParameter(parameterName)); this(new LongParameter(parameterName));
} }
@Override @Override
public boolean isSelected(final PageState state) { public boolean isSelected(final PageState state) {
return model.isSelected(state); return model.isSelected(state);
@ -71,12 +71,16 @@ public class ItemAttachmentSelectionModel implements SingleSelectionModel<Long>{
public ItemAttachment<?> getSelectedAttachment(final PageState state) { public ItemAttachment<?> getSelectedAttachment(final PageState state) {
final Long key = getSelectedKey(state); final Long key = getSelectedKey(state);
final ItemAttachmentManager manager = CdiUtil if (key == null) {
.createCdiUtil() return null;
.findBean(ItemAttachmentManager.class); } else {
return manager.findById(key).get(); final ItemAttachmentManager manager = CdiUtil
.createCdiUtil()
.findBean(ItemAttachmentManager.class);
return manager.findById(key).get();
}
} }
@Override @Override
public void clearSelection(final PageState state) { public void clearSelection(final PageState state) {
model.clearSelection(state); model.clearSelection(state);
@ -96,5 +100,5 @@ public class ItemAttachmentSelectionModel implements SingleSelectionModel<Long>{
public ParameterModel getStateParameter() { public ParameterModel getStateParameter() {
return model.getStateParameter(); return model.getStateParameter();
} }
} }

View File

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

View File

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

View File

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