2
* This file is part of the ZoRa project: http://www.photozora.org.
4
* ZoRa is free software; you can redistribute it and/or modify
5
* it under the terms of the GNU General Public License as published by
6
* the Free Software Foundation; either version 2 of the License, or
7
* (at your option) any later version.
9
* ZoRa is distributed in the hope that it will be useful,
10
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
* GNU General Public License for more details.
14
* You should have received a copy of the GNU General Public License
15
* along with ZoRa; if not, write to the Free Software
16
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18
* (c) 2009 Berthold Daum (berthold.daum@bdaum.de)
21
package com.bdaum.zoom.operations.internal;
25
import java.util.ArrayList;
26
import java.util.Date;
27
import java.util.HashSet;
28
import java.util.List;
31
import org.eclipse.core.commands.ExecutionException;
32
import org.eclipse.core.runtime.IAdaptable;
33
import org.eclipse.core.runtime.IProgressMonitor;
34
import org.eclipse.core.runtime.IStatus;
35
import org.eclipse.core.runtime.jobs.Job;
36
import org.eclipse.osgi.util.NLS;
38
import com.bdaum.zoom.cat.model.asset.Asset;
39
import com.bdaum.zoom.core.Constants;
40
import com.bdaum.zoom.core.Core;
41
import com.bdaum.zoom.core.IVolumeManager;
42
import com.bdaum.zoom.core.db.IDbErrorHandler;
43
import com.bdaum.zoom.operations.DbOperation;
44
import com.bdaum.zoom.operations.IProfiledOperation;
46
public class DeleteVoicenoteOperation extends DbOperation {
48
private List<Asset> assets;
50
public DeleteVoicenoteOperation(List<Asset> assets) {
51
super(Messages.getString("DeleteVoicenoteOperation.Delete_voice_notes")); //$NON-NLS-1$
53
this.date = new Date();
57
public IStatus execute(IProgressMonitor aMonitor, final IAdaptable info)
58
throws ExecutionException {
59
final Set<String> volumes = new HashSet<String>();
60
final List<String> errands = new ArrayList<String>();
61
init(aMonitor, assets.size() + 2);
62
boolean deleted = false;
63
IVolumeManager volumeManager = Core.getCore().getVolumeManager();
64
for (Asset asset : assets) {
65
if (asset.getFileState() != IVolumeManager.PEER) {
66
if (".".equals(asset.getVoiceFileURI())) { //$NON-NLS-1$
67
URI uri = volumeManager.findFile(asset);
69
if (volumeManager.findExistingFile(asset, true) != null) {
70
deleted |= deleteVoiceNote(asset);
72
String volume = asset.getVolume();
73
if (volume != null && volume.length() > 0)
75
errands.add(uri.toString());
79
deleted |= deleteVoiceNote(asset);
80
if (aMonitor.isCanceled())
85
fireAssetsModified(assets, null);
86
if (errands.size() > 0) {
87
final IDbErrorHandler errorHandler = Core.getCore()
89
if (errorHandler != null) {
91
if (errands.size() == 1) {
94
.getString("DeleteVoicenoteOperation.File_offline"), //$NON-NLS-1$
95
errands.get(0), volumes.toArray()[0]);
97
StringBuffer sb = new StringBuffer();
98
for (String volume : volumes) {
100
sb.append(", "); //$NON-NLS-1$
105
.getString("DeleteVoicenoteOperation.Files_offline"), //$NON-NLS-1$
106
errands.size(), sb.toString());
111
Messages.getString("DeleteVoicenoteOperation.Unable_to_delete"), //$NON-NLS-1$
119
private boolean deleteVoiceNote(Asset asset) {
120
String voiceFileURI = asset.getVoiceFileURI();
121
if (voiceFileURI != null && voiceFileURI.length() > 0) {
122
if (".".equals(voiceFileURI)) { //$NON-NLS-1$
123
IVolumeManager volumeManager = Core.getCore()
125
URI uri = volumeManager.findVoiceFile(asset);
126
if (uri != null && Constants.FILESCHEME.equals(uri.getScheme()))
127
new File(uri).delete();
129
asset.setVoiceFileURI(null);
130
storeSafely(null, 1, asset);
137
public boolean canRedo() {
142
public IStatus redo(IProgressMonitor aMonitor, IAdaptable info)
143
throws ExecutionException {
148
public boolean canUndo() {
153
public IStatus undo(IProgressMonitor aMonitor, IAdaptable info)
154
throws ExecutionException {
158
public int getExecuteProfile() {
159
return IProfiledOperation.CONTENT;
162
public int getUndoProfile() {
167
public int getPriority() {
168
return assets.size() > 3 ? Job.LONG : Job.SHORT;