Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/infra/org.eclipse.papyrus.infra.ui.resources/src/org/eclipse/papyrus/infra/ui/resources/refactoring/MoveModelParticipant.java')
-rw-r--r--plugins/infra/org.eclipse.papyrus.infra.ui.resources/src/org/eclipse/papyrus/infra/ui/resources/refactoring/MoveModelParticipant.java117
1 files changed, 117 insertions, 0 deletions
diff --git a/plugins/infra/org.eclipse.papyrus.infra.ui.resources/src/org/eclipse/papyrus/infra/ui/resources/refactoring/MoveModelParticipant.java b/plugins/infra/org.eclipse.papyrus.infra.ui.resources/src/org/eclipse/papyrus/infra/ui/resources/refactoring/MoveModelParticipant.java
new file mode 100644
index 00000000000..034462bf004
--- /dev/null
+++ b/plugins/infra/org.eclipse.papyrus.infra.ui.resources/src/org/eclipse/papyrus/infra/ui/resources/refactoring/MoveModelParticipant.java
@@ -0,0 +1,117 @@
+/*****************************************************************************
+ * Copyright (c) 2009 Atos Origin.
+ *
+ *
+ * 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:
+ * <a href="mailto:thomas.szadel@atosorigin.com">Thomas Szadel</a> - Initial API and implementation
+ * <a href="mailto:arthur.daussy@atosorigin.com">Arthur Daussy</a> - Correction of the move ( set the destination attribute)
+ *****************************************************************************/
+package org.eclipse.papyrus.infra.ui.resources.refactoring;
+
+import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
+import org.eclipse.core.resources.IContainer;
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IResource;
+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.NullChange;
+import org.eclipse.ltk.core.refactoring.RefactoringStatus;
+import org.eclipse.ltk.core.refactoring.participants.CheckConditionsContext;
+import org.eclipse.ltk.core.refactoring.participants.MoveParticipant;
+import org.eclipse.ltk.core.refactoring.resource.MoveResourceChange;
+
+/**
+ * Participant that is aware of model deletion.
+ * FIXME Integrate and create register to the extension point
+ *
+ * @author <a href="mailto:thomas.szadel@atosorigin.com">Thomas Szadel</a>
+ *
+ */
+public class MoveModelParticipant extends MoveParticipant {
+
+ private Set<IResource> filesToMove = new HashSet<IResource>();
+
+ private IContainer destination;
+
+ /**
+ * Overrides checkConditions.
+ *
+ * {@inheritDoc}
+ *
+ * @see org.eclipse.ltk.core.refactoring.participants.RefactoringParticipant#checkConditions(org.eclipse.core.runtime.IProgressMonitor,
+ * org.eclipse.ltk.core.refactoring.participants.CheckConditionsContext)
+ */
+ @Override
+ public RefactoringStatus checkConditions(IProgressMonitor pm, CheckConditionsContext context) throws OperationCanceledException {
+ return new RefactoringStatus();
+ }
+
+ /**
+ * Overrides createChange.
+ *
+ * {@inheritDoc}
+ *
+ * @see org.eclipse.ltk.core.refactoring.participants.RefactoringParticipant#createChange(org.eclipse.core.runtime.IProgressMonitor)
+ */
+ @Override
+ public Change createChange(IProgressMonitor pm) throws CoreException, OperationCanceledException {
+ List<Change> changes = new ArrayList<Change>(filesToMove.size());
+
+ for(IResource path : filesToMove) {
+ if(path.exists()) {
+ changes.add(new MoveResourceChange(path, destination));
+ }
+ }
+ if(changes.isEmpty()) {
+ return new NullChange();
+ } else {
+ return new CompositeChange(getName(), changes.toArray(new Change[changes.size()]));
+ }
+ }
+
+ /**
+ * Overrides getName.
+ *
+ * {@inheritDoc}
+ *
+ * @see org.eclipse.ltk.core.refactoring.participants.RefactoringParticipant#getName()
+ */
+ @Override
+ public String getName() {
+ return Messages.MoveModelParticipant_Name;
+ }
+
+ /**
+ * Overrides initialize.
+ *
+ * {@inheritDoc}
+ *
+ * @see org.eclipse.ltk.core.refactoring.participants.RefactoringParticipant#initialize(java.lang.Object)
+ */
+ @Override
+ protected boolean initialize(Object element) {
+ if(!(element instanceof IFile)) {
+ return false;
+ }
+ IFile file = (IFile)element;
+ Object _destination = getArguments().getDestination();
+ if(_destination instanceof IContainer) {
+ destination = (IContainer)_destination;
+
+ }
+ filesToMove = ModelParticipantHelpers.getRelatedFiles(file);
+ return filesToMove.size() > 0;
+ }
+}

Back to the top