001: /*******************************************************************************
002: * Copyright (c) 2006 IBM Corporation and others.
003: * All rights reserved. This program and the accompanying materials
004: * are made available under the terms of the Eclipse Public License v1.0
005: * which accompanies this distribution, and is available at
006: * http://www.eclipse.org/legal/epl-v10.html
007: *
008: * Contributors:
009: * IBM Corporation - initial API and implementation
010: *******************************************************************************/package org.eclipse.jdt.internal.corext.refactoring.reorg;
011:
012: import org.eclipse.core.runtime.CoreException;
013: import org.eclipse.core.runtime.IProgressMonitor;
014: import org.eclipse.core.runtime.OperationCanceledException;
015:
016: import org.eclipse.core.resources.IResource;
017:
018: import org.eclipse.ltk.core.refactoring.Change;
019: import org.eclipse.ltk.core.refactoring.RefactoringStatus;
020:
021: import org.eclipse.jdt.core.IJavaElement;
022:
023: import org.eclipse.jdt.internal.corext.refactoring.Checks;
024: import org.eclipse.jdt.internal.corext.refactoring.RefactoringCoreMessages;
025: import org.eclipse.jdt.internal.corext.refactoring.base.JDTChange;
026: import org.eclipse.jdt.internal.corext.util.Messages;
027:
028: import org.eclipse.jdt.ui.JavaElementLabels;
029:
030: /**
031: * Change to create move targets during scripting of move refactorings.
032: *
033: * @since 3.3
034: */
035: public final class LoggedCreateTargetChange extends JDTChange {
036:
037: /** The queries */
038: private final ICreateTargetQueries fQueries;
039:
040: /** The selection */
041: private Object fSelection;
042:
043: /**
044: * Creates a new logged create target change.
045: *
046: * @param selection
047: * the selection
048: * @param queries
049: * the queries
050: */
051: public LoggedCreateTargetChange(Object selection,
052: ICreateTargetQueries queries) {
053: fSelection = selection;
054: fQueries = queries;
055: }
056:
057: /**
058: * {@inheritDoc}
059: */
060: public Object getModifiedElement() {
061: return null;
062: }
063:
064: /**
065: * {@inheritDoc}
066: */
067: public String getName() {
068: return RefactoringCoreMessages.LoggedCreateTargetChange_change_name;
069: }
070:
071: /**
072: * {@inheritDoc}
073: */
074: public RefactoringStatus isValid(IProgressMonitor monitor)
075: throws CoreException, OperationCanceledException {
076: if (fSelection instanceof IJavaElement) {
077: final IJavaElement element = (IJavaElement) fSelection;
078: if (!Checks.isAvailable(element))
079: RefactoringStatus
080: .createFatalErrorStatus(Messages
081: .format(
082: RefactoringCoreMessages.RenameResourceChange_does_not_exist,
083: JavaElementLabels
084: .getTextLabel(
085: fSelection,
086: JavaElementLabels.ALL_DEFAULT)));
087: } else if (fSelection instanceof IResource) {
088: final IResource resource = (IResource) fSelection;
089: if (!resource.exists())
090: RefactoringStatus
091: .createFatalErrorStatus(Messages
092: .format(
093: RefactoringCoreMessages.RenameResourceChange_does_not_exist,
094: JavaElementLabels
095: .getTextLabel(
096: fSelection,
097: JavaElementLabels.ALL_DEFAULT)));
098: }
099: return new RefactoringStatus();
100: }
101:
102: /**
103: * {@inheritDoc}
104: */
105: public Change perform(IProgressMonitor monitor)
106: throws CoreException {
107: fQueries.createNewPackageQuery().getCreatedTarget(fSelection);
108: return null;
109: }
110: }
|