Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: a211179a76c65deea8b6ae15c968e0fabe37907e (plain) (blame)
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
/*****************************************************************************
 * Copyright (c) 2011, 2015 CEA LIST, Christian W. Damus, and others.
 *
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *  Camille Letavernier (CEA LIST) camille.letavernier@cea.fr - Initial API and implementation
 *  Christian W. Damus (CEA) - Factor out workspace storage for pluggable storage providers (CDO)
 *  Christian W. Damus - bug 482927
 *****************************************************************************/
package org.eclipse.papyrus.views.properties.toolsmiths.storage.actions.workspace;

import java.io.File;

import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.SubMonitor;
import org.eclipse.papyrus.infra.properties.contexts.Context;
import org.eclipse.papyrus.infra.properties.internal.ui.runtime.IInternalConfigurationManager;
import org.eclipse.papyrus.views.properties.toolsmiths.messages.Messages;
import org.eclipse.papyrus.views.properties.toolsmiths.storage.actions.IContextDeleteAction;

/**
 * An action to delete an existing context. This action cannot be undone.
 * If you simply want to disable an existing context, see {@link IInternalConfigurationManager#disableContext(Context, boolean)}
 *
 * @author Camille Letavernier
 */
public class WorkspaceContextDeleteAction implements IContextDeleteAction {

	@Override
	public String getToolTip() {
		return Messages.WorkspaceContextDeleteAction_0;
	}

	/**
	 * Deletes the given context.
	 *
	 * @param context
	 *            The context to delete
	 */
	@Override
	public void delete(final Context context, IProgressMonitor monitor) throws CoreException {
		final File directory = new File(context.eResource().getURI().toFileString()).getParentFile();

		SubMonitor sub = SubMonitor.convert(monitor, Messages.WorkspaceContextDeleteAction_1 + context.getUserLabel(), IProgressMonitor.UNKNOWN);
		try {
			delete(directory);
		} finally {
			sub.done();
		}
	}

	/**
	 * Recursively deletes a file or directory
	 *
	 * @param file
	 *            The file or directory to delete recusively
	 */
	private void delete(File file) {
		if (file.isDirectory()) {
			for (File subFile : file.listFiles()) {
				delete(subFile);
			}

		}
		file.delete();
	}
}

Back to the top