blob: 51ee6cc6accd3ac929117a0c2d7c98f7690af49d (
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
|
/*******************************************************************************
* Copyright (c) 2007 IBM Corporation 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:
* IBM Corporation - initial API and implementation
*******************************************************************************/
package org.eclipse.equinox.prov.ui.operations;
import java.net.URL;
import org.eclipse.core.runtime.*;
import org.eclipse.equinox.prov.core.ProvisionException;
import org.eclipse.equinox.prov.metadata.repository.IMetadataRepository;
import org.eclipse.equinox.prov.ui.ProvisioningUtil;
/**
* Operation that adds a metadata repository given its URL.
*
* @since 3.4
*/
public class AddMetadataRepositoryOperation extends RepositoryOperation {
boolean added = false;
public AddMetadataRepositoryOperation(String label, URL url, String name) {
super(label, new URL[] {url}, new String[] {name});
}
protected IStatus doExecute(IProgressMonitor monitor, IAdaptable uiInfo) throws ProvisionException {
for (int i = 0; i < urls.length; i++) {
IMetadataRepository repo = ProvisioningUtil.addMetadataRepository(urls[i], monitor, uiInfo);
if (repo == null) {
return failureStatus();
}
if (names[i] != null) {
ProvisioningUtil.setRepositoryName(repo, names[i]);
}
}
added = true;
return okStatus();
}
protected IStatus doUndo(IProgressMonitor monitor, IAdaptable uiInfo) throws ProvisionException {
for (int i = 0; i < urls.length; i++) {
ProvisioningUtil.removeMetadataRepository(urls[i], monitor, uiInfo);
}
added = false;
return okStatus();
}
/*
* (non-Javadoc)
*
* @see org.eclipse.core.commands.operations.AbstractOperation#canExecute()
*/
public boolean canExecute() {
return super.canExecute() && !added;
}
/*
* (non-Javadoc)
*
* @see org.eclipse.core.commands.operations.AbstractOperation#canUndo()
*/
public boolean canUndo() {
return super.canUndo() && added;
}
}
|