/*******************************************************************************
* Copyright (c) 2009, 2010 Innovation Gate GmbH.
* 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:
* Innovation Gate GmbH - initial API and implementation
******************************************************************************/
package de.innovationgate.eclipse.wgadesigner.refactoring;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import org.eclipse.core.resources.IContainer;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.OperationCanceledException;
import org.eclipse.ltk.core.refactoring.Change;
import org.eclipse.ltk.core.refactoring.CompositeChange;
import org.eclipse.ltk.core.refactoring.RefactoringStatus;
import org.eclipse.ltk.core.refactoring.RefactoringStatusEntry;
import org.eclipse.ltk.core.refactoring.participants.CheckConditionsContext;
import org.eclipse.ltk.core.refactoring.participants.RenameParticipant;
import de.innovationgate.eclipse.wgadesigner.WGADesignerPlugin;
public class ContainerRenameParticipant extends RenameParticipant {
private RefactoringStatus _refactoringStatus = new RefactoringStatus();
private List<RefactoringInfo> _refactoringInformations = new ArrayList<RefactoringInfo>();
private List<Change> _changes = new ArrayList<Change>();
@Override
public RefactoringStatus checkConditions(IProgressMonitor pm, CheckConditionsContext context) throws OperationCanceledException {
Iterator<RefactoringInfo> infos = _refactoringInformations.iterator();
while (infos.hasNext()) {
RefactoringInfo info = infos.next();
try {
_changes.add(RefactoringManager.createChange(info));
} catch (Exception e) {
_refactoringStatus.addEntry(new RefactoringStatusEntry(RefactoringStatus.WARNING, "Unable to create change for '" + info.getDescription() + "'. See log for details."));
WGADesignerPlugin.getDefault().logError("Unable to create change for '" + info.getDescription() + "'.", e);
}
}
return _refactoringStatus;
}
@Override
public Change createChange(IProgressMonitor pm) throws CoreException, OperationCanceledException {
CompositeChange change = new CompositeChange("WGA resource changes");
change.addAll(_changes.toArray(new Change[0]));
return change;
}
@Override
public String getName() {
return "Container rename participant";
}
@Override
protected boolean initialize(Object element) {
if (element instanceof IContainer) {
IContainer container = (IContainer) element;
try {
_refactoringInformations = RefactoringManager.getAffectedResources(container, getArguments());
} catch (Exception e) {
_refactoringStatus.addEntry(new RefactoringStatusEntry(RefactoringStatus.ERROR,"Unable to gather refactoring information. See error log for details. Essential refactoring operations will be skipped. Workspace structure might get invalid."));
WGADesignerPlugin.getDefault().logError("Unable to gather refactoring information.", e);
}
}
return !_refactoringInformations.isEmpty();
}
}