package com.foc.web.modules.photoAlbum;

import com.foc.OptionDialog;
import com.foc.business.photoAlbum.PhotoAlbumAppGroup;
import com.foc.desc.FocObject;
import com.foc.vaadin.FocWebApplication;
import com.foc.vaadin.gui.FVIconFactory;
import com.foc.vaadin.gui.FocXMLGuiComponentStatic;
import com.foc.vaadin.gui.layouts.validationLayout.FVValidationLayout;
import com.foc.vaadin.gui.xmlForm.FocXMLLayout;
import com.vaadin.event.MouseEvents;
import com.vaadin.ui.Alignment;
import com.vaadin.ui.Embedded;

@SuppressWarnings("serial")
public class PhotoAlbum_Reduced_Form extends PhotoAlbum_Form {

	private PhotoAlbum_Thumb_Table thumbForm = null;

	@Override
	public void dispose() {
		super.dispose();
		thumbForm = null;
	}
	
	public void deleteButtonClickListener() {
  	OptionDialog dialog = new OptionDialog("Confirm Deletion", "Are you sure you want to delete this item", getFocData()) {
			
			@Override
			public boolean executeOption(String optionName) {
				if(optionName.equals("DELETE")){
	    		FocObject focObject = getFocObject();
	    		if(focObject != null){
	    			focObject.delete();
	    			FocXMLLayout previousLayout = getThumbForm();
	    			getValidationLayout().goBack();
						if(previousLayout != null) {
							previousLayout.refresh();
						}
	    		}
				}else if(optionName.equals("CANCEL")){
					
				}
				return false;
			}
		};
  	dialog.addOption("DELETE", "Delete");
  	dialog.addOption("CANCEL", "Cancel");
  	dialog.setWidth("300px");
  	dialog.setHeight("200px");
  	dialog.popup();
	}
	
	@Override
	public void showValidationLayout(boolean showBackButton, int position) {
		super.showValidationLayout(showBackButton, position);
		
		FVValidationLayout vLay = getValidationLayout();
		if(vLay != null && getFocObject() != null && !getFocObject().isCreated()) {
			
			if(			PhotoAlbumAppGroup.getCurrentAppGroup() != null 
					&& 	PhotoAlbumAppGroup.getCurrentAppGroup().isAllowDelete()) {
				Embedded valo_DeleteEmbedded = new Embedded();
	  		valo_DeleteEmbedded.addStyleName(FocXMLGuiComponentStatic.STYLE_HAND_POINTER_ON_HOVER);
				if(FocWebApplication.getInstanceForThread().isMobile()){
					valo_DeleteEmbedded.setSource(FVIconFactory.getInstance().getFVIcon_Big(FVIconFactory.ICON_TRASH_WHITE));
				}else{
					valo_DeleteEmbedded.setSource(FVIconFactory.getInstance().getFVIcon_Big(FVIconFactory.ICON_TRASH_BLACK));
				}
				valo_DeleteEmbedded.addClickListener(new MouseEvents.ClickListener() {
					@Override
					public void click(com.vaadin.event.MouseEvents.ClickEvent event) {
						deleteButtonClickListener();					
					}
				});
				if(valo_DeleteEmbedded != null){
					vLay.addComponent(valo_DeleteEmbedded);
					vLay.setComponentAlignment(valo_DeleteEmbedded, Alignment.BOTTOM_LEFT);
				}
			}
		}
	}
	
	public PhotoAlbum_Thumb_Table getThumbForm() {
		return thumbForm;
	}

	public void setThumbForm(PhotoAlbum_Thumb_Table thumbForm) {
		this.thumbForm = thumbForm;
	}
}
@@ -723,16 +723,74 @@
 ose();%0D%0A
+%09%09if (thumbForm != null) %7B%0D%0A%09%09%09thumbForm.refresh();%0D%0A%09%09%7D%0D%0A
 %09%09thumbF

Refresh photo album after user edits a photo.