~berthold-daum/zora/trunk

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
/*
 * This file is part of the ZoRa project: http://www.photozora.org.
 *
 * ZoRa is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * ZoRa is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with ZoRa; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 *
 * (c) 2014 Berthold Daum  (berthold.daum@bdaum.de)
 */
package com.bdaum.zoom.ui.internal.operations;

import org.eclipse.core.commands.ExecutionException;
import org.eclipse.core.commands.operations.AbstractOperation;
import org.eclipse.core.runtime.IAdaptable;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;

import com.bdaum.zoom.cat.model.group.exhibition.ExhibitionImpl;
import com.bdaum.zoom.core.Core;

public class ExhibitionPropertiesOperation extends AbstractOperation {

	/**
	 *
	 */
	private ExhibitionImpl backup;
	private ExhibitionImpl exhibition;
	private ExhibitionImpl redo;

	public ExhibitionPropertiesOperation(ExhibitionImpl backup,
			ExhibitionImpl exhibition) {
		super(Messages.ExhibitionPropertiesOperation_set_exhibition_properties);
		this.backup = backup;
		this.exhibition = exhibition;
	}

	public static ExhibitionImpl cloneExhibition(ExhibitionImpl exhibition) {
		return new ExhibitionImpl(exhibition.getName(),
				exhibition.getDescription(), exhibition.getInfo(),
				exhibition.getDefaultViewingHeight(), exhibition.getVariance(),
				exhibition.getGridSize(), exhibition.getShowGrid(),
				exhibition.getSnapToGrid(), exhibition.getDefaultDescription(),
				exhibition.getLabelFontFamily(), exhibition.getLabelFontSize(),
				exhibition.getLabelSequence(), exhibition.getHideLabel(),
				exhibition.getLabelAlignment(), exhibition.getLabelDistance(),
				exhibition.getLabelIndent(), exhibition.getStartX(),
				exhibition.getStartY(), exhibition.getMatWidth(),
				exhibition.getMatColor(), exhibition.getFrameWidth(),
				exhibition.getFrameColor(), exhibition.getGroundColor(),
				exhibition.getHorizonColor(), exhibition.getCeilingColor(),
				exhibition.getAudio(), exhibition.getOutputFolder(),
				exhibition.getFtpDir(), exhibition.getIsFtp(),
				exhibition.getPageName(), exhibition.getApplySharpening(),
				exhibition.getRadius(), exhibition.getAmount(),
				exhibition.getThreshold(), exhibition.getAddWatermark(),
				exhibition.getContactName(), exhibition.getEmail(),
				exhibition.getWebUrl(), exhibition.getCopyright(),
				exhibition.getLogo(), exhibition.getInfoPlatePosition(),
				exhibition.getHideCredits(), exhibition.getJpegQuality(),
				exhibition.getScalingMethod(), exhibition.getLastAccessDate(),
				exhibition.getPerspective());
	}

	@Override
	public IStatus execute(IProgressMonitor monitor, IAdaptable info)
			throws ExecutionException {
		Core.getCore().getDbManager().safeTransaction(null, exhibition);
		return Status.OK_STATUS;
	}

	@Override
	public IStatus redo(IProgressMonitor monitor, IAdaptable info)
			throws ExecutionException {
		transferValues(redo, exhibition);
		return execute(monitor, info);
	}

	@Override
	public IStatus undo(IProgressMonitor monitor, IAdaptable info)
			throws ExecutionException {
		redo = cloneExhibition(exhibition);
		transferValues(backup, exhibition);
		return execute(monitor, info);
	}

	public static void transferValues(ExhibitionImpl from, ExhibitionImpl to) {
		to.setAddWatermark(from.getAddWatermark());
		to.setAmount(from.getAmount());
		to.setApplySharpening(from.getApplySharpening());
		to.setAudio(from.getAudio());
		to.setCeilingColor(from.getCeilingColor());
		to.setContactName(from.getContactName());
		to.setCopyright(from.getCopyright());
		to.setDefaultDescription(from.getDefaultDescription());
		to.setDefaultViewingHeight(from.getDefaultViewingHeight());
		to.setDescription(from.getDescription());
		to.setEmail(from.getEmail());
		to.setFrameColor(from.getFrameColor());
		to.setFrameWidth(from.getFrameWidth());
		to.setFtpDir(from.getFtpDir());
		to.setGridSize(from.getGridSize());
		to.setGroundColor(from.getGroundColor());
		to.setHideCredits(from.getHideCredits());
		to.setHideLabel(from.getHideLabel());
		to.setHorizonColor(from.getHorizonColor());
		to.setInfo(from.getInfo());
		to.setInfoPlatePosition(from.getInfoPlatePosition());
		to.setIsFtp(from.getIsFtp());
		to.setJpegQuality(from.getJpegQuality());
		to.setKeyword(from.getKeyword());
		to.setLabelFontFamily(from.getLabelFontFamily());
		to.setLabelFontSize(from.getLabelFontSize());
		to.setLabelSequence(from.getLabelSequence());
		to.setLogo(from.getLogo());
		to.setMatColor(from.getMatColor());
		to.setMatWidth(from.getMatWidth());
		to.setName(from.getName());
		to.setOutputFolder(from.getOutputFolder());
		to.setPageName(from.getPageName());
		to.setRadius(from.getRadius());
		to.setScalingMethod(from.getScalingMethod());
		to.setShowGrid(from.getShowGrid());
		to.setSnapToGrid(from.getSnapToGrid());
		to.setStartX(from.getStartX());
		to.setStartY(from.getStartY());
		to.setThreshold(from.getThreshold());
		to.setVariance(from.getVariance());
		to.setWebUrl(from.getWebUrl());
	}

}