From 9c664306e687afa5506f762a3953bf178433b627 Mon Sep 17 00:00:00 2001 From: Lukas Ladenberger <lukas.ladenberger@googlemail.com> Date: Thu, 5 Jun 2014 15:01:51 +0200 Subject: [PATCH] fixed PROBPLUGIN-108 --- de.bmotionstudio.rodin/fragment.xml | 50 +------ .../bmotionstudio/rodin/ActionCollection.java | 131 +++++++++--------- .../rodin/BMotionLabelProvider.java | 12 +- .../rodin/BMotionStudioActionProvider.java | 14 +- .../rodin/BMotionStudioContentProvider.java | 58 ++++---- .../rodin/BMotionStudioRodinFile.java | 27 ++++ .../rodin/BMotionSurfaceRoot.java | 34 ----- .../rodin/IBMotionSurfaceRoot.java | 21 --- .../rodin/RenameFileHandler.java | 114 --------------- .../StartEventBVisualizationHandler.java | 15 +- 10 files changed, 152 insertions(+), 324 deletions(-) create mode 100644 de.bmotionstudio.rodin/src/de/bmotionstudio/rodin/BMotionStudioRodinFile.java delete mode 100644 de.bmotionstudio.rodin/src/de/bmotionstudio/rodin/BMotionSurfaceRoot.java delete mode 100644 de.bmotionstudio.rodin/src/de/bmotionstudio/rodin/IBMotionSurfaceRoot.java delete mode 100644 de.bmotionstudio.rodin/src/de/bmotionstudio/rodin/RenameFileHandler.java diff --git a/de.bmotionstudio.rodin/fragment.xml b/de.bmotionstudio.rodin/fragment.xml index 5fb8856c..47bd37ef 100644 --- a/de.bmotionstudio.rodin/fragment.xml +++ b/de.bmotionstudio.rodin/fragment.xml @@ -31,23 +31,7 @@ <iterate operator="or"> <instanceof - value="de.bmotionstudio.rodin.IBMotionSurfaceRoot"> - </instanceof> - </iterate> - </with> - </visibleWhen> - </command> - <command - commandId="de.bmotionstudio.rodin.command.renameVisualization" - label="Rename" - style="push"> - <visibleWhen> - <with - variable="selection"> - <iterate - operator="or"> - <instanceof - value="de.bmotionstudio.rodin.IBMotionSurfaceRoot"> + value="de.bmotionstudio.rodin.BMotionStudioRodinFile"> </instanceof> </iterate> </with> @@ -62,11 +46,6 @@ id="de.bmotionstudio.rodin.command.startVisualization" name="Start Visualization"> </command> - <command - defaultHandler="de.bmotionstudio.rodin.RenameFileHandler" - id="de.bmotionstudio.rodin.command.renameVisualization" - name="Rename"> - </command> </extension> <extension point="org.rodinp.core.fileAssociations"> @@ -75,20 +54,6 @@ root-element-type="de.bmotionstudio.gef.editor.BMotionStudioFile"> </fileAssociation> </extension> - <extension - point="org.eclipse.core.contenttype.contentTypes"> - <content-type - base-type="org.rodinp.core.rodin" - file-extensions="bmso" - id="BMotionStudioFile" - name="BMotion Studio Surface File" - priority="normal"> - </content-type> - <file-association - content-type="de.bmotionstudio.gef.editor.BMotionStudioFile" - file-extensions="bmso"> - </file-association> - </extension> <extension point="org.eclipse.ui.navigator.navigatorContent"> <navigatorContent @@ -104,7 +69,7 @@ </triggerPoints> <possibleChildren> <instanceof - value="de.bmotionstudio.rodin.IBMotionSurfaceRoot"> + value="de.bmotionstudio.rodin.BMotionStudioRodinFile"> </instanceof> </possibleChildren> <actionProvider @@ -112,8 +77,7 @@ id="de.bmotionstudio.ui.navigatorAction" priority="normal"> <enablement> - <instanceof - value="de.bmotionstudio.rodin.IBMotionSurfaceRoot"> + <instanceof value="de.bmotionstudio.rodin.BMotionStudioRodinFile"> </instanceof> </enablement> </actionProvider> @@ -138,14 +102,6 @@ </includes> </viewerActionBinding> </extension> - <extension - point="org.rodinp.core.internalElementTypes"> - <internalElementType - class="de.bmotionstudio.rodin.BMotionSurfaceRoot" - id="BMotionStudioFile" - name="BMotion Studio Surface File"> - </internalElementType> - </extension> diff --git a/de.bmotionstudio.rodin/src/de/bmotionstudio/rodin/ActionCollection.java b/de.bmotionstudio.rodin/src/de/bmotionstudio/rodin/ActionCollection.java index 9ac7a03b..b70999a3 100644 --- a/de.bmotionstudio.rodin/src/de/bmotionstudio/rodin/ActionCollection.java +++ b/de.bmotionstudio.rodin/src/de/bmotionstudio/rodin/ActionCollection.java @@ -11,6 +11,8 @@ import java.util.Collection; import java.util.Iterator; import org.eclipse.core.resources.IFile; +import org.eclipse.core.resources.IResource; +import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.NullProgressMonitor; import org.eclipse.core.runtime.Status; @@ -18,15 +20,16 @@ import org.eclipse.jface.action.Action; import org.eclipse.jface.dialogs.MessageDialog; import org.eclipse.jface.viewers.ISelection; import org.eclipse.jface.viewers.IStructuredSelection; -import org.eclipse.ui.*; +import org.eclipse.ui.IEditorDescriptor; +import org.eclipse.ui.IEditorPart; +import org.eclipse.ui.IEditorReference; +import org.eclipse.ui.IWorkbenchPage; +import org.eclipse.ui.PartInitException; +import org.eclipse.ui.PlatformUI; import org.eclipse.ui.navigator.ICommonActionExtensionSite; import org.eclipse.ui.part.FileEditorInput; -import org.rodinp.core.IRodinElement; -import org.rodinp.core.IRodinFile; -import org.rodinp.core.RodinDBException; import de.bmotionstudio.gef.editor.BMotionEditorPlugin; -import de.bmotionstudio.gef.editor.BMotionStudioImage; public class ActionCollection { @@ -42,42 +45,39 @@ public class ActionCollection { @Override public void run() { - IRodinFile component; - final ISelection selection = site.getStructuredViewer() .getSelection(); final Object obj = ((IStructuredSelection) selection) .getFirstElement(); - if (obj instanceof IBMotionSurfaceRoot) { - - component = (IRodinFile) ((IRodinElement) obj) - .getOpenable(); + if (obj instanceof BMotionStudioRodinFile) { - if (component == null) { - return; - } + BMotionStudioRodinFile file = (BMotionStudioRodinFile) obj; + IResource resource = file.getResource(); + final IFile ifile = resource.getProject().getFile( + resource.getName()); try { final IEditorDescriptor desc = PlatformUI .getWorkbench().getEditorRegistry() - .getDefaultEditor( - component.getCorrespondingResource() - .getName()); - - BMotionEditorPlugin.getActivePage().openEditor( - new FileEditorInput(component.getResource()), - desc.getId()); + .getDefaultEditor(resource.getName()); - // editor.getSite().getSelectionProvider().setSelection( - // new StructuredSelection(obj)); + BMotionEditorPlugin + .getDefault() + .getWorkbench() + .getActiveWorkbenchWindow() + .getActivePage() + .openEditor(new FileEditorInput(ifile), + desc.getId()); } catch (final PartInitException e) { final String errorMsg = "Error open Editor"; MessageDialog.openError(null, null, errorMsg); - BMotionEditorPlugin.getDefault().getLog().log( - new Status(IStatus.ERROR, + BMotionEditorPlugin + .getDefault() + .getLog() + .log(new Status(IStatus.ERROR, BMotionEditorPlugin.PLUGIN_ID, errorMsg, e)); } @@ -101,59 +101,56 @@ public class ActionCollection { public void run() { if (!(site.getStructuredViewer().getSelection().isEmpty())) { - Collection<IRodinElement> set = new ArrayList<IRodinElement>(); + Collection<BMotionStudioRodinFile> set = new ArrayList<BMotionStudioRodinFile>(); IStructuredSelection ssel = (IStructuredSelection) site .getStructuredViewer().getSelection(); for (Iterator<?> it = ssel.iterator(); it.hasNext();) { final Object obj = it.next(); - if (!(obj instanceof IBMotionSurfaceRoot)) { + if (!(obj instanceof BMotionStudioRodinFile)) { continue; } - IRodinElement elem = (IRodinElement) obj; - if (elem.isRoot()) { - elem = elem.getParent(); - } + BMotionStudioRodinFile elem = (BMotionStudioRodinFile) obj; set.add(elem); } int answer = YesToAllMessageDialog.YES; - for (IRodinElement element : set) { - if (element instanceof IRodinFile) { - if (answer != YesToAllMessageDialog.YES_TO_ALL) { - answer = YesToAllMessageDialog - .openYesNoToAllQuestion( - site.getViewSite().getShell(), - "Confirm File Delete", - "Are you sure you want to delete file '" - + ((IRodinFile) element) - .getElementName() - + "' in project '" - + element - .getParent() - .getElementName() - + "' ?"); - } + for (BMotionStudioRodinFile element : set) { + + if (answer != YesToAllMessageDialog.YES_TO_ALL) { + answer = YesToAllMessageDialog + .openYesNoToAllQuestion( + site.getViewSite().getShell(), + "Confirm File Delete", + "Are you sure you want to delete file '" + + ((BMotionStudioRodinFile) element) + .getResource() + .getName() + + "' in project '" + + element.getResource() + .getProject() + .getName() + "' ?"); + } - if (answer == YesToAllMessageDialog.NO_TO_ALL - || answer == YesToAllMessageDialog.CANCEL) - break; - - if (answer != YesToAllMessageDialog.NO) { - try { - closeOpenedEditor((IRodinFile) element); - ((IRodinFile) element).delete(true, - new NullProgressMonitor()); - } catch (PartInitException e) { - MessageDialog.openError(null, "Error", - "Could not delete file"); - } catch (RodinDBException e) { - MessageDialog.openError(null, "Error", - "Could not delete file"); - } + if (answer == YesToAllMessageDialog.NO_TO_ALL + || answer == YesToAllMessageDialog.CANCEL) + break; + + if (answer != YesToAllMessageDialog.NO) { + try { + closeOpenedEditor((BMotionStudioRodinFile) element); + ((BMotionStudioRodinFile) element) + .getResource().delete(true, + new NullProgressMonitor()); + } catch (PartInitException e) { + MessageDialog.openError(null, "Error", + "Could not delete file"); + } catch (CoreException e) { + e.printStackTrace(); } } + } } @@ -161,13 +158,15 @@ public class ActionCollection { }; deleteAction.setText("&Delete"); deleteAction.setToolTipText("Delete these elements"); - deleteAction.setImageDescriptor(BMotionStudioImage.getImageDescriptor( - "org.eclipse.ui", "$nl$/icons/full/etool16/delete_edit.gif")); + deleteAction.setImageDescriptor(BMotionEditorPlugin + .imageDescriptorFromPlugin("org.eclipse.ui", + "$nl$/icons/full/etool16/delete_edit.gif")); return deleteAction; } - static void closeOpenedEditor(IRodinFile file) throws PartInitException { + static void closeOpenedEditor(BMotionStudioRodinFile file) + throws PartInitException { IEditorReference[] editorReferences = BMotionEditorPlugin .getActivePage().getEditorReferences(); for (int j = 0; j < editorReferences.length; j++) { diff --git a/de.bmotionstudio.rodin/src/de/bmotionstudio/rodin/BMotionLabelProvider.java b/de.bmotionstudio.rodin/src/de/bmotionstudio/rodin/BMotionLabelProvider.java index 75c5a160..06ae49b3 100644 --- a/de.bmotionstudio.rodin/src/de/bmotionstudio/rodin/BMotionLabelProvider.java +++ b/de.bmotionstudio.rodin/src/de/bmotionstudio/rodin/BMotionLabelProvider.java @@ -9,8 +9,6 @@ package de.bmotionstudio.rodin; import org.eclipse.jface.viewers.ILabelProvider; import org.eclipse.jface.viewers.ILabelProviderListener; import org.eclipse.swt.graphics.Image; -import org.rodinp.core.IInternalElement; -import org.rodinp.core.IRodinFile; import de.bmotionstudio.gef.editor.BMotionStudioImage; @@ -22,12 +20,10 @@ public class BMotionLabelProvider implements ILabelProvider { public String getText(final Object element) { - if (element instanceof IRodinFile) { - return ((IRodinFile) element).getBareName(); - } else if (element instanceof IInternalElement) { - return ((IInternalElement) element).getRodinFile().getBareName(); - } - return null; + if (element instanceof BMotionStudioRodinFile) + return ((BMotionStudioRodinFile) element).getResource().getName() + .replace(".bmso", ""); + return element.toString(); } diff --git a/de.bmotionstudio.rodin/src/de/bmotionstudio/rodin/BMotionStudioActionProvider.java b/de.bmotionstudio.rodin/src/de/bmotionstudio/rodin/BMotionStudioActionProvider.java index 9492e7ac..e6b1ca71 100644 --- a/de.bmotionstudio.rodin/src/de/bmotionstudio/rodin/BMotionStudioActionProvider.java +++ b/de.bmotionstudio.rodin/src/de/bmotionstudio/rodin/BMotionStudioActionProvider.java @@ -25,7 +25,7 @@ public class BMotionStudioActionProvider extends CommonActionProvider { public static String GROUP_FILEACTIONS = "fileactionsGroup"; - // StructuredViewer viewer; + // StructuredViewer viewer; ICommonActionExtensionSite site; @@ -33,7 +33,7 @@ public class BMotionStudioActionProvider extends CommonActionProvider { public void init(final ICommonActionExtensionSite aSite) { super.init(aSite); site = aSite; - // viewer = aSite.getStructuredViewer(); + // viewer = aSite.getStructuredViewer(); } @Override @@ -49,12 +49,12 @@ public class BMotionStudioActionProvider extends CommonActionProvider { public void fillContextMenu(IMenuManager menu) { super.fillContextMenu(menu); menu.add(new GroupMarker(GROUP_FILEACTIONS)); - menu.appendToGroup(ICommonMenuConstants.GROUP_OPEN, ActionCollection - .getOpenAction(site)); + menu.appendToGroup(ICommonMenuConstants.GROUP_OPEN, + ActionCollection.getOpenAction(site)); menu.appendToGroup(ICommonMenuConstants.GROUP_OPEN_WITH, buildOpenWithMenu()); - menu.appendToGroup(GROUP_FILEACTIONS, ActionCollection - .getDeleteAction(site)); + menu.appendToGroup(GROUP_FILEACTIONS, + ActionCollection.getDeleteAction(site)); } MenuManager buildOpenWithMenu() { @@ -63,7 +63,7 @@ public class BMotionStudioActionProvider extends CommonActionProvider { ISelection selection = site.getStructuredViewer().getSelection(); Object obj = ((IStructuredSelection) selection).getFirstElement(); menu.add(new OpenWithMenu(BMotionEditorPlugin.getActivePage(), - ((IBMotionSurfaceRoot) obj).getRodinFile().getResource())); + ((BMotionStudioRodinFile) obj).getResource())); return menu; } diff --git a/de.bmotionstudio.rodin/src/de/bmotionstudio/rodin/BMotionStudioContentProvider.java b/de.bmotionstudio.rodin/src/de/bmotionstudio/rodin/BMotionStudioContentProvider.java index c00e4a4e..7a643432 100644 --- a/de.bmotionstudio.rodin/src/de/bmotionstudio/rodin/BMotionStudioContentProvider.java +++ b/de.bmotionstudio.rodin/src/de/bmotionstudio/rodin/BMotionStudioContentProvider.java @@ -6,37 +6,45 @@ package de.bmotionstudio.rodin; -import org.eclipse.core.resources.IProject; -import org.eclipse.jface.viewers.ITreeContentProvider; -import org.eclipse.jface.viewers.Viewer; -import org.rodinp.core.IRodinProject; -import org.rodinp.core.RodinCore; -import org.rodinp.core.RodinDBException; +import java.util.ArrayList; +import java.util.List; + +import org.eclipse.core.resources.IProject; +import org.eclipse.core.resources.IResource; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.jface.viewers.ITreeContentProvider; +import org.eclipse.jface.viewers.Viewer; public class BMotionStudioContentProvider implements ITreeContentProvider { public Object[] getChildren(final Object parentElement) { - if (parentElement instanceof IProject) { - - final IProject project = (IProject) parentElement; - - // if it is a RodinProject return the IRodinProject from the DB. - final IRodinProject proj = RodinCore.valueOf(project); - if (proj.exists()) { - - try { - return proj - .getRootElementsOfType(IBMotionSurfaceRoot.ELEMENT_TYPE); - } catch (final RodinDBException e) { - e.printStackTrace(); - } - - } - - } - + List<Object> res = new ArrayList<Object>(); + + if (parentElement instanceof IProject) { + + final IProject project = (IProject) parentElement; + + if (project.exists()) { + + try { + for (IResource rs : project.members()) { + if (rs.getFileExtension() != null + && rs.getFileExtension().equals("bmso")) { + res.add(new BMotionStudioRodinFile(rs)); + } + + } + } catch (CoreException e) { + e.printStackTrace(); + } + } + + return res.toArray(new BMotionStudioRodinFile[res.size()]); + + } + return new Object[0]; } diff --git a/de.bmotionstudio.rodin/src/de/bmotionstudio/rodin/BMotionStudioRodinFile.java b/de.bmotionstudio.rodin/src/de/bmotionstudio/rodin/BMotionStudioRodinFile.java new file mode 100644 index 00000000..6286b03e --- /dev/null +++ b/de.bmotionstudio.rodin/src/de/bmotionstudio/rodin/BMotionStudioRodinFile.java @@ -0,0 +1,27 @@ +/** + * (c) 2009 Lehrstuhl fuer Softwaretechnik und Programmiersprachen, + * Heinrich Heine Universitaet Duesseldorf + * This software is licenced under EPL 1.0 (http://www.eclipse.org/org/documents/epl-v10.html) + * */ + +package de.bmotionstudio.rodin; + +import org.eclipse.core.resources.IResource; + +public class BMotionStudioRodinFile { + + private IResource resource; + + public BMotionStudioRodinFile(IResource resource) { + this.resource = resource; + } + + public IResource getResource() { + return resource; + } + + public void setResource(IResource resource) { + this.resource = resource; + } + +} diff --git a/de.bmotionstudio.rodin/src/de/bmotionstudio/rodin/BMotionSurfaceRoot.java b/de.bmotionstudio.rodin/src/de/bmotionstudio/rodin/BMotionSurfaceRoot.java deleted file mode 100644 index 32710b10..00000000 --- a/de.bmotionstudio.rodin/src/de/bmotionstudio/rodin/BMotionSurfaceRoot.java +++ /dev/null @@ -1,34 +0,0 @@ -/** - * (c) 2009 Lehrstuhl fuer Softwaretechnik und Programmiersprachen, - * Heinrich Heine Universitaet Duesseldorf - * This software is licenced under EPL 1.0 (http://www.eclipse.org/org/documents/epl-v10.html) - * */ - -package de.bmotionstudio.rodin; - -import org.rodinp.core.IInternalElementType; -import org.rodinp.core.IRodinElement; -import org.rodinp.core.RodinDBException; -import org.rodinp.core.basis.InternalElement; -import org.rodinp.core.basis.RodinElement; - - - -public class BMotionSurfaceRoot extends InternalElement implements - IBMotionSurfaceRoot { - - public BMotionSurfaceRoot(final String name, final IRodinElement parent) { - super(name, parent); - } - - @Override - public RodinElement[] getChildren() throws RodinDBException { - return NO_ELEMENTS; - } - - @Override - public IInternalElementType<IBMotionSurfaceRoot> getElementType() { - return ELEMENT_TYPE; - } - -} diff --git a/de.bmotionstudio.rodin/src/de/bmotionstudio/rodin/IBMotionSurfaceRoot.java b/de.bmotionstudio.rodin/src/de/bmotionstudio/rodin/IBMotionSurfaceRoot.java deleted file mode 100644 index 5311a6aa..00000000 --- a/de.bmotionstudio.rodin/src/de/bmotionstudio/rodin/IBMotionSurfaceRoot.java +++ /dev/null @@ -1,21 +0,0 @@ -/** - * (c) 2009 Lehrstuhl fuer Softwaretechnik und Programmiersprachen, - * Heinrich Heine Universitaet Duesseldorf - * This software is licenced under EPL 1.0 (http://www.eclipse.org/org/documents/epl-v10.html) - * */ - -package de.bmotionstudio.rodin; - -import org.rodinp.core.IInternalElement; -import org.rodinp.core.IInternalElementType; -import org.rodinp.core.RodinCore; - -import de.bmotionstudio.gef.editor.BMotionEditorPlugin; - -public interface IBMotionSurfaceRoot extends IInternalElement { - - IInternalElementType<IBMotionSurfaceRoot> ELEMENT_TYPE = RodinCore - .getInternalElementType(BMotionEditorPlugin.PLUGIN_ID - + ".BMotionStudioFile"); //$NON-NLS-1$ - -} diff --git a/de.bmotionstudio.rodin/src/de/bmotionstudio/rodin/RenameFileHandler.java b/de.bmotionstudio.rodin/src/de/bmotionstudio/rodin/RenameFileHandler.java deleted file mode 100644 index 01f9f981..00000000 --- a/de.bmotionstudio.rodin/src/de/bmotionstudio/rodin/RenameFileHandler.java +++ /dev/null @@ -1,114 +0,0 @@ -/** - * (c) 2009 Lehrstuhl fuer Softwaretechnik und Programmiersprachen, - * Heinrich Heine Universitaet Duesseldorf - * This software is licenced under EPL 1.0 (http://www.eclipse.org/org/documents/epl-v10.html) - * */ - -package de.bmotionstudio.rodin; - -import org.eclipse.core.commands.AbstractHandler; -import org.eclipse.core.commands.ExecutionEvent; -import org.eclipse.core.commands.ExecutionException; -import org.eclipse.core.commands.IHandler; -import org.eclipse.core.resources.IWorkspaceRunnable; -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.jface.action.IAction; -import org.eclipse.jface.dialogs.InputDialog; -import org.eclipse.jface.viewers.ISelection; -import org.eclipse.jface.viewers.IStructuredSelection; -import org.eclipse.ui.IWorkbenchPart; -import org.eclipse.ui.handlers.HandlerUtil; -import org.rodinp.core.IRodinFile; -import org.rodinp.core.IRodinProject; -import org.rodinp.core.RodinCore; -import org.rodinp.core.RodinDBException; - -import de.bmotionstudio.gef.editor.BMotionEditorPlugin; -import de.bmotionstudio.gef.editor.internal.BMotionFileInputValidator; - -/** - * @author Lukas Ladenberger - * - */ -public class RenameFileHandler extends AbstractHandler implements IHandler { - - private ISelection fSelection; - private IWorkbenchPart part; - - @Override - public Object execute(ExecutionEvent event) throws ExecutionException { - - fSelection = HandlerUtil.getCurrentSelection(event); - part = HandlerUtil.getActivePart(event); - - if (fSelection instanceof IStructuredSelection) { - IStructuredSelection ssel = (IStructuredSelection) fSelection; - - if (ssel.size() == 1) { - - Object obj = ssel.getFirstElement(); - - if (obj instanceof IBMotionSurfaceRoot) { - - final IBMotionSurfaceRoot root = (IBMotionSurfaceRoot) obj; - if (root.getParent() instanceof IRodinFile) { - - final IRodinFile file = root.getRodinFile(); - final IRodinProject prj = file.getRodinProject(); - - InputDialog dialog = new InputDialog(part.getSite() - .getShell(), "Rename BMotion Studio Project", - "Please enter the new name for the Project", - getDefaultName(root), - new BMotionFileInputValidator(prj)); - - dialog.open(); - - final String bareName = dialog.getValue(); - - if (dialog.getReturnCode() == InputDialog.CANCEL) - return null; // Cancel - - assert bareName != null; - - try { - RodinCore.run(new IWorkspaceRunnable() { - - public void run(IProgressMonitor monitor) - throws RodinDBException { - String newName = bareName - + "." - + BMotionEditorPlugin.FILEEXT_STUDIO; - if (newName != null) - file.rename(newName, false, monitor); - } - - }, null); - } catch (RodinDBException e) { - e.printStackTrace(); - } - - } - } - - } - } - - return null; - - } - - public void selectionChanged(final IAction action, - final ISelection selection) { - fSelection = selection; - } - - public void setActivePart(IAction action, IWorkbenchPart targetPart) { - part = targetPart; - } - - private String getDefaultName(IBMotionSurfaceRoot root) { - return root.getResource().getName().replace(".bmso", ""); - } - -} diff --git a/de.bmotionstudio.rodin/src/de/bmotionstudio/rodin/StartEventBVisualizationHandler.java b/de.bmotionstudio.rodin/src/de/bmotionstudio/rodin/StartEventBVisualizationHandler.java index b3598766..7d0799c3 100644 --- a/de.bmotionstudio.rodin/src/de/bmotionstudio/rodin/StartEventBVisualizationHandler.java +++ b/de.bmotionstudio.rodin/src/de/bmotionstudio/rodin/StartEventBVisualizationHandler.java @@ -8,6 +8,11 @@ package de.bmotionstudio.rodin; import org.eclipse.core.commands.IHandler; import org.eclipse.core.resources.IFile; +import org.eclipse.core.resources.IResource; +import org.eclipse.core.resources.IWorkspace; +import org.eclipse.core.resources.ResourcesPlugin; +import org.eclipse.core.runtime.IPath; +import org.eclipse.core.runtime.Path; import org.eclipse.jface.viewers.IStructuredSelection; import de.bmotionstudio.gef.editor.handler.StartVisualizationFileHandler; @@ -21,8 +26,14 @@ public class StartEventBVisualizationHandler extends @Override protected IFile getBmsFileFromSelection(IStructuredSelection ssel) { - if (ssel.getFirstElement() instanceof IBMotionSurfaceRoot) - return ((IBMotionSurfaceRoot) ssel.getFirstElement()).getResource(); + if (ssel.getFirstElement() instanceof BMotionStudioRodinFile) { + IResource resource = ((BMotionStudioRodinFile) ssel + .getFirstElement()).getResource(); + IWorkspace workspace = ResourcesPlugin.getWorkspace(); + IPath location = Path.fromOSString(resource.getFullPath() + .toOSString()); + return workspace.getRoot().getFileForLocation(location); + } return null; } -- GitLab