blob: 4b7e43a335a37a93265bc57070005d1c73abc217 [file] [log] [blame]
/*******************************************************************************
* Copyright (c) 2007, 2008 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.internal.provisional.p2.ui.operations;
import java.net.URL;
import org.eclipse.core.runtime.*;
import org.eclipse.equinox.internal.provisional.p2.core.ProvisionException;
/**
* Operation which adds an artifact repository given its URL.
*
* @since 3.4
*/
public class AddArtifactRepositoryOperation extends RepositoryOperation {
boolean added = false;
public AddArtifactRepositoryOperation(String label, URL url) {
super(label, new URL[] {url});
}
protected IStatus doBatchedExecute(IProgressMonitor monitor, IAdaptable uiInfo) throws ProvisionException {
for (int i = 0; i < urls.length; i++) {
ProvisioningUtil.addArtifactRepository(urls[i]);
}
added = true;
return okStatus();
}
protected IStatus doBatchedUndo(IProgressMonitor monitor, IAdaptable uiInfo) throws ProvisionException {
for (int i = 0; i < urls.length; i++) {
ProvisioningUtil.removeArtifactRepository(urls[i], monitor);
}
// assume the best if no exception is thrown;
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;
}
}