diff options
-rw-r--r-- | bundles/org.eclipse.e4.tools.emf.editor3x/plugin.xml | 19 | ||||
-rw-r--r-- | bundles/org.eclipse.e4.tools.emf.editor3x/src/org/eclipse/e4/tools/emf/editor3x/ClassMoveParticipant.java | 52 | ||||
-rw-r--r-- | bundles/org.eclipse.e4.tools.emf.editor3x/src/org/eclipse/e4/tools/emf/editor3x/ModelMoveParticipant.java | 151 | ||||
-rw-r--r-- | bundles/org.eclipse.e4.tools.emf.editor3x/src/org/eclipse/e4/tools/emf/editor3x/ModelRenameParticipant.java (renamed from bundles/org.eclipse.e4.tools.emf.editor3x/src/org/eclipse/e4/tools/emf/editor3x/RenameParticipant.java) | 2 | ||||
-rw-r--r-- | bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/wbm/ApplicationModelEditor.java | 21 |
5 files changed, 179 insertions, 66 deletions
diff --git a/bundles/org.eclipse.e4.tools.emf.editor3x/plugin.xml b/bundles/org.eclipse.e4.tools.emf.editor3x/plugin.xml index 86a929eb..d141b313 100644 --- a/bundles/org.eclipse.e4.tools.emf.editor3x/plugin.xml +++ b/bundles/org.eclipse.e4.tools.emf.editor3x/plugin.xml @@ -35,7 +35,7 @@ <extension point="org.eclipse.ltk.core.refactoring.renameParticipants"> <renameParticipant - class="org.eclipse.e4.tools.emf.editor3x.RenameParticipant" + class="org.eclipse.e4.tools.emf.editor3x.ModelRenameParticipant" id="org.eclipse.e4.tools.emf.editor3x.renameParticipant" name="Workbench Model Contribution Participant"> <enablement> @@ -66,7 +66,7 @@ <extension point="org.eclipse.ltk.core.refactoring.moveParticipants"> <moveParticipant - class="org.eclipse.e4.tools.emf.editor3x.ClassMoveParticipant" + class="org.eclipse.e4.tools.emf.editor3x.ModelMoveParticipant" id="org.eclipse.e4.tools.emf.editor3x.moveParticipant" name="Workbench Model Contribution Participant"> <enablement> @@ -76,7 +76,20 @@ </iterate> </with> <with variable="element"> - <instanceof value="org.eclipse.jdt.core.IType"/> + <or> + <instanceof + value="org.eclipse.jdt.core.IType"> + </instanceof> + <instanceof + value="org.eclipse.jdt.core.IPackageFragment"> + </instanceof> + <instanceof + value="org.eclipse.core.resources.IFile"> + </instanceof> + <instanceof + value="org.eclipse.core.resources.IFolder"> + </instanceof> + </or> </with> </enablement> </moveParticipant> diff --git a/bundles/org.eclipse.e4.tools.emf.editor3x/src/org/eclipse/e4/tools/emf/editor3x/ClassMoveParticipant.java b/bundles/org.eclipse.e4.tools.emf.editor3x/src/org/eclipse/e4/tools/emf/editor3x/ClassMoveParticipant.java deleted file mode 100644 index 675979aa..00000000 --- a/bundles/org.eclipse.e4.tools.emf.editor3x/src/org/eclipse/e4/tools/emf/editor3x/ClassMoveParticipant.java +++ /dev/null @@ -1,52 +0,0 @@ -package org.eclipse.e4.tools.emf.editor3x; - -import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.core.runtime.OperationCanceledException; -import org.eclipse.e4.tools.emf.editor3x.extension.Util; -import org.eclipse.jdt.core.IPackageFragment; -import org.eclipse.jdt.core.IType; -import org.eclipse.ltk.core.refactoring.Change; -import org.eclipse.ltk.core.refactoring.RefactoringStatus; -import org.eclipse.ltk.core.refactoring.participants.CheckConditionsContext; - -public class ClassMoveParticipant extends - org.eclipse.ltk.core.refactoring.participants.MoveParticipant { - private IType type; - - @Override - protected boolean initialize(Object element) { - if( element instanceof IType ) { - type = (IType) element; - } else { - type = null; - } - - return type != null; - } - - @Override - public String getName() { - return "Workbench Model Contribution Participant"; - } - - @Override - public RefactoringStatus checkConditions(IProgressMonitor pm, - CheckConditionsContext context) throws OperationCanceledException { - return new RefactoringStatus(); - } - - @Override - public Change createChange(IProgressMonitor pm) throws CoreException, - OperationCanceledException { - String fromBundle = Util.getBundleSymbolicName(type.getJavaProject().getProject()); - String fromClassname = type.getFullyQualifiedName(); - - IPackageFragment fragment = (IPackageFragment) getArguments().getDestination(); - String toBundle = Util.getBundleSymbolicName(fragment.getJavaProject().getProject()); - String toClassName = fragment.getElementName().length() == 0 ? type.getElementName() : fragment.getElementName() + "." + type.getElementName(); - - return RefactorParticipantDelegate.createChange(pm, this, "bundleclass://"+fromBundle+"/"+fromClassname, "bundleclass://"+toBundle+"/"+toClassName); - } - -} diff --git a/bundles/org.eclipse.e4.tools.emf.editor3x/src/org/eclipse/e4/tools/emf/editor3x/ModelMoveParticipant.java b/bundles/org.eclipse.e4.tools.emf.editor3x/src/org/eclipse/e4/tools/emf/editor3x/ModelMoveParticipant.java new file mode 100644 index 00000000..2ec2342e --- /dev/null +++ b/bundles/org.eclipse.e4.tools.emf.editor3x/src/org/eclipse/e4/tools/emf/editor3x/ModelMoveParticipant.java @@ -0,0 +1,151 @@ +package org.eclipse.e4.tools.emf.editor3x; + +import org.eclipse.core.resources.IFile; +import org.eclipse.core.resources.IFolder; +import org.eclipse.core.resources.IProject; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.core.runtime.OperationCanceledException; +import org.eclipse.e4.tools.emf.editor3x.extension.Util; +import org.eclipse.jdt.core.IPackageFragment; +import org.eclipse.jdt.core.IPackageFragmentRoot; +import org.eclipse.jdt.core.IType; +import org.eclipse.ltk.core.refactoring.Change; +import org.eclipse.ltk.core.refactoring.RefactoringStatus; +import org.eclipse.ltk.core.refactoring.participants.CheckConditionsContext; +import org.eclipse.ltk.core.refactoring.participants.MoveParticipant; + +public class ModelMoveParticipant extends MoveParticipant { + private IType _type; + private IPackageFragment _pckage; + private IFile _file; + private IFolder _folder; + + @Override + protected boolean initialize(Object element) { + + if (element instanceof IType) { + _type = (IType) element; + return true; + } + + if (element instanceof IPackageFragment) { + _pckage = (IPackageFragment) element; + return true; + } + + if (element instanceof IFile) { + _file = (IFile) element; + return true; + } + + if (element instanceof IFolder) { + _folder = (IFolder) element; + return true; + } + return false; + } + + @Override + public String getName() { + return "Workbench Model Contribution Participant"; + } + + @Override + public RefactoringStatus checkConditions(IProgressMonitor pm, + CheckConditionsContext context) throws OperationCanceledException { + return new RefactoringStatus(); + } + + @Override + public Change createChange(IProgressMonitor pm) throws CoreException, + OperationCanceledException { + + pm.beginTask("Creating Change ..", IProgressMonitor.UNKNOWN); + + Change change = null; + + if (_type != null) { + change = createClassChange(pm, _type); + } + + else if (_pckage != null) { + change = createPackageChange(pm, _pckage); + } + + else if (_file != null) { + change = createFileChange(pm, _file); + } + + // + // if (_folder != null) { + // return createFolderChange(pm, _folder); + // } + + pm.done(); + + return change; + } + + private Change createFileChange(IProgressMonitor pm, IFile file) + throws CoreException { + + String newUrl = "platform:/plugin/"; + if (getArguments().getDestination() instanceof IFolder) { + IFolder folder = (IFolder) getArguments().getDestination(); + newUrl += folder.getProject().getName() + "/" + + folder.getProjectRelativePath().toString() + "/" + + file.getName(); + } else { + IProject project = (IProject) getArguments().getDestination(); + newUrl += project.getName() + "/" + file.getName(); + + } + + String oldUrl = "platform:/plugin" + file.getFullPath(); + + return RefactorParticipantDelegate.createChange(pm, this, oldUrl, + newUrl); + } + + private Change createPackageChange(IProgressMonitor pm, + IPackageFragment pckage) throws CoreException, + OperationCanceledException { + String fromBundle = Util.getBundleSymbolicName(pckage.getJavaProject() + .getProject()); + + IPackageFragmentRoot fragmentRoot = (IPackageFragmentRoot) getArguments() + .getDestination(); + String toBundle = Util.getBundleSymbolicName(fragmentRoot + .getJavaProject().getProject()); + + final String newUrl = "bundleclass://" + toBundle + "/" + + pckage.getElementName(); + + String oldUrl = "bundleclass://" + fromBundle + "/" + + pckage.getElementName(); + + return RefactorParticipantDelegate.createChange(pm, this, oldUrl, + newUrl); + } + + private Change createClassChange(IProgressMonitor pm, IType type) + throws CoreException, OperationCanceledException { + String fromBundle = Util.getBundleSymbolicName(_type.getJavaProject() + .getProject()); + String fromClassname = type.getFullyQualifiedName(); + + IPackageFragment fragment = (IPackageFragment) getArguments() + .getDestination(); + String toBundle = Util.getBundleSymbolicName(fragment.getJavaProject() + .getProject()); + String toClassName = fragment.getElementName().length() == 0 ? type + .getElementName() : fragment.getElementName() + "." + + type.getElementName(); + + return RefactorParticipantDelegate.createChange(pm, this, + "bundleclass://" + fromBundle + "/" + fromClassname, + "bundleclass://" + toBundle + "/" + toClassName); + } + +} diff --git a/bundles/org.eclipse.e4.tools.emf.editor3x/src/org/eclipse/e4/tools/emf/editor3x/RenameParticipant.java b/bundles/org.eclipse.e4.tools.emf.editor3x/src/org/eclipse/e4/tools/emf/editor3x/ModelRenameParticipant.java index 5972877a..24ee9ceb 100644 --- a/bundles/org.eclipse.e4.tools.emf.editor3x/src/org/eclipse/e4/tools/emf/editor3x/RenameParticipant.java +++ b/bundles/org.eclipse.e4.tools.emf.editor3x/src/org/eclipse/e4/tools/emf/editor3x/ModelRenameParticipant.java @@ -22,7 +22,7 @@ import org.eclipse.ltk.core.refactoring.Change; import org.eclipse.ltk.core.refactoring.RefactoringStatus; import org.eclipse.ltk.core.refactoring.participants.CheckConditionsContext; -public class RenameParticipant extends +public class ModelRenameParticipant extends org.eclipse.ltk.core.refactoring.participants.RenameParticipant { private IType _type; private IPackageFragment _pckage; diff --git a/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/wbm/ApplicationModelEditor.java b/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/wbm/ApplicationModelEditor.java index e05ca64d..1487f116 100644 --- a/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/wbm/ApplicationModelEditor.java +++ b/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/wbm/ApplicationModelEditor.java @@ -22,6 +22,7 @@ import org.eclipse.core.resources.IResourceChangeEvent; import org.eclipse.core.resources.IResourceChangeListener; import org.eclipse.core.resources.IResourceDelta; import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.NullProgressMonitor; import org.eclipse.core.runtime.Path; import org.eclipse.core.runtime.Status; import org.eclipse.e4.core.contexts.IEclipseContext; @@ -150,17 +151,17 @@ public class ApplicationModelEditor extends ModelEditor { * Reload the model. */ protected void reloadModel() { - try { - resource.unload(); - resource.load(null); - // must be done in ui thread because of databinding - sync.syncExec(new Runnable() { - public void run() { + getModelProvider().getRoot().getRealm().asyncExec(new Runnable() { + public void run() { + try { + resource.unload(); + resource.load(null); getModelProvider().replaceRoot(resource.getContents().get(0)); + doSave(new NullProgressMonitor()); + } catch (IOException e) { + statusDialog(e); } - }); - } catch (IOException e) { - statusDialog(e); - } + } + }); } }
\ No newline at end of file |